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

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

Issue 8399009: Add support for touch based zoom gesture on Windows. This change also handles the WM_POINTERDOWN (Closed) Base URL: svn://svn.chromium.org/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 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/win/scoped_comptr.h" 14 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_gdi_object.h" 15 #include "base/win/scoped_gdi_object.h"
16 #include "base/win/win_util.h" 16 #include "base/win/win_util.h"
17 #include "base/win/windows_version.h" 17 #include "base/win/windows_version.h"
18 #include "base/win/wrapped_window_proc.h" 18 #include "base/win/wrapped_window_proc.h"
19 #include "content/browser/accessibility/browser_accessibility_manager.h" 19 #include "content/browser/accessibility/browser_accessibility_manager.h"
20 #include "content/browser/accessibility/browser_accessibility_state.h" 20 #include "content/browser/accessibility/browser_accessibility_state.h"
21 #include "content/browser/accessibility/browser_accessibility_win.h" 21 #include "content/browser/accessibility/browser_accessibility_win.h"
22 #include "content/browser/browser_thread.h" 22 #include "content/browser/browser_thread.h"
23 #include "content/browser/plugin_process_host.h" 23 #include "content/browser/plugin_process_host.h"
24 #include "content/browser/renderer_host/backing_store.h" 24 #include "content/browser/renderer_host/backing_store.h"
25 #include "content/browser/renderer_host/backing_store_win.h" 25 #include "content/browser/renderer_host/backing_store_win.h"
26 #include "content/browser/renderer_host/render_process_host.h" 26 #include "content/browser/renderer_host/render_process_host.h"
27 #include "content/browser/renderer_host/render_widget_host.h" 27 #include "content/browser/renderer_host/render_widget_host.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/common/page_zoom.h"
29 #include "content/common/plugin_messages.h" 30 #include "content/common/plugin_messages.h"
30 #include "content/common/view_messages.h" 31 #include "content/common/view_messages.h"
31 #include "content/public/browser/content_browser_client.h" 32 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/browser/native_web_keyboard_event.h" 33 #include "content/public/browser/native_web_keyboard_event.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
35 #include "skia/ext/skia_utils_win.h" 36 #include "skia/ext/skia_utils_win.h"
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
38 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h" 39 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 case WM_MBUTTONDOWN: 195 case WM_MBUTTONDOWN:
195 ::SendMessage(GetParent(window), message, wparam, lparam); 196 ::SendMessage(GetParent(window), message, wparam, lparam);
196 return 0; 197 return 0;
197 default: 198 default:
198 break; 199 break;
199 } 200 }
200 } 201 }
201 return ::DefWindowProc(window, message, wparam, lparam); 202 return ::DefWindowProc(window, message, wparam, lparam);
202 } 203 }
203 204
204 bool DecodeScrollGesture(WPARAM wParam, 205 bool DecodeZoomGesture(HWND hwnd, const GESTUREINFO& gi,
205 LPARAM lParam, 206 PageZoom::Function* zoom,
207 POINT* zoom_center) {
208 static long start = 0;
209 static POINT zoom_first;
210
211 if (gi.dwFlags == GF_BEGIN) {
212 start = gi.ullArguments;
213 zoom_first.x = gi.ptsLocation.x;
214 zoom_first.y = gi.ptsLocation.y;
215 ScreenToClient(hwnd, &zoom_first);
216 return false;
217 }
218
219 if (gi.dwFlags == GF_END)
220 return false;
221
222 POINT zoom_second = {0};
223 zoom_second.x = gi.ptsLocation.x;
224 zoom_second.y = gi.ptsLocation.y;
225 ScreenToClient(hwnd, &zoom_second);
226
227 zoom_center->x = (zoom_first.x + zoom_second.x) / 2;
228 zoom_center->y = (zoom_first.y + zoom_second.y) / 2;
229
230 *zoom = PageZoom::ZOOM_IN;
231
cpu_(ooo_6.6-7.5) 2011/10/28 02:30:03 *zoom = distance < start ? zoom_out : zoom_in
ananta 2011/10/28 18:42:03 Done.
232 long distance = gi.ullArguments;
233
234 if (distance < start)
235 *zoom = PageZoom::ZOOM_OUT;
236 start = distance;
237 zoom_first = zoom_second;
238 return true;
239 }
240
241 bool DecodeScrollGesture(const GESTUREINFO& gi,
206 POINT* start, 242 POINT* start,
207 POINT* delta){ 243 POINT* delta){
208 // Windows gestures are streams of messages with begin/end messages that 244 // Windows gestures are streams of messages with begin/end messages that
209 // separate each new gesture. We key off the begin message to reset 245 // separate each new gesture. We key off the begin message to reset
210 // the static variables. 246 // the static variables.
211 static POINT last_pt; 247 static POINT last_pt;
212 static POINT start_pt; 248 static POINT start_pt;
213 249
214 GESTUREINFO gi = {sizeof(GESTUREINFO)};
215 HGESTUREINFO gi_handle = reinterpret_cast<HGESTUREINFO>(lParam);
216 if (!::GetGestureInfo(gi_handle, &gi)) {
217 DWORD error = GetLastError();
218 NOTREACHED() << "Unable to get gesture info. Error : " << error;
219 }
220
221 if (gi.dwID != GID_PAN)
222 return false;
223
224 if (gi.dwFlags == GF_BEGIN) { 250 if (gi.dwFlags == GF_BEGIN) {
225 delta->x = 0; 251 delta->x = 0;
226 delta->y = 0; 252 delta->y = 0;
227 start_pt.x = gi.ptsLocation.x; 253 start_pt.x = gi.ptsLocation.x;
228 start_pt.y = gi.ptsLocation.y; 254 start_pt.y = gi.ptsLocation.y;
229 } else { 255 } else {
230 delta->x = gi.ptsLocation.x - last_pt.x; 256 delta->x = gi.ptsLocation.x - last_pt.x;
231 delta->y = gi.ptsLocation.y - last_pt.y; 257 delta->y = gi.ptsLocation.y - last_pt.y;
232 } 258 }
233 last_pt.x = gi.ptsLocation.x; 259 last_pt.x = gi.ptsLocation.x;
234 last_pt.y = gi.ptsLocation.y; 260 last_pt.y = gi.ptsLocation.y;
235 *start = start_pt; 261 *start = start_pt;
236 ::CloseGestureInfoHandle(gi_handle);
237 return true; 262 return true;
238 } 263 }
239 264
240 WebKit::WebMouseWheelEvent MakeFakeScrollWheelEvent(HWND hwnd, 265 WebKit::WebMouseWheelEvent MakeFakeScrollWheelEvent(HWND hwnd,
241 POINT start, 266 POINT start,
242 POINT delta) { 267 POINT delta) {
243 WebKit::WebMouseWheelEvent result; 268 WebKit::WebMouseWheelEvent result;
244 result.type = WebInputEvent::MouseWheel; 269 result.type = WebInputEvent::MouseWheel;
245 result.timeStampSeconds = ::GetMessageTime() / 1000.0; 270 result.timeStampSeconds = ::GetMessageTime() / 1000.0;
246 result.button = WebMouseEvent::ButtonNone; 271 result.button = WebMouseEvent::ButtonNone;
247 result.globalX = start.x; 272 result.globalX = start.x;
248 result.globalY = start.y; 273 result.globalY = start.y;
249 // Map to window coordinates. 274 // Map to window coordinates.
250 POINT clientPoint = { result.globalX, result.globalY }; 275 POINT client_point = { result.globalX, result.globalY };
251 MapWindowPoints(0, hwnd, &clientPoint, 1); 276 MapWindowPoints(0, hwnd, &client_point, 1);
252 result.x = clientPoint.x; 277 result.x = client_point.x;
253 result.y = clientPoint.y; 278 result.y = client_point.y;
254 result.windowX = result.x; 279 result.windowX = result.x;
255 result.windowY = result.y; 280 result.windowY = result.y;
256 // Note that we support diagonal scrolling. 281 // Note that we support diagonal scrolling.
257 result.deltaX = static_cast<float>(delta.x); 282 result.deltaX = static_cast<float>(delta.x);
258 result.wheelTicksX = WHEEL_DELTA; 283 result.wheelTicksX = WHEEL_DELTA;
259 result.deltaY = static_cast<float>(delta.y); 284 result.deltaY = static_cast<float>(delta.y);
260 result.wheelTicksY = WHEEL_DELTA; 285 result.wheelTicksY = WHEEL_DELTA;
261 return result; 286 return result;
262 } 287 }
263 288
264 } // namespace 289 } // namespace
265 290
266 /////////////////////////////////////////////////////////////////////////////// 291 ///////////////////////////////////////////////////////////////////////////////
267 // RenderWidgetHostViewWin, public: 292 // RenderWidgetHostViewWin, public:
268 293
269 RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget) 294 RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget)
270 : render_widget_host_(widget), 295 : render_widget_host_(widget),
271 compositor_host_window_(NULL), 296 compositor_host_window_(NULL),
272 hide_compositor_window_at_next_paint_(false), 297 hide_compositor_window_at_next_paint_(false),
273 track_mouse_leave_(false), 298 track_mouse_leave_(false),
274 ime_notification_(false), 299 ime_notification_(false),
275 capture_enter_key_(false), 300 capture_enter_key_(false),
276 is_hidden_(false), 301 is_hidden_(false),
277 about_to_validate_and_paint_(false), 302 about_to_validate_and_paint_(false),
278 close_on_deactivate_(false), 303 close_on_deactivate_(false),
279 being_destroyed_(false), 304 being_destroyed_(false),
280 tooltip_hwnd_(NULL), 305 tooltip_hwnd_(NULL),
281 tooltip_showing_(false), 306 tooltip_showing_(false),
282 shutdown_factory_(this), 307 shutdown_factory_(this),
283 parent_hwnd_(NULL), 308 parent_hwnd_(NULL),
284 is_loading_(false), 309 is_loading_(false),
285 overlay_color_(0), 310 overlay_color_(0),
286 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 311 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
287 is_fullscreen_(false), 312 is_fullscreen_(false),
288 ignore_mouse_movement_(true) { 313 ignore_mouse_movement_(true),
314 ignore_next_lbutton_message_at_same_location(false),
315 last_pointer_down_location_(0) {
289 render_widget_host_->SetView(this); 316 render_widget_host_->SetView(this);
290 registrar_.Add(this, 317 registrar_.Add(this,
291 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 318 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
292 content::NotificationService::AllBrowserContextsAndSources()); 319 content::NotificationService::AllBrowserContextsAndSources());
293 } 320 }
294 321
295 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { 322 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() {
296 UnlockMouse(); 323 UnlockMouse();
297 ResetTooltip(); 324 ResetTooltip();
298 } 325 }
299 326
300 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { 327 void RenderWidgetHostViewWin::CreateWnd(HWND parent) {
301 Create(parent); // ATL function to create the window. 328 // ATL function to create the window.
329 Create(parent);
302 } 330 }
303 331
304 /////////////////////////////////////////////////////////////////////////////// 332 ///////////////////////////////////////////////////////////////////////////////
305 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: 333 // RenderWidgetHostViewWin, RenderWidgetHostView implementation:
306 334
307 void RenderWidgetHostViewWin::InitAsPopup( 335 void RenderWidgetHostViewWin::InitAsPopup(
308 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { 336 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) {
309 close_on_deactivate_ = true; 337 close_on_deactivate_ = true;
310 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos, 338 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos,
311 WS_EX_TOOLWINDOW); 339 WS_EX_TOOLWINDOW);
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 ime_input_.DestroyImeWindow(m_hWnd); 1302 ime_input_.DestroyImeWindow(m_hWnd);
1275 // Let WTL call ::DefWindowProc() and release its resources. 1303 // Let WTL call ::DefWindowProc() and release its resources.
1276 handled = FALSE; 1304 handled = FALSE;
1277 return 0; 1305 return 0;
1278 } 1306 }
1279 1307
1280 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, 1308 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam,
1281 LPARAM lparam, BOOL& handled) { 1309 LPARAM lparam, BOOL& handled) {
1282 handled = TRUE; 1310 handled = TRUE;
1283 1311
1312 if (ignore_next_lbutton_message_at_same_location &&
1313 message == WM_LBUTTONDOWN) {
1314 ignore_next_lbutton_message_at_same_location = false;
1315 LPARAM last_location = last_pointer_down_location_;
1316 last_pointer_down_location_ = 0;
1317 if (last_location == lparam)
1318 return 0;
1319 }
1320
1284 if (message == WM_MOUSELEAVE) 1321 if (message == WM_MOUSELEAVE)
1285 ignore_mouse_movement_ = true; 1322 ignore_mouse_movement_ = true;
1286 1323
1287 if (mouse_locked_) { 1324 if (mouse_locked_) {
1288 HandleLockedMouseEvent(message, wparam, lparam); 1325 HandleLockedMouseEvent(message, wparam, lparam);
1289 MoveCursorToCenter(); 1326 MoveCursorToCenter();
1290 return 0; 1327 return 0;
1291 } 1328 }
1292 1329
1293 if (::IsWindow(tooltip_hwnd_)) { 1330 if (::IsWindow(tooltip_hwnd_)) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 ::SetFocus(child_window); 1563 ::SetFocus(child_window);
1527 return MA_NOACTIVATE; 1564 return MA_NOACTIVATE;
1528 } 1565 }
1529 } 1566 }
1530 handled = FALSE; 1567 handled = FALSE;
1531 render_widget_host_->OnMouseActivate(); 1568 render_widget_host_->OnMouseActivate();
1532 return MA_ACTIVATE; 1569 return MA_ACTIVATE;
1533 } 1570 }
1534 1571
1535 LRESULT RenderWidgetHostViewWin::OnGestureEvent( 1572 LRESULT RenderWidgetHostViewWin::OnGestureEvent(
1536 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 1573 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
1537 // Right now we only decode scroll gestures and we forward to the page 1574
1538 // as scroll events. 1575 handled = FALSE;
1539 POINT start; 1576
1540 POINT delta; 1577 GESTUREINFO gi = {sizeof(GESTUREINFO)};
1541 if (DecodeScrollGesture(wparam, lparam, &start, &delta)) { 1578 HGESTUREINFO gi_handle = reinterpret_cast<HGESTUREINFO>(lparam);
1542 handled = TRUE; 1579 if (!::GetGestureInfo(gi_handle, &gi)) {
1543 render_widget_host_->ForwardWheelEvent( 1580 DWORD error = GetLastError();
1544 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); 1581 NOTREACHED() << "Unable to get gesture info. Error : " << error;
1545 } else { 1582 ::CloseGestureInfoHandle(gi_handle);
cpu_(ooo_6.6-7.5) 2011/10/28 02:30:03 dont call close here.
ananta 2011/10/28 18:42:03 Done.
1546 handled = FALSE; 1583 return 0;
1547 } 1584 }
1585
1586 if (gi.dwID == GID_ZOOM) {
1587 PageZoom::Function zoom = PageZoom::RESET;
1588 POINT zoom_center = {0};
1589 if (DecodeZoomGesture(m_hWnd, gi, &zoom, &zoom_center)) {
1590 handled = TRUE;
1591 Send(new ViewMsg_ZoomFactor(render_widget_host_->routing_id(),
1592 zoom, zoom_center.x, zoom_center.y));
1593 }
1594 } else if (gi.dwID == GID_PAN) {
1595 // Right now we only decode scroll gestures and we forward to the page
1596 // as scroll events.
1597 POINT start;
1598 POINT delta;
1599 if (DecodeScrollGesture(gi, &start, &delta)) {
1600 handled = TRUE;
1601 render_widget_host_->ForwardWheelEvent(
1602 MakeFakeScrollWheelEvent(m_hWnd, start, delta));
1603 }
1604 }
1605 ::CloseGestureInfoHandle(gi_handle);
1548 return 0; 1606 return 0;
1549 } 1607 }
1550 1608
1551 void RenderWidgetHostViewWin::OnAccessibilityNotifications( 1609 void RenderWidgetHostViewWin::OnAccessibilityNotifications(
1552 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { 1610 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) {
1553 if (!browser_accessibility_manager_.get()) { 1611 if (!browser_accessibility_manager_.get()) {
1554 browser_accessibility_manager_.reset( 1612 browser_accessibility_manager_.reset(
1555 BrowserAccessibilityManager::CreateEmptyDocument( 1613 BrowserAccessibilityManager::CreateEmptyDocument(
1556 m_hWnd, static_cast<WebAccessibility::State>(0), this)); 1614 m_hWnd, static_cast<WebAccessibility::State>(0), this));
1557 } 1615 }
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 case WM_RBUTTONDOWN: 1880 case WM_RBUTTONDOWN:
1823 case WM_MBUTTONDOWN: 1881 case WM_MBUTTONDOWN:
1824 render_widget_host_->StartUserGesture(); 1882 render_widget_host_->StartUserGesture();
1825 break; 1883 break;
1826 default: 1884 default:
1827 break; 1885 break;
1828 } 1886 }
1829 return 0; 1887 return 0;
1830 } 1888 }
1831 1889
1890 LRESULT RenderWidgetHostViewWin::OnPointerMessage(
1891 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
1892 POINT point = {0};
1893
1894 point.x = GET_X_LPARAM(lparam);
1895 point.y = GET_Y_LPARAM(lparam);
1896 ScreenToClient(&point);
1897
1898 lparam = MAKELPARAM(point.x, point.y);
1899
1900 if (message == WM_POINTERDOWN) {
1901 OnMouseEvent(WM_LBUTTONDOWN, MK_LBUTTON, lparam, handled);
1902 ignore_next_lbutton_message_at_same_location = true;
1903 last_pointer_down_location_ = lparam;
1904 } else if (message == WM_POINTERUP) {
1905 OnMouseEvent(WM_LBUTTONUP, MK_LBUTTON, lparam, handled);
1906 }
1907 handled = FALSE;
1908 return 0;
1909 }
1910
1832 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { 1911 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) {
1833 // When the render widget host is being destroyed, it ends up calling 1912 // When the render widget host is being destroyed, it ends up calling
1834 // Destroy() which NULLs render_widget_host_. 1913 // Destroy() which NULLs render_widget_host_.
1835 // Note: the following bug http://crbug.com/24248 seems to report that 1914 // Note: the following bug http://crbug.com/24248 seems to report that
1836 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not 1915 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not
1837 // clear how this could happen, hence the NULLing of render_widget_host_ 1916 // clear how this could happen, hence the NULLing of render_widget_host_
1838 // above. 1917 // above.
1839 if (!render_widget_host_ && !being_destroyed_) { 1918 if (!render_widget_host_ && !being_destroyed_) {
1840 // If you hit this NOTREACHED, please add a comment to report it on 1919 // If you hit this NOTREACHED, please add a comment to report it on
1841 // http://crbug.com/24248, including what you did when it happened and if 1920 // http://crbug.com/24248, including what you did when it happened and if
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 if (message == WM_MOUSEMOVE) { 2097 if (message == WM_MOUSEMOVE) {
2019 CPoint center = GetClientCenter(); 2098 CPoint center = GetClientCenter();
2020 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). 2099 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter().
2021 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) 2100 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y)
2022 return; 2101 return;
2023 } 2102 }
2024 2103
2025 ForwardMouseEventToRenderer(message, wparam, lparam); 2104 ForwardMouseEventToRenderer(message, wparam, lparam);
2026 } 2105 }
2027 2106
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698