summaryrefslogtreecommitdiffstats
path: root/views/events
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 01:20:41 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 01:20:41 +0000
commitbb021bad4ee651f51b2b84cd2d35490206b0996d (patch)
treea2aacafd16a7bdf90d54387c7ff5831c61e0eecb /views/events
parent7f23bac00f99429e34198b12322c11de3097e0ae (diff)
downloadchromium_src-bb021bad4ee651f51b2b84cd2d35490206b0996d.zip
chromium_src-bb021bad4ee651f51b2b84cd2d35490206b0996d.tar.gz
chromium_src-bb021bad4ee651f51b2b84cd2d35490206b0996d.tar.bz2
Add new MouseEvent ctors; update WidgetWin & WindowWin usage.
BUG=72040 TEST=Manual mouse event testing. Review URL: http://codereview.chromium.org/6591120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77221 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/events')
-rw-r--r--views/events/event.cc26
-rw-r--r--views/events/event.h79
-rw-r--r--views/events/event_gtk.cc21
-rw-r--r--views/events/event_win.cc134
-rw-r--r--views/events/event_x.cc11
5 files changed, 180 insertions, 91 deletions
diff --git a/views/events/event.cc b/views/events/event.cc
index 4b74dbe..de8a1ba 100644
--- a/views/events/event.cc
+++ b/views/events/event.cc
@@ -38,6 +38,7 @@ Event::Event(NativeEvent2 native_event_2, ui::EventType type, int flags,
////////////////////////////////////////////////////////////////////////////////
// LocatedEvent, protected:
+// TODO(msw): Kill this legacy constructor when we update uses.
LocatedEvent::LocatedEvent(ui::EventType type, const gfx::Point& location,
int flags)
: Event(type, flags),
@@ -52,9 +53,6 @@ LocatedEvent::LocatedEvent(const LocatedEvent& model, View* source,
View::ConvertPointToView(source, target, &location_);
}
-////////////////////////////////////////////////////////////////////////////////
-// LocatedEvent, private:
-
LocatedEvent::LocatedEvent(const LocatedEvent& model, RootView* root)
: Event(model),
location_(model.location_) {
@@ -73,16 +71,17 @@ KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code,
////////////////////////////////////////////////////////////////////////////////
// MouseEvent, public:
+// TODO(msw): Kill this legacy constructor when we update uses.
MouseEvent::MouseEvent(ui::EventType type,
- View* from,
- View* to,
+ View* source,
+ View* target,
const gfx::Point &l,
int flags)
- : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), from, to) {
+ : LocatedEvent(MouseEvent(type, l.x(), l.y(), flags), source, target) {
}
-MouseEvent::MouseEvent(const MouseEvent& model, View* from, View* to)
- : LocatedEvent(model, from, to) {
+MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target)
+ : LocatedEvent(model, source, target) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -97,17 +96,18 @@ TouchEvent::TouchEvent(ui::EventType type, int x, int y, int flags,
TouchEvent::TouchEvent(ui::EventType type,
- View* from,
- View* to,
+ View* source,
+ View* target,
const gfx::Point& l,
int flags,
int touch_id)
- : LocatedEvent(TouchEvent(type, l.x(), l.y(), flags, touch_id), from, to),
+ : LocatedEvent(TouchEvent(type, l.x(), l.y(), flags, touch_id), source,
+ target),
touch_id_(touch_id) {
}
-TouchEvent::TouchEvent(const TouchEvent& model, View* from, View* to)
- : LocatedEvent(model, from, to),
+TouchEvent::TouchEvent(const TouchEvent& model, View* source, View* target)
+ : LocatedEvent(model, source, target),
touch_id_(model.touch_id_) {
}
#endif
diff --git a/views/events/event.h b/views/events/event.h
index a670234..2d68e30 100644
--- a/views/events/event.h
+++ b/views/events/event.h
@@ -83,9 +83,6 @@ class Event {
#if defined(OS_WIN)
// Returns the EventFlags in terms of windows flags.
int GetWindowsFlags() const;
-
- // Convert windows flags to views::Event flags
- static int ConvertWindowsFlags(uint32 win_flags);
#elif defined(OS_LINUX)
// Convert the state member on a GdkEvent to views::Event flags
static int GetFlagsFromGdkState(unsigned int state);
@@ -137,23 +134,22 @@ class LocatedEvent : public Event {
const gfx::Point& location() const { return location_; }
protected:
- // This constructor is to allow converting the location of an event from the
- // widget's coordinate system to the RootView's coordinate system.
- LocatedEvent(const LocatedEvent& model, RootView* root);
-
explicit LocatedEvent(NativeEvent native_event);
LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
- // TODO(msw): Kill this legacy constructor when we update MouseEvent???
+ // TODO(msw): Kill this legacy constructor when we update uses.
// Simple initialization from cracked metadata.
LocatedEvent(ui::EventType type, const gfx::Point& location, int flags);
// Create a new LocatedEvent which is identical to the provided model.
// If source / target views are provided, the model location will be converted
- // from 'source' coordinate system to 'target' coordinate system
+ // from |source| coordinate system to |target| coordinate system.
LocatedEvent(const LocatedEvent& model, View* source, View* target);
- private:
+ // This constructor is to allow converting the location of an event from the
+ // widget's coordinate system to the RootView's coordinate system.
+ LocatedEvent(const LocatedEvent& model, RootView* root);
+
gfx::Point location_;
};
@@ -166,30 +162,30 @@ class LocatedEvent : public Event {
////////////////////////////////////////////////////////////////////////////////
class MouseEvent : public LocatedEvent {
public:
+ explicit MouseEvent(NativeEvent native_event);
+ MouseEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
+
+ // Create a new MouseEvent which is identical to the provided model.
+ // If source / target views are provided, the model location will be converted
+ // from |source| coordinate system to |target| coordinate system.
+ MouseEvent(const MouseEvent& model, View* source, View* target);
+
+ // TODO(msw): Kill this legacy constructor when we update uses.
// Create a new mouse event
MouseEvent(ui::EventType type, int x, int y, int flags)
: LocatedEvent(type, gfx::Point(x, y), flags) {
}
- // Create a new mouse event from a type and a point. If from / to views
- // are provided, the point will be converted from 'from' coordinate system to
- // 'to' coordinate system.
+ // TODO(msw): Kill this legacy constructor when we update uses.
+ // Create a new mouse event from a type and a point. If source / target views
+ // are provided, the point will be converted from |source| coordinate system
+ // to |target| coordinate system.
MouseEvent(ui::EventType type,
- View* from,
- View* to,
+ View* source,
+ View* target,
const gfx::Point &l,
int flags);
- // Create a new MouseEvent which is identical to the provided model.
- // If from / to views are provided, the model location will be converted
- // from 'from' coordinate system to 'to' coordinate system
- MouseEvent(const MouseEvent& model, View* from, View* to);
-
-#if defined(TOUCH_UI)
- // Create a mouse event from an X mouse event.
- explicit MouseEvent(XEvent* xevent);
-#endif
-
// Conveniences to quickly test what button is down
bool IsOnlyLeftMouseButton() const {
return (flags() & ui::EF_LEFT_BUTTON_DOWN) &&
@@ -218,13 +214,14 @@ class MouseEvent : public LocatedEvent {
return (flags() & ui::EF_RIGHT_BUTTON_DOWN) != 0;
}
- private:
- friend class RootView;
-
+ protected:
MouseEvent(const MouseEvent& model, RootView* root)
: LocatedEvent(model, root) {
}
+ private:
+ friend class RootView;
+
DISALLOW_COPY_AND_ASSIGN(MouseEvent);
};
@@ -240,27 +237,26 @@ class MouseEvent : public LocatedEvent {
////////////////////////////////////////////////////////////////////////////////
class TouchEvent : public LocatedEvent {
public:
+ explicit TouchEvent(NativeEvent native_event);
+ TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
+
// Create a new touch event.
TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id);
// Create a new touch event from a type and a point. If from / to views
- // are provided, the point will be converted from 'from' coordinate system to
- // 'to' coordinate system.
+ // are provided, the point will be converted from 'source' coordinate system
+ // to 'target' coordinate system.
TouchEvent(ui::EventType type,
- View* from,
- View* to,
+ View* source,
+ View* target,
const gfx::Point& l,
int flags,
int touch_id);
// Create a new TouchEvent which is identical to the provided model.
- // If from / to views are provided, the model location will be converted
- // from 'from' coordinate system to 'to' coordinate system.
- TouchEvent(const TouchEvent& model, View* from, View* to);
-
-#if defined(HAVE_XINPUT2)
- explicit TouchEvent(XEvent* xev);
-#endif
+ // If source / target views are provided, the model location will be converted
+ // from |source| coordinate system to |target| coordinate system.
+ TouchEvent(const TouchEvent& model, View* source, View* target);
bool identity() const { return touch_id_; }
@@ -285,6 +281,7 @@ class TouchEvent : public LocatedEvent {
//
// KeyEvent encapsulates keyboard input events - key press and release.
//
+////////////////////////////////////////////////////////////////////////////////
class KeyEvent : public Event {
public:
explicit KeyEvent(NativeEvent native_event);
@@ -314,7 +311,7 @@ class KeyEvent : public Event {
// Note: e.GetOffset() > 0 means scroll up / left.
//
////////////////////////////////////////////////////////////////////////////////
-class MouseWheelEvent : public LocatedEvent {
+class MouseWheelEvent : public MouseEvent {
public:
// See |offset| for details.
static const int kWheelDelta;
@@ -329,7 +326,7 @@ class MouseWheelEvent : public LocatedEvent {
friend class RootView;
MouseWheelEvent(const MouseWheelEvent& model, RootView* root)
- : LocatedEvent(model, root),
+ : MouseEvent(model, root),
offset_(model.offset_) {
}
diff --git a/views/events/event_gtk.cc b/views/events/event_gtk.cc
index a82abd5..8b29369 100644
--- a/views/events/event_gtk.cc
+++ b/views/events/event_gtk.cc
@@ -142,6 +142,23 @@ LocatedEvent::LocatedEvent(NativeEvent2 native_event_2,
#endif
////////////////////////////////////////////////////////////////////////////////
+// MouseEvent, public:
+
+MouseEvent::MouseEvent(NativeEvent native_event)
+ : LocatedEvent(native_event) {
+}
+
+#if !defined(TOUCH_UI)
+MouseEvent::MouseEvent(NativeEvent2 native_event_2,
+ FromNativeEvent2 from_native)
+ : LocatedEvent(native_event_2, from_native) {
+ // No one should ever call this on Gtk-views.
+ // TODO(msw): remove once we rid views of Gtk/Gdk.
+ NOTREACHED();
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
// KeyEvent, public:
KeyEvent::KeyEvent(NativeEvent native_event)
@@ -164,14 +181,14 @@ KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native)
// MouseWheelEvent, public:
MouseWheelEvent::MouseWheelEvent(NativeEvent native_event)
- : LocatedEvent(native_event),
+ : MouseEvent(native_event),
offset_(GetMouseWheelOffset(native_event)) {
}
#if !defined(TOUCH_UI)
MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2,
FromNativeEvent2 from_native)
- : LocatedEvent(native_event_2, from_native) {
+ : MouseEvent(native_event_2, from_native) {
// No one should ever call this on Gtk-views.
// TODO(msw): remove once we rid views of Gtk/Gdk.
NOTREACHED();
diff --git a/views/events/event_win.cc b/views/events/event_win.cc
index b79f839..11f63ec 100644
--- a/views/events/event_win.cc
+++ b/views/events/event_win.cc
@@ -18,12 +18,9 @@ namespace {
// as with mouse messages, so we need to explicitly ask for these states.
int GetKeyStateFlags() {
int flags = 0;
- if (GetKeyState(VK_MENU) & 0x80)
- flags |= ui::EF_ALT_DOWN;
- if (GetKeyState(VK_SHIFT) & 0x80)
- flags |= ui::EF_SHIFT_DOWN;
- if (GetKeyState(VK_CONTROL) & 0x80)
- flags |= ui::EF_CONTROL_DOWN;
+ flags |= (GetKeyState(VK_MENU) & 0x80)? ui::EF_ALT_DOWN : 0;
+ flags |= (GetKeyState(VK_SHIFT) & 0x80)? ui::EF_SHIFT_DOWN : 0;
+ flags |= (GetKeyState(VK_CONTROL) & 0x80)? ui::EF_CONTROL_DOWN : 0;
return flags;
}
@@ -71,10 +68,81 @@ ui::EventType EventTypeFromNative(NativeEvent native_event) {
return ui::ET_UNKNOWN;
}
-int GetFlagsFromNative(NativeEvent native_event) {
- // Allow other applicable messages as necessary.
- DCHECK(native_event.message == WM_MOUSEWHEEL);
- return Event::ConvertWindowsFlags(GET_KEYSTATE_WPARAM(native_event.wParam));
+bool IsClientMouseEvent(NativeEvent native_event) {
+ return native_event.message == WM_MOUSELEAVE ||
+ native_event.message == WM_MOUSEHOVER ||
+ (native_event.message >= WM_MOUSEFIRST &&
+ native_event.message <= WM_MOUSELAST);
+}
+
+bool IsNonClientMouseEvent(NativeEvent native_event) {
+ return native_event.message == WM_NCMOUSELEAVE ||
+ native_event.message == WM_NCMOUSEHOVER ||
+ (native_event.message >= WM_NCMOUSEMOVE &&
+ native_event.message <= WM_NCXBUTTONDBLCLK);
+}
+
+// Get views::Event flags from a native Windows message
+int EventFlagsFromNative(NativeEvent native_event) {
+ int flags = 0;
+
+ // TODO(msw): ORing the pressed/released button into the flags is _wrong_.
+ // It makes it impossible to tell which button was modified when multiple
+ // buttons are/were held down. We need to instead put the modified button into
+ // a separate member on the MouseEvent, then audit all consumers of
+ // MouseEvents to fix them to use the resulting values correctly.
+ switch (native_event.message) {
+ case WM_LBUTTONDBLCLK:
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONUP:
+ case WM_NCLBUTTONDBLCLK:
+ case WM_NCLBUTTONDOWN:
+ case WM_NCLBUTTONUP:
+ native_event.wParam |= MK_LBUTTON;
+ break;
+ case WM_MBUTTONDBLCLK:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONUP:
+ case WM_NCMBUTTONDBLCLK:
+ case WM_NCMBUTTONDOWN:
+ case WM_NCMBUTTONUP:
+ native_event.wParam |= MK_MBUTTON;
+ break;
+ case WM_RBUTTONDBLCLK:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONUP:
+ case WM_NCRBUTTONDBLCLK:
+ case WM_NCRBUTTONDOWN:
+ case WM_NCRBUTTONUP:
+ native_event.wParam |= MK_RBUTTON;
+ break;
+ }
+
+ // Check if the event occurred in the non-client area.
+ if (IsNonClientMouseEvent(native_event))
+ flags |= ui::EF_IS_NON_CLIENT;
+
+ // Check for double click events.
+ switch (native_event.message) {
+ case WM_NCLBUTTONDBLCLK:
+ case WM_NCMBUTTONDBLCLK:
+ case WM_NCRBUTTONDBLCLK:
+ case WM_LBUTTONDBLCLK:
+ case WM_MBUTTONDBLCLK:
+ case WM_RBUTTONDBLCLK:
+ flags |= ui::EF_IS_DOUBLE_CLICK;
+ break;
+ }
+
+ UINT win_flags = GET_KEYSTATE_WPARAM(native_event.wParam);
+ flags |= (win_flags & MK_CONTROL) ? ui::EF_CONTROL_DOWN : 0;
+ flags |= (win_flags & MK_SHIFT) ? ui::EF_SHIFT_DOWN : 0;
+ flags |= (GetKeyState(VK_MENU) < 0) ? ui::EF_ALT_DOWN : 0;
+ flags |= (win_flags & MK_LBUTTON) ? ui::EF_LEFT_BUTTON_DOWN : 0;
+ flags |= (win_flags & MK_MBUTTON) ? ui::EF_MIDDLE_BUTTON_DOWN : 0;
+ flags |= (win_flags & MK_RBUTTON) ? ui::EF_RIGHT_BUTTON_DOWN : 0;
+
+ return flags;
}
} // namespace
@@ -93,24 +161,6 @@ int Event::GetWindowsFlags() const {
return result;
}
-//static
-int Event::ConvertWindowsFlags(UINT win_flags) {
- int r = 0;
- if (win_flags & MK_CONTROL)
- r |= ui::EF_CONTROL_DOWN;
- if (win_flags & MK_SHIFT)
- r |= ui::EF_SHIFT_DOWN;
- if (GetKeyState(VK_MENU) < 0)
- r |= ui::EF_ALT_DOWN;
- if (win_flags & MK_LBUTTON)
- r |= ui::EF_LEFT_BUTTON_DOWN;
- if (win_flags & MK_MBUTTON)
- r |= ui::EF_MIDDLE_BUTTON_DOWN;
- if (win_flags & MK_RBUTTON)
- r |= ui::EF_RIGHT_BUTTON_DOWN;
- return r;
-}
-
////////////////////////////////////////////////////////////////////////////////
// Event, private:
@@ -138,7 +188,7 @@ void Event::InitWithNativeEvent2(NativeEvent2 native_event_2,
LocatedEvent::LocatedEvent(NativeEvent native_event)
: Event(native_event, EventTypeFromNative(native_event),
- GetFlagsFromNative(native_event)),
+ EventFlagsFromNative(native_event)),
location_(native_event.pt.x, native_event.pt.y) {
}
@@ -168,16 +218,38 @@ KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native)
}
////////////////////////////////////////////////////////////////////////////////
+// MouseEvent, public:
+
+MouseEvent::MouseEvent(NativeEvent native_event)
+ : LocatedEvent(native_event) {
+ if (IsNonClientMouseEvent(native_event)) {
+ // Non-client message. The position is contained in a POINTS structure in
+ // LPARAM, and is in screen coordinates so we have to convert to client.
+ POINT native_point = location_.ToPOINT();
+ ScreenToClient(native_event.hwnd, &native_point);
+ location_ = gfx::Point(native_point);
+ }
+}
+
+MouseEvent::MouseEvent(NativeEvent2 native_event_2,
+ FromNativeEvent2 from_native)
+ : LocatedEvent(native_event_2, from_native) {
+ // No one should ever call this on Windows.
+ // TODO(msw): remove once we rid views of Gtk/Gdk.
+ NOTREACHED();
+}
+
+////////////////////////////////////////////////////////////////////////////////
// MouseWheelEvent, public:
MouseWheelEvent::MouseWheelEvent(NativeEvent native_event)
- : LocatedEvent(native_event),
+ : MouseEvent(native_event),
offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) {
}
MouseWheelEvent::MouseWheelEvent(NativeEvent2 native_event_2,
FromNativeEvent2 from_native)
- : LocatedEvent(native_event_2, from_native) {
+ : MouseEvent(native_event_2, from_native) {
// No one should ever call this on Windows.
// TODO(msw): remove once we rid views of Gtk/Gdk.
NOTREACHED();
diff --git a/views/events/event_x.cc b/views/events/event_x.cc
index 189b70b..d3187a2 100644
--- a/views/events/event_x.cc
+++ b/views/events/event_x.cc
@@ -262,10 +262,13 @@ KeyEvent::KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native)
////////////////////////////////////////////////////////////////////////////////
// MouseEvent, public:
-MouseEvent::MouseEvent(XEvent* xev)
- : LocatedEvent(EventTypeFromNative(xev),
- GetMouseEventLocation(xev),
- GetMouseEventFlags(xev)) {
+MouseEvent::MouseEvent(NativeEvent native_event)
+ : LocatedEvent(native_event) {
+}
+
+MouseEvent::MouseEvent(NativeEvent2 native_event_2,
+ FromNativeEvent2 from_native)
+ : LocatedEvent(native_event_2, from_native) {
}
////////////////////////////////////////////////////////////////////////////////