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

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

Issue 9549020: Improve switch between gestures and touch mode when kEnableTouchEvents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 parent_hwnd_(NULL), 322 parent_hwnd_(NULL),
323 is_loading_(false), 323 is_loading_(false),
324 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 324 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
325 is_fullscreen_(false), 325 is_fullscreen_(false),
326 ignore_mouse_movement_(true), 326 ignore_mouse_movement_(true),
327 composition_range_(ui::Range::InvalidRange()), 327 composition_range_(ui::Range::InvalidRange()),
328 touch_state_(this), 328 touch_state_(this),
329 pointer_down_context_(false), 329 pointer_down_context_(false),
330 focus_on_editable_field_(false), 330 focus_on_editable_field_(false),
331 received_focus_change_after_pointer_down_(false), 331 received_focus_change_after_pointer_down_(false),
332 transparent_region_(0) { 332 transparent_region_(0),
333 touch_events_enabled_(false) {
333 render_widget_host_ = static_cast<RenderWidgetHostImpl*>(widget); 334 render_widget_host_ = static_cast<RenderWidgetHostImpl*>(widget);
334 render_widget_host_->SetView(this); 335 render_widget_host_->SetView(this);
335 registrar_.Add(this, 336 registrar_.Add(this,
336 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 337 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
337 content::NotificationService::AllBrowserContextsAndSources()); 338 content::NotificationService::AllBrowserContextsAndSources());
338 registrar_.Add(this, 339 registrar_.Add(this,
339 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, 340 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
340 content::NotificationService::AllBrowserContextsAndSources()); 341 content::NotificationService::AllBrowserContextsAndSources());
341 } 342 }
342 343
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 904
904 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { 905 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) {
905 content::RenderWidgetHostViewBase::SetBackground(background); 906 content::RenderWidgetHostViewBase::SetBackground(background);
906 render_widget_host_->SetBackground(background); 907 render_widget_host_->SetBackground(background);
907 } 908 }
908 909
909 void RenderWidgetHostViewWin::UnhandledWheelEvent( 910 void RenderWidgetHostViewWin::UnhandledWheelEvent(
910 const WebKit::WebMouseWheelEvent& event) { 911 const WebKit::WebMouseWheelEvent& event) {
911 } 912 }
912 913
913 void RenderWidgetHostViewWin::ProcessTouchAck(bool processed) { 914 void RenderWidgetHostViewWin::ProcessTouchAck(
915 WebKit::WebInputEvent::Type type, bool processed) {
916 if (type == WebKit::WebInputEvent::TouchStart)
917 UpdateDesiredTouchMode(processed);
918 }
919
920 void RenderWidgetHostViewWin::SetToGestureMode() {
921 if (base::win::GetVersion() < base::win::VERSION_WIN7)
922 return;
923 UnregisterTouchWindow(m_hWnd);
924 // Single finger panning is consistent with other windows applications.
925 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY |
926 GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
927 const DWORD gesture_block = GC_PAN_WITH_GUTTER;
928 GESTURECONFIG gc[] = {
929 { GID_ZOOM, GC_ZOOM, 0 },
930 { GID_PAN, gesture_allow , gesture_block},
931 { GID_TWOFINGERTAP, GC_TWOFINGERTAP , 0},
932 { GID_PRESSANDTAP, GC_PRESSANDTAP , 0}
933 };
934 if (!SetGestureConfig(m_hWnd, 0, arraysize(gc), gc,
935 sizeof(GESTURECONFIG))) {
936 NOTREACHED();
937 }
938 touch_events_enabled_ = false;
939 }
940
941 bool RenderWidgetHostViewWin::SetToTouchMode() {
942 if (base::win::GetVersion() < base::win::VERSION_WIN7)
943 return false;
944 bool touch_mode = RegisterTouchWindow(m_hWnd, TWF_WANTPALM) == TRUE;
945 touch_events_enabled_ = touch_mode;
946 return touch_mode;
947 }
948
949 void RenderWidgetHostViewWin::UpdateDesiredTouchMode(bool touch_mode) {
950 // Make sure that touch events even make sense.
951 bool touch_mode_valid = base::win::GetVersion() >= base::win::VERSION_WIN7 &&
952 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTouchEvents);
953 touch_mode = touch_mode && touch_mode_valid;
954
955 // Already in correct mode, nothing to do.
956 if ((touch_mode && touch_events_enabled_) ||
957 (!touch_mode && !touch_events_enabled_))
958 return;
959
960 // Now we know that the window's current state doesn't match the desired
961 // state. If we want touch mode, then we attempt to register for touch
962 // events, and otherwise to unregister.
963 if (touch_mode) {
964 touch_mode = SetToTouchMode();
965 }
966 if (!touch_mode) {
967 SetToGestureMode();
968 }
914 } 969 }
915 970
916 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( 971 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar(
917 bool has_horizontal_scrollbar) { 972 bool has_horizontal_scrollbar) {
918 } 973 }
919 974
920 void RenderWidgetHostViewWin::SetScrollOffsetPinning( 975 void RenderWidgetHostViewWin::SetScrollOffsetPinning(
921 bool is_pinned_to_left, bool is_pinned_to_right) { 976 bool is_pinned_to_left, bool is_pinned_to_right) {
922 } 977 }
923 978
924 /////////////////////////////////////////////////////////////////////////////// 979 ///////////////////////////////////////////////////////////////////////////////
925 // RenderWidgetHostViewWin, private: 980 // RenderWidgetHostViewWin, private:
926 981
927 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { 982 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) {
928 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale 983 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale
929 // of a browser process. 984 // of a browser process.
930 OnInputLangChange(0, 0); 985 OnInputLangChange(0, 0);
931 // Marks that window as supporting mouse-wheel messages rerouting so it is 986 // Marks that window as supporting mouse-wheel messages rerouting so it is
932 // scrolled when under the mouse pointer even if inactive. 987 // scrolled when under the mouse pointer even if inactive.
933 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd)); 988 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd));
934 989
935 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { 990 SetToGestureMode();
936 // Use gestures if touch event switch isn't present or registration fails. 991
937 if (!CommandLine::ForCurrentProcess()->HasSwitch(
938 switches::kEnableTouchEvents) ||
939 !RegisterTouchWindow(m_hWnd, TWF_WANTPALM)) {
940 // Single finger panning is consistent with other windows applications.
941 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY |
942 GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
943 const DWORD gesture_block = GC_PAN_WITH_GUTTER;
944 GESTURECONFIG gc[] = {
945 { GID_ZOOM, GC_ZOOM, 0 },
946 { GID_PAN, gesture_allow , gesture_block},
947 { GID_TWOFINGERTAP, GC_TWOFINGERTAP , 0},
948 { GID_PRESSANDTAP, GC_PRESSANDTAP , 0}
949 };
950 if (!SetGestureConfig(m_hWnd, 0, arraysize(gc), gc,
951 sizeof(GESTURECONFIG))) {
952 NOTREACHED();
953 }
954 }
955 }
956 return 0; 992 return 0;
957 } 993 }
958 994
959 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, 995 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized,
960 HWND window) { 996 HWND window) {
961 // If the container is a popup, clicking elsewhere on screen should close the 997 // If the container is a popup, clicking elsewhere on screen should close the
962 // popup. 998 // popup.
963 if (close_on_deactivate_ && action == WA_INACTIVE) { 999 if (close_on_deactivate_ && action == WA_INACTIVE) {
964 // Send a windows message so that any derived classes 1000 // Send a windows message so that any derived classes
965 // will get a change to override the default handling 1001 // will get a change to override the default handling
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 } else if (gi.dwID == GID_PAN) { 1936 } else if (gi.dwID == GID_PAN) {
1901 // Right now we only decode scroll gestures and we forward to the page 1937 // Right now we only decode scroll gestures and we forward to the page
1902 // as scroll events. 1938 // as scroll events.
1903 POINT start; 1939 POINT start;
1904 POINT delta; 1940 POINT delta;
1905 if (DecodeScrollGesture(gi, &start, &delta)) { 1941 if (DecodeScrollGesture(gi, &start, &delta)) {
1906 handled = TRUE; 1942 handled = TRUE;
1907 render_widget_host_->ForwardWheelEvent( 1943 render_widget_host_->ForwardWheelEvent(
1908 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); 1944 MakeFakeScrollWheelEvent(m_hWnd, start, delta));
1909 } 1945 }
1946 } else if (gi.dwID == GID_BEGIN) {
1947 // Send a touch event at this location; if the touch start is handled
1948 // then we switch to touch mode, rather than gesture mode (in the ACK).
1949 TOUCHINPUT fake_touch;
1950 fake_touch.x = gi.ptsLocation.x * 100;
1951 fake_touch.y = gi.ptsLocation.y * 100;
1952 fake_touch.cxContact = 100;
1953 fake_touch.cyContact = 100;
1954 fake_touch.dwMask = 0;
1955 fake_touch.dwFlags = TOUCHEVENTF_DOWN | TOUCHEVENTF_PRIMARY;
1956 fake_touch.dwID = gi.dwInstanceID;
1957 touch_state_.UpdateTouchPoints(&fake_touch, 1);
1958 if (touch_state_.is_changed())
1959 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event());
1960 } else if (gi.dwID == GID_END) {
1961 if (touch_state_.ReleaseTouchPoints())
1962 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event());
1910 } 1963 }
1911 ::CloseGestureInfoHandle(gi_handle); 1964 ::CloseGestureInfoHandle(gi_handle);
1912 return 0; 1965 return 0;
1913 } 1966 }
1914 1967
1915 void RenderWidgetHostViewWin::OnAccessibilityNotifications( 1968 void RenderWidgetHostViewWin::OnAccessibilityNotifications(
1916 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { 1969 const std::vector<AccessibilityHostMsg_NotificationParams>& params) {
1917 if (!GetBrowserAccessibilityManager()) { 1970 if (!GetBrowserAccessibilityManager()) {
1918 SetBrowserAccessibilityManager( 1971 SetBrowserAccessibilityManager(
1919 BrowserAccessibilityManager::CreateEmptyDocument( 1972 BrowserAccessibilityManager::CreateEmptyDocument(
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 void RenderWidgetHostViewWin::ResetPointerDownContext() { 2652 void RenderWidgetHostViewWin::ResetPointerDownContext() {
2600 // If the default focus on the page is on an edit field and we did not 2653 // If the default focus on the page is on an edit field and we did not
2601 // receive a focus change in the context of a pointer down message, it means 2654 // receive a focus change in the context of a pointer down message, it means
2602 // that the pointer down message occurred on the edit field and we should 2655 // that the pointer down message occurred on the edit field and we should
2603 // display the on screen keyboard 2656 // display the on screen keyboard
2604 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) 2657 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_)
2605 DisplayOnScreenKeyboardIfNeeded(); 2658 DisplayOnScreenKeyboardIfNeeded();
2606 received_focus_change_after_pointer_down_ = false; 2659 received_focus_change_after_pointer_down_ = false;
2607 pointer_down_context_ = false; 2660 pointer_down_context_ = false;
2608 } 2661 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_win.h ('k') | content/browser/renderer_host/test_render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698