Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ash/wm/panels/panel_frame_view.cc

Issue 189463013: [Refactor] Move code for painting the window header for browser windows out of ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/panels/panel_frame_view.h" 5 #include "ash/wm/panels/panel_frame_view.h"
6 6
7 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" 7 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
8 #include "ash/wm/default_header_painter.h"
8 #include "ash/wm/frame_border_hit_test_controller.h" 9 #include "ash/wm/frame_border_hit_test_controller.h"
9 #include "ash/wm/header_painter.h"
10 #include "grit/ash_resources.h"
11 #include "ui/base/hit_test.h" 10 #include "ui/base/hit_test.h"
12 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
14 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
15 #include "ui/views/widget/native_widget_aura.h"
16 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h" 15 #include "ui/views/widget/widget_delegate.h"
18 16
19 namespace ash { 17 namespace ash {
20 18
21 // static 19 // static
22 const char PanelFrameView::kViewClassName[] = "PanelFrameView"; 20 const char PanelFrameView::kViewClassName[] = "PanelFrameView";
23 21
24 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) 22 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type)
25 : frame_(frame), 23 : frame_(frame),
26 caption_button_container_(NULL), 24 caption_button_container_(NULL),
27 window_icon_(NULL), 25 window_icon_(NULL),
28 title_font_list_(views::NativeWidgetAura::GetWindowTitleFontList()),
29 frame_border_hit_test_controller_( 26 frame_border_hit_test_controller_(
30 new FrameBorderHitTestController(frame_)) { 27 new FrameBorderHitTestController(frame_)) {
31 DCHECK(!frame_->widget_delegate()->CanMaximize()); 28 DCHECK(!frame_->widget_delegate()->CanMaximize());
32 if (frame_type != FRAME_NONE) 29 if (frame_type != FRAME_NONE)
33 InitHeaderPainter(); 30 InitHeaderPainter();
34 } 31 }
35 32
36 PanelFrameView::~PanelFrameView() { 33 PanelFrameView::~PanelFrameView() {
37 } 34 }
38 35
39 const char* PanelFrameView::GetClassName() const { 36 const char* PanelFrameView::GetClassName() const {
40 return kViewClassName; 37 return kViewClassName;
41 } 38 }
42 39
43 void PanelFrameView::InitHeaderPainter() { 40 void PanelFrameView::InitHeaderPainter() {
44 header_painter_.reset(new HeaderPainter); 41 header_painter_.reset(new DefaultHeaderPainter);
45 42
46 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, 43 caption_button_container_ = new FrameCaptionButtonContainerView(frame_,
47 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); 44 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
48 AddChildView(caption_button_container_); 45 AddChildView(caption_button_container_);
49 46
50 if (frame_->widget_delegate()->ShouldShowWindowIcon()) { 47 if (frame_->widget_delegate()->ShouldShowWindowIcon()) {
51 window_icon_ = new views::ImageView(); 48 window_icon_ = new views::ImageView();
52 AddChildView(window_icon_); 49 AddChildView(window_icon_);
53 } 50 }
54 51
55 header_painter_->Init(HeaderPainter::STYLE_OTHER, frame_, this, window_icon_, 52 header_painter_->Init(frame_, this, window_icon_, caption_button_container_);
56 caption_button_container_);
57 } 53 }
58 54
59 int PanelFrameView::NonClientTopBorderHeight() const { 55 int PanelFrameView::NonClientTopBorderHeight() const {
60 if (!header_painter_) 56 if (!header_painter_)
61 return 0; 57 return 0;
62 // Reserve enough space to see the buttons and the separator line. 58 return header_painter_->GetHeaderHeightForPainting();
63 return caption_button_container_->bounds().bottom() +
64 header_painter_->HeaderContentSeparatorSize();
65 } 59 }
66 60
67 gfx::Size PanelFrameView::GetMinimumSize() { 61 gfx::Size PanelFrameView::GetMinimumSize() {
68 if (!header_painter_) 62 if (!header_painter_)
69 return gfx::Size(); 63 return gfx::Size();
70 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize()); 64 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize());
71 return gfx::Size( 65 return gfx::Size(
72 std::max(header_painter_->GetMinimumHeaderWidth(), 66 std::max(header_painter_->GetMinimumHeaderWidth(),
73 min_client_view_size.width()), 67 min_client_view_size.width()),
74 NonClientTopBorderHeight() + min_client_view_size.height()); 68 NonClientTopBorderHeight() + min_client_view_size.height());
75 } 69 }
76 70
77 void PanelFrameView::Layout() { 71 void PanelFrameView::Layout() {
78 if (!header_painter_) 72 if (!header_painter_)
79 return; 73 return;
80 header_painter_->LayoutHeader(); 74 header_painter_->LayoutHeader();
81 header_painter_->set_header_height(NonClientTopBorderHeight());
82 } 75 }
83 76
84 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { 77 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
85 // Nothing. 78 // Nothing.
86 } 79 }
87 80
88 void PanelFrameView::ResetWindowControls() { 81 void PanelFrameView::ResetWindowControls() {
89 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
90 } 83 }
91 84
92 void PanelFrameView::UpdateWindowIcon() { 85 void PanelFrameView::UpdateWindowIcon() {
93 if (!window_icon_) 86 if (!window_icon_)
94 return; 87 return;
95 views::WidgetDelegate* delegate = frame_->widget_delegate(); 88 views::WidgetDelegate* delegate = frame_->widget_delegate();
96 if (delegate) 89 if (delegate)
97 window_icon_->SetImage(delegate->GetWindowIcon()); 90 window_icon_->SetImage(delegate->GetWindowIcon());
98 window_icon_->SchedulePaint(); 91 window_icon_->SchedulePaint();
99 } 92 }
100 93
101 void PanelFrameView::UpdateWindowTitle() { 94 void PanelFrameView::UpdateWindowTitle() {
102 if (!header_painter_) 95 if (!header_painter_)
103 return; 96 return;
104 header_painter_->SchedulePaintForTitle(title_font_list_); 97 header_painter_->SchedulePaintForTitle();
105 } 98 }
106 99
107 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { 100 int PanelFrameView::NonClientHitTest(const gfx::Point& point) {
108 if (!header_painter_) 101 if (!header_painter_)
109 return HTNOWHERE; 102 return HTNOWHERE;
110 return FrameBorderHitTestController::NonClientHitTest(this, 103 return FrameBorderHitTestController::NonClientHitTest(this,
111 header_painter_.get(), point); 104 caption_button_container_, point);
112 } 105 }
113 106
114 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { 107 void PanelFrameView::OnPaint(gfx::Canvas* canvas) {
115 if (!header_painter_) 108 if (!header_painter_)
116 return; 109 return;
117 bool paint_as_active = ShouldPaintAsActive(); 110 bool paint_as_active = ShouldPaintAsActive();
118 caption_button_container_->SetPaintAsActive(paint_as_active); 111 caption_button_container_->SetPaintAsActive(paint_as_active);
119 112
120 int theme_frame_id = 0;
121 if (paint_as_active)
122 theme_frame_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE;
123 else
124 theme_frame_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;
125
126 HeaderPainter::Mode header_mode = paint_as_active ? 113 HeaderPainter::Mode header_mode = paint_as_active ?
127 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; 114 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE;
128 header_painter_->PaintHeader(canvas, header_mode, theme_frame_id, 0); 115 header_painter_->PaintHeader(canvas, header_mode);
129 header_painter_->PaintTitleBar(canvas, title_font_list_);
130 header_painter_->PaintHeaderContentSeparator(canvas, header_mode);
131 } 116 }
132 117
133 gfx::Rect PanelFrameView::GetBoundsForClientView() const { 118 gfx::Rect PanelFrameView::GetBoundsForClientView() const {
134 if (!header_painter_) 119 gfx::Rect client_bounds = bounds();
135 return bounds(); 120 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
136 return HeaderPainter::GetBoundsForClientView( 121 return client_bounds;
137 NonClientTopBorderHeight(), bounds());
138 } 122 }
139 123
140 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( 124 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds(
141 const gfx::Rect& client_bounds) const { 125 const gfx::Rect& client_bounds) const {
142 if (!header_painter_) 126 gfx::Rect window_bounds = client_bounds;
143 return client_bounds; 127 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0);
144 return HeaderPainter::GetWindowBoundsForClientBounds( 128 return window_bounds;
145 NonClientTopBorderHeight(), client_bounds);
146 } 129 }
147 130
148 } // namespace ash 131 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698