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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 #include "ui/gfx/geometry/size_conversions.h" | 90 #include "ui/gfx/geometry/size_conversions.h" |
91 #include "ui/gfx/skia_util.h" | 91 #include "ui/gfx/skia_util.h" |
92 #include "ui/touch_selection/touch_selection_controller.h" | 92 #include "ui/touch_selection/touch_selection_controller.h" |
93 #include "ui/wm/public/activation_client.h" | 93 #include "ui/wm/public/activation_client.h" |
94 #include "ui/wm/public/scoped_tooltip_disabler.h" | 94 #include "ui/wm/public/scoped_tooltip_disabler.h" |
95 #include "ui/wm/public/tooltip_client.h" | 95 #include "ui/wm/public/tooltip_client.h" |
96 #include "ui/wm/public/transient_window_client.h" | 96 #include "ui/wm/public/transient_window_client.h" |
97 #include "ui/wm/public/window_types.h" | 97 #include "ui/wm/public/window_types.h" |
98 | 98 |
99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
100 #include "base/time/time.h" | |
100 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 101 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
101 #include "content/browser/accessibility/browser_accessibility_win.h" | 102 #include "content/browser/accessibility/browser_accessibility_win.h" |
102 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" | 103 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" |
103 #include "ui/base/win/hidden_window.h" | 104 #include "ui/base/win/hidden_window.h" |
105 #include "ui/base/win/osk_display_manager.h" | |
104 #include "ui/display/win/screen_win.h" | 106 #include "ui/display/win/screen_win.h" |
105 #include "ui/gfx/gdi_util.h" | 107 #include "ui/gfx/gdi_util.h" |
106 #endif | 108 #endif |
107 | 109 |
108 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 110 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
109 #include "content/common/input_messages.h" | 111 #include "content/common/input_messages.h" |
110 #include "ui/events/linux/text_edit_command_auralinux.h" | 112 #include "ui/events/linux/text_edit_command_auralinux.h" |
111 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" | 113 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" |
112 #endif | 114 #endif |
113 | 115 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 int changed_touch_id) { | 207 int changed_touch_id) { |
206 if (event->type == blink::WebInputEvent::TouchMove || | 208 if (event->type == blink::WebInputEvent::TouchMove || |
207 event->type == blink::WebInputEvent::TouchCancel) { | 209 event->type == blink::WebInputEvent::TouchCancel) { |
208 for (size_t i = 0; i < event->touchesLength; ++i) { | 210 for (size_t i = 0; i < event->touchesLength; ++i) { |
209 if (event->touches[i].id != changed_touch_id) | 211 if (event->touches[i].id != changed_touch_id) |
210 event->touches[i].state = blink::WebTouchPoint::StateStationary; | 212 event->touches[i].state = blink::WebTouchPoint::StateStationary; |
211 } | 213 } |
212 } | 214 } |
213 } | 215 } |
214 | 216 |
217 #if defined(OS_WIN) | |
218 const int kVirtualKeyboardDisplayWaitTimeoutMs = 100; | |
219 const int kMaxVirtualKeyboardDisplayRetries = 5; | |
220 | |
221 void DismissVirtualKeyboardTask() { | |
222 static int virtual_keyboard_display_retries = 0; | |
ncarter (slow)
2016/05/19 17:45:55
I believe was preexisting behavior, but isn't it p
ananta
2016/05/19 19:33:38
Thanks for identifying this issue.
Added a commen
| |
223 // If the virtual keyboard is not yet visible, then we execute the task again | |
224 // waiting for it to show up. | |
225 if (!ui::DismissVirtualKeyboard()) { | |
226 if (virtual_keyboard_display_retries < kMaxVirtualKeyboardDisplayRetries) { | |
227 BrowserThread::PostDelayedTask( | |
228 BrowserThread::UI, FROM_HERE, | |
229 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)), | |
230 base::TimeDelta::FromMilliseconds( | |
231 kVirtualKeyboardDisplayWaitTimeoutMs)); | |
232 ++virtual_keyboard_display_retries; | |
233 } | |
234 else { | |
235 virtual_keyboard_display_retries = 0; | |
236 } | |
237 } | |
238 } | |
239 | |
240 // This class implements the ui::OnScreenKeyboardObserver interface | |
241 // which provides notifications about the on screen keyboard on Windows getting | |
242 // displayed or hidden in response to taps on editable fields. | |
243 // It provides functionality to request blink to scroll the input field if it | |
244 // is obscured by the on screen keyboard. | |
245 class WinScreenKeyboardObserver : public ui::OnScreenKeyboardObserver { | |
246 public: | |
247 explicit WinScreenKeyboardObserver(RenderWidgetHostImpl* host, | |
248 const gfx::Point& location_dips, | |
249 float scale_factor) | |
250 : host_(host), | |
251 location_in_dips_(location_dips), | |
252 device_scale_factor_(scale_factor) { | |
253 if (host_ && host_->GetView()) | |
254 host_->GetView()->SetInsets(gfx::Insets()); | |
255 } | |
256 | |
257 // base::win::OnScreenKeyboardObserver overrides. | |
258 void OnKeyboardVisible(const gfx::Rect& keyboard_rect_dips) override { | |
259 DCHECK(host_); | |
260 if (host_ && host_->GetView()) { | |
261 // We use the PtInRect API to determine if the touch occurred in the | |
262 // bounds of the OSK. | |
263 // The API expects the point and the rectangle in pixels. | |
264 gfx::Rect keyboard_rect_pixels = | |
265 gfx::ConvertRectToPixel(device_scale_factor_, keyboard_rect_dips); | |
266 RECT keyboard_rect_windows = keyboard_rect_pixels.ToRECT(); | |
267 | |
268 gfx::Point location_in_pixels = gfx::ConvertPointToPixel( | |
269 device_scale_factor_, location_in_dips_); | |
270 POINT touch_location = location_in_pixels.ToPOINT(); | |
271 | |
272 if (::PtInRect(&keyboard_rect_windows, touch_location)) { | |
273 DVLOG(1) << "OSK covering focus point."; | |
274 // Get the intersection of the view rectangle and the OSK. | |
275 // The viewport needs to be moved up by the height of the intersection. | |
276 gfx::Rect screen_rect = host_->GetView()->GetBoundsInRootWindow(); | |
277 gfx::Rect intersect = gfx::IntersectRects(keyboard_rect_dips, | |
278 screen_rect); | |
279 host_->GetView()->SetInsets(gfx::Insets(0, 0, intersect.height(), 0)); | |
280 host_->ScrollFocusedEditableNodeIntoRect(intersect); | |
281 } else { | |
282 // Restore the viewport. | |
283 host_->GetView()->SetInsets(gfx::Insets()); | |
284 } | |
285 } | |
286 } | |
287 | |
288 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_dips) override { | |
289 DCHECK(host_); | |
290 // Restore the viewport. | |
291 if (host_ && host_->GetView()) | |
292 host_->GetView()->SetInsets(gfx::Insets()); | |
293 } | |
294 | |
295 private: | |
296 RenderWidgetHostImpl* host_; | |
297 // The location in DIPs where the touch occurred. | |
298 gfx::Point location_in_dips_; | |
299 // The current device scale factor. | |
300 float device_scale_factor_; | |
301 | |
302 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); | |
303 }; | |
304 #endif | |
305 | |
215 } // namespace | 306 } // namespace |
216 | 307 |
217 // We need to watch for mouse events outside a Web Popup or its parent | 308 // We need to watch for mouse events outside a Web Popup or its parent |
218 // and dismiss the popup for certain events. | 309 // and dismiss the popup for certain events. |
219 class RenderWidgetHostViewAura::EventFilterForPopupExit | 310 class RenderWidgetHostViewAura::EventFilterForPopupExit |
220 : public ui::EventHandler { | 311 : public ui::EventHandler { |
221 public: | 312 public: |
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 313 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
223 : rwhva_(rwhva) { | 314 : rwhva_(rwhva) { |
224 DCHECK(rwhva_); | 315 DCHECK(rwhva_); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 can_compose_inline_(true), | 467 can_compose_inline_(true), |
377 has_composition_text_(false), | 468 has_composition_text_(false), |
378 accept_return_character_(false), | 469 accept_return_character_(false), |
379 begin_frame_source_(nullptr), | 470 begin_frame_source_(nullptr), |
380 needs_begin_frames_(false), | 471 needs_begin_frames_(false), |
381 synthetic_move_sent_(false), | 472 synthetic_move_sent_(false), |
382 cursor_visibility_state_in_renderer_(UNKNOWN), | 473 cursor_visibility_state_in_renderer_(UNKNOWN), |
383 #if defined(OS_WIN) | 474 #if defined(OS_WIN) |
384 legacy_render_widget_host_HWND_(nullptr), | 475 legacy_render_widget_host_HWND_(nullptr), |
385 legacy_window_destroyed_(false), | 476 legacy_window_destroyed_(false), |
477 virtual_keyboard_requested_(false), | |
386 #endif | 478 #endif |
387 has_snapped_to_boundary_(false), | 479 has_snapped_to_boundary_(false), |
388 is_guest_view_hack_(is_guest_view_hack), | 480 is_guest_view_hack_(is_guest_view_hack), |
389 set_focus_on_mouse_down_or_key_event_(false), | 481 set_focus_on_mouse_down_or_key_event_(false), |
390 device_scale_factor_(0.0f), | 482 device_scale_factor_(0.0f), |
391 disable_input_event_router_for_testing_(false), | 483 disable_input_event_router_for_testing_(false), |
392 weak_ptr_factory_(this) { | 484 weak_ptr_factory_(this) { |
393 if (!is_guest_view_hack_) | 485 if (!is_guest_view_hack_) |
394 host_->SetView(this); | 486 host_->SetView(this); |
395 | 487 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 return requested_rect.size(); | 949 return requested_rect.size(); |
858 } | 950 } |
859 | 951 |
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 952 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
861 if (insets != insets_) { | 953 if (insets != insets_) { |
862 insets_ = insets; | 954 insets_ = insets; |
863 host_->WasResized(); | 955 host_->WasResized(); |
864 } | 956 } |
865 } | 957 } |
866 | 958 |
959 void RenderWidgetHostViewAura::FocusedNodeTouched( | |
960 const gfx::Point& location_dips, | |
961 bool editable) { | |
962 #if defined(OS_WIN) | |
963 RenderViewHost* rvh = RenderViewHost::From(host_); | |
964 if (rvh && rvh->GetDelegate()) | |
965 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable); | |
966 | |
967 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
968 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
ncarter (slow)
2016/05/19 17:45:55
Indent += 2
ananta
2016/05/19 19:33:38
Done.
| |
969 DCHECK(osk_display_manager); | |
970 if (editable) { | |
971 keyboard_observer_.reset(new WinScreenKeyboardObserver(host_, | |
972 location_dips, device_scale_factor_)); | |
973 virtual_keyboard_requested_ = osk_display_manager->DisplayVirtualKeyboard( | |
974 keyboard_observer_.get()); | |
975 } else { | |
976 virtual_keyboard_requested_ = false; | |
977 osk_display_manager->DismissVirtualKeyboard(); | |
978 } | |
979 #endif | |
980 } | |
981 | |
867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { | 982 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { |
868 current_cursor_ = cursor; | 983 current_cursor_ = cursor; |
869 const display::Display display = | 984 const display::Display display = |
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 985 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
871 current_cursor_.SetDisplayInfo(display); | 986 current_cursor_.SetDisplayInfo(display); |
872 UpdateCursorIfOverSelf(); | 987 UpdateCursorIfOverSelf(); |
873 } | 988 } |
874 | 989 |
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 990 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
876 is_loading_ = is_loading; | 991 is_loading_ = is_loading; |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1996 // Transformations use physical pixels rather than DIP, so conversion | 2111 // Transformations use physical pixels rather than DIP, so conversion |
1997 // is necessary. | 2112 // is necessary. |
1998 gfx::Point point_in_pixels = | 2113 gfx::Point point_in_pixels = |
1999 gfx::ConvertPointToPixel(device_scale_factor_, point); | 2114 gfx::ConvertPointToPixel(device_scale_factor_, point); |
2000 delegated_frame_host_->TransformPointToLocalCoordSpace( | 2115 delegated_frame_host_->TransformPointToLocalCoordSpace( |
2001 point_in_pixels, original_surface, transformed_point); | 2116 point_in_pixels, original_surface, transformed_point); |
2002 *transformed_point = | 2117 *transformed_point = |
2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | 2118 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); |
2004 } | 2119 } |
2005 | 2120 |
2121 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) { | |
2122 #if defined(OS_WIN) | |
2123 if (!editable && virtual_keyboard_requested_) { | |
2124 virtual_keyboard_requested_ = false; | |
2125 | |
2126 RenderViewHost* rvh = RenderViewHost::From(host_); | |
2127 if (rvh && rvh->GetDelegate()) | |
2128 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | |
2129 | |
2130 BrowserThread::PostDelayedTask( | |
2131 BrowserThread::UI, FROM_HERE, | |
2132 base::Bind(base::IgnoreResult(&DismissVirtualKeyboardTask)), | |
ncarter (slow)
2016/05/19 17:45:55
IgnoreResult shouldn't be necessary -- this functi
ananta
2016/05/19 19:33:37
Done.
| |
2133 base::TimeDelta::FromMilliseconds(kVirtualKeyboardDisplayWaitTimeoutMs)); | |
ncarter (slow)
2016/05/19 17:45:54
This indentation looks off (git cl format?)
ananta
2016/05/19 19:33:37
Done.
| |
2134 } | |
2135 #endif | |
2136 } | |
2137 | |
2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 2138 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 2139 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); |
2008 | 2140 |
2009 if (event->type() == ui::ET_SCROLL) { | 2141 if (event->type() == ui::ET_SCROLL) { |
2010 #if !defined(OS_WIN) | 2142 #if !defined(OS_WIN) |
2011 // TODO(ananta) | 2143 // TODO(ananta) |
2012 // Investigate if this is true for Windows 8 Metro ASH as well. | 2144 // Investigate if this is true for Windows 8 Metro ASH as well. |
2013 if (event->finger_count() != 2) | 2145 if (event->finger_count() != 2) |
2014 return; | 2146 return; |
2015 #endif | 2147 #endif |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2865 | 2997 |
2866 //////////////////////////////////////////////////////////////////////////////// | 2998 //////////////////////////////////////////////////////////////////////////////// |
2867 // RenderWidgetHostViewBase, public: | 2999 // RenderWidgetHostViewBase, public: |
2868 | 3000 |
2869 // static | 3001 // static |
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 3002 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2871 GetScreenInfoForWindow(results, NULL); | 3003 GetScreenInfoForWindow(results, NULL); |
2872 } | 3004 } |
2873 | 3005 |
2874 } // namespace content | 3006 } // namespace content |
OLD | NEW |