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