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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 window_state_ = window_state; | 67 window_state_ = window_state; |
68 window_state_->AddObserver(this); | 68 window_state_->AddObserver(this); |
69 GetAuraWindow()->AddObserver(this); | 69 GetAuraWindow()->AddObserver(this); |
70 } | 70 } |
71 ~CustomFrameViewAshWindowStateDelegate() override { | 71 ~CustomFrameViewAshWindowStateDelegate() override { |
72 if (window_state_) { | 72 if (window_state_) { |
73 window_state_->RemoveObserver(this); | 73 window_state_->RemoveObserver(this); |
74 GetAuraWindow()->RemoveObserver(this); | 74 GetAuraWindow()->RemoveObserver(this); |
75 } | 75 } |
76 } | 76 } |
| 77 |
77 private: | 78 private: |
78 aura::Window* GetAuraWindow() { | 79 aura::Window* GetAuraWindow() { |
79 return ash::WmWindowAura::GetAuraWindow(window_state_->window()); | 80 return ash::WmWindowAura::GetAuraWindow(window_state_->window()); |
80 } | 81 } |
81 | 82 |
82 // Overridden from ash::wm::WindowStateDelegate: | 83 // Overridden from ash::wm::WindowStateDelegate: |
83 bool ToggleFullscreen(ash::wm::WindowState* window_state) override { | 84 bool ToggleFullscreen(ash::wm::WindowState* window_state) override { |
84 bool enter_fullscreen = !window_state->IsFullscreen(); | 85 bool enter_fullscreen = !window_state->IsFullscreen(); |
85 if (enter_fullscreen) { | 86 if (enter_fullscreen) { |
86 GetAuraWindow()->SetProperty(aura::client::kShowStateKey, | 87 GetAuraWindow()->SetProperty(aura::client::kShowStateKey, |
(...skipping 10 matching lines...) Expand all Loading... |
97 } | 98 } |
98 // Overridden from aura::WindowObserver: | 99 // Overridden from aura::WindowObserver: |
99 void OnWindowDestroying(aura::Window* window) override { | 100 void OnWindowDestroying(aura::Window* window) override { |
100 window_state_->RemoveObserver(this); | 101 window_state_->RemoveObserver(this); |
101 GetAuraWindow()->RemoveObserver(this); | 102 GetAuraWindow()->RemoveObserver(this); |
102 window_state_ = NULL; | 103 window_state_ = NULL; |
103 } | 104 } |
104 // Overridden from ash::wm::WindowStateObserver: | 105 // Overridden from ash::wm::WindowStateObserver: |
105 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, | 106 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, |
106 ash::wm::WindowStateType old_type) override { | 107 ash::wm::WindowStateType old_type) override { |
107 if (!window_state->IsFullscreen() && | 108 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && |
108 !window_state->IsMinimized() && | |
109 immersive_fullscreen_controller_.get() && | 109 immersive_fullscreen_controller_.get() && |
110 immersive_fullscreen_controller_->IsEnabled()) { | 110 immersive_fullscreen_controller_->IsEnabled()) { |
111 immersive_fullscreen_controller_->SetEnabled( | 111 immersive_fullscreen_controller_->SetEnabled( |
112 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, | 112 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, false); |
113 false); | |
114 } | 113 } |
115 } | 114 } |
116 | 115 |
117 ash::wm::WindowState* window_state_; | 116 ash::wm::WindowState* window_state_; |
118 std::unique_ptr<ash::ImmersiveFullscreenController> | 117 std::unique_ptr<ash::ImmersiveFullscreenController> |
119 immersive_fullscreen_controller_; | 118 immersive_fullscreen_controller_; |
120 | 119 |
121 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); | 120 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); |
122 }; | 121 }; |
123 | 122 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void ChildPreferredSizeChanged(views::View* child) override; | 165 void ChildPreferredSizeChanged(views::View* child) override; |
167 | 166 |
168 // ShellObserver: | 167 // ShellObserver: |
169 void OnMaximizeModeStarted() override; | 168 void OnMaximizeModeStarted() override; |
170 void OnMaximizeModeEnded() override; | 169 void OnMaximizeModeEnded() override; |
171 | 170 |
172 FrameCaptionButtonContainerView* caption_button_container() { | 171 FrameCaptionButtonContainerView* caption_button_container() { |
173 return caption_button_container_; | 172 return caption_button_container_; |
174 } | 173 } |
175 | 174 |
176 views::View* avatar_icon() const { | 175 views::View* avatar_icon() const { return avatar_icon_; } |
177 return avatar_icon_; | |
178 } | |
179 | 176 |
180 private: | 177 private: |
181 // ImmersiveFullscreenController::Delegate: | 178 // ImmersiveFullscreenController::Delegate: |
182 void OnImmersiveRevealStarted() override; | 179 void OnImmersiveRevealStarted() override; |
183 void OnImmersiveRevealEnded() override; | 180 void OnImmersiveRevealEnded() override; |
184 void OnImmersiveFullscreenExited() override; | 181 void OnImmersiveFullscreenExited() override; |
185 void SetVisibleFraction(double visible_fraction) override; | 182 void SetVisibleFraction(double visible_fraction) override; |
186 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; | 183 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; |
187 | 184 |
188 // The widget that the caption buttons act on. | 185 // The widget that the caption buttons act on. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { | 223 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { |
227 header_painter_->SchedulePaintForTitle(); | 224 header_painter_->SchedulePaintForTitle(); |
228 } | 225 } |
229 | 226 |
230 void CustomFrameViewAsh::HeaderView::ResetWindowControls() { | 227 void CustomFrameViewAsh::HeaderView::ResetWindowControls() { |
231 caption_button_container_->ResetWindowControls(); | 228 caption_button_container_->ResetWindowControls(); |
232 } | 229 } |
233 | 230 |
234 int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const { | 231 int CustomFrameViewAsh::HeaderView::GetPreferredOnScreenHeight() const { |
235 if (frame_->IsFullscreen()) { | 232 if (frame_->IsFullscreen()) { |
236 return static_cast<int>( | 233 return static_cast<int>(GetPreferredHeight() * |
237 GetPreferredHeight() * fullscreen_visible_fraction_); | 234 fullscreen_visible_fraction_); |
238 } | 235 } |
239 return GetPreferredHeight(); | 236 return GetPreferredHeight(); |
240 } | 237 } |
241 | 238 |
242 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { | 239 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { |
243 return header_painter_->GetHeaderHeightForPainting(); | 240 return header_painter_->GetHeaderHeightForPainting(); |
244 } | 241 } |
245 | 242 |
246 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { | 243 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { |
247 return header_painter_->GetMinimumHeaderWidth(); | 244 return header_painter_->GetMinimumHeaderWidth(); |
(...skipping 21 matching lines...) Expand all Loading... |
269 Layout(); | 266 Layout(); |
270 } | 267 } |
271 | 268 |
272 void CustomFrameViewAsh::HeaderView::SizeConstraintsChanged() { | 269 void CustomFrameViewAsh::HeaderView::SizeConstraintsChanged() { |
273 caption_button_container_->ResetWindowControls(); | 270 caption_button_container_->ResetWindowControls(); |
274 caption_button_container_->UpdateSizeButtonVisibility(); | 271 caption_button_container_->UpdateSizeButtonVisibility(); |
275 Layout(); | 272 Layout(); |
276 } | 273 } |
277 | 274 |
278 void CustomFrameViewAsh::HeaderView::SetFrameColors( | 275 void CustomFrameViewAsh::HeaderView::SetFrameColors( |
279 SkColor active_frame_color, SkColor inactive_frame_color) { | 276 SkColor active_frame_color, |
| 277 SkColor inactive_frame_color) { |
280 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color); | 278 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color); |
281 } | 279 } |
282 | 280 |
283 /////////////////////////////////////////////////////////////////////////////// | 281 /////////////////////////////////////////////////////////////////////////////// |
284 // CustomFrameViewAsh::HeaderView, views::View overrides: | 282 // CustomFrameViewAsh::HeaderView, views::View overrides: |
285 | 283 |
286 void CustomFrameViewAsh::HeaderView::Layout() { | 284 void CustomFrameViewAsh::HeaderView::Layout() { |
287 header_painter_->LayoutHeader(); | 285 header_painter_->LayoutHeader(); |
288 } | 286 } |
289 | 287 |
290 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { | 288 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { |
291 bool paint_as_active = | 289 bool paint_as_active = |
292 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); | 290 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); |
293 caption_button_container_->SetPaintAsActive(paint_as_active); | 291 caption_button_container_->SetPaintAsActive(paint_as_active); |
294 | 292 |
295 HeaderPainter::Mode header_mode = paint_as_active ? | 293 HeaderPainter::Mode header_mode = paint_as_active |
296 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; | 294 ? HeaderPainter::MODE_ACTIVE |
| 295 : HeaderPainter::MODE_INACTIVE; |
297 header_painter_->PaintHeader(canvas, header_mode); | 296 header_painter_->PaintHeader(canvas, header_mode); |
298 } | 297 } |
299 | 298 |
300 void CustomFrameViewAsh::HeaderView:: | 299 void CustomFrameViewAsh::HeaderView::ChildPreferredSizeChanged( |
301 ChildPreferredSizeChanged(views::View* child) { | 300 views::View* child) { |
302 // FrameCaptionButtonContainerView animates the visibility changes in | 301 // FrameCaptionButtonContainerView animates the visibility changes in |
303 // UpdateSizeButtonVisibility(false). Due to this a new size is not available | 302 // UpdateSizeButtonVisibility(false). Due to this a new size is not available |
304 // until the completion of the animation. Layout in response to the preferred | 303 // until the completion of the animation. Layout in response to the preferred |
305 // size changes. | 304 // size changes. |
306 if (child != caption_button_container_) | 305 if (child != caption_button_container_) |
307 return; | 306 return; |
308 parent()->Layout(); | 307 parent()->Layout(); |
309 } | 308 } |
310 | 309 |
311 /////////////////////////////////////////////////////////////////////////////// | 310 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 DISALLOW_COPY_AND_ASSIGN(OverlayView); | 388 DISALLOW_COPY_AND_ASSIGN(OverlayView); |
390 }; | 389 }; |
391 | 390 |
392 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) | 391 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) |
393 : header_view_(header_view) { | 392 : header_view_(header_view) { |
394 AddChildView(header_view); | 393 AddChildView(header_view); |
395 SetEventTargeter( | 394 SetEventTargeter( |
396 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 395 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
397 } | 396 } |
398 | 397 |
399 CustomFrameViewAsh::OverlayView::~OverlayView() { | 398 CustomFrameViewAsh::OverlayView::~OverlayView() {} |
400 } | |
401 | 399 |
402 /////////////////////////////////////////////////////////////////////////////// | 400 /////////////////////////////////////////////////////////////////////////////// |
403 // CustomFrameViewAsh::OverlayView, views::View overrides: | 401 // CustomFrameViewAsh::OverlayView, views::View overrides: |
404 | 402 |
405 void CustomFrameViewAsh::OverlayView::Layout() { | 403 void CustomFrameViewAsh::OverlayView::Layout() { |
406 // Layout |header_view_| because layout affects the result of | 404 // Layout |header_view_| because layout affects the result of |
407 // GetPreferredOnScreenHeight(). | 405 // GetPreferredOnScreenHeight(). |
408 header_view_->Layout(); | 406 header_view_->Layout(); |
409 | 407 |
410 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); | 408 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 444 |
447 // A delegate for a more complex way of fullscreening the window may already | 445 // A delegate for a more complex way of fullscreening the window may already |
448 // be set. This is the case for packaged apps. | 446 // be set. This is the case for packaged apps. |
449 wm::WindowState* window_state = wm::GetWindowState(frame->GetNativeWindow()); | 447 wm::WindowState* window_state = wm::GetWindowState(frame->GetNativeWindow()); |
450 if (!window_state->HasDelegate()) { | 448 if (!window_state->HasDelegate()) { |
451 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( | 449 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( |
452 new CustomFrameViewAshWindowStateDelegate(window_state, this))); | 450 new CustomFrameViewAshWindowStateDelegate(window_state, this))); |
453 } | 451 } |
454 } | 452 } |
455 | 453 |
456 CustomFrameViewAsh::~CustomFrameViewAsh() { | 454 CustomFrameViewAsh::~CustomFrameViewAsh() {} |
457 } | |
458 | 455 |
459 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( | 456 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( |
460 ImmersiveFullscreenController* immersive_fullscreen_controller) { | 457 ImmersiveFullscreenController* immersive_fullscreen_controller) { |
461 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); | 458 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); |
462 } | 459 } |
463 | 460 |
464 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, | 461 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, |
465 SkColor inactive_frame_color) { | 462 SkColor inactive_frame_color) { |
466 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); | 463 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); |
467 } | 464 } |
468 | 465 |
469 //////////////////////////////////////////////////////////////////////////////// | 466 //////////////////////////////////////////////////////////////////////////////// |
470 // CustomFrameViewAsh, views::NonClientFrameView overrides: | 467 // CustomFrameViewAsh, views::NonClientFrameView overrides: |
471 | 468 |
472 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { | 469 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { |
473 gfx::Rect client_bounds = bounds(); | 470 gfx::Rect client_bounds = bounds(); |
474 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | 471 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
475 return client_bounds; | 472 return client_bounds; |
476 } | 473 } |
477 | 474 |
478 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( | 475 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( |
479 const gfx::Rect& client_bounds) const { | 476 const gfx::Rect& client_bounds) const { |
480 gfx::Rect window_bounds = client_bounds; | 477 gfx::Rect window_bounds = client_bounds; |
481 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); | 478 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); |
482 return window_bounds; | 479 return window_bounds; |
483 } | 480 } |
484 | 481 |
485 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 482 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
486 return FrameBorderHitTestController::NonClientHitTest(this, | 483 return FrameBorderHitTestController::NonClientHitTest( |
487 header_view_->caption_button_container(), point); | 484 this, header_view_->caption_button_container(), point); |
488 } | 485 } |
489 | 486 |
490 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, | 487 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, |
491 gfx::Path* window_mask) { | 488 gfx::Path* window_mask) { |
492 // No window masks in Aura. | 489 // No window masks in Aura. |
493 } | 490 } |
494 | 491 |
495 void CustomFrameViewAsh::ResetWindowControls() { | 492 void CustomFrameViewAsh::ResetWindowControls() { |
496 header_view_->ResetWindowControls(); | 493 header_view_->ResetWindowControls(); |
497 } | 494 } |
498 | 495 |
499 void CustomFrameViewAsh::UpdateWindowIcon() { | 496 void CustomFrameViewAsh::UpdateWindowIcon() {} |
500 } | |
501 | 497 |
502 void CustomFrameViewAsh::UpdateWindowTitle() { | 498 void CustomFrameViewAsh::UpdateWindowTitle() { |
503 header_view_->SchedulePaintForTitle(); | 499 header_view_->SchedulePaintForTitle(); |
504 } | 500 } |
505 | 501 |
506 void CustomFrameViewAsh::SizeConstraintsChanged() { | 502 void CustomFrameViewAsh::SizeConstraintsChanged() { |
507 header_view_->SizeConstraintsChanged(); | 503 header_view_->SizeConstraintsChanged(); |
508 } | 504 } |
509 | 505 |
510 //////////////////////////////////////////////////////////////////////////////// | 506 //////////////////////////////////////////////////////////////////////////////// |
511 // CustomFrameViewAsh, views::View overrides: | 507 // CustomFrameViewAsh, views::View overrides: |
512 | 508 |
513 gfx::Size CustomFrameViewAsh::GetPreferredSize() const { | 509 gfx::Size CustomFrameViewAsh::GetPreferredSize() const { |
514 gfx::Size pref = frame_->client_view()->GetPreferredSize(); | 510 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
515 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 511 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
516 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 512 return frame_->non_client_view() |
517 bounds).size(); | 513 ->GetWindowBoundsForClientBounds(bounds) |
| 514 .size(); |
518 } | 515 } |
519 | 516 |
520 void CustomFrameViewAsh::Layout() { | 517 void CustomFrameViewAsh::Layout() { |
521 views::NonClientFrameView::Layout(); | 518 views::NonClientFrameView::Layout(); |
522 frame_->GetNativeWindow()->SetProperty(aura::client::kTopViewInset, | 519 frame_->GetNativeWindow()->SetProperty(aura::client::kTopViewInset, |
523 NonClientTopBorderHeight()); | 520 NonClientTopBorderHeight()); |
524 } | 521 } |
525 | 522 |
526 const char* CustomFrameViewAsh::GetClassName() const { | 523 const char* CustomFrameViewAsh::GetClassName() const { |
527 return kViewClassName; | 524 return kViewClassName; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 579 |
583 // views::NonClientFrameView: | 580 // views::NonClientFrameView: |
584 bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target, | 581 bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target, |
585 const gfx::Rect& rect) const { | 582 const gfx::Rect& rect) const { |
586 CHECK_EQ(target, this); | 583 CHECK_EQ(target, this); |
587 // NonClientView hit tests the NonClientFrameView first instead of going in | 584 // NonClientView hit tests the NonClientFrameView first instead of going in |
588 // z-order. Return false so that events get to the OverlayView. | 585 // z-order. Return false so that events get to the OverlayView. |
589 return false; | 586 return false; |
590 } | 587 } |
591 | 588 |
592 FrameCaptionButtonContainerView* CustomFrameViewAsh:: | 589 FrameCaptionButtonContainerView* |
593 GetFrameCaptionButtonContainerViewForTest() { | 590 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { |
594 return header_view_->caption_button_container(); | 591 return header_view_->caption_button_container(); |
595 } | 592 } |
596 | 593 |
597 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 594 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
598 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 595 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
599 } | 596 } |
600 | 597 |
601 } // namespace ash | 598 } // namespace ash |
OLD | NEW |