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 |
| 15 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, |
| 16 kVirtualKeyboardRestoreBoundsKey, |
| 17 nullptr); |
| 18 |
| 19 bool MoveWindowToEnsureCaretNotInRect(aura::Window* window, |
| 20 const gfx::Rect& rect_in_screen) { |
| 21 gfx::Rect original_window_bounds = window->GetBoundsInScreen(); |
| 22 // Calculate vertial window shift |
| 23 gfx::Rect rect_in_root_window = rect_in_screen; |
| 24 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window); |
| 25 gfx::Rect bounds_in_root_window = window->GetBoundsInRootWindow(); |
| 26 const int top_y = |
| 27 std::max(rect_in_root_window.y() - bounds_in_root_window.height(), 0); |
| 28 |
| 29 // No need to move up the window |
| 30 if (top_y >= bounds_in_root_window.y()) |
| 31 return false; |
| 32 |
| 33 // Set restore bounds and move the window. |
| 34 window->SetProperty(kVirtualKeyboardRestoreBoundsKey, |
| 35 new gfx::Rect(original_window_bounds)); |
| 36 |
| 37 gfx::Rect new_bounds_in_root_window = bounds_in_root_window; |
| 38 new_bounds_in_root_window.set_y(top_y); |
| 39 window->SetBounds(new_bounds_in_root_window); |
| 40 return true; |
| 41 } |
| 42 |
| 43 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { |
| 44 #if defined(OS_CHROMEOS) |
| 45 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 46 ::switches::kUseNewVirtualKeyboardBehavior)) |
| 47 return; |
| 48 |
| 49 // Get restore bounds of the window |
| 50 gfx::Rect* vk_restore_bounds = |
| 51 window->GetProperty(kVirtualKeyboardRestoreBoundsKey); |
| 52 |
| 53 if (vk_restore_bounds) { |
| 54 // Restore the window bounds |
| 55 // TODO(yhanada): Don't move the window if a user has moved it while the |
| 56 // keyboard is shown. |
| 57 if (window->GetBoundsInScreen() != *vk_restore_bounds) { |
| 58 gfx::Rect original_bounds = *vk_restore_bounds; |
| 59 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); |
| 60 window->SetBounds(original_bounds); |
| 61 } |
| 62 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey); |
| 63 } |
| 64 #endif // defined(OS_CHROMEOS) |
| 65 } |
| 66 |
| 67 } // namespace wm |
OLD | NEW |