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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #include "ui/aura/client/window_parenting_client.h" | 71 #include "ui/aura/client/window_parenting_client.h" |
72 #include "ui/aura/env.h" | 72 #include "ui/aura/env.h" |
73 #include "ui/aura/mus/window_port_mus.h" | 73 #include "ui/aura/mus/window_port_mus.h" |
74 #include "ui/aura/window.h" | 74 #include "ui/aura/window.h" |
75 #include "ui/aura/window_event_dispatcher.h" | 75 #include "ui/aura/window_event_dispatcher.h" |
76 #include "ui/aura/window_observer.h" | 76 #include "ui/aura/window_observer.h" |
77 #include "ui/aura/window_tree_host.h" | 77 #include "ui/aura/window_tree_host.h" |
78 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 78 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
79 #include "ui/base/hit_test.h" | 79 #include "ui/base/hit_test.h" |
80 #include "ui/base/ime/input_method.h" | 80 #include "ui/base/ime/input_method.h" |
81 #include "ui/base/ui_base_switches.h" | |
81 #include "ui/base/ui_base_types.h" | 82 #include "ui/base/ui_base_types.h" |
82 #include "ui/compositor/compositor_vsync_manager.h" | 83 #include "ui/compositor/compositor_vsync_manager.h" |
83 #include "ui/compositor/dip_util.h" | 84 #include "ui/compositor/dip_util.h" |
84 #include "ui/display/screen.h" | 85 #include "ui/display/screen.h" |
85 #include "ui/events/blink/blink_event_util.h" | 86 #include "ui/events/blink/blink_event_util.h" |
86 #include "ui/events/blink/web_input_event.h" | 87 #include "ui/events/blink/web_input_event.h" |
87 #include "ui/events/event.h" | 88 #include "ui/events/event.h" |
88 #include "ui/events/event_utils.h" | 89 #include "ui/events/event_utils.h" |
89 #include "ui/events/gesture_detection/gesture_configuration.h" | 90 #include "ui/events/gesture_detection/gesture_configuration.h" |
90 #include "ui/events/gestures/gesture_recognizer.h" | 91 #include "ui/events/gestures/gesture_recognizer.h" |
91 #include "ui/gfx/canvas.h" | 92 #include "ui/gfx/canvas.h" |
92 #include "ui/gfx/geometry/dip_util.h" | 93 #include "ui/gfx/geometry/dip_util.h" |
93 #include "ui/gfx/geometry/rect_conversions.h" | 94 #include "ui/gfx/geometry/rect_conversions.h" |
94 #include "ui/gfx/geometry/size_conversions.h" | 95 #include "ui/gfx/geometry/size_conversions.h" |
95 #include "ui/gfx/skia_util.h" | 96 #include "ui/gfx/skia_util.h" |
96 #include "ui/touch_selection/touch_selection_controller.h" | 97 #include "ui/touch_selection/touch_selection_controller.h" |
98 #include "ui/wm/core/coordinate_conversion.h" | |
99 #include "ui/wm/core/ime_util.h" | |
97 #include "ui/wm/public/activation_client.h" | 100 #include "ui/wm/public/activation_client.h" |
98 #include "ui/wm/public/scoped_tooltip_disabler.h" | 101 #include "ui/wm/public/scoped_tooltip_disabler.h" |
99 #include "ui/wm/public/tooltip_client.h" | 102 #include "ui/wm/public/tooltip_client.h" |
100 | 103 |
101 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
102 #include "base/time/time.h" | 105 #include "base/time/time.h" |
103 #include "content/browser/accessibility/browser_accessibility_manager_win.h" | 106 #include "content/browser/accessibility/browser_accessibility_manager_win.h" |
104 #include "content/browser/accessibility/browser_accessibility_win.h" | 107 #include "content/browser/accessibility/browser_accessibility_win.h" |
105 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" | 108 #include "content/browser/renderer_host/legacy_render_widget_host_win.h" |
106 #include "ui/base/win/hidden_window.h" | 109 #include "ui/base/win/hidden_window.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 } | 569 } |
567 #endif | 570 #endif |
568 } | 571 } |
569 | 572 |
570 #if defined(OS_WIN) | 573 #if defined(OS_WIN) |
571 if (legacy_render_widget_host_HWND_) | 574 if (legacy_render_widget_host_HWND_) |
572 legacy_render_widget_host_HWND_->Hide(); | 575 legacy_render_widget_host_HWND_->Hide(); |
573 #endif | 576 #endif |
574 } | 577 } |
575 | 578 |
579 aura::Window* RenderWidgetHostViewAura::GetToplevelWindow() { | |
580 return window_->GetToplevelWindow(); | |
581 } | |
582 | |
576 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 583 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
577 // For a SetSize operation, we don't care what coordinate system the origin | 584 // For a SetSize operation, we don't care what coordinate system the origin |
578 // of the window is in, it's only important to make sure that the origin | 585 // of the window is in, it's only important to make sure that the origin |
579 // remains constant after the operation. | 586 // remains constant after the operation. |
580 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size)); | 587 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size)); |
581 } | 588 } |
582 | 589 |
583 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 590 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
584 gfx::Point relative_origin(rect.origin()); | 591 gfx::Point relative_origin(rect.origin()); |
585 | 592 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1251 if (!screen_position_client) | 1258 if (!screen_position_client) |
1252 return rect; | 1259 return rect; |
1253 screen_position_client->ConvertPointToScreen(window_, &origin); | 1260 screen_position_client->ConvertPointToScreen(window_, &origin); |
1254 screen_position_client->ConvertPointToScreen(window_, &end); | 1261 screen_position_client->ConvertPointToScreen(window_, &end); |
1255 return gfx::Rect(origin.x(), | 1262 return gfx::Rect(origin.x(), |
1256 origin.y(), | 1263 origin.y(), |
1257 end.x() - origin.x(), | 1264 end.x() - origin.x(), |
1258 end.y() - origin.y()); | 1265 end.y() - origin.y()); |
1259 } | 1266 } |
1260 | 1267 |
1261 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( | |
1262 const gfx::Rect& rect) const { | |
1263 gfx::Point origin = rect.origin(); | |
1264 gfx::Point end = gfx::Point(rect.right(), rect.bottom()); | |
1265 | |
1266 aura::Window* root_window = window_->GetRootWindow(); | |
1267 if (root_window) { | |
1268 aura::client::ScreenPositionClient* screen_position_client = | |
1269 aura::client::GetScreenPositionClient(root_window); | |
1270 screen_position_client->ConvertPointFromScreen(window_, &origin); | |
1271 screen_position_client->ConvertPointFromScreen(window_, &end); | |
1272 return gfx::Rect(origin.x(), | |
1273 origin.y(), | |
1274 end.x() - origin.x(), | |
1275 end.y() - origin.y()); | |
1276 } | |
1277 | |
1278 return rect; | |
1279 } | |
1280 | |
1281 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { | 1268 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { |
1282 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) | 1269 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) |
1283 return gfx::Rect(); | 1270 return gfx::Rect(); |
1284 | 1271 |
1285 const TextInputManager::SelectionRegion* region = | 1272 const TextInputManager::SelectionRegion* region = |
1286 text_input_manager_->GetSelectionRegion(); | 1273 text_input_manager_->GetSelectionRegion(); |
1287 return ConvertRectToScreen( | 1274 return ConvertRectToScreen( |
1288 gfx::RectBetweenSelectionBounds(region->anchor, region->focus)); | 1275 gfx::RectBetweenSelectionBounds(region->anchor, region->focus)); |
1289 } | 1276 } |
1290 | 1277 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 return true; | 1393 return true; |
1407 } | 1394 } |
1408 | 1395 |
1409 void RenderWidgetHostViewAura::ExtendSelectionAndDelete( | 1396 void RenderWidgetHostViewAura::ExtendSelectionAndDelete( |
1410 size_t before, size_t after) { | 1397 size_t before, size_t after) { |
1411 RenderFrameHostImpl* rfh = GetFocusedFrame(); | 1398 RenderFrameHostImpl* rfh = GetFocusedFrame(); |
1412 if (rfh) | 1399 if (rfh) |
1413 rfh->ExtendSelectionAndDelete(before, after); | 1400 rfh->ExtendSelectionAndDelete(before, after); |
1414 } | 1401 } |
1415 | 1402 |
1416 void RenderWidgetHostViewAura::EnsureCaretNotInRect(const gfx::Rect& rect) { | 1403 void RenderWidgetHostViewAura::EnsureCaretNotInRect( |
1417 gfx::Rect rect_in_local_space = ConvertRectFromScreen(rect); | 1404 const gfx::Rect& rect_in_screen) { |
1418 gfx::Rect hiding_area_in_this_window = | 1405 aura::Window* top_level_window = GetToplevelWindow(); |
1419 gfx::IntersectRects(rect_in_local_space, window_->bounds()); | 1406 gfx::Rect original_window_bounds = top_level_window->GetBoundsInScreen(); |
1407 if (top_level_window->GetProperty( | |
1408 aura::client::kVirtualKeyboardRestoreBoundsKey)) { | |
1409 original_window_bounds = *top_level_window->GetProperty( | |
1410 aura::client::kVirtualKeyboardRestoreBoundsKey); | |
1411 } | |
1420 | 1412 |
1421 if (hiding_area_in_this_window.IsEmpty()) | 1413 gfx::Rect hidden_window_bounds_in_screen = |
1414 gfx::IntersectRects(rect_in_screen, original_window_bounds); | |
1415 if (hidden_window_bounds_in_screen.IsEmpty()) { | |
1416 // The window isn't covered by the keyboard, restore the window position if | |
1417 // necessary. | |
1418 wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); | |
1419 return; | |
1420 } | |
1421 | |
1422 #if defined(OS_CHROMEOS) | |
1423 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1424 ::switches::kUseNewVirtualKeyboardBehavior)) | |
oshima
2017/04/11 04:48:50
won't this skip overscroll?
yhanada
2017/04/11 15:26:53
Yes... Fixed.
| |
1422 return; | 1425 return; |
1423 | 1426 |
1424 host_->ScrollFocusedEditableNodeIntoRect( | 1427 if (wm::MoveWindowToEnsureCaretNotInRect(top_level_window, rect_in_screen)) { |
1425 gfx::SubtractRects(window_->bounds(), hiding_area_in_this_window)); | 1428 // Recalculate hidden_window_bounds_in_screen after moving up the window. |
1429 original_window_bounds = top_level_window->GetBoundsInScreen(); | |
1430 hidden_window_bounds_in_screen = | |
1431 gfx::IntersectRects(rect_in_screen, original_window_bounds); | |
1432 } else { | |
1433 // No need to move the window or need to restore the window position. | |
1434 wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); | |
1435 return; | |
1436 } | |
1437 #endif // defined(OS_CHROMEOS) | |
1438 | |
1439 // Perform overscroll if the caret is still hidden by the keyboard. | |
1440 gfx::Rect visible_area_in_local_space = gfx::SubtractRects( | |
1441 window_->GetBoundsInScreen(), hidden_window_bounds_in_screen); | |
1442 wm::ConvertRectFromScreen(window_, &visible_area_in_local_space); | |
1443 host_->ScrollFocusedEditableNodeIntoRect(visible_area_in_local_space); | |
1426 } | 1444 } |
1427 | 1445 |
1428 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( | 1446 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( |
1429 ui::TextEditCommand command) const { | 1447 ui::TextEditCommand command) const { |
1430 return false; | 1448 return false; |
1431 } | 1449 } |
1432 | 1450 |
1433 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent( | 1451 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent( |
1434 ui::TextEditCommand command) {} | 1452 ui::TextEditCommand command) {} |
1435 | 1453 |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2187 #if defined(OS_WIN) | 2205 #if defined(OS_WIN) |
2188 // Update the legacy window's parent temporarily to the hidden window. It | 2206 // Update the legacy window's parent temporarily to the hidden window. It |
2189 // will eventually get reparented to the right root. | 2207 // will eventually get reparented to the right root. |
2190 if (legacy_render_widget_host_HWND_) | 2208 if (legacy_render_widget_host_HWND_) |
2191 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow()); | 2209 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow()); |
2192 #endif | 2210 #endif |
2193 } | 2211 } |
2194 | 2212 |
2195 void RenderWidgetHostViewAura::DetachFromInputMethod() { | 2213 void RenderWidgetHostViewAura::DetachFromInputMethod() { |
2196 ui::InputMethod* input_method = GetInputMethod(); | 2214 ui::InputMethod* input_method = GetInputMethod(); |
2197 if (input_method) | 2215 if (input_method) { |
2198 input_method->DetachTextInputClient(this); | 2216 input_method->DetachTextInputClient(this); |
2217 wm::RestoreWindowBoundsOnClientFocusLost(GetToplevelWindow()); | |
2218 } | |
2199 } | 2219 } |
2200 | 2220 |
2201 void RenderWidgetHostViewAura::ForwardKeyboardEvent( | 2221 void RenderWidgetHostViewAura::ForwardKeyboardEvent( |
2202 const NativeWebKeyboardEvent& event, | 2222 const NativeWebKeyboardEvent& event, |
2203 bool* update_event) { | 2223 bool* update_event) { |
2204 RenderWidgetHostImpl* target_host = host_; | 2224 RenderWidgetHostImpl* target_host = host_; |
2205 | 2225 |
2206 // If there are multiple widgets on the page (such as when there are | 2226 // If there are multiple widgets on the page (such as when there are |
2207 // out-of-process iframes), pick the one that should process this event. | 2227 // out-of-process iframes), pick the one that should process this event. |
2208 if (host_->delegate()) | 2228 if (host_->delegate()) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2346 } | 2366 } |
2347 | 2367 |
2348 void RenderWidgetHostViewAura::UpdateNeedsBeginFramesInternal() { | 2368 void RenderWidgetHostViewAura::UpdateNeedsBeginFramesInternal() { |
2349 if (!delegated_frame_host_) | 2369 if (!delegated_frame_host_) |
2350 return; | 2370 return; |
2351 delegated_frame_host_->SetNeedsBeginFrames(needs_begin_frames_ || | 2371 delegated_frame_host_->SetNeedsBeginFrames(needs_begin_frames_ || |
2352 needs_flush_input_); | 2372 needs_flush_input_); |
2353 } | 2373 } |
2354 | 2374 |
2355 } // namespace content | 2375 } // namespace content |
OLD | NEW |