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 f2abca344b83fd3287b861799d2f270327bf6db0..0ccdca8e0d5d566244f691dc91f22a4204986f77 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" |
| @@ -1268,20 +1269,21 @@ gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen( |
| } |
| gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( |
|
oshima
2017/01/18 02:37:19
this no longer depends on RWHVAura. Can you move t
yhanada
2017/01/30 13:02:47
Done.
|
| - const gfx::Rect& rect) const { |
| + const gfx::Rect& rect, |
| + aura::Window* window) const { |
| gfx::Point origin = rect.origin(); |
| gfx::Point end = gfx::Point(rect.right(), rect.bottom()); |
| - aura::Window* root_window = window_->GetRootWindow(); |
| + 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()); |
| + if (screen_position_client) { |
| + 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; |
| @@ -1422,16 +1424,86 @@ 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 = 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); |
| + } |
| + |
| + const gfx::Rect hiding_area_in_screen = |
|
oshima
2017/01/18 02:37:19
how about hidden_window_bounds_in_screen?
yhanada
2017/01/30 13:02:47
Done.
|
| + gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| + |
| + if (hiding_area_in_screen.IsEmpty()) { |
| + // The window isn't covered by the keyboard, restore the window position if |
| + // necessary. |
| + OnClientFocusLost(); |
| + return; |
| + } |
| + |
| +#if defined(OS_CHROMEOS) |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + ::switches::kUseNewVirtualKeyboardBehavior)) |
| + return; |
| + |
| + // Calculate vertical window shift. |
| + const int vertical_displacement = std::max(0, hiding_area_in_screen.height()); |
|
oshima
2017/01/18 02:37:19
the height should be always positive, right?
yhanada
2017/01/30 13:02:47
Removed this variable.
|
| + const int shift = std::min(vertical_displacement, |
| + top_level_window->GetBoundsInRootWindow().y()); |
|
oshima
2017/01/18 02:37:19
how about:
int top_y = std::max(vk_bounds.y() - t
yhanada
2017/01/30 13:02:47
Done.
|
| + |
| + // Set restore bounds and move window. |
| + if (shift > 0) { |
| + top_level_window->SetProperty( |
| + aura::client::kVirtualKeyboardRestoreBoundsKey, |
| + new gfx::Rect(original_window_bounds)); |
| + |
| + gfx::Point new_origin(original_window_bounds.x(), |
| + original_window_bounds.y() - shift); |
| + gfx::Rect new_window_bounds_in_root_window_space = ConvertRectFromScreen( |
| + gfx::Rect(new_origin, original_window_bounds.size()), |
| + top_level_window->GetRootWindow()); |
| + top_level_window->SetBounds(new_window_bounds_in_root_window_space); |
| + } else { |
| + // No need to move the window or need to restore the window position. |
| + OnClientFocusLost(); |
| + } |
| +#endif // defined(OS_CHROMEOS) |
| + |
| + // Perform overscroll if the caret is still hidden by the keyboard. |
| + gfx::Rect visible_area_in_local_space(ConvertRectFromScreen( |
| + gfx::SubtractRects(window_->GetBoundsInScreen(), hiding_area_in_screen), |
| + window_)); |
| + host_->ScrollFocusedEditableNodeIntoRect(visible_area_in_local_space); |
| +} |
| - if (hiding_area_in_this_window.IsEmpty()) |
| +void RenderWidgetHostViewAura::OnClientFocusLost() { |
| +#if defined(OS_CHROMEOS) |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + ::switches::kUseNewVirtualKeyboardBehavior)) |
| return; |
| - host_->ScrollFocusedEditableNodeIntoRect( |
| - gfx::SubtractRects(window_->bounds(), hiding_area_in_this_window)); |
| + LOG(ERROR) << "OnClientFocusLost is called"; |
|
oshima
2017/01/18 02:37:19
nit: remove debug log
yhanada
2017/01/30 13:02:47
Done.
|
| + |
| + // Get restore bounds of window. |
| + aura::Window* top_level_window = window_->GetToplevelWindow(); |
| + gfx::Rect* vk_restore_bounds = top_level_window->GetProperty( |
| + aura::client::kVirtualKeyboardRestoreBoundsKey); |
| + |
| + if (vk_restore_bounds) { |
| + // Restore window. |
| + // TODO(yhanada): Clarify behavior when a user has moved a window while the |
| + // keyboard is shown. See crbug.com/624521. |
| + if (top_level_window->GetBoundsInScreen() != *vk_restore_bounds) { |
| + top_level_window->SetBounds(ConvertRectFromScreen( |
| + *vk_restore_bounds, top_level_window->GetRootWindow())); |
| + } |
| + top_level_window->ClearProperty( |
| + aura::client::kVirtualKeyboardRestoreBoundsKey); |
| + } |
| +#endif // defined(OS_CHROMEOS) |
| } |
| bool RenderWidgetHostViewAura::IsTextEditCommandEnabled( |