OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/frame_painter.h" | 5 #include "ash/wm/frame_painter.h" |
6 | 6 |
7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const int kCloseButtonOffsetY = 0; | 69 const int kCloseButtonOffsetY = 0; |
70 // The size and close buttons are designed to slightly overlap in order | 70 // The size and close buttons are designed to slightly overlap in order |
71 // to do fancy hover highlighting. | 71 // to do fancy hover highlighting. |
72 const int kButtonOverlap = 1; | 72 const int kButtonOverlap = 1; |
73 // In the pre-Ash era the web content area had a frame along the left edge, so | 73 // In the pre-Ash era the web content area had a frame along the left edge, so |
74 // user-generated theme images for the new tab page assume they are shifted | 74 // user-generated theme images for the new tab page assume they are shifted |
75 // right relative to the header. Now that we have removed the left edge frame | 75 // right relative to the header. Now that we have removed the left edge frame |
76 // we need to copy the theme image for the window header from a few pixels | 76 // we need to copy the theme image for the window header from a few pixels |
77 // inset to preserve alignment with the NTP image, or else we'll break a bunch | 77 // inset to preserve alignment with the NTP image, or else we'll break a bunch |
78 // of existing themes. We do something similar on OS X for the same reason. | 78 // of existing themes. We do something similar on OS X for the same reason. |
79 const int kThemeFrameImageOffsetX = 5; | 79 const int kThemeFrameImageInsetX = 5; |
80 // Duration of crossfade animation for activating and deactivating frame. | 80 // Duration of crossfade animation for activating and deactivating frame. |
81 const int kActivationCrossfadeDurationMs = 200; | 81 const int kActivationCrossfadeDurationMs = 200; |
82 // Alpha/opacity value for fully-opaque headers. | 82 // Alpha/opacity value for fully-opaque headers. |
83 const int kFullyOpaque = 255; | 83 const int kFullyOpaque = 255; |
84 | 84 |
85 // Tiles an image into an area, rounding the top corners. Samples the |bitmap| | 85 // Tiles an image into an area, rounding the top corners. Samples the |bitmap| |
86 // starting |bitmap_offset_x| pixels from the left of the image. | 86 // starting |bitmap_offset_x| pixels from the left of the image. |
87 void TileRoundRect(gfx::Canvas* canvas, | 87 void TileRoundRect(gfx::Canvas* canvas, |
88 int x, int y, int w, int h, | 88 int x, int y, int w, int h, |
89 const SkPaint& paint, | 89 const SkPaint& paint, |
90 const gfx::ImageSkia& image, | 90 const gfx::ImageSkia& image, |
91 int corner_radius, | 91 int corner_radius, |
92 int image_offset_x) { | 92 int image_inset_x) { |
93 // To get the shader to sample the image |inset_y| pixels in but tile across | 93 // To get the shader to sample the image |inset_y| pixels in but tile across |
94 // the whole image, we adjust the target rectangle for the shader to the right | 94 // the whole image, we adjust the target rectangle for the shader to the right |
95 // and translate the canvas left to compensate. | 95 // and translate the canvas left to compensate. |
96 SkRect rect; | 96 SkRect rect; |
97 rect.iset(x, y, x + w, y + h); | 97 rect.iset(x, y, x + w, y + h); |
98 const SkScalar kRadius = SkIntToScalar(corner_radius); | 98 const SkScalar kRadius = SkIntToScalar(corner_radius); |
99 SkScalar radii[8] = { | 99 SkScalar radii[8] = { |
100 kRadius, kRadius, // top-left | 100 kRadius, kRadius, // top-left |
101 kRadius, kRadius, // top-right | 101 kRadius, kRadius, // top-right |
102 0, 0, // bottom-right | 102 0, 0, // bottom-right |
103 0, 0}; // bottom-left | 103 0, 0}; // bottom-left |
104 SkPath path; | 104 SkPath path; |
105 path.addRoundRect(rect, radii, SkPath::kCW_Direction); | 105 path.addRoundRect(rect, radii, SkPath::kCW_Direction); |
106 canvas->DrawImageInPath(image, -image_offset_x, 0, path, paint); | 106 canvas->DrawImageInPath(image, -image_inset_x, 0, path, paint); |
107 } | 107 } |
108 | 108 |
109 // Returns true if |window| is a visible, normal window. | 109 // Returns true if |window| is a visible, normal window. |
110 bool IsVisibleNormalWindow(aura::Window* window) { | 110 bool IsVisibleNormalWindow(aura::Window* window) { |
111 // We must use TargetVisibility() because windows animate in and out and | 111 // We must use TargetVisibility() because windows animate in and out and |
112 // IsVisible() also tracks the layer visibility state. | 112 // IsVisible() also tracks the layer visibility state. |
113 return window && | 113 return window && |
114 window->TargetVisibility() && | 114 window->TargetVisibility() && |
115 (window->type() == aura::client::WINDOW_TYPE_NORMAL || | 115 (window->type() == aura::client::WINDOW_TYPE_NORMAL || |
116 window->type() == aura::client::WINDOW_TYPE_PANEL); | 116 window->type() == aura::client::WINDOW_TYPE_PANEL); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return min_size; | 294 return min_size; |
295 } | 295 } |
296 | 296 |
297 int FramePainter::GetRightInset() const { | 297 int FramePainter::GetRightInset() const { |
298 gfx::Size close_size = close_button_->GetPreferredSize(); | 298 gfx::Size close_size = close_button_->GetPreferredSize(); |
299 gfx::Size size_button_size = size_button_->GetPreferredSize(); | 299 gfx::Size size_button_size = size_button_->GetPreferredSize(); |
300 return close_size.width() + kCloseButtonOffsetX + size_button_size.width() - | 300 return close_size.width() + kCloseButtonOffsetX + size_button_size.width() - |
301 kButtonOverlap; | 301 kButtonOverlap; |
302 } | 302 } |
303 | 303 |
| 304 int FramePainter::GetThemeBackgroundXInset() const { |
| 305 return kThemeFrameImageInsetX; |
| 306 } |
| 307 |
304 void FramePainter::PaintHeader(views::NonClientFrameView* view, | 308 void FramePainter::PaintHeader(views::NonClientFrameView* view, |
305 gfx::Canvas* canvas, | 309 gfx::Canvas* canvas, |
306 HeaderMode header_mode, | 310 HeaderMode header_mode, |
307 int theme_frame_id, | 311 int theme_frame_id, |
308 const gfx::ImageSkia* theme_frame_overlay) { | 312 const gfx::ImageSkia* theme_frame_overlay) { |
309 if (previous_theme_frame_id_ != 0 && | 313 if (previous_theme_frame_id_ != 0 && |
310 previous_theme_frame_id_ != theme_frame_id) { | 314 previous_theme_frame_id_ != theme_frame_id) { |
311 crossfade_animation_.reset(new ui::SlideAnimation(this)); | 315 crossfade_animation_.reset(new ui::SlideAnimation(this)); |
312 crossfade_theme_frame_id_ = previous_theme_frame_id_; | 316 crossfade_theme_frame_id_ = previous_theme_frame_id_; |
313 crossfade_opacity_ = previous_opacity_; | 317 crossfade_opacity_ = previous_opacity_; |
(...skipping 20 matching lines...) Expand all Loading... |
334 int new_alpha = current_value * opacity; | 338 int new_alpha = current_value * opacity; |
335 | 339 |
336 // Draw the old header background, clipping the corners to be rounded. | 340 // Draw the old header background, clipping the corners to be rounded. |
337 paint.setAlpha(old_alpha); | 341 paint.setAlpha(old_alpha); |
338 paint.setXfermodeMode(SkXfermode::kPlus_Mode); | 342 paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
339 TileRoundRect(canvas, | 343 TileRoundRect(canvas, |
340 0, 0, view->width(), theme_frame->height(), | 344 0, 0, view->width(), theme_frame->height(), |
341 paint, | 345 paint, |
342 *crossfade_theme_frame, | 346 *crossfade_theme_frame, |
343 kCornerRadius, | 347 kCornerRadius, |
344 kThemeFrameImageOffsetX); | 348 GetThemeBackgroundXInset()); |
345 | 349 |
346 paint.setAlpha(new_alpha); | 350 paint.setAlpha(new_alpha); |
347 } else { | 351 } else { |
348 crossfade_animation_.reset(); | 352 crossfade_animation_.reset(); |
349 paint.setAlpha(opacity); | 353 paint.setAlpha(opacity); |
350 } | 354 } |
351 } else { | 355 } else { |
352 paint.setAlpha(opacity); | 356 paint.setAlpha(opacity); |
353 } | 357 } |
354 | 358 |
355 // Draw the header background, clipping the corners to be rounded. | 359 // Draw the header background, clipping the corners to be rounded. |
356 TileRoundRect(canvas, | 360 TileRoundRect(canvas, |
357 0, 0, view->width(), theme_frame->height(), | 361 0, 0, view->width(), theme_frame->height(), |
358 paint, | 362 paint, |
359 *theme_frame, | 363 *theme_frame, |
360 kCornerRadius, | 364 kCornerRadius, |
361 kThemeFrameImageOffsetX); | 365 GetThemeBackgroundXInset()); |
362 | 366 |
363 previous_theme_frame_id_ = theme_frame_id; | 367 previous_theme_frame_id_ = theme_frame_id; |
364 previous_opacity_ = opacity; | 368 previous_opacity_ = opacity; |
365 | 369 |
366 // Draw the theme frame overlay, if available. | 370 // Draw the theme frame overlay, if available. |
367 if (theme_frame_overlay) | 371 if (theme_frame_overlay) |
368 canvas->DrawImageInt(*theme_frame_overlay, 0, 0); | 372 canvas->DrawImageInt(*theme_frame_overlay, 0, 0); |
369 | 373 |
370 // Separator between the maximize and close buttons. It overlaps the left | 374 // Separator between the maximize and close buttons. It overlaps the left |
371 // edge of the close button. | 375 // edge of the close button. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 for (std::set<FramePainter*>::const_iterator it = instances_->begin(); | 625 for (std::set<FramePainter*>::const_iterator it = instances_->begin(); |
622 it != instances_->end(); | 626 it != instances_->end(); |
623 ++it) { | 627 ++it) { |
624 FramePainter* painter = *it; | 628 FramePainter* painter = *it; |
625 if (IsVisibleNormalWindow(painter->window_)) | 629 if (IsVisibleNormalWindow(painter->window_)) |
626 painter->frame_->non_client_view()->SchedulePaint(); | 630 painter->frame_->non_client_view()->SchedulePaint(); |
627 } | 631 } |
628 } | 632 } |
629 | 633 |
630 } // namespace ash | 634 } // namespace ash |
OLD | NEW |