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 <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 Loading... | |
| 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 Loading... | |
| 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 UnregisterTouchWindow(m_hWnd); | |
| 922 // Single finger panning is consistent with other windows applications. | |
| 923 const DWORD gesture_allow = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | | |
| 924 GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY; | |
| 925 const DWORD gesture_block = GC_PAN_WITH_GUTTER; | |
| 926 GESTURECONFIG gc[] = { | |
| 927 { GID_ZOOM, GC_ZOOM, 0 }, | |
| 928 { GID_PAN, gesture_allow , gesture_block}, | |
| 929 { GID_TWOFINGERTAP, GC_TWOFINGERTAP , 0}, | |
| 930 { GID_PRESSANDTAP, GC_PRESSANDTAP , 0} | |
| 931 }; | |
| 932 if (!SetGestureConfig(m_hWnd, 0, arraysize(gc), gc, | |
| 933 sizeof(GESTURECONFIG))) { | |
| 934 NOTREACHED(); | |
| 935 } | |
| 936 touch_events_enabled_ = false; | |
| 937 } | |
| 938 | |
| 939 bool RenderWidgetHostViewWin::SetToTouchMode() { | |
| 940 bool touch_mode = !!RegisterTouchWindow(m_hWnd, TWF_WANTPALM); | |
|
cpu_(ooo_6.6-7.5)
2012/03/02 21:26:36
we're not fans of the !! construct, you can use fo
scottmg
2012/03/02 22:27:29
Done.
| |
| 941 touch_events_enabled_ = touch_mode; | |
| 942 return touch_mode; | |
| 943 } | |
| 944 | |
| 945 void RenderWidgetHostViewWin::UpdateDesiredTouchMode(bool touch_mode) { | |
| 946 // Make sure that touch events even make sense. | |
| 947 bool touch_mode_valid = base::win::GetVersion() >= base::win::VERSION_WIN7 && | |
| 948 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTouchEvents); | |
| 949 touch_mode = touch_mode && touch_mode_valid; | |
| 950 | |
| 951 // Already in correct mode, nothing to do. | |
| 952 if ((touch_mode && touch_events_enabled_) || | |
| 953 (!touch_mode && !touch_events_enabled_)) | |
| 954 return; | |
| 955 | |
| 956 // Now we know that the window's current state doesn't match the desired | |
| 957 // state. If we want touch mode, then we attempt to register for touch | |
| 958 // events, and otherwise to unregister. | |
| 959 if (touch_mode) { | |
| 960 touch_mode = SetToTouchMode(); | |
| 961 } | |
| 962 if (!touch_mode) { | |
| 963 SetToGestureMode(); | |
| 964 } | |
| 914 } | 965 } |
| 915 | 966 |
| 916 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( | 967 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( |
| 917 bool has_horizontal_scrollbar) { | 968 bool has_horizontal_scrollbar) { |
| 918 } | 969 } |
| 919 | 970 |
| 920 void RenderWidgetHostViewWin::SetScrollOffsetPinning( | 971 void RenderWidgetHostViewWin::SetScrollOffsetPinning( |
| 921 bool is_pinned_to_left, bool is_pinned_to_right) { | 972 bool is_pinned_to_left, bool is_pinned_to_right) { |
| 922 } | 973 } |
| 923 | 974 |
| 924 /////////////////////////////////////////////////////////////////////////////// | 975 /////////////////////////////////////////////////////////////////////////////// |
| 925 // RenderWidgetHostViewWin, private: | 976 // RenderWidgetHostViewWin, private: |
| 926 | 977 |
| 927 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { | 978 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { |
| 928 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale | 979 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale |
| 929 // of a browser process. | 980 // of a browser process. |
| 930 OnInputLangChange(0, 0); | 981 OnInputLangChange(0, 0); |
| 931 // Marks that window as supporting mouse-wheel messages rerouting so it is | 982 // Marks that window as supporting mouse-wheel messages rerouting so it is |
| 932 // scrolled when under the mouse pointer even if inactive. | 983 // scrolled when under the mouse pointer even if inactive. |
| 933 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd)); | 984 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd)); |
| 934 | 985 |
| 935 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | 986 SetToGestureMode(); |
| 936 // Use gestures if touch event switch isn't present or registration fails. | 987 |
| 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; | 988 return 0; |
| 957 } | 989 } |
| 958 | 990 |
| 959 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, | 991 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, |
| 960 HWND window) { | 992 HWND window) { |
| 961 // If the container is a popup, clicking elsewhere on screen should close the | 993 // If the container is a popup, clicking elsewhere on screen should close the |
| 962 // popup. | 994 // popup. |
| 963 if (close_on_deactivate_ && action == WA_INACTIVE) { | 995 if (close_on_deactivate_ && action == WA_INACTIVE) { |
| 964 // Send a windows message so that any derived classes | 996 // Send a windows message so that any derived classes |
| 965 // will get a change to override the default handling | 997 // will get a change to override the default handling |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 } | 1931 } |
| 1900 } else if (gi.dwID == GID_PAN) { | 1932 } else if (gi.dwID == GID_PAN) { |
| 1901 // Right now we only decode scroll gestures and we forward to the page | 1933 // Right now we only decode scroll gestures and we forward to the page |
| 1902 // as scroll events. | 1934 // as scroll events. |
| 1903 POINT start; | 1935 POINT start; |
| 1904 POINT delta; | 1936 POINT delta; |
| 1905 if (DecodeScrollGesture(gi, &start, &delta)) { | 1937 if (DecodeScrollGesture(gi, &start, &delta)) { |
| 1906 handled = TRUE; | 1938 handled = TRUE; |
| 1907 render_widget_host_->ForwardWheelEvent( | 1939 render_widget_host_->ForwardWheelEvent( |
| 1908 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); | 1940 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); |
| 1941 | |
| 1942 // Send a touch event at this location; if the touch start is handled | |
| 1943 // then we switch to touch mode, rather than gesture mode (in the ACK). | |
| 1944 TOUCHINPUT fake_touch; | |
|
cpu_(ooo_6.6-7.5)
2012/03/02 21:26:36
sounds like we send the fake a lot of times if we
scottmg
2012/03/02 22:27:29
Good point, thanks. Changed to only send fake touc
| |
| 1945 fake_touch.x = gi.ptsLocation.x * 100; | |
| 1946 fake_touch.y = gi.ptsLocation.y * 100; | |
| 1947 fake_touch.cxContact = 100; | |
| 1948 fake_touch.cyContact = 100; | |
| 1949 fake_touch.dwMask = 0; | |
| 1950 fake_touch.dwFlags = TOUCHEVENTF_DOWN | TOUCHEVENTF_PRIMARY; | |
| 1951 fake_touch.dwID = gi.dwInstanceID; | |
| 1952 touch_state_.UpdateTouchPoints(&fake_touch, 1); | |
| 1953 if (touch_state_.is_changed()) | |
| 1954 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event()); | |
| 1909 } | 1955 } |
| 1956 } else if (gi.dwID == GID_END) { | |
| 1957 if (touch_state_.ReleaseTouchPoints()) | |
| 1958 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event()); | |
| 1910 } | 1959 } |
| 1911 ::CloseGestureInfoHandle(gi_handle); | 1960 ::CloseGestureInfoHandle(gi_handle); |
| 1912 return 0; | 1961 return 0; |
| 1913 } | 1962 } |
| 1914 | 1963 |
| 1915 void RenderWidgetHostViewWin::OnAccessibilityNotifications( | 1964 void RenderWidgetHostViewWin::OnAccessibilityNotifications( |
| 1916 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 1965 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
| 1917 if (!GetBrowserAccessibilityManager()) { | 1966 if (!GetBrowserAccessibilityManager()) { |
| 1918 SetBrowserAccessibilityManager( | 1967 SetBrowserAccessibilityManager( |
| 1919 BrowserAccessibilityManager::CreateEmptyDocument( | 1968 BrowserAccessibilityManager::CreateEmptyDocument( |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2599 void RenderWidgetHostViewWin::ResetPointerDownContext() { | 2648 void RenderWidgetHostViewWin::ResetPointerDownContext() { |
| 2600 // If the default focus on the page is on an edit field and we did not | 2649 // 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 | 2650 // 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 | 2651 // that the pointer down message occurred on the edit field and we should |
| 2603 // display the on screen keyboard | 2652 // display the on screen keyboard |
| 2604 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 2653 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
| 2605 DisplayOnScreenKeyboardIfNeeded(); | 2654 DisplayOnScreenKeyboardIfNeeded(); |
| 2606 received_focus_change_after_pointer_down_ = false; | 2655 received_focus_change_after_pointer_down_ = false; |
| 2607 pointer_down_context_ = false; | 2656 pointer_down_context_ = false; |
| 2608 } | 2657 } |
| OLD | NEW |