Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: ui/wm/core/ime_util.cc

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: Remove unused variable Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/wm/core/ime_util.h ('K') | « ui/wm/core/ime_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..32b70f0c372f7074ae89f2078cc4eff51d135039
--- /dev/null
+++ b/ui/wm/core/ime_util.cc
@@ -0,0 +1,67 @@
+// 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/base/ui_base_switches.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/wm/core/coordinate_conversion.h"
+
+namespace wm {
+
+DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
+ kVirtualKeyboardRestoreBoundsKey,
+ nullptr);
+
+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);
+ gfx::Rect bounds_in_root_window = window->GetBoundsInRootWindow();
+ const int top_y =
+ std::max(rect_in_root_window.y() - bounds_in_root_window.height(), 0);
+
+ // No need to move up the window
+ if (top_y >= bounds_in_root_window.y())
+ return false;
+
+ // Set restore bounds and move the window.
+ window->SetProperty(kVirtualKeyboardRestoreBoundsKey,
+ new gfx::Rect(original_window_bounds));
+
+ gfx::Rect new_bounds_in_root_window = bounds_in_root_window;
+ new_bounds_in_root_window.set_y(top_y);
+ window->SetBounds(new_bounds_in_root_window);
+ 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(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(wm::kVirtualKeyboardRestoreBoundsKey);
+ }
+#endif // defined(OS_CHROMEOS)
+}
+
+} // namespace wm
« ui/wm/core/ime_util.h ('K') | « ui/wm/core/ime_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698