OLD | NEW |
| (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/wm/header_painter.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "ash/wm/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-maximized window title text. | |
43 const SkColor kNonMaximizedWindowTitleTextColor = SkColorSetRGB(40, 40, 40); | |
44 // Color for the maximized window title text. | |
45 const SkColor kMaximizedWindowTitleTextColor = SK_ColorWHITE; | |
46 // Size of header/content separator line below the header image for non-browser | |
47 // windows. | |
48 const int kHeaderContentSeparatorSize = 1; | |
49 // Color of the active window header/content separator line for non-browser | |
50 // windows. | |
51 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(180, 180, 182); | |
52 // Color of the inactive window header/content separator line for non-browser | |
53 // windows. | |
54 const SkColor kHeaderContentSeparatorInactiveColor = | |
55 SkColorSetRGB(150, 150, 152); | |
56 // In the pre-Ash era the web content area had a frame along the left edge, so | |
57 // user-generated theme images for the new tab page assume they are shifted | |
58 // right relative to the header. Now that we have removed the left edge frame | |
59 // we need to copy the theme image for the window header from a few pixels | |
60 // inset to preserve alignment with the NTP image, or else we'll break a bunch | |
61 // of existing themes. We do something similar on OS X for the same reason. | |
62 const int kThemeFrameImageInsetX = 5; | |
63 // Duration of crossfade animation for activating and deactivating frame. | |
64 const int kActivationCrossfadeDurationMs = 200; | |
65 | |
66 // Tiles an image into an area, rounding the top corners. Samples |image| | |
67 // starting |image_inset_x| pixels from the left of the image. | |
68 void TileRoundRect(gfx::Canvas* canvas, | |
69 const gfx::ImageSkia& image, | |
70 const SkPaint& paint, | |
71 const gfx::Rect& bounds, | |
72 int top_left_corner_radius, | |
73 int top_right_corner_radius, | |
74 int image_inset_x) { | |
75 SkRect rect = gfx::RectToSkRect(bounds); | |
76 const SkScalar kTopLeftRadius = SkIntToScalar(top_left_corner_radius); | |
77 const SkScalar kTopRightRadius = SkIntToScalar(top_right_corner_radius); | |
78 SkScalar radii[8] = { | |
79 kTopLeftRadius, kTopLeftRadius, // top-left | |
80 kTopRightRadius, kTopRightRadius, // top-right | |
81 0, 0, // bottom-right | |
82 0, 0}; // bottom-left | |
83 SkPath path; | |
84 path.addRoundRect(rect, radii, SkPath::kCW_Direction); | |
85 canvas->DrawImageInPath(image, -image_inset_x, 0, path, paint); | |
86 } | |
87 | |
88 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top | |
89 // corners. | |
90 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, | |
91 const gfx::ImageSkia* frame_image, | |
92 const gfx::ImageSkia* frame_overlay_image, | |
93 const SkPaint& paint, | |
94 const gfx::Rect& bounds, | |
95 int corner_radius, | |
96 int image_inset_x) { | |
97 SkXfermode::Mode normal_mode; | |
98 SkXfermode::AsMode(NULL, &normal_mode); | |
99 | |
100 // If |paint| is using an unusual SkXfermode::Mode (this is the case while | |
101 // crossfading), we must create a new canvas to overlay |frame_image| and | |
102 // |frame_overlay_image| using |normal_mode| and then paint the result | |
103 // using the unusual mode. We try to avoid this because creating a new | |
104 // browser-width canvas is expensive. | |
105 bool fast_path = (!frame_overlay_image || | |
106 SkXfermode::IsMode(paint.getXfermode(), normal_mode)); | |
107 if (fast_path) { | |
108 TileRoundRect(canvas, *frame_image, paint, bounds, corner_radius, | |
109 corner_radius, image_inset_x); | |
110 | |
111 if (frame_overlay_image) { | |
112 // Adjust |bounds| such that |frame_overlay_image| is not tiled. | |
113 gfx::Rect overlay_bounds = bounds; | |
114 overlay_bounds.Intersect( | |
115 gfx::Rect(bounds.origin(), frame_overlay_image->size())); | |
116 int top_left_corner_radius = corner_radius; | |
117 int top_right_corner_radius = corner_radius; | |
118 if (overlay_bounds.width() < bounds.width() - corner_radius) | |
119 top_right_corner_radius = 0; | |
120 TileRoundRect(canvas, *frame_overlay_image, paint, overlay_bounds, | |
121 top_left_corner_radius, top_right_corner_radius, 0); | |
122 } | |
123 } else { | |
124 gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false); | |
125 temporary_canvas.TileImageInt(*frame_image, | |
126 image_inset_x, 0, | |
127 0, 0, | |
128 bounds.width(), bounds.height()); | |
129 temporary_canvas.DrawImageInt(*frame_overlay_image, 0, 0); | |
130 TileRoundRect(canvas, gfx::ImageSkia(temporary_canvas.ExtractImageRep()), | |
131 paint, bounds, corner_radius, corner_radius, 0); | |
132 } | |
133 } | |
134 | |
135 } // namespace | |
136 | |
137 namespace ash { | |
138 | |
139 /////////////////////////////////////////////////////////////////////////////// | |
140 // HeaderPainter, public: | |
141 | |
142 HeaderPainter::HeaderPainter() | |
143 : frame_(NULL), | |
144 header_view_(NULL), | |
145 window_icon_(NULL), | |
146 caption_button_container_(NULL), | |
147 header_height_(0), | |
148 previous_theme_frame_id_(0), | |
149 previous_theme_frame_overlay_id_(0), | |
150 crossfade_theme_frame_id_(0), | |
151 crossfade_theme_frame_overlay_id_(0) {} | |
152 | |
153 HeaderPainter::~HeaderPainter() { | |
154 } | |
155 | |
156 void HeaderPainter::Init( | |
157 Style style, | |
158 views::Widget* frame, | |
159 views::View* header_view, | |
160 views::View* window_icon, | |
161 FrameCaptionButtonContainerView* caption_button_container) { | |
162 DCHECK(frame); | |
163 DCHECK(header_view); | |
164 // window_icon may be NULL. | |
165 DCHECK(caption_button_container); | |
166 style_ = style; | |
167 frame_ = frame; | |
168 header_view_ = header_view; | |
169 window_icon_ = window_icon; | |
170 caption_button_container_ = caption_button_container; | |
171 } | |
172 | |
173 // static | |
174 gfx::Rect HeaderPainter::GetBoundsForClientView( | |
175 int header_height, | |
176 const gfx::Rect& window_bounds) { | |
177 gfx::Rect client_bounds(window_bounds); | |
178 client_bounds.Inset(0, header_height, 0, 0); | |
179 return client_bounds; | |
180 } | |
181 | |
182 // static | |
183 gfx::Rect HeaderPainter::GetWindowBoundsForClientBounds( | |
184 int header_height, | |
185 const gfx::Rect& client_bounds) { | |
186 gfx::Rect window_bounds(client_bounds); | |
187 window_bounds.Inset(0, -header_height, 0, 0); | |
188 if (window_bounds.y() < 0) | |
189 window_bounds.set_y(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 PaintBorder(canvas, mode); | |
314 } | |
315 | |
316 void HeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas, | |
317 Mode mode) { | |
318 DCHECK_EQ(style_, STYLE_OTHER); | |
319 SkColor color = (mode == MODE_ACTIVE) ? | |
320 kHeaderContentSeparatorColor : | |
321 kHeaderContentSeparatorInactiveColor; | |
322 | |
323 canvas->FillRect(gfx::Rect(0, | |
324 header_height_ - kHeaderContentSeparatorSize, | |
325 header_view_->width(), | |
326 kHeaderContentSeparatorSize), | |
327 color); | |
328 } | |
329 | |
330 int HeaderPainter::HeaderContentSeparatorSize() const { | |
331 return kHeaderContentSeparatorSize; | |
332 } | |
333 | |
334 void HeaderPainter::PaintTitleBar(gfx::Canvas* canvas, | |
335 const gfx::FontList& title_font_list) { | |
336 // The window icon is painted by its own views::View. | |
337 views::WidgetDelegate* delegate = frame_->widget_delegate(); | |
338 if (delegate && delegate->ShouldShowWindowTitle()) { | |
339 gfx::Rect title_bounds = GetTitleBounds(title_font_list); | |
340 title_bounds.set_x(header_view_->GetMirroredXForRect(title_bounds)); | |
341 SkColor title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ? | |
342 kMaximizedWindowTitleTextColor : kNonMaximizedWindowTitleTextColor; | |
343 canvas->DrawStringRectWithFlags(delegate->GetWindowTitle(), | |
344 title_font_list, | |
345 title_color, | |
346 title_bounds, | |
347 gfx::Canvas::NO_SUBPIXEL_RENDERING); | |
348 } | |
349 } | |
350 | |
351 void HeaderPainter::LayoutHeader() { | |
352 // Purposefully set |header_height_| to an invalid value. We cannot use | |
353 // |header_height_| because the computation of |header_height_| may depend | |
354 // on having laid out the window controls. | |
355 header_height_ = -1; | |
356 | |
357 UpdateCaptionButtonImages(); | |
358 caption_button_container_->Layout(); | |
359 | |
360 gfx::Size caption_button_container_size = | |
361 caption_button_container_->GetPreferredSize(); | |
362 caption_button_container_->SetBounds( | |
363 header_view_->width() - caption_button_container_size.width(), | |
364 0, | |
365 caption_button_container_size.width(), | |
366 caption_button_container_size.height()); | |
367 | |
368 if (window_icon_) { | |
369 // Vertically center the window icon with respect to the caption button | |
370 // container. | |
371 int icon_offset_y = | |
372 GetCaptionButtonContainerCenterY() - window_icon_->height() / 2; | |
373 window_icon_->SetBounds(kIconOffsetX, icon_offset_y, kIconSize, kIconSize); | |
374 } | |
375 } | |
376 | |
377 void HeaderPainter::SchedulePaintForTitle( | |
378 const gfx::FontList& title_font_list) { | |
379 header_view_->SchedulePaintInRect(GetTitleBounds(title_font_list)); | |
380 } | |
381 | |
382 void HeaderPainter::OnThemeChanged() { | |
383 // We do not cache the images for |previous_theme_frame_id_| and | |
384 // |previous_theme_frame_overlay_id_|. Changing the theme changes the images | |
385 // returned from ui::ThemeProvider for |previous_theme_frame_id_| | |
386 // and |previous_theme_frame_overlay_id_|. Reset the image ids to prevent | |
387 // starting a crossfade animation with these images. | |
388 previous_theme_frame_id_ = 0; | |
389 previous_theme_frame_overlay_id_ = 0; | |
390 | |
391 if (crossfade_animation_.get() && crossfade_animation_->is_animating()) { | |
392 crossfade_animation_.reset(); | |
393 header_view_->SchedulePaintInRect(GetHeaderLocalBounds()); | |
394 } | |
395 } | |
396 | |
397 /////////////////////////////////////////////////////////////////////////////// | |
398 // gfx::AnimationDelegate overrides: | |
399 | |
400 void HeaderPainter::AnimationProgressed(const gfx::Animation* animation) { | |
401 header_view_->SchedulePaintInRect(GetHeaderLocalBounds()); | |
402 } | |
403 | |
404 /////////////////////////////////////////////////////////////////////////////// | |
405 // HeaderPainter, private: | |
406 | |
407 void HeaderPainter::PaintBorder(gfx::Canvas* canvas, Mode mode) { | |
408 if (frame_->IsMaximized() || | |
409 frame_->IsFullscreen() || | |
410 (style_ == STYLE_OTHER && mode == MODE_ACTIVE)) { | |
411 return; | |
412 } | |
413 | |
414 gfx::ImageSkia top_left_corner; | |
415 gfx::ImageSkia top_right_corner; | |
416 gfx::ImageSkia top_edge; | |
417 gfx::ImageSkia left_edge; | |
418 gfx::ImageSkia right_edge; | |
419 gfx::ImageSkia bottom_edge; | |
420 | |
421 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
422 if (style_ == STYLE_BROWSER) { | |
423 top_left_corner = *rb.GetImageSkiaNamed( | |
424 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT); | |
425 top_right_corner = *rb.GetImageSkiaNamed( | |
426 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT); | |
427 top_edge = *rb.GetImageSkiaNamed(IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP); | |
428 left_edge = *rb.GetImageSkiaNamed( | |
429 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT); | |
430 right_edge = *rb.GetImageSkiaNamed( | |
431 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT); | |
432 } else { | |
433 top_edge = *rb.GetImageSkiaNamed( | |
434 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP); | |
435 left_edge = *rb.GetImageSkiaNamed( | |
436 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT); | |
437 right_edge = *rb.GetImageSkiaNamed( | |
438 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT); | |
439 bottom_edge = *rb.GetImageSkiaNamed( | |
440 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM); | |
441 } | |
442 | |
443 DCHECK(!top_edge.isNull()); | |
444 DCHECK(!left_edge.isNull()); | |
445 DCHECK(!right_edge.isNull()); | |
446 | |
447 int top_left_width = top_left_corner.width(); | |
448 int top_left_height = top_left_corner.height(); | |
449 if (!top_left_corner.isNull()) { | |
450 canvas->DrawImageInt(top_left_corner, 0, 0); | |
451 } | |
452 | |
453 int top_right_height = top_right_corner.height(); | |
454 if (!top_right_corner.isNull()) { | |
455 canvas->DrawImageInt(top_right_corner, | |
456 header_view_->width() - top_right_corner.width(), | |
457 top_right_height); | |
458 } | |
459 | |
460 canvas->TileImageInt(top_edge, | |
461 top_left_width, | |
462 0, | |
463 header_view_->width() - top_left_width - top_right_corner.width(), | |
464 top_edge.height()); | |
465 | |
466 // TODO(pkotwicz): Compute |bottom| more accurately. The computation is | |
467 // inaccurate for browser windows. | |
468 int bottom = header_height_ - kHeaderContentSeparatorSize; | |
469 int bottom_height = bottom_edge.height(); | |
470 if (!bottom_edge.isNull()) { | |
471 canvas->TileImageInt(bottom_edge, | |
472 0, bottom - bottom_height, | |
473 header_view_->width(), bottom_height); | |
474 } | |
475 | |
476 int left_edge_height = bottom - bottom_height - top_left_height; | |
477 canvas->TileImageInt(left_edge, | |
478 0, top_left_height, | |
479 left_edge.width(), left_edge_height); | |
480 | |
481 int right_edge_height = bottom - bottom_height - top_right_height; | |
482 canvas->TileImageInt(right_edge, | |
483 header_view_->width() - right_edge.width(), | |
484 top_right_height, | |
485 right_edge.width(), | |
486 right_edge_height); | |
487 } | |
488 | |
489 void HeaderPainter::UpdateCaptionButtonImages() { | |
490 if (style_ == STYLE_BROWSER) { | |
491 if (frame_->IsMaximized() || frame_->IsFullscreen()) { | |
492 caption_button_container_->SetButtonImages( | |
493 CAPTION_BUTTON_ICON_MINIMIZE, | |
494 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE, | |
495 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE, | |
496 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, | |
497 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P); | |
498 caption_button_container_->SetButtonImages( | |
499 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, | |
500 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE, | |
501 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_SIZE, | |
502 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, | |
503 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P); | |
504 caption_button_container_->SetButtonImages( | |
505 CAPTION_BUTTON_ICON_CLOSE, | |
506 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE, | |
507 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_CLOSE, | |
508 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, | |
509 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P); | |
510 caption_button_container_->SetButtonImages( | |
511 CAPTION_BUTTON_ICON_LEFT_SNAPPED, | |
512 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED, | |
513 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_LEFT_SNAPPED, | |
514 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, | |
515 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P); | |
516 caption_button_container_->SetButtonImages( | |
517 CAPTION_BUTTON_ICON_RIGHT_SNAPPED, | |
518 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED, | |
519 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_RIGHT_SNAPPED, | |
520 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, | |
521 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_P); | |
522 } else { | |
523 caption_button_container_->SetButtonImages( | |
524 CAPTION_BUTTON_ICON_MINIMIZE, | |
525 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE, | |
526 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_MINIMIZE, | |
527 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H, | |
528 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P); | |
529 caption_button_container_->SetButtonImages( | |
530 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, | |
531 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE, | |
532 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_SIZE, | |
533 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H, | |
534 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P); | |
535 caption_button_container_->SetButtonImages( | |
536 CAPTION_BUTTON_ICON_CLOSE, | |
537 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE, | |
538 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_CLOSE, | |
539 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H, | |
540 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P); | |
541 caption_button_container_->SetButtonImages( | |
542 CAPTION_BUTTON_ICON_LEFT_SNAPPED, | |
543 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED, | |
544 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_LEFT_SNAPPED, | |
545 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H, | |
546 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P); | |
547 caption_button_container_->SetButtonImages( | |
548 CAPTION_BUTTON_ICON_RIGHT_SNAPPED, | |
549 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED, | |
550 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_RESTORED_RIGHT_SNAPPED, | |
551 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_H, | |
552 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_RESTORED_P); | |
553 } | |
554 } else { | |
555 caption_button_container_->SetButtonImages( | |
556 CAPTION_BUTTON_ICON_MINIMIZE, | |
557 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, | |
558 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, | |
559 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | |
560 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | |
561 caption_button_container_->SetButtonImages( | |
562 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, | |
563 IDR_AURA_WINDOW_CONTROL_ICON_SIZE, | |
564 IDR_AURA_WINDOW_CONTROL_ICON_SIZE_I, | |
565 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | |
566 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | |
567 caption_button_container_->SetButtonImages( | |
568 CAPTION_BUTTON_ICON_CLOSE, | |
569 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE, | |
570 IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_I, | |
571 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | |
572 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | |
573 | |
574 // There is no dedicated icon for the snap-left and snap-right buttons | |
575 // when |frame_| is inactive because they should never be visible while | |
576 // |frame_| is inactive. | |
577 caption_button_container_->SetButtonImages( | |
578 CAPTION_BUTTON_ICON_LEFT_SNAPPED, | |
579 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED, | |
580 IDR_AURA_WINDOW_CONTROL_ICON_LEFT_SNAPPED, | |
581 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | |
582 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | |
583 caption_button_container_->SetButtonImages( | |
584 CAPTION_BUTTON_ICON_RIGHT_SNAPPED, | |
585 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED, | |
586 IDR_AURA_WINDOW_CONTROL_ICON_RIGHT_SNAPPED, | |
587 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | |
588 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | |
589 } | |
590 } | |
591 | |
592 gfx::Rect HeaderPainter::GetHeaderLocalBounds() const { | |
593 return gfx::Rect(header_view_->width(), header_height_); | |
594 } | |
595 | |
596 int HeaderPainter::GetTitleOffsetX() const { | |
597 return window_icon_ ? | |
598 window_icon_->bounds().right() + kTitleIconOffsetX : | |
599 kTitleNoIconOffsetX; | |
600 } | |
601 | |
602 int HeaderPainter::GetCaptionButtonContainerCenterY() const { | |
603 return caption_button_container_->y() + | |
604 caption_button_container_->height() / 2; | |
605 } | |
606 | |
607 int HeaderPainter::GetHeaderCornerRadius() const { | |
608 bool square_corners = (frame_->IsMaximized() || frame_->IsFullscreen()); | |
609 const int kCornerRadius = 2; | |
610 return square_corners ? 0 : kCornerRadius; | |
611 } | |
612 | |
613 gfx::Rect HeaderPainter::GetTitleBounds(const gfx::FontList& title_font_list) { | |
614 int title_x = GetTitleOffsetX(); | |
615 // Center the text with respect to the caption button container. This way it | |
616 // adapts to the caption button height and aligns exactly with the window | |
617 // icon. Don't use |window_icon_| for this computation as it may be NULL. | |
618 int title_y = | |
619 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2; | |
620 return gfx::Rect( | |
621 title_x, | |
622 std::max(0, title_y), | |
623 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), | |
624 title_font_list.GetHeight()); | |
625 } | |
626 | |
627 } // namespace ash | |
OLD | NEW |