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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_win.cc

Issue 10832230: gestures: Cleanup touch-event handling code in Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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
« no previous file with comments | « no previous file | ui/base/event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_win.h" 5 #include "content/browser/renderer_host/render_widget_host_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <peninputpanel_i.c> 9 #include <peninputpanel_i.c>
10 #include <stack> 10 #include <stack>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
45 #include "content/public/browser/notification_types.h" 45 #include "content/public/browser/notification_types.h"
46 #include "content/public/common/content_switches.h" 46 #include "content/public/common/content_switches.h"
47 #include "content/public/common/page_zoom.h" 47 #include "content/public/common/page_zoom.h"
48 #include "content/public/common/process_type.h" 48 #include "content/public/common/process_type.h"
49 #include "skia/ext/skia_utils_win.h" 49 #include "skia/ext/skia_utils_win.h"
50 #include "third_party/skia/include/core/SkRegion.h" 50 #include "third_party/skia/include/core/SkRegion.h"
51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
53 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h" 53 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h"
54 #include "ui/base/event.h"
54 #include "ui/base/ime/composition_text.h" 55 #include "ui/base/ime/composition_text.h"
55 #include "ui/base/l10n/l10n_util_win.h" 56 #include "ui/base/l10n/l10n_util_win.h"
56 #include "ui/base/text/text_elider.h" 57 #include "ui/base/text/text_elider.h"
57 #include "ui/base/ui_base_switches.h" 58 #include "ui/base/ui_base_switches.h"
58 #include "ui/base/view_prop.h" 59 #include "ui/base/view_prop.h"
59 #include "ui/base/win/hwnd_util.h" 60 #include "ui/base/win/hwnd_util.h"
60 #include "ui/base/win/mouse_wheel_util.h" 61 #include "ui/base/win/mouse_wheel_util.h"
61 #include "ui/gfx/canvas.h" 62 #include "ui/gfx/canvas.h"
62 #include "ui/gfx/gdi_util.h" 63 #include "ui/gfx/gdi_util.h"
63 #include "ui/gfx/rect.h" 64 #include "ui/gfx/rect.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 299
299 inline void SetTouchType(TOUCHINPUT* point, int type) { 300 inline void SetTouchType(TOUCHINPUT* point, int type) {
300 point->dwFlags = (point->dwFlags & kTouchMask) | type; 301 point->dwFlags = (point->dwFlags & kTouchMask) | type;
301 } 302 }
302 303
303 template <class IINTERFACE, class PAYLOAD> 304 template <class IINTERFACE, class PAYLOAD>
304 class WrappedObject : public IINTERFACE { 305 class WrappedObject : public IINTERFACE {
305 public: 306 public:
306 WrappedObject() { 307 WrappedObject() {
307 } 308 }
308 WrappedObject(const PAYLOAD &copy)
309 : data_(copy) {
310 }
311 const PAYLOAD& data() const { 309 const PAYLOAD& data() const {
312 return data_; 310 return data_;
313 } 311 }
314 PAYLOAD& data() { 312 PAYLOAD& data() {
315 return data_; 313 return data_;
316 } 314 }
317 315
318 private: 316 private:
319 PAYLOAD data_; 317 PAYLOAD data_;
320 318
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // |touch_ids_bitfield_| is the set of touch_ids associate with this gesture. 450 // |touch_ids_bitfield_| is the set of touch_ids associate with this gesture.
453 // This value is stored as a bitfield because the number of touch ids varies, 451 // This value is stored as a bitfield because the number of touch ids varies,
454 // but we currently don't need more than 32 touches at a time. 452 // but we currently don't need more than 32 touches at a time.
455 const unsigned int touch_ids_bitfield_; 453 const unsigned int touch_ids_bitfield_;
456 454
457 ui::EventType type_; 455 ui::EventType type_;
458 456
459 DISALLOW_COPY_AND_ASSIGN(LocalGestureEvent); 457 DISALLOW_COPY_AND_ASSIGN(LocalGestureEvent);
460 }; 458 };
461 459
462 class LocalTouchEvent : 460 class TouchEventFromWebTouchPoint : public ui::TouchEventImpl {
463 public WrappedObject<ui::TouchEvent, WebKit::WebTouchEvent> {
464 public: 461 public:
465 LocalTouchEvent() : index_(0) {} 462 TouchEventFromWebTouchPoint(const WebKit::WebTouchPoint& touch_point,
466 LocalTouchEvent( 463 base::TimeDelta& timestamp)
467 ui::EventType type, 464 : ui::TouchEventImpl(ConvertToUIEvent(touch_point.state),
468 const gfx::Point& location, 465 touch_point.position,
469 int touch_id, 466 touch_point.id,
470 base::TimeDelta time_stamp) : 467 timestamp) {
471 index_(0) { 468 set_radius(touch_point.radiusX, touch_point.radiusY);
472 data().type = ConvertToWebInputEvent(type); 469 set_rotation_angle(touch_point.rotationAngle);
473 data().timeStampSeconds = time_stamp.InSecondsF(); 470 set_force(touch_point.force);
474 } 471 }
475 472
476 LocalTouchEvent(const WebKit::WebTouchEvent& copy, 473 virtual ~TouchEventFromWebTouchPoint() {}
477 ui::EventType type,
478 base::TimeDelta time_stamp,
479 size_t index = 0) :
480 WrappedObject<ui::TouchEvent, WebKit::WebTouchEvent>(copy),
481 index_(index) {
482 data().type = ConvertToWebInputEvent(type);
483 DCHECK(copy.touchesLength > index) << "Undefined touch point.";
484 data().timeStampSeconds = time_stamp.InSecondsF();
485 }
486
487 // TODO: make these functions non-virtual post http://crbug.com/125937
488 virtual ui::EventType GetEventType() const OVERRIDE {
489 return ConvertToUIEvent(data().touches[index_].state);
490 }
491 virtual gfx::Point GetLocation() const OVERRIDE {
492 return data().touches[index_].position;
493 }
494 virtual int GetTouchId() const OVERRIDE {
495 return data().touches[index_].id;
496 }
497 virtual int GetEventFlags() const OVERRIDE {
498 return 0;
499 }
500 virtual base::TimeDelta GetTimestamp() const OVERRIDE {
501 return base::TimeDelta::FromMilliseconds( 1000 * data().timeStampSeconds);
502 }
503 void SetTimestamp(base::TimeDelta t) {
504 data().timeStampSeconds = t.InSecondsF();
505 }
506 virtual float RadiusX() const OVERRIDE {
507 return data().touches[index_].radiusX;
508 }
509 virtual float RadiusY() const OVERRIDE {
510 return data().touches[index_].radiusY;
511 }
512 virtual float RotationAngle() const OVERRIDE {
513 return data().touches[index_].rotationAngle;
514 }
515 virtual float Force() const OVERRIDE {
516 return data().touches[index_].force;
517 }
518
519 // Returns a copy of the touch event at the specified index.
520 const LocalTouchEvent& Index( size_t index) const {
521 const int touch_history_size = 40;
522 static LocalTouchEvent touch_history[touch_history_size];
523 static int touch_history_index;
524 int current = (touch_history_index++ % touch_history_size);
525 touch_history[current].data() = data();
526 touch_history[current].index_ = index;
527 return touch_history[current];
528 }
529 474
530 private: 475 private:
531 size_t index_; 476 DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint);
532
533 DISALLOW_COPY_AND_ASSIGN(LocalTouchEvent);
534 }; 477 };
535 478
536 } // namespace 479 } // namespace
537 480
538 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; 481 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND";
539 482
540 // Wrapper for maintaining touchstate associated with a WebTouchEvent. 483 // Wrapper for maintaining touchstate associated with a WebTouchEvent.
541 class WebTouchState { 484 class WebTouchState {
542 public: 485 public:
543 explicit WebTouchState(const RenderWidgetHostViewWin* window); 486 explicit WebTouchState(const RenderWidgetHostViewWin* window);
544 487
545 // Updates the current touchpoint state with the supplied touches. 488 // Updates the current touchpoint state with the supplied touches.
546 // Touches will be consumed only if they are of the same type (e.g. down, 489 // Touches will be consumed only if they are of the same type (e.g. down,
547 // up, move). Returns the number of consumed touches. 490 // up, move). Returns the number of consumed touches.
548 size_t UpdateTouchPoints(TOUCHINPUT* points, size_t count); 491 size_t UpdateTouchPoints(TOUCHINPUT* points, size_t count);
549 492
550 // Marks all active touchpoints as released. 493 // Marks all active touchpoints as released.
551 bool ReleaseTouchPoints(); 494 bool ReleaseTouchPoints();
552 495
553 // The contained WebTouchEvent. 496 // The contained WebTouchEvent.
554 const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); } 497 const WebKit::WebTouchEvent& touch_event() { return touch_event_; }
555 const LocalTouchEvent* ui_touch_event() { return &touch_event_; }
556 498
557 // Returns if any touches are modified in the event. 499 // Returns if any touches are modified in the event.
558 bool is_changed() { return touch_event_.data().changedTouchesLength != 0; } 500 bool is_changed() { return touch_event_.changedTouchesLength != 0; }
559 501
560 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) { 502 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) {
561 if (touch_event_.data().touchesLength > 0) 503 if (touch_event_.touchesLength > 0)
562 touch_count_.push(touch_event_.data().touchesLength); 504 touch_count_.push(touch_event_.touchesLength);
563 for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) { 505 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(
564 gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i)); 506 touch_event_.timeStampSeconds * 1000);
507 for (size_t i = 0; i < touch_event_.touchesLength; ++i) {
508 gr->QueueTouchEventForGesture(consumer,
509 TouchEventFromWebTouchPoint(touch_event_.touches[i], timestamp));
565 } 510 }
566 } 511 }
567 512
568 int GetNextTouchCount() { 513 int GetNextTouchCount() {
569 DCHECK(!touch_count_.empty()); 514 DCHECK(!touch_count_.empty());
570 int result = touch_count_.top(); 515 int result = touch_count_.top();
571 touch_count_.pop(); 516 touch_count_.pop();
572 return result; 517 return result;
573 } 518 }
574 519
(...skipping 13 matching lines...) Expand all
588 533
589 // Remove any mappings that are no longer in use. 534 // Remove any mappings that are no longer in use.
590 void RemoveExpiredMappings(); 535 void RemoveExpiredMappings();
591 536
592 // The gesture recognizer processes touch events one at a time, but WebKit 537 // The gesture recognizer processes touch events one at a time, but WebKit
593 // (ForwardTouchEvent) takes a set of touch events. |touchCount_| tracks how 538 // (ForwardTouchEvent) takes a set of touch events. |touchCount_| tracks how
594 // many individual touch events were sent to ForwardTouchEvent, so we can 539 // many individual touch events were sent to ForwardTouchEvent, so we can
595 // send the correct number of AdvanceTouchQueue's 540 // send the correct number of AdvanceTouchQueue's
596 std::stack<int> touch_count_; 541 std::stack<int> touch_count_;
597 542
598 LocalTouchEvent touch_event_; 543 WebKit::WebTouchEvent touch_event_;
599 const RenderWidgetHostViewWin* const window_; 544 const RenderWidgetHostViewWin* const window_;
600 545
601 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. 546 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id.
602 // WebKit expects small consecutive integers, starting at 0. 547 // WebKit expects small consecutive integers, starting at 0.
603 MapType touch_map_; 548 MapType touch_map_;
604 549
605 DISALLOW_COPY_AND_ASSIGN(WebTouchState); 550 DISALLOW_COPY_AND_ASSIGN(WebTouchState);
606 }; 551 };
607 552
608 /////////////////////////////////////////////////////////////////////////////// 553 ///////////////////////////////////////////////////////////////////////////////
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 unsigned int touch_id_bitfield) { 1252 unsigned int touch_id_bitfield) {
1308 return new LocalGestureEvent(m_hWnd, details, location, flags, time, 1253 return new LocalGestureEvent(m_hWnd, details, location, flags, time,
1309 touch_id_bitfield); 1254 touch_id_bitfield);
1310 } 1255 }
1311 1256
1312 ui::TouchEvent* RenderWidgetHostViewWin::CreateTouchEvent( 1257 ui::TouchEvent* RenderWidgetHostViewWin::CreateTouchEvent(
1313 ui::EventType type, 1258 ui::EventType type,
1314 const gfx::Point& location, 1259 const gfx::Point& location,
1315 int touch_id, 1260 int touch_id,
1316 base::TimeDelta time_stamp) { 1261 base::TimeDelta time_stamp) {
1317 return new LocalTouchEvent(type, location, touch_id, time_stamp); 1262 return new ui::TouchEventImpl(type, location, touch_id, time_stamp);
1318 } 1263 }
1319 1264
1320 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent( 1265 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent(
1321 ui::GestureEvent* event) { 1266 ui::GestureEvent* event) {
1322 return ForwardGestureEventToRenderer(event); 1267 return ForwardGestureEventToRenderer(event);
1323 } 1268 }
1324 1269
1325 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent( 1270 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent(
1326 ui::TouchEvent* event) { 1271 ui::TouchEvent* event) {
1327 if (!render_widget_host_ || !touch_events_enabled_) 1272 if (!render_widget_host_ || !touch_events_enabled_)
1328 return false; 1273 return false;
1329 DCHECK(event->GetEventType() == WebKit::WebInputEvent::TouchCancel); 1274 DCHECK(event->GetEventType() == WebKit::WebInputEvent::TouchCancel);
1330 LocalTouchEvent touchEvent(event->GetEventType(), 1275 WebKit::WebTouchEvent cancel_event;
1331 event->GetLocation(), event->GetTouchId(), event->GetTimestamp()); 1276 cancel_event.type = WebKit::WebInputEvent::TouchCancel;
1332 render_widget_host_->ForwardTouchEvent(touchEvent.data()); 1277 cancel_event.timeStampSeconds = event->GetTimestamp().InSecondsF();
1278 render_widget_host_->ForwardTouchEvent(cancel_event);
1333 return true; 1279 return true;
1334 } 1280 }
1335 1281
1336 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( 1282 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar(
1337 bool has_horizontal_scrollbar) { 1283 bool has_horizontal_scrollbar) {
1338 } 1284 }
1339 1285
1340 void RenderWidgetHostViewWin::SetScrollOffsetPinning( 1286 void RenderWidgetHostViewWin::SetScrollOffsetPinning(
1341 bool is_pinned_to_left, bool is_pinned_to_right) { 1287 bool is_pinned_to_left, bool is_pinned_to_right) {
1342 } 1288 }
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 WebTouchState::WebTouchState(const RenderWidgetHostViewWin* window) 2040 WebTouchState::WebTouchState(const RenderWidgetHostViewWin* window)
2095 : window_(window) { } 2041 : window_(window) { }
2096 2042
2097 size_t WebTouchState::UpdateTouchPoints( 2043 size_t WebTouchState::UpdateTouchPoints(
2098 TOUCHINPUT* points, size_t count) { 2044 TOUCHINPUT* points, size_t count) {
2099 // First we reset all touch event state. This involves removing any released 2045 // First we reset all touch event state. This involves removing any released
2100 // touchpoints and marking the rest as stationary. After that we go through 2046 // touchpoints and marking the rest as stationary. After that we go through
2101 // and alter/add any touchpoints (from the touch input buffer) that we can 2047 // and alter/add any touchpoints (from the touch input buffer) that we can
2102 // coalesce into a single message. The return value is the number of consumed 2048 // coalesce into a single message. The return value is the number of consumed
2103 // input message. 2049 // input message.
2104 WebKit::WebTouchPoint* point = touch_event_.data().touches; 2050 WebKit::WebTouchPoint* point = touch_event_.touches;
2105 WebKit::WebTouchPoint* end = point + touch_event_.data().touchesLength; 2051 WebKit::WebTouchPoint* end = point + touch_event_.touchesLength;
2106 while (point < end) { 2052 while (point < end) {
2107 if (point->state == WebKit::WebTouchPoint::StateReleased) { 2053 if (point->state == WebKit::WebTouchPoint::StateReleased) {
2108 *point = *(--end); 2054 *point = *(--end);
2109 --touch_event_.data().touchesLength; 2055 --touch_event_.touchesLength;
2110 } else { 2056 } else {
2111 point->state = WebKit::WebTouchPoint::StateStationary; 2057 point->state = WebKit::WebTouchPoint::StateStationary;
2112 point++; 2058 point++;
2113 } 2059 }
2114 } 2060 }
2115 touch_event_.data().changedTouchesLength = 0; 2061 touch_event_.changedTouchesLength = 0;
2116 2062
2117 // Consume all events of the same type and add them to the changed list. 2063 // Consume all events of the same type and add them to the changed list.
2118 int last_type = 0; 2064 int last_type = 0;
2119 for (size_t i = 0; i < count; ++i) { 2065 for (size_t i = 0; i < count; ++i) {
2120 unsigned int mapped_id = GetMappedTouch(points[i].dwID); 2066 unsigned int mapped_id = GetMappedTouch(points[i].dwID);
2121 2067
2122 WebKit::WebTouchPoint* point = NULL; 2068 WebKit::WebTouchPoint* point = NULL;
2123 for (unsigned j = 0; j < touch_event_.data().touchesLength; ++j) { 2069 for (unsigned j = 0; j < touch_event_.touchesLength; ++j) {
2124 if (static_cast<DWORD>(touch_event_.data().touches[j].id) == mapped_id) { 2070 if (static_cast<DWORD>(touch_event_.touches[j].id) == mapped_id) {
2125 point = &touch_event_.data().touches[j]; 2071 point = &touch_event_.touches[j];
2126 break; 2072 break;
2127 } 2073 }
2128 } 2074 }
2129 2075
2130 // Use a move instead if we see a down on a point we already have. 2076 // Use a move instead if we see a down on a point we already have.
2131 int type = GetTouchType(points[i]); 2077 int type = GetTouchType(points[i]);
2132 if (point && type == TOUCHEVENTF_DOWN) 2078 if (point && type == TOUCHEVENTF_DOWN)
2133 SetTouchType(&points[i], TOUCHEVENTF_MOVE); 2079 SetTouchType(&points[i], TOUCHEVENTF_MOVE);
2134 2080
2135 // Stop processing when the event type changes. 2081 // Stop processing when the event type changes.
2136 if (touch_event_.data().changedTouchesLength && type != last_type) 2082 if (touch_event_.changedTouchesLength && type != last_type)
2137 return i; 2083 return i;
2138 2084
2139 touch_event_.SetTimestamp( 2085 touch_event_.timeStampSeconds = points[i].dwTime / 1000.0;
2140 base::TimeDelta::FromMilliseconds(points[i].dwTime));
2141 2086
2142 last_type = type; 2087 last_type = type;
2143 switch (type) { 2088 switch (type) {
2144 case TOUCHEVENTF_DOWN: { 2089 case TOUCHEVENTF_DOWN: {
2145 if (!(point = AddTouchPoint(&points[i]))) 2090 if (!(point = AddTouchPoint(&points[i])))
2146 continue; 2091 continue;
2147 touch_event_.data().type = WebKit::WebInputEvent::TouchStart; 2092 touch_event_.type = WebKit::WebInputEvent::TouchStart;
2148 break; 2093 break;
2149 } 2094 }
2150 2095
2151 case TOUCHEVENTF_UP: { 2096 case TOUCHEVENTF_UP: {
2152 if (!point) // Just throw away a stray up. 2097 if (!point) // Just throw away a stray up.
2153 continue; 2098 continue;
2154 point->state = WebKit::WebTouchPoint::StateReleased; 2099 point->state = WebKit::WebTouchPoint::StateReleased;
2155 UpdateTouchPoint(point, &points[i]); 2100 UpdateTouchPoint(point, &points[i]);
2156 touch_event_.data().type = WebKit::WebInputEvent::TouchEnd; 2101 touch_event_.type = WebKit::WebInputEvent::TouchEnd;
2157 break; 2102 break;
2158 } 2103 }
2159 2104
2160 case TOUCHEVENTF_MOVE: { 2105 case TOUCHEVENTF_MOVE: {
2161 if (point) { 2106 if (point) {
2162 point->state = WebKit::WebTouchPoint::StateMoved; 2107 point->state = WebKit::WebTouchPoint::StateMoved;
2163 // Don't update the message if the point didn't really move. 2108 // Don't update the message if the point didn't really move.
2164 if (UpdateTouchPoint(point, &points[i])) 2109 if (UpdateTouchPoint(point, &points[i]))
2165 continue; 2110 continue;
2166 touch_event_.data().type = WebKit::WebInputEvent::TouchMove; 2111 touch_event_.type = WebKit::WebInputEvent::TouchMove;
2167 } else if (touch_event_.data().changedTouchesLength) { 2112 } else if (touch_event_.changedTouchesLength) {
2168 RemoveExpiredMappings(); 2113 RemoveExpiredMappings();
2169 // Can't add a point if we're already handling move events. 2114 // Can't add a point if we're already handling move events.
2170 return i; 2115 return i;
2171 } else { 2116 } else {
2172 // Treat a move with no existing point as a down. 2117 // Treat a move with no existing point as a down.
2173 if (!(point = AddTouchPoint(&points[i]))) 2118 if (!(point = AddTouchPoint(&points[i])))
2174 continue; 2119 continue;
2175 last_type = TOUCHEVENTF_DOWN; 2120 last_type = TOUCHEVENTF_DOWN;
2176 SetTouchType(&points[i], TOUCHEVENTF_DOWN); 2121 SetTouchType(&points[i], TOUCHEVENTF_DOWN);
2177 touch_event_.data().type = WebKit::WebInputEvent::TouchStart; 2122 touch_event_.type = WebKit::WebInputEvent::TouchStart;
2178 } 2123 }
2179 break; 2124 break;
2180 } 2125 }
2181 2126
2182 default: 2127 default:
2183 NOTREACHED(); 2128 NOTREACHED();
2184 continue; 2129 continue;
2185 } 2130 }
2186 touch_event_.data().changedTouches[ 2131 touch_event_.changedTouches[touch_event_.changedTouchesLength++] = *point;
2187 touch_event_.data().changedTouchesLength++] = *point;
2188 } 2132 }
2189 2133
2190 RemoveExpiredMappings(); 2134 RemoveExpiredMappings();
2191 return count; 2135 return count;
2192 } 2136 }
2193 2137
2194 void WebTouchState::RemoveExpiredMappings() { 2138 void WebTouchState::RemoveExpiredMappings() {
2195 WebTouchState::MapType new_map; 2139 WebTouchState::MapType new_map;
2196 for (MapType::iterator it = touch_map_.begin(); 2140 for (MapType::iterator it = touch_map_.begin();
2197 it != touch_map_.end(); 2141 it != touch_map_.end();
2198 ++it) { 2142 ++it) {
2199 WebKit::WebTouchPoint* point = touch_event_.data().touches; 2143 WebKit::WebTouchPoint* point = touch_event_.touches;
2200 WebKit::WebTouchPoint* end = point + touch_event_.data().touchesLength; 2144 WebKit::WebTouchPoint* end = point + touch_event_.touchesLength;
2201 while (point < end) { 2145 while (point < end) {
2202 if ((point->id == it->second) && 2146 if ((point->id == it->second) &&
2203 (point->state != WebKit::WebTouchPoint::StateReleased)) { 2147 (point->state != WebKit::WebTouchPoint::StateReleased)) {
2204 new_map.insert(*it); 2148 new_map.insert(*it);
2205 break; 2149 break;
2206 } 2150 }
2207 point++; 2151 point++;
2208 } 2152 }
2209 } 2153 }
2210 touch_map_.swap(new_map); 2154 touch_map_.swap(new_map);
2211 } 2155 }
2212 2156
2213 2157
2214 bool WebTouchState::ReleaseTouchPoints() { 2158 bool WebTouchState::ReleaseTouchPoints() {
2215 if (touch_event_.data().touchesLength == 0) 2159 if (touch_event_.touchesLength == 0)
2216 return false; 2160 return false;
2217 // Mark every active touchpoint as released. 2161 // Mark every active touchpoint as released.
2218 touch_event_.data().type = WebKit::WebInputEvent::TouchEnd; 2162 touch_event_.type = WebKit::WebInputEvent::TouchEnd;
2219 touch_event_.data().changedTouchesLength = touch_event_.data().touchesLength; 2163 touch_event_.changedTouchesLength = touch_event_.touchesLength;
2220 for (unsigned int i = 0; i < touch_event_.data().touchesLength; ++i) { 2164 for (unsigned int i = 0; i < touch_event_.touchesLength; ++i) {
2221 touch_event_.data().touches[i].state = WebKit::WebTouchPoint::StateReleased; 2165 touch_event_.touches[i].state = WebKit::WebTouchPoint::StateReleased;
2222 touch_event_.data().changedTouches[i].state = 2166 touch_event_.changedTouches[i].state =
2223 WebKit::WebTouchPoint::StateReleased; 2167 WebKit::WebTouchPoint::StateReleased;
2224 } 2168 }
2225 2169
2226 return true; 2170 return true;
2227 } 2171 }
2228 2172
2229 WebKit::WebTouchPoint* WebTouchState::AddTouchPoint( 2173 WebKit::WebTouchPoint* WebTouchState::AddTouchPoint(
2230 TOUCHINPUT* touch_input) { 2174 TOUCHINPUT* touch_input) {
2231 DCHECK(touch_event_.data().touchesLength < 2175 DCHECK(touch_event_.touchesLength <
2232 WebKit::WebTouchEvent::touchesLengthCap); 2176 WebKit::WebTouchEvent::touchesLengthCap);
2233 if (touch_event_.data().touchesLength >= 2177 if (touch_event_.touchesLength >=
2234 WebKit::WebTouchEvent::touchesLengthCap) 2178 WebKit::WebTouchEvent::touchesLengthCap)
2235 return NULL; 2179 return NULL;
2236 WebKit::WebTouchPoint* point = 2180 WebKit::WebTouchPoint* point =
2237 &touch_event_.data().touches[touch_event_.data().touchesLength++]; 2181 &touch_event_.touches[touch_event_.touchesLength++];
2238 point->state = WebKit::WebTouchPoint::StatePressed; 2182 point->state = WebKit::WebTouchPoint::StatePressed;
2239 point->id = GetMappedTouch(touch_input->dwID); 2183 point->id = GetMappedTouch(touch_input->dwID);
2240 UpdateTouchPoint(point, touch_input); 2184 UpdateTouchPoint(point, touch_input);
2241 return point; 2185 return point;
2242 } 2186 }
2243 2187
2244 bool WebTouchState::UpdateTouchPoint( 2188 bool WebTouchState::UpdateTouchPoint(
2245 WebKit::WebTouchPoint* touch_point, 2189 WebKit::WebTouchPoint* touch_point,
2246 TOUCHINPUT* touch_input) { 2190 TOUCHINPUT* touch_input) {
2247 CPoint coordinates(TOUCH_COORD_TO_PIXEL(touch_input->x), 2191 CPoint coordinates(TOUCH_COORD_TO_PIXEL(touch_input->x),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 2250
2307 // Send a copy of the touch events on to the gesture recognizer. 2251 // Send a copy of the touch events on to the gesture recognizer.
2308 for (size_t start = 0; start < total;) { 2252 for (size_t start = 0; start < total;) {
2309 start += touch_state_->UpdateTouchPoints(points + start, total - start); 2253 start += touch_state_->UpdateTouchPoints(points + start, total - start);
2310 if (has_touch_handler) { 2254 if (has_touch_handler) {
2311 if (touch_state_->is_changed()) { 2255 if (touch_state_->is_changed()) {
2312 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); 2256 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event());
2313 touch_state_->QueueEvents(this, gesture_recognizer_.get()); 2257 touch_state_->QueueEvents(this, gesture_recognizer_.get());
2314 } 2258 }
2315 } else { 2259 } else {
2316 const LocalTouchEvent* touch_event = touch_state_->ui_touch_event(); 2260 const WebKit::WebTouchEvent& touch_event = touch_state_->touch_event();
2317 for (size_t i = 0; i < touch_event->data().touchesLength; ++i) { 2261 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds(
2262 touch_event.timeStampSeconds * 1000);
2263 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
2318 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 2264 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
2319 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( 2265 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(
2320 touch_event->Index(i), ui::TOUCH_STATUS_UNKNOWN, this)); 2266 TouchEventFromWebTouchPoint(touch_event.touches[i], timestamp),
2267 ui::TOUCH_STATUS_UNKNOWN, this));
2321 ProcessGestures(gestures.get()); 2268 ProcessGestures(gestures.get());
2322 } 2269 }
2323 } 2270 }
2324 } 2271 }
2325 2272
2326 CloseTouchInputHandle((HTOUCHINPUT)lparam); 2273 CloseTouchInputHandle((HTOUCHINPUT)lparam);
2327 2274
2328 return 0; 2275 return 0;
2329 } 2276 }
2330 2277
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
3167 // receive a focus change in the context of a pointer down message, it means 3114 // receive a focus change in the context of a pointer down message, it means
3168 // that the pointer down message occurred on the edit field and we should 3115 // that the pointer down message occurred on the edit field and we should
3169 // display the on screen keyboard 3116 // display the on screen keyboard
3170 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) 3117 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_)
3171 DisplayOnScreenKeyboardIfNeeded(); 3118 DisplayOnScreenKeyboardIfNeeded();
3172 received_focus_change_after_pointer_down_ = false; 3119 received_focus_change_after_pointer_down_ = false;
3173 pointer_down_context_ = false; 3120 pointer_down_context_ = false;
3174 } 3121 }
3175 3122
3176 } // namespace content 3123 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | ui/base/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698