Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
| diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| index fd03a2b224eb710718c6e91b0e32aa4f3aa0fdb5..4917f65b1e9be869c71d1fda2af9a735b11c33f9 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
| +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| @@ -78,6 +78,7 @@ |
| #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| #include "ui/base/hit_test.h" |
| #include "ui/base/ime/input_method.h" |
| +#include "ui/base/ui_base_switches.h" |
| #include "ui/base/ui_base_types.h" |
| #include "ui/compositor/compositor_vsync_manager.h" |
| #include "ui/compositor/dip_util.h" |
| @@ -94,6 +95,8 @@ |
| #include "ui/gfx/geometry/size_conversions.h" |
| #include "ui/gfx/skia_util.h" |
| #include "ui/touch_selection/touch_selection_controller.h" |
| +#include "ui/wm/core/coordinate_conversion.h" |
| +#include "ui/wm/core/ime_util.h" |
| #include "ui/wm/public/activation_client.h" |
| #include "ui/wm/public/scoped_tooltip_disabler.h" |
| #include "ui/wm/public/tooltip_client.h" |
| @@ -573,6 +576,10 @@ void RenderWidgetHostViewAura::Hide() { |
| #endif |
| } |
| +aura::Window* RenderWidgetHostViewAura::GetToplevelWindow() { |
| + return window_->GetToplevelWindow(); |
| +} |
| + |
| void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
| // For a SetSize operation, we don't care what coordinate system the origin |
| // of the window is in, it's only important to make sure that the origin |
| @@ -1258,26 +1265,6 @@ gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
| end.y() - origin.y()); |
| } |
| -gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( |
| - const gfx::Rect& rect) const { |
| - gfx::Point origin = rect.origin(); |
| - gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
| - |
| - aura::Window* root_window = window_->GetRootWindow(); |
| - if (root_window) { |
| - aura::client::ScreenPositionClient* screen_position_client = |
| - aura::client::GetScreenPositionClient(root_window); |
| - screen_position_client->ConvertPointFromScreen(window_, &origin); |
| - screen_position_client->ConvertPointFromScreen(window_, &end); |
| - return gfx::Rect(origin.x(), |
| - origin.y(), |
| - end.x() - origin.x(), |
| - end.y() - origin.y()); |
| - } |
| - |
| - return rect; |
| -} |
| - |
| gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { |
| if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) |
| return gfx::Rect(); |
| @@ -1413,16 +1400,47 @@ void RenderWidgetHostViewAura::ExtendSelectionAndDelete( |
| rfh->ExtendSelectionAndDelete(before, after); |
| } |
| -void RenderWidgetHostViewAura::EnsureCaretNotInRect(const gfx::Rect& rect) { |
| - gfx::Rect rect_in_local_space = ConvertRectFromScreen(rect); |
| - gfx::Rect hiding_area_in_this_window = |
| - gfx::IntersectRects(rect_in_local_space, window_->bounds()); |
| +void RenderWidgetHostViewAura::EnsureCaretNotInRect( |
| + const gfx::Rect& rect_in_screen) { |
| + aura::Window* top_level_window = GetToplevelWindow(); |
| + gfx::Rect original_window_bounds = top_level_window->GetBoundsInScreen(); |
| + if (top_level_window->GetProperty( |
| + aura::client::kVirtualKeyboardRestoreBoundsKey)) { |
| + original_window_bounds = *top_level_window->GetProperty( |
| + aura::client::kVirtualKeyboardRestoreBoundsKey); |
| + } |
| + |
| + gfx::Rect hidden_window_bounds_in_screen = |
| + gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| + if (hidden_window_bounds_in_screen.IsEmpty()) { |
| + // The window isn't covered by the keyboard, restore the window position if |
| + // necessary. |
| + wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); |
| + return; |
| + } |
| - if (hiding_area_in_this_window.IsEmpty()) |
| +#if defined(OS_CHROMEOS) |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + ::switches::kUseNewVirtualKeyboardBehavior)) |
|
oshima
2017/04/11 04:48:50
won't this skip overscroll?
yhanada
2017/04/11 15:26:53
Yes... Fixed.
|
| return; |
| - host_->ScrollFocusedEditableNodeIntoRect( |
| - gfx::SubtractRects(window_->bounds(), hiding_area_in_this_window)); |
| + if (wm::MoveWindowToEnsureCaretNotInRect(top_level_window, rect_in_screen)) { |
| + // Recalculate hidden_window_bounds_in_screen after moving up the window. |
| + original_window_bounds = top_level_window->GetBoundsInScreen(); |
| + hidden_window_bounds_in_screen = |
| + gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| + } else { |
| + // No need to move the window or need to restore the window position. |
| + wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); |
| + return; |
| + } |
| +#endif // defined(OS_CHROMEOS) |
| + |
| + // Perform overscroll if the caret is still hidden by the keyboard. |
| + gfx::Rect visible_area_in_local_space = gfx::SubtractRects( |
| + window_->GetBoundsInScreen(), hidden_window_bounds_in_screen); |
| + wm::ConvertRectFromScreen(window_, &visible_area_in_local_space); |
| + host_->ScrollFocusedEditableNodeIntoRect(visible_area_in_local_space); |
| } |
| bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( |
| @@ -2194,8 +2212,10 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() { |
| void RenderWidgetHostViewAura::DetachFromInputMethod() { |
| ui::InputMethod* input_method = GetInputMethod(); |
| - if (input_method) |
| + if (input_method) { |
| input_method->DetachTextInputClient(this); |
| + wm::RestoreWindowBoundsOnClientFocusLost(GetToplevelWindow()); |
| + } |
| } |
| void RenderWidgetHostViewAura::ForwardKeyboardEvent( |