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

Side by Side Diff: ash/frame/default_header_painter.cc

Issue 934503002: Ash frames: dark frames now use white caption buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ash_unittests Created 5 years, 10 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
OLDNEW
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/frame/caption_buttons/frame_caption_button_container_view.h" 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
8 #include "ash/frame/header_painter_util.h" 8 #include "ash/frame/header_painter_util.h"
9 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
10 #include "base/logging.h" // DCHECK 10 #include "base/logging.h" // DCHECK
(...skipping 23 matching lines...) Expand all
34 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(150, 150, 152); 34 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(150, 150, 152);
35 // Color of the inactive window header/content separator line. 35 // Color of the inactive window header/content separator line.
36 const SkColor kHeaderContentSeparatorInactiveColor = 36 const SkColor kHeaderContentSeparatorInactiveColor =
37 SkColorSetRGB(180, 180, 182); 37 SkColorSetRGB(180, 180, 182);
38 // The default color of the frame. 38 // The default color of the frame.
39 const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242); 39 const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242);
40 // The alpha of the inactive frame. 40 // The alpha of the inactive frame.
41 const SkAlpha kInactiveFrameAlpha = 204; 41 const SkAlpha kInactiveFrameAlpha = 204;
42 // Duration of crossfade animation for activating and deactivating frame. 42 // Duration of crossfade animation for activating and deactivating frame.
43 const int kActivationCrossfadeDurationMs = 200; 43 const int kActivationCrossfadeDurationMs = 200;
44 // Luminance below which to use white caption buttons.
45 const int kMaxLuminanceForLightButtons = 125;
44 46
45 // Tiles an image into an area, rounding the top corners. 47 // Tiles an image into an area, rounding the top corners.
46 void TileRoundRect(gfx::Canvas* canvas, 48 void TileRoundRect(gfx::Canvas* canvas,
47 const SkPaint& paint, 49 const SkPaint& paint,
48 const gfx::Rect& bounds, 50 const gfx::Rect& bounds,
49 int corner_radius) { 51 int corner_radius) {
50 SkRect rect = gfx::RectToSkRect(bounds); 52 SkRect rect = gfx::RectToSkRect(bounds);
51 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius); 53 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius);
52 SkScalar radii[8] = { 54 SkScalar radii[8] = {
53 corner_radius_scalar, corner_radius_scalar, // top-left 55 corner_radius_scalar, corner_radius_scalar, // top-left
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void DefaultHeaderPainter::Init( 96 void DefaultHeaderPainter::Init(
95 views::Widget* frame, 97 views::Widget* frame,
96 views::View* header_view, 98 views::View* header_view,
97 FrameCaptionButtonContainerView* caption_button_container) { 99 FrameCaptionButtonContainerView* caption_button_container) {
98 DCHECK(frame); 100 DCHECK(frame);
99 DCHECK(header_view); 101 DCHECK(header_view);
100 DCHECK(caption_button_container); 102 DCHECK(caption_button_container);
101 frame_ = frame; 103 frame_ = frame;
102 view_ = header_view; 104 view_ = header_view;
103 caption_button_container_ = caption_button_container; 105 caption_button_container_ = caption_button_container;
104 106 UpdateAllButtonImages();
105 caption_button_container_->SetButtonImages(
106 CAPTION_BUTTON_ICON_MINIMIZE,
107 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE,
108 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I,
109 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
110 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
111 UpdateSizeButtonImages();
112 caption_button_container_->SetButtonImages(
113 CAPTION_BUTTON_ICON_CLOSE,
114 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
115 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_I,
116 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
117 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
118
119 // There is no dedicated icon for the snap-left and snap-right buttons
120 // when |frame_| is inactive because they should never be visible while
121 // |frame_| is inactive.
122 caption_button_container_->SetButtonImages(
123 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
124 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
125 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
126 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
127 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
128 caption_button_container_->SetButtonImages(
129 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
130 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
131 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
132 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
133 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
134 } 107 }
135 108
136 int DefaultHeaderPainter::GetMinimumHeaderWidth() const { 109 int DefaultHeaderPainter::GetMinimumHeaderWidth() const {
137 // Ensure we have enough space for the window icon and buttons. We allow 110 // Ensure we have enough space for the window icon and buttons. We allow
138 // the title string to collapse to zero width. 111 // the title string to collapse to zero width.
139 return GetTitleBounds().x() + 112 return GetTitleBounds().x() +
140 caption_button_container_->GetMinimumSize().width(); 113 caption_button_container_->GetMinimumSize().width();
141 } 114 }
142 115
143 void DefaultHeaderPainter::PaintHeader(gfx::Canvas* canvas, Mode mode) { 116 void DefaultHeaderPainter::PaintHeader(gfx::Canvas* canvas, Mode mode) {
144 Mode old_mode = mode_; 117 Mode old_mode = mode_;
145 mode_ = mode; 118 mode_ = mode;
146 119
147 if (mode_ != old_mode) { 120 if (mode_ != old_mode) {
121 UpdateAllButtonImages();
148 if (!initial_paint_ && HeaderPainterUtil::CanAnimateActivation(frame_)) { 122 if (!initial_paint_ && HeaderPainterUtil::CanAnimateActivation(frame_)) {
149 activation_animation_->SetSlideDuration(kActivationCrossfadeDurationMs); 123 activation_animation_->SetSlideDuration(kActivationCrossfadeDurationMs);
150 if (mode_ == MODE_ACTIVE) 124 if (mode_ == MODE_ACTIVE)
151 activation_animation_->Show(); 125 activation_animation_->Show();
152 else 126 else
153 activation_animation_->Hide(); 127 activation_animation_->Hide();
154 } else { 128 } else {
155 if (mode_ == MODE_ACTIVE) 129 if (mode_ == MODE_ACTIVE)
156 activation_animation_->Reset(1); 130 activation_animation_->Reset(1);
157 else 131 else
(...skipping 18 matching lines...) Expand all
176 PaintHighlightForInactiveRestoredWindow(canvas); 150 PaintHighlightForInactiveRestoredWindow(canvas);
177 } 151 }
178 if (frame_->widget_delegate() && 152 if (frame_->widget_delegate() &&
179 frame_->widget_delegate()->ShouldShowWindowTitle()) { 153 frame_->widget_delegate()->ShouldShowWindowTitle()) {
180 PaintTitleBar(canvas); 154 PaintTitleBar(canvas);
181 } 155 }
182 PaintHeaderContentSeparator(canvas); 156 PaintHeaderContentSeparator(canvas);
183 } 157 }
184 158
185 void DefaultHeaderPainter::LayoutHeader() { 159 void DefaultHeaderPainter::LayoutHeader() {
186 UpdateSizeButtonImages(); 160 UpdateSizeButtonImages(ShouldUseLightImages());
187 caption_button_container_->Layout(); 161 caption_button_container_->Layout();
188 162
189 gfx::Size caption_button_container_size = 163 gfx::Size caption_button_container_size =
190 caption_button_container_->GetPreferredSize(); 164 caption_button_container_->GetPreferredSize();
191 caption_button_container_->SetBounds( 165 caption_button_container_->SetBounds(
192 view_->width() - caption_button_container_size.width(), 166 view_->width() - caption_button_container_size.width(),
193 0, 167 0,
194 caption_button_container_size.width(), 168 caption_button_container_size.width(),
195 caption_button_container_size.height()); 169 caption_button_container_size.height());
196 170
(...skipping 19 matching lines...) Expand all
216 if (left_view_x_inset_ != left_view_x_inset) { 190 if (left_view_x_inset_ != left_view_x_inset) {
217 left_view_x_inset_ = left_view_x_inset; 191 left_view_x_inset_ = left_view_x_inset;
218 LayoutLeftHeaderView(); 192 LayoutLeftHeaderView();
219 } 193 }
220 } 194 }
221 195
222 void DefaultHeaderPainter::SetFrameColors(SkColor active_frame_color, 196 void DefaultHeaderPainter::SetFrameColors(SkColor active_frame_color,
223 SkColor inactive_frame_color) { 197 SkColor inactive_frame_color) {
224 active_frame_color_ = active_frame_color; 198 active_frame_color_ = active_frame_color;
225 inactive_frame_color_ = inactive_frame_color; 199 inactive_frame_color_ = inactive_frame_color;
200 UpdateAllButtonImages();
226 } 201 }
227 202
228 void DefaultHeaderPainter::UpdateLeftHeaderView(views::View* left_header_view) { 203 void DefaultHeaderPainter::UpdateLeftHeaderView(views::View* left_header_view) {
229 left_header_view_ = left_header_view; 204 left_header_view_ = left_header_view;
230 } 205 }
231 206
232 /////////////////////////////////////////////////////////////////////////////// 207 ///////////////////////////////////////////////////////////////////////////////
233 // gfx::AnimationDelegate overrides: 208 // gfx::AnimationDelegate overrides:
234 209
235 void DefaultHeaderPainter::AnimationProgressed( 210 void DefaultHeaderPainter::AnimationProgressed(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // container. 281 // container.
307 // Floor when computing the center of |caption_button_container_|. 282 // Floor when computing the center of |caption_button_container_|.
308 gfx::Size size = left_header_view_->GetPreferredSize(); 283 gfx::Size size = left_header_view_->GetPreferredSize();
309 int icon_offset_y = caption_button_container_->height() / 2 - 284 int icon_offset_y = caption_button_container_->height() / 2 -
310 size.height() / 2; 285 size.height() / 2;
311 left_header_view_->SetBounds( 286 left_header_view_->SetBounds(
312 left_view_x_inset_, icon_offset_y, size.width(), size.height()); 287 left_view_x_inset_, icon_offset_y, size.width(), size.height());
313 } 288 }
314 } 289 }
315 290
316 void DefaultHeaderPainter::UpdateSizeButtonImages() { 291 bool DefaultHeaderPainter::ShouldUseLightImages() {
James Cook 2015/02/17 22:16:55 Can you add a little test for this? It would be ni
benwells 2015/02/18 07:08:46 Done.
292 int luminance = color_utils::GetLuminanceForColor(
293 mode_ == MODE_INACTIVE ? inactive_frame_color_ : active_frame_color_);
294 return luminance < kMaxLuminanceForLightButtons;
295 }
296
297 void DefaultHeaderPainter::UpdateAllButtonImages() {
298 bool use_light_images = ShouldUseLightImages();
299 caption_button_container_->SetButtonImages(
300 CAPTION_BUTTON_ICON_MINIMIZE,
301 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_WHITE
302 : IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE,
303 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
304 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
305
306 UpdateSizeButtonImages(use_light_images);
307
308 caption_button_container_->SetButtonImages(
309 CAPTION_BUTTON_ICON_CLOSE,
310 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_WHITE
311 : IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
312 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
313 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
314
315 caption_button_container_->SetButtonImages(
316 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
317 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED_WHITE
318 : IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
319 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
320 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
321
322 caption_button_container_->SetButtonImages(
323 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
324 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED_WHITE
325 : IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
326 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
327 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
328 }
329
330 void DefaultHeaderPainter::UpdateSizeButtonImages(bool use_light_images) {
317 int icon_id = 0; 331 int icon_id = 0;
318 int inactive_icon_id = 0;
319 if (frame_->IsMaximized() || frame_->IsFullscreen()) { 332 if (frame_->IsMaximized() || frame_->IsFullscreen()) {
320 icon_id = IDR_AURA_WINDOW_CONTROL_ICON_RESTORE; 333 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RESTORE_WHITE
321 inactive_icon_id = IDR_AURA_WINDOW_CONTROL_ICON_RESTORE_I; 334 : IDR_AURA_WINDOW_CONTROL_ICON_RESTORE;
322 } else { 335 } else {
323 icon_id = IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE; 336 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE_WHITE
324 inactive_icon_id = IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE_I; 337 : IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE;
325 } 338 }
326 caption_button_container_->SetButtonImages( 339 caption_button_container_->SetButtonImages(
327 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, 340 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
328 icon_id, 341 icon_id,
329 inactive_icon_id,
330 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, 342 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
331 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); 343 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
332 } 344 }
333 345
334 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { 346 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const {
335 return gfx::Rect(view_->width(), height_); 347 return gfx::Rect(view_->width(), height_);
336 } 348 }
337 349
338 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { 350 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const {
339 return HeaderPainterUtil::GetTitleBounds( 351 return HeaderPainterUtil::GetTitleBounds(
340 left_header_view_, caption_button_container_, GetTitleFontList()); 352 left_header_view_, caption_button_container_, GetTitleFontList());
341 } 353 }
342 354
343 SkColor DefaultHeaderPainter::GetInactiveFrameColor() const { 355 SkColor DefaultHeaderPainter::GetInactiveFrameColor() const {
344 SkColor color = inactive_frame_color_; 356 SkColor color = inactive_frame_color_;
345 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) { 357 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) {
346 color = SkColorSetARGB(kInactiveFrameAlpha, 358 color = SkColorSetARGB(kInactiveFrameAlpha,
347 SkColorGetR(color), 359 SkColorGetR(color),
348 SkColorGetG(color), 360 SkColorGetG(color),
349 SkColorGetB(color)); 361 SkColorGetB(color));
350 } 362 }
351 return color; 363 return color;
352 } 364 }
353 365
354 } // namespace ash 366 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698