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

Side by Side Diff: ui/wm/core/ime_util_chromeos.cc

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: rebase Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « ui/wm/core/ime_util_chromeos.h ('k') | ui/wm/core/ime_util_chromeos_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/wm/core/ime_util_chromeos.h"
6
7 #include "base/command_line.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/base/ui_base_switches.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/wm/core/coordinate_conversion.h"
12
13 namespace wm {
14 namespace {
15
16 // Moves the window to ensure caret not in rect.
17 // Returns whether the window was moved or not.
18 void MoveWindowToEnsureCaretNotInRect(aura::Window* window,
19 const gfx::Rect& rect_in_screen) {
20 gfx::Rect original_window_bounds = window->GetBoundsInScreen();
21 if (window->GetProperty(kVirtualKeyboardRestoreBoundsKey)) {
22 original_window_bounds =
23 *window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
24 }
25
26 // Calculate vertical window shift.
27 gfx::Rect rect_in_root_window = rect_in_screen;
28 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window);
29 gfx::Rect bounds_in_root_window = original_window_bounds;
30 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &bounds_in_root_window);
31 const int top_y =
32 std::max(rect_in_root_window.y() - bounds_in_root_window.height(), 0);
33
34 // No need to move the window up.
35 if (top_y >= bounds_in_root_window.y())
36 return;
37
38 // Set restore bounds and move the window.
39 window->SetProperty(kVirtualKeyboardRestoreBoundsKey,
40 new gfx::Rect(original_window_bounds));
41
42 gfx::Rect new_bounds_in_root_window = bounds_in_root_window;
43 new_bounds_in_root_window.set_y(top_y);
44 window->SetBounds(new_bounds_in_root_window);
45 }
46
47 } // namespace
48
49 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
50 kVirtualKeyboardRestoreBoundsKey,
51 nullptr);
52
53 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) {
54 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
55 ::switches::kUseNewVirtualKeyboardBehavior))
56 return;
57
58 // Get restore bounds of the window
59 gfx::Rect* vk_restore_bounds =
60 window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
61
62 if (!vk_restore_bounds)
63 return;
64
65 // Restore the window bounds
66 // TODO(yhanada): Don't move the window if a user has moved it while the
67 // keyboard is shown.
68 if (window->GetBoundsInScreen() != *vk_restore_bounds) {
69 gfx::Rect original_bounds = *vk_restore_bounds;
70 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds);
71 window->SetBounds(original_bounds);
72 }
73 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey);
74 }
75
76 void EnsureWindowNotInRect(aura::Window* window,
77 const gfx::Rect& rect_in_screen) {
78 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
79 ::switches::kUseNewVirtualKeyboardBehavior))
80 return;
81
82 gfx::Rect original_window_bounds = window->GetBoundsInScreen();
83 if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) {
84 original_window_bounds =
85 *window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey);
86 }
87
88 gfx::Rect hidden_window_bounds_in_screen =
89 gfx::IntersectRects(rect_in_screen, original_window_bounds);
90 if (hidden_window_bounds_in_screen.IsEmpty()) {
91 // The window isn't covered by the keyboard, restore the window position if
92 // necessary.
93 RestoreWindowBoundsOnClientFocusLost(window);
94 return;
95 }
96
97 MoveWindowToEnsureCaretNotInRect(window, rect_in_screen);
98 }
99
100 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/ime_util_chromeos.h ('k') | ui/wm/core/ime_util_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698