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_in_screen, |
| 228 float scale_factor, |
| 229 aura::Window* window) |
| 230 : host_(host), |
| 231 location_in_screen_(location_in_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_in_screen_); |
| 241 |
| 242 // Restore the viewport. |
| 243 host_->GetView()->SetInsets(gfx::Insets()); |
| 244 |
| 245 if (keyboard_rect_pixels.Contains(location_in_pixels)) { |
| 246 aura::client::ScreenPositionClient* screen_position_client = |
| 247 aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
| 248 if (!screen_position_client) |
| 249 return; |
| 250 |
| 251 DVLOG(1) << "OSK covering focus point."; |
| 252 gfx::Rect keyboard_rect = |
| 253 gfx::ConvertRectToDIP(device_scale_factor_, keyboard_rect_pixels); |
| 254 gfx::Rect bounds_in_screen = window_->GetBoundsInScreen(); |
| 255 |
| 256 DCHECK(bounds_in_screen.bottom() > keyboard_rect.y()); |
| 257 |
| 258 // Set the viewport of the window to be just above the on screen |
| 259 // keyboard. |
| 260 int viewport_bottom = bounds_in_screen.bottom() - keyboard_rect.y(); |
| 261 |
| 262 // If the viewport is bigger than the view, then we cannot handle it |
| 263 // with the current approach. Moving the window above the OSK is one way. |
| 264 // That for a later patchset. |
| 265 if (viewport_bottom > bounds_in_screen.height()) |
| 266 return; |
| 267 |
| 268 host_->GetView()->SetInsets(gfx::Insets(0, 0, viewport_bottom, 0)); |
| 269 |
| 270 gfx::Point origin(location_in_screen_); |
| 271 screen_position_client->ConvertPointFromScreen(window_, &origin); |
| 272 |
| 273 // We want to scroll the node into a rectangle which originates from |
| 274 // the touch point and a small offset (10) in either direction. |
| 275 gfx::Rect node_rect(origin.x(), origin.y(), 10, 10); |
| 276 host_->ScrollFocusedEditableNodeIntoRect(node_rect); |
| 277 } |
| 278 } |
| 279 |
| 280 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override { |
| 281 // Restore the viewport. |
| 282 host_->GetView()->SetInsets(gfx::Insets()); |
| 283 } |
| 284 |
| 285 private: |
| 286 RenderWidgetHostImpl* host_; |
| 287 // The location in DIPs where the touch occurred. |
| 288 gfx::Point location_in_screen_; |
| 289 // The current device scale factor. |
| 290 float device_scale_factor_; |
| 291 |
| 292 // The content Window. |
| 293 aura::Window* window_; |
| 294 |
| 295 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); |
| 296 }; |
| 297 #endif |
| 298 |
215 } // namespace | 299 } // namespace |
216 | 300 |
217 // We need to watch for mouse events outside a Web Popup or its parent | 301 // We need to watch for mouse events outside a Web Popup or its parent |
218 // and dismiss the popup for certain events. | 302 // and dismiss the popup for certain events. |
219 class RenderWidgetHostViewAura::EventFilterForPopupExit | 303 class RenderWidgetHostViewAura::EventFilterForPopupExit |
220 : public ui::EventHandler { | 304 : public ui::EventHandler { |
221 public: | 305 public: |
222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 306 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
223 : rwhva_(rwhva) { | 307 : rwhva_(rwhva) { |
224 DCHECK(rwhva_); | 308 DCHECK(rwhva_); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 can_compose_inline_(true), | 460 can_compose_inline_(true), |
377 has_composition_text_(false), | 461 has_composition_text_(false), |
378 accept_return_character_(false), | 462 accept_return_character_(false), |
379 begin_frame_source_(nullptr), | 463 begin_frame_source_(nullptr), |
380 needs_begin_frames_(false), | 464 needs_begin_frames_(false), |
381 synthetic_move_sent_(false), | 465 synthetic_move_sent_(false), |
382 cursor_visibility_state_in_renderer_(UNKNOWN), | 466 cursor_visibility_state_in_renderer_(UNKNOWN), |
383 #if defined(OS_WIN) | 467 #if defined(OS_WIN) |
384 legacy_render_widget_host_HWND_(nullptr), | 468 legacy_render_widget_host_HWND_(nullptr), |
385 legacy_window_destroyed_(false), | 469 legacy_window_destroyed_(false), |
| 470 virtual_keyboard_requested_(false), |
386 #endif | 471 #endif |
387 has_snapped_to_boundary_(false), | 472 has_snapped_to_boundary_(false), |
388 is_guest_view_hack_(is_guest_view_hack), | 473 is_guest_view_hack_(is_guest_view_hack), |
389 set_focus_on_mouse_down_or_key_event_(false), | 474 set_focus_on_mouse_down_or_key_event_(false), |
390 device_scale_factor_(0.0f), | 475 device_scale_factor_(0.0f), |
391 disable_input_event_router_for_testing_(false), | 476 disable_input_event_router_for_testing_(false), |
392 weak_ptr_factory_(this) { | 477 weak_ptr_factory_(this) { |
393 if (!is_guest_view_hack_) | 478 if (!is_guest_view_hack_) |
394 host_->SetView(this); | 479 host_->SetView(this); |
395 | 480 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 return requested_rect.size(); | 942 return requested_rect.size(); |
858 } | 943 } |
859 | 944 |
860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 945 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
861 if (insets != insets_) { | 946 if (insets != insets_) { |
862 insets_ = insets; | 947 insets_ = insets; |
863 host_->WasResized(); | 948 host_->WasResized(); |
864 } | 949 } |
865 } | 950 } |
866 | 951 |
| 952 void RenderWidgetHostViewAura::FocusedNodeTouched( |
| 953 const gfx::Point& location_dips_screen, |
| 954 bool editable) { |
| 955 #if defined(OS_WIN) |
| 956 RenderViewHost* rvh = RenderViewHost::From(host_); |
| 957 if (rvh && rvh->GetDelegate()) |
| 958 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable); |
| 959 |
| 960 ui::OnScreenKeyboardDisplayManager* osk_display_manager = |
| 961 ui::OnScreenKeyboardDisplayManager::GetInstance(); |
| 962 DCHECK(osk_display_manager); |
| 963 if (editable && host_ && host_->GetView()) { |
| 964 keyboard_observer_.reset(new WinScreenKeyboardObserver( |
| 965 host_, location_dips_screen, device_scale_factor_, 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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |