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

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

Issue 1505223004: Do not use assets for Ash window control button backgrounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WIP for pkasting and estade feedback Created 5 years 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 13 matching lines...) Expand all
24 #include "ui/views/widget/native_widget_aura.h" 24 #include "ui/views/widget/native_widget_aura.h"
25 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
27 27
28 using views::Widget; 28 using views::Widget;
29 29
30 namespace { 30 namespace {
31 31
32 // Color for the window title text. 32 // Color for the window title text.
33 const SkColor kTitleTextColor = SkColorSetRGB(40, 40, 40); 33 const SkColor kTitleTextColor = SkColorSetRGB(40, 40, 40);
34
34 // Color of the active window header/content separator line. 35 // Color of the active window header/content separator line.
35 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(150, 150, 152); 36 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(150, 150, 152);
37
36 // Color of the inactive window header/content separator line. 38 // Color of the inactive window header/content separator line.
37 const SkColor kHeaderContentSeparatorInactiveColor = 39 const SkColor kHeaderContentSeparatorInactiveColor =
38 SkColorSetRGB(180, 180, 182); 40 SkColorSetRGB(180, 180, 182);
41
39 // The default color of the frame. 42 // The default color of the frame.
40 const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242); 43 const SkColor kDefaultFrameColor = SkColorSetRGB(242, 242, 242);
44
41 // Duration of crossfade animation for activating and deactivating frame. 45 // Duration of crossfade animation for activating and deactivating frame.
42 const int kActivationCrossfadeDurationMs = 200; 46 const int kActivationCrossfadeDurationMs = 200;
47
43 // Luminance below which to use white caption buttons. 48 // Luminance below which to use white caption buttons.
44 const int kMaxLuminanceForLightButtons = 125; 49 const int kMaxLuminanceForLightButtons = 125;
45 50
51 // The dimensions of the control buttons used in the header.
52 const int kButtonWidth = 32;
53 const int kButtonHeight = 33;
tdanderson 2015/12/17 18:00:54 Peter, I'd like to not have these hard-coded here
Peter Kasting 2015/12/17 20:56:08 I would create a separate set of layout constants
tdanderson 2015/12/18 17:42:53 Done.
54
46 // Tiles an image into an area, rounding the top corners. 55 // Tiles an image into an area, rounding the top corners.
47 void TileRoundRect(gfx::Canvas* canvas, 56 void TileRoundRect(gfx::Canvas* canvas,
48 const SkPaint& paint, 57 const SkPaint& paint,
49 const gfx::Rect& bounds, 58 const gfx::Rect& bounds,
50 int corner_radius) { 59 int corner_radius) {
51 SkRect rect = gfx::RectToSkRect(bounds); 60 SkRect rect = gfx::RectToSkRect(bounds);
52 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius); 61 const SkScalar corner_radius_scalar = SkIntToScalar(corner_radius);
53 SkScalar radii[8] = { 62 SkScalar radii[8] = {
54 corner_radius_scalar, corner_radius_scalar, // top-left 63 corner_radius_scalar, corner_radius_scalar, // top-left
55 corner_radius_scalar, corner_radius_scalar, // top-right 64 corner_radius_scalar, corner_radius_scalar, // top-right
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void DefaultHeaderPainter::Init( 103 void DefaultHeaderPainter::Init(
95 views::Widget* frame, 104 views::Widget* frame,
96 views::View* header_view, 105 views::View* header_view,
97 FrameCaptionButtonContainerView* caption_button_container) { 106 FrameCaptionButtonContainerView* caption_button_container) {
98 DCHECK(frame); 107 DCHECK(frame);
99 DCHECK(header_view); 108 DCHECK(header_view);
100 DCHECK(caption_button_container); 109 DCHECK(caption_button_container);
101 frame_ = frame; 110 frame_ = frame;
102 view_ = header_view; 111 view_ = header_view;
103 caption_button_container_ = caption_button_container; 112 caption_button_container_ = caption_button_container;
113 caption_button_container_->SetButtonSize(
114 gfx::Size(kButtonWidth, kButtonHeight));
tdanderson 2015/12/17 18:00:54 Peter, WDYT about adding a GetLayoutSize() to the
Peter Kasting 2015/12/17 20:56:08 Seems fine to me.
tdanderson 2015/12/18 17:42:53 Acknowledged.
104 UpdateAllButtonImages(); 115 UpdateAllButtonImages();
105 } 116 }
106 117
107 int DefaultHeaderPainter::GetMinimumHeaderWidth() const { 118 int DefaultHeaderPainter::GetMinimumHeaderWidth() const {
108 // Ensure we have enough space for the window icon and buttons. We allow 119 // Ensure we have enough space for the window icon and buttons. We allow
109 // the title string to collapse to zero width. 120 // the title string to collapse to zero width.
110 return GetTitleBounds().x() + 121 return GetTitleBounds().x() +
111 caption_button_container_->GetMinimumSize().width(); 122 caption_button_container_->GetMinimumSize().width();
112 } 123 }
113 124
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 297 }
287 298
288 bool DefaultHeaderPainter::ShouldUseLightImages() { 299 bool DefaultHeaderPainter::ShouldUseLightImages() {
289 int luminance = color_utils::GetLuminanceForColor( 300 int luminance = color_utils::GetLuminanceForColor(
290 mode_ == MODE_INACTIVE ? inactive_frame_color_ : active_frame_color_); 301 mode_ == MODE_INACTIVE ? inactive_frame_color_ : active_frame_color_);
291 return luminance < kMaxLuminanceForLightButtons; 302 return luminance < kMaxLuminanceForLightButtons;
292 } 303 }
293 304
294 void DefaultHeaderPainter::UpdateAllButtonImages() { 305 void DefaultHeaderPainter::UpdateAllButtonImages() {
295 bool use_light_images = ShouldUseLightImages(); 306 bool use_light_images = ShouldUseLightImages();
296 caption_button_container_->SetButtonImages( 307 caption_button_container_->SetButtonImage(
297 CAPTION_BUTTON_ICON_MINIMIZE, 308 CAPTION_BUTTON_ICON_MINIMIZE,
298 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_WHITE 309 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_WHITE
299 : IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, 310 : IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE);
300 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
301 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
302 311
303 UpdateSizeButtonImages(use_light_images); 312 UpdateSizeButtonImages(use_light_images);
304 313
305 caption_button_container_->SetButtonImages( 314 caption_button_container_->SetButtonImage(
306 CAPTION_BUTTON_ICON_CLOSE, 315 CAPTION_BUTTON_ICON_CLOSE, use_light_images
307 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_WHITE 316 ? IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_WHITE
tdanderson 2015/12/17 18:00:54 Evan, if this CL landed as-is, am I leaving things
Evan Stade 2015/12/17 21:52:37 I can't see how this gets us any farther away from
tdanderson 2015/12/18 17:42:53 Acknowledged.
308 : IDR_AURA_WINDOW_CONTROL_ICON_CLOSE, 317 : IDR_AURA_WINDOW_CONTROL_ICON_CLOSE);
309 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
310 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
311 318
312 caption_button_container_->SetButtonImages( 319 caption_button_container_->SetButtonImage(
313 CAPTION_BUTTON_ICON_LEFT_SNAPPED, 320 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
314 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED_WHITE 321 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED_WHITE
315 : IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED, 322 : IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED);
316 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
317 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
318 323
319 caption_button_container_->SetButtonImages( 324 caption_button_container_->SetButtonImage(
320 CAPTION_BUTTON_ICON_RIGHT_SNAPPED, 325 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
321 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED_WHITE 326 use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED_WHITE
322 : IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED, 327 : IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED);
323 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
324 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
325 } 328 }
326 329
327 void DefaultHeaderPainter::UpdateSizeButtonImages(bool use_light_images) { 330 void DefaultHeaderPainter::UpdateSizeButtonImages(bool use_light_images) {
328 int icon_id = 0; 331 int icon_id = 0;
329 if (frame_->IsMaximized() || frame_->IsFullscreen()) { 332 if (frame_->IsMaximized() || frame_->IsFullscreen()) {
330 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RESTORE_WHITE 333 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_RESTORE_WHITE
331 : IDR_AURA_WINDOW_CONTROL_ICON_RESTORE; 334 : IDR_AURA_WINDOW_CONTROL_ICON_RESTORE;
332 } else { 335 } else {
333 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE_WHITE 336 icon_id = use_light_images ? IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE_WHITE
334 : IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE; 337 : IDR_AURA_WINDOW_CONTROL_ICON_MAXIMIZE;
335 } 338 }
336 caption_button_container_->SetButtonImages( 339 caption_button_container_->SetButtonImage(
337 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, 340 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, icon_id);
338 icon_id,
339 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
340 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
341 } 341 }
342 342
343 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { 343 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const {
344 return gfx::Rect(view_->width(), painted_height_); 344 return gfx::Rect(view_->width(), painted_height_);
345 } 345 }
346 346
347 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { 347 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const {
348 return HeaderPainterUtil::GetTitleBounds( 348 return HeaderPainterUtil::GetTitleBounds(
349 left_header_view_, caption_button_container_, GetTitleFontList()); 349 left_header_view_, caption_button_container_, GetTitleFontList());
350 } 350 }
351 351
352 bool DefaultHeaderPainter::UsesCustomFrameColors() const { 352 bool DefaultHeaderPainter::UsesCustomFrameColors() const {
353 return active_frame_color_ != kDefaultFrameColor || 353 return active_frame_color_ != kDefaultFrameColor ||
354 inactive_frame_color_ != kDefaultFrameColor; 354 inactive_frame_color_ != kDefaultFrameColor;
355 } 355 }
356 356
357 } // namespace ash 357 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698