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

Side by Side Diff: ash/frame/header_painter.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
« no previous file with comments | « ash/frame/header_painter.h ('k') | ash/frame/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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/frame/header_painter.h"
6
7 #include <vector>
8
9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
10 #include "base/logging.h" // DCHECK
11 #include "grit/ash_resources.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkColor.h"
14 #include "third_party/skia/include/core/SkPaint.h"
15 #include "third_party/skia/include/core/SkPath.h"
16 #include "ui/aura/window.h"
17 #include "ui/base/hit_test.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/base/theme_provider.h"
20 #include "ui/gfx/animation/slide_animation.h"
21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/font_list.h"
23 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/skia_util.h"
25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h"
27
28 using aura::Window;
29 using views::Widget;
30
31 namespace {
32 // Space between left edge of window and popup window icon.
33 const int kIconOffsetX = 9;
34 // Height and width of window icon.
35 const int kIconSize = 16;
36 // Space between the title text and the caption buttons.
37 const int kTitleLogoSpacing = 5;
38 // Space between window icon and title text.
39 const int kTitleIconOffsetX = 5;
40 // Space between window edge and title text, when there is no icon.
41 const int kTitleNoIconOffsetX = 8;
42 // Color for the non-browser window title text.
43 const SkColor kWindowTitleTextColor = SkColorSetRGB(40, 40, 40);
44 // Color for the restored browser window title text.
45 const SkColor kRestoredBrowserWindowTitleTextColor = SkColorSetRGB(40, 40, 40);
46 // Color for the maximized browser window title text.
47 const SkColor kMaximizedBrowserWindowTitleTextColor = SK_ColorWHITE;
48 // Size of header/content separator line below the header image for non-browser
49 // windows.
50 const int kHeaderContentSeparatorSize = 1;
51 // Color of the active window header/content separator line for non-browser
52 // windows.
53 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(180, 180, 182);
54 // Color of the inactive window header/content separator line for non-browser
55 // windows.
56 const SkColor kHeaderContentSeparatorInactiveColor =
57 SkColorSetRGB(150, 150, 152);
58 // In the pre-Ash era the web content area had a frame along the left edge, so
59 // user-generated theme images for the new tab page assume they are shifted
60 // right relative to the header. Now that we have removed the left edge frame
61 // we need to copy the theme image for the window header from a few pixels
62 // inset to preserve alignment with the NTP image, or else we'll break a bunch
63 // of existing themes. We do something similar on OS X for the same reason.
64 const int kThemeFrameImageInsetX = 5;
65 // Duration of crossfade animation for activating and deactivating frame.
66 const int kActivationCrossfadeDurationMs = 200;
67
68 // Tiles an image into an area, rounding the top corners. Samples |image|
69 // starting |image_inset_x| pixels from the left of the image.
70 void TileRoundRect(gfx::Canvas* canvas,
71 const gfx::ImageSkia& image,
72 const SkPaint& paint,
73 const gfx::Rect& bounds,
74 int top_left_corner_radius,
75 int top_right_corner_radius,
76 int image_inset_x) {
77 SkRect rect = gfx::RectToSkRect(bounds);
78 const SkScalar kTopLeftRadius = SkIntToScalar(top_left_corner_radius);
79 const SkScalar kTopRightRadius = SkIntToScalar(top_right_corner_radius);
80 SkScalar radii[8] = {
81 kTopLeftRadius, kTopLeftRadius, // top-left
82 kTopRightRadius, kTopRightRadius, // top-right
83 0, 0, // bottom-right
84 0, 0}; // bottom-left
85 SkPath path;
86 path.addRoundRect(rect, radii, SkPath::kCW_Direction);
87 canvas->DrawImageInPath(image, -image_inset_x, 0, path, paint);
88 }
89
90 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top
91 // corners.
92 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas,
93 const gfx::ImageSkia* frame_image,
94 const gfx::ImageSkia* frame_overlay_image,
95 const SkPaint& paint,
96 const gfx::Rect& bounds,
97 int corner_radius,
98 int image_inset_x) {
99 SkXfermode::Mode normal_mode;
100 SkXfermode::AsMode(NULL, &normal_mode);
101
102 // If |paint| is using an unusual SkXfermode::Mode (this is the case while
103 // crossfading), we must create a new canvas to overlay |frame_image| and
104 // |frame_overlay_image| using |normal_mode| and then paint the result
105 // using the unusual mode. We try to avoid this because creating a new
106 // browser-width canvas is expensive.
107 bool fast_path = (!frame_overlay_image ||
108 SkXfermode::IsMode(paint.getXfermode(), normal_mode));
109 if (fast_path) {
110 TileRoundRect(canvas, *frame_image, paint, bounds, corner_radius,
111 corner_radius, image_inset_x);
112
113 if (frame_overlay_image) {
114 // Adjust |bounds| such that |frame_overlay_image| is not tiled.
115 gfx::Rect overlay_bounds = bounds;
116 overlay_bounds.Intersect(
117 gfx::Rect(bounds.origin(), frame_overlay_image->size()));
118 int top_left_corner_radius = corner_radius;
119 int top_right_corner_radius = corner_radius;
120 if (overlay_bounds.width() < bounds.width() - corner_radius)
121 top_right_corner_radius = 0;
122 TileRoundRect(canvas, *frame_overlay_image, paint, overlay_bounds,
123 top_left_corner_radius, top_right_corner_radius, 0);
124 }
125 } else {
126 gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false);
127 temporary_canvas.TileImageInt(*frame_image,
128 image_inset_x, 0,
129 0, 0,
130 bounds.width(), bounds.height());
131 temporary_canvas.DrawImageInt(*frame_overlay_image, 0, 0);
132 TileRoundRect(canvas, gfx::ImageSkia(temporary_canvas.ExtractImageRep()),
133 paint, bounds, corner_radius, corner_radius, 0);
134 }
135 }
136
137 } // namespace
138
139 namespace ash {
140
141 ///////////////////////////////////////////////////////////////////////////////
142 // HeaderPainter, public:
143
144 HeaderPainter::HeaderPainter()
145 : frame_(NULL),
146 header_view_(NULL),
147 window_icon_(NULL),
148 caption_button_container_(NULL),
149 header_height_(0),
150 previous_theme_frame_id_(0),
151 previous_theme_frame_overlay_id_(0),
152 crossfade_theme_frame_id_(0),
153 crossfade_theme_frame_overlay_id_(0) {}
154
155 HeaderPainter::~HeaderPainter() {
156 }
157
158 void HeaderPainter::Init(
159 Style style,
160 views::Widget* frame,
161 views::View* header_view,
162 views::View* window_icon,
163 FrameCaptionButtonContainerView* caption_button_container) {
164 DCHECK(frame);
165 DCHECK(header_view);
166 // window_icon may be NULL.
167 DCHECK(caption_button_container);
168 style_ = style;
169 frame_ = frame;
170 header_view_ = header_view;
171 window_icon_ = window_icon;
172 caption_button_container_ = caption_button_container;
173 }
174
175 // static
176 gfx::Rect HeaderPainter::GetBoundsForClientView(
177 int header_height,
178 const gfx::Rect& window_bounds) {
179 gfx::Rect client_bounds(window_bounds);
180 client_bounds.Inset(0, header_height, 0, 0);
181 return client_bounds;
182 }
183
184 // static
185 gfx::Rect HeaderPainter::GetWindowBoundsForClientBounds(
186 int header_height,
187 const gfx::Rect& client_bounds) {
188 gfx::Rect window_bounds(client_bounds);
189 window_bounds.Inset(0, -header_height, 0, 0);
190 return window_bounds;
191 }
192
193 int HeaderPainter::NonClientHitTest(const gfx::Point& point) const {
194 gfx::Point point_in_header_view(point);
195 views::View::ConvertPointFromWidget(header_view_, &point_in_header_view);
196 if (!GetHeaderLocalBounds().Contains(point_in_header_view))
197 return HTNOWHERE;
198 if (caption_button_container_->visible()) {
199 gfx::Point point_in_caption_button_container(point);
200 views::View::ConvertPointFromWidget(caption_button_container_,
201 &point_in_caption_button_container);
202 int component = caption_button_container_->NonClientHitTest(
203 point_in_caption_button_container);
204 if (component != HTNOWHERE)
205 return component;
206 }
207 // Caption is a safe default.
208 return HTCAPTION;
209 }
210
211 int HeaderPainter::GetMinimumHeaderWidth() const {
212 // Ensure we have enough space for the window icon and buttons. We allow
213 // the title string to collapse to zero width.
214 return GetTitleOffsetX() +
215 caption_button_container_->GetMinimumSize().width();
216 }
217
218 int HeaderPainter::GetRightInset() const {
219 return caption_button_container_->GetPreferredSize().width();
220 }
221
222 int HeaderPainter::GetThemeBackgroundXInset() const {
223 return kThemeFrameImageInsetX;
224 }
225
226 void HeaderPainter::PaintHeader(gfx::Canvas* canvas,
227 Mode mode,
228 int theme_frame_id,
229 int theme_frame_overlay_id) {
230 bool initial_paint = (previous_theme_frame_id_ == 0);
231 if (!initial_paint &&
232 (previous_theme_frame_id_ != theme_frame_id ||
233 previous_theme_frame_overlay_id_ != theme_frame_overlay_id)) {
234 aura::Window* parent = frame_->GetNativeWindow()->parent();
235 // Don't animate the header if the parent (a workspace) is already
236 // animating. Doing so results in continually painting during the animation
237 // and gives a slower frame rate.
238 // TODO(sky): expose a better way to determine this rather than assuming
239 // the parent is a workspace.
240 bool parent_animating = parent &&
241 (parent->layer()->GetAnimator()->IsAnimatingProperty(
242 ui::LayerAnimationElement::OPACITY) ||
243 parent->layer()->GetAnimator()->IsAnimatingProperty(
244 ui::LayerAnimationElement::VISIBILITY));
245 if (!parent_animating) {
246 crossfade_animation_.reset(new gfx::SlideAnimation(this));
247 crossfade_theme_frame_id_ = previous_theme_frame_id_;
248 crossfade_theme_frame_overlay_id_ = previous_theme_frame_overlay_id_;
249 crossfade_animation_->SetSlideDuration(kActivationCrossfadeDurationMs);
250 crossfade_animation_->Show();
251 } else {
252 crossfade_animation_.reset();
253 }
254 }
255
256 ui::ThemeProvider* theme_provider = frame_->GetThemeProvider();
257 gfx::ImageSkia* theme_frame = theme_provider->GetImageSkiaNamed(
258 theme_frame_id);
259 gfx::ImageSkia* theme_frame_overlay = NULL;
260 if (theme_frame_overlay_id != 0) {
261 theme_frame_overlay = theme_provider->GetImageSkiaNamed(
262 theme_frame_overlay_id);
263 }
264
265 int corner_radius = GetHeaderCornerRadius();
266 SkPaint paint;
267
268 if (crossfade_animation_.get() && crossfade_animation_->is_animating()) {
269 gfx::ImageSkia* crossfade_theme_frame =
270 theme_provider->GetImageSkiaNamed(crossfade_theme_frame_id_);
271 gfx::ImageSkia* crossfade_theme_frame_overlay = NULL;
272 if (crossfade_theme_frame_overlay_id_ != 0) {
273 crossfade_theme_frame_overlay = theme_provider->GetImageSkiaNamed(
274 crossfade_theme_frame_overlay_id_);
275 }
276 if (!crossfade_theme_frame ||
277 (crossfade_theme_frame_overlay_id_ != 0 &&
278 !crossfade_theme_frame_overlay)) {
279 // Reset the animation. This case occurs when the user switches the theme
280 // that they are using.
281 crossfade_animation_.reset();
282 } else {
283 int old_alpha = crossfade_animation_->CurrentValueBetween(255, 0);
284 int new_alpha = 255 - old_alpha;
285
286 // Draw the old header background, clipping the corners to be rounded.
287 paint.setAlpha(old_alpha);
288 paint.setXfermodeMode(SkXfermode::kPlus_Mode);
289 PaintFrameImagesInRoundRect(canvas,
290 crossfade_theme_frame,
291 crossfade_theme_frame_overlay,
292 paint,
293 GetHeaderLocalBounds(),
294 corner_radius,
295 GetThemeBackgroundXInset());
296
297 paint.setAlpha(new_alpha);
298 }
299 }
300
301 // Draw the header background, clipping the corners to be rounded.
302 PaintFrameImagesInRoundRect(canvas,
303 theme_frame,
304 theme_frame_overlay,
305 paint,
306 GetHeaderLocalBounds(),
307 corner_radius,
308 GetThemeBackgroundXInset());
309
310 previous_theme_frame_id_ = theme_frame_id;
311 previous_theme_frame_overlay_id_ = theme_frame_overlay_id;
312
313 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) {
314 if (style_ == STYLE_BROWSER) {
315 PaintHighlightForRestoredBrowserWindow(canvas);
316 } else {
317 if (mode == MODE_INACTIVE)
318 PaintHighlightForInactiveRestoredWindow(canvas);
319 }
320 }
321 }
322
323 void HeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas,
324 Mode mode) {
325 DCHECK_EQ(style_, STYLE_OTHER);
326 SkColor color = (mode == MODE_ACTIVE) ?
327 kHeaderContentSeparatorColor :
328 kHeaderContentSeparatorInactiveColor;
329
330 canvas->FillRect(gfx::Rect(0,
331 header_height_ - kHeaderContentSeparatorSize,
332 header_view_->width(),
333 kHeaderContentSeparatorSize),
334 color);
335 }
336
337 int HeaderPainter::HeaderContentSeparatorSize() const {
338 return kHeaderContentSeparatorSize;
339 }
340
341 void HeaderPainter::PaintTitleBar(gfx::Canvas* canvas,
342 const gfx::FontList& title_font_list) {
343 // The window icon is painted by its own views::View.
344 views::WidgetDelegate* delegate = frame_->widget_delegate();
345 if (delegate && delegate->ShouldShowWindowTitle()) {
346 gfx::Rect title_bounds = GetTitleBounds(title_font_list);
347 title_bounds.set_x(header_view_->GetMirroredXForRect(title_bounds));
348 SkColor title_color = kWindowTitleTextColor;
349 if (style_ == STYLE_BROWSER) {
350 title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
351 kMaximizedBrowserWindowTitleTextColor :
352 kRestoredBrowserWindowTitleTextColor;
353 }
354 canvas->DrawStringRectWithFlags(delegate->GetWindowTitle(),
355 title_font_list,
356 title_color,
357 title_bounds,
358 gfx::Canvas::NO_SUBPIXEL_RENDERING);
359 }
360 }
361
362 void HeaderPainter::LayoutHeader() {
363 // Purposefully set |header_height_| to an invalid value. We cannot use
364 // |header_height_| because the computation of |header_height_| may depend
365 // on having laid out the window controls.
366 header_height_ = -1;
367
368 UpdateCaptionButtonImages();
369 caption_button_container_->Layout();
370
371 gfx::Size caption_button_container_size =
372 caption_button_container_->GetPreferredSize();
373 caption_button_container_->SetBounds(
374 header_view_->width() - caption_button_container_size.width(),
375 0,
376 caption_button_container_size.width(),
377 caption_button_container_size.height());
378
379 if (window_icon_) {
380 // Vertically center the window icon with respect to the caption button
381 // container.
382 int icon_offset_y =
383 GetCaptionButtonContainerCenterY() - window_icon_->height() / 2;
384 window_icon_->SetBounds(kIconOffsetX, icon_offset_y, kIconSize, kIconSize);
385 }
386 }
387
388 void HeaderPainter::SchedulePaintForTitle(
389 const gfx::FontList& title_font_list) {
390 header_view_->SchedulePaintInRect(GetTitleBounds(title_font_list));
391 }
392
393 void HeaderPainter::OnThemeChanged() {
394 // We do not cache the images for |previous_theme_frame_id_| and
395 // |previous_theme_frame_overlay_id_|. Changing the theme changes the images
396 // returned from ui::ThemeProvider for |previous_theme_frame_id_|
397 // and |previous_theme_frame_overlay_id_|. Reset the image ids to prevent
398 // starting a crossfade animation with these images.
399 previous_theme_frame_id_ = 0;
400 previous_theme_frame_overlay_id_ = 0;
401
402 if (crossfade_animation_.get() && crossfade_animation_->is_animating()) {
403 crossfade_animation_.reset();
404 header_view_->SchedulePaintInRect(GetHeaderLocalBounds());
405 }
406 }
407
408 ///////////////////////////////////////////////////////////////////////////////
409 // gfx::AnimationDelegate overrides:
410
411 void HeaderPainter::AnimationProgressed(const gfx::Animation* animation) {
412 header_view_->SchedulePaintInRect(GetHeaderLocalBounds());
413 }
414
415 ///////////////////////////////////////////////////////////////////////////////
416 // HeaderPainter, private:
417
418 void HeaderPainter::PaintHighlightForRestoredBrowserWindow(
419 gfx::Canvas* canvas) {
420 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
421 gfx::ImageSkia top_left_corner = *rb.GetImageSkiaNamed(
422 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT);
423 gfx::ImageSkia top_right_corner = *rb.GetImageSkiaNamed(
424 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT);
425 gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed(
426 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP);
427 gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed(
428 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT);
429 gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed(
430 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT);
431
432 int top_left_width = top_left_corner.width();
433 int top_left_height = top_left_corner.height();
434 canvas->DrawImageInt(top_left_corner, 0, 0);
435
436 int top_right_width = top_right_corner.width();
437 int top_right_height = top_right_corner.height();
438 canvas->DrawImageInt(top_right_corner,
439 header_view_->width() - top_right_width,
440 0);
441
442 canvas->TileImageInt(
443 top_edge,
444 top_left_width,
445 0,
446 header_view_->width() - top_left_width - top_right_width,
447 top_edge.height());
448
449 canvas->TileImageInt(left_edge,
450 0,
451 top_left_height,
452 left_edge.width(),
453 header_height_ - top_left_height);
454
455 canvas->TileImageInt(right_edge,
456 header_view_->width() - right_edge.width(),
457 top_right_height,
458 right_edge.width(),
459 header_height_ - top_right_height);
460 }
461
462 void HeaderPainter::PaintHighlightForInactiveRestoredWindow(
463 gfx::Canvas* canvas) {
464 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
465 gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed(
466 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP);
467 gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed(
468 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT);
469 gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed(
470 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT);
471 gfx::ImageSkia bottom_edge = *rb.GetImageSkiaNamed(
472 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM);
473
474 int left_edge_width = left_edge.width();
475 int right_edge_width = right_edge.width();
476 canvas->DrawImageInt(left_edge, 0, 0);
477 canvas->DrawImageInt(right_edge, header_view_->width() - right_edge_width, 0);
478 canvas->TileImageInt(
479 top_edge,
480 left_edge_width,
481 0,
482 header_view_->width() - left_edge_width - right_edge_width,
483 top_edge.height());
484
485 DCHECK_EQ(left_edge.height(), right_edge.height());
486 int bottom = left_edge.height();
487 int bottom_height = bottom_edge.height();
488 canvas->TileImageInt(
489 bottom_edge,
490 left_edge_width,
491 bottom - bottom_height,
492 header_view_->width() - left_edge_width - right_edge_width,
493 bottom_height);
494 }
495
496 void HeaderPainter::UpdateCaptionButtonImages() {
497 if (style_ == STYLE_BROWSER) {
498 if (frame_->IsMaximized() || frame_->IsFullscreen()) {
499 caption_button_container_->SetButtonImages(
500 CAPTION_BUTTON_ICON_MINIMIZE,
501 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
502 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
503 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
504 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
505 caption_button_container_->SetButtonImages(
506 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
507 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
508 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE,
509 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
510 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
511 caption_button_container_->SetButtonImages(
512 CAPTION_BUTTON_ICON_CLOSE,
513 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
514 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE,
515 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
516 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
517 caption_button_container_->SetButtonImages(
518 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
519 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
520 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED,
521 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
522 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
523 caption_button_container_->SetButtonImages(
524 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
525 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
526 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED,
527 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
528 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P);
529 } else {
530 caption_button_container_->SetButtonImages(
531 CAPTION_BUTTON_ICON_MINIMIZE,
532 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
533 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE,
534 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
535 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
536 caption_button_container_->SetButtonImages(
537 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
538 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
539 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE,
540 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
541 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
542 caption_button_container_->SetButtonImages(
543 CAPTION_BUTTON_ICON_CLOSE,
544 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
545 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE,
546 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
547 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
548 caption_button_container_->SetButtonImages(
549 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
550 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
551 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED,
552 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
553 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
554 caption_button_container_->SetButtonImages(
555 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
556 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
557 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED,
558 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H,
559 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P);
560 }
561 } else {
562 caption_button_container_->SetButtonImages(
563 CAPTION_BUTTON_ICON_MINIMIZE,
564 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE,
565 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I,
566 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
567 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
568 caption_button_container_->SetButtonImages(
569 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
570 IDR_AURA_WINDOW_CONTROL_ICON_SIZE,
571 IDR_AURA_WINDOW_CONTROL_ICON_SIZE_I,
572 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
573 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
574 caption_button_container_->SetButtonImages(
575 CAPTION_BUTTON_ICON_CLOSE,
576 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
577 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_I,
578 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
579 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
580
581 // There is no dedicated icon for the snap-left and snap-right buttons
582 // when |frame_| is inactive because they should never be visible while
583 // |frame_| is inactive.
584 caption_button_container_->SetButtonImages(
585 CAPTION_BUTTON_ICON_LEFT_SNAPPED,
586 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
587 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED,
588 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
589 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
590 caption_button_container_->SetButtonImages(
591 CAPTION_BUTTON_ICON_RIGHT_SNAPPED,
592 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
593 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED,
594 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
595 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
596 }
597 }
598
599 gfx::Rect HeaderPainter::GetHeaderLocalBounds() const {
600 return gfx::Rect(header_view_->width(), header_height_);
601 }
602
603 int HeaderPainter::GetTitleOffsetX() const {
604 return window_icon_ ?
605 window_icon_->bounds().right() + kTitleIconOffsetX :
606 kTitleNoIconOffsetX;
607 }
608
609 int HeaderPainter::GetCaptionButtonContainerCenterY() const {
610 return caption_button_container_->y() +
611 caption_button_container_->height() / 2;
612 }
613
614 int HeaderPainter::GetHeaderCornerRadius() const {
615 bool square_corners = (frame_->IsMaximized() || frame_->IsFullscreen());
616 const int kCornerRadius = 2;
617 return square_corners ? 0 : kCornerRadius;
618 }
619
620 gfx::Rect HeaderPainter::GetTitleBounds(const gfx::FontList& title_font_list) {
621 int title_x = GetTitleOffsetX();
622 // Center the text with respect to the caption button container. This way it
623 // adapts to the caption button height and aligns exactly with the window
624 // icon. Don't use |window_icon_| for this computation as it may be NULL.
625 int title_y =
626 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2;
627 return gfx::Rect(
628 title_x,
629 std::max(0, title_y),
630 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x),
631 title_font_list.GetHeight());
632 }
633
634 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/header_painter.h ('k') | ash/frame/header_painter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698