Skip to content

Commit

Permalink
[Refactor] Move code for painting the window header for browser windo…
Browse files Browse the repository at this point in the history
…ws out of ash

BUG=340143
TEST=None

Review URL: https://codereview.chromium.org/189463013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257494 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkotwicz@chromium.org committed Mar 17, 2014
1 parent be6d25a commit 8f9a4f9
Show file tree
Hide file tree
Showing 22 changed files with 1,353 additions and 1,100 deletions.
7 changes: 5 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@
'frame/custom_frame_view_ash.h',
'frame/frame_border_hit_test_controller.cc',
'frame/frame_border_hit_test_controller.h',
'frame/default_header_painter.cc',
'frame/default_header_painter.h',
'frame/frame_util.cc',
'frame/frame_util.h',
'frame/header_painter.cc',
'frame/header_painter.h',
'frame/header_painter_util.cc',
'frame/header_painter_util.h',
'gpu_support.h',
'gpu_support_stub.cc',
'gpu_support_stub.h',
Expand Down Expand Up @@ -887,7 +890,7 @@
'frame/caption_buttons/frame_caption_button_container_view_unittest.cc',
'frame/caption_buttons/frame_maximize_button_unittest.cc',
'frame/custom_frame_view_ash_unittest.cc',
'frame/header_painter_unittest.cc',
'frame/default_header_painter_unittest.cc',
'ime/candidate_window_view_unittest.cc',
'ime/input_method_menu_item_unittest.cc',
'ime/input_method_menu_manager_unittest.cc',
Expand Down
57 changes: 16 additions & 41 deletions ash/frame/custom_frame_view_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,28 @@
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/frame/caption_buttons/frame_maximize_button.h"
#include "ash/frame/caption_buttons/frame_maximize_button_observer.h"
#include "ash/frame/default_header_painter.h"
#include "ash/frame/frame_border_hit_test_controller.h"
#include "ash/frame/header_painter.h"
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/window_state_observer.h"
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "grit/ash_resources.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size.h"
#include "ui/views/view.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_deletion_observer.h"

namespace {

const gfx::FontList& GetTitleFontList() {
static const gfx::FontList* title_font_list =
new gfx::FontList(views::NativeWidgetAura::GetWindowTitleFontList());
ANNOTATE_LEAKING_OBJECT_PTR(title_font_list);
return *title_font_list;
}

///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAshWindowStateDelegate

Expand Down Expand Up @@ -160,8 +150,8 @@ class CustomFrameViewAsh::HeaderView
virtual void Layout() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;

HeaderPainter* header_painter() {
return header_painter_.get();
FrameCaptionButtonContainerView* caption_button_container() {
return caption_button_container_;
}

private:
Expand All @@ -179,7 +169,7 @@ class CustomFrameViewAsh::HeaderView
views::Widget* frame_;

// Helper for painting the header.
scoped_ptr<HeaderPainter> header_painter_;
scoped_ptr<DefaultHeaderPainter> header_painter_;

// View which contains the window caption buttons.
FrameCaptionButtonContainerView* caption_button_container_;
Expand All @@ -200,7 +190,7 @@ class CustomFrameViewAsh::HeaderView

CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
: frame_(frame),
header_painter_(new ash::HeaderPainter),
header_painter_(new ash::DefaultHeaderPainter),
caption_button_container_(NULL),
maximize_bubble_(NULL),
fullscreen_visible_fraction_(0) {
Expand All @@ -218,8 +208,7 @@ CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
if (frame_maximize_button)
frame_maximize_button->AddObserver(this);

header_painter_->Init(HeaderPainter::STYLE_OTHER, frame_, this, NULL,
caption_button_container_);
header_painter_->Init(frame_, this, NULL, caption_button_container_);
}

CustomFrameViewAsh::HeaderView::~HeaderView() {
Expand All @@ -230,7 +219,7 @@ CustomFrameViewAsh::HeaderView::~HeaderView() {
}

void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() {
header_painter_->SchedulePaintForTitle(GetTitleFontList());
header_painter_->SchedulePaintForTitle();
}

void CustomFrameViewAsh::HeaderView::ResetWindowControls() {
Expand All @@ -246,9 +235,7 @@ int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const {
}

int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const {
// Reserve enough space to see the buttons and the separator line.
return caption_button_container_->bounds().bottom() +
header_painter_->HeaderContentSeparatorSize();
return header_painter_->GetHeaderHeightForPainting();
}

int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
Expand All @@ -257,29 +244,16 @@ int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {

void CustomFrameViewAsh::HeaderView::Layout() {
header_painter_->LayoutHeader();
header_painter_->set_header_height(GetPreferredHeight());
}

void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) {
bool paint_as_active =
frame_->non_client_view()->frame_view()->ShouldPaintAsActive();
caption_button_container_->SetPaintAsActive(paint_as_active);

int theme_image_id = 0;
if (paint_as_active)
theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE;
else
theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;

HeaderPainter::Mode header_mode = paint_as_active ?
HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE;
header_painter_->PaintHeader(
canvas,
header_mode,
theme_image_id,
0);
header_painter_->PaintTitleBar(canvas, GetTitleFontList());
header_painter_->PaintHeaderContentSeparator(canvas, header_mode);
header_painter_->PaintHeader(canvas, header_mode);
}

void CustomFrameViewAsh::HeaderView::OnImmersiveRevealStarted() {
Expand Down Expand Up @@ -419,20 +393,21 @@ void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
// CustomFrameViewAsh, views::NonClientFrameView overrides:

gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const {
int top_height = NonClientTopBorderHeight();
return HeaderPainter::GetBoundsForClientView(top_height, bounds());
gfx::Rect client_bounds = bounds();
client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
return client_bounds;
}

gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const {
int top_height = NonClientTopBorderHeight();
return HeaderPainter::GetWindowBoundsForClientBounds(top_height,
client_bounds);
gfx::Rect window_bounds = client_bounds;
window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0);
return window_bounds;
}

int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
return FrameBorderHitTestController::NonClientHitTest(this,
header_view_->header_painter(), point);
header_view_->caption_button_container(), point);
}

void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size,
Expand Down
1 change: 0 additions & 1 deletion ash/frame/custom_frame_view_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace ash {
class FrameBorderHitTestController;
class HeaderPainter;
class ImmersiveFullscreenController;
}
namespace views {
Expand Down
2 changes: 1 addition & 1 deletion ash/frame/custom_frame_view_ash_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TEST_F(CustomFrameViewAshTest, HeaderHeight) {
rb.GetImageSkiaNamed(IDR_AURA_WINDOW_CONTROL_BACKGROUND_H);

// |kSeparatorSize| should match |kHeaderContentSeparatorSize| in
// header_painter.cc
// default_header_painter.cc
// TODO(pkotwicz): Clean this test up once the separator overlays the window
// controls.
const int kSeparatorSize = 1;
Expand Down
Loading

0 comments on commit 8f9a4f9

Please sign in to comment.