Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" | 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/window_properties.h" | 9 #include "ash/wm/window_properties.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 12 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" | 12 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" |
| 13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 14 #include "chrome/browser/ui/views/frame/top_container_view.h" | 14 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 17 #include "ui/aura/client/activation_client.h" | 17 #include "ui/aura/client/activation_client.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/capture_client.h" | 19 #include "ui/aura/client/capture_client.h" |
| 20 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
| 21 #include "ui/aura/root_window.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/compositor/layer_animation_observer.h" | 24 #include "ui/compositor/layer_animation_observer.h" |
| 24 #include "ui/compositor/scoped_layer_animation_settings.h" | 25 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 26 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
| 27 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
| 28 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/window/non_client_view.h" | 30 #include "ui/views/window/non_client_view.h" |
| 30 | 31 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 | 291 |
| 291 std::map<views::Widget*, int>::iterator it = widgets_.find(widget); | 292 std::map<views::Widget*, int>::iterator it = widgets_.find(widget); |
| 292 DCHECK(it != widgets_.end()); | 293 DCHECK(it != widgets_.end()); |
| 293 UpdateWidgetBounds(it->first, it->second); | 294 UpdateWidgetBounds(it->first, it->second); |
| 294 } | 295 } |
| 295 | 296 |
| 296 //////////////////////////////////////////////////////////////////////////////// | 297 //////////////////////////////////////////////////////////////////////////////// |
| 297 | 298 |
| 298 // Observer to watch for window restore. views::Widget does not provide a hook | 299 // Observer to watch for window restore. views::Widget does not provide a hook |
| 299 // to observe for window restore, so do this at the Aura level. | 300 // to observe for window restore, so do this at the Aura level. |
| 300 class ImmersiveModeControllerAsh::WindowObserver : public aura::WindowObserver { | 301 class ImmersiveModeControllerAsh::WindowObserver : public aura::WindowObserver { |
|
pkotwicz
2013/05/24 03:27:30
I think we should make ImmersiveModeControllerAsh
rharrison
2013/05/27 19:00:54
Done.
| |
| 301 public: | 302 public: |
| 302 explicit WindowObserver(ImmersiveModeControllerAsh* controller) | 303 explicit WindowObserver(ImmersiveModeControllerAsh* controller) |
| 303 : controller_(controller) { | 304 : controller_(controller) { |
| 304 controller_->native_window_->AddObserver(this); | 305 window_ = controller_->native_window_; |
| 306 window_->AddObserver(this); | |
| 305 } | 307 } |
| 306 | 308 |
| 307 virtual ~WindowObserver() { | 309 virtual ~WindowObserver() { |
| 308 controller_->native_window_->RemoveObserver(this); | 310 window_->RemoveObserver(this); |
| 309 } | 311 } |
| 310 | 312 |
| 311 // aura::WindowObserver overrides: | 313 // aura::WindowObserver overrides: |
| 312 virtual void OnWindowPropertyChanged(aura::Window* window, | 314 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 313 const void* key, | 315 const void* key, |
| 314 intptr_t old) OVERRIDE { | 316 intptr_t old) OVERRIDE { |
| 315 using aura::client::kShowStateKey; | 317 using aura::client::kShowStateKey; |
| 316 if (key == kShowStateKey) { | 318 if (key == kShowStateKey) { |
| 317 // Disable immersive mode when leaving the fullscreen state. | 319 // Disable immersive mode when leaving the fullscreen state. |
| 318 ui::WindowShowState show_state = static_cast<ui::WindowShowState>( | 320 ui::WindowShowState show_state = static_cast<ui::WindowShowState>( |
| 319 window->GetProperty(kShowStateKey)); | 321 window->GetProperty(kShowStateKey)); |
| 320 if (controller_->IsEnabled() && | 322 if (controller_->IsEnabled() && |
| 321 show_state != ui::SHOW_STATE_FULLSCREEN && | 323 show_state != ui::SHOW_STATE_FULLSCREEN && |
| 322 show_state != ui::SHOW_STATE_MINIMIZED) { | 324 show_state != ui::SHOW_STATE_MINIMIZED) { |
| 323 controller_->delegate_->FullscreenStateChanged(); | 325 controller_->delegate_->FullscreenStateChanged(); |
| 324 } | 326 } |
| 325 return; | 327 return; |
| 326 } | 328 } |
| 327 } | 329 } |
| 328 | 330 |
| 331 virtual void OnWindowAddedToRootWindow(aura::Window* window) { | |
| 332 DCHECK(window == window_); | |
|
pkotwicz
2013/05/24 03:27:30
Nit: DCHECK_EQ
rharrison
2013/05/27 19:00:54
Done.
| |
| 333 controller_->SetPreTargetHandler(); | |
| 334 } | |
| 335 | |
| 336 virtual void OnWindowRemovedFromRootWindow(aura::Window* window) { | |
| 337 DCHECK(window == window_); | |
|
pkotwicz
2013/05/24 03:27:30
DCHECK_EQ
rharrison
2013/05/27 19:00:54
Done.
| |
| 338 controller_->SetPreTargetHandler(); | |
| 339 } | |
| 340 | |
| 329 private: | 341 private: |
| 330 ImmersiveModeControllerAsh* controller_; // Not owned. | 342 ImmersiveModeControllerAsh* controller_; // Not owned. |
| 343 aura::Window* window_; // Not owned. | |
| 331 | 344 |
| 332 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 345 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| 333 }; | 346 }; |
| 334 | 347 |
| 335 //////////////////////////////////////////////////////////////////////////////// | 348 //////////////////////////////////////////////////////////////////////////////// |
| 336 | 349 |
| 337 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 350 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| 338 : delegate_(NULL), | 351 : delegate_(NULL), |
| 339 widget_(NULL), | 352 widget_(NULL), |
| 340 top_container_(NULL), | 353 top_container_(NULL), |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 370 if (revealed_lock_count_ == 0) { | 383 if (revealed_lock_count_ == 0) { |
| 371 // Always animate ending the reveal fast. | 384 // Always animate ending the reveal fast. |
| 372 MaybeEndReveal(ANIMATE_FAST); | 385 MaybeEndReveal(ANIMATE_FAST); |
| 373 } | 386 } |
| 374 } | 387 } |
| 375 | 388 |
| 376 void ImmersiveModeControllerAsh::MaybeRevealWithoutAnimation() { | 389 void ImmersiveModeControllerAsh::MaybeRevealWithoutAnimation() { |
| 377 MaybeStartReveal(ANIMATE_NO); | 390 MaybeStartReveal(ANIMATE_NO); |
| 378 } | 391 } |
| 379 | 392 |
| 393 void ImmersiveModeControllerAsh::SetPreTargetHandler() { | |
|
pkotwicz
2013/05/24 03:27:30
I don't think that you will need this function onc
rharrison
2013/05/27 19:00:54
I think it will still be needed to avoid code dupl
| |
| 394 if (!native_window_) | |
| 395 return; | |
| 396 aura::RootWindow* root_window = native_window_->GetRootWindow(); | |
| 397 if (!root_window) | |
| 398 return; | |
| 399 if (observers_enabled_) | |
| 400 root_window->AddPreTargetHandler(this); | |
| 401 else | |
| 402 root_window->RemovePreTargetHandler(this); | |
| 403 } | |
| 404 | |
| 380 void ImmersiveModeControllerAsh::Init( | 405 void ImmersiveModeControllerAsh::Init( |
| 381 Delegate* delegate, | 406 Delegate* delegate, |
| 382 views::Widget* widget, | 407 views::Widget* widget, |
| 383 TopContainerView* top_container) { | 408 TopContainerView* top_container) { |
| 384 delegate_ = delegate; | 409 delegate_ = delegate; |
| 385 widget_ = widget; | 410 widget_ = widget; |
| 386 // Browser view is detached from its widget during destruction. Cache the | 411 // Browser view is detached from its widget during destruction. Cache the |
| 387 // window pointer so |this| can stop observing during destruction. | 412 // window pointer so |this| can stop observing during destruction. |
| 388 native_window_ = widget_->GetNativeWindow(); | 413 native_window_ = widget_->GetNativeWindow(); |
| 389 top_container_ = top_container; | 414 top_container_ = top_container; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 views::Widget::GetWidgetForNativeWindow(native_window_); | 679 views::Widget::GetWidgetForNativeWindow(native_window_); |
| 655 views::FocusManager* focus_manager = widget->GetFocusManager(); | 680 views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 656 if (enable) { | 681 if (enable) { |
| 657 widget->AddObserver(this); | 682 widget->AddObserver(this); |
| 658 focus_manager->AddFocusChangeListener(this); | 683 focus_manager->AddFocusChangeListener(this); |
| 659 } else { | 684 } else { |
| 660 widget->RemoveObserver(this); | 685 widget->RemoveObserver(this); |
| 661 focus_manager->RemoveFocusChangeListener(this); | 686 focus_manager->RemoveFocusChangeListener(this); |
| 662 } | 687 } |
| 663 | 688 |
| 664 if (enable) | 689 SetPreTargetHandler(); |
| 665 native_window_->AddPreTargetHandler(this); | |
| 666 else | |
| 667 native_window_->RemovePreTargetHandler(this); | |
| 668 | 690 |
| 669 // The window observer adds and removes itself from the native window. | 691 // The window observer adds and removes itself from the native window. |
| 670 window_observer_.reset(enable ? new WindowObserver(this) : NULL); | 692 window_observer_.reset(enable ? new WindowObserver(this) : NULL); |
| 671 | 693 |
| 672 if (enable) { | 694 if (enable) { |
| 673 registrar_.Add( | 695 registrar_.Add( |
| 674 this, | 696 this, |
| 675 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 697 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 676 content::Source<FullscreenController>( | 698 content::Source<FullscreenController>( |
| 677 delegate_->GetFullscreenController())); | 699 delegate_->GetFullscreenController())); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1020 if (abs(event->details().scroll_y()) <= | 1042 if (abs(event->details().scroll_y()) <= |
| 1021 kSwipeVerticalThresholdMultiplier * abs(event->details().scroll_x())) | 1043 kSwipeVerticalThresholdMultiplier * abs(event->details().scroll_x())) |
| 1022 return SWIPE_NONE; | 1044 return SWIPE_NONE; |
| 1023 if (event->details().scroll_y() < 0) | 1045 if (event->details().scroll_y() < 0) |
| 1024 return SWIPE_CLOSE; | 1046 return SWIPE_CLOSE; |
| 1025 else if (event->details().scroll_y() > 0) | 1047 else if (event->details().scroll_y() > 0) |
| 1026 return SWIPE_OPEN; | 1048 return SWIPE_OPEN; |
| 1027 return SWIPE_NONE; | 1049 return SWIPE_NONE; |
| 1028 } | 1050 } |
| 1029 | 1051 |
| 1030 bool ImmersiveModeControllerAsh::IsNearTopContainer(gfx::Point location) const { | 1052 bool ImmersiveModeControllerAsh::IsNearTopContainer(gfx::Point location) const { |
|
pkotwicz
2013/05/24 03:27:30
Nits:
- We should rename this method to something
rharrison
2013/05/27 19:00:54
Done.
| |
| 1031 gfx::Rect near_bounds = top_container_->GetTargetBoundsInScreen(); | 1053 gfx::Rect near_bounds = top_container_->GetTargetBoundsInScreen(); |
| 1032 if (reveal_state_ == CLOSED) | 1054 if (reveal_state_ == CLOSED) |
| 1033 near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0)); | 1055 near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0)); |
| 1034 return near_bounds.Contains(location); | 1056 return near_bounds.Contains(location) || |
|
pkotwicz
2013/05/24 03:27:30
Can you please add a comment as to why the conditi
rharrison
2013/05/27 19:00:54
Done.
| |
| 1057 ((location.y() < near_bounds.y()) && | |
| 1058 (location.x() >= near_bounds.x()) && | |
| 1059 (location.x() <= near_bounds.x() + near_bounds.width())); | |
|
pkotwicz
2013/05/24 03:27:30
Nit: You can use near_bounds.right()
rharrison
2013/05/27 19:00:54
Done.
| |
| 1035 } | 1060 } |
| OLD | NEW |