diff options
author | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 17:10:46 +0000 |
---|---|---|
committer | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-11 17:10:46 +0000 |
commit | e3d5088818a8bce126d6b8be02a2852293230d31 (patch) | |
tree | f65716b8fd7e0207d2dd4ce62fe8f3f5e5f362cd /ui/views/widget | |
parent | 7201d8a61391d00c02b83c1e970705f45fa91219 (diff) | |
download | chromium_src-e3d5088818a8bce126d6b8be02a2852293230d31.zip chromium_src-e3d5088818a8bce126d6b8be02a2852293230d31.tar.gz chromium_src-e3d5088818a8bce126d6b8be02a2852293230d31.tar.bz2 |
Mouse events, touch events, or both can be locked to a target.
NativeWidgetPrivate and Window event capture related commands now take a
set of flags, indicating what event types to lock. Current options are
CW_LOCK_MOUSE and CW_LOCK_TOUCH.
BUG=117554
TEST=WindowTest.TouchCaptureTests, WindowTest.CaptureTests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=131761
Review URL: http://codereview.chromium.org/9838011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131783 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/widget')
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 12 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.h | 6 | ||||
-rw-r--r-- | ui/views/widget/native_widget_private.h | 18 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.cc | 26 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.h | 7 | ||||
-rw-r--r-- | ui/views/widget/widget.cc | 19 | ||||
-rw-r--r-- | ui/views/widget/widget_unittest.cc | 14 |
7 files changed, 59 insertions, 43 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 8c14eb0..db69d23 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -338,16 +338,16 @@ void NativeWidgetAura::SendNativeAccessibilityEvent( //NOTIMPLEMENTED(); } -void NativeWidgetAura::SetMouseCapture() { - window_->SetCapture(); +void NativeWidgetAura::SetCapture(unsigned int flags) { + window_->SetCapture(flags); } -void NativeWidgetAura::ReleaseMouseCapture() { +void NativeWidgetAura::ReleaseCapture() { window_->ReleaseCapture(); } -bool NativeWidgetAura::HasMouseCapture() const { - return window_->HasCapture(); +bool NativeWidgetAura::HasCapture(unsigned int flags) const { + return window_->HasCapture(flags); } InputMethod* NativeWidgetAura::CreateInputMethod() { @@ -664,7 +664,7 @@ void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { if (window_->parent() && aura::client::GetWindowMoveClient(window_->parent())) { - SetMouseCapture(); + SetCapture(ui::CW_LOCK_MOUSE); aura::client::GetWindowMoveClient(window_->parent())->RunMoveLoop(window_); return Widget::MOVE_LOOP_SUCCESSFUL; } diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index 516fa98..d9a23ea 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -68,9 +68,9 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, virtual void SendNativeAccessibilityEvent( View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; - virtual void SetMouseCapture() OVERRIDE; - virtual void ReleaseMouseCapture() OVERRIDE; - virtual bool HasMouseCapture() const OVERRIDE; + virtual void SetCapture(unsigned int flags) OVERRIDE; + virtual void ReleaseCapture() OVERRIDE; + virtual bool HasCapture(unsigned int flags) const OVERRIDE; virtual InputMethod* CreateInputMethod() OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; virtual void GetWindowPlacement( diff --git a/ui/views/widget/native_widget_private.h b/ui/views/widget/native_widget_private.h index fb4d2cf..19fa904 100644 --- a/ui/views/widget/native_widget_private.h +++ b/ui/views/widget/native_widget_private.h @@ -121,12 +121,18 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, View* view, ui::AccessibilityTypes::Event event_type) = 0; - // Sets or releases event capturing for this native widget. - virtual void SetMouseCapture() = 0; - virtual void ReleaseMouseCapture() = 0; - - // Returns true if this native widget is capturing mouse events. - virtual bool HasMouseCapture() const = 0; + // Sets event capturing for the native widget for events specified in + // |flags|. |flags| is ui::CaptureEventFlags. This does nothing if + // the window isn't showing (VISIBILITY_SHOWN), or isn't contained + // in a valid window hierarchy. + virtual void SetCapture(unsigned int flags) = 0; + + // Stop capturing events. + virtual void ReleaseCapture() = 0; + + // Returns true if this native widget is capturing all event types + // specified by |flags|. flags is ui::CaptureEventFlags. + virtual bool HasCapture(unsigned int flags) const = 0; // Returns the InputMethod for this native widget. // Note that all widgets in a widget hierarchy share the same input method. diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index a128771..fc85a88 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -642,17 +642,21 @@ void NativeWidgetWin::SendNativeAccessibilityEvent( GetNativeView(), OBJID_CLIENT, child_id); } -void NativeWidgetWin::SetMouseCapture() { - DCHECK(!HasMouseCapture()); - SetCapture(hwnd()); +void NativeWidgetWin::SetCapture(unsigned int flags) { + if (flags & ui::CW_LOCK_MOUSE) { + DCHECK(!HasCapture(ui::CW_LOCK_MOUSE)); + ::SetCapture(hwnd()); + } } -void NativeWidgetWin::ReleaseMouseCapture() { - ReleaseCapture(); +void NativeWidgetWin::ReleaseCapture() { + ::ReleaseCapture(); } -bool NativeWidgetWin::HasMouseCapture() const { - return GetCapture() == hwnd(); +bool NativeWidgetWin::HasCapture(unsigned int flags) const { + if (flags == ui::CW_LOCK_MOUSE) + return ::GetCapture() == hwnd(); + return false; } InputMethod* NativeWidgetWin::CreateInputMethod() { @@ -1124,7 +1128,7 @@ void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { } Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop() { - ReleaseMouseCapture(); + ReleaseCapture(); MoveLoopMouseWatcher watcher(this); SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, GetMessagePos()); // Windows doesn't appear to offer a way to determine whether the user @@ -1560,10 +1564,10 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message, } else if (message == WM_NCRBUTTONDOWN && (w_param == HTCAPTION || w_param == HTSYSMENU)) { is_right_mouse_pressed_on_caption_ = true; - // We SetMouseCapture() to ensure we only show the menu when the button + // We SetCapture() to ensure we only show the menu when the button // down and up are both on the caption. Note: this causes the button up to // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. - SetMouseCapture(); + SetCapture(ui::CW_LOCK_MOUSE); } MSG msg = { hwnd(), message, w_param, l_param, 0, @@ -1574,7 +1578,7 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message, if (tooltip_manager_.get()) tooltip_manager_->OnMouse(message, w_param, l_param); - if (event.type() == ui::ET_MOUSE_MOVED && !HasMouseCapture()) { + if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture(ui::CW_LOCK_MOUSE)) { // Windows only fires WM_MOUSELEAVE events if the application begins // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index 659818d..1f76cce 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -194,9 +194,10 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual void SendNativeAccessibilityEvent( View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; - virtual void SetMouseCapture() OVERRIDE; - virtual void ReleaseMouseCapture() OVERRIDE; - virtual bool HasMouseCapture() const OVERRIDE; + // NativeWidgetWin ignores touch captures. + virtual void SetCapture(unsigned int flags) OVERRIDE; + virtual void ReleaseCapture() OVERRIDE; + virtual bool HasCapture(unsigned int flags) const OVERRIDE; virtual InputMethod* CreateInputMethod() OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; virtual void GetWindowPlacement( diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 50ec745..527110c 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -849,13 +849,13 @@ NativeWidget* Widget::native_widget() { void Widget::SetMouseCapture(views::View* view) { is_mouse_button_pressed_ = true; root_view_->SetMouseHandler(view); - if (!native_widget_->HasMouseCapture()) - native_widget_->SetMouseCapture(); + if (!native_widget_->HasCapture(ui::CW_LOCK_MOUSE)) + native_widget_->SetCapture(ui::CW_LOCK_MOUSE); } void Widget::ReleaseMouseCapture() { - if (native_widget_->HasMouseCapture()) - native_widget_->ReleaseMouseCapture(); + if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE)) + native_widget_->ReleaseCapture(); } const Event* Widget::GetCurrentEvent() { @@ -1060,8 +1060,8 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { // press processing may have made the window hide (as happens with menus). if (GetRootView()->OnMousePressed(event) && IsVisible()) { is_mouse_button_pressed_ = true; - if (!native_widget_->HasMouseCapture()) - native_widget_->SetMouseCapture(); + if (!native_widget_->HasCapture(ui::CW_LOCK_MOUSE)) + native_widget_->SetCapture(ui::CW_LOCK_MOUSE); return true; } return false; @@ -1069,15 +1069,16 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { last_mouse_event_was_move_ = false; is_mouse_button_pressed_ = false; // Release capture first, to avoid confusion if OnMouseReleased blocks. - if (native_widget_->HasMouseCapture() && + if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE) && ShouldReleaseCaptureOnMouseReleased()) { - native_widget_->ReleaseMouseCapture(); + native_widget_->ReleaseCapture(); } GetRootView()->OnMouseReleased(event); return (event.flags() & ui::EF_IS_NON_CLIENT) ? false : true; case ui::ET_MOUSE_MOVED: case ui::ET_MOUSE_DRAGGED: - if (native_widget_->HasMouseCapture() && is_mouse_button_pressed_) { + if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE) && + is_mouse_button_pressed_) { last_mouse_event_was_move_ = false; GetRootView()->OnMouseDragged(event); } else if (!last_mouse_event_was_move_ || diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc index 685adfc..c1dbca0 100644 --- a/ui/views/widget/widget_unittest.cc +++ b/ui/views/widget/widget_unittest.cc @@ -40,16 +40,20 @@ class NativeWidgetCapture : public NativeWidgetPlatform { mouse_capture_(false) {} virtual ~NativeWidgetCapture() {} - virtual void SetMouseCapture() OVERRIDE { + virtual void SetCapture(unsigned int flags) OVERRIDE { + if (!(flags & ui::CW_LOCK_MOUSE)) + return; mouse_capture_ = true; } - virtual void ReleaseMouseCapture() OVERRIDE { + virtual void ReleaseCapture() OVERRIDE { if (mouse_capture_) delegate()->OnMouseCaptureLost(); mouse_capture_ = false; } - virtual bool HasMouseCapture() const OVERRIDE { - return mouse_capture_; + virtual bool HasCapture(unsigned int flags) const OVERRIDE { + if (flags == ui::CW_LOCK_MOUSE) + return mouse_capture_; + return false; } private: @@ -141,7 +145,7 @@ Widget* CreateChildNativeWidget() { bool WidgetHasMouseCapture(const Widget* widget) { return static_cast<const internal::NativeWidgetPrivate*>(widget-> - native_widget())->HasMouseCapture(); + native_widget())->HasCapture(ui::CW_LOCK_MOUSE); } ui::WindowShowState GetWidgetShowState(const Widget* widget) { |