Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1008)

Unified Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc

Issue 15734011: Correct immersive mode gestures under rotation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved SetPreTargetHandler() to private section Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc
diff --git a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc b/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc
index a35b5e16f29889d718951dfc1dfde35f36c7e940..a463841a1bdee564d7ab5cf3878b434c810e1a13 100644
--- a/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc
+++ b/chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc
@@ -18,8 +18,8 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
-#include "ui/aura/window_observer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/screen.h"
@@ -295,45 +295,6 @@ void ImmersiveModeControllerAsh::AnchoredWidgetManager::
////////////////////////////////////////////////////////////////////////////////
-// Observer to watch for window restore. views::Widget does not provide a hook
-// to observe for window restore, so do this at the Aura level.
-class ImmersiveModeControllerAsh::WindowObserver : public aura::WindowObserver {
- public:
- explicit WindowObserver(ImmersiveModeControllerAsh* controller)
- : controller_(controller) {
- controller_->native_window_->AddObserver(this);
- }
-
- virtual ~WindowObserver() {
- controller_->native_window_->RemoveObserver(this);
- }
-
- // aura::WindowObserver overrides:
- virtual void OnWindowPropertyChanged(aura::Window* window,
- const void* key,
- intptr_t old) OVERRIDE {
- using aura::client::kShowStateKey;
- if (key == kShowStateKey) {
- // Disable immersive mode when leaving the fullscreen state.
- ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
- window->GetProperty(kShowStateKey));
- if (controller_->IsEnabled() &&
- show_state != ui::SHOW_STATE_FULLSCREEN &&
- show_state != ui::SHOW_STATE_MINIMIZED) {
- controller_->delegate_->FullscreenStateChanged();
- }
- return;
- }
- }
-
- private:
- ImmersiveModeControllerAsh* controller_; // Not owned.
-
- DISALLOW_COPY_AND_ASSIGN(WindowObserver);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
ImmersiveModeControllerAsh::ImmersiveModeControllerAsh()
: delegate_(NULL),
widget_(NULL),
@@ -543,7 +504,7 @@ void ImmersiveModeControllerAsh::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN:
- if (IsNearTopContainer(event->location())) {
+ if (ShouldHandleEvent(event->location())) {
gesture_begun_ = true;
event->SetHandled();
}
@@ -616,6 +577,36 @@ void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() {
}
////////////////////////////////////////////////////////////////////////////////
+// aura::WindowObserver overrides:
+void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window,
+ const void* key,
+ intptr_t old) {
+ using aura::client::kShowStateKey;
+ if (key == kShowStateKey) {
+ // Disable immersive mode when leaving the fullscreen state.
+ ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
+ window->GetProperty(kShowStateKey));
+ if (IsEnabled() &&
+ show_state != ui::SHOW_STATE_FULLSCREEN &&
+ show_state != ui::SHOW_STATE_MINIMIZED) {
+ delegate_->FullscreenStateChanged();
+ }
+ }
+}
+
+void ImmersiveModeControllerAsh::OnWindowAddedToRootWindow(
+ aura::Window* window) {
+ DCHECK_EQ(window, native_window_);
+ SetPreTargetHandler();
+}
+
+void ImmersiveModeControllerAsh::OnWindowRemovedFromRootWindow(
+ aura::Window* window) {
+ DCHECK_EQ(window, native_window_);
+ SetPreTargetHandler();
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Testing interface:
void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) {
@@ -661,13 +652,13 @@ void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) {
focus_manager->RemoveFocusChangeListener(this);
}
- if (enable)
- native_window_->AddPreTargetHandler(this);
- else
- native_window_->RemovePreTargetHandler(this);
+ SetPreTargetHandler();
- // The window observer adds and removes itself from the native window.
- window_observer_.reset(enable ? new WindowObserver(this) : NULL);
+ if (enable) {
+ native_window_->AddObserver(this);
+ } else {
+ native_window_->RemoveObserver(this);
+ }
if (enable) {
registrar_.Add(
@@ -1027,9 +1018,31 @@ ImmersiveModeControllerAsh::SwipeType ImmersiveModeControllerAsh::GetSwipeType(
return SWIPE_NONE;
}
-bool ImmersiveModeControllerAsh::IsNearTopContainer(gfx::Point location) const {
+bool ImmersiveModeControllerAsh::ShouldHandleEvent(
+ const gfx::Point& location) const {
+ // All of the gestures that are of interest start in a region with left &
+ // right edges agreeing with |top_container_|. When CLOSED it is difficult to
+ // hit the bounds due to small on screen size, so the hit target needs to be
pkotwicz 2013/05/27 21:32:46 The small size of the tab strip?
rharrison 2013/05/28 17:03:01 Done.
+ // extended on the bottom, thus the inset call. Finally there may be a bezel
+ // sensor off screen logically above |top_container_| thus the test needs to
+ // include gestures starting above.
gfx::Rect near_bounds = top_container_->GetTargetBoundsInScreen();
if (reveal_state_ == CLOSED)
near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0));
- return near_bounds.Contains(location);
+ return near_bounds.Contains(location) ||
+ ((location.y() < near_bounds.y()) &&
+ (location.x() >= near_bounds.x()) &&
+ (location.x() <= near_bounds.x() + near_bounds.right()));
pkotwicz 2013/05/27 21:32:46 This is supposed to be near_bounds.right() instead
rharrison 2013/05/28 17:03:01 Done.
+}
+
+void ImmersiveModeControllerAsh::SetPreTargetHandler() {
+ if (!native_window_)
+ return;
+ aura::RootWindow* root_window = native_window_->GetRootWindow();
+ if (!root_window)
+ return;
+ if (observers_enabled_)
+ root_window->AddPreTargetHandler(this);
+ else
+ root_window->RemovePreTargetHandler(this);
}

Powered by Google App Engine
This is Rietveld 408576698