Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_views_touch.cc

Issue 7206055: Add an option to run Chrome in the views desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
6
7 static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__";
8
9 using WebKit::WebInputEventFactory;
10 using WebKit::WebMouseWheelEvent;
11 using WebKit::WebTouchEvent;
12
13 namespace {
14
15 WebKit::WebTouchPoint::State TouchPointStateFromEvent(
16 const views::TouchEvent* event) {
17 switch (event->type()) {
18 case ui::ET_TOUCH_PRESSED:
19 return WebKit::WebTouchPoint::StatePressed;
20 case ui::ET_TOUCH_RELEASED:
21 return WebKit::WebTouchPoint::StateReleased;
22 case ui::ET_TOUCH_MOVED:
23 return WebKit::WebTouchPoint::StateMoved;
24 case ui::ET_TOUCH_CANCELLED:
25 return WebKit::WebTouchPoint::StateCancelled;
26 default:
27 return WebKit::WebTouchPoint::StateUndefined;
28 }
29 }
30
31 WebKit::WebInputEvent::Type TouchEventTypeFromEvent(
32 const views::TouchEvent* event) {
33 switch (event->type()) {
34 case ui::ET_TOUCH_PRESSED:
35 return WebKit::WebInputEvent::TouchStart;
36 case ui::ET_TOUCH_RELEASED:
37 return WebKit::WebInputEvent::TouchEnd;
38 case ui::ET_TOUCH_MOVED:
39 return WebKit::WebInputEvent::TouchMove;
40 case ui::ET_TOUCH_CANCELLED:
41 return WebKit::WebInputEvent::TouchCancel;
42 default:
43 return WebKit::WebInputEvent::Undefined;
44 }
45 }
46
47 inline void UpdateTouchParams(const views::TouchEvent& event,
48 WebKit::WebTouchPoint* tpoint) {
49 tpoint->radiusX = event.radius_x();
50 tpoint->radiusY = event.radius_y();
51 tpoint->rotationAngle = event.rotation_angle();
52 tpoint->force = event.force();
53 }
54
55 void UpdateTouchPointPosition(const views::TouchEvent* event,
56 const gfx::Point& origin,
57 WebKit::WebTouchPoint* tpoint) {
58 tpoint->position.x = event->x();
59 tpoint->position.y = event->y();
60
61 tpoint->screenPosition.x = tpoint->position.x + origin.x();
62 tpoint->screenPosition.y = tpoint->position.y + origin.y();
63 }
64
65 } // namespace
66
67 // static
68 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
69 RenderWidgetHost* widget) {
70 return new RenderWidgetHostViewViews(widget);
71 }
72
73 ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent(
74 const views::TouchEvent& event) {
75 if (!host_)
76 return ui::TOUCH_STATUS_UNKNOWN;
77
78 // Update the list of touch points first.
79 WebKit::WebTouchPoint* point = NULL;
80 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN;
81
82 switch (event.type()) {
83 case ui::ET_TOUCH_PRESSED:
84 // Add a new touch point.
85 if (touch_event_.touchPointsLength <
86 WebTouchEvent::touchPointsLengthCap) {
87 point = &touch_event_.touchPoints[touch_event_.touchPointsLength++];
88 point->id = event.identity();
89
90 if (touch_event_.touchPointsLength == 1) {
91 // A new touch sequence has started.
92 status = ui::TOUCH_STATUS_START;
93
94 // We also want the focus.
95 RequestFocus();
96
97 // Confirm existing composition text on touch press events, to make
98 // sure the input caret won't be moved with an ongoing composition
99 // text.
100 FinishImeCompositionSession();
101 }
102 }
103 break;
104 case ui::ET_TOUCH_RELEASED:
105 case ui::ET_TOUCH_CANCELLED:
106 case ui::ET_TOUCH_MOVED: {
107 // The touch point should have been added to the event from an earlier
108 // _PRESSED event. So find that.
109 // At the moment, only a maximum of 4 touch-points are allowed. So a
110 // simple loop should be sufficient.
111 for (int i = 0; i < touch_event_.touchPointsLength; ++i) {
112 point = touch_event_.touchPoints + i;
113 if (point->id == event.identity()) {
114 break;
115 }
116 point = NULL;
117 }
118 break;
119 }
120 default:
121 DLOG(WARNING) << "Unknown touch event " << event.type();
122 break;
123 }
124
125 if (!point)
126 return ui::TOUCH_STATUS_UNKNOWN;
127
128 if (status != ui::TOUCH_STATUS_START)
129 status = ui::TOUCH_STATUS_CONTINUE;
130
131 UpdateTouchParams(event, point);
132
133 // Update the location and state of the point.
134 point->state = TouchPointStateFromEvent(&event);
135 if (point->state == WebKit::WebTouchPoint::StateMoved) {
136 // It is possible for badly written touch drivers to emit Move events even
137 // when the touch location hasn't changed. In such cases, consume the event
138 // and pretend nothing happened.
139 if (point->position.x == event.x() && point->position.y == event.y()) {
140 return status;
141 }
142 }
143 UpdateTouchPointPosition(&event, GetMirroredPosition(), point);
144
145 // Mark the rest of the points as stationary.
146 for (int i = 0; i < touch_event_.touchPointsLength; ++i) {
147 WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i;
148 if (iter != point) {
149 iter->state = WebKit::WebTouchPoint::StateStationary;
150 }
151 }
152
153 // Update the type of the touch event.
154 touch_event_.type = TouchEventTypeFromEvent(&event);
155 touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT();
156
157 // The event and all the touches have been updated. Dispatch.
158 host_->ForwardTouchEvent(touch_event_);
159
160 // If the touch was released, then remove it from the list of touch points.
161 if (event.type() == ui::ET_TOUCH_RELEASED) {
162 --touch_event_.touchPointsLength;
163 for (int i = point - touch_event_.touchPoints;
164 i < touch_event_.touchPointsLength;
165 ++i) {
166 touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1];
167 }
168 if (touch_event_.touchPointsLength == 0)
169 status = ui::TOUCH_STATUS_END;
170 } else if (event.type() == ui::ET_TOUCH_CANCELLED) {
171 status = ui::TOUCH_STATUS_CANCEL;
172 }
173
174 return status;
175 }
176
177 // static
178 RenderWidgetHostView*
179 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView(
180 gfx::NativeView widget) {
181 // TODO(beng): Figure out what to do here for Windows/v.o.v.
182 gpointer user_data = g_object_get_data(G_OBJECT(widget),
183 kRenderWidgetHostViewKey);
184 return reinterpret_cast<RenderWidgetHostView*>(user_data);
185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698