Commit d8f09f33 authored by girard@chromium.org's avatar girard@chromium.org

Adding Gesture Recognition to RenderWidgetHostViewWin (web client)

Gesture and Touch events are now passed into the content window. 
This is only enabled if --enable-touch-events is flagged on the command line.

BUG=124938
TEST=


Review URL: https://chromiumcodereview.appspot.com/10365009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137920 0039d316-1c4b-4281-b951-d872f2087c98
parent 44727621
......@@ -24,6 +24,8 @@
#include "content/common/content_export.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/gestures/gesture_recognizer.h"
#include "ui/base/gestures/gesture_types.h"
#include "ui/base/win/ime_input.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
......@@ -32,6 +34,7 @@
class BackingStore;
class SkRegion;
class WebTouchState;
namespace content {
class RenderWidgetHost;
......@@ -92,7 +95,9 @@ class RenderWidgetHostViewWin
RenderWidgetHostHWNDTraits>,
public content::RenderWidgetHostViewBase,
public content::NotificationObserver,
public BrowserAccessibilityDelegate {
public BrowserAccessibilityDelegate,
public ui::GestureConsumer,
public ui::GestureEventHelper {
public:
virtual ~RenderWidgetHostViewWin();
......@@ -240,6 +245,23 @@ class RenderWidgetHostViewWin
virtual void AccessibilitySetTextSelection(
int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
// Overridden from ui::GestureEventHelper.
virtual ui::GestureEvent* CreateGestureEvent(
ui::EventType type,
const gfx::Point& location,
int flags,
base::Time time,
float param_first,
float param_second,
unsigned int touch_id_bitfield) OVERRIDE;
virtual ui::TouchEvent* CreateTouchEvent(
ui::EventType type,
const gfx::Point& location,
int touch_id,
base::TimeDelta time_stamp) OVERRIDE;
virtual bool DispatchLongPressGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual bool DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
protected:
friend class content::RenderWidgetHostView;
......@@ -325,6 +347,13 @@ class RenderWidgetHostViewWin
// becomes hidden, this method is called to reset the tooltip.
void ResetTooltip();
// Builds and forwards a WebKitGestureEvent to the renderer.
bool ForwardGestureEventToRenderer(
ui::GestureEvent* gesture);
// Process all of the given gestures (passes them on to renderer)
void ProcessGestures(ui::GestureRecognizer::Gestures* gestures);
// Sends the specified mouse event to the renderer.
void ForwardMouseEventToRenderer(UINT message, WPARAM wparam, LPARAM lparam);
......@@ -425,42 +454,10 @@ class RenderWidgetHostViewWin
// true if the View is not visible.
bool is_hidden_;
// Wrapper for maintaining touchstate associated with a WebTouchEvent.
class WebTouchState {
public:
explicit WebTouchState(const CWindowImpl* window);
// Updates the current touchpoint state with the supplied touches.
// Touches will be consumed only if they are of the same type (e.g. down,
// up, move). Returns the number of consumed touches.
size_t UpdateTouchPoints(TOUCHINPUT* points, size_t count);
// Marks all active touchpoints as released.
bool ReleaseTouchPoints();
// The contained WebTouchEvent.
const WebKit::WebTouchEvent& touch_event() { return touch_event_; }
// Returns if any touches are modified in the event.
bool is_changed() { return touch_event_.changedTouchesLength != 0; }
private:
// Adds a touch point or returns NULL if there's not enough space.
WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input);
// Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning
// true if the resulting point is a stationary move.
bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point,
TOUCHINPUT* touch_input);
WebKit::WebTouchEvent touch_event_;
const CWindowImpl* const window_;
};
// The touch-state. Its touch-points are updated as necessary. A new
// touch-point is added from an TOUCHEVENTF_DOWN message, and a touch-point
// is removed from the list on an TOUCHEVENTF_UP message.
WebTouchState touch_state_;
scoped_ptr<WebTouchState> touch_state_;
// True if we're in the midst of a paint operation and should respond to
// DidPaintRect() notifications by merely invalidating. See comments on
......@@ -567,6 +564,8 @@ class RenderWidgetHostViewWin
// Are touch events currently enabled?
bool touch_events_enabled_;
scoped_ptr<ui::GestureRecognizer> gesture_recognizer_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewWin);
};
......
......@@ -371,7 +371,7 @@ class AURA_EXPORT GestureEvent : public LocatedEvent,
float delta_y,
unsigned int touch_ids_bitfield);
// Create a new TouchEvent which is identical to the provided model.
// Create a new GestureEvent which is identical to the provided model.
// If source / target windows are provided, the model location will be
// converted from |source| coordinate system to |target| coordinate system.
GestureEvent(const GestureEvent& model, Window* source, Window* target);
......
......@@ -862,7 +862,7 @@ bool RootWindow::DispatchCancelTouchEvent(ui::TouchEvent* event) {
ui::GestureEvent* RootWindow::CreateGestureEvent(ui::EventType type,
const gfx::Point& location,
int flags,
const base::Time time,
base::Time time,
float param_first,
float param_second,
unsigned int touch_id_bitfield) {
......
......@@ -292,18 +292,20 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
virtual internal::FocusManager* GetFocusManager() OVERRIDE;
// Overridden from ui::GestureEventHelper.
virtual ui::GestureEvent* CreateGestureEvent(ui::EventType type,
virtual ui::GestureEvent* CreateGestureEvent(
ui::EventType type,
const gfx::Point& location,
int flags,
const base::Time time,
base::Time time,
float param_first,
float param_second,
unsigned int touch_id_bitfield) OVERRIDE;
virtual ui::TouchEvent* CreateTouchEvent(ui::EventType type,
const gfx::Point& location,
int touch_id,
base::TimeDelta time_stamp) OVERRIDE;
virtual ui::TouchEvent* CreateTouchEvent(
ui::EventType type,
const gfx::Point& location,
int touch_id,
base::TimeDelta time_stamp) OVERRIDE;
virtual bool DispatchLongPressGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual bool DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
......
......@@ -40,6 +40,15 @@ class UI_EXPORT GestureEvent {
// A gesture event can have multiple touches. This function should return the
// lowest ID of the touches in this gesture.
virtual int GetLowestTouchId() const = 0;
// A helper function used in several (all) derived classes.
// Returns lowest set bit, or -1 if no bits are set.
static int LowestBit(unsigned int bitfield) {
int i = -1;
// Find the index of the least significant 1 bit
while (bitfield && (!((1 << ++i) & bitfield)));
return i;
}
};
// An abstract type for consumers of gesture-events created by the
......@@ -76,7 +85,7 @@ class UI_EXPORT GestureEventHelper {
virtual GestureEvent* CreateGestureEvent(EventType type,
const gfx::Point& location,
int flags,
const base::Time time,
base::Time time,
float param_first,
float param_second,
unsigned int touch_id_bitfield) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment