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

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
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 bool 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 false;
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 return true;
46 }
47
48 } // namespace
49
50 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
51 kVirtualKeyboardRestoreBoundsKey,
52 nullptr);
53
54 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) {
55 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
56 ::switches::kUseNewVirtualKeyboardBehavior))
57 return;
58
59 // Get restore bounds of the window
60 gfx::Rect* vk_restore_bounds =
61 window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
62
63 if (vk_restore_bounds) {
sadrul 2017/05/08 15:47:26 Early return instead
yhanada 2017/05/09 03:19:14 Done.
64 // Restore the window bounds
65 // TODO(yhanada): Don't move the window if a user has moved it while the
66 // keyboard is shown.
67 if (window->GetBoundsInScreen() != *vk_restore_bounds) {
68 gfx::Rect original_bounds = *vk_restore_bounds;
69 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds);
70 window->SetBounds(original_bounds);
71 }
72 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey);
73 }
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 if (!MoveWindowToEnsureCaretNotInRect(window, rect_in_screen))
98 RestoreWindowBoundsOnClientFocusLost(window);
sadrul 2017/05/08 15:47:26 Do you need the restore here?
yhanada 2017/05/09 03:19:14 No. I didn't realize that. Thank you for pointing
99 }
100
101 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698