Index: ui/views/controls/textfield/textfield.cc |
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
index 1586362197bbeeefe7910675eb0c4747e5441b76..0e91e52485e21fa33fa79738e4a280675645e14d 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" |
@@ -1010,8 +1016,13 @@ void Textfield::OnFocus() { |
void Textfield::OnBlur() { |
gfx::RenderText* render_text = GetRenderText(); |
render_text->set_focused(false); |
- if (GetInputMethod()) |
+ if (GetInputMethod()) { |
GetInputMethod()->DetachTextInputClient(this); |
+#if defined(OS_CHROMEOS) |
+ wm::RestoreWindowBoundsOnClientFocusLost( |
+ GetNativeView()->GetToplevelWindow()); |
+#endif // defined(OS_CHROMEOS) |
+ } |
StopBlinkingCursor(); |
cursor_view_.SetVisible(false); |
@@ -1484,7 +1495,39 @@ 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(wm::kVirtualKeyboardRestoreBoundsKey)) { |
+ original_window_bounds = |
+ *top_level_window->GetProperty(wm::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 (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); |
oshima
2017/04/17 13:24:22
These code aren't necessary (if you want to keep t
yhanada
2017/04/26 11:29:45
Done.
|
+ } else { |
+ // No need to move the window or need to restore the window position. |
+ wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); |
+ } |
+#endif // defined(OS_CHROMEOS) |
oshima
2017/04/17 13:24:22
The fundamental logic must be same as one in RWHVA
yhanada
2017/04/26 11:29:45
I moved the logic to ime_util. Done.
|
+} |
bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
base::string16 result; |