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

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

Issue 10702096: Corrected issues with queued touch events. This fixes gestures in Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix build breakage. Adding a missing header. Created 8 years, 5 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
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.cc » ('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 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
15 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/process_util.h" 18 #include "base/process_util.h"
18 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
19 #include "base/win/metro.h" 20 #include "base/win/metro.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return data().touches[index_].radiusY; 493 return data().touches[index_].radiusY;
493 } 494 }
494 virtual float RotationAngle() const OVERRIDE { 495 virtual float RotationAngle() const OVERRIDE {
495 return data().touches[index_].rotationAngle; 496 return data().touches[index_].rotationAngle;
496 } 497 }
497 virtual float Force() const OVERRIDE { 498 virtual float Force() const OVERRIDE {
498 return data().touches[index_].force; 499 return data().touches[index_].force;
499 } 500 }
500 501
501 // Returns a copy of the touch event at the specified index. 502 // Returns a copy of the touch event at the specified index.
502 const LocalTouchEvent& Index( size_t index) { 503 const LocalTouchEvent& Index( size_t index) const {
503 const int touch_history_size = 40; 504 const int touch_history_size = 40;
504 static LocalTouchEvent touch_history[touch_history_size]; 505 static LocalTouchEvent touch_history[touch_history_size];
505 static int touch_history_index; 506 static int touch_history_index;
506 int current = (touch_history_index++ % touch_history_size); 507 int current = (touch_history_index++ % touch_history_size);
507 touch_history[current].data() = data(); 508 touch_history[current].data() = data();
508 touch_history[current].index_ = index; 509 touch_history[current].index_ = index;
509 return touch_history[current]; 510 return touch_history[current];
510 } 511 }
511 512
512 private: 513 private:
(...skipping 18 matching lines...) Expand all
531 bool ReleaseTouchPoints(); 532 bool ReleaseTouchPoints();
532 533
533 // The contained WebTouchEvent. 534 // The contained WebTouchEvent.
534 const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); } 535 const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); }
535 const LocalTouchEvent* ui_touch_event() { return &touch_event_; } 536 const LocalTouchEvent* ui_touch_event() { return &touch_event_; }
536 537
537 // Returns if any touches are modified in the event. 538 // Returns if any touches are modified in the event.
538 bool is_changed() { return touch_event_.data().changedTouchesLength != 0; } 539 bool is_changed() { return touch_event_.data().changedTouchesLength != 0; }
539 540
540 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) { 541 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) {
542 if (touch_event_.data().touchesLength > 0)
543 touch_count_.push(touch_event_.data().touchesLength);
541 for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) { 544 for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) {
542 gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i)); 545 gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i));
543 } 546 }
544 } 547 }
545 548
549 int GetNextTouchCount() {
550 int result = touch_count_.top();
551 touch_count_.pop();
552 return result;
553 }
554
546 private: 555 private:
547 typedef std::map<unsigned int, int> MapType; 556 typedef std::map<unsigned int, int> MapType;
548 557
549 // Adds a touch point or returns NULL if there's not enough space. 558 // Adds a touch point or returns NULL if there's not enough space.
550 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input); 559 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input);
551 560
552 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning 561 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning
553 // true if the resulting point is a stationary move. 562 // true if the resulting point is a stationary move.
554 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point, 563 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point,
555 TOUCHINPUT* touch_input); 564 TOUCHINPUT* touch_input);
556 565
557 // Find (or create) a mapping for _os_touch_id_. 566 // Find (or create) a mapping for _os_touch_id_.
558 unsigned int GetMappedTouch(unsigned int os_touch_id); 567 unsigned int GetMappedTouch(unsigned int os_touch_id);
559 568
560 // Remove any mappings that are no longer in use. 569 // Remove any mappings that are no longer in use.
561 void RemoveExpiredMappings(); 570 void RemoveExpiredMappings();
562 571
572 // The gesture recognizer processes touch events one at a time, but WebKit
573 // (ForwardTouchEvent) takes a set of touch events. |touchCount_| tracks how
574 // many individual touch events were sent to ForwardTouchEvent, so we can
575 // send the correct number of AdvanceTouchQueue's
576 std::stack<int> touch_count_;
577
563 LocalTouchEvent touch_event_; 578 LocalTouchEvent touch_event_;
564 const RenderWidgetHostViewWin* const window_; 579 const RenderWidgetHostViewWin* const window_;
565 580
566 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. 581 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id.
567 // WebKit expects small consecutive integers, starting at 0. 582 // WebKit expects small consecutive integers, starting at 0.
568 MapType touch_map_; 583 MapType touch_map_;
569 584
570 DISALLOW_COPY_AND_ASSIGN(WebTouchState); 585 DISALLOW_COPY_AND_ASSIGN(WebTouchState);
571 }; 586 };
572 587
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 callback.Run(result); 1203 callback.Run(result);
1189 } 1204 }
1190 1205
1191 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { 1206 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) {
1192 content::RenderWidgetHostViewBase::SetBackground(background); 1207 content::RenderWidgetHostViewBase::SetBackground(background);
1193 render_widget_host_->SetBackground(background); 1208 render_widget_host_->SetBackground(background);
1194 } 1209 }
1195 1210
1196 void RenderWidgetHostViewWin::ProcessTouchAck( 1211 void RenderWidgetHostViewWin::ProcessTouchAck(
1197 WebKit::WebInputEvent::Type type, bool processed) { 1212 WebKit::WebInputEvent::Type type, bool processed) {
1198 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 1213
1199 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed)); 1214 DCHECK(render_widget_host_->has_touch_handler() &&
1200 ProcessGestures(gestures.get()); 1215 touch_events_enabled_);
1216
1217 int touch_count = touch_state_->GetNextTouchCount();
1218 for (int i = 0; i < touch_count; ++i) {
1219 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
1220 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed));
1221 ProcessGestures(gestures.get());
1222 }
1201 1223
1202 if (type == WebKit::WebInputEvent::TouchStart) 1224 if (type == WebKit::WebInputEvent::TouchStart)
1203 UpdateDesiredTouchMode(processed); 1225 UpdateDesiredTouchMode(processed);
1204 } 1226 }
1205 1227
1206 void RenderWidgetHostViewWin::SetToGestureMode() { 1228 void RenderWidgetHostViewWin::SetToGestureMode() {
1207 if (base::win::GetVersion() < base::win::VERSION_WIN7) 1229 if (base::win::GetVersion() < base::win::VERSION_WIN7)
1208 return; 1230 return;
1209 UnregisterTouchWindow(m_hWnd); 1231 UnregisterTouchWindow(m_hWnd);
1210 // Single finger panning is consistent with other windows applications. 1232 // Single finger panning is consistent with other windows applications.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 void RenderWidgetHostViewWin::OnSetFocus(HWND window) { 1587 void RenderWidgetHostViewWin::OnSetFocus(HWND window) {
1566 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnSetFocus"); 1588 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnSetFocus");
1567 if (!render_widget_host_) 1589 if (!render_widget_host_)
1568 return; 1590 return;
1569 1591
1570 if (GetBrowserAccessibilityManager()) 1592 if (GetBrowserAccessibilityManager())
1571 GetBrowserAccessibilityManager()->GotFocus(); 1593 GetBrowserAccessibilityManager()->GotFocus();
1572 1594
1573 render_widget_host_->GotFocus(); 1595 render_widget_host_->GotFocus();
1574 render_widget_host_->SetActive(true); 1596 render_widget_host_->SetActive(true);
1575
1576 if (touch_state_->ReleaseTouchPoints() && touch_events_enabled_)
1577 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event());
1578 } 1597 }
1579 1598
1580 void RenderWidgetHostViewWin::OnKillFocus(HWND window) { 1599 void RenderWidgetHostViewWin::OnKillFocus(HWND window) {
1581 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnKillFocus"); 1600 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnKillFocus");
1582 if (!render_widget_host_) 1601 if (!render_widget_host_)
1583 return; 1602 return;
1584 1603
1585 render_widget_host_->SetActive(false); 1604 render_widget_host_->SetActive(false);
1586 render_widget_host_->Blur(); 1605 render_widget_host_->Blur();
1587
1588 if (touch_state_->ReleaseTouchPoints() && touch_events_enabled_)
1589 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event());
1590 } 1606 }
1591 1607
1592 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) { 1608 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) {
1593 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCaptureChanged"); 1609 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCaptureChanged");
1594 if (render_widget_host_) 1610 if (render_widget_host_)
1595 render_widget_host_->LostCapture(); 1611 render_widget_host_->LostCapture();
1596 } 1612 }
1597 1613
1598 void RenderWidgetHostViewWin::OnCancelMode() { 1614 void RenderWidgetHostViewWin::OnCancelMode() {
1599 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCancelMode"); 1615 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCancelMode");
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 return 0; 2290 return 0;
2275 } 2291 }
2276 2292
2277 bool has_touch_handler = render_widget_host_->has_touch_handler() && 2293 bool has_touch_handler = render_widget_host_->has_touch_handler() &&
2278 touch_events_enabled_; 2294 touch_events_enabled_;
2279 2295
2280 // Send a copy of the touch events on to the gesture recognizer. 2296 // Send a copy of the touch events on to the gesture recognizer.
2281 for (size_t start = 0; start < total;) { 2297 for (size_t start = 0; start < total;) {
2282 start += touch_state_->UpdateTouchPoints(points + start, total - start); 2298 start += touch_state_->UpdateTouchPoints(points + start, total - start);
2283 if (has_touch_handler) { 2299 if (has_touch_handler) {
2284 if (touch_state_->is_changed()) 2300 if (touch_state_->is_changed()) {
2285 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); 2301 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event());
2286 touch_state_->QueueEvents(this,gesture_recognizer_.get()); 2302 touch_state_->QueueEvents(this, gesture_recognizer_.get());
2303 }
2287 } else { 2304 } else {
2288 // TODO: This probably needs to be updated to call Next() 2305 const LocalTouchEvent* touch_event = touch_state_->ui_touch_event();
2289 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 2306 for (size_t i = 0; i < touch_event->data().touchesLength; ++i) {
2290 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( 2307 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
2291 *touch_state_->ui_touch_event(), ui::TOUCH_STATUS_UNKNOWN, this)); 2308 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(
2292 ProcessGestures(gestures.get()); 2309 touch_event->Index(i), ui::TOUCH_STATUS_UNKNOWN, this));
2310 ProcessGestures(gestures.get());
2311 }
2293 } 2312 }
2294 } 2313 }
2295 2314
2296 CloseTouchInputHandle((HTOUCHINPUT)lparam); 2315 CloseTouchInputHandle((HTOUCHINPUT)lparam);
2297 2316
2298 return 0; 2317 return 0;
2299 } 2318 }
2300 2319
2301 void RenderWidgetHostViewWin::ProcessGestures( 2320 void RenderWidgetHostViewWin::ProcessGestures(
2302 ui::GestureRecognizer::Gestures* gestures) { 2321 ui::GestureRecognizer::Gestures* gestures) {
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
3148 void RenderWidgetHostViewWin::ResetPointerDownContext() { 3167 void RenderWidgetHostViewWin::ResetPointerDownContext() {
3149 // If the default focus on the page is on an edit field and we did not 3168 // If the default focus on the page is on an edit field and we did not
3150 // receive a focus change in the context of a pointer down message, it means 3169 // receive a focus change in the context of a pointer down message, it means
3151 // that the pointer down message occurred on the edit field and we should 3170 // that the pointer down message occurred on the edit field and we should
3152 // display the on screen keyboard 3171 // display the on screen keyboard
3153 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) 3172 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_)
3154 DisplayOnScreenKeyboardIfNeeded(); 3173 DisplayOnScreenKeyboardIfNeeded();
3155 received_focus_change_after_pointer_down_ = false; 3174 received_focus_change_after_pointer_down_ = false;
3156 pointer_down_context_ = false; 3175 pointer_down_context_ = false;
3157 } 3176 }
OLDNEW
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698