diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 00:16:59 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-15 00:16:59 +0000 |
commit | a8dffcec83c5eba7b9f17b03e0e35f28b44a8d52 (patch) | |
tree | 27e7dc26d245d83d5a8b81318d236d19e0ae0c21 /ui/views | |
parent | 06ea3e51e4ca77a6e16f549eff9094c472786f91 (diff) | |
download | chromium_src-a8dffcec83c5eba7b9f17b03e0e35f28b44a8d52.zip chromium_src-a8dffcec83c5eba7b9f17b03e0e35f28b44a8d52.tar.gz chromium_src-a8dffcec83c5eba7b9f17b03e0e35f28b44a8d52.tar.bz2 |
Take 2 at: Changes RootWindow capture code so that we only have one capture
type. Makes gesture generated mouse events use the right mouse
generating code so that we generate the correct enter/exit/moved
events and update the appropriate state.
BUG=115684
TEST=covered by unit tests
TBR=sadrul@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10332141
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/menu/menu_host.cc | 5 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 10 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.h | 4 | ||||
-rw-r--r-- | ui/views/widget/native_widget_private.h | 14 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.cc | 18 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.h | 5 | ||||
-rw-r--r-- | ui/views/widget/widget.cc | 15 | ||||
-rw-r--r-- | ui/views/widget/widget_unittest.cc | 12 |
8 files changed, 33 insertions, 50 deletions
diff --git a/ui/views/controls/menu/menu_host.cc b/ui/views/controls/menu/menu_host.cc index 4a887e5..a9f2f7f 100644 --- a/ui/views/controls/menu/menu_host.cc +++ b/ui/views/controls/menu/menu_host.cc @@ -49,7 +49,7 @@ void MenuHost::ShowMenuHost(bool do_capture) { ignore_capture_lost_ = true; Show(); if (do_capture) - native_widget_private()->SetCapture(ui::CW_LOCK_MOUSE | ui::CW_LOCK_TOUCH); + native_widget_private()->SetCapture(); ignore_capture_lost_ = false; } @@ -72,8 +72,7 @@ void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) { } void MenuHost::ReleaseMenuHostCapture() { - if (native_widget_private()->HasCapture(ui::CW_LOCK_MOUSE) || - native_widget_private()->HasCapture(ui::CW_LOCK_TOUCH)) + if (native_widget_private()->HasCapture()) native_widget_private()->ReleaseCapture(); } diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index d840fa1..b63e8fd 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -325,16 +325,16 @@ void NativeWidgetAura::SendNativeAccessibilityEvent( //NOTIMPLEMENTED(); } -void NativeWidgetAura::SetCapture(unsigned int flags) { - window_->SetCapture(flags); +void NativeWidgetAura::SetCapture() { + window_->SetCapture(); } void NativeWidgetAura::ReleaseCapture() { window_->ReleaseCapture(); } -bool NativeWidgetAura::HasCapture(unsigned int flags) const { - return window_->HasCapture(flags); +bool NativeWidgetAura::HasCapture() const { + return window_->HasCapture(); } InputMethod* NativeWidgetAura::CreateInputMethod() { @@ -653,7 +653,7 @@ void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { if (window_->parent() && aura::client::GetWindowMoveClient(window_->parent())) { - SetCapture(ui::CW_LOCK_MOUSE); + SetCapture(); 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 7a66d2e..c9a1480 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -65,9 +65,9 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, virtual void SendNativeAccessibilityEvent( View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; - virtual void SetCapture(unsigned int flags) OVERRIDE; + virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; - virtual bool HasCapture(unsigned int flags) const OVERRIDE; + virtual bool HasCapture() 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 19fa904..a56e5a6d 100644 --- a/ui/views/widget/native_widget_private.h +++ b/ui/views/widget/native_widget_private.h @@ -121,18 +121,12 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, View* view, ui::AccessibilityTypes::Event event_type) = 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. + // Sets or releases event capturing for this native widget. + virtual void SetCapture() = 0; 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 true if this native widget is capturing events. + virtual bool HasCapture() 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 1cbc98b..975b905 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -650,21 +650,17 @@ void NativeWidgetWin::SendNativeAccessibilityEvent( GetNativeView(), OBJID_CLIENT, child_id); } -void NativeWidgetWin::SetCapture(unsigned int flags) { - if (flags & ui::CW_LOCK_MOUSE) { - DCHECK(!HasCapture(ui::CW_LOCK_MOUSE)); - ::SetCapture(hwnd()); - } +void NativeWidgetWin::SetCapture() { + DCHECK(!HasCapture()); + ::SetCapture(hwnd()); } void NativeWidgetWin::ReleaseCapture() { ::ReleaseCapture(); } -bool NativeWidgetWin::HasCapture(unsigned int flags) const { - if (flags == ui::CW_LOCK_MOUSE) - return ::GetCapture() == hwnd(); - return false; +bool NativeWidgetWin::HasCapture() const { + return ::GetCapture() == hwnd(); } InputMethod* NativeWidgetWin::CreateInputMethod() { @@ -1580,7 +1576,7 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message, // 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. - SetCapture(ui::CW_LOCK_MOUSE); + SetCapture(); } MSG msg = { hwnd(), message, w_param, l_param, 0, @@ -1591,7 +1587,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 && !HasCapture(ui::CW_LOCK_MOUSE)) { + if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) { // 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 059425c..5e1b7b7 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -194,10 +194,9 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual void SendNativeAccessibilityEvent( View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; - // NativeWidgetWin ignores touch captures. - virtual void SetCapture(unsigned int flags) OVERRIDE; + virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; - virtual bool HasCapture(unsigned int flags) const OVERRIDE; + virtual bool HasCapture() 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 2cb0caa..e238c67 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -827,12 +827,12 @@ NativeWidget* Widget::native_widget() { void Widget::SetMouseCapture(views::View* view) { is_mouse_button_pressed_ = true; root_view_->SetMouseHandler(view); - if (!native_widget_->HasCapture(ui::CW_LOCK_MOUSE)) - native_widget_->SetCapture(ui::CW_LOCK_MOUSE); + if (!native_widget_->HasCapture()) + native_widget_->SetCapture(); } void Widget::ReleaseMouseCapture() { - if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE)) + if (native_widget_->HasCapture()) native_widget_->ReleaseCapture(); } @@ -1046,8 +1046,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_->HasCapture(ui::CW_LOCK_MOUSE)) - native_widget_->SetCapture(ui::CW_LOCK_MOUSE); + if (!native_widget_->HasCapture()) + native_widget_->SetCapture(); return true; } return false; @@ -1055,7 +1055,7 @@ 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_->HasCapture(ui::CW_LOCK_MOUSE) && + if (native_widget_->HasCapture() && ShouldReleaseCaptureOnMouseReleased()) { native_widget_->ReleaseCapture(); } @@ -1063,8 +1063,7 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { return (event.flags() & ui::EF_IS_NON_CLIENT) ? false : true; case ui::ET_MOUSE_MOVED: case ui::ET_MOUSE_DRAGGED: - if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE) && - is_mouse_button_pressed_) { + if (native_widget_->HasCapture() && 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 df2c1b7..9716a6c 100644 --- a/ui/views/widget/widget_unittest.cc +++ b/ui/views/widget/widget_unittest.cc @@ -41,9 +41,7 @@ class NativeWidgetCapture : public NativeWidgetPlatform { mouse_capture_(false) {} virtual ~NativeWidgetCapture() {} - virtual void SetCapture(unsigned int flags) OVERRIDE { - if (!(flags & ui::CW_LOCK_MOUSE)) - return; + virtual void SetCapture() OVERRIDE { mouse_capture_ = true; } virtual void ReleaseCapture() OVERRIDE { @@ -51,10 +49,8 @@ class NativeWidgetCapture : public NativeWidgetPlatform { delegate()->OnMouseCaptureLost(); mouse_capture_ = false; } - virtual bool HasCapture(unsigned int flags) const OVERRIDE { - if (flags == ui::CW_LOCK_MOUSE) - return mouse_capture_; - return false; + virtual bool HasCapture() const OVERRIDE { + return mouse_capture_; } private: @@ -146,7 +142,7 @@ Widget* CreateChildNativeWidget() { bool WidgetHasMouseCapture(const Widget* widget) { return static_cast<const internal::NativeWidgetPrivate*>(widget-> - native_widget())->HasCapture(ui::CW_LOCK_MOUSE); + native_widget())->HasCapture(); } ui::WindowShowState GetWidgetShowState(const Widget* widget) { |