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

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

Issue 8341125: Forward Windows touch messages to the renderer (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 <vector>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
12 #include "base/process_util.h" 14 #include "base/process_util.h"
13 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
14 #include "base/win/scoped_comptr.h" 16 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_gdi_object.h" 17 #include "base/win/scoped_gdi_object.h"
18 #include "base/win/windows_version.h"
16 #include "base/win/win_util.h" 19 #include "base/win/win_util.h"
17 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
18 #include "base/win/wrapped_window_proc.h" 21 #include "base/win/wrapped_window_proc.h"
19 #include "content/browser/accessibility/browser_accessibility_manager.h" 22 #include "content/browser/accessibility/browser_accessibility_manager.h"
20 #include "content/browser/accessibility/browser_accessibility_state.h" 23 #include "content/browser/accessibility/browser_accessibility_state.h"
21 #include "content/browser/accessibility/browser_accessibility_win.h" 24 #include "content/browser/accessibility/browser_accessibility_win.h"
22 #include "content/browser/plugin_process_host.h" 25 #include "content/browser/plugin_process_host.h"
23 #include "content/browser/renderer_host/backing_store.h" 26 #include "content/browser/renderer_host/backing_store.h"
24 #include "content/browser/renderer_host/backing_store_win.h" 27 #include "content/browser/renderer_host/backing_store_win.h"
25 #include "content/browser/renderer_host/render_process_host.h" 28 #include "content/browser/renderer_host/render_process_host.h"
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 // Single finger panning is consistent with other windows applications. 885 // Single finger panning is consistent with other windows applications.
883 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | 886 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY |
884 GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY; 887 GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
885 const DWORD gesture_block = GC_PAN_WITH_GUTTER; 888 const DWORD gesture_block = GC_PAN_WITH_GUTTER;
886 GESTURECONFIG gc[] = { 889 GESTURECONFIG gc[] = {
887 { GID_ZOOM, GC_ZOOM, 0 }, 890 { GID_ZOOM, GC_ZOOM, 0 },
888 { GID_PAN, gesture_allow , gesture_block}, 891 { GID_PAN, gesture_allow , gesture_block},
889 { GID_TWOFINGERTAP, GC_TWOFINGERTAP , 0}, 892 { GID_TWOFINGERTAP, GC_TWOFINGERTAP , 0},
890 { GID_PRESSANDTAP, GC_PRESSANDTAP , 0} 893 { GID_PRESSANDTAP, GC_PRESSANDTAP , 0}
891 }; 894 };
892 if (!SetGestureConfig(m_hWnd, 0, arraysize(gc), gc, sizeof(GESTURECONFIG))) 895 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
893 { 896 CommandLine::ForCurrentProcess()->HasSwitch(
897 switches::kEnableTouchEvents)) {
898 DCHECK(RegisterTouchWindow(m_hWnd, 0));
cpu_(ooo_6.6-7.5) 2011/11/08 02:34:04 bug: on release RTE is not called.
jschuh 2011/11/08 17:12:41 I'm confused. Are you saying I need a call to Unre
cpu_(ooo_6.6-7.5) 2011/11/08 19:20:14 No. release build. dcheck goes *puff*
899 } else if (!SetGestureConfig(m_hWnd, 0, arraysize(gc), gc,
900 sizeof(GESTURECONFIG))) {
cpu_(ooo_6.6-7.5) 2011/11/08 02:34:04 886 to 893 should be moved inside this block and t
jschuh 2011/11/08 17:12:41 Ugh, merge noise. Sorry, I should have caught that
894 NOTREACHED(); 901 NOTREACHED();
895 } 902 }
896 } 903 }
897 904
898 return 0; 905 return 0;
899 } 906 }
900 907
901 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, 908 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized,
902 HWND window) { 909 HWND window) {
903 // If the container is a popup, clicking elsewhere on screen should close the 910 // If the container is a popup, clicking elsewhere on screen should close the
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 return 0; 1102 return 0;
1096 } 1103 }
1097 1104
1098 void RenderWidgetHostViewWin::OnSetFocus(HWND window) { 1105 void RenderWidgetHostViewWin::OnSetFocus(HWND window) {
1099 if (browser_accessibility_manager_.get()) 1106 if (browser_accessibility_manager_.get())
1100 browser_accessibility_manager_->GotFocus(); 1107 browser_accessibility_manager_->GotFocus();
1101 if (render_widget_host_) { 1108 if (render_widget_host_) {
1102 render_widget_host_->GotFocus(); 1109 render_widget_host_->GotFocus();
1103 render_widget_host_->SetActive(true); 1110 render_widget_host_->SetActive(true);
1104 } 1111 }
1112 FinishTouchEvent();
1105 } 1113 }
1106 1114
1107 void RenderWidgetHostViewWin::OnKillFocus(HWND window) { 1115 void RenderWidgetHostViewWin::OnKillFocus(HWND window) {
1108 if (render_widget_host_) { 1116 if (render_widget_host_) {
1109 render_widget_host_->SetActive(false); 1117 render_widget_host_->SetActive(false);
1110 render_widget_host_->Blur(); 1118 render_widget_host_->Blur();
1111 } 1119 }
1120 FinishTouchEvent();
1112 } 1121 }
1113 1122
1114 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) { 1123 void RenderWidgetHostViewWin::OnCaptureChanged(HWND window) {
1115 if (render_widget_host_) 1124 if (render_widget_host_)
1116 render_widget_host_->LostCapture(); 1125 render_widget_host_->LostCapture();
1117 } 1126 }
1118 1127
1119 void RenderWidgetHostViewWin::OnCancelMode() { 1128 void RenderWidgetHostViewWin::OnCancelMode() {
1120 if (render_widget_host_) 1129 if (render_widget_host_)
1121 render_widget_host_->LostCapture(); 1130 render_widget_host_->LostCapture();
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1572
1564 if (!handled_by_TabContents && render_widget_host_) { 1573 if (!handled_by_TabContents && render_widget_host_) {
1565 render_widget_host_->ForwardWheelEvent( 1574 render_widget_host_->ForwardWheelEvent(
1566 WebInputEventFactory::mouseWheelEvent(m_hWnd, message, wparam, 1575 WebInputEventFactory::mouseWheelEvent(m_hWnd, message, wparam,
1567 lparam)); 1576 lparam));
1568 } 1577 }
1569 handled = TRUE; 1578 handled = TRUE;
1570 return 0; 1579 return 0;
1571 } 1580 }
1572 1581
1582 void RenderWidgetHostViewWin::FinishTouchEvent() {
1583 if (touch_event_.touchesLength == 0)
1584 return;
1585
1586 // Release all active touchpoints.
1587 for (unsigned int i = 0; i < touch_event_.touchesLength; ++i) {
1588 touch_event_.touches[i].state = WebKit::WebTouchPoint::StateReleased;
1589 touch_event_.changedTouches[i].state =
1590 WebKit::WebTouchPoint::StateReleased;
1591 }
1592 touch_event_.changedTouchesLength = touch_event_.touchesLength = 0;
1593 touch_event_.type = WebKit::WebInputEvent::TouchEnd;
1594 render_widget_host_->ForwardTouchEvent(touch_event_);
1595 touch_event_.touchesLength = 0;
1596 }
1597
1598 WebKit::WebTouchPoint* RenderWidgetHostViewWin::AddTouchPoint(
1599 TOUCHINPUT* touch_input) {
1600 if (touch_event_.touchesLength >= WebKit::WebTouchEvent::touchesLengthCap)
1601 return NULL;
1602 WebKit::WebTouchPoint* point =
1603 &touch_event_.touches[touch_event_.touchesLength++];
1604 point->state = WebKit::WebTouchPoint::StatePressed;
1605 point->id = touch_input->dwID;
1606 UpdateTouchPoint(point, touch_input);
1607 return point;
1608 }
1609
1610 bool RenderWidgetHostViewWin::UpdateTouchPoint(
1611 WebKit::WebTouchPoint* touch_point,
1612 TOUCHINPUT* touch_input) {
1613 CPoint coordinates(TOUCH_COORD_TO_PIXEL(touch_input->x),
1614 TOUCH_COORD_TO_PIXEL(touch_input->y));
1615 int radius_x = 0;
1616 int radius_y = 0;
1617 if (touch_input->dwMask & TOUCHINPUTMASKF_CONTACTAREA) {
1618 radius_x = TOUCH_COORD_TO_PIXEL(touch_input->cxContact);
1619 radius_y = TOUCH_COORD_TO_PIXEL(touch_input->cyContact);
1620 }
1621
1622 // Detect and exclude stationary moves.
1623 if (touch_point->state == WebKit::WebTouchPoint::StateMoved &&
1624 touch_point->screenPosition.x == coordinates.x &&
1625 touch_point->screenPosition.y == coordinates.y &&
1626 touch_point->radiusX == radius_x &&
1627 touch_point->radiusY == radius_y) {
1628 touch_point->state = WebKit::WebTouchPoint::StateStationary;
1629 return true;
1630 }
1631
1632 touch_point->screenPosition.x = coordinates.x;
1633 touch_point->screenPosition.y = coordinates.y;
1634 GetParent().ScreenToClient(&coordinates);
1635 touch_point->position.x = coordinates.x;
1636 touch_point->position.y = coordinates.y;
1637 touch_point->radiusX = radius_x;
1638 touch_point->radiusY = radius_y;
1639 touch_point->force = 1.0;
1640 touch_point->rotationAngle = 0;
1641 return false;
1642 }
1643
1644 LRESULT RenderWidgetHostViewWin::OnTouchEvent(UINT message, WPARAM wparam,
1645 LPARAM lparam, BOOL& handled) {
1646 unsigned int touches_down = 0;
1647 unsigned int touches_up = 0;
1648 unsigned int touches_moved = 0;
1649 // TODO(jschuh): Add support for an arbitrary number of touchpoints.
1650 size_t points_count = std::min(static_cast<int>(LOWORD(wparam)),
1651 static_cast<int>(WebKit::WebTouchEvent::touchesLengthCap));
1652 TOUCHINPUT points[WebKit::WebTouchEvent::touchesLengthCap];
1653
1654 if (points_count > WebKit::WebTouchEvent::touchesLengthCap)
1655 points_count = WebKit::WebTouchEvent::touchesLengthCap;
1656 if (!points_count || !GetTouchInputInfo((HTOUCHINPUT)lparam, points_count,
1657 points, sizeof(TOUCHINPUT))) {
1658 return 0;
1659 }
1660 touch_event_.changedTouchesLength = 0;
1661
1662 for (size_t i = 0; i < points_count; i++) {
1663 if (points[i].dwID == 0ul)
1664 continue;
1665
1666 WebKit::WebTouchPoint* point = NULL;
1667 for (unsigned j = 0; j < touch_event_.touchesLength; ++j) {
1668 if (static_cast<DWORD>(touch_event_.touches[j].id) == points[i].dwID) {
1669 point = &touch_event_.touches[j];
1670 break;
1671 }
1672 }
1673
1674 // Use a move instead if we see a down on a point we already have.
1675 if (point && (points[i].dwFlags & 0x7) == TOUCHEVENTF_DOWN)
1676 points[i].dwFlags = (points[i].dwFlags & ~0x7) | TOUCHEVENTF_MOVE;
1677
1678 switch (points[i].dwFlags & 0x7) {
1679 case TOUCHEVENTF_DOWN: {
1680 if (!(point = AddTouchPoint(&points[i])))
1681 continue;
1682 ++touches_down;
1683 break;
1684 }
1685
1686 case TOUCHEVENTF_UP: {
1687 if (!point)
1688 continue;
1689 point->state = WebKit::WebTouchPoint::StateReleased;
1690 UpdateTouchPoint(point, &points[i]);
1691 ++touches_up;
1692 break;
1693 }
1694
1695 case TOUCHEVENTF_MOVE: {
1696 if (point) {
1697 point->state = WebKit::WebTouchPoint::StateMoved;
1698 // Don't update the message if the point didn't really move.
1699 if (UpdateTouchPoint(point, &points[i]))
1700 continue;
1701 ++touches_moved;
1702 } else { // Add a new point if we missed the TOUCHEVENTF_DOWN
1703 if (!(point = AddTouchPoint(&points[i])))
1704 continue;
1705 ++touches_down;
1706 }
1707 break;
1708 }
1709
1710 default:
1711 NOTREACHED();
1712 continue;
1713 }
1714 touch_event_.changedTouches[touch_event_.changedTouchesLength++] = *point;
1715 }
1716
1717 CloseTouchInputHandle((HTOUCHINPUT)lparam);
1718
1719 // Set the event type based on what we've received.
1720 if (touches_down)
1721 touch_event_.type = WebKit::WebInputEvent::TouchStart;
1722 else if (touches_up)
1723 touch_event_.type = WebKit::WebInputEvent::TouchEnd;
1724 else if (touches_moved)
1725 touch_event_.type = WebKit::WebInputEvent::TouchMove;
1726 else
1727 touch_event_.type = WebKit::WebInputEvent::Undefined;
1728
1729 // Forward the event only when there's a legitimate change.
1730 if (touch_event_.changedTouchesLength)
1731 render_widget_host_->ForwardTouchEvent(touch_event_);
1732
1733 // Clean up released touches and reset everything else to staitonary.
1734 WebKit::WebTouchPoint* point = touch_event_.touches;
1735 WebKit::WebTouchPoint* end =
1736 &touch_event_.touches[touch_event_.touchesLength];
1737 while (point < end) {
1738 if (point->state == WebKit::WebTouchPoint::StateReleased) {
1739 *point = *(--end);
1740 --touch_event_.touchesLength;
1741 } else {
1742 point->state = WebKit::WebTouchPoint::StateStationary;
1743 point++;
1744 }
1745 }
1746
1747 return 0;
1748 }
1749
1573 LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT message, 1750 LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT message,
1574 WPARAM wparam, 1751 WPARAM wparam,
1575 LPARAM lparam, 1752 LPARAM lparam,
1576 BOOL& handled) { 1753 BOOL& handled) {
1577 if (!render_widget_host_) 1754 if (!render_widget_host_)
1578 return MA_NOACTIVATE; 1755 return MA_NOACTIVATE;
1579 1756
1580 if (!IsActivatable()) 1757 if (!IsActivatable())
1581 return MA_NOACTIVATE; 1758 return MA_NOACTIVATE;
1582 1759
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 2402
2226 size_t offset = selection_range_.GetMin() - selection_text_offset_; 2403 size_t offset = selection_range_.GetMin() - selection_text_offset_;
2227 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), 2404 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
2228 selection_text_.c_str() + offset, len * sizeof(WCHAR)); 2405 selection_text_.c_str() + offset, len * sizeof(WCHAR));
2229 2406
2230 // According to Microsft API document, IMR_RECONVERTSTRING and 2407 // According to Microsft API document, IMR_RECONVERTSTRING and
2231 // IMR_DOCUMENTFEED should return reconv, but some applications return 2408 // IMR_DOCUMENTFEED should return reconv, but some applications return
2232 // need_size. 2409 // need_size.
2233 return reinterpret_cast<LRESULT>(reconv); 2410 return reinterpret_cast<LRESULT>(reconv);
2234 } 2411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698