Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.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 #if defined(OS_CHROMEOS) | |
|
sky
2017/04/26 15:24:36
It seems that all this code is chromeos specific.
oshima
2017/04/26 18:03:42
These are used in content/browser and ui/views. Th
sky
2017/04/26 19:58:17
I'm ok with them living here, but how about making
| |
| 17 // Moves the window to ensure caret not in rect. | |
| 18 // Returns whether the window is actually moved or not. | |
| 19 // This function has to be in ifdef to prevent unused function error. | |
| 20 bool MoveWindowToEnsureCaretNotInRect(aura::Window* window, | |
| 21 const gfx::Rect& rect_in_screen) { | |
| 22 gfx::Rect original_window_bounds = window->GetBoundsInScreen(); | |
| 23 // Calculate vertial window shift | |
| 24 gfx::Rect rect_in_root_window = rect_in_screen; | |
| 25 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window); | |
| 26 gfx::Rect bounds_in_root_window = window->GetBoundsInRootWindow(); | |
| 27 const int top_y = | |
| 28 std::max(rect_in_root_window.y() - bounds_in_root_window.height(), 0); | |
| 29 | |
| 30 // No need to move up the window | |
| 31 if (top_y >= bounds_in_root_window.y()) | |
| 32 return false; | |
| 33 | |
| 34 // Set restore bounds and move the window. | |
| 35 window->SetProperty(kVirtualKeyboardRestoreBoundsKey, | |
| 36 new gfx::Rect(original_window_bounds)); | |
| 37 | |
| 38 gfx::Rect new_bounds_in_root_window = bounds_in_root_window; | |
| 39 new_bounds_in_root_window.set_y(top_y); | |
| 40 window->SetBounds(new_bounds_in_root_window); | |
| 41 return true; | |
| 42 } | |
| 43 #endif // defined(OS_CHROMEOS) | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, | |
| 48 kVirtualKeyboardRestoreBoundsKey, | |
| 49 nullptr); | |
| 50 | |
| 51 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { | |
| 52 #if defined(OS_CHROMEOS) | |
| 53 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 54 ::switches::kUseNewVirtualKeyboardBehavior)) | |
| 55 return; | |
| 56 | |
| 57 // Get restore bounds of the window | |
| 58 gfx::Rect* vk_restore_bounds = | |
| 59 window->GetProperty(kVirtualKeyboardRestoreBoundsKey); | |
| 60 | |
| 61 if (vk_restore_bounds) { | |
| 62 // Restore the window bounds | |
| 63 // TODO(yhanada): Don't move the window if a user has moved it while the | |
| 64 // keyboard is shown. | |
| 65 if (window->GetBoundsInScreen() != *vk_restore_bounds) { | |
| 66 gfx::Rect original_bounds = *vk_restore_bounds; | |
| 67 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); | |
| 68 window->SetBounds(original_bounds); | |
| 69 } | |
| 70 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey); | |
| 71 } | |
| 72 #endif // defined(OS_CHROMEOS) | |
| 73 } | |
| 74 | |
| 75 void EnsureWindowNotInRect(aura::Window* window, | |
| 76 const gfx::Rect& rect_in_screen) { | |
| 77 #if defined(OS_CHROMEOS) | |
| 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); | |
| 99 #endif // defined(OS_CHROMEOS) | |
| 100 } | |
| 101 | |
| 102 } // namespace wm | |
| OLD | NEW |