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 "ui/aura/client/aura_constants.h" |
| 8 #include "ui/aura/window.h" |
| 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/wm/core/coordinate_conversion.h" |
| 11 |
| 12 namespace wm { |
| 13 |
| 14 bool MoveWindowToEnsureCaretNotInRect(aura::Window* window, |
| 15 const gfx::Rect& rect_in_screen) { |
| 16 gfx::Rect original_window_bounds = window->GetBoundsInScreen(); |
| 17 // Calculate vertial window shift |
| 18 gfx::Rect rect_in_root_window = rect_in_screen; |
| 19 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &rect_in_root_window); |
| 20 const int top_y = std::max( |
| 21 rect_in_root_window.y() - window->GetBoundsInRootWindow().height(), 0); |
| 22 |
| 23 // No need to move up the window |
| 24 if (top_y == window->GetBoundsInRootWindow().y()) |
| 25 return false; |
| 26 |
| 27 // Set restore bounds and move the window. |
| 28 window->SetProperty(aura::client::kVirtualKeyboardRestoreBoundsKey, |
| 29 new gfx::Rect(original_window_bounds)); |
| 30 |
| 31 gfx::Point new_origin(window->GetBoundsInRootWindow().x(), top_y); |
| 32 gfx::Rect new_window_bounds_in_root_window_space = |
| 33 gfx::Rect(new_origin, original_window_bounds.size()); |
| 34 window->SetBounds(new_window_bounds_in_root_window_space); |
| 35 return true; |
| 36 } |
| 37 |
| 38 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { |
| 39 // Get restore bounds of the window |
| 40 gfx::Rect* vk_restore_bounds = |
| 41 window->GetProperty(aura::client::kVirtualKeyboardRestoreBoundsKey); |
| 42 |
| 43 if (vk_restore_bounds) { |
| 44 // Restore the window bounds |
| 45 // TODO(yhanada): Don't move the window if a user has moved it while the |
| 46 // keyboard is shown. |
| 47 if (window->GetBoundsInScreen() != *vk_restore_bounds) { |
| 48 gfx::Rect original_bounds = *vk_restore_bounds; |
| 49 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); |
| 50 window->SetBounds(original_bounds); |
| 51 } |
| 52 window->ClearProperty(aura::client::kVirtualKeyboardRestoreBoundsKey); |
| 53 } |
| 54 } |
| 55 |
| 56 } // namespace wm |
OLD | NEW |