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 explicit WinScreenKeyboardObserver(RenderWidgetHostImpl* host, | |
|
grt (UTC plus 2)
2016/05/20 14:56:35
nit: omit "explicit" as per https://google.github.
ananta
2016/05/20 19:32:54
Done.
| |
| 227 const gfx::Point& location_dips, | |
| 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()) | |
| 235 host_->GetView()->SetInsets(gfx::Insets()); | |
| 236 } | |
| 237 | |
| 238 // base::win::OnScreenKeyboardObserver overrides. | |
| 239 void OnKeyboardVisible(const gfx::Rect& keyboard_rect_pixels) override { | |
| 240 DCHECK(host_); | |
|
grt (UTC plus 2)
2016/05/20 14:56:35
it's counter to style to both DCHECK that a ptr is
ananta
2016/05/20 19:32:55
Removed the DCHECK
| |
| 241 | |
| 242 if (host_ && host_->GetView()) { | |
| 243 // We use the PtInRect API to determine if the touch occurred in the | |
| 244 // bounds of the OSK. | |
| 245 // The API expects the point and the rectangle in pixels. | |
| 246 RECT keyboard_rect_windows = keyboard_rect_pixels.ToRECT(); | |
| 247 | |
| 248 gfx::Point location_in_pixels = | |
| 249 gfx::ConvertPointToPixel(device_scale_factor_, location_in_dips_); | |
| 250 POINT touch_location = location_in_pixels.ToPOINT(); | |
| 251 | |
| 252 if (::PtInRect(&keyboard_rect_windows, touch_location)) { | |
| 253 DVLOG(1) << "OSK covering focus point."; | |
| 254 gfx::Rect keyboard_rect_dips = | |
| 255 gfx::ConvertRectToDIP(device_scale_factor_, keyboard_rect_pixels); | |
| 256 // Get the intersection of the view rectangle and the OSK. | |
| 257 // The viewport needs to be moved up by the height of the intersection. | |
| 258 gfx::Rect intersect = | |
| 259 gfx::IntersectRects(keyboard_rect_dips, bounds_in_screen_); | |
| 260 host_->GetView()->SetInsets(gfx::Insets(0, 0, intersect.height(), 0)); | |
| 261 host_->ScrollFocusedEditableNodeIntoRect(intersect); | |
| 262 } else { | |
| 263 // Restore the viewport. | |
| 264 host_->GetView()->SetInsets(gfx::Insets()); | |
| 265 } | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 void OnKeyboardHidden(const gfx::Rect& keyboard_rect_pixels) override { | |
| 270 DCHECK(host_); | |
| 271 // Restore the viewport. | |
| 272 if (host_ && host_->GetView()) | |
| 273 host_->GetView()->SetInsets(gfx::Insets()); | |
| 274 } | |
| 275 | |
| 276 private: | |
| 277 RenderWidgetHostImpl* host_; | |
| 278 // The location in DIPs where the touch occurred. | |
| 279 gfx::Point location_in_dips_; | |
| 280 // The current device scale factor. | |
| 281 float device_scale_factor_; | |
| 282 | |
| 283 // The window bounds in screen coordinates. | |
| 284 gfx::Rect bounds_in_screen_; | |
| 285 | |
| 286 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); | |
| 287 }; | |
| 288 #endif | |
| 289 | |
| 215 } // namespace | 290 } // namespace |
| 216 | 291 |
| 217 // We need to watch for mouse events outside a Web Popup or its parent | 292 // We need to watch for mouse events outside a Web Popup or its parent |
| 218 // and dismiss the popup for certain events. | 293 // and dismiss the popup for certain events. |
| 219 class RenderWidgetHostViewAura::EventFilterForPopupExit | 294 class RenderWidgetHostViewAura::EventFilterForPopupExit |
| 220 : public ui::EventHandler { | 295 : public ui::EventHandler { |
| 221 public: | 296 public: |
| 222 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 297 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
| 223 : rwhva_(rwhva) { | 298 : rwhva_(rwhva) { |
| 224 DCHECK(rwhva_); | 299 DCHECK(rwhva_); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 can_compose_inline_(true), | 451 can_compose_inline_(true), |
| 377 has_composition_text_(false), | 452 has_composition_text_(false), |
| 378 accept_return_character_(false), | 453 accept_return_character_(false), |
| 379 begin_frame_source_(nullptr), | 454 begin_frame_source_(nullptr), |
| 380 needs_begin_frames_(false), | 455 needs_begin_frames_(false), |
| 381 synthetic_move_sent_(false), | 456 synthetic_move_sent_(false), |
| 382 cursor_visibility_state_in_renderer_(UNKNOWN), | 457 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 383 #if defined(OS_WIN) | 458 #if defined(OS_WIN) |
| 384 legacy_render_widget_host_HWND_(nullptr), | 459 legacy_render_widget_host_HWND_(nullptr), |
| 385 legacy_window_destroyed_(false), | 460 legacy_window_destroyed_(false), |
| 461 virtual_keyboard_requested_(false), | |
| 386 #endif | 462 #endif |
| 387 has_snapped_to_boundary_(false), | 463 has_snapped_to_boundary_(false), |
| 388 is_guest_view_hack_(is_guest_view_hack), | 464 is_guest_view_hack_(is_guest_view_hack), |
| 389 set_focus_on_mouse_down_or_key_event_(false), | 465 set_focus_on_mouse_down_or_key_event_(false), |
| 390 device_scale_factor_(0.0f), | 466 device_scale_factor_(0.0f), |
| 391 disable_input_event_router_for_testing_(false), | 467 disable_input_event_router_for_testing_(false), |
| 392 weak_ptr_factory_(this) { | 468 weak_ptr_factory_(this) { |
| 393 if (!is_guest_view_hack_) | 469 if (!is_guest_view_hack_) |
| 394 host_->SetView(this); | 470 host_->SetView(this); |
| 395 | 471 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 return requested_rect.size(); | 933 return requested_rect.size(); |
| 858 } | 934 } |
| 859 | 935 |
| 860 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 936 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
| 861 if (insets != insets_) { | 937 if (insets != insets_) { |
| 862 insets_ = insets; | 938 insets_ = insets; |
| 863 host_->WasResized(); | 939 host_->WasResized(); |
| 864 } | 940 } |
| 865 } | 941 } |
| 866 | 942 |
| 943 void RenderWidgetHostViewAura::FocusedNodeTouched( | |
| 944 const gfx::Point& location_dips, | |
| 945 bool editable) { | |
| 946 #if defined(OS_WIN) | |
| 947 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 948 if (rvh && rvh->GetDelegate()) | |
| 949 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(editable); | |
| 950 | |
| 951 ui::OnScreenKeyboardDisplayManager* osk_display_manager = | |
| 952 ui::OnScreenKeyboardDisplayManager::GetInstance(); | |
| 953 DCHECK(osk_display_manager); | |
| 954 if (editable) { | |
| 955 keyboard_observer_.reset(new WinScreenKeyboardObserver( | |
| 956 host_, location_dips, device_scale_factor_, | |
| 957 window_->GetBoundsInScreen())); | |
| 958 virtual_keyboard_requested_ = | |
| 959 osk_display_manager->DisplayVirtualKeyboard(keyboard_observer_.get()); | |
|
grt (UTC plus 2)
2016/05/20 14:56:34
looks like this RWHVA could be destroyed while the
ananta
2016/05/20 19:32:54
Done.
| |
| 960 } else { | |
| 961 virtual_keyboard_requested_ = false; | |
| 962 osk_display_manager->DismissVirtualKeyboard(); | |
| 963 } | |
| 964 #endif | |
| 965 } | |
| 966 | |
| 867 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { | 967 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) { |
| 868 current_cursor_ = cursor; | 968 current_cursor_ = cursor; |
| 869 const display::Display display = | 969 const display::Display display = |
| 870 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | 970 display::Screen::GetScreen()->GetDisplayNearestWindow(window_); |
| 871 current_cursor_.SetDisplayInfo(display); | 971 current_cursor_.SetDisplayInfo(display); |
| 872 UpdateCursorIfOverSelf(); | 972 UpdateCursorIfOverSelf(); |
| 873 } | 973 } |
| 874 | 974 |
| 875 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { | 975 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { |
| 876 is_loading_ = is_loading; | 976 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 | 2096 // Transformations use physical pixels rather than DIP, so conversion |
| 1997 // is necessary. | 2097 // is necessary. |
| 1998 gfx::Point point_in_pixels = | 2098 gfx::Point point_in_pixels = |
| 1999 gfx::ConvertPointToPixel(device_scale_factor_, point); | 2099 gfx::ConvertPointToPixel(device_scale_factor_, point); |
| 2000 delegated_frame_host_->TransformPointToLocalCoordSpace( | 2100 delegated_frame_host_->TransformPointToLocalCoordSpace( |
| 2001 point_in_pixels, original_surface, transformed_point); | 2101 point_in_pixels, original_surface, transformed_point); |
| 2002 *transformed_point = | 2102 *transformed_point = |
| 2003 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | 2103 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); |
| 2004 } | 2104 } |
| 2005 | 2105 |
| 2106 void RenderWidgetHostViewAura::FocusedNodeChanged(bool editable) { | |
| 2107 #if defined(OS_WIN) | |
| 2108 if (!editable && virtual_keyboard_requested_) { | |
| 2109 virtual_keyboard_requested_ = false; | |
| 2110 | |
| 2111 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 2112 if (rvh && rvh->GetDelegate()) | |
| 2113 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | |
| 2114 | |
| 2115 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); | |
| 2116 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); | |
| 2117 } | |
| 2118 #endif | |
| 2119 } | |
| 2120 | |
| 2006 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 2121 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
| 2007 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 2122 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); |
| 2008 | 2123 |
| 2009 if (event->type() == ui::ET_SCROLL) { | 2124 if (event->type() == ui::ET_SCROLL) { |
| 2010 #if !defined(OS_WIN) | 2125 #if !defined(OS_WIN) |
| 2011 // TODO(ananta) | 2126 // TODO(ananta) |
| 2012 // Investigate if this is true for Windows 8 Metro ASH as well. | 2127 // Investigate if this is true for Windows 8 Metro ASH as well. |
| 2013 if (event->finger_count() != 2) | 2128 if (event->finger_count() != 2) |
| 2014 return; | 2129 return; |
| 2015 #endif | 2130 #endif |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2865 | 2980 |
| 2866 //////////////////////////////////////////////////////////////////////////////// | 2981 //////////////////////////////////////////////////////////////////////////////// |
| 2867 // RenderWidgetHostViewBase, public: | 2982 // RenderWidgetHostViewBase, public: |
| 2868 | 2983 |
| 2869 // static | 2984 // static |
| 2870 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2985 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2871 GetScreenInfoForWindow(results, NULL); | 2986 GetScreenInfoForWindow(results, NULL); |
| 2872 } | 2987 } |
| 2873 | 2988 |
| 2874 } // namespace content | 2989 } // namespace content |
| OLD | NEW |