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