Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 10 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 return data().touches[index_].radiusY; | 492 return data().touches[index_].radiusY; |
| 493 } | 493 } |
| 494 virtual float RotationAngle() const OVERRIDE { | 494 virtual float RotationAngle() const OVERRIDE { |
| 495 return data().touches[index_].rotationAngle; | 495 return data().touches[index_].rotationAngle; |
| 496 } | 496 } |
| 497 virtual float Force() const OVERRIDE { | 497 virtual float Force() const OVERRIDE { |
| 498 return data().touches[index_].force; | 498 return data().touches[index_].force; |
| 499 } | 499 } |
| 500 | 500 |
| 501 // Returns a copy of the touch event at the specified index. | 501 // Returns a copy of the touch event at the specified index. |
| 502 const LocalTouchEvent& Index( size_t index) { | 502 const LocalTouchEvent& Index( size_t index) const { |
| 503 const int touch_history_size = 40; | 503 const int touch_history_size = 40; |
| 504 static LocalTouchEvent touch_history[touch_history_size]; | 504 static LocalTouchEvent touch_history[touch_history_size]; |
| 505 static int touch_history_index; | 505 static int touch_history_index; |
| 506 int current = (touch_history_index++ % touch_history_size); | 506 int current = (touch_history_index++ % touch_history_size); |
| 507 touch_history[current].data() = data(); | 507 touch_history[current].data() = data(); |
| 508 touch_history[current].index_ = index; | 508 touch_history[current].index_ = index; |
| 509 return touch_history[current]; | 509 return touch_history[current]; |
| 510 } | 510 } |
| 511 | 511 |
| 512 private: | 512 private: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 531 bool ReleaseTouchPoints(); | 531 bool ReleaseTouchPoints(); |
| 532 | 532 |
| 533 // The contained WebTouchEvent. | 533 // The contained WebTouchEvent. |
| 534 const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); } | 534 const WebKit::WebTouchEvent& touch_event() { return touch_event_.data(); } |
| 535 const LocalTouchEvent* ui_touch_event() { return &touch_event_; } | 535 const LocalTouchEvent* ui_touch_event() { return &touch_event_; } |
| 536 | 536 |
| 537 // Returns if any touches are modified in the event. | 537 // Returns if any touches are modified in the event. |
| 538 bool is_changed() { return touch_event_.data().changedTouchesLength != 0; } | 538 bool is_changed() { return touch_event_.data().changedTouchesLength != 0; } |
| 539 | 539 |
| 540 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) { | 540 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) { |
| 541 if (touch_event_.data().touchesLength > 0) | |
| 542 touch_count_.push( touch_event_.data().touchesLength); | |
|
sadrul
2012/07/05 17:00:54
no space after (
girard
2012/07/05 18:43:44
Done.
| |
| 541 for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) { | 543 for (size_t i = 0; i < touch_event_.data().touchesLength; ++i) { |
| 542 gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i)); | 544 gr->QueueTouchEventForGesture(consumer, touch_event_.Index(i)); |
| 543 } | 545 } |
| 544 } | 546 } |
| 545 | 547 |
| 548 int get_touch_count() { | |
|
sadrul
2012/07/05 17:00:54
Perhaps GetNextTouchCount would be a better name f
girard
2012/07/05 18:43:44
Done.
| |
| 549 int result = touch_count_.top(); | |
| 550 touch_count_.pop(); | |
| 551 return result; | |
| 552 } | |
| 553 | |
| 546 private: | 554 private: |
| 547 typedef std::map<unsigned int, int> MapType; | 555 typedef std::map<unsigned int, int> MapType; |
| 548 | 556 |
| 549 // Adds a touch point or returns NULL if there's not enough space. | 557 // Adds a touch point or returns NULL if there's not enough space. |
| 550 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input); | 558 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input); |
| 551 | 559 |
| 552 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning | 560 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning |
| 553 // true if the resulting point is a stationary move. | 561 // true if the resulting point is a stationary move. |
| 554 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point, | 562 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point, |
| 555 TOUCHINPUT* touch_input); | 563 TOUCHINPUT* touch_input); |
| 556 | 564 |
| 557 // Find (or create) a mapping for _os_touch_id_. | 565 // Find (or create) a mapping for _os_touch_id_. |
| 558 unsigned int GetMappedTouch(unsigned int os_touch_id); | 566 unsigned int GetMappedTouch(unsigned int os_touch_id); |
| 559 | 567 |
| 560 // Remove any mappings that are no longer in use. | 568 // Remove any mappings that are no longer in use. |
| 561 void RemoveExpiredMappings(); | 569 void RemoveExpiredMappings(); |
| 562 | 570 |
| 571 // The gesture recognizer processes touch events one at a time, but WebKit | |
| 572 // (ForwardTouchEvent) takes a set of touch events. _touchCount_ tracks how | |
|
sadrul
2012/07/05 17:00:54
|touch_count_| instead of _touchCount_
girard
2012/07/05 18:43:44
Done. Thanks.
| |
| 573 // many individual touch events were sent to ForwardTouchEvent, so we can | |
| 574 // send the correct number of AdvanceTouchQueue's | |
| 575 std::stack<int> touch_count_; | |
| 576 | |
| 563 LocalTouchEvent touch_event_; | 577 LocalTouchEvent touch_event_; |
| 564 const RenderWidgetHostViewWin* const window_; | 578 const RenderWidgetHostViewWin* const window_; |
| 565 | 579 |
| 566 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. | 580 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. |
| 567 // WebKit expects small consecutive integers, starting at 0. | 581 // WebKit expects small consecutive integers, starting at 0. |
| 568 MapType touch_map_; | 582 MapType touch_map_; |
| 569 | 583 |
| 570 DISALLOW_COPY_AND_ASSIGN(WebTouchState); | 584 DISALLOW_COPY_AND_ASSIGN(WebTouchState); |
| 571 }; | 585 }; |
| 572 | 586 |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 callback.Run(result); | 1217 callback.Run(result); |
| 1204 } | 1218 } |
| 1205 | 1219 |
| 1206 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { | 1220 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { |
| 1207 content::RenderWidgetHostViewBase::SetBackground(background); | 1221 content::RenderWidgetHostViewBase::SetBackground(background); |
| 1208 render_widget_host_->SetBackground(background); | 1222 render_widget_host_->SetBackground(background); |
| 1209 } | 1223 } |
| 1210 | 1224 |
| 1211 void RenderWidgetHostViewWin::ProcessTouchAck( | 1225 void RenderWidgetHostViewWin::ProcessTouchAck( |
| 1212 WebKit::WebInputEvent::Type type, bool processed) { | 1226 WebKit::WebInputEvent::Type type, bool processed) { |
| 1213 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 1227 |
| 1214 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed)); | 1228 DCHECK(render_widget_host_->has_touch_handler() && |
| 1215 ProcessGestures(gestures.get()); | 1229 touch_events_enabled_); |
| 1230 | |
| 1231 int touchCount = touch_state_->get_touch_count(); | |
| 1232 for (int i = 0; i < touchCount; ++i) { | |
| 1233 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | |
| 1234 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed)); | |
| 1235 ProcessGestures(gestures.get()); | |
| 1236 } | |
| 1216 | 1237 |
| 1217 if (type == WebKit::WebInputEvent::TouchStart) | 1238 if (type == WebKit::WebInputEvent::TouchStart) |
| 1218 UpdateDesiredTouchMode(processed); | 1239 UpdateDesiredTouchMode(processed); |
| 1219 } | 1240 } |
| 1220 | 1241 |
| 1221 void RenderWidgetHostViewWin::SetToGestureMode() { | 1242 void RenderWidgetHostViewWin::SetToGestureMode() { |
| 1222 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 1243 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 1223 return; | 1244 return; |
| 1224 UnregisterTouchWindow(m_hWnd); | 1245 UnregisterTouchWindow(m_hWnd); |
| 1225 // Single finger panning is consistent with other windows applications. | 1246 // Single finger panning is consistent with other windows applications. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1580 void RenderWidgetHostViewWin::OnSetFocus(HWND window) { | 1601 void RenderWidgetHostViewWin::OnSetFocus(HWND window) { |
| 1581 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnSetFocus"); | 1602 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnSetFocus"); |
| 1582 if (!render_widget_host_) | 1603 if (!render_widget_host_) |
| 1583 return; | 1604 return; |
| 1584 | 1605 |
| 1585 if (GetBrowserAccessibilityManager()) | 1606 if (GetBrowserAccessibilityManager()) |
| 1586 GetBrowserAccessibilityManager()->GotFocus(); | 1607 GetBrowserAccessibilityManager()->GotFocus(); |
| 1587 | 1608 |
| 1588 render_widget_host_->GotFocus(); | 1609 render_widget_host_->GotFocus(); |
| 1589 render_widget_host_->SetActive(true); | 1610 render_widget_host_->SetActive(true); |
| 1590 | |
| 1591 if (touch_state_->ReleaseTouchPoints() && touch_events_enabled_) | |
| 1592 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); | |
| 1593 } | 1611 } |
| 1594 | 1612 |
| 1595 void RenderWidgetHostViewWin::OnKillFocus(HWND window) { | 1613 void RenderWidgetHostViewWin::OnKillFocus(HWND window) { |
| 1596 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnKillFocus"); | 1614 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnKillFocus"); |
| 1597 if (!render_widget_host_) | 1615 if (!render_widget_host_) |
| 1598 return; | 1616 return; |
| 1599 | 1617 |
| 1600 render_widget_host_->SetActive(false); | 1618 render_widget_host_->SetActive(false); |
| 1601 render_widget_host_->Blur(); | 1619 render_widget_host_->Blur(); |
| 1602 | |
| 1603 if (touch_state_->ReleaseTouchPoints() && touch_events_enabled_) | |
| 1604 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); | |
| 1605 } | 1620 } |
| 1606 | 1621 |
| 1607 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) { | 1622 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) { |
| 1608 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCaptureChanged"); | 1623 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCaptureChanged"); |
| 1609 if (render_widget_host_) | 1624 if (render_widget_host_) |
| 1610 render_widget_host_->LostCapture(); | 1625 render_widget_host_->LostCapture(); |
| 1611 } | 1626 } |
| 1612 | 1627 |
| 1613 void RenderWidgetHostViewWin::OnCancelMode() { | 1628 void RenderWidgetHostViewWin::OnCancelMode() { |
| 1614 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCancelMode"); | 1629 TRACE_EVENT0("browser", "RenderWidgetHostViewWin::OnCancelMode"); |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2290 return 0; | 2305 return 0; |
| 2291 } | 2306 } |
| 2292 | 2307 |
| 2293 bool has_touch_handler = render_widget_host_->has_touch_handler() && | 2308 bool has_touch_handler = render_widget_host_->has_touch_handler() && |
| 2294 touch_events_enabled_; | 2309 touch_events_enabled_; |
| 2295 | 2310 |
| 2296 // Send a copy of the touch events on to the gesture recognizer. | 2311 // Send a copy of the touch events on to the gesture recognizer. |
| 2297 for (size_t start = 0; start < total;) { | 2312 for (size_t start = 0; start < total;) { |
| 2298 start += touch_state_->UpdateTouchPoints(points + start, total - start); | 2313 start += touch_state_->UpdateTouchPoints(points + start, total - start); |
| 2299 if (has_touch_handler) { | 2314 if (has_touch_handler) { |
| 2300 if (touch_state_->is_changed()) | 2315 if (touch_state_->is_changed()) { |
| 2301 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); | 2316 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); |
| 2302 touch_state_->QueueEvents(this,gesture_recognizer_.get()); | 2317 touch_state_->QueueEvents(this,gesture_recognizer_.get()); |
|
sadrul
2012/07/05 17:00:54
space after ,
| |
| 2318 } | |
| 2303 } else { | 2319 } else { |
| 2304 // TODO: This probably needs to be updated to call Next() | 2320 const LocalTouchEvent *touch_event = touch_state_->ui_touch_event(); |
|
sadrul
2012/07/05 17:00:54
'LocatedTouchEvent* touch_event'
| |
| 2305 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 2321 for (size_t i = 0; i < touch_event->data().touchesLength; ++i) { |
| 2306 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( | 2322 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
| 2307 *touch_state_->ui_touch_event(), ui::TOUCH_STATUS_UNKNOWN, this)); | 2323 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
| 2308 ProcessGestures(gestures.get()); | 2324 touch_event->Index(i), ui::TOUCH_STATUS_UNKNOWN, this)); |
| 2325 this->ProcessGestures(gestures.get()); | |
|
sadrul
2012/07/05 17:00:54
Is this |this->| bit necessary here?
girard
2012/07/05 18:43:44
Nope. Removed.
| |
| 2326 } | |
| 2309 } | 2327 } |
| 2310 } | 2328 } |
| 2311 | 2329 |
| 2312 CloseTouchInputHandle((HTOUCHINPUT)lparam); | 2330 CloseTouchInputHandle((HTOUCHINPUT)lparam); |
| 2313 | 2331 |
| 2314 return 0; | 2332 return 0; |
| 2315 } | 2333 } |
| 2316 | 2334 |
| 2317 void RenderWidgetHostViewWin::ProcessGestures( | 2335 void RenderWidgetHostViewWin::ProcessGestures( |
| 2318 ui::GestureRecognizer::Gestures* gestures) { | 2336 ui::GestureRecognizer::Gestures* gestures) { |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3165 void RenderWidgetHostViewWin::ResetPointerDownContext() { | 3183 void RenderWidgetHostViewWin::ResetPointerDownContext() { |
| 3166 // If the default focus on the page is on an edit field and we did not | 3184 // If the default focus on the page is on an edit field and we did not |
| 3167 // receive a focus change in the context of a pointer down message, it means | 3185 // 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 | 3186 // that the pointer down message occurred on the edit field and we should |
| 3169 // display the on screen keyboard | 3187 // display the on screen keyboard |
| 3170 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 3188 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
| 3171 DisplayOnScreenKeyboardIfNeeded(); | 3189 DisplayOnScreenKeyboardIfNeeded(); |
| 3172 received_focus_change_after_pointer_down_ = false; | 3190 received_focus_change_after_pointer_down_ = false; |
| 3173 pointer_down_context_ = false; | 3191 pointer_down_context_ = false; |
| 3174 } | 3192 } |
| OLD | NEW |