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

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 more sky comments 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 const gfx::Rect& bounds_in_screen)
230 : host_(host),
231 location_dips_screen_(location_dips_screen),
232 device_scale_factor_(scale_factor),
233 bounds_in_screen_(bounds_in_screen) {
234 if (host_ && host_->GetView())
sky 2016/05/20 22:14:55 Remove check as it's done at call site.
ananta 2016/05/20 22:21:31 Done.
235 host_->GetView()->SetInsets(gfx::Insets());
236 }
237
238 // base::win::OnScreenKeyboardObserver overrides.
239 void OnKeyboardVisible(const gfx::Rect& keyboard_rect_pixels) override {
240 gfx::Point location_in_pixels =
241 gfx::ConvertPointToPixel(device_scale_factor_, location_dips_screen_);
242
243 if (keyboard_rect_pixels.Contains(location_in_pixels)) {
244 DVLOG(1) << "OSK covering focus point.";
245 gfx::Rect keyboard_rect_dips =
246 gfx::ConvertRectToDIP(device_scale_factor_, keyboard_rect_pixels);
247 // Get the intersection of the view rectangle and the OSK.
248 // The viewport needs to be moved up by the height of the intersection.
249 gfx::Rect intersect =
250 gfx::IntersectRects(keyboard_rect_dips, bounds_in_screen_);
251 int viewport_bottom = keyboard_rect_dips.y() - bounds_in_screen.bottom();
252 host_->GetView()->SetInsets(gfx::Insets(0, 0, viewport_bottom, 0));
253 host_->ScrollFocusedEditableNodeIntoRect(intersect);
254 } else {
255 // Restore the viewport.
256 host_->GetView()->SetInsets(gfx::Insets());
257 }
258 }
259
260 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override {
261 // Restore the viewport.
262 if (host_ && host_->GetView())
sky 2016/05/20 22:14:55 remove check.
ananta 2016/05/20 22:21:31 Done.
263 host_->GetView()->SetInsets(gfx::Insets());
264 }
265
266 private:
267 RenderWidgetHostImpl* host_;
268 // The location in DIPs where the touch occurred.
269 gfx::Point location_dips_screen_;
270 // The current device scale factor.
271 float device_scale_factor_;
272
273 // The window bounds in screen coordinates.
274 gfx::Rect bounds_in_screen_;
275
276 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver);
277 };
278 #endif
279
215 } // namespace 280 } // namespace
216 281
217 // We need to watch for mouse events outside a Web Popup or its parent 282 // We need to watch for mouse events outside a Web Popup or its parent
218 // and dismiss the popup for certain events. 283 // and dismiss the popup for certain events.
219 class RenderWidgetHostViewAura::EventFilterForPopupExit 284 class RenderWidgetHostViewAura::EventFilterForPopupExit
220 : public ui::EventHandler { 285 : public ui::EventHandler {
221 public: 286 public:
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) 287 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
223 : rwhva_(rwhva) { 288 : rwhva_(rwhva) {
224 DCHECK(rwhva_); 289 DCHECK(rwhva_);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 can_compose_inline_(true), 441 can_compose_inline_(true),
377 has_composition_text_(false), 442 has_composition_text_(false),
378 accept_return_character_(false), 443 accept_return_character_(false),
379 begin_frame_source_(nullptr), 444 begin_frame_source_(nullptr),
380 needs_begin_frames_(false), 445 needs_begin_frames_(false),
381 synthetic_move_sent_(false), 446 synthetic_move_sent_(false),
382 cursor_visibility_state_in_renderer_(UNKNOWN), 447 cursor_visibility_state_in_renderer_(UNKNOWN),
383 #if defined(OS_WIN) 448 #if defined(OS_WIN)
384 legacy_render_widget_host_HWND_(nullptr), 449 legacy_render_widget_host_HWND_(nullptr),
385 legacy_window_destroyed_(false), 450 legacy_window_destroyed_(false),
451 virtual_keyboard_requested_(false),
386 #endif 452 #endif
387 has_snapped_to_boundary_(false), 453 has_snapped_to_boundary_(false),
388 is_guest_view_hack_(is_guest_view_hack), 454 is_guest_view_hack_(is_guest_view_hack),
389 set_focus_on_mouse_down_or_key_event_(false), 455 set_focus_on_mouse_down_or_key_event_(false),
390 device_scale_factor_(0.0f), 456 device_scale_factor_(0.0f),
391 disable_input_event_router_for_testing_(false), 457 disable_input_event_router_for_testing_(false),
392 weak_ptr_factory_(this) { 458 weak_ptr_factory_(this) {
393 if (!is_guest_view_hack_) 459 if (!is_guest_view_hack_)
394 host_->SetView(this); 460 host_->SetView(this);
395 461
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 return requested_rect.size(); 923 return requested_rect.size();
858 } 924 }
859 925
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { 926 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
861 if (insets != insets_) { 927 if (insets != insets_) {
862 insets_ = insets; 928 insets_ = insets;
863 host_->WasResized(); 929 host_->WasResized();
864 } 930 }
865 } 931 }
866 932
933 void RenderWidgetHostViewAura::FocusedNodeTouched(
934 const gfx::Point& location_dips_screen,
935 bool editable) {
936 #if defined(OS_WIN)
937 RenderViewHost* rvh = RenderViewHost::From(host_);
938 if (rvh && rvh->GetDelegate())
939 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable);
940
941 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
942 ui::OnScreenKeyboardDisplayManager::GetInstance();
943 DCHECK(osk_display_manager);
944 if (editable && host_ && host_->GetView()) {
945 keyboard_observer_.reset(new WinScreenKeyboardObserver(
946 host_, location_dips_screen, device_scale_factor_,
947 window_->GetBoundsInScreen()));
948 virtual_keyboard_requested_ =
949 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get());
950 } else {
951 virtual_keyboard_requested_ = false;
952 osk_display_manager->DismissVirtualKeyboard();
953 }
954 #endif
955 }
956
867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { 957 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
868 current_cursor_ = cursor; 958 current_cursor_ = cursor;
869 const display::Display display = 959 const display::Display display =
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); 960 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
871 current_cursor_.SetDisplayInfo(display); 961 current_cursor_.SetDisplayInfo(display);
872 UpdateCursorIfOverSelf(); 962 UpdateCursorIfOverSelf();
873 } 963 }
874 964
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 965 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
876 is_loading_ = is_loading; 966 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 2086 // Transformations use physical pixels rather than DIP, so conversion
1997 // is necessary. 2087 // is necessary.
1998 gfx::Point point_in_pixels = 2088 gfx::Point point_in_pixels =
1999 gfx::ConvertPointToPixel(device_scale_factor_, point); 2089 gfx::ConvertPointToPixel(device_scale_factor_, point);
2000 delegated_frame_host_->TransformPointToLocalCoordSpace( 2090 delegated_frame_host_->TransformPointToLocalCoordSpace(
2001 point_in_pixels, original_surface, transformed_point); 2091 point_in_pixels, original_surface, transformed_point);
2002 *transformed_point = 2092 *transformed_point =
2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); 2093 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point);
2004 } 2094 }
2005 2095
2096 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) {
2097 #if defined(OS_WIN)
2098 if (!editable && virtual_keyboard_requested_) {
2099 virtual_keyboard_requested_ = false;
2100
2101 RenderViewHost* rvh = RenderViewHost::From(host_);
2102 if (rvh && rvh->GetDelegate())
2103 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false);
2104
2105 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance());
2106 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard();
2107 }
2108 #endif
2109 }
2110
2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { 2111 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); 2112 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2008 2113
2009 if (event->type() == ui::ET_SCROLL) { 2114 if (event->type() == ui::ET_SCROLL) {
2010 #if !defined(OS_WIN) 2115 #if !defined(OS_WIN)
2011 // TODO(ananta) 2116 // TODO(ananta)
2012 // Investigate if this is true for Windows 8 Metro ASH as well. 2117 // Investigate if this is true for Windows 8 Metro ASH as well.
2013 if (event->finger_count() != 2) 2118 if (event->finger_count() != 2)
2014 return; 2119 return;
2015 #endif 2120 #endif
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 popup_child_host_view_->popup_parent_host_view_ == this); 2384 popup_child_host_view_->popup_parent_host_view_ == this);
2280 popup_child_host_view_->popup_parent_host_view_ = NULL; 2385 popup_child_host_view_->popup_parent_host_view_ = NULL;
2281 } 2386 }
2282 event_filter_for_popup_exit_.reset(); 2387 event_filter_for_popup_exit_.reset();
2283 2388
2284 #if defined(OS_WIN) 2389 #if defined(OS_WIN)
2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in 2390 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should 2391 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2287 // be set to NULL. 2392 // be set to NULL.
2288 DCHECK(!legacy_render_widget_host_HWND_); 2393 DCHECK(!legacy_render_widget_host_HWND_);
2394 if (virtual_keyboard_requested_) {
2395 DCHECK(keyboard_observer_.get());
2396 ui::OnScreenKeyboardDisplayManager* osk_display_manager =
2397 ui::OnScreenKeyboardDisplayManager::GetInstance();
2398 DCHECK(osk_display_manager);
2399 osk_display_manager->RemoveObserver(keyboard_observer_.get());
2400 }
2401
2289 #endif 2402 #endif
2290 } 2403 }
2291 2404
2292 void RenderWidgetHostViewAura::CreateAuraWindow() { 2405 void RenderWidgetHostViewAura::CreateAuraWindow() {
2293 DCHECK(!window_); 2406 DCHECK(!window_);
2294 window_ = new aura::Window(this); 2407 window_ = new aura::Window(this);
2295 window_observer_.reset(new WindowObserver(this)); 2408 window_observer_.reset(new WindowObserver(this));
2296 2409
2297 aura::client::SetTooltipText(window_, &tooltip_); 2410 aura::client::SetTooltipText(window_, &tooltip_);
2298 aura::client::SetActivationDelegate(window_, this); 2411 aura::client::SetActivationDelegate(window_, this);
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 2978
2866 //////////////////////////////////////////////////////////////////////////////// 2979 ////////////////////////////////////////////////////////////////////////////////
2867 // RenderWidgetHostViewBase, public: 2980 // RenderWidgetHostViewBase, public:
2868 2981
2869 // static 2982 // static
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2983 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2871 GetScreenInfoForWindow(results, NULL); 2984 GetScreenInfoForWindow(results, NULL);
2872 } 2985 }
2873 2986
2874 } // namespace content 2987 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698