diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 21:39:30 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 21:39:30 +0000 |
commit | 4e721741ebb5f584d23483bf1f5577dea2539f3c (patch) | |
tree | b952663a8fbddad65d4bb69062c0da762394e438 | |
parent | bb986abf62f8a4bc98537b008c205c83f6940e34 (diff) | |
download | chromium_src-4e721741ebb5f584d23483bf1f5577dea2539f3c.zip chromium_src-4e721741ebb5f584d23483bf1f5577dea2539f3c.tar.gz chromium_src-4e721741ebb5f584d23483bf1f5577dea2539f3c.tar.bz2 |
Differentiate invisible cursor mode and disabled mouse events mode.
I made the cursor visibility and the mouse events enable state work as follows.
- Typing keys just hides the cursor and mouse events are not disabled (mouse hover state is not cleared)
- Scrolling a web page when the cursor is invisible disables mouse events.
- Touch events disable mouse events.
BUG=154979
TBR=jln@chromium.org
Review URL: https://codereview.chromium.org/11888003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180528 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/shell.cc | 10 | ||||
-rw-r--r-- | ash/wm/session_state_controller_impl.cc | 4 | ||||
-rw-r--r-- | ash/wm/session_state_controller_impl2.cc | 6 | ||||
-rw-r--r-- | ash/wm/window_manager_unittest.cc | 80 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_impl.cc | 7 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_impl.h | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.cc | 14 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura.h | 1 | ||||
-rw-r--r-- | content/common/view_messages.h | 6 | ||||
-rw-r--r-- | content/port/browser/render_widget_host_view_port.h | 3 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rw-r--r-- | ui/views/corewm/compound_event_filter.cc | 45 | ||||
-rw-r--r-- | ui/views/corewm/compound_event_filter.h | 5 |
13 files changed, 130 insertions, 54 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index b788522..cd317d7 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -582,12 +582,14 @@ void Shell::Init() { user_wallpaper_delegate_->InitializeWallpaper(); if (initially_hide_cursor_) - cursor_manager_.DisableMouseEvents(); + cursor_manager_.HideCursor(); cursor_manager_.SetCursor(ui::kCursorPointer); - // Cursor might have been hidden by somethign other than chrome. - // Let the first mouse event show the cursor. - env_filter_->set_cursor_hidden_by_filter(true); + if (!cursor_manager_.IsCursorVisible()) { + // Cursor might have been hidden by something other than chrome. + // Let the first mouse event show the cursor. + env_filter_->set_cursor_hidden_by_filter(true); + } } void Shell::ShowContextMenu(const gfx::Point& location_in_screen) { diff --git a/ash/wm/session_state_controller_impl.cc b/ash/wm/session_state_controller_impl.cc index b31b29b6..7a54f35 100644 --- a/ash/wm/session_state_controller_impl.cc +++ b/ash/wm/session_state_controller_impl.cc @@ -52,7 +52,7 @@ void SessionStateControllerImpl::OnAppTerminating() { shutting_down_ = true; Shell* shell = ash::Shell::GetInstance(); shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->DisableMouseEvents(); + shell->cursor_manager()->HideCursor(); animator_->StartAnimation( internal::SessionStateAnimator::kAllContainersMask, internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, @@ -219,7 +219,7 @@ void SessionStateControllerImpl::RequestShutdownImpl() { Shell* shell = ash::Shell::GetInstance(); shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->DisableMouseEvents(); + shell->cursor_manager()->HideCursor(); if (login_status_ != user::LOGGED_IN_NONE) { // Hide the other containers before starting the animation. diff --git a/ash/wm/session_state_controller_impl2.cc b/ash/wm/session_state_controller_impl2.cc index 6858a91..2a386a3 100644 --- a/ash/wm/session_state_controller_impl2.cc +++ b/ash/wm/session_state_controller_impl2.cc @@ -171,7 +171,7 @@ void SessionStateControllerImpl2::OnAppTerminating() { shutting_down_ = true; Shell* shell = ash::Shell::GetInstance(); shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->DisableMouseEvents(); + shell->cursor_manager()->HideCursor(); animator_->StartAnimation( internal::SessionStateAnimator::kAllContainersMask, internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY, @@ -279,7 +279,7 @@ void SessionStateControllerImpl2::RequestShutdownImpl() { Shell* shell = ash::Shell::GetInstance(); shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->DisableMouseEvents(); + shell->cursor_manager()->HideCursor(); StartShutdownAnimationImpl(); } @@ -338,7 +338,7 @@ void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() { Shell* shell = ash::Shell::GetInstance(); shell->env_filter()->set_cursor_hidden_by_filter(false); - shell->cursor_manager()->DisableMouseEvents(); + shell->cursor_manager()->HideCursor(); StartRealShutdownTimer(false); } diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index bf1317a..b5ff1e1d 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -642,56 +642,78 @@ TEST_F(WindowManagerTest, AdditionalFilters) { // We should show and hide the cursor in response to mouse and touch events as // requested. TEST_F(WindowManagerTest, UpdateCursorVisibility) { - aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); - root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); - scoped_ptr<aura::Window> window(CreateTestWindowInShell( - SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); - + aura::test::EventGenerator& generator = GetEventGenerator(); ash::CursorManager* cursor_manager = ash::Shell::GetInstance()->cursor_manager(); - ui::MouseEvent mouse_moved( - ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); - ui::TouchEvent touch_pressed1( - ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); - ui::TouchEvent touch_pressed2( - ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); - ui::TouchEvent touch_released1( - ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 0, getTime()); - ui::TouchEvent touch_released2( - ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 1, getTime()); - - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_TRUE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed1); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.PressTouch(); EXPECT_FALSE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_TRUE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released1); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.ReleaseTouch(); EXPECT_TRUE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); // If someone else made cursor invisible keep it invisible even after it // received mouse events. - cursor_manager->DisableMouseEvents(); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + cursor_manager->EnableMouseEvents(); + cursor_manager->HideCursor(); + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_FALSE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.PressTouch(); EXPECT_FALSE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_FALSE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.ReleaseTouch(); EXPECT_FALSE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); // Back to normal. cursor_manager->EnableMouseEvents(); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + cursor_manager->ShowCursor(); + generator.MoveMouseTo(gfx::Point(0, 0)); + EXPECT_TRUE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.PressTouch(); + EXPECT_FALSE(cursor_manager->IsCursorVisible()); + EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); + generator.MoveMouseTo(gfx::Point(0, 0)); + EXPECT_TRUE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + generator.ReleaseTouch(); EXPECT_TRUE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); +} + +TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { + aura::test::EventGenerator& generator = GetEventGenerator(); + ash::CursorManager* cursor_manager = + ash::Shell::GetInstance()->cursor_manager(); + + // Pressing a key hides the cursor but does not disable mouse events. + generator.PressKey(ui::VKEY_A, ui::EF_NONE); EXPECT_FALSE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + // Moving mouse shows the cursor. + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_TRUE(cursor_manager->IsCursorVisible()); - root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + // Releasing a key also hides the cursor but does not disable mouse events. + generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); + EXPECT_FALSE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); + // Moving mouse shows the cursor again. + generator.MoveMouseTo(gfx::Point(0, 0)); EXPECT_TRUE(cursor_manager->IsCursorVisible()); + EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); } } // namespace ash diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 7c9df2f..9bbdca2 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -963,6 +963,8 @@ bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnOpenURL) IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, OnDidContentsPreferredSizeChange) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffset, + OnDidChangeScrollOffset) IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollbarsForMainFrame, OnDidChangeScrollbarsForMainFrame) IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame, @@ -1375,6 +1377,11 @@ void RenderViewHostImpl::OnRenderAutoResized(const gfx::Size& new_size) { delegate_->ResizeDueToAutoResize(new_size); } +void RenderViewHostImpl::OnDidChangeScrollOffset() { + if (view_) + view_->ScrollOffsetChanged(); +} + void RenderViewHostImpl::OnDidChangeScrollbarsForMainFrame( bool has_horizontal_scrollbar, bool has_vertical_scrollbar) { if (view_) diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index d0c5cf8..53c21e4 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -495,6 +495,7 @@ class CONTENT_EXPORT RenderViewHostImpl void OnToggleFullscreen(bool enter_fullscreen); void OnOpenURL(const ViewHostMsg_OpenURL_Params& params); void OnDidContentsPreferredSizeChange(const gfx::Size& new_size); + void OnDidChangeScrollOffset(); void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar, bool has_vertical_scrollbar); void OnDidChangeScrollOffsetPinningForMainFrame(bool is_pinned_to_left, diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 7abf0ef..ae80e24 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -1032,6 +1032,16 @@ void RenderWidgetHostViewAura::SetBackground(const SkBitmap& background) { window_->layer()->SetFillsBoundsOpaquely(background.isOpaque()); } +void RenderWidgetHostViewAura::ScrollOffsetChanged() { + aura::RootWindow* root = window_->GetRootWindow(); + if (!root) + return; + aura::client::CursorClient* cursor_client = + aura::client::GetCursorClient(root); + if (cursor_client && !cursor_client->IsCursorVisible()) + cursor_client->DisableMouseEvents(); +} + void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) { GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL); } @@ -1091,7 +1101,7 @@ bool RenderWidgetHostViewAura::LockMouse() { aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(root_window); if (cursor_client) - cursor_client->DisableMouseEvents(); + cursor_client->HideCursor(); synthetic_move_sent_ = true; window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); if (aura::client::GetTooltipClient(root_window)) @@ -1111,7 +1121,7 @@ void RenderWidgetHostViewAura::UnlockMouse() { aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(root_window); if (cursor_client) - cursor_client->EnableMouseEvents(); + cursor_client->ShowCursor(); if (aura::client::GetTooltipClient(root_window)) aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(true); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index f47e110..0249ed5 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -105,6 +105,7 @@ class RenderWidgetHostViewAura virtual bool IsShowing() OVERRIDE; virtual gfx::Rect GetViewBounds() const OVERRIDE; virtual void SetBackground(const SkBitmap& background) OVERRIDE; + virtual void ScrollOffsetChanged() OVERRIDE; // Overridden from RenderWidgetHostViewPort: virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 22c246d..ce156d4 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1825,6 +1825,12 @@ IPC_MESSAGE_ROUTED1(ViewHostMsg_OpenURL, ViewHostMsg_OpenURL_Params) IPC_MESSAGE_ROUTED1(ViewHostMsg_DidContentsPreferredSizeChange, gfx::Size /* pref_size */) +// Notifies that the scroll offset changed. +// This is different from ViewHostMsg_UpdateRect in that ViewHostMsg_UpdateRect +// is not sent at all when threaded compositing is enabled while +// ViewHostMsg_DidChangeScrollOffset works properly in this case. +IPC_MESSAGE_ROUTED0(ViewHostMsg_DidChangeScrollOffset) + // Notifies that the scrollbars-visible state of the content changed. IPC_MESSAGE_ROUTED2(ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame, bool /* has_horizontal_scrollbar */, diff --git a/content/port/browser/render_widget_host_view_port.h b/content/port/browser/render_widget_host_view_port.h index 953296c..d126c3d 100644 --- a/content/port/browser/render_widget_host_view_port.h +++ b/content/port/browser/render_widget_host_view_port.h @@ -147,6 +147,9 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView { const gfx::Rect& end_rect, WebKit::WebTextDirection end_direction) {} + // Notifies the view that the scroll offset has changed. + virtual void ScrollOffsetChanged() {} + // Allocate a backing store for this view. virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 8beb818..95a38df 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -4134,6 +4134,8 @@ void RenderViewImpl::UpdateScrollState(WebFrame* frame) { cached_is_main_frame_pinned_to_left_ = is_pinned_to_left; cached_is_main_frame_pinned_to_right_ = is_pinned_to_right; } + + Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_)); } void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) { diff --git a/ui/views/corewm/compound_event_filter.cc b/ui/views/corewm/compound_event_filter.cc index de3e4aa..54350bf 100644 --- a/ui/views/corewm/compound_event_filter.cc +++ b/ui/views/corewm/compound_event_filter.cc @@ -169,22 +169,38 @@ void CompoundEventFilter::FilterTouchEvent(ui::TouchEvent* event) { void CompoundEventFilter::SetCursorVisibilityOnEvent(aura::Window* target, ui::Event* event, bool show) { - if (!(event->flags() & ui::EF_IS_SYNTHESIZED)) { - aura::client::CursorClient* client = - aura::client::GetCursorClient(target->GetRootWindow()); - if (client) { - if (show && cursor_hidden_by_filter_) { - cursor_hidden_by_filter_ = false; - client->EnableMouseEvents(); - } else if (client->IsCursorVisible() && !show && - !cursor_hidden_by_filter_) { - cursor_hidden_by_filter_ = true; - client->DisableMouseEvents(); - } - } + if (event->flags() & ui::EF_IS_SYNTHESIZED) + return; + aura::client::CursorClient* client = + aura::client::GetCursorClient(target->GetRootWindow()); + if (!client) + return; + + if (show && cursor_hidden_by_filter_) { + cursor_hidden_by_filter_ = false; + client->ShowCursor(); + } else if (!show && !cursor_hidden_by_filter_) { + cursor_hidden_by_filter_ = true; + client->HideCursor(); } } +void CompoundEventFilter::SetMouseEventsEnableStateOnEvent(aura::Window* target, + ui::Event* event, + bool enable) { + if (event->flags() & ui::EF_IS_SYNTHESIZED) + return; + aura::client::CursorClient* client = + aura::client::GetCursorClient(target->GetRootWindow()); + if (!client) + return; + + if (enable) + client->EnableMouseEvents(); + else + client->DisableMouseEvents(); +} + //////////////////////////////////////////////////////////////////////////////// // CompoundEventFilter, ui::EventHandler implementation: @@ -214,6 +230,7 @@ void CompoundEventFilter::OnMouseEvent(ui::MouseEvent* event) { event->type() == ui::ET_MOUSE_MOVED || event->type() == ui::ET_MOUSE_PRESSED || event->type() == ui::ET_MOUSEWHEEL) { + SetMouseEventsEnableStateOnEvent(window, event, true); SetCursorVisibilityOnEvent(window, event, true); UpdateCursor(window, event); } @@ -227,7 +244,7 @@ void CompoundEventFilter::OnScrollEvent(ui::ScrollEvent* event) { void CompoundEventFilter::OnTouchEvent(ui::TouchEvent* event) { FilterTouchEvent(event); if (!event->handled() && event->type() == ui::ET_TOUCH_PRESSED) { - SetCursorVisibilityOnEvent( + SetMouseEventsEnableStateOnEvent( static_cast<aura::Window*>(event->target()), event, false); } } diff --git a/ui/views/corewm/compound_event_filter.h b/ui/views/corewm/compound_event_filter.h index e2dba41..e9c927f 100644 --- a/ui/views/corewm/compound_event_filter.h +++ b/ui/views/corewm/compound_event_filter.h @@ -77,6 +77,11 @@ class VIEWS_EXPORT CompoundEventFilter : public ui::EventHandler { ui::Event* event, bool show); + // Enables or disables mouse events if the event is not synthesized. + void SetMouseEventsEnableStateOnEvent(aura::Window* target, + ui::Event* event, + bool enable); + // Overridden from ui::EventHandler: virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |