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

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

Issue 10365009: Adding Gesture Recognition to RenderWidgetHostViewWin (web client) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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
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 <peninputpanel_i.c> 8 #include <peninputpanel_i.c>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 28 matching lines...) Expand all
39 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
41 #include "content/public/common/content_switches.h" 41 #include "content/public/common/content_switches.h"
42 #include "content/public/common/page_zoom.h" 42 #include "content/public/common/page_zoom.h"
43 #include "content/public/common/process_type.h" 43 #include "content/public/common/process_type.h"
44 #include "skia/ext/skia_utils_win.h" 44 #include "skia/ext/skia_utils_win.h"
45 #include "third_party/skia/include/core/SkRegion.h" 45 #include "third_party/skia/include/core/SkRegion.h"
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
48 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h" 48 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h"
49 #include "ui/base/gestures/gesture_recognizer.h"
49 #include "ui/base/ime/composition_text.h" 50 #include "ui/base/ime/composition_text.h"
50 #include "ui/base/l10n/l10n_util_win.h" 51 #include "ui/base/l10n/l10n_util_win.h"
51 #include "ui/base/text/text_elider.h" 52 #include "ui/base/text/text_elider.h"
52 #include "ui/base/ui_base_switches.h" 53 #include "ui/base/ui_base_switches.h"
53 #include "ui/base/view_prop.h" 54 #include "ui/base/view_prop.h"
54 #include "ui/base/win/hwnd_util.h" 55 #include "ui/base/win/hwnd_util.h"
55 #include "ui/base/win/mouse_wheel_util.h" 56 #include "ui/base/win/mouse_wheel_util.h"
56 #include "ui/gfx/canvas.h" 57 #include "ui/gfx/canvas.h"
57 #include "ui/gfx/gdi_util.h" 58 #include "ui/gfx/gdi_util.h"
58 #include "ui/gfx/rect.h" 59 #include "ui/gfx/rect.h"
59 #include "ui/gfx/screen.h" 60 #include "ui/gfx/screen.h"
61 #include "ui/views/events/event.h"
rjkroege 2012/05/04 15:42:46 afaik: content is not allowed to depend on views.
60 #include "webkit/glue/webaccessibility.h" 62 #include "webkit/glue/webaccessibility.h"
61 #include "webkit/glue/webcursor.h" 63 #include "webkit/glue/webcursor.h"
62 #include "webkit/plugins/npapi/plugin_constants_win.h" 64 #include "webkit/plugins/npapi/plugin_constants_win.h"
63 #include "webkit/plugins/npapi/webplugin.h" 65 #include "webkit/plugins/npapi/webplugin.h"
64 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" 66 #include "webkit/plugins/npapi/webplugin_delegate_impl.h"
65 67
66 using base::TimeDelta; 68 using base::TimeDelta;
67 using base::TimeTicks; 69 using base::TimeTicks;
68 using content::BrowserThread; 70 using content::BrowserThread;
69 using content::RenderWidgetHost; 71 using content::RenderWidgetHost;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 is_loading_(false), 328 is_loading_(false),
327 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 329 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
328 is_fullscreen_(false), 330 is_fullscreen_(false),
329 ignore_mouse_movement_(true), 331 ignore_mouse_movement_(true),
330 composition_range_(ui::Range::InvalidRange()), 332 composition_range_(ui::Range::InvalidRange()),
331 touch_state_(this), 333 touch_state_(this),
332 pointer_down_context_(false), 334 pointer_down_context_(false),
333 focus_on_editable_field_(false), 335 focus_on_editable_field_(false),
334 received_focus_change_after_pointer_down_(false), 336 received_focus_change_after_pointer_down_(false),
335 touch_events_enabled_(false), 337 touch_events_enabled_(false),
338 ALLOW_THIS_IN_INITIALIZER_LIST(
sky 2012/05/04 16:23:40 No scoped_ptr since you're creating all the time (
339 gesture_recognizer_(ui::GestureRecognizer::Create(this))),
336 ALLOW_THIS_IN_INITIALIZER_LIST(sys_color_change_listener_(this)) { 340 ALLOW_THIS_IN_INITIALIZER_LIST(sys_color_change_listener_(this)) {
337 render_widget_host_->SetView(this); 341 render_widget_host_->SetView(this);
338 registrar_.Add(this, 342 registrar_.Add(this,
339 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 343 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
340 content::NotificationService::AllBrowserContextsAndSources()); 344 content::NotificationService::AllBrowserContextsAndSources());
341 registrar_.Add(this, 345 registrar_.Add(this,
342 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, 346 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
343 content::NotificationService::AllBrowserContextsAndSources()); 347 content::NotificationService::AllBrowserContextsAndSources());
344 } 348 }
345 349
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 callback.Run(false); 935 callback.Run(false);
932 } 936 }
933 937
934 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { 938 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) {
935 content::RenderWidgetHostViewBase::SetBackground(background); 939 content::RenderWidgetHostViewBase::SetBackground(background);
936 render_widget_host_->SetBackground(background); 940 render_widget_host_->SetBackground(background);
937 } 941 }
938 942
939 void RenderWidgetHostViewWin::ProcessTouchAck( 943 void RenderWidgetHostViewWin::ProcessTouchAck(
940 WebKit::WebInputEvent::Type type, bool processed) { 944 WebKit::WebInputEvent::Type type, bool processed) {
945 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
946 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed));
947 ProcessGestures(gestures.get());
948
941 if (type == WebKit::WebInputEvent::TouchStart) 949 if (type == WebKit::WebInputEvent::TouchStart)
942 UpdateDesiredTouchMode(processed); 950 UpdateDesiredTouchMode(processed);
943 } 951 }
944 952
945 void RenderWidgetHostViewWin::SetToGestureMode() { 953 void RenderWidgetHostViewWin::SetToGestureMode() {
946 if (base::win::GetVersion() < base::win::VERSION_WIN7) 954 if (base::win::GetVersion() < base::win::VERSION_WIN7)
947 return; 955 return;
948 UnregisterTouchWindow(m_hWnd); 956 UnregisterTouchWindow(m_hWnd);
949 // Single finger panning is consistent with other windows applications. 957 // Single finger panning is consistent with other windows applications.
950 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | 958 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // state. If we want touch mode, then we attempt to register for touch 994 // state. If we want touch mode, then we attempt to register for touch
987 // events, and otherwise to unregister. 995 // events, and otherwise to unregister.
988 if (touch_mode) { 996 if (touch_mode) {
989 touch_mode = SetToTouchMode(); 997 touch_mode = SetToTouchMode();
990 } 998 }
991 if (!touch_mode) { 999 if (!touch_mode) {
992 SetToGestureMode(); 1000 SetToGestureMode();
993 } 1001 }
994 } 1002 }
995 1003
1004 ui::GestureEvent* RenderWidgetHostViewWin::CreateGestureEvent(
rjkroege 2012/05/04 15:42:46 my intuition is that this class is not the right p
1005 ui::EventType type,
1006 const gfx::Point& location,
1007 int flags,
1008 const base::Time& time,
1009 float param_first,
1010 float param_second,
1011 unsigned int touch_id_bitfield) {
1012 return new views::GestureEvent(type, location.x(), location.y(), flags, time,
1013 param_first, param_second, touch_id_bitfield);
1014 }
1015
1016 ui::TouchEvent* RenderWidgetHostViewWin::CreateTouchEvent(
1017 ui::EventType type,
1018 const gfx::Point& location,
1019 int touch_id,
1020 const base::TimeDelta& time_stamp) {
1021 return new views::TouchEvent(
1022 type, location.x(), location.y(), 0, touch_id, 0, 0, 0, 0);
1023 }
1024
1025 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent(
1026 ui::GestureEvent* event) {
1027 return ForwardGestureEventToRenderer( WebKit::WebInputEvent::GestureLongPress,
1028 reinterpret_cast< const views::GestureEvent *>(event));
1029 }
1030
1031 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent(
1032 ui::TouchEvent* event) {
1033 if (!render_widget_host_)
1034 return false;
1035
1036 WebKit::WebTouchEvent generatedEvent;
1037 generatedEvent.changedTouchesLength = 1;
1038 generatedEvent.changedTouches[0].id = event->GetTouchId();
1039 generatedEvent.type = WebKit::WebInputEvent::TouchCancel;
1040 render_widget_host_->ForwardTouchEvent(generatedEvent);
1041 return true;
1042 }
1043
996 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( 1044 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar(
997 bool has_horizontal_scrollbar) { 1045 bool has_horizontal_scrollbar) {
998 } 1046 }
999 1047
1000 void RenderWidgetHostViewWin::SetScrollOffsetPinning( 1048 void RenderWidgetHostViewWin::SetScrollOffsetPinning(
1001 bool is_pinned_to_left, bool is_pinned_to_right) { 1049 bool is_pinned_to_left, bool is_pinned_to_right) {
1002 } 1050 }
1003 1051
1004 /////////////////////////////////////////////////////////////////////////////// 1052 ///////////////////////////////////////////////////////////////////////////////
1005 // RenderWidgetHostViewWin, private: 1053 // RenderWidgetHostViewWin, private:
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 LPARAM lparam, BOOL& handled) { 1938 LPARAM lparam, BOOL& handled) {
1891 // TODO(jschuh): Add support for an arbitrary number of touchpoints. 1939 // TODO(jschuh): Add support for an arbitrary number of touchpoints.
1892 size_t total = std::min(static_cast<int>(LOWORD(wparam)), 1940 size_t total = std::min(static_cast<int>(LOWORD(wparam)),
1893 static_cast<int>(WebKit::WebTouchEvent::touchesLengthCap)); 1941 static_cast<int>(WebKit::WebTouchEvent::touchesLengthCap));
1894 TOUCHINPUT points[WebKit::WebTouchEvent::touchesLengthCap]; 1942 TOUCHINPUT points[WebKit::WebTouchEvent::touchesLengthCap];
1895 1943
1896 if (!total || !GetTouchInputInfo((HTOUCHINPUT)lparam, total, 1944 if (!total || !GetTouchInputInfo((HTOUCHINPUT)lparam, total,
1897 points, sizeof(TOUCHINPUT))) { 1945 points, sizeof(TOUCHINPUT))) {
1898 return 0; 1946 return 0;
1899 } 1947 }
1900
1901 for (size_t start = 0; start < total;) { 1948 for (size_t start = 0; start < total;) {
1902 start += touch_state_.UpdateTouchPoints(points + start, total - start); 1949 start += touch_state_.UpdateTouchPoints(points + start, total - start);
1903 if (touch_state_.is_changed()) 1950 if (touch_state_.is_changed())
1904 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event()); 1951 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event());
rjkroege 2012/05/04 15:42:46 are the touch-ids normalized here?
1905 } 1952 }
1906 1953
1954 // Send a copy of the touch events on to the gesture recognizer.
1955 for (size_t index = 0; index < total; ++index) {
1956 // Create a views::TouchEvent
1957 bool hasAreaInfo =
1958 (points[index].dwMask & TOUCHINPUTMASKF_CONTACTAREA) != 0;
1959
1960 DWORD flags = points[index].dwFlags;
1961 ui::EventType eventType = ui::ET_TOUCH_STATIONARY;
1962
1963 if ((flags & TOUCHEVENTF_UP) != 0)
1964 eventType = ui::ET_TOUCH_RELEASED;
1965 else if ((flags & TOUCHEVENTF_MOVE) != 0) {
1966 eventType = ui::ET_TOUCH_MOVED;
1967 // Ignore this touch if there is a backlog.
rjkroege 2012/05/04 15:42:46 why? you drop the moves on the floor? wouldn't th
1968 if (!gesture_recognizer_->IsQueueEmpty(this))
1969 continue;
1970 }
1971 else if ((flags & TOUCHEVENTF_DOWN) != 0)
1972 eventType = ui::ET_TOUCH_PRESSED;
1973
1974 views::TouchEvent touchEvent( eventType,
1975 TOUCH_COORD_TO_PIXEL( points[index].x),
1976 TOUCH_COORD_TO_PIXEL( points[index].y),
1977 0, // flags are not used.
1978 points[index].dwID,
1979 hasAreaInfo ? points[index].cxContact : 0.0,
1980 hasAreaInfo ? points[index].cyContact : 0.0,
1981 0.0, // angle is unknown?
1982 0.0); // force is 0?
1983 GestureConsumer* consumer = this;
1984 gesture_recognizer_->QueueTouchEventForGesture(
1985 consumer, touchEvent);
1986 }
1987
1907 CloseTouchInputHandle((HTOUCHINPUT)lparam); 1988 CloseTouchInputHandle((HTOUCHINPUT)lparam);
1908 1989
1909 return 0; 1990 return 0;
1910 } 1991 }
1911 1992
1993 void RenderWidgetHostViewWin::ProcessGestures(
1994 ui::GestureRecognizer::Gestures* gestures) {
1995 if ((gestures == 0) || gestures->empty())
1996 return;
1997
1998 for (ui::GestureRecognizer::Gestures::iterator g_it = gestures->begin();
rjkroege 2012/05/04 15:42:46 we have code that knows how to make Web events out
1999 g_it != gestures->end();
2000 ++g_it) {
2001 views::GestureEvent *gesture =
2002 reinterpret_cast<views::GestureEvent *>( *g_it);
2003 switch (gesture->type()) {
2004 case ui::ET_GESTURE_SCROLL_BEGIN:
2005 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureScrollBegin,
2006 gesture);
2007 break;
2008 case ui::ET_GESTURE_SCROLL_END:
2009 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureScrollEnd,
2010 gesture);
2011 break;
2012 case ui::ET_GESTURE_SCROLL_UPDATE:
2013 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureScrollUpdate,
2014 gesture);
2015 break;
2016 case ui::ET_GESTURE_PINCH_BEGIN:
2017 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GesturePinchBegin,
2018 gesture);
2019 break;
2020 case ui::ET_GESTURE_PINCH_END:
2021 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GesturePinchEnd,
2022 gesture);
2023 break;
2024 case ui::ET_GESTURE_PINCH_UPDATE:
2025 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GesturePinchUpdate,
2026 gesture);
2027 break;
2028 case ui::ET_GESTURE_LONG_PRESS:
2029 ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureLongPress,
2030 gesture);
2031 break;
2032 case ui::ET_GESTURE_THREE_FINGER_SWIPE:
2033 // TODO: Add this code when three finger swipes are added.
2034 //ForwardGestureEventToRenderer(
2035 // WebKit::WebInputEvent::GestureThreeFingerSwipe, gesture);
2036 break;
2037 case ui::ET_GESTURE_TAP:
2038 if (!ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureTap,
2039 gesture))
2040 ForwardMouseEventToRenderer(WM_LBUTTONUP, 0,
2041 MAKELONG(gesture->x(),gesture->y()));
2042 break;
2043 case ui::ET_GESTURE_TAP_DOWN:
rjkroege 2012/05/04 15:42:46 Something looks wrong here. Taps from the GR are h
2044 if (!ForwardGestureEventToRenderer(WebKit::WebInputEvent::GestureTapDown,
2045 gesture))
2046 ForwardMouseEventToRenderer(WM_LBUTTONDOWN, 0,
2047 MAKELONG(gesture->x(),gesture->y()));
2048 break;
2049 case ui::ET_GESTURE_DOUBLE_TAP:
2050 if (!ForwardGestureEventToRenderer(
2051 WebKit::WebInputEvent::GestureDoubleTap, gesture))
2052 ForwardMouseEventToRenderer(WM_LBUTTONDBLCLK, 0,
rjkroege 2012/05/04 15:42:46 Same comment
2053 MAKELONG(gesture->x(),gesture->y()));
2054 break;
2055 }
2056 }
2057 }
2058
1912 LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT message, 2059 LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT message,
1913 WPARAM wparam, 2060 WPARAM wparam,
1914 LPARAM lparam, 2061 LPARAM lparam,
1915 BOOL& handled) { 2062 BOOL& handled) {
1916 if (!render_widget_host_) 2063 if (!render_widget_host_)
1917 return MA_NOACTIVATE; 2064 return MA_NOACTIVATE;
1918 2065
1919 if (!IsActivatable()) 2066 if (!IsActivatable())
1920 return MA_NOACTIVATE; 2067 return MA_NOACTIVATE;
1921 2068
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 GetClientRect(&ti.rect); 2592 GetClientRect(&ti.rect);
2446 SendMessage(tooltip_hwnd_, message, NULL, reinterpret_cast<LPARAM>(&ti)); 2593 SendMessage(tooltip_hwnd_, message, NULL, reinterpret_cast<LPARAM>(&ti));
2447 } 2594 }
2448 2595
2449 void RenderWidgetHostViewWin::ResetTooltip() { 2596 void RenderWidgetHostViewWin::ResetTooltip() {
2450 if (::IsWindow(tooltip_hwnd_)) 2597 if (::IsWindow(tooltip_hwnd_))
2451 ::DestroyWindow(tooltip_hwnd_); 2598 ::DestroyWindow(tooltip_hwnd_);
2452 tooltip_hwnd_ = NULL; 2599 tooltip_hwnd_ = NULL;
2453 } 2600 }
2454 2601
2602 bool RenderWidgetHostViewWin::ForwardGestureEventToRenderer(
2603 WebKit::WebInputEvent::Type eventType,
2604 const views::GestureEvent* gesture) {
2605 if (!render_widget_host_)
2606 return false;
2607
2608 WebKit::WebGestureEvent generatedEvent;
2609 generatedEvent.x = gesture->x();
2610 generatedEvent.y = gesture->y();
2611 generatedEvent.deltaX = gesture->delta_x();
2612 generatedEvent.deltaY = gesture->delta_y();
2613 generatedEvent.timeStampSeconds =
2614 gesture->time_stamp().UnixEpoch().ToDoubleT();
2615 generatedEvent.type = eventType;
2616 render_widget_host_->ForwardGestureEvent(generatedEvent);
2617 return true;
2618 }
2619
2455 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, 2620 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message,
2456 WPARAM wparam, 2621 WPARAM wparam,
2457 LPARAM lparam) { 2622 LPARAM lparam) {
2458 if (!render_widget_host_) 2623 if (!render_widget_host_)
2459 return; 2624 return;
2460 2625
2461 WebMouseEvent event( 2626 WebMouseEvent event(
2462 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); 2627 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam));
2463 2628
2464 if (mouse_locked_) { 2629 if (mouse_locked_) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 void RenderWidgetHostViewWin::ResetPointerDownContext() { 2862 void RenderWidgetHostViewWin::ResetPointerDownContext() {
2698 // If the default focus on the page is on an edit field and we did not 2863 // If the default focus on the page is on an edit field and we did not
2699 // receive a focus change in the context of a pointer down message, it means 2864 // receive a focus change in the context of a pointer down message, it means
2700 // that the pointer down message occurred on the edit field and we should 2865 // that the pointer down message occurred on the edit field and we should
2701 // display the on screen keyboard 2866 // display the on screen keyboard
2702 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) 2867 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_)
2703 DisplayOnScreenKeyboardIfNeeded(); 2868 DisplayOnScreenKeyboardIfNeeded();
2704 received_focus_change_after_pointer_down_ = false; 2869 received_focus_change_after_pointer_down_ = false;
2705 pointer_down_context_ = false; 2870 pointer_down_context_ = false;
2706 } 2871 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698