summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 14:14:45 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 14:14:45 +0000
commit2527579cd4d7ca238982e00b6ebfbc1a0988acf4 (patch)
tree87d2a6f637d16ea49d441ec79c378087284a9d7f /ui
parentcaf99866fa13ab0321d38aaed8c1e7e4759e2f69 (diff)
downloadchromium_src-2527579cd4d7ca238982e00b6ebfbc1a0988acf4.zip
chromium_src-2527579cd4d7ca238982e00b6ebfbc1a0988acf4.tar.gz
chromium_src-2527579cd4d7ca238982e00b6ebfbc1a0988acf4.tar.bz2
Revert 131761 - Mouse events, touch events, or both can be locked to a target.
Broke Win-Aura compile. 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 Review URL: http://codereview.chromium.org/9838011 TBR=tdresser@chromium.org Review URL: https://chromiumcodereview.appspot.com/10052012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/root_window.cc46
-rw-r--r--ui/aura/root_window.h15
-rw-r--r--ui/aura/root_window_host_linux.cc2
-rw-r--r--ui/aura/window.cc10
-rw-r--r--ui/aura/window.h15
-rw-r--r--ui/aura/window_unittest.cc70
-rw-r--r--ui/base/events.h5
-rw-r--r--ui/views/controls/menu/menu_host.cc9
-rw-r--r--ui/views/widget/native_widget_aura.cc12
-rw-r--r--ui/views/widget/native_widget_aura.h6
-rw-r--r--ui/views/widget/native_widget_private.h18
-rw-r--r--ui/views/widget/native_widget_win.cc26
-rw-r--r--ui/views/widget/native_widget_win.h7
-rw-r--r--ui/views/widget/widget.cc19
-rw-r--r--ui/views/widget/widget_unittest.cc14
15 files changed, 90 insertions, 184 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 0133b1c..3f80348 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -98,7 +98,6 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds)
focused_window_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(
gesture_recognizer_(ui::GestureRecognizer::Create(this))),
- capture_window_flags_(0),
synthesize_mouse_move_(false),
waiting_on_compositing_end_(false),
draw_on_compositing_end_(false),
@@ -267,17 +266,13 @@ bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
DispatchHeldMouseMove();
event->UpdateForRootTransform(layer()->transform());
bool handled = false;
-
- Window* target = NULL;
- if (HasCapture(capture_window_, ui::CW_LOCK_TOUCH))
- target = capture_window_;
+ Window* target = capture_window_;
+ ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN;
if (!target)
target = static_cast<Window*>(
gesture_recognizer_->GetTargetForTouchEvent(event));
- ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN;
-
if (!target && !bounds().Contains(event->location())) {
// If the touch is outside the root window, set its target to the
// root window.
@@ -310,13 +305,11 @@ bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
bool RootWindow::DispatchGestureEvent(GestureEvent* event) {
DispatchHeldMouseMove();
- Window* target = NULL;
- if (HasCapture(capture_window_, ui::CW_LOCK_TOUCH))
- target = capture_window_;
- if (!target)
+ Window* target = capture_window_;
+ if (!target) {
target = static_cast<Window*>(
gesture_recognizer_->GetTargetForGestureEvent(event));
-
+ }
if (target) {
GestureEvent translated_event(*event, this, target);
ui::GestureStatus status = ProcessGestureEvent(target, &translated_event);
@@ -403,20 +396,19 @@ void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const {
point->Offset(location.x(), location.y());
}
-void RootWindow::SetCapture(Window* window, unsigned int flags) {
- if (capture_window_ == window && flags == capture_window_flags_)
+void RootWindow::SetCapture(Window* window) {
+ if (capture_window_ == window)
return;
aura::Window* old_capture_window = capture_window_;
capture_window_ = window;
- capture_window_flags_ = flags;
HandleMouseCaptureChanged(old_capture_window);
- if (capture_window_ && flags & ui::CW_LOCK_MOUSE) {
- // Make all subsequent mouse events go to the capture window. We
- // shouldn't need to send an event here as OnCaptureLost should
- // take care of that.
+ if (capture_window_) {
+ // Make all subsequent mouse events and touch go to the capture window. We
+ // shouldn't need to send an event here as OnCaptureLost should take care of
+ // that.
if (mouse_moved_handler_ || mouse_button_flags_ != 0)
mouse_moved_handler_ = capture_window_;
} else {
@@ -429,12 +421,7 @@ void RootWindow::SetCapture(Window* window, unsigned int flags) {
void RootWindow::ReleaseCapture(Window* window) {
if (capture_window_ != window)
return;
- SetCapture(NULL, 0);
-}
-
-bool RootWindow::HasCapture(Window* window, unsigned int flags) {
- return capture_window_ && window == capture_window_ &&
- ((flags & capture_window_flags_) == flags);
+ SetCapture(NULL);
}
void RootWindow::AdvanceQueuedTouchEvent(Window* window, bool processed) {
@@ -538,7 +525,7 @@ void RootWindow::OnCompositingEnded(ui::Compositor*) {
// RootWindow, private:
void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) {
- if (capture_window_ && capture_window_flags_ & ui::CW_LOCK_MOUSE)
+ if (capture_window_)
host_->SetCapture();
else
host_->ReleaseCapture();
@@ -658,8 +645,6 @@ ui::GestureStatus RootWindow::ProcessGestureEvent(Window* target,
if (status == ui::GESTURE_STATUS_UNKNOWN) {
// The gesture was unprocessed. Generate corresponding mouse events here
// (e.g. tap to click).
- // TODO(tdresser|sadrul): We may need to stop firing mouse events
- // if a mouse lock exists and target != capture_window_.
switch (event->type()) {
case ui::ET_GESTURE_TAP:
case ui::ET_GESTURE_DOUBLE_TAP: {
@@ -856,9 +841,8 @@ bool RootWindow::DispatchMouseEventImpl(MouseEvent* event) {
last_mouse_location_ = event->location();
synthesize_mouse_move_ = false;
- Window* target = mouse_pressed_handler_;
- if (!target && HasCapture(capture_window_, ui::CW_LOCK_MOUSE))
- target = capture_window_;
+ Window* target =
+ mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_;
if (!target)
target = GetEventHandlerForPoint(event->location());
switch (event->type()) {
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 140543e..88ab0a6 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -188,19 +188,12 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Capture -------------------------------------------------------------------
- // Sets the capture window to |window|, 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.
- void SetCapture(Window* window, unsigned int flags);
+ // Sets capture to the specified window.
+ void SetCapture(Window* window);
- // Stop capturing all events (mouse and touch).
+ // If |window| has mouse capture, the current capture window is set to NULL.
void ReleaseCapture(Window* window);
- // Returns true if there is a window capturing all event types
- // specified by |flags|. |flags| is ui::CaptureEventFlags.
- bool HasCapture(Window* window, unsigned int flags);
-
// Gesture Recognition -------------------------------------------------------
// When a touch event is dispatched to a Window, it can notify the RootWindow
@@ -375,8 +368,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// The gesture_recognizer_ for this.
scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
- unsigned int capture_window_flags_;
-
bool synthesize_mouse_move_;
bool waiting_on_compositing_end_;
bool draw_on_compositing_end_;
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index f0d17bc..6699780 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -414,7 +414,7 @@ bool RootWindowHostLinux::Dispatch(const base::NativeEvent& event) {
}
case FocusOut:
if (xev->xfocus.mode != NotifyGrab)
- root_window_->SetCapture(NULL, 0);
+ root_window_->SetCapture(NULL);
break;
case ConfigureNotify: {
DCHECK_EQ(xwindow_, xev->xconfigure.window);
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index e01f2e8..e1d9729 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -478,7 +478,7 @@ const internal::FocusManager* Window::GetFocusManager() const {
return parent_ ? parent_->GetFocusManager() : NULL;
}
-void Window::SetCapture(unsigned int flags) {
+void Window::SetCapture() {
if (!IsVisible())
return;
@@ -486,7 +486,7 @@ void Window::SetCapture(unsigned int flags) {
if (!root_window)
return;
- root_window->SetCapture(this, flags);
+ root_window->SetCapture(this);
}
void Window::ReleaseCapture() {
@@ -497,11 +497,9 @@ void Window::ReleaseCapture() {
root_window->ReleaseCapture(this);
}
-bool Window::HasCapture(unsigned int flags) {
+bool Window::HasCapture() {
RootWindow* root_window = GetRootWindow();
- if (!root_window)
- return false;
- return root_window->HasCapture(this, flags);
+ return root_window && root_window->capture_window() == this;
}
void Window::SuppressPaint() {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index f642d7b..3b0cc34 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -292,18 +292,15 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
virtual internal::FocusManager* GetFocusManager();
virtual const internal::FocusManager* GetFocusManager() const;
- // Sets the capture window to |window|, 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.
- void SetCapture(unsigned int flags);
+ // Does a mouse capture on the window. This does nothing if the window isn't
+ // showing (VISIBILITY_SHOWN) or isn't contained in a valid window hierarchy.
+ void SetCapture();
- // Stop capturing all events (mouse and touch).
+ // Releases a mouse capture.
void ReleaseCapture();
- // Returns true if there is a window capturing all event types
- // specified by |flags|. |flags| is ui::CaptureEventFlags.
- bool HasCapture(unsigned int flags);
+ // Returns true if this window has a mouse capture.
+ bool HasCapture();
// Suppresses painting window content by disgarding damaged rect and ignoring
// new paint requests.
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index dd95610..279c091 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -536,58 +536,18 @@ TEST_F(WindowTest, StackChildAbove) {
EXPECT_EQ(child3.layer(), parent.layer()->children()[2]);
}
-// Ensure capture of touch events works.
-TEST_F(WindowTest, TouchCaptureTests) {
-CaptureWindowDelegateImpl delegate;
- scoped_ptr<Window> window(CreateTestWindowWithDelegate(
- &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_TOUCH));
-
- delegate.ResetCounts();
-
- // Capture touch events.
- window->SetCapture(ui::CW_LOCK_TOUCH);
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_TOUCH));
- EXPECT_EQ(0, delegate.capture_lost_count());
- EXPECT_EQ(0, delegate.capture_changed_event_count());
- EventGenerator generator(root_window(), gfx::Point(50, 50));
- generator.PressLeftButton();
- EXPECT_EQ(0, delegate.mouse_event_count());
-
- TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0, getTime());
- root_window()->DispatchTouchEvent(&touchev);
- EXPECT_EQ(1, delegate.touch_event_count());
- delegate.ResetCounts();
- window->ReleaseCapture();
-
- // Capture both touch and mouse events.
- window->SetCapture(ui::CW_LOCK_TOUCH | ui::CW_LOCK_MOUSE);
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_TOUCH));
- generator.PressLeftButton();
- EXPECT_EQ(1, delegate.mouse_event_count());
-
- TouchEvent touchev2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, getTime());
- root_window()->DispatchTouchEvent(&touchev2);
- EXPECT_EQ(1, delegate.touch_event_count());
-}
-
// Various capture assertions.
TEST_F(WindowTest, CaptureTests) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_TOUCH));
+ EXPECT_FALSE(window->HasCapture());
delegate.ResetCounts();
// Do a capture.
- window->SetCapture(ui::CW_LOCK_MOUSE);
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_TOUCH));
+ window->SetCapture();
+ EXPECT_TRUE(window->HasCapture());
EXPECT_EQ(0, delegate.capture_lost_count());
EXPECT_EQ(0, delegate.capture_changed_event_count());
EventGenerator generator(root_window(), gfx::Point(50, 50));
@@ -600,12 +560,11 @@ TEST_F(WindowTest, CaptureTests) {
TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0, getTime());
root_window()->DispatchTouchEvent(&touchev);
- EXPECT_EQ(0, delegate.touch_event_count());
+ EXPECT_EQ(1, delegate.touch_event_count());
delegate.ResetCounts();
window->ReleaseCapture();
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_TOUCH));
+ EXPECT_FALSE(window->HasCapture());
EXPECT_EQ(1, delegate.capture_lost_count());
EXPECT_EQ(1, delegate.capture_changed_event_count());
EXPECT_EQ(1, delegate.mouse_event_count());
@@ -619,10 +578,10 @@ TEST_F(WindowTest, CaptureTests) {
// Removing the capture window from parent should reset the capture window
// in the root window.
- window->SetCapture(ui::CW_LOCK_MOUSE);
+ window->SetCapture();
EXPECT_EQ(window.get(), root_window()->capture_window());
window->parent()->RemoveChild(window.get());
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
+ EXPECT_FALSE(window->HasCapture());
EXPECT_EQ(NULL, root_window()->capture_window());
}
@@ -639,13 +598,12 @@ TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
// aggregated.
RunAllPendingInMessageLoop();
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_TOUCH));
+ EXPECT_FALSE(window->HasCapture());
// Do a capture.
delegate.ResetCounts();
- window->SetCapture(ui::CW_LOCK_MOUSE);
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_MOUSE));
+ window->SetCapture();
+ EXPECT_TRUE(window->HasCapture());
EXPECT_EQ(0, delegate.capture_lost_count());
EXPECT_EQ(0, delegate.capture_changed_event_count());
EventGenerator generator(root_window(), gfx::Point(50, 50));
@@ -657,7 +615,7 @@ TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {
// Set capture to |w2|, should implicitly unset capture for |window|.
delegate.ResetCounts();
delegate2.ResetCounts();
- w2->SetCapture(ui::CW_LOCK_MOUSE);
+ w2->SetCapture();
generator.MoveMouseTo(gfx::Point(40, 40), 2);
EXPECT_EQ(1, delegate.capture_lost_count());
@@ -671,11 +629,11 @@ TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
- EXPECT_FALSE(window->HasCapture(ui::CW_LOCK_MOUSE));
+ EXPECT_FALSE(window->HasCapture());
// Do a capture.
- window->SetCapture(ui::CW_LOCK_MOUSE);
- EXPECT_TRUE(window->HasCapture(ui::CW_LOCK_MOUSE));
+ window->SetCapture();
+ EXPECT_TRUE(window->HasCapture());
// Destroy the window.
window.reset();
diff --git a/ui/base/events.h b/ui/base/events.h
index 814ffe3..55e82ad 100644
--- a/ui/base/events.h
+++ b/ui/base/events.h
@@ -103,11 +103,6 @@ enum TouchStatus {
// handler.
};
-enum CaptureEventFlags {
- CW_LOCK_MOUSE = 1 << 0,
- CW_LOCK_TOUCH = 1 << 1,
-};
-
// Updates the list of devices for cached properties.
UI_EXPORT void UpdateDeviceList();
diff --git a/ui/views/controls/menu/menu_host.cc b/ui/views/controls/menu/menu_host.cc
index 23060d7..701056f 100644
--- a/ui/views/controls/menu/menu_host.cc
+++ b/ui/views/controls/menu/menu_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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()->SetMouseCapture();
ignore_capture_lost_ = false;
}
@@ -72,9 +72,8 @@ 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))
- native_widget_private()->ReleaseCapture();
+ if (native_widget_private()->HasMouseCapture())
+ native_widget_private()->ReleaseMouseCapture();
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index db69d23..8c14eb0 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::SetCapture(unsigned int flags) {
- window_->SetCapture(flags);
+void NativeWidgetAura::SetMouseCapture() {
+ window_->SetCapture();
}
-void NativeWidgetAura::ReleaseCapture() {
+void NativeWidgetAura::ReleaseMouseCapture() {
window_->ReleaseCapture();
}
-bool NativeWidgetAura::HasCapture(unsigned int flags) const {
- return window_->HasCapture(flags);
+bool NativeWidgetAura::HasMouseCapture() const {
+ return window_->HasCapture();
}
InputMethod* NativeWidgetAura::CreateInputMethod() {
@@ -664,7 +664,7 @@ void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) {
Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() {
if (window_->parent() &&
aura::client::GetWindowMoveClient(window_->parent())) {
- SetCapture(ui::CW_LOCK_MOUSE);
+ SetMouseCapture();
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 d9a23ea..516fa98 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 SetCapture(unsigned int flags) OVERRIDE;
- virtual void ReleaseCapture() OVERRIDE;
- virtual bool HasCapture(unsigned int flags) const OVERRIDE;
+ virtual void SetMouseCapture() OVERRIDE;
+ virtual void ReleaseMouseCapture() OVERRIDE;
+ virtual bool HasMouseCapture() 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..fb4d2cf 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.
- 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;
+ // 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;
// 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 fc85a88..a128771 100644
--- a/ui/views/widget/native_widget_win.cc
+++ b/ui/views/widget/native_widget_win.cc
@@ -642,21 +642,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::SetMouseCapture() {
+ DCHECK(!HasMouseCapture());
+ SetCapture(hwnd());
}
-void NativeWidgetWin::ReleaseCapture() {
- ::ReleaseCapture();
+void NativeWidgetWin::ReleaseMouseCapture() {
+ ReleaseCapture();
}
-bool NativeWidgetWin::HasCapture(unsigned int flags) const {
- if (flags == ui::CW_LOCK_MOUSE)
- return ::GetCapture() == hwnd();
- return false;
+bool NativeWidgetWin::HasMouseCapture() const {
+ return GetCapture() == hwnd();
}
InputMethod* NativeWidgetWin::CreateInputMethod() {
@@ -1128,7 +1124,7 @@ void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) {
}
Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop() {
- ReleaseCapture();
+ ReleaseMouseCapture();
MoveLoopMouseWatcher watcher(this);
SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, GetMessagePos());
// Windows doesn't appear to offer a way to determine whether the user
@@ -1564,10 +1560,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 SetCapture() to ensure we only show the menu when the button
+ // We SetMouseCapture() 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);
+ SetMouseCapture();
}
MSG msg = { hwnd(), message, w_param, l_param, 0,
@@ -1578,7 +1574,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 && !HasMouseCapture()) {
// 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 1f76cce..659818d 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 ReleaseCapture() OVERRIDE;
- virtual bool HasCapture(unsigned int flags) const OVERRIDE;
+ virtual void SetMouseCapture() OVERRIDE;
+ virtual void ReleaseMouseCapture() OVERRIDE;
+ virtual bool HasMouseCapture() 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 527110c..50ec745 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_->HasCapture(ui::CW_LOCK_MOUSE))
- native_widget_->SetCapture(ui::CW_LOCK_MOUSE);
+ if (!native_widget_->HasMouseCapture())
+ native_widget_->SetMouseCapture();
}
void Widget::ReleaseMouseCapture() {
- if (native_widget_->HasCapture(ui::CW_LOCK_MOUSE))
- native_widget_->ReleaseCapture();
+ if (native_widget_->HasMouseCapture())
+ native_widget_->ReleaseMouseCapture();
}
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_->HasCapture(ui::CW_LOCK_MOUSE))
- native_widget_->SetCapture(ui::CW_LOCK_MOUSE);
+ if (!native_widget_->HasMouseCapture())
+ native_widget_->SetMouseCapture();
return true;
}
return false;
@@ -1069,16 +1069,15 @@ 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_->HasMouseCapture() &&
ShouldReleaseCaptureOnMouseReleased()) {
- native_widget_->ReleaseCapture();
+ native_widget_->ReleaseMouseCapture();
}
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_->HasCapture(ui::CW_LOCK_MOUSE) &&
- is_mouse_button_pressed_) {
+ if (native_widget_->HasMouseCapture() && 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 c1dbca0..685adfc 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -40,20 +40,16 @@ 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 SetMouseCapture() OVERRIDE {
mouse_capture_ = true;
}
- virtual void ReleaseCapture() OVERRIDE {
+ virtual void ReleaseMouseCapture() OVERRIDE {
if (mouse_capture_)
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 HasMouseCapture() const OVERRIDE {
+ return mouse_capture_;
}
private:
@@ -145,7 +141,7 @@ Widget* CreateChildNativeWidget() {
bool WidgetHasMouseCapture(const Widget* widget) {
return static_cast<const internal::NativeWidgetPrivate*>(widget->
- native_widget())->HasCapture(ui::CW_LOCK_MOUSE);
+ native_widget())->HasMouseCapture();
}
ui::WindowShowState GetWidgetShowState(const Widget* widget) {