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