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

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: Renamed to ime_util_chromeos and added the unittests 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 is actually moved or not.
sky 2017/04/28 20:17:51 'is actually' -> 'was'
yhanada 2017/05/01 09:12:44 Done.
18 // This function has to be in ifdef to prevent unused function error.
sky 2017/04/28 20:17:51 Remove this line.
yhanada 2017/05/01 09:12:46 Done.
19 bool MoveWindowToEnsureCaretNotInRect(aura::Window* window,
20 const gfx::Rect& rect_in_screen) {
21 gfx::Rect original_window_bounds = window->GetBoundsInScreen();
22 if (window->GetProperty(kVirtualKeyboardRestoreBoundsKey)) {
23 original_window_bounds =
24 *window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
25 }
26
27 // Calculate vertial window shift
sky 2017/04/28 20:17:51 vertial -> vertical Also, end sentences with punct
yhanada 2017/05/01 09:12:47 Done.
28 gfx::Rect rect_in_root_window = rect_in_screen;
29 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window);
30 gfx::Rect bounds_in_root_window = original_window_bounds;
31 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &bounds_in_root_window);
32 const int top_y =
33 std::max(rect_in_root_window.y() - bounds_in_root_window.height(), 0);
sky 2017/04/28 20:17:51 Why do you use bounds_in_root_window.height() here
yhanada 2017/05/01 09:12:45 (rect_in_root_window.y() - bounds_in_root_window.h
sky 2017/05/01 21:06:09 Acknowledged.
34
35 // No need to move up the window
sky 2017/04/28 20:17:51 No need to move the window up.
yhanada 2017/05/01 09:12:46 Done.
36 if (top_y >= bounds_in_root_window.y())
37 return false;
38
39 // Set restore bounds and move the window.
40 window->SetProperty(kVirtualKeyboardRestoreBoundsKey,
41 new gfx::Rect(original_window_bounds));
42
43 gfx::Rect new_bounds_in_root_window = bounds_in_root_window;
44 new_bounds_in_root_window.set_y(top_y);
45 window->SetBounds(new_bounds_in_root_window);
46 return true;
47 }
48
49 } // namespace
50
51 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
52 kVirtualKeyboardRestoreBoundsKey,
53 nullptr);
54
55 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) {
56 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
57 ::switches::kUseNewVirtualKeyboardBehavior))
58 return;
59
60 // Get restore bounds of the window
61 gfx::Rect* vk_restore_bounds =
62 window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
63
64 if (vk_restore_bounds) {
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
77 void EnsureWindowNotInRect(aura::Window* window,
78 const gfx::Rect& rect_in_screen) {
79 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
80 ::switches::kUseNewVirtualKeyboardBehavior))
81 return;
82
83 gfx::Rect original_window_bounds = window->GetBoundsInScreen();
84 if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) {
85 original_window_bounds =
86 *window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey);
87 }
88
89 gfx::Rect hidden_window_bounds_in_screen =
90 gfx::IntersectRects(rect_in_screen, original_window_bounds);
91 if (hidden_window_bounds_in_screen.IsEmpty()) {
92 // The window isn't covered by the keyboard, restore the window position if
93 // necessary.
94 RestoreWindowBoundsOnClientFocusLost(window);
95 return;
96 }
97
98 if (!MoveWindowToEnsureCaretNotInRect(window, rect_in_screen))
99 RestoreWindowBoundsOnClientFocusLost(window);
100 }
101
102 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698