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