Chromium Code Reviews| 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, | |
|
sky
2016/05/20 19:57:16
It looks like this is in screen coordinates too. P
ananta
2016/05/20 20:54:18
Done.
| |
| 228 float scale_factor, | |
| 229 const gfx::Rect& bounds_in_screen) | |
| 230 : host_(host), | |
| 231 location_in_dips_(location_dips), | |
| 232 device_scale_factor_(scale_factor), | |
| 233 bounds_in_screen_(bounds_in_screen) { | |
| 234 if (host_ && host_->GetView()) | |
|
sky
2016/05/20 19:57:16
How about only creating if host_ and host_->Getvie
ananta
2016/05/20 20:54:18
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 if (host_ && host_->GetView()) { | |
| 241 // We use the PtInRect API to determine if the touch occurred in the | |
|
sky
2016/05/20 19:57:16
Why? Why can't you use keyboard_rect_pixels.Contai
ananta
2016/05/20 20:54:18
Done.
| |
| 242 // bounds of the OSK. | |
| 243 // The API expects the point and the rectangle in pixels. | |
| 244 RECT keyboard_rect_windows = keyboard_rect_pixels.ToRECT(); | |
| 245 | |
| 246 gfx::Point location_in_pixels = | |
| 247 gfx::ConvertPointToPixel(device_scale_factor_, location_in_dips_); | |
| 248 POINT touch_location = location_in_pixels.ToPOINT(); | |
| 249 | |
| 250 if (::PtInRect(&keyboard_rect_windows, touch_location)) { | |
| 251 DVLOG(1) << "OSK covering focus point."; | |
| 252 gfx::Rect keyboard_rect_dips = | |
| 253 gfx::ConvertRectToDIP(device_scale_factor_, keyboard_rect_pixels); | |
| 254 // Get the intersection of the view rectangle and the OSK. | |
| 255 // The viewport needs to be moved up by the height of the intersection. | |
|
sky
2016/05/20 19:57:16
I don't think this is quite right. I think you nee
ananta
2016/05/20 20:54:17
Will look into this.
ananta
2016/05/20 22:21:31
Done. Changed this as per our discussion.
| |
| 256 gfx::Rect intersect = | |
| 257 gfx::IntersectRects(keyboard_rect_dips, bounds_in_screen_); | |
| 258 host_->GetView()->SetInsets(gfx::Insets(0, 0, intersect.height(), 0)); | |
|
sky
2016/05/20 19:57:16
What happens if the height is > height of view?
ananta
2016/05/20 22:21:31
The logic above has changed.
| |
| 259 host_->ScrollFocusedEditableNodeIntoRect(intersect); | |
| 260 } else { | |
| 261 // Restore the viewport. | |
| 262 host_->GetView()->SetInsets(gfx::Insets()); | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override { | |
| 268 // Restore the viewport. | |
| 269 if (host_ && host_->GetView()) | |
| 270 host_->GetView()->SetInsets(gfx::Insets()); | |
| 271 } | |
| 272 | |
| 273 private: | |
| 274 RenderWidgetHostImpl* host_; | |
| 275 // The location in DIPs where the touch occurred. | |
| 276 gfx::Point location_in_dips_; | |
| 277 // The current device scale factor. | |
| 278 float device_scale_factor_; | |
| 279 | |
| 280 // The window bounds in screen coordinates. | |
| 281 gfx::Rect bounds_in_screen_; | |
| 282 | |
| 283 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); | |
| 284 }; | |
| 285 #endif | |
| 286 | |
| 215 } // namespace | 287 } // namespace |
| 216 | 288 |
| 217 // We need to watch for mouse events outside a Web Popup or its parent | 289 // We need to watch for mouse events outside a Web Popup or its parent |
| 218 // and dismiss the popup for certain events. | 290 // and dismiss the popup for certain events. |
| 219 class RenderWidgetHostViewAura::EventFilterForPopupExit | 291 class RenderWidgetHostViewAura::EventFilterForPopupExit |
| 220 : public ui::EventHandler { | 292 : public ui::EventHandler { |
| 221 public: | 293 public: |
| 222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 294 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
| 223 : rwhva_(rwhva) { | 295 : rwhva_(rwhva) { |
| 224 DCHECK(rwhva_); | 296 DCHECK(rwhva_); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 can_compose_inline_(true), | 448 can_compose_inline_(true), |
| 377 has_composition_text_(false), | 449 has_composition_text_(false), |
| 378 accept_return_character_(false), | 450 accept_return_character_(false), |
| 379 begin_frame_source_(nullptr), | 451 begin_frame_source_(nullptr), |
| 380 needs_begin_frames_(false), | 452 needs_begin_frames_(false), |
| 381 synthetic_move_sent_(false), | 453 synthetic_move_sent_(false), |
| 382 cursor_visibility_state_in_renderer_(UNKNOWN), | 454 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 383 #if defined(OS_WIN) | 455 #if defined(OS_WIN) |
| 384 legacy_render_widget_host_HWND_(nullptr), | 456 legacy_render_widget_host_HWND_(nullptr), |
| 385 legacy_window_destroyed_(false), | 457 legacy_window_destroyed_(false), |
| 458 virtual_keyboard_requested_(false), | |
| 386 #endif | 459 #endif |
| 387 has_snapped_to_boundary_(false), | 460 has_snapped_to_boundary_(false), |
| 388 is_guest_view_hack_(is_guest_view_hack), | 461 is_guest_view_hack_(is_guest_view_hack), |
| 389 set_focus_on_mouse_down_or_key_event_(false), | 462 set_focus_on_mouse_down_or_key_event_(false), |
| 390 device_scale_factor_(0.0f), | 463 device_scale_factor_(0.0f), |
| 391 disable_input_event_router_for_testing_(false), | 464 disable_input_event_router_for_testing_(false), |
| 392 weak_ptr_factory_(this) { | 465 weak_ptr_factory_(this) { |
| 393 if (!is_guest_view_hack_) | 466 if (!is_guest_view_hack_) |
| 394 host_->SetView(this); | 467 host_->SetView(this); |
| 395 | 468 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 return requested_rect.size(); | 930 return requested_rect.size(); |
| 858 } | 931 } |
| 859 | 932 |
| 860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 933 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
| 861 if (insets != insets_) { | 934 if (insets != insets_) { |
| 862 insets_ = insets; | 935 insets_ = insets; |
| 863 host_->WasResized(); | 936 host_->WasResized(); |
| 864 } | 937 } |
| 865 } | 938 } |
| 866 | 939 |
| 940 void RenderWidgetHostViewAura::FocusedNodeTouched( | |
| 941 const gfx::Point& location_dips, | |
| 942 bool editable) { | |
| 943 #if defined(OS_WIN) | |
| 944 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 945 if (rvh && rvh->GetDelegate()) | |
| 946 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable); | |
| 947 | |
| 948 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
| 949 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
| 950 DCHECK(osk_display_manager); | |
| 951 if (editable) { | |
| 952 keyboard_observer_.reset(new WinScreenKeyboardObserver( | |
| 953 host_, location_dips, device_scale_factor_, | |
| 954 window_->GetBoundsInScreen())); | |
| 955 virtual_keyboard_requested_ = | |
| 956 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get()); | |
| 957 } else { | |
| 958 virtual_keyboard_requested_ = false; | |
| 959 osk_display_manager->DismissVirtualKeyboard(); | |
| 960 } | |
| 961 #endif | |
| 962 } | |
| 963 | |
| 867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { | 964 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { |
| 868 current_cursor_ = cursor; | 965 current_cursor_ = cursor; |
| 869 const display::Display display = | 966 const display::Display display = |
| 870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 967 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
| 871 current_cursor_.SetDisplayInfo(display); | 968 current_cursor_.SetDisplayInfo(display); |
| 872 UpdateCursorIfOverSelf(); | 969 UpdateCursorIfOverSelf(); |
| 873 } | 970 } |
| 874 | 971 |
| 875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 972 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
| 876 is_loading_ = is_loading; | 973 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 | 2093 // Transformations use physical pixels rather than DIP, so conversion |
| 1997 // is necessary. | 2094 // is necessary. |
| 1998 gfx::Point point_in_pixels = | 2095 gfx::Point point_in_pixels = |
| 1999 gfx::ConvertPointToPixel(device_scale_factor_, point); | 2096 gfx::ConvertPointToPixel(device_scale_factor_, point); |
| 2000 delegated_frame_host_->TransformPointToLocalCoordSpace( | 2097 delegated_frame_host_->TransformPointToLocalCoordSpace( |
| 2001 point_in_pixels, original_surface, transformed_point); | 2098 point_in_pixels, original_surface, transformed_point); |
| 2002 *transformed_point = | 2099 *transformed_point = |
| 2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | 2100 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); |
| 2004 } | 2101 } |
| 2005 | 2102 |
| 2103 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) { | |
| 2104 #if defined(OS_WIN) | |
| 2105 if (!editable && virtual_keyboard_requested_) { | |
| 2106 virtual_keyboard_requested_ = false; | |
| 2107 | |
| 2108 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 2109 if (rvh && rvh->GetDelegate()) | |
| 2110 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | |
| 2111 | |
| 2112 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); | |
| 2113 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); | |
| 2114 } | |
| 2115 #endif | |
| 2116 } | |
| 2117 | |
| 2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 2118 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
| 2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 2119 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); |
| 2008 | 2120 |
| 2009 if (event->type() == ui::ET_SCROLL) { | 2121 if (event->type() == ui::ET_SCROLL) { |
| 2010 #if !defined(OS_WIN) | 2122 #if !defined(OS_WIN) |
| 2011 // TODO(ananta) | 2123 // TODO(ananta) |
| 2012 // Investigate if this is true for Windows 8 Metro ASH as well. | 2124 // Investigate if this is true for Windows 8 Metro ASH as well. |
| 2013 if (event->finger_count() != 2) | 2125 if (event->finger_count() != 2) |
| 2014 return; | 2126 return; |
| 2015 #endif | 2127 #endif |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 popup_child_host_view_->popup_parent_host_view_ == this); | 2391 popup_child_host_view_->popup_parent_host_view_ == this); |
| 2280 popup_child_host_view_->popup_parent_host_view_ = NULL; | 2392 popup_child_host_view_->popup_parent_host_view_ = NULL; |
| 2281 } | 2393 } |
| 2282 event_filter_for_popup_exit_.reset(); | 2394 event_filter_for_popup_exit_.reset(); |
| 2283 | 2395 |
| 2284 #if defined(OS_WIN) | 2396 #if defined(OS_WIN) |
| 2285 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 2397 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
| 2286 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should | 2398 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should |
| 2287 // be set to NULL. | 2399 // be set to NULL. |
| 2288 DCHECK(!legacy_render_widget_host_HWND_); | 2400 DCHECK(!legacy_render_widget_host_HWND_); |
| 2401 if (virtual_keyboard_requested_) { | |
| 2402 DCHECK(keyboard_observer_.get()); | |
| 2403 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
| 2404 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
| 2405 DCHECK(osk_display_manager); | |
| 2406 osk_display_manager->RemoveObserver(keyboard_observer_.get()); | |
| 2407 } | |
| 2408 | |
| 2289 #endif | 2409 #endif |
| 2290 } | 2410 } |
| 2291 | 2411 |
| 2292 void RenderWidgetHostViewAura::CreateAuraWindow() { | 2412 void RenderWidgetHostViewAura::CreateAuraWindow() { |
| 2293 DCHECK(!window_); | 2413 DCHECK(!window_); |
| 2294 window_ = new aura::Window(this); | 2414 window_ = new aura::Window(this); |
| 2295 window_observer_.reset(new WindowObserver(this)); | 2415 window_observer_.reset(new WindowObserver(this)); |
| 2296 | 2416 |
| 2297 aura::client::SetTooltipText(window_, &tooltip_); | 2417 aura::client::SetTooltipText(window_, &tooltip_); |
| 2298 aura::client::SetActivationDelegate(window_, this); | 2418 aura::client::SetActivationDelegate(window_, this); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2865 | 2985 |
| 2866 //////////////////////////////////////////////////////////////////////////////// | 2986 //////////////////////////////////////////////////////////////////////////////// |
| 2867 // RenderWidgetHostViewBase, public: | 2987 // RenderWidgetHostViewBase, public: |
| 2868 | 2988 |
| 2869 // static | 2989 // static |
| 2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2990 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2871 GetScreenInfoForWindow(results, NULL); | 2991 GetScreenInfoForWindow(results, NULL); |
| 2872 } | 2992 } |
| 2873 | 2993 |
| 2874 } // namespace content | 2994 } // namespace content |
| OLD | NEW |