| 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/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 // Add a window state observer to exit fullscreen properly in case | 60 // Add a window state observer to exit fullscreen properly in case |
| 61 // fullscreen is exited without going through | 61 // fullscreen is exited without going through |
| 62 // WindowState::ToggleFullscreen(). This is the case when exiting | 62 // WindowState::ToggleFullscreen(). This is the case when exiting |
| 63 // immersive fullscreen via the "Restore" window control. | 63 // immersive fullscreen via the "Restore" window control. |
| 64 // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 | 64 // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 |
| 65 window_state_ = window_state; | 65 window_state_ = window_state; |
| 66 window_state_->AddObserver(this); | 66 window_state_->AddObserver(this); |
| 67 window_state_->window()->AddObserver(this); | 67 window_state_->window()->AddObserver(this); |
| 68 } | 68 } |
| 69 virtual ~CustomFrameViewAshWindowStateDelegate() { | 69 ~CustomFrameViewAshWindowStateDelegate() override { |
| 70 if (window_state_) { | 70 if (window_state_) { |
| 71 window_state_->RemoveObserver(this); | 71 window_state_->RemoveObserver(this); |
| 72 window_state_->window()->RemoveObserver(this); | 72 window_state_->window()->RemoveObserver(this); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 private: | 75 private: |
| 76 // Overridden from ash::wm::WindowStateDelegate: | 76 // Overridden from ash::wm::WindowStateDelegate: |
| 77 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) override { | 77 bool ToggleFullscreen(ash::wm::WindowState* window_state) override { |
| 78 bool enter_fullscreen = !window_state->IsFullscreen(); | 78 bool enter_fullscreen = !window_state->IsFullscreen(); |
| 79 if (enter_fullscreen) { | 79 if (enter_fullscreen) { |
| 80 window_state->window()->SetProperty(aura::client::kShowStateKey, | 80 window_state->window()->SetProperty(aura::client::kShowStateKey, |
| 81 ui::SHOW_STATE_FULLSCREEN); | 81 ui::SHOW_STATE_FULLSCREEN); |
| 82 } else { | 82 } else { |
| 83 window_state->Restore(); | 83 window_state->Restore(); |
| 84 } | 84 } |
| 85 if (immersive_fullscreen_controller_) { | 85 if (immersive_fullscreen_controller_) { |
| 86 immersive_fullscreen_controller_->SetEnabled( | 86 immersive_fullscreen_controller_->SetEnabled( |
| 87 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, | 87 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, |
| 88 enter_fullscreen); | 88 enter_fullscreen); |
| 89 } | 89 } |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 // Overridden from aura::WindowObserver: | 92 // Overridden from aura::WindowObserver: |
| 93 virtual void OnWindowDestroying(aura::Window* window) override { | 93 void OnWindowDestroying(aura::Window* window) override { |
| 94 window_state_->RemoveObserver(this); | 94 window_state_->RemoveObserver(this); |
| 95 window_state_->window()->RemoveObserver(this); | 95 window_state_->window()->RemoveObserver(this); |
| 96 window_state_ = NULL; | 96 window_state_ = NULL; |
| 97 } | 97 } |
| 98 // Overridden from ash::wm::WindowStateObserver: | 98 // Overridden from ash::wm::WindowStateObserver: |
| 99 virtual void OnPostWindowStateTypeChange( | 99 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, |
| 100 ash::wm::WindowState* window_state, | 100 ash::wm::WindowStateType old_type) override { |
| 101 ash::wm::WindowStateType old_type) override { | |
| 102 if (!window_state->IsFullscreen() && | 101 if (!window_state->IsFullscreen() && |
| 103 !window_state->IsMinimized() && | 102 !window_state->IsMinimized() && |
| 104 immersive_fullscreen_controller_.get() && | 103 immersive_fullscreen_controller_.get() && |
| 105 immersive_fullscreen_controller_->IsEnabled()) { | 104 immersive_fullscreen_controller_->IsEnabled()) { |
| 106 immersive_fullscreen_controller_->SetEnabled( | 105 immersive_fullscreen_controller_->SetEnabled( |
| 107 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, | 106 ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, |
| 108 false); | 107 false); |
| 109 } | 108 } |
| 110 } | 109 } |
| 111 | 110 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 | 124 |
| 126 // View which paints the header. It slides off and on screen in immersive | 125 // View which paints the header. It slides off and on screen in immersive |
| 127 // fullscreen. | 126 // fullscreen. |
| 128 class CustomFrameViewAsh::HeaderView | 127 class CustomFrameViewAsh::HeaderView |
| 129 : public views::View, | 128 : public views::View, |
| 130 public ImmersiveFullscreenController::Delegate, | 129 public ImmersiveFullscreenController::Delegate, |
| 131 public ShellObserver { | 130 public ShellObserver { |
| 132 public: | 131 public: |
| 133 // |frame| is the widget that the caption buttons act on. | 132 // |frame| is the widget that the caption buttons act on. |
| 134 explicit HeaderView(views::Widget* frame); | 133 explicit HeaderView(views::Widget* frame); |
| 135 virtual ~HeaderView(); | 134 ~HeaderView() override; |
| 136 | 135 |
| 137 // Schedules a repaint for the entire title. | 136 // Schedules a repaint for the entire title. |
| 138 void SchedulePaintForTitle(); | 137 void SchedulePaintForTitle(); |
| 139 | 138 |
| 140 // Tells the window controls to reset themselves to the normal state. | 139 // Tells the window controls to reset themselves to the normal state. |
| 141 void ResetWindowControls(); | 140 void ResetWindowControls(); |
| 142 | 141 |
| 143 // Returns the amount of the view's pixels which should be on screen. | 142 // Returns the amount of the view's pixels which should be on screen. |
| 144 int GetPreferredOnScreenHeight() const; | 143 int GetPreferredOnScreenHeight() const; |
| 145 | 144 |
| 146 // Returns the view's preferred height. | 145 // Returns the view's preferred height. |
| 147 int GetPreferredHeight() const; | 146 int GetPreferredHeight() const; |
| 148 | 147 |
| 149 // Returns the view's minimum width. | 148 // Returns the view's minimum width. |
| 150 int GetMinimumWidth() const; | 149 int GetMinimumWidth() const; |
| 151 | 150 |
| 152 void UpdateAvatarIcon(); | 151 void UpdateAvatarIcon(); |
| 153 | 152 |
| 154 void SizeConstraintsChanged(); | 153 void SizeConstraintsChanged(); |
| 155 | 154 |
| 156 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); | 155 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); |
| 157 | 156 |
| 158 // views::View: | 157 // views::View: |
| 159 virtual void Layout() override; | 158 void Layout() override; |
| 160 virtual void OnPaint(gfx::Canvas* canvas) override; | 159 void OnPaint(gfx::Canvas* canvas) override; |
| 161 virtual void ChildPreferredSizeChanged(views::View* child) override; | 160 void ChildPreferredSizeChanged(views::View* child) override; |
| 162 | 161 |
| 163 // ShellObserver: | 162 // ShellObserver: |
| 164 virtual void OnMaximizeModeStarted() override; | 163 void OnMaximizeModeStarted() override; |
| 165 virtual void OnMaximizeModeEnded() override; | 164 void OnMaximizeModeEnded() override; |
| 166 | 165 |
| 167 FrameCaptionButtonContainerView* caption_button_container() { | 166 FrameCaptionButtonContainerView* caption_button_container() { |
| 168 return caption_button_container_; | 167 return caption_button_container_; |
| 169 } | 168 } |
| 170 | 169 |
| 171 views::View* avatar_icon() const { | 170 views::View* avatar_icon() const { |
| 172 return avatar_icon_; | 171 return avatar_icon_; |
| 173 } | 172 } |
| 174 | 173 |
| 175 private: | 174 private: |
| 176 // ImmersiveFullscreenController::Delegate: | 175 // ImmersiveFullscreenController::Delegate: |
| 177 virtual void OnImmersiveRevealStarted() override; | 176 void OnImmersiveRevealStarted() override; |
| 178 virtual void OnImmersiveRevealEnded() override; | 177 void OnImmersiveRevealEnded() override; |
| 179 virtual void OnImmersiveFullscreenExited() override; | 178 void OnImmersiveFullscreenExited() override; |
| 180 virtual void SetVisibleFraction(double visible_fraction) override; | 179 void SetVisibleFraction(double visible_fraction) override; |
| 181 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; | 180 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; |
| 182 | 181 |
| 183 // The widget that the caption buttons act on. | 182 // The widget that the caption buttons act on. |
| 184 views::Widget* frame_; | 183 views::Widget* frame_; |
| 185 | 184 |
| 186 // Helper for painting the header. | 185 // Helper for painting the header. |
| 187 scoped_ptr<DefaultHeaderPainter> header_painter_; | 186 scoped_ptr<DefaultHeaderPainter> header_painter_; |
| 188 | 187 |
| 189 views::ImageView* avatar_icon_; | 188 views::ImageView* avatar_icon_; |
| 190 | 189 |
| 191 // View which contains the window caption buttons. | 190 // View which contains the window caption buttons. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 /////////////////////////////////////////////////////////////////////////////// | 364 /////////////////////////////////////////////////////////////////////////////// |
| 366 // CustomFrameViewAsh::OverlayView | 365 // CustomFrameViewAsh::OverlayView |
| 367 | 366 |
| 368 // View which takes up the entire widget and contains the HeaderView. HeaderView | 367 // View which takes up the entire widget and contains the HeaderView. HeaderView |
| 369 // is a child of OverlayView to avoid creating a larger texture than necessary | 368 // is a child of OverlayView to avoid creating a larger texture than necessary |
| 370 // when painting the HeaderView to its own layer. | 369 // when painting the HeaderView to its own layer. |
| 371 class CustomFrameViewAsh::OverlayView : public views::View, | 370 class CustomFrameViewAsh::OverlayView : public views::View, |
| 372 public views::ViewTargeterDelegate { | 371 public views::ViewTargeterDelegate { |
| 373 public: | 372 public: |
| 374 explicit OverlayView(HeaderView* header_view); | 373 explicit OverlayView(HeaderView* header_view); |
| 375 virtual ~OverlayView(); | 374 ~OverlayView() override; |
| 376 | 375 |
| 377 // views::View: | 376 // views::View: |
| 378 virtual void Layout() override; | 377 void Layout() override; |
| 379 | 378 |
| 380 private: | 379 private: |
| 381 // views::ViewTargeterDelegate: | 380 // views::ViewTargeterDelegate: |
| 382 virtual bool DoesIntersectRect(const views::View* target, | 381 bool DoesIntersectRect(const views::View* target, |
| 383 const gfx::Rect& rect) const override; | 382 const gfx::Rect& rect) const override; |
| 384 | 383 |
| 385 HeaderView* header_view_; | 384 HeaderView* header_view_; |
| 386 | 385 |
| 387 DISALLOW_COPY_AND_ASSIGN(OverlayView); | 386 DISALLOW_COPY_AND_ASSIGN(OverlayView); |
| 388 }; | 387 }; |
| 389 | 388 |
| 390 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) | 389 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) |
| 391 : header_view_(header_view) { | 390 : header_view_(header_view) { |
| 392 AddChildView(header_view); | 391 AddChildView(header_view); |
| 393 SetEventTargeter( | 392 SetEventTargeter( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 FrameCaptionButtonContainerView* CustomFrameViewAsh:: | 584 FrameCaptionButtonContainerView* CustomFrameViewAsh:: |
| 586 GetFrameCaptionButtonContainerViewForTest() { | 585 GetFrameCaptionButtonContainerViewForTest() { |
| 587 return header_view_->caption_button_container(); | 586 return header_view_->caption_button_container(); |
| 588 } | 587 } |
| 589 | 588 |
| 590 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 589 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
| 591 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 590 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
| 592 } | 591 } |
| 593 | 592 |
| 594 } // namespace ash | 593 } // namespace ash |
| OLD | NEW |