Index: ui/wm/core/ime_util.cc |
diff --git a/ui/wm/core/ime_util.cc b/ui/wm/core/ime_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7c98e6fb2daef15aae41de76ce59663d575fa0c4 |
--- /dev/null |
+++ b/ui/wm/core/ime_util.cc |
@@ -0,0 +1,64 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/wm/core/ime_util.h" |
+ |
+#include "base/command_line.h" |
+#include "ui/aura/client/aura_constants.h" |
+#include "ui/aura/window.h" |
+#include "ui/base/ui_base_switches.h" |
+#include "ui/gfx/geometry/rect.h" |
+#include "ui/wm/core/coordinate_conversion.h" |
+ |
+namespace wm { |
+ |
+bool MoveWindowToEnsureCaretNotInRect(aura::Window* window, |
+ const gfx::Rect& rect_in_screen) { |
+ gfx::Rect original_window_bounds = window->GetBoundsInScreen(); |
+ // Calculate vertial window shift |
+ gfx::Rect rect_in_root_window = rect_in_screen; |
+ ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window); |
+ const int top_y = std::max( |
+ rect_in_root_window.y() - window->GetBoundsInRootWindow().height(), 0); |
oshima
2017/04/11 04:48:50
you can use just bounds. Or store to local variabl
yhanada
2017/04/11 15:26:53
Done.
|
+ |
+ // No need to move up the window |
+ if (top_y == window->GetBoundsInRootWindow().y()) |
+ return false; |
+ |
+ // Set restore bounds and move the window. |
+ window->SetProperty(aura::client::kVirtualKeyboardRestoreBoundsKey, |
+ new gfx::Rect(original_window_bounds)); |
+ |
+ gfx::Point new_origin(window->GetBoundsInRootWindow().x(), top_y); |
oshima
2017/04/11 04:48:50
copy the bounds in root, and set_y
yhanada
2017/04/11 15:26:53
Done.
|
+ gfx::Rect new_window_bounds_in_root_window_space = |
+ gfx::Rect(new_origin, original_window_bounds.size()); |
+ window->SetBounds(new_window_bounds_in_root_window_space); |
+ return true; |
+} |
+ |
+void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { |
+#if defined(OS_CHROMEOS) |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ ::switches::kUseNewVirtualKeyboardBehavior)) |
+ return; |
+ |
+ // Get restore bounds of the window |
+ gfx::Rect* vk_restore_bounds = |
+ window->GetProperty(aura::client::kVirtualKeyboardRestoreBoundsKey); |
+ |
+ if (vk_restore_bounds) { |
+ // Restore the window bounds |
+ // TODO(yhanada): Don't move the window if a user has moved it while the |
+ // keyboard is shown. |
+ if (window->GetBoundsInScreen() != *vk_restore_bounds) { |
+ gfx::Rect original_bounds = *vk_restore_bounds; |
+ ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); |
+ window->SetBounds(original_bounds); |
+ } |
+ window->ClearProperty(aura::client::kVirtualKeyboardRestoreBoundsKey); |
+ } |
+#endif // defined(OS_CHROMEOS) |
+} |
+ |
+} // namespace wm |