summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/renderer_host/render_widget_host_view_win.cc173
-rw-r--r--ui/base/event.h16
2 files changed, 74 insertions, 115 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc
index 3de8d20..56dfab5 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.cc
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc
@@ -51,6 +51,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderline.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFactory.h"
+#include "ui/base/event.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/base/text/text_elider.h"
@@ -305,9 +306,6 @@ class WrappedObject : public IINTERFACE {
public:
WrappedObject() {
}
- WrappedObject(const PAYLOAD &copy)
- : data_(copy) {
- }
const PAYLOAD& data() const {
return data_;
}
@@ -459,78 +457,23 @@ class LocalGestureEvent :
DISALLOW_COPY_AND_ASSIGN(LocalGestureEvent);
};
-class LocalTouchEvent :
- public WrappedObject<ui::TouchEvent, WebKit::WebTouchEvent> {
+class TouchEventFromWebTouchPoint : public ui::TouchEventImpl {
public:
- LocalTouchEvent() : index_(0) {}
- LocalTouchEvent(
- ui::EventType type,
- const gfx::Point& location,
- int touch_id,
- base::TimeDelta time_stamp) :
- index_(0) {
- data().type = ConvertToWebInputEvent(type);
- data().timeStampSeconds = time_stamp.InSecondsF();
- }
-
- LocalTouchEvent(const WebKit::WebTouchEvent& copy,
- ui::EventType type,
- base::TimeDelta time_stamp,
- size_t index = 0) :
- WrappedObject<ui::TouchEvent, WebKit::WebTouchEvent>(copy),
- index_(index) {
- data().type = ConvertToWebInputEvent(type);
- DCHECK(copy.touchesLength > index) << "Undefined touch point.";
- data().timeStampSeconds = time_stamp.InSecondsF();
- }
-
- // TODO: make these functions non-virtual post http://crbug.com/125937
- virtual ui::EventType GetEventType() const OVERRIDE {
- return ConvertToUIEvent(data().touches[index_].state);
- }
- virtual gfx::Point GetLocation() const OVERRIDE {
- return data().touches[index_].position;
- }
- virtual int GetTouchId() const OVERRIDE {
- return data().touches[index_].id;
- }
- virtual int GetEventFlags() const OVERRIDE {
- return 0;
- }
- virtual base::TimeDelta GetTimestamp() const OVERRIDE {
- return base::TimeDelta::FromMilliseconds( 1000 * data().timeStampSeconds);
- }
- void SetTimestamp(base::TimeDelta t) {
- data().timeStampSeconds = t.InSecondsF();
- }
- virtual float RadiusX() const OVERRIDE {
- return data().touches[index_].radiusX;
- }
- virtual float RadiusY() const OVERRIDE {
- return data().touches[index_].radiusY;
- }
- virtual float RotationAngle() const OVERRIDE {
- return data().touches[index_].rotationAngle;
- }
- virtual float Force() const OVERRIDE {
- return data().touches[index_].force;
+ TouchEventFromWebTouchPoint(const WebKit::WebTouchPoint& touch_point,
+ base::TimeDelta& timestamp)
+ : ui::TouchEventImpl(ConvertToUIEvent(touch_point.state),
+ touch_point.position,
+ touch_point.id,
+ timestamp) {
+ set_radius(touch_point.radiusX, touch_point.radiusY);
+ set_rotation_angle(touch_point.rotationAngle);
+ set_force(touch_point.force);
}
- // Returns a copy of the touch event at the specified index.
- const LocalTouchEvent& Index( size_t index) const {
- const int touch_history_size = 40;
- static LocalTouchEvent touch_history[touch_history_size];
- static int touch_history_index;
- int current = (touch_history_index++ % touch_history_size);
- touch_history[current].data() = data();
- touch_history[current].index_ = index;
- return touch_history[current];
- }
+ virtual ~TouchEventFromWebTouchPoint() {}
private:
- size_t index_;
-
- DISALLOW_COPY_AND_ASSIGN(LocalTouchEvent);
+ DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint);
};
} // namespace
@@ -551,17 +494,19 @@ class WebTouchState {
bool ReleaseTouchPoints();
// The contained WebTouchEvent.
- const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); }
- const LocalTouchEvent* ui_touch_event() { return &touch_event_; }
+ const WebKit::WebTouchEvent& touch_event() { return touch_event_; }
// Returns if any touches are modified in the event.
- bool is_changed() { return touch_event_.data().changedTouchesLength != 0; }
+ bool is_changed() { return touch_event_.changedTouchesLength != 0; }
void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) {
- if (touch_event_.data().touchesLength > 0)
- touch_count_.push(touch_event_.data().touchesLength);
- for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) {
- gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i));
+ if (touch_event_.touchesLength > 0)
+ touch_count_.push(touch_event_.touchesLength);
+ base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(
+ touch_event_.timeStampSeconds * 1000);
+ for (size_t i = 0; i < touch_event_.touchesLength; ++i) {
+ gr->QueueTouchEventForGesture(consumer,
+ TouchEventFromWebTouchPoint(touch_event_.touches[i], timestamp));
}
}
@@ -595,7 +540,7 @@ class WebTouchState {
// send the correct number of AdvanceTouchQueue's
std::stack<int> touch_count_;
- LocalTouchEvent touch_event_;
+ WebKit::WebTouchEvent touch_event_;
const RenderWidgetHostViewWin* const window_;
// Maps OS touch Id's into an internal (WebKit-friendly) touch-id.
@@ -1314,7 +1259,7 @@ ui::TouchEvent* RenderWidgetHostViewWin::CreateTouchEvent(
const gfx::Point& location,
int touch_id,
base::TimeDelta time_stamp) {
- return new LocalTouchEvent(type, location, touch_id, time_stamp);
+ return new ui::TouchEventImpl(type, location, touch_id, time_stamp);
}
bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent(
@@ -1327,9 +1272,10 @@ bool RenderWidgetHostViewWin::DispatchCancelTouchEvent(
if (!render_widget_host_ || !touch_events_enabled_)
return false;
DCHECK(event->GetEventType() == WebKit::WebInputEvent::TouchCancel);
- LocalTouchEvent touchEvent(event->GetEventType(),
- event->GetLocation(), event->GetTouchId(), event->GetTimestamp());
- render_widget_host_->ForwardTouchEvent(touchEvent.data());
+ WebKit::WebTouchEvent cancel_event;
+ cancel_event.type = WebKit::WebInputEvent::TouchCancel;
+ cancel_event.timeStampSeconds = event->GetTimestamp().InSecondsF();
+ render_widget_host_->ForwardTouchEvent(cancel_event);
return true;
}
@@ -2101,18 +2047,18 @@ size_t WebTouchState::UpdateTouchPoints(
// and alter/add any touchpoints (from the touch input buffer) that we can
// coalesce into a single message. The return value is the number of consumed
// input message.
- WebKit::WebTouchPoint* point = touch_event_.data().touches;
- WebKit::WebTouchPoint* end = point + touch_event_.data().touchesLength;
+ WebKit::WebTouchPoint* point = touch_event_.touches;
+ WebKit::WebTouchPoint* end = point + touch_event_.touchesLength;
while (point < end) {
if (point->state == WebKit::WebTouchPoint::StateReleased) {
*point = *(--end);
- --touch_event_.data().touchesLength;
+ --touch_event_.touchesLength;
} else {
point->state = WebKit::WebTouchPoint::StateStationary;
point++;
}
}
- touch_event_.data().changedTouchesLength = 0;
+ touch_event_.changedTouchesLength = 0;
// Consume all events of the same type and add them to the changed list.
int last_type = 0;
@@ -2120,9 +2066,9 @@ size_t WebTouchState::UpdateTouchPoints(
unsigned int mapped_id = GetMappedTouch(points[i].dwID);
WebKit::WebTouchPoint* point = NULL;
- for (unsigned j = 0; j < touch_event_.data().touchesLength; ++j) {
- if (static_cast<DWORD>(touch_event_.data().touches[j].id) == mapped_id) {
- point = &touch_event_.data().touches[j];
+ for (unsigned j = 0; j < touch_event_.touchesLength; ++j) {
+ if (static_cast<DWORD>(touch_event_.touches[j].id) == mapped_id) {
+ point = &touch_event_.touches[j];
break;
}
}
@@ -2133,18 +2079,17 @@ size_t WebTouchState::UpdateTouchPoints(
SetTouchType(&points[i], TOUCHEVENTF_MOVE);
// Stop processing when the event type changes.
- if (touch_event_.data().changedTouchesLength && type != last_type)
+ if (touch_event_.changedTouchesLength && type != last_type)
return i;
- touch_event_.SetTimestamp(
- base::TimeDelta::FromMilliseconds(points[i].dwTime));
+ touch_event_.timeStampSeconds = points[i].dwTime / 1000.0;
last_type = type;
switch (type) {
case TOUCHEVENTF_DOWN: {
if (!(point = AddTouchPoint(&points[i])))
continue;
- touch_event_.data().type = WebKit::WebInputEvent::TouchStart;
+ touch_event_.type = WebKit::WebInputEvent::TouchStart;
break;
}
@@ -2153,7 +2098,7 @@ size_t WebTouchState::UpdateTouchPoints(
continue;
point->state = WebKit::WebTouchPoint::StateReleased;
UpdateTouchPoint(point, &points[i]);
- touch_event_.data().type = WebKit::WebInputEvent::TouchEnd;
+ touch_event_.type = WebKit::WebInputEvent::TouchEnd;
break;
}
@@ -2163,8 +2108,8 @@ size_t WebTouchState::UpdateTouchPoints(
// Don't update the message if the point didn't really move.
if (UpdateTouchPoint(point, &points[i]))
continue;
- touch_event_.data().type = WebKit::WebInputEvent::TouchMove;
- } else if (touch_event_.data().changedTouchesLength) {
+ touch_event_.type = WebKit::WebInputEvent::TouchMove;
+ } else if (touch_event_.changedTouchesLength) {
RemoveExpiredMappings();
// Can't add a point if we're already handling move events.
return i;
@@ -2174,7 +2119,7 @@ size_t WebTouchState::UpdateTouchPoints(
continue;
last_type = TOUCHEVENTF_DOWN;
SetTouchType(&points[i], TOUCHEVENTF_DOWN);
- touch_event_.data().type = WebKit::WebInputEvent::TouchStart;
+ touch_event_.type = WebKit::WebInputEvent::TouchStart;
}
break;
}
@@ -2183,8 +2128,7 @@ size_t WebTouchState::UpdateTouchPoints(
NOTREACHED();
continue;
}
- touch_event_.data().changedTouches[
- touch_event_.data().changedTouchesLength++] = *point;
+ touch_event_.changedTouches[touch_event_.changedTouchesLength++] = *point;
}
RemoveExpiredMappings();
@@ -2196,8 +2140,8 @@ void WebTouchState::RemoveExpiredMappings() {
for (MapType::iterator it = touch_map_.begin();
it != touch_map_.end();
++it) {
- WebKit::WebTouchPoint* point = touch_event_.data().touches;
- WebKit::WebTouchPoint* end = point + touch_event_.data().touchesLength;
+ WebKit::WebTouchPoint* point = touch_event_.touches;
+ WebKit::WebTouchPoint* end = point + touch_event_.touchesLength;
while (point < end) {
if ((point->id == it->second) &&
(point->state != WebKit::WebTouchPoint::StateReleased)) {
@@ -2212,14 +2156,14 @@ void WebTouchState::RemoveExpiredMappings() {
bool WebTouchState::ReleaseTouchPoints() {
- if (touch_event_.data().touchesLength == 0)
+ if (touch_event_.touchesLength == 0)
return false;
// Mark every active touchpoint as released.
- touch_event_.data().type = WebKit::WebInputEvent::TouchEnd;
- touch_event_.data().changedTouchesLength = touch_event_.data().touchesLength;
- for (unsigned int i = 0; i < touch_event_.data().touchesLength; ++i) {
- touch_event_.data().touches[i].state = WebKit::WebTouchPoint::StateReleased;
- touch_event_.data().changedTouches[i].state =
+ touch_event_.type = WebKit::WebInputEvent::TouchEnd;
+ touch_event_.changedTouchesLength = touch_event_.touchesLength;
+ for (unsigned int i = 0; i < touch_event_.touchesLength; ++i) {
+ touch_event_.touches[i].state = WebKit::WebTouchPoint::StateReleased;
+ touch_event_.changedTouches[i].state =
WebKit::WebTouchPoint::StateReleased;
}
@@ -2228,13 +2172,13 @@ bool WebTouchState::ReleaseTouchPoints() {
WebKit::WebTouchPoint* WebTouchState::AddTouchPoint(
TOUCHINPUT* touch_input) {
- DCHECK(touch_event_.data().touchesLength <
+ DCHECK(touch_event_.touchesLength <
WebKit::WebTouchEvent::touchesLengthCap);
- if (touch_event_.data().touchesLength >=
+ if (touch_event_.touchesLength >=
WebKit::WebTouchEvent::touchesLengthCap)
return NULL;
WebKit::WebTouchPoint* point =
- &touch_event_.data().touches[touch_event_.data().touchesLength++];
+ &touch_event_.touches[touch_event_.touchesLength++];
point->state = WebKit::WebTouchPoint::StatePressed;
point->id = GetMappedTouch(touch_input->dwID);
UpdateTouchPoint(point, touch_input);
@@ -2313,11 +2257,14 @@ LRESULT RenderWidgetHostViewWin::OnTouchEvent(UINT message, WPARAM wparam,
touch_state_->QueueEvents(this, gesture_recognizer_.get());
}
} else {
- const LocalTouchEvent* touch_event = touch_state_->ui_touch_event();
- for (size_t i = 0; i < touch_event->data().touchesLength; ++i) {
+ const WebKit::WebTouchEvent& touch_event = touch_state_->touch_event();
+ base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(
+ touch_event.timeStampSeconds * 1000);
+ for (size_t i = 0; i < touch_event.touchesLength; ++i) {
scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(
- touch_event->Index(i), ui::TOUCH_STATUS_UNKNOWN, this));
+ TouchEventFromWebTouchPoint(touch_event.touches[i], timestamp),
+ ui::TOUCH_STATUS_UNKNOWN, this));
ProcessGestures(gestures.get());
}
}
diff --git a/ui/base/event.h b/ui/base/event.h
index 86d5488..4cd59cb 100644
--- a/ui/base/event.h
+++ b/ui/base/event.h
@@ -242,6 +242,18 @@ class UI_EXPORT TouchEventImpl : public LocatedEvent,
virtual float RotationAngle() const OVERRIDE;
virtual float Force() const OVERRIDE;
+ protected:
+ void set_radius(float radius_x, float radius_y) {
+ radius_x_ = radius_x;
+ radius_y_ = radius_y;
+ }
+
+ void set_rotation_angle(float rotation_angle) {
+ rotation_angle_ = rotation_angle;
+ }
+
+ void set_force(float force) { force_ = force; }
+
private:
// The identity (typically finger) of the touch starting at 0 and incrementing
// for each separable additional touch that the hardware can detect.
@@ -254,10 +266,10 @@ class UI_EXPORT TouchEventImpl : public LocatedEvent,
float radius_y_;
// Angle of the major axis away from the X axis. Default 0.0.
- const float rotation_angle_;
+ float rotation_angle_;
// Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
- const float force_;
+ float force_;
DISALLOW_COPY_AND_ASSIGN(TouchEventImpl);
};