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" | |
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 Loading... | |
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; | |
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()); | |
257 host_->GetView()->SetInsets(gfx::Insets(0, 0, viewport_bottom, 0)); | |
sky
2016/05/20 22:42:59
What happens if viewport_bottom is > height of vie
ananta
2016/05/20 22:52:33
That would make the height of the view 0. https://
| |
258 | |
259 gfx::Point origin(location_dips_screen_); | |
260 screen_position_client->ConvertPointFromScreen(window_, &origin); | |
261 | |
262 // We want to scroll the node into a rectangle which originates from | |
263 // the touch point and a small offset (10) in either direction. | |
264 gfx::Rect node_rect(origin.x(), origin.y(), 10, 10); | |
265 host_->ScrollFocusedEditableNodeIntoRect(node_rect); | |
266 } else { | |
267 // Restore the viewport. | |
268 host_->GetView()->SetInsets(gfx::Insets()); | |
269 } | |
270 } | |
271 | |
272 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override { | |
273 // Restore the viewport. | |
274 host_->GetView()->SetInsets(gfx::Insets()); | |
275 } | |
276 | |
277 private: | |
278 RenderWidgetHostImpl* host_; | |
279 // The location in DIPs where the touch occurred. | |
280 gfx::Point location_dips_screen_; | |
281 // The current device scale factor. | |
282 float device_scale_factor_; | |
283 | |
284 // The content Window. | |
285 aura::Window* window_; | |
286 | |
287 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); | |
288 }; | |
289 #endif | |
290 | |
215 } // namespace | 291 } // namespace |
216 | 292 |
217 // We need to watch for mouse events outside a Web Popup or its parent | 293 // We need to watch for mouse events outside a Web Popup or its parent |
218 // and dismiss the popup for certain events. | 294 // and dismiss the popup for certain events. |
219 class RenderWidgetHostViewAura::EventFilterForPopupExit | 295 class RenderWidgetHostViewAura::EventFilterForPopupExit |
220 : public ui::EventHandler { | 296 : public ui::EventHandler { |
221 public: | 297 public: |
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 298 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
223 : rwhva_(rwhva) { | 299 : rwhva_(rwhva) { |
224 DCHECK(rwhva_); | 300 DCHECK(rwhva_); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 can_compose_inline_(true), | 452 can_compose_inline_(true), |
377 has_composition_text_(false), | 453 has_composition_text_(false), |
378 accept_return_character_(false), | 454 accept_return_character_(false), |
379 begin_frame_source_(nullptr), | 455 begin_frame_source_(nullptr), |
380 needs_begin_frames_(false), | 456 needs_begin_frames_(false), |
381 synthetic_move_sent_(false), | 457 synthetic_move_sent_(false), |
382 cursor_visibility_state_in_renderer_(UNKNOWN), | 458 cursor_visibility_state_in_renderer_(UNKNOWN), |
383 #if defined(OS_WIN) | 459 #if defined(OS_WIN) |
384 legacy_render_widget_host_HWND_(nullptr), | 460 legacy_render_widget_host_HWND_(nullptr), |
385 legacy_window_destroyed_(false), | 461 legacy_window_destroyed_(false), |
462 virtual_keyboard_requested_(false), | |
386 #endif | 463 #endif |
387 has_snapped_to_boundary_(false), | 464 has_snapped_to_boundary_(false), |
388 is_guest_view_hack_(is_guest_view_hack), | 465 is_guest_view_hack_(is_guest_view_hack), |
389 set_focus_on_mouse_down_or_key_event_(false), | 466 set_focus_on_mouse_down_or_key_event_(false), |
390 device_scale_factor_(0.0f), | 467 device_scale_factor_(0.0f), |
391 disable_input_event_router_for_testing_(false), | 468 disable_input_event_router_for_testing_(false), |
392 weak_ptr_factory_(this) { | 469 weak_ptr_factory_(this) { |
393 if (!is_guest_view_hack_) | 470 if (!is_guest_view_hack_) |
394 host_->SetView(this); | 471 host_->SetView(this); |
395 | 472 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 return requested_rect.size(); | 934 return requested_rect.size(); |
858 } | 935 } |
859 | 936 |
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 937 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
861 if (insets != insets_) { | 938 if (insets != insets_) { |
862 insets_ = insets; | 939 insets_ = insets; |
863 host_->WasResized(); | 940 host_->WasResized(); |
864 } | 941 } |
865 } | 942 } |
866 | 943 |
944 void RenderWidgetHostViewAura::FocusedNodeTouched( | |
945 const gfx::Point& location_dips_screen, | |
946 bool editable) { | |
947 #if defined(OS_WIN) | |
948 RenderViewHost* rvh = RenderViewHost::From(host_); | |
949 if (rvh && rvh->GetDelegate()) | |
950 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable); | |
951 | |
952 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
953 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
954 DCHECK(osk_display_manager); | |
955 if (editable && host_ && host_->GetView()) { | |
956 keyboard_observer_.reset(new WinScreenKeyboardObserver( | |
957 host_, location_dips_screen, device_scale_factor_, | |
958 window_)); | |
959 virtual_keyboard_requested_ = | |
960 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get()); | |
961 } else { | |
962 virtual_keyboard_requested_ = false; | |
963 osk_display_manager->DismissVirtualKeyboard(); | |
964 } | |
965 #endif | |
966 } | |
967 | |
867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { | 968 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { |
868 current_cursor_ = cursor; | 969 current_cursor_ = cursor; |
869 const display::Display display = | 970 const display::Display display = |
870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 971 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
871 current_cursor_.SetDisplayInfo(display); | 972 current_cursor_.SetDisplayInfo(display); |
872 UpdateCursorIfOverSelf(); | 973 UpdateCursorIfOverSelf(); |
873 } | 974 } |
874 | 975 |
875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 976 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
876 is_loading_ = is_loading; | 977 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 | 2097 // Transformations use physical pixels rather than DIP, so conversion |
1997 // is necessary. | 2098 // is necessary. |
1998 gfx::Point point_in_pixels = | 2099 gfx::Point point_in_pixels = |
1999 gfx::ConvertPointToPixel(device_scale_factor_, point); | 2100 gfx::ConvertPointToPixel(device_scale_factor_, point); |
2000 delegated_frame_host_->TransformPointToLocalCoordSpace( | 2101 delegated_frame_host_->TransformPointToLocalCoordSpace( |
2001 point_in_pixels, original_surface, transformed_point); | 2102 point_in_pixels, original_surface, transformed_point); |
2002 *transformed_point = | 2103 *transformed_point = |
2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | 2104 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); |
2004 } | 2105 } |
2005 | 2106 |
2107 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) { | |
2108 #if defined(OS_WIN) | |
2109 if (!editable && virtual_keyboard_requested_) { | |
2110 virtual_keyboard_requested_ = false; | |
2111 | |
2112 RenderViewHost* rvh = RenderViewHost::From(host_); | |
2113 if (rvh && rvh->GetDelegate()) | |
2114 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | |
2115 | |
2116 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); | |
2117 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); | |
2118 } | |
2119 #endif | |
2120 } | |
2121 | |
2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 2122 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 2123 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); |
2008 | 2124 |
2009 if (event->type() == ui::ET_SCROLL) { | 2125 if (event->type() == ui::ET_SCROLL) { |
2010 #if !defined(OS_WIN) | 2126 #if !defined(OS_WIN) |
2011 // TODO(ananta) | 2127 // TODO(ananta) |
2012 // Investigate if this is true for Windows 8 Metro ASH as well. | 2128 // Investigate if this is true for Windows 8 Metro ASH as well. |
2013 if (event->finger_count() != 2) | 2129 if (event->finger_count() != 2) |
2014 return; | 2130 return; |
2015 #endif | 2131 #endif |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2279 popup_child_host_view_->popup_parent_host_view_ == this); | 2395 popup_child_host_view_->popup_parent_host_view_ == this); |
2280 popup_child_host_view_->popup_parent_host_view_ = NULL; | 2396 popup_child_host_view_->popup_parent_host_view_ = NULL; |
2281 } | 2397 } |
2282 event_filter_for_popup_exit_.reset(); | 2398 event_filter_for_popup_exit_.reset(); |
2283 | 2399 |
2284 #if defined(OS_WIN) | 2400 #if defined(OS_WIN) |
2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 2401 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should | 2402 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should |
2287 // be set to NULL. | 2403 // be set to NULL. |
2288 DCHECK(!legacy_render_widget_host_HWND_); | 2404 DCHECK(!legacy_render_widget_host_HWND_); |
2405 if (virtual_keyboard_requested_) { | |
2406 DCHECK(keyboard_observer_.get()); | |
2407 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
2408 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
2409 DCHECK(osk_display_manager); | |
2410 osk_display_manager->RemoveObserver(keyboard_observer_.get()); | |
2411 } | |
2412 | |
2289 #endif | 2413 #endif |
2290 } | 2414 } |
2291 | 2415 |
2292 void RenderWidgetHostViewAura::CreateAuraWindow() { | 2416 void RenderWidgetHostViewAura::CreateAuraWindow() { |
2293 DCHECK(!window_); | 2417 DCHECK(!window_); |
2294 window_ = new aura::Window(this); | 2418 window_ = new aura::Window(this); |
2295 window_observer_.reset(new WindowObserver(this)); | 2419 window_observer_.reset(new WindowObserver(this)); |
2296 | 2420 |
2297 aura::client::SetTooltipText(window_, &tooltip_); | 2421 aura::client::SetTooltipText(window_, &tooltip_); |
2298 aura::client::SetActivationDelegate(window_, this); | 2422 aura::client::SetActivationDelegate(window_, this); |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2865 | 2989 |
2866 //////////////////////////////////////////////////////////////////////////////// | 2990 //////////////////////////////////////////////////////////////////////////////// |
2867 // RenderWidgetHostViewBase, public: | 2991 // RenderWidgetHostViewBase, public: |
2868 | 2992 |
2869 // static | 2993 // static |
2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2994 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2871 GetScreenInfoForWindow(results, NULL); | 2995 GetScreenInfoForWindow(results, NULL); |
2872 } | 2996 } |
2873 | 2997 |
2874 } // namespace content | 2998 } // namespace content |
OLD | NEW |