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

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: Add a check for viewport bottom bigger than view height 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 // This class implements the ui::OnScreenKeyboardObserver interface
220 // which provides notifications about the on screen keyboard on Windows getting
221 // displayed or hidden in response to taps on editable fields.
222 // It provides functionality to request blink to scroll the input field if it
223 // is obscured by the on screen keyboard.
224 class WinScreenKeyboardObserver : public ui::OnScreenKeyboardObserver {
225 public:
226 WinScreenKeyboardObserver(RenderWidgetHostImpl* host,
227 const gfx::Point& location_dips_screen,
228 float scale_factor,
229 aura::Window* window)
230 : host_(host),
231 location_dips_screen_(location_dips_screen),
232 device_scale_factor_(scale_factor),
233 window_(window) {
234 host_->GetView()->SetInsets(gfx::Insets());
235 }
236
237 // base::win::OnScreenKeyboardObserver overrides.
238 void OnKeyboardVisible(const gfx::Rect& keyboard_rect_pixels) override {
239 gfx::Point location_in_pixels =
240 gfx::ConvertPointToPixel(device_scale_factor_, location_dips_screen_);
241
242 if (keyboard_rect_pixels.Contains(location_in_pixels)) {
243 aura::client::ScreenPositionClient* screen_position_client =
244 aura::client::GetScreenPositionClient(window_->GetRootWindow());
245 if (!screen_position_client)
246 return;
sky 2016/05/21 16:04:38 If you early return in this function do you need t
ananta 2016/05/23 19:32:07 Reset the view port at the top of this function.
247
248 DVLOG(1) << "OSK covering focus point.";
249 gfx::Rect keyboard_rect_dips =
250 gfx::ConvertRectToDIP(device_scale_factor_, keyboard_rect_pixels);
251 gfx::Rect bounds_in_screen = window_->GetBoundsInScreen();
252
253 // Set the viewport of the window to be just above the on screen
254 // keyboard.
255 int viewport_bottom =
256 abs(keyboard_rect_dips.y() - bounds_in_screen.bottom());
sky 2016/05/21 16:04:38 Why do you do abs here? Shouldn't bounds_in_screen
ananta 2016/05/23 19:32:07 Done.
ananta 2016/05/23 19:32:07 Done.
257
258 // If the viewport is bigger than the view, then we cannot handle it
259 // with the current approach. Moving the window above the OSK is one way.
260 // That for a later patchset.
261 if (viewport_bottom > bounds_in_screen.height())
262 return;
263
264 host_->GetView()->SetInsets(gfx::Insets(0, 0, viewport_bottom, 0));
265
266 gfx::Point origin(location_dips_screen_);
267 screen_position_client->ConvertPointFromScreen(window_, &origin);
268
269 // We want to scroll the node into a rectangle which originates from
270 // the touch point and a small offset (10) in either direction.
271 gfx::Rect node_rect(origin.x(), origin.y(), 10, 10);
272 host_->ScrollFocusedEditableNodeIntoRect(node_rect);
273 } else {
274 // Restore the viewport.
275 host_->GetView()->SetInsets(gfx::Insets());
276 }
277 }
278
279 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override {
280 // Restore the viewport.
281 host_->GetView()->SetInsets(gfx::Insets());
282 }
283
284 private:
285 RenderWidgetHostImpl* host_;
286 // The location in DIPs where the touch occurred.
287 gfx::Point location_dips_screen_;
288 // The current device scale factor.
289 float device_scale_factor_;
290
291 // The content Window.
292 aura::Window* window_;
293
294 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver);
295 };
296 #endif
297
215 } // namespace 298 } // namespace
216 299
217 // We need to watch for mouse events outside a Web Popup or its parent 300 // We need to watch for mouse events outside a Web Popup or its parent
218 // and dismiss the popup for certain events. 301 // and dismiss the popup for certain events.
219 class RenderWidgetHostViewAura::EventFilterForPopupExit 302 class RenderWidgetHostViewAura::EventFilterForPopupExit
220 : public ui::EventHandler { 303 : public ui::EventHandler {
221 public: 304 public:
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) 305 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
223 : rwhva_(rwhva) { 306 : rwhva_(rwhva) {
224 DCHECK(rwhva_); 307 DCHECK(rwhva_);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 can_compose_inline_(true), 459 can_compose_inline_(true),
377 has_composition_text_(false), 460 has_composition_text_(false),
378 accept_return_character_(false), 461 accept_return_character_(false),
379 begin_frame_source_(nullptr), 462 begin_frame_source_(nullptr),
380 needs_begin_frames_(false), 463 needs_begin_frames_(false),
381 synthetic_move_sent_(false), 464 synthetic_move_sent_(false),
382 cursor_visibility_state_in_renderer_(UNKNOWN), 465 cursor_visibility_state_in_renderer_(UNKNOWN),
383 #if defined(OS_WIN) 466 #if defined(OS_WIN)
384 legacy_render_widget_host_HWND_(nullptr), 467 legacy_render_widget_host_HWND_(nullptr),
385 legacy_window_destroyed_(false), 468 legacy_window_destroyed_(false),
469 virtual_keyboard_requested_(false),
386 #endif 470 #endif
387 has_snapped_to_boundary_(false), 471 has_snapped_to_boundary_(false),
388 is_guest_view_hack_(is_guest_view_hack), 472 is_guest_view_hack_(is_guest_view_hack),
389 set_focus_on_mouse_down_or_key_event_(false), 473 set_focus_on_mouse_down_or_key_event_(false),
390 device_scale_factor_(0.0f), 474 device_scale_factor_(0.0f),
391 disable_input_event_router_for_testing_(false), 475 disable_input_event_router_for_testing_(false),
392 weak_ptr_factory_(this) { 476 weak_ptr_factory_(this) {
393 if (!is_guest_view_hack_) 477 if (!is_guest_view_hack_)
394 host_->SetView(this); 478 host_->SetView(this);
395 479
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 return requested_rect.size(); 941 return requested_rect.size();
858 } 942 }
859 943
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { 944 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
861 if (insets != insets_) { 945 if (insets != insets_) {
862 insets_ = insets; 946 insets_ = insets;
863 host_->WasResized(); 947 host_->WasResized();
864 } 948 }
865 } 949 }
866 950
951 void RenderWidgetHostViewAura::FocusedNodeTouched(
952 const gfx::Point& location_dips_screen,
953 bool editable) {
954 #if defined(OS_WIN)
955 RenderViewHost* rvh = RenderViewHost::From(host_);
956 if (rvh && rvh->GetDelegate())
957 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable);
958
959 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
960 ui::OnScreenKeyboardDisplayManager::GetInstance();
961 DCHECK(osk_display_manager);
962 if (editable && host_ && host_->GetView()) {
963 keyboard_observer_.reset(new WinScreenKeyboardObserver(
964 host_, location_dips_screen, device_scale_factor_,
965 window_));
966 virtual_keyboard_requested_ =
967 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get());
968 } else {
969 virtual_keyboard_requested_ = false;
970 osk_display_manager->DismissVirtualKeyboard();
971 }
972 #endif
973 }
974
867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { 975 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
868 current_cursor_ = cursor; 976 current_cursor_ = cursor;
869 const display::Display display = 977 const display::Display display =
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 978 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
871 current_cursor_.SetDisplayInfo(display); 979 current_cursor_.SetDisplayInfo(display);
872 UpdateCursorIfOverSelf(); 980 UpdateCursorIfOverSelf();
873 } 981 }
874 982
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 983 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
876 is_loading_ = is_loading; 984 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 2104 // Transformations use physical pixels rather than DIP, so conversion
1997 // is necessary. 2105 // is necessary.
1998 gfx::Point point_in_pixels = 2106 gfx::Point point_in_pixels =
1999 gfx::ConvertPointToPixel(device_scale_factor_, point); 2107 gfx::ConvertPointToPixel(device_scale_factor_, point);
2000 delegated_frame_host_->TransformPointToLocalCoordSpace( 2108 delegated_frame_host_->TransformPointToLocalCoordSpace(
2001 point_in_pixels, original_surface, transformed_point); 2109 point_in_pixels, original_surface, transformed_point);
2002 *transformed_point = 2110 *transformed_point =
2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); 2111 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point);
2004 } 2112 }
2005 2113
2114 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) {
2115 #if defined(OS_WIN)
2116 if (!editable && virtual_keyboard_requested_) {
2117 virtual_keyboard_requested_ = false;
2118
2119 RenderViewHost* rvh = RenderViewHost::From(host_);
2120 if (rvh && rvh->GetDelegate())
2121 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false);
2122
2123 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance());
2124 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard();
2125 }
2126 #endif
2127 }
2128
2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { 2129 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); 2130 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2008 2131
2009 if (event->type() == ui::ET_SCROLL) { 2132 if (event->type() == ui::ET_SCROLL) {
2010 #if !defined(OS_WIN) 2133 #if !defined(OS_WIN)
2011 // TODO(ananta) 2134 // TODO(ananta)
2012 // Investigate if this is true for Windows 8 Metro ASH as well. 2135 // Investigate if this is true for Windows 8 Metro ASH as well.
2013 if (event->finger_count() != 2) 2136 if (event->finger_count() != 2)
2014 return; 2137 return;
2015 #endif 2138 #endif
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 popup_child_host_view_->popup_parent_host_view_ == this); 2402 popup_child_host_view_->popup_parent_host_view_ == this);
2280 popup_child_host_view_->popup_parent_host_view_ = NULL; 2403 popup_child_host_view_->popup_parent_host_view_ = NULL;
2281 } 2404 }
2282 event_filter_for_popup_exit_.reset(); 2405 event_filter_for_popup_exit_.reset();
2283 2406
2284 #if defined(OS_WIN) 2407 #if defined(OS_WIN)
2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in 2408 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should 2409 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2287 // be set to NULL. 2410 // be set to NULL.
2288 DCHECK(!legacy_render_widget_host_HWND_); 2411 DCHECK(!legacy_render_widget_host_HWND_);
2412 if (virtual_keyboard_requested_) {
2413 DCHECK(keyboard_observer_.get());
2414 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
2415 ui::OnScreenKeyboardDisplayManager::GetInstance();
2416 DCHECK(osk_display_manager);
2417 osk_display_manager->RemoveObserver(keyboard_observer_.get());
2418 }
2419
2289 #endif 2420 #endif
2290 } 2421 }
2291 2422
2292 void RenderWidgetHostViewAura::CreateAuraWindow() { 2423 void RenderWidgetHostViewAura::CreateAuraWindow() {
2293 DCHECK(!window_); 2424 DCHECK(!window_);
2294 window_ = new aura::Window(this); 2425 window_ = new aura::Window(this);
2295 window_observer_.reset(new WindowObserver(this)); 2426 window_observer_.reset(new WindowObserver(this));
2296 2427
2297 aura::client::SetTooltipText(window_, &tooltip_); 2428 aura::client::SetTooltipText(window_, &tooltip_);
2298 aura::client::SetActivationDelegate(window_, this); 2429 aura::client::SetActivationDelegate(window_, this);
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 2996
2866 //////////////////////////////////////////////////////////////////////////////// 2997 ////////////////////////////////////////////////////////////////////////////////
2867 // RenderWidgetHostViewBase, public: 2998 // RenderWidgetHostViewBase, public:
2868 2999
2869 // static 3000 // static
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 3001 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2871 GetScreenInfoForWindow(results, NULL); 3002 GetScreenInfoForWindow(results, NULL);
2872 } 3003 }
2873 3004
2874 } // namespace content 3005 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698