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) { | |
334 render_widget_host_ = static_cast<RenderWidgetHostImpl*>(widget); | 333 render_widget_host_ = static_cast<RenderWidgetHostImpl*>(widget); |
335 render_widget_host_->SetView(this); | 334 render_widget_host_->SetView(this); |
336 registrar_.Add(this, | 335 registrar_.Add(this, |
337 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 336 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
338 content::NotificationService::AllBrowserContextsAndSources()); | 337 content::NotificationService::AllBrowserContextsAndSources()); |
339 registrar_.Add(this, | 338 registrar_.Add(this, |
340 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 339 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
341 content::NotificationService::AllBrowserContextsAndSources()); | 340 content::NotificationService::AllBrowserContextsAndSources()); |
342 } | 341 } |
343 | 342 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 | 903 |
905 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { | 904 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { |
906 content::RenderWidgetHostViewBase::SetBackground(background); | 905 content::RenderWidgetHostViewBase::SetBackground(background); |
907 render_widget_host_->SetBackground(background); | 906 render_widget_host_->SetBackground(background); |
908 } | 907 } |
909 | 908 |
910 void RenderWidgetHostViewWin::UnhandledWheelEvent( | 909 void RenderWidgetHostViewWin::UnhandledWheelEvent( |
911 const WebKit::WebMouseWheelEvent& event) { | 910 const WebKit::WebMouseWheelEvent& event) { |
912 } | 911 } |
913 | 912 |
914 void RenderWidgetHostViewWin::ProcessTouchAck( | 913 void RenderWidgetHostViewWin::ProcessTouchAck(bool processed) { |
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) == TRUE; | |
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 } | |
965 } | 914 } |
966 | 915 |
967 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( | 916 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( |
968 bool has_horizontal_scrollbar) { | 917 bool has_horizontal_scrollbar) { |
969 } | 918 } |
970 | 919 |
971 void RenderWidgetHostViewWin::SetScrollOffsetPinning( | 920 void RenderWidgetHostViewWin::SetScrollOffsetPinning( |
972 bool is_pinned_to_left, bool is_pinned_to_right) { | 921 bool is_pinned_to_left, bool is_pinned_to_right) { |
973 } | 922 } |
974 | 923 |
975 /////////////////////////////////////////////////////////////////////////////// | 924 /////////////////////////////////////////////////////////////////////////////// |
976 // RenderWidgetHostViewWin, private: | 925 // RenderWidgetHostViewWin, private: |
977 | 926 |
978 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { | 927 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { |
979 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale | 928 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale |
980 // of a browser process. | 929 // of a browser process. |
981 OnInputLangChange(0, 0); | 930 OnInputLangChange(0, 0); |
982 // Marks that window as supporting mouse-wheel messages rerouting so it is | 931 // Marks that window as supporting mouse-wheel messages rerouting so it is |
983 // scrolled when under the mouse pointer even if inactive. | 932 // scrolled when under the mouse pointer even if inactive. |
984 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd)); | 933 props_.push_back(ui::SetWindowSupportsRerouteMouseWheel(m_hWnd)); |
985 | 934 |
986 SetToGestureMode(); | 935 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { |
987 | 936 // Use gestures if touch event switch isn't present or registration fails. |
| 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 } |
988 return 0; | 956 return 0; |
989 } | 957 } |
990 | 958 |
991 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, | 959 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, |
992 HWND window) { | 960 HWND window) { |
993 // If the container is a popup, clicking elsewhere on screen should close the | 961 // If the container is a popup, clicking elsewhere on screen should close the |
994 // popup. | 962 // popup. |
995 if (close_on_deactivate_ && action == WA_INACTIVE) { | 963 if (close_on_deactivate_ && action == WA_INACTIVE) { |
996 // Send a windows message so that any derived classes | 964 // Send a windows message so that any derived classes |
997 // will get a change to override the default handling | 965 // will get a change to override the default handling |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 } else if (gi.dwID == GID_PAN) { | 1900 } else if (gi.dwID == GID_PAN) { |
1933 // Right now we only decode scroll gestures and we forward to the page | 1901 // Right now we only decode scroll gestures and we forward to the page |
1934 // as scroll events. | 1902 // as scroll events. |
1935 POINT start; | 1903 POINT start; |
1936 POINT delta; | 1904 POINT delta; |
1937 if (DecodeScrollGesture(gi, &start, &delta)) { | 1905 if (DecodeScrollGesture(gi, &start, &delta)) { |
1938 handled = TRUE; | 1906 handled = TRUE; |
1939 render_widget_host_->ForwardWheelEvent( | 1907 render_widget_host_->ForwardWheelEvent( |
1940 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); | 1908 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); |
1941 } | 1909 } |
1942 } else if (gi.dwID == GID_BEGIN) { | |
1943 // Send a touch event at this location; if the touch start is handled | |
1944 // then we switch to touch mode, rather than gesture mode (in the ACK). | |
1945 TOUCHINPUT fake_touch; | |
1946 fake_touch.x = gi.ptsLocation.x * 100; | |
1947 fake_touch.y = gi.ptsLocation.y * 100; | |
1948 fake_touch.cxContact = 100; | |
1949 fake_touch.cyContact = 100; | |
1950 fake_touch.dwMask = 0; | |
1951 fake_touch.dwFlags = TOUCHEVENTF_DOWN | TOUCHEVENTF_PRIMARY; | |
1952 fake_touch.dwID = gi.dwInstanceID; | |
1953 touch_state_.UpdateTouchPoints(&fake_touch, 1); | |
1954 if (touch_state_.is_changed()) | |
1955 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event()); | |
1956 } else if (gi.dwID == GID_END) { | |
1957 if (touch_state_.ReleaseTouchPoints()) | |
1958 render_widget_host_->ForwardTouchEvent(touch_state_.touch_event()); | |
1959 } | 1910 } |
1960 ::CloseGestureInfoHandle(gi_handle); | 1911 ::CloseGestureInfoHandle(gi_handle); |
1961 return 0; | 1912 return 0; |
1962 } | 1913 } |
1963 | 1914 |
1964 void RenderWidgetHostViewWin::OnAccessibilityNotifications( | 1915 void RenderWidgetHostViewWin::OnAccessibilityNotifications( |
1965 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 1916 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
1966 if (!GetBrowserAccessibilityManager()) { | 1917 if (!GetBrowserAccessibilityManager()) { |
1967 SetBrowserAccessibilityManager( | 1918 SetBrowserAccessibilityManager( |
1968 BrowserAccessibilityManager::CreateEmptyDocument( | 1919 BrowserAccessibilityManager::CreateEmptyDocument( |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2648 void RenderWidgetHostViewWin::ResetPointerDownContext() { | 2599 void RenderWidgetHostViewWin::ResetPointerDownContext() { |
2649 // If the default focus on the page is on an edit field and we did not | 2600 // If the default focus on the page is on an edit field and we did not |
2650 // receive a focus change in the context of a pointer down message, it means | 2601 // receive a focus change in the context of a pointer down message, it means |
2651 // that the pointer down message occurred on the edit field and we should | 2602 // that the pointer down message occurred on the edit field and we should |
2652 // display the on screen keyboard | 2603 // display the on screen keyboard |
2653 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 2604 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
2654 DisplayOnScreenKeyboardIfNeeded(); | 2605 DisplayOnScreenKeyboardIfNeeded(); |
2655 received_focus_change_after_pointer_down_ = false; | 2606 received_focus_change_after_pointer_down_ = false; |
2656 pointer_down_context_ = false; | 2607 pointer_down_context_ = false; |
2657 } | 2608 } |
OLD | NEW |