diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 21:47:56 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 21:47:56 +0000 |
commit | 36df22b48817bc7fe7159e498f65b5e8b00f1605 (patch) | |
tree | 15e7aa8f769102d90479c5c59330a5309f4dbc3c /views/events | |
parent | af5ee7f3fe7c555578bd9c0cf1290bcf6af553e7 (diff) | |
download | chromium_src-36df22b48817bc7fe7159e498f65b5e8b00f1605.zip chromium_src-36df22b48817bc7fe7159e498f65b5e8b00f1605.tar.gz chromium_src-36df22b48817bc7fe7159e498f65b5e8b00f1605.tar.bz2 |
Transformable views: Use the transformation for points and events.
Added and updated API for converting points between views' coordinate systems,
taking transformations into consideration. This in turn gives us, for free,
transformation for located events (mouse events, touch events).
BUG=none
TEST=ViewTest.TransformEvent
Review URL: http://codereview.chromium.org/6534015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/events')
-rw-r--r-- | views/events/event.cc | 10 | ||||
-rw-r--r-- | views/events/event.h | 26 |
2 files changed, 36 insertions, 0 deletions
diff --git a/views/events/event.cc b/views/events/event.cc index 2a814bd..49fe29b 100644 --- a/views/events/event.cc +++ b/views/events/event.cc @@ -5,6 +5,7 @@ #include "views/events/event.h" #include "views/view.h" +#include "views/widget/root_view.h" namespace views { @@ -45,6 +46,15 @@ LocatedEvent::LocatedEvent(const LocatedEvent& model, View* from, View* to) } //////////////////////////////////////////////////////////////////////////////// +// LocatedEvent, private: + +LocatedEvent::LocatedEvent(const LocatedEvent& model, RootView* root) + : Event(model), + location_(model.location_) { + View::ConvertPointFromWidget(root, &location_); +} + +//////////////////////////////////////////////////////////////////////////////// // KeyEvent, public: KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, diff --git a/views/events/event.h b/views/events/event.h index 5382573..83f8bbf 100644 --- a/views/events/event.h +++ b/views/events/event.h @@ -24,6 +24,7 @@ using ui::OSExchangeData; namespace views { +class RootView; class View; //////////////////////////////////////////////////////////////////////////////// @@ -145,6 +146,11 @@ class LocatedEvent : public Event { int y() const { return location_.y(); } 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); + private: gfx::Point location_; }; @@ -211,6 +217,12 @@ class MouseEvent : public LocatedEvent { } private: + friend class RootView; + + MouseEvent(const MouseEvent& model, RootView* root) + : LocatedEvent(model, root) { + } + DISALLOW_COPY_AND_ASSIGN(MouseEvent); }; @@ -251,6 +263,13 @@ class TouchEvent : public LocatedEvent { bool identity() const { return touch_id_; } private: + friend class RootView; + + TouchEvent(const TouchEvent& model, RootView* root) + : LocatedEvent(model, root), + touch_id_(model.touch_id_) { + } + // The identity (typically finger) of the touch starting at 0 and incrementing // for each separable additional touch that the hardware can detect. const int touch_id_; @@ -308,6 +327,13 @@ class MouseWheelEvent : public LocatedEvent { int offset() const { return offset_; } private: + friend class RootView; + + MouseWheelEvent(const MouseWheelEvent& model, RootView* root) + : LocatedEvent(model, root), + offset_(model.offset_) { + } + int offset_; DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); |