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

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

Issue 1986153005: The on screen keyboard on Windows 8+ should not obscure the input field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments and update comment Created 4 years, 7 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
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_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
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"
106 #include "ui/base/win/osk_display_observer.h"
104 #include "ui/display/win/screen_win.h" 107 #include "ui/display/win/screen_win.h"
105 #include "ui/gfx/gdi_util.h" 108 #include "ui/gfx/gdi_util.h"
106 #endif 109 #endif
107 110
108 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 111 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
109 #include "content/common/input_messages.h" 112 #include "content/common/input_messages.h"
110 #include "ui/events/linux/text_edit_command_auralinux.h" 113 #include "ui/events/linux/text_edit_command_auralinux.h"
111 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" 114 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
112 #endif 115 #endif
113 116
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 int changed_touch_id) { 208 int changed_touch_id) {
206 if (event->type == blink::WebInputEvent::TouchMove || 209 if (event->type == blink::WebInputEvent::TouchMove ||
207 event->type == blink::WebInputEvent::TouchCancel) { 210 event->type == blink::WebInputEvent::TouchCancel) {
208 for (size_t i = 0; i < event->touchesLength; ++i) { 211 for (size_t i = 0; i < event->touchesLength; ++i) {
209 if (event->touches[i].id != changed_touch_id) 212 if (event->touches[i].id != changed_touch_id)
210 event->touches[i].state = blink::WebTouchPoint::StateStationary; 213 event->touches[i].state = blink::WebTouchPoint::StateStationary;
211 } 214 }
212 } 215 }
213 } 216 }
214 217
218 #if defined(OS_WIN)
219 const int kVirtualKeyboardDisplayWaitTimeoutMs = 100;
220 const int kMaxVirtualKeyboardDisplayRetries = 5;
221
222 // Using a static variable here to detect retries could cause issues in cases
223 // like the virtual keyboard getting displayed in multiple tabs/windows. The
224 // attempts to dismiss the virtual keyboard in these tabs/windows would result
225 // in the retry counter getting overwritten incorrectly thus leading to issues.
226 // TODO(ananta)
227 // Come up with a better approach to handle this.
228 void DismissVirtualKeyboardTask() {
sky 2016/05/19 22:25:08 I think this should be handled in the display mana
ananta 2016/05/19 23:15:40 Done. Handled in the DismissKeyboard function.
229 static int virtual_keyboard_display_retries = 0;
230 // If the virtual keyboard is not yet visible, then we execute the task again
231 // waiting for it to show up.
232 if (!ui::DismissVirtualKeyboard()) {
233 if (virtual_keyboard_display_retries < kMaxVirtualKeyboardDisplayRetries) {
234 BrowserThread::PostDelayedTask(
235 BrowserThread::UI, FROM_HERE,
236 base::Bind(&DismissVirtualKeyboardTask),
237 base::TimeDelta::FromMilliseconds(
238 kVirtualKeyboardDisplayWaitTimeoutMs));
239 ++virtual_keyboard_display_retries;
240 } else {
241 virtual_keyboard_display_retries = 0;
242 }
243 }
244 }
245
246 // This class implements the ui::OnScreenKeyboardObserver interface
247 // which provides notifications about the on screen keyboard on Windows getting
248 // displayed or hidden in response to taps on editable fields.
249 // It provides functionality to request blink to scroll the input field if it
250 // is obscured by the on screen keyboard.
251 class WinScreenKeyboardObserver : public ui::OnScreenKeyboardObserver {
252 public:
253 explicit WinScreenKeyboardObserver(RenderWidgetHostImpl* host,
254 const gfx::Point& location_dips,
255 float scale_factor)
256 : host_(host),
257 location_in_dips_(location_dips),
258 device_scale_factor_(scale_factor) {
259 if (host_ && host_->GetView())
260 host_->GetView()->SetInsets(gfx::Insets());
261 }
262
263 // base::win::OnScreenKeyboardObserver overrides.
264 void OnKeyboardVisible(const gfx::Rect& keyboard_rect_dips) override {
265 DCHECK(host_);
266
267 if (host_ && host_->GetView()) {
268 // We use the PtInRect API to determine if the touch occurred in the
269 // bounds of the OSK.
270 // The API expects the point and the rectangle in pixels.
271 gfx::Rect keyboard_rect_pixels =
272 gfx::ConvertRectToPixel(device_scale_factor_, keyboard_rect_dips);
273 RECT keyboard_rect_windows = keyboard_rect_pixels.ToRECT();
274
275 gfx::Point location_in_pixels =
276 gfx::ConvertPointToPixel(device_scale_factor_, location_in_dips_);
277 POINT touch_location = location_in_pixels.ToPOINT();
278
279 if (::PtInRect(&keyboard_rect_windows, touch_location)) {
280 DVLOG(1) << "OSK covering focus point.";
281 // Get the intersection of the view rectangle and the OSK.
282 // The viewport needs to be moved up by the height of the intersection.
283 gfx::Rect screen_rect = host_->GetView()->GetBoundsInRootWindow();
284 gfx::Rect intersect =
285 gfx::IntersectRects(keyboard_rect_dips, screen_rect);
286 host_->GetView()->SetInsets(gfx::Insets(0, 0, intersect.height(), 0));
287 host_->ScrollFocusedEditableNodeIntoRect(intersect);
288 } else {
289 // Restore the viewport.
290 host_->GetView()->SetInsets(gfx::Insets());
291 }
292 }
293 }
294
295 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_dips) override {
296 DCHECK(host_);
297 // Restore the viewport.
298 if (host_ && host_->GetView())
299 host_->GetView()->SetInsets(gfx::Insets());
300 }
301
302 private:
303 RenderWidgetHostImpl* host_;
304 // The location in DIPs where the touch occurred.
305 gfx::Point location_in_dips_;
306 // The current device scale factor.
307 float device_scale_factor_;
308
309 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver);
310 };
311 #endif
312
215 } // namespace 313 } // namespace
216 314
217 // We need to watch for mouse events outside a Web Popup or its parent 315 // We need to watch for mouse events outside a Web Popup or its parent
218 // and dismiss the popup for certain events. 316 // and dismiss the popup for certain events.
219 class RenderWidgetHostViewAura::EventFilterForPopupExit 317 class RenderWidgetHostViewAura::EventFilterForPopupExit
220 : public ui::EventHandler { 318 : public ui::EventHandler {
221 public: 319 public:
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) 320 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
223 : rwhva_(rwhva) { 321 : rwhva_(rwhva) {
224 DCHECK(rwhva_); 322 DCHECK(rwhva_);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 can_compose_inline_(true), 474 can_compose_inline_(true),
377 has_composition_text_(false), 475 has_composition_text_(false),
378 accept_return_character_(false), 476 accept_return_character_(false),
379 begin_frame_source_(nullptr), 477 begin_frame_source_(nullptr),
380 needs_begin_frames_(false), 478 needs_begin_frames_(false),
381 synthetic_move_sent_(false), 479 synthetic_move_sent_(false),
382 cursor_visibility_state_in_renderer_(UNKNOWN), 480 cursor_visibility_state_in_renderer_(UNKNOWN),
383 #if defined(OS_WIN) 481 #if defined(OS_WIN)
384 legacy_render_widget_host_HWND_(nullptr), 482 legacy_render_widget_host_HWND_(nullptr),
385 legacy_window_destroyed_(false), 483 legacy_window_destroyed_(false),
484 virtual_keyboard_requested_(false),
386 #endif 485 #endif
387 has_snapped_to_boundary_(false), 486 has_snapped_to_boundary_(false),
388 is_guest_view_hack_(is_guest_view_hack), 487 is_guest_view_hack_(is_guest_view_hack),
389 set_focus_on_mouse_down_or_key_event_(false), 488 set_focus_on_mouse_down_or_key_event_(false),
390 device_scale_factor_(0.0f), 489 device_scale_factor_(0.0f),
391 disable_input_event_router_for_testing_(false), 490 disable_input_event_router_for_testing_(false),
392 weak_ptr_factory_(this) { 491 weak_ptr_factory_(this) {
393 if (!is_guest_view_hack_) 492 if (!is_guest_view_hack_)
394 host_->SetView(this); 493 host_->SetView(this);
395 494
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 return requested_rect.size(); 956 return requested_rect.size();
858 } 957 }
859 958
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { 959 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
861 if (insets != insets_) { 960 if (insets != insets_) {
862 insets_ = insets; 961 insets_ = insets;
863 host_->WasResized(); 962 host_->WasResized();
864 } 963 }
865 } 964 }
866 965
966 void RenderWidgetHostViewAura::FocusedNodeTouched(
967 const gfx::Point& location_dips,
968 bool editable) {
969 #if defined(OS_WIN)
970 RenderViewHost* rvh = RenderViewHost::From(host_);
971 if (rvh && rvh->GetDelegate())
972 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable);
973
974 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
975 ui::OnScreenKeyboardDisplayManager::GetInstance();
976 DCHECK(osk_display_manager);
977 if (editable) {
978 keyboard_observer_.reset(new WinScreenKeyboardObserver(
979 host_, location_dips, device_scale_factor_));
980 virtual_keyboard_requested_ =
981 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get());
982 } else {
983 virtual_keyboard_requested_ = false;
984 osk_display_manager->DismissVirtualKeyboard();
985 }
986 #endif
987 }
988
867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { 989 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
868 current_cursor_ = cursor; 990 current_cursor_ = cursor;
869 const display::Display display = 991 const display::Display display =
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 992 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
871 current_cursor_.SetDisplayInfo(display); 993 current_cursor_.SetDisplayInfo(display);
872 UpdateCursorIfOverSelf(); 994 UpdateCursorIfOverSelf();
873 } 995 }
874 996
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 997 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
876 is_loading_ = is_loading; 998 is_loading_ = is_loading;
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 // Transformations use physical pixels rather than DIP, so conversion 2118 // Transformations use physical pixels rather than DIP, so conversion
1997 // is necessary. 2119 // is necessary.
1998 gfx::Point point_in_pixels = 2120 gfx::Point point_in_pixels =
1999 gfx::ConvertPointToPixel(device_scale_factor_, point); 2121 gfx::ConvertPointToPixel(device_scale_factor_, point);
2000 delegated_frame_host_->TransformPointToLocalCoordSpace( 2122 delegated_frame_host_->TransformPointToLocalCoordSpace(
2001 point_in_pixels, original_surface, transformed_point); 2123 point_in_pixels, original_surface, transformed_point);
2002 *transformed_point = 2124 *transformed_point =
2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); 2125 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point);
2004 } 2126 }
2005 2127
2128 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) {
2129 #if defined(OS_WIN)
2130 if (!editable && virtual_keyboard_requested_) {
2131 virtual_keyboard_requested_ = false;
2132
2133 RenderViewHost* rvh = RenderViewHost::From(host_);
2134 if (rvh && rvh->GetDelegate())
2135 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false);
2136
2137 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
2138 base::Bind(&DismissVirtualKeyboardTask),
2139 base::TimeDelta::FromMilliseconds(
2140 kVirtualKeyboardDisplayWaitTimeoutMs));
2141 }
2142 #endif
2143 }
2144
2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { 2145 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); 2146 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2008 2147
2009 if (event->type() == ui::ET_SCROLL) { 2148 if (event->type() == ui::ET_SCROLL) {
2010 #if !defined(OS_WIN) 2149 #if !defined(OS_WIN)
2011 // TODO(ananta) 2150 // TODO(ananta)
2012 // Investigate if this is true for Windows 8 Metro ASH as well. 2151 // Investigate if this is true for Windows 8 Metro ASH as well.
2013 if (event->finger_count() != 2) 2152 if (event->finger_count() != 2)
2014 return; 2153 return;
2015 #endif 2154 #endif
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 3004
2866 //////////////////////////////////////////////////////////////////////////////// 3005 ////////////////////////////////////////////////////////////////////////////////
2867 // RenderWidgetHostViewBase, public: 3006 // RenderWidgetHostViewBase, public:
2868 3007
2869 // static 3008 // static
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 3009 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2871 GetScreenInfoForWindow(results, NULL); 3010 GetScreenInfoForWindow(results, NULL);
2872 } 3011 }
2873 3012
2874 } // namespace content 3013 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698