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/custom_frame_view_ash.h" | 5 #include "ash/wm/custom_frame_view_ash.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
9 #include "ash/wm/caption_buttons/frame_maximize_button.h" | 9 #include "ash/wm/caption_buttons/frame_maximize_button.h" |
10 #include "ash/wm/caption_buttons/frame_maximize_button_observer.h" | 10 #include "ash/wm/caption_buttons/frame_maximize_button_observer.h" |
| 11 #include "ash/wm/default_header_painter.h" |
11 #include "ash/wm/frame_border_hit_test_controller.h" | 12 #include "ash/wm/frame_border_hit_test_controller.h" |
12 #include "ash/wm/header_painter.h" | |
13 #include "ash/wm/immersive_fullscreen_controller.h" | 13 #include "ash/wm/immersive_fullscreen_controller.h" |
14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
15 #include "ash/wm/window_state_delegate.h" | 15 #include "ash/wm/window_state_delegate.h" |
16 #include "ash/wm/window_state_observer.h" | 16 #include "ash/wm/window_state_observer.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/debug/leak_annotations.h" | |
19 #include "grit/ash_resources.h" | |
20 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
21 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
22 #include "ui/aura/window_observer.h" | 20 #include "ui/aura/window_observer.h" |
23 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/font_list.h" | |
25 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/rect_conversions.h" | 23 #include "ui/gfx/rect_conversions.h" |
27 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
28 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
29 #include "ui/views/widget/native_widget_aura.h" | |
30 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
31 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
32 #include "ui/views/widget/widget_deletion_observer.h" | 28 #include "ui/views/widget/widget_deletion_observer.h" |
33 | 29 |
34 namespace { | 30 namespace { |
35 | 31 |
36 const gfx::FontList& GetTitleFontList() { | |
37 static const gfx::FontList* title_font_list = | |
38 new gfx::FontList(views::NativeWidgetAura::GetWindowTitleFontList()); | |
39 ANNOTATE_LEAKING_OBJECT_PTR(title_font_list); | |
40 return *title_font_list; | |
41 } | |
42 | |
43 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
44 // CustomFrameViewAshWindowStateDelegate | 33 // CustomFrameViewAshWindowStateDelegate |
45 | 34 |
46 // Handles a user's fullscreen request (Shift+F4/F4). Puts the window into | 35 // Handles a user's fullscreen request (Shift+F4/F4). Puts the window into |
47 // immersive fullscreen if immersive fullscreen is enabled for non-browser | 36 // immersive fullscreen if immersive fullscreen is enabled for non-browser |
48 // windows. | 37 // windows. |
49 class CustomFrameViewAshWindowStateDelegate | 38 class CustomFrameViewAshWindowStateDelegate |
50 : public ash::wm::WindowStateDelegate, | 39 : public ash::wm::WindowStateDelegate, |
51 public ash::wm::WindowStateObserver, | 40 public ash::wm::WindowStateObserver, |
52 public aura::WindowObserver { | 41 public aura::WindowObserver { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Returns the view's preferred height. | 144 // Returns the view's preferred height. |
156 int GetPreferredHeight() const; | 145 int GetPreferredHeight() const; |
157 | 146 |
158 // Returns the view's minimum width. | 147 // Returns the view's minimum width. |
159 int GetMinimumWidth() const; | 148 int GetMinimumWidth() const; |
160 | 149 |
161 // views::View overrides: | 150 // views::View overrides: |
162 virtual void Layout() OVERRIDE; | 151 virtual void Layout() OVERRIDE; |
163 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 152 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
164 | 153 |
165 HeaderPainter* header_painter() { | 154 FrameCaptionButtonContainerView* caption_button_container() { |
166 return header_painter_.get(); | 155 return caption_button_container_; |
167 } | 156 } |
168 | 157 |
169 private: | 158 private: |
170 // ImmersiveFullscreenController::Delegate overrides: | 159 // ImmersiveFullscreenController::Delegate overrides: |
171 virtual void OnImmersiveRevealStarted() OVERRIDE; | 160 virtual void OnImmersiveRevealStarted() OVERRIDE; |
172 virtual void OnImmersiveRevealEnded() OVERRIDE; | 161 virtual void OnImmersiveRevealEnded() OVERRIDE; |
173 virtual void OnImmersiveFullscreenExited() OVERRIDE; | 162 virtual void OnImmersiveFullscreenExited() OVERRIDE; |
174 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; | 163 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; |
175 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE; | 164 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE; |
176 | 165 |
177 // FrameMaximizeButtonObserver overrides: | 166 // FrameMaximizeButtonObserver overrides: |
178 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE; | 167 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE; |
179 | 168 |
180 // The widget that the caption buttons act on. | 169 // The widget that the caption buttons act on. |
181 views::Widget* frame_; | 170 views::Widget* frame_; |
182 | 171 |
183 // Helper for painting the header. | 172 // Helper for painting the header. |
184 scoped_ptr<HeaderPainter> header_painter_; | 173 scoped_ptr<DefaultHeaderPainter> header_painter_; |
185 | 174 |
186 // View which contains the window caption buttons. | 175 // View which contains the window caption buttons. |
187 FrameCaptionButtonContainerView* caption_button_container_; | 176 FrameCaptionButtonContainerView* caption_button_container_; |
188 | 177 |
189 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have | 178 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have |
190 // been already destroyed. | 179 // been already destroyed. |
191 views::Widget* maximize_bubble_; | 180 views::Widget* maximize_bubble_; |
192 | 181 |
193 // Keeps track of whether |maximize_bubble_| is still alive. | 182 // Keeps track of whether |maximize_bubble_| is still alive. |
194 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; | 183 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; |
195 | 184 |
196 // The fraction of the header's height which is visible while in fullscreen. | 185 // The fraction of the header's height which is visible while in fullscreen. |
197 // This value is meaningless when not in fullscreen. | 186 // This value is meaningless when not in fullscreen. |
198 double fullscreen_visible_fraction_; | 187 double fullscreen_visible_fraction_; |
199 | 188 |
200 DISALLOW_COPY_AND_ASSIGN(HeaderView); | 189 DISALLOW_COPY_AND_ASSIGN(HeaderView); |
201 }; | 190 }; |
202 | 191 |
203 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) | 192 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) |
204 : frame_(frame), | 193 : frame_(frame), |
205 header_painter_(new ash::HeaderPainter), | 194 header_painter_(new ash::DefaultHeaderPainter), |
206 caption_button_container_(NULL), | 195 caption_button_container_(NULL), |
207 maximize_bubble_(NULL), | 196 maximize_bubble_(NULL), |
208 fullscreen_visible_fraction_(0) { | 197 fullscreen_visible_fraction_(0) { |
209 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume | 198 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume |
210 // that the window frame can be minimized if it can be maximized. | 199 // that the window frame can be minimized if it can be maximized. |
211 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = | 200 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = |
212 frame_->widget_delegate()->CanMaximize() ? | 201 frame_->widget_delegate()->CanMaximize() ? |
213 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : | 202 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : |
214 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; | 203 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; |
215 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, | 204 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, |
216 minimize_allowed); | 205 minimize_allowed); |
217 AddChildView(caption_button_container_); | 206 AddChildView(caption_button_container_); |
218 FrameMaximizeButton* frame_maximize_button = | 207 FrameMaximizeButton* frame_maximize_button = |
219 caption_button_container_->GetOldStyleSizeButton(); | 208 caption_button_container_->GetOldStyleSizeButton(); |
220 if (frame_maximize_button) | 209 if (frame_maximize_button) |
221 frame_maximize_button->AddObserver(this); | 210 frame_maximize_button->AddObserver(this); |
222 | 211 |
223 header_painter_->Init(HeaderPainter::STYLE_OTHER, frame_, this, NULL, | 212 header_painter_->Init(frame_, this, NULL, caption_button_container_); |
224 caption_button_container_); | |
225 } | 213 } |
226 | 214 |
227 CustomFrameViewAsh::HeaderView::~HeaderView() { | 215 CustomFrameViewAsh::HeaderView::~HeaderView() { |
228 FrameMaximizeButton* frame_maximize_button = | 216 FrameMaximizeButton* frame_maximize_button = |
229 caption_button_container_->GetOldStyleSizeButton(); | 217 caption_button_container_->GetOldStyleSizeButton(); |
230 if (frame_maximize_button) | 218 if (frame_maximize_button) |
231 frame_maximize_button->RemoveObserver(this); | 219 frame_maximize_button->RemoveObserver(this); |
232 } | 220 } |
233 | 221 |
234 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { | 222 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { |
235 header_painter_->SchedulePaintForTitle(GetTitleFontList()); | 223 header_painter_->SchedulePaintForTitle(); |
236 } | 224 } |
237 | 225 |
238 void CustomFrameViewAsh::HeaderView::ResetWindowControls() { | 226 void CustomFrameViewAsh::HeaderView::ResetWindowControls() { |
239 caption_button_container_->ResetWindowControls(); | 227 caption_button_container_->ResetWindowControls(); |
240 } | 228 } |
241 | 229 |
242 int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const { | 230 int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const { |
243 if (frame_->IsFullscreen()) { | 231 if (frame_->IsFullscreen()) { |
244 return static_cast<int>( | 232 return static_cast<int>( |
245 GetPreferredHeight() * fullscreen_visible_fraction_); | 233 GetPreferredHeight() * fullscreen_visible_fraction_); |
246 } | 234 } |
247 return GetPreferredHeight(); | 235 return GetPreferredHeight(); |
248 } | 236 } |
249 | 237 |
250 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { | 238 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { |
251 // Reserve enough space to see the buttons and the separator line. | 239 return header_painter_->GetHeaderHeightForPainting(); |
252 return caption_button_container_->bounds().bottom() + | |
253 header_painter_->HeaderContentSeparatorSize(); | |
254 } | 240 } |
255 | 241 |
256 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { | 242 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { |
257 return header_painter_->GetMinimumHeaderWidth(); | 243 return header_painter_->GetMinimumHeaderWidth(); |
258 } | 244 } |
259 | 245 |
260 void CustomFrameViewAsh::HeaderView::Layout() { | 246 void CustomFrameViewAsh::HeaderView::Layout() { |
261 header_painter_->LayoutHeader(); | 247 header_painter_->LayoutHeader(); |
262 header_painter_->set_header_height(GetPreferredHeight()); | |
263 } | 248 } |
264 | 249 |
265 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { | 250 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { |
266 bool paint_as_active = | 251 bool paint_as_active = |
267 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); | 252 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); |
268 caption_button_container_->SetPaintAsActive(paint_as_active); | 253 caption_button_container_->SetPaintAsActive(paint_as_active); |
269 | 254 |
270 int theme_image_id = 0; | |
271 if (paint_as_active) | |
272 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | |
273 else | |
274 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; | |
275 | |
276 HeaderPainter::Mode header_mode = paint_as_active ? | 255 HeaderPainter::Mode header_mode = paint_as_active ? |
277 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; | 256 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; |
278 header_painter_->PaintHeader( | 257 header_painter_->PaintHeader(canvas, header_mode); |
279 canvas, | |
280 header_mode, | |
281 theme_image_id, | |
282 0); | |
283 header_painter_->PaintTitleBar(canvas, GetTitleFontList()); | |
284 header_painter_->PaintHeaderContentSeparator(canvas, header_mode); | |
285 } | 258 } |
286 | 259 |
287 void CustomFrameViewAsh::HeaderView::OnImmersiveRevealStarted() { | 260 void CustomFrameViewAsh::HeaderView::OnImmersiveRevealStarted() { |
288 fullscreen_visible_fraction_ = 0; | 261 fullscreen_visible_fraction_ = 0; |
289 SetPaintToLayer(true); | 262 SetPaintToLayer(true); |
290 SetFillsBoundsOpaquely(false); | 263 SetFillsBoundsOpaquely(false); |
291 parent()->Layout(); | 264 parent()->Layout(); |
292 } | 265 } |
293 | 266 |
294 void CustomFrameViewAsh::HeaderView::OnImmersiveRevealEnded() { | 267 void CustomFrameViewAsh::HeaderView::OnImmersiveRevealEnded() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 387 |
415 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( | 388 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( |
416 ImmersiveFullscreenController* immersive_fullscreen_controller) { | 389 ImmersiveFullscreenController* immersive_fullscreen_controller) { |
417 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); | 390 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); |
418 } | 391 } |
419 | 392 |
420 //////////////////////////////////////////////////////////////////////////////// | 393 //////////////////////////////////////////////////////////////////////////////// |
421 // CustomFrameViewAsh, views::NonClientFrameView overrides: | 394 // CustomFrameViewAsh, views::NonClientFrameView overrides: |
422 | 395 |
423 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { | 396 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { |
424 int top_height = NonClientTopBorderHeight(); | 397 gfx::Rect client_bounds = bounds(); |
425 return HeaderPainter::GetBoundsForClientView(top_height, bounds()); | 398 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
| 399 return client_bounds; |
426 } | 400 } |
427 | 401 |
428 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( | 402 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( |
429 const gfx::Rect& client_bounds) const { | 403 const gfx::Rect& client_bounds) const { |
430 int top_height = NonClientTopBorderHeight(); | 404 gfx::Rect window_bounds = client_bounds; |
431 return HeaderPainter::GetWindowBoundsForClientBounds(top_height, | 405 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); |
432 client_bounds); | 406 return window_bounds; |
433 } | 407 } |
434 | 408 |
435 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 409 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
436 return FrameBorderHitTestController::NonClientHitTest(this, | 410 return FrameBorderHitTestController::NonClientHitTest(this, |
437 header_view_->header_painter(), point); | 411 header_view_->caption_button_container(), point); |
438 } | 412 } |
439 | 413 |
440 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, | 414 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, |
441 gfx::Path* window_mask) { | 415 gfx::Path* window_mask) { |
442 // No window masks in Aura. | 416 // No window masks in Aura. |
443 } | 417 } |
444 | 418 |
445 void CustomFrameViewAsh::ResetWindowControls() { | 419 void CustomFrameViewAsh::ResetWindowControls() { |
446 header_view_->ResetWindowControls(); | 420 header_view_->ResetWindowControls(); |
447 } | 421 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } | 476 } |
503 | 477 |
504 //////////////////////////////////////////////////////////////////////////////// | 478 //////////////////////////////////////////////////////////////////////////////// |
505 // CustomFrameViewAsh, private: | 479 // CustomFrameViewAsh, private: |
506 | 480 |
507 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 481 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
508 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 482 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
509 } | 483 } |
510 | 484 |
511 } // namespace ash | 485 } // namespace ash |
OLD | NEW |