OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame/default_header_painter.h" | 5 #include "ash/frame/default_header_painter.h" |
6 | 6 |
7 #include "ash/common/ash_layout_constants.h" | 7 #include "ash/common/ash_layout_constants.h" |
8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
9 #include "ash/frame/header_painter_util.h" | 9 #include "ash/frame/header_painter_util.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Duration of crossfade animation for activating and deactivating frame. | 43 // Duration of crossfade animation for activating and deactivating frame. |
44 const int kActivationCrossfadeDurationMs = 200; | 44 const int kActivationCrossfadeDurationMs = 200; |
45 | 45 |
46 // Tiles an image into an area, rounding the top corners. | 46 // Tiles an image into an area, rounding the top corners. |
47 void TileRoundRect(gfx::Canvas* canvas, | 47 void TileRoundRect(gfx::Canvas* canvas, |
48 const SkPaint& paint, | 48 const SkPaint& paint, |
49 const gfx::Rect& bounds, | 49 const gfx::Rect& bounds, |
50 int corner_radius) { | 50 int corner_radius) { |
51 SkRect rect = gfx::RectToSkRect(bounds); | 51 SkRect rect = gfx::RectToSkRect(bounds); |
52 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius); | 52 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius); |
53 SkScalar radii[8] = { | 53 SkScalar radii[8] = {corner_radius_scalar, |
54 corner_radius_scalar, corner_radius_scalar, // top-left | 54 corner_radius_scalar, // top-left |
55 corner_radius_scalar, corner_radius_scalar, // top-right | 55 corner_radius_scalar, |
56 0, 0, // bottom-right | 56 corner_radius_scalar, // top-right |
57 0, 0}; // bottom-left | 57 0, |
| 58 0, // bottom-right |
| 59 0, |
| 60 0}; // bottom-left |
58 SkPath path; | 61 SkPath path; |
59 path.addRoundRect(rect, radii, SkPath::kCW_Direction); | 62 path.addRoundRect(rect, radii, SkPath::kCW_Direction); |
60 canvas->DrawPath(path, paint); | 63 canvas->DrawPath(path, paint); |
61 } | 64 } |
62 | 65 |
63 // Returns the FontList to use for the title. | 66 // Returns the FontList to use for the title. |
64 const gfx::FontList& GetTitleFontList() { | 67 const gfx::FontList& GetTitleFontList() { |
65 static const gfx::FontList* title_font_list = | 68 static const gfx::FontList* title_font_list = |
66 new gfx::FontList(views::NativeWidgetAura::GetWindowTitleFontList()); | 69 new gfx::FontList(views::NativeWidgetAura::GetWindowTitleFontList()); |
67 ANNOTATE_LEAKING_OBJECT_PTR(title_font_list); | 70 ANNOTATE_LEAKING_OBJECT_PTR(title_font_list); |
(...skipping 12 matching lines...) Expand all Loading... |
80 view_(NULL), | 83 view_(NULL), |
81 left_header_view_(NULL), | 84 left_header_view_(NULL), |
82 active_frame_color_(kDefaultFrameColor), | 85 active_frame_color_(kDefaultFrameColor), |
83 inactive_frame_color_(kDefaultFrameColor), | 86 inactive_frame_color_(kDefaultFrameColor), |
84 caption_button_container_(NULL), | 87 caption_button_container_(NULL), |
85 painted_height_(0), | 88 painted_height_(0), |
86 mode_(MODE_INACTIVE), | 89 mode_(MODE_INACTIVE), |
87 initial_paint_(true), | 90 initial_paint_(true), |
88 activation_animation_(new gfx::SlideAnimation(this)) {} | 91 activation_animation_(new gfx::SlideAnimation(this)) {} |
89 | 92 |
90 DefaultHeaderPainter::~DefaultHeaderPainter() { | 93 DefaultHeaderPainter::~DefaultHeaderPainter() {} |
91 } | |
92 | 94 |
93 void DefaultHeaderPainter::Init( | 95 void DefaultHeaderPainter::Init( |
94 views::Widget* frame, | 96 views::Widget* frame, |
95 views::View* header_view, | 97 views::View* header_view, |
96 FrameCaptionButtonContainerView* caption_button_container) { | 98 FrameCaptionButtonContainerView* caption_button_container) { |
97 DCHECK(frame); | 99 DCHECK(frame); |
98 DCHECK(header_view); | 100 DCHECK(header_view); |
99 DCHECK(caption_button_container); | 101 DCHECK(caption_button_container); |
100 frame_ = frame; | 102 frame_ = frame; |
101 view_ = header_view; | 103 view_ = header_view; |
102 caption_button_container_ = caption_button_container; | 104 caption_button_container_ = caption_button_container; |
103 caption_button_container_->SetButtonSize( | 105 caption_button_container_->SetButtonSize( |
104 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON)); | 106 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON)); |
105 UpdateAllButtonImages(); | 107 UpdateAllButtonImages(); |
106 } | 108 } |
107 | 109 |
108 int DefaultHeaderPainter::GetMinimumHeaderWidth() const { | 110 int DefaultHeaderPainter::GetMinimumHeaderWidth() const { |
109 // Ensure we have enough space for the window icon and buttons. We allow | 111 // Ensure we have enough space for the window icon and buttons. We allow |
110 // the title string to collapse to zero width. | 112 // the title string to collapse to zero width. |
111 return GetTitleBounds().x() + | 113 return GetTitleBounds().x() + |
112 caption_button_container_->GetMinimumSize().width(); | 114 caption_button_container_->GetMinimumSize().width(); |
113 } | 115 } |
114 | 116 |
115 void DefaultHeaderPainter::PaintHeader(gfx::Canvas* canvas, Mode mode) { | 117 void DefaultHeaderPainter::PaintHeader(gfx::Canvas* canvas, Mode mode) { |
116 Mode old_mode = mode_; | 118 Mode old_mode = mode_; |
117 mode_ = mode; | 119 mode_ = mode; |
118 | 120 |
119 if (mode_ != old_mode) { | 121 if (mode_ != old_mode) { |
120 UpdateAllButtonImages(); | 122 UpdateAllButtonImages(); |
121 if (!initial_paint_ && HeaderPainterUtil::CanAnimateActivation(frame_)) { | 123 if (!initial_paint_ && HeaderPainterUtil::CanAnimateActivation(frame_)) { |
122 activation_animation_->SetSlideDuration(kActivationCrossfadeDurationMs); | 124 activation_animation_->SetSlideDuration(kActivationCrossfadeDurationMs); |
123 if (mode_ == MODE_ACTIVE) | 125 if (mode_ == MODE_ACTIVE) |
124 activation_animation_->Show(); | 126 activation_animation_->Show(); |
125 else | 127 else |
126 activation_animation_->Hide(); | 128 activation_animation_->Hide(); |
127 } else { | 129 } else { |
128 if (mode_ == MODE_ACTIVE) | 130 if (mode_ == MODE_ACTIVE) |
129 activation_animation_->Reset(1); | 131 activation_animation_->Reset(1); |
130 else | 132 else |
131 activation_animation_->Reset(0); | 133 activation_animation_->Reset(0); |
132 } | 134 } |
133 initial_paint_ = false; | 135 initial_paint_ = false; |
134 } | 136 } |
135 | 137 |
136 int corner_radius = (frame_->IsMaximized() || frame_->IsFullscreen()) ? | 138 int corner_radius = (frame_->IsMaximized() || frame_->IsFullscreen()) |
137 0 : HeaderPainterUtil::GetTopCornerRadiusWhenRestored(); | 139 ? 0 |
| 140 : HeaderPainterUtil::GetTopCornerRadiusWhenRestored(); |
138 | 141 |
139 SkPaint paint; | 142 SkPaint paint; |
140 int active_alpha = activation_animation_->CurrentValueBetween(0, 255); | 143 int active_alpha = activation_animation_->CurrentValueBetween(0, 255); |
141 paint.setColor(color_utils::AlphaBlend(active_frame_color_, | 144 paint.setColor(color_utils::AlphaBlend(active_frame_color_, |
142 inactive_frame_color_, active_alpha)); | 145 inactive_frame_color_, active_alpha)); |
143 | 146 |
144 TileRoundRect(canvas, paint, GetLocalBounds(), corner_radius); | 147 TileRoundRect(canvas, paint, GetLocalBounds(), corner_radius); |
145 | 148 |
146 if (!frame_->IsMaximized() && !frame_->IsFullscreen() && | 149 if (!frame_->IsMaximized() && !frame_->IsFullscreen() && |
147 mode_ == MODE_INACTIVE && !UsesCustomFrameColors()) { | 150 mode_ == MODE_INACTIVE && !UsesCustomFrameColors()) { |
148 PaintHighlightForInactiveRestoredWindow(canvas); | 151 PaintHighlightForInactiveRestoredWindow(canvas); |
149 } | 152 } |
150 if (frame_->widget_delegate() && | 153 if (frame_->widget_delegate() && |
151 frame_->widget_delegate()->ShouldShowWindowTitle()) { | 154 frame_->widget_delegate()->ShouldShowWindowTitle()) { |
152 PaintTitleBar(canvas); | 155 PaintTitleBar(canvas); |
153 } | 156 } |
154 if (!UsesCustomFrameColors()) | 157 if (!UsesCustomFrameColors()) |
155 PaintHeaderContentSeparator(canvas); | 158 PaintHeaderContentSeparator(canvas); |
156 } | 159 } |
157 | 160 |
158 void DefaultHeaderPainter::LayoutHeader() { | 161 void DefaultHeaderPainter::LayoutHeader() { |
159 caption_button_container_->SetUseLightImages(ShouldUseLightImages()); | 162 caption_button_container_->SetUseLightImages(ShouldUseLightImages()); |
160 UpdateSizeButtonImages(); | 163 UpdateSizeButtonImages(); |
161 caption_button_container_->Layout(); | 164 caption_button_container_->Layout(); |
162 | 165 |
163 gfx::Size caption_button_container_size = | 166 gfx::Size caption_button_container_size = |
164 caption_button_container_->GetPreferredSize(); | 167 caption_button_container_->GetPreferredSize(); |
165 caption_button_container_->SetBounds( | 168 caption_button_container_->SetBounds( |
166 view_->width() - caption_button_container_size.width(), | 169 view_->width() - caption_button_container_size.width(), 0, |
167 0, | |
168 caption_button_container_size.width(), | 170 caption_button_container_size.width(), |
169 caption_button_container_size.height()); | 171 caption_button_container_size.height()); |
170 | 172 |
171 if (left_header_view_) { | 173 if (left_header_view_) { |
172 // Vertically center the left header view with respect to the caption button | 174 // Vertically center the left header view with respect to the caption button |
173 // container. | 175 // container. |
174 // Floor when computing the center of |caption_button_container_|. | 176 // Floor when computing the center of |caption_button_container_|. |
175 gfx::Size size = left_header_view_->GetPreferredSize(); | 177 gfx::Size size = left_header_view_->GetPreferredSize(); |
176 int icon_offset_y = | 178 int icon_offset_y = |
177 caption_button_container_->height() / 2 - size.height() / 2; | 179 caption_button_container_->height() / 2 - size.height() / 2; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 const gfx::Animation* animation) { | 219 const gfx::Animation* animation) { |
218 view_->SchedulePaintInRect(GetLocalBounds()); | 220 view_->SchedulePaintInRect(GetLocalBounds()); |
219 } | 221 } |
220 | 222 |
221 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
222 // DefaultHeaderPainter, private: | 224 // DefaultHeaderPainter, private: |
223 | 225 |
224 void DefaultHeaderPainter::PaintHighlightForInactiveRestoredWindow( | 226 void DefaultHeaderPainter::PaintHighlightForInactiveRestoredWindow( |
225 gfx::Canvas* canvas) { | 227 gfx::Canvas* canvas) { |
226 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 228 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
227 gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed( | 229 gfx::ImageSkia top_edge = |
228 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP); | 230 *rb.GetImageSkiaNamed(IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP); |
229 gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed( | 231 gfx::ImageSkia left_edge = |
230 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT); | 232 *rb.GetImageSkiaNamed(IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT); |
231 gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed( | 233 gfx::ImageSkia right_edge = |
232 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT); | 234 *rb.GetImageSkiaNamed(IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT); |
233 gfx::ImageSkia bottom_edge = *rb.GetImageSkiaNamed( | 235 gfx::ImageSkia bottom_edge = |
234 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM); | 236 *rb.GetImageSkiaNamed(IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM); |
235 | 237 |
236 int left_edge_width = left_edge.width(); | 238 int left_edge_width = left_edge.width(); |
237 int right_edge_width = right_edge.width(); | 239 int right_edge_width = right_edge.width(); |
238 canvas->DrawImageInt(left_edge, 0, 0); | 240 canvas->DrawImageInt(left_edge, 0, 0); |
239 canvas->DrawImageInt(right_edge, view_->width() - right_edge_width, 0); | 241 canvas->DrawImageInt(right_edge, view_->width() - right_edge_width, 0); |
240 canvas->TileImageInt( | 242 canvas->TileImageInt(top_edge, left_edge_width, 0, |
241 top_edge, | 243 view_->width() - left_edge_width - right_edge_width, |
242 left_edge_width, | 244 top_edge.height()); |
243 0, | |
244 view_->width() - left_edge_width - right_edge_width, | |
245 top_edge.height()); | |
246 | 245 |
247 DCHECK_EQ(left_edge.height(), right_edge.height()); | 246 DCHECK_EQ(left_edge.height(), right_edge.height()); |
248 int bottom = left_edge.height(); | 247 int bottom = left_edge.height(); |
249 int bottom_height = bottom_edge.height(); | 248 int bottom_height = bottom_edge.height(); |
250 canvas->TileImageInt( | 249 canvas->TileImageInt(bottom_edge, left_edge_width, bottom - bottom_height, |
251 bottom_edge, | 250 view_->width() - left_edge_width - right_edge_width, |
252 left_edge_width, | 251 bottom_height); |
253 bottom - bottom_height, | |
254 view_->width() - left_edge_width - right_edge_width, | |
255 bottom_height); | |
256 } | 252 } |
257 | 253 |
258 void DefaultHeaderPainter::PaintTitleBar(gfx::Canvas* canvas) { | 254 void DefaultHeaderPainter::PaintTitleBar(gfx::Canvas* canvas) { |
259 // The window icon is painted by its own views::View. | 255 // The window icon is painted by its own views::View. |
260 gfx::Rect title_bounds = GetTitleBounds(); | 256 gfx::Rect title_bounds = GetTitleBounds(); |
261 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); | 257 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); |
262 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), | 258 canvas->DrawStringRectWithFlags( |
263 GetTitleFontList(), | 259 frame_->widget_delegate()->GetWindowTitle(), GetTitleFontList(), |
264 kTitleTextColor, | 260 kTitleTextColor, title_bounds, gfx::Canvas::NO_SUBPIXEL_RENDERING); |
265 title_bounds, | |
266 gfx::Canvas::NO_SUBPIXEL_RENDERING); | |
267 } | 261 } |
268 | 262 |
269 void DefaultHeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas) { | 263 void DefaultHeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas) { |
270 gfx::ScopedCanvas scoped_canvas(canvas); | 264 gfx::ScopedCanvas scoped_canvas(canvas); |
271 const float scale = canvas->UndoDeviceScaleFactor(); | 265 const float scale = canvas->UndoDeviceScaleFactor(); |
272 gfx::RectF rect(0, painted_height_ * scale - 1, view_->width() * scale, 1); | 266 gfx::RectF rect(0, painted_height_ * scale - 1, view_->width() * scale, 1); |
273 SkPaint paint; | 267 SkPaint paint; |
274 paint.setColor((mode_ == MODE_ACTIVE) ? | 268 paint.setColor((mode_ == MODE_ACTIVE) ? kHeaderContentSeparatorColor |
275 kHeaderContentSeparatorColor : kHeaderContentSeparatorInactiveColor); | 269 : kHeaderContentSeparatorInactiveColor); |
276 canvas->sk_canvas()->drawRect(gfx::RectFToSkRect(rect), paint); | 270 canvas->sk_canvas()->drawRect(gfx::RectFToSkRect(rect), paint); |
277 } | 271 } |
278 | 272 |
279 bool DefaultHeaderPainter::ShouldUseLightImages() { | 273 bool DefaultHeaderPainter::ShouldUseLightImages() { |
280 return color_utils::IsDark(mode_ == MODE_INACTIVE ? inactive_frame_color_ | 274 return color_utils::IsDark(mode_ == MODE_INACTIVE ? inactive_frame_color_ |
281 : active_frame_color_); | 275 : active_frame_color_); |
282 } | 276 } |
283 | 277 |
284 void DefaultHeaderPainter::UpdateAllButtonImages() { | 278 void DefaultHeaderPainter::UpdateAllButtonImages() { |
285 caption_button_container_->SetUseLightImages(ShouldUseLightImages()); | 279 caption_button_container_->SetUseLightImages(ShouldUseLightImages()); |
(...skipping 30 matching lines...) Expand all Loading... |
316 return HeaderPainterUtil::GetTitleBounds( | 310 return HeaderPainterUtil::GetTitleBounds( |
317 left_header_view_, caption_button_container_, GetTitleFontList()); | 311 left_header_view_, caption_button_container_, GetTitleFontList()); |
318 } | 312 } |
319 | 313 |
320 bool DefaultHeaderPainter::UsesCustomFrameColors() const { | 314 bool DefaultHeaderPainter::UsesCustomFrameColors() const { |
321 return active_frame_color_ != kDefaultFrameColor || | 315 return active_frame_color_ != kDefaultFrameColor || |
322 inactive_frame_color_ != kDefaultFrameColor; | 316 inactive_frame_color_ != kDefaultFrameColor; |
323 } | 317 } |
324 | 318 |
325 } // namespace ash | 319 } // namespace ash |
OLD | NEW |