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

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

Powered by Google App Engine
This is Rietveld 408576698