| 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/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 11 #include "ash/frame/frame_border_hit_test.h" | 11 #include "ash/frame/frame_border_hit_test.h" |
| 12 #include "ash/frame/header_view.h" | 12 #include "ash/frame/header_view.h" |
| 13 #include "ash/shared/immersive_fullscreen_controller.h" | 13 #include "ash/shared/immersive_fullscreen_controller.h" |
| 14 #include "ash/shared/immersive_fullscreen_controller_delegate.h" | 14 #include "ash/shared/immersive_fullscreen_controller_delegate.h" |
| 15 #include "ash/shell_port.h" | 15 #include "ash/shell_port.h" |
| 16 #include "ash/wm/window_state.h" | 16 #include "ash/wm/window_state.h" |
| 17 #include "ash/wm/window_state_delegate.h" | 17 #include "ash/wm/window_state_delegate.h" |
| 18 #include "ash/wm/window_state_observer.h" | 18 #include "ash/wm/window_state_observer.h" |
| 19 #include "ash/wm_window.h" | 19 #include "ash/wm_window.h" |
| 20 #include "base/memory/ptr_util.h" |
| 20 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_observer.h" | 23 #include "ui/aura/window_observer.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 25 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/image/image_skia.h" |
| 26 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
| 27 #include "ui/views/view_targeter.h" | 29 #include "ui/views/view_targeter.h" |
| 28 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| 30 | 32 |
| 31 namespace ash { | 33 namespace ash { |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 ui::SHOW_STATE_FULLSCREEN); | 83 ui::SHOW_STATE_FULLSCREEN); |
| 82 } else { | 84 } else { |
| 83 window_state->Restore(); | 85 window_state->Restore(); |
| 84 } | 86 } |
| 85 if (immersive_fullscreen_controller_) { | 87 if (immersive_fullscreen_controller_) { |
| 86 immersive_fullscreen_controller_->SetEnabled( | 88 immersive_fullscreen_controller_->SetEnabled( |
| 87 ImmersiveFullscreenController::WINDOW_TYPE_OTHER, enter_fullscreen); | 89 ImmersiveFullscreenController::WINDOW_TYPE_OTHER, enter_fullscreen); |
| 88 } | 90 } |
| 89 return true; | 91 return true; |
| 90 } | 92 } |
| 93 |
| 91 // Overridden from aura::WindowObserver: | 94 // Overridden from aura::WindowObserver: |
| 92 void OnWindowDestroying(aura::Window* window) override { | 95 void OnWindowDestroying(aura::Window* window) override { |
| 93 window_state_->RemoveObserver(this); | 96 window_state_->RemoveObserver(this); |
| 94 window->RemoveObserver(this); | 97 window->RemoveObserver(this); |
| 95 window_state_ = nullptr; | 98 window_state_ = nullptr; |
| 96 } | 99 } |
| 100 |
| 97 // Overridden from wm::WindowStateObserver: | 101 // Overridden from wm::WindowStateObserver: |
| 98 void OnPostWindowStateTypeChange(wm::WindowState* window_state, | 102 void OnPostWindowStateTypeChange(wm::WindowState* window_state, |
| 99 wm::WindowStateType old_type) override { | 103 wm::WindowStateType old_type) override { |
| 100 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && | 104 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && |
| 101 immersive_fullscreen_controller_ && | 105 immersive_fullscreen_controller_ && |
| 102 immersive_fullscreen_controller_->IsEnabled()) { | 106 immersive_fullscreen_controller_->IsEnabled()) { |
| 103 immersive_fullscreen_controller_->SetEnabled( | 107 immersive_fullscreen_controller_->SetEnabled( |
| 104 ImmersiveFullscreenController::WINDOW_TYPE_OTHER, false); | 108 ImmersiveFullscreenController::WINDOW_TYPE_OTHER, false); |
| 105 } | 109 } |
| 106 } | 110 } |
| 107 | 111 |
| 108 wm::WindowState* window_state_; | 112 wm::WindowState* window_state_; |
| 109 std::unique_ptr<ImmersiveFullscreenController> | 113 std::unique_ptr<ImmersiveFullscreenController> |
| 110 immersive_fullscreen_controller_; | 114 immersive_fullscreen_controller_; |
| 111 | 115 |
| 112 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); | 116 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); |
| 113 }; | 117 }; |
| 114 | 118 |
| 115 } // namespace | 119 } // namespace |
| 116 | 120 |
| 117 // static | 121 // static |
| 118 bool CustomFrameViewAsh::use_empty_minimum_size_for_test_ = false; | 122 bool CustomFrameViewAsh::use_empty_minimum_size_for_test_ = false; |
| 119 | 123 |
| 120 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
| 125 // CustomFrameViewAsh::AvatarObserver |
| 126 |
| 127 // AvatarObserver watches the frame window's avatar icon property and updates |
| 128 // HeaderView with it. |
| 129 class CustomFrameViewAsh::AvatarObserver : public aura::WindowObserver { |
| 130 public: |
| 131 AvatarObserver(views::Widget* frame, HeaderView* header_view) |
| 132 : frame_window_(frame->GetNativeWindow()), header_view_(header_view) { |
| 133 frame_window_->AddObserver(this); |
| 134 } |
| 135 |
| 136 ~AvatarObserver() override { |
| 137 if (frame_window_) |
| 138 frame_window_->RemoveObserver(this); |
| 139 } |
| 140 |
| 141 // aura::WindowObserver: |
| 142 void OnWindowPropertyChanged(aura::Window* window, |
| 143 const void* key, |
| 144 intptr_t old) override { |
| 145 DCHECK_EQ(frame_window_, window); |
| 146 if (key != aura::client::kAvatarIconKey) |
| 147 return; |
| 148 |
| 149 gfx::ImageSkia* const avatar_icon = |
| 150 frame_window_->GetProperty(aura::client::kAvatarIconKey); |
| 151 header_view_->SetAvatarIcon(avatar_icon ? *avatar_icon : gfx::ImageSkia()); |
| 152 } |
| 153 |
| 154 void OnWindowDestroyed(aura::Window* window) override { |
| 155 DCHECK_EQ(frame_window_, window); |
| 156 frame_window_ = nullptr; |
| 157 } |
| 158 |
| 159 private: |
| 160 aura::Window* frame_window_; |
| 161 HeaderView* const header_view_; |
| 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(AvatarObserver); |
| 164 }; |
| 165 |
| 166 /////////////////////////////////////////////////////////////////////////////// |
| 121 // CustomFrameViewAsh::OverlayView | 167 // CustomFrameViewAsh::OverlayView |
| 122 | 168 |
| 123 // View which takes up the entire widget and contains the HeaderView. HeaderView | 169 // View which takes up the entire widget and contains the HeaderView. HeaderView |
| 124 // is a child of OverlayView to avoid creating a larger texture than necessary | 170 // is a child of OverlayView to avoid creating a larger texture than necessary |
| 125 // when painting the HeaderView to its own layer. | 171 // when painting the HeaderView to its own layer. |
| 126 class CustomFrameViewAsh::OverlayView : public views::View, | 172 class CustomFrameViewAsh::OverlayView : public views::View, |
| 127 public views::ViewTargeterDelegate { | 173 public views::ViewTargeterDelegate { |
| 128 public: | 174 public: |
| 129 explicit OverlayView(HeaderView* header_view); | 175 explicit OverlayView(HeaderView* header_view); |
| 130 ~OverlayView() override; | 176 ~OverlayView() override; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 252 |
| 207 CustomFrameViewAsh::CustomFrameViewAsh( | 253 CustomFrameViewAsh::CustomFrameViewAsh( |
| 208 views::Widget* frame, | 254 views::Widget* frame, |
| 209 ImmersiveFullscreenControllerDelegate* immersive_delegate, | 255 ImmersiveFullscreenControllerDelegate* immersive_delegate, |
| 210 bool enable_immersive, | 256 bool enable_immersive, |
| 211 mojom::WindowStyle window_style) | 257 mojom::WindowStyle window_style) |
| 212 : frame_(frame), | 258 : frame_(frame), |
| 213 header_view_(new HeaderView(frame, window_style)), | 259 header_view_(new HeaderView(frame, window_style)), |
| 214 overlay_view_(new OverlayView(header_view_)), | 260 overlay_view_(new OverlayView(header_view_)), |
| 215 immersive_delegate_(immersive_delegate ? immersive_delegate | 261 immersive_delegate_(immersive_delegate ? immersive_delegate |
| 216 : header_view_) { | 262 : header_view_), |
| 263 avatar_observer_(base::MakeUnique<AvatarObserver>(frame_, header_view_)) { |
| 217 WmWindow* frame_window = WmWindow::Get(frame->GetNativeWindow()); | 264 WmWindow* frame_window = WmWindow::Get(frame->GetNativeWindow()); |
| 218 frame_window->InstallResizeHandleWindowTargeter(nullptr); | 265 frame_window->InstallResizeHandleWindowTargeter(nullptr); |
| 219 // |header_view_| is set as the non client view's overlay view so that it can | 266 // |header_view_| is set as the non client view's overlay view so that it can |
| 220 // overlay the web contents in immersive fullscreen. | 267 // overlay the web contents in immersive fullscreen. |
| 221 frame->non_client_view()->SetOverlayView(overlay_view_); | 268 frame->non_client_view()->SetOverlayView(overlay_view_); |
| 222 frame_window->aura_window()->SetProperty( | 269 frame_window->aura_window()->SetProperty( |
| 223 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); | 270 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); |
| 224 | 271 |
| 225 // A delegate for a more complex way of fullscreening the window may already | 272 // A delegate for a more complex way of fullscreening the window may already |
| 226 // be set. This is the case for packaged apps. | 273 // be set. This is the case for packaged apps. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 245 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); | 292 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); |
| 246 WmWindow* frame_window = WmWindow::Get(frame_->GetNativeWindow()); | 293 WmWindow* frame_window = WmWindow::Get(frame_->GetNativeWindow()); |
| 247 frame_window->aura_window()->SetProperty( | 294 frame_window->aura_window()->SetProperty( |
| 248 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); | 295 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); |
| 249 } | 296 } |
| 250 | 297 |
| 251 void CustomFrameViewAsh::SetHeaderHeight(base::Optional<int> height) { | 298 void CustomFrameViewAsh::SetHeaderHeight(base::Optional<int> height) { |
| 252 overlay_view_->SetHeaderHeight(height); | 299 overlay_view_->SetHeaderHeight(height); |
| 253 } | 300 } |
| 254 | 301 |
| 255 views::View* CustomFrameViewAsh::header_view() { | 302 views::View* CustomFrameViewAsh::GetHeaderView() { |
| 256 return header_view_; | 303 return header_view_; |
| 257 } | 304 } |
| 258 | 305 |
| 259 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
| 260 // CustomFrameViewAsh, views::NonClientFrameView overrides: | 307 // CustomFrameViewAsh, views::NonClientFrameView overrides: |
| 261 | 308 |
| 262 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { | 309 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { |
| 263 gfx::Rect client_bounds = bounds(); | 310 gfx::Rect client_bounds = bounds(); |
| 264 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | 311 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
| 265 return client_bounds; | 312 return client_bounds; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint | 399 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint |
| 353 // to HeaderView instead. | 400 // to HeaderView instead. |
| 354 gfx::RectF to_paint(r); | 401 gfx::RectF to_paint(r); |
| 355 views::View::ConvertRectToTarget(this, header_view_, &to_paint); | 402 views::View::ConvertRectToTarget(this, header_view_, &to_paint); |
| 356 header_view_->SchedulePaintInRect(gfx::ToEnclosingRect(to_paint)); | 403 header_view_->SchedulePaintInRect(gfx::ToEnclosingRect(to_paint)); |
| 357 } else { | 404 } else { |
| 358 views::NonClientFrameView::SchedulePaintInRect(r); | 405 views::NonClientFrameView::SchedulePaintInRect(r); |
| 359 } | 406 } |
| 360 } | 407 } |
| 361 | 408 |
| 362 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from, | |
| 363 bool is_visible) { | |
| 364 if (is_visible) | |
| 365 header_view_->UpdateAvatarIcon(); | |
| 366 } | |
| 367 | |
| 368 views::View* CustomFrameViewAsh::GetHeaderView() { | |
| 369 return header_view_; | |
| 370 } | |
| 371 | |
| 372 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { | 409 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { |
| 373 return header_view_->avatar_icon(); | 410 return header_view_->avatar_icon(); |
| 374 } | 411 } |
| 375 | 412 |
| 376 //////////////////////////////////////////////////////////////////////////////// | 413 //////////////////////////////////////////////////////////////////////////////// |
| 377 // CustomFrameViewAsh, private: | 414 // CustomFrameViewAsh, private: |
| 378 | 415 |
| 379 // views::NonClientFrameView: | 416 // views::NonClientFrameView: |
| 380 bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target, | 417 bool CustomFrameViewAsh::DoesIntersectRect(const views::View* target, |
| 381 const gfx::Rect& rect) const { | 418 const gfx::Rect& rect) const { |
| 382 CHECK_EQ(target, this); | 419 CHECK_EQ(target, this); |
| 383 // NonClientView hit tests the NonClientFrameView first instead of going in | 420 // NonClientView hit tests the NonClientFrameView first instead of going in |
| 384 // z-order. Return false so that events get to the OverlayView. | 421 // z-order. Return false so that events get to the OverlayView. |
| 385 return false; | 422 return false; |
| 386 } | 423 } |
| 387 | 424 |
| 388 FrameCaptionButtonContainerView* | 425 FrameCaptionButtonContainerView* |
| 389 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { | 426 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { |
| 390 return header_view_->caption_button_container(); | 427 return header_view_->caption_button_container(); |
| 391 } | 428 } |
| 392 | 429 |
| 393 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 430 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
| 394 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 431 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
| 395 } | 432 } |
| 396 | 433 |
| 397 } // namespace ash | 434 } // namespace ash |
| OLD | NEW |