Index: ui/views/controls/textfield/textfield.cc |
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
index 8414521dd258ccc1ec46ef855a242c5fc03b3fa8..a090858c4e229ec7eaaf5d9ee5c6a2a83312176a 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,8 @@ |
#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" |
+#include "ui/wm/core/ime_util.h" |
#if defined(OS_WIN) |
#include "base/win/win_util.h" |
@@ -1481,7 +1487,52 @@ 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(); |
+ 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. |
+ OnClientFocusLost(); |
+ return; |
+ } |
+ |
+ 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. |
+ OnClientFocusLost(); |
+ } |
+#endif // defined(OS_CHROMEOS) |
+} |
+ |
+void Textfield::OnClientFocusLost() { |
+#if defined(OS_CHROMEOS) |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ ::switches::kUseNewVirtualKeyboardBehavior)) |
+ return; |
+ |
+ aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
+ DCHECK(top_level_window); |
+ wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); |
+#endif // defined(OS_CHROMEOS) |
+} |
bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
base::string16 result; |