Index: ui/views/controls/textfield/textfield.cc |
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
index 217bb57a1247b35ab9fe89594162a04427f8c6ba..244ee70271ebbf7f2c30e4b17f40473f4322c3ff 100644 |
--- a/ui/views/controls/textfield/textfield.cc |
+++ b/ui/views/controls/textfield/textfield.cc |
@@ -7,12 +7,15 @@ |
#include <string> |
#include <utility> |
+#include "base/command_line.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/trace_event/trace_event.h" |
#include "build/build_config.h" |
#include "ui/accessibility/ax_action_data.h" |
#include "ui/accessibility/ax_node_data.h" |
+#include "ui/aura/client/aura_constants.h" |
+#include "ui/aura/window.h" |
#include "ui/base/clipboard/scoped_clipboard_writer.h" |
#include "ui/base/cursor/cursor.h" |
#include "ui/base/default_style.h" |
@@ -22,6 +25,7 @@ |
#include "ui/base/ime/text_edit_commands.h" |
#include "ui/base/material_design/material_design_controller.h" |
#include "ui/base/resource/resource_bundle.h" |
+#include "ui/base/ui_base_switches.h" |
#include "ui/base/ui_base_switches_util.h" |
#include "ui/compositor/canvas_painter.h" |
#include "ui/compositor/scoped_animation_duration_scale_mode.h" |
@@ -48,6 +52,7 @@ |
#include "ui/views/style/platform_style.h" |
#include "ui/views/views_delegate.h" |
#include "ui/views/widget/widget.h" |
+#include "ui/wm/core/coordinate_conversion.h" |
#if defined(OS_WIN) |
#include "base/win/win_util.h" |
@@ -1440,7 +1445,77 @@ void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) { |
DeleteRange(range); |
} |
-void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} |
+void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) { |
+#if defined(OS_CHROMEOS) |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ ::switches::kUseNewVirtualKeyboardBehavior)) |
+ return; |
+ |
+ aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
+ if (!top_level_window->GetProperty( |
+ aura::client::kVirtualKeyboardRestoreBoundsKey)) { |
+ top_level_window->SetProperty( |
+ aura::client::kVirtualKeyboardRestoreBoundsKey, |
+ new gfx::Rect(top_level_window->GetBoundsInScreen())); |
+ } |
+ |
+ const gfx::Rect original_window_bounds = *top_level_window->GetProperty( |
+ aura::client::kVirtualKeyboardRestoreBoundsKey); |
+ const gfx::Rect hiding_area_in_screen( |
+ gfx::IntersectRects(rect_in_screen, original_window_bounds)); |
+ |
+ if (hiding_area_in_screen.IsEmpty()) { |
+ // The window isn't covered by the keyboad, restore the window position if |
+ // necessary |
+ OnClientFocusLost(); |
+ return; |
+ } |
+ |
+ // Calculate vertical window shift. |
+ const int vertical_displacement = std::max(0, hiding_area_in_screen.height()); |
+ const int shift = std::min(vertical_displacement, |
+ top_level_window->GetBoundsInRootWindow().y()); |
+ |
+ // 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_in_root_window_space( |
+ original_window_bounds.x(), original_window_bounds.y() - shift); |
+ wm::ConvertPointFromScreen(top_level_window, |
+ &new_origin_in_root_window_space); |
+ |
+ gfx::Rect new_window_bounds_in_root_window_space( |
+ new_origin_in_root_window_space, original_window_bounds.size()); |
+ 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) |
+} |
+ |
+void Textfield::OnClientFocusLost() { |
+#if defined(OS_CHROMEOS) |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ ::switches::kUseNewVirtualKeyboardBehavior)) |
+ return; |
+ |
+ // Get restore bounds of window. |
+ aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
+ gfx::Rect* vk_restore_bounds = top_level_window->GetProperty( |
+ aura::client::kVirtualKeyboardRestoreBoundsKey); |
+ |
+ if (vk_restore_bounds) { |
+ // Restore window. |
+ top_level_window->SetBounds(*vk_restore_bounds); |
+ top_level_window->ClearProperty( |
+ aura::client::kVirtualKeyboardRestoreBoundsKey); |
+ } |
+#endif // defined(OS_CHROMEOS) |
+} |
bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
base::string16 result; |