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

Powered by Google App Engine
This is Rietveld 408576698