| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/wm/core/ime_util_chromeos.h" | 5 #include "ui/wm/core/ime_util_chromeos.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/base/ui_base_switches.h" | 9 #include "ui/base/ui_base_switches.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 window->SetBounds(new_bounds_in_root_window); | 44 window->SetBounds(new_bounds_in_root_window); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, | 49 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, |
| 50 kVirtualKeyboardRestoreBoundsKey, | 50 kVirtualKeyboardRestoreBoundsKey, |
| 51 nullptr); | 51 nullptr); |
| 52 | 52 |
| 53 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { | 53 void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { |
| 54 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 54 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 55 ::switches::kUseNewVirtualKeyboardBehavior)) | 55 ::switches::kDisableNewVirtualKeyboardBehavior)) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 // Get restore bounds of the window | 58 // Get restore bounds of the window |
| 59 gfx::Rect* vk_restore_bounds = | 59 gfx::Rect* vk_restore_bounds = |
| 60 window->GetProperty(kVirtualKeyboardRestoreBoundsKey); | 60 window->GetProperty(kVirtualKeyboardRestoreBoundsKey); |
| 61 | 61 |
| 62 if (!vk_restore_bounds) | 62 if (!vk_restore_bounds) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 // Restore the window bounds | 65 // Restore the window bounds |
| 66 // TODO(yhanada): Don't move the window if a user has moved it while the | 66 // TODO(yhanada): Don't move the window if a user has moved it while the |
| 67 // keyboard is shown. | 67 // keyboard is shown. |
| 68 if (window->GetBoundsInScreen() != *vk_restore_bounds) { | 68 if (window->GetBoundsInScreen() != *vk_restore_bounds) { |
| 69 gfx::Rect original_bounds = *vk_restore_bounds; | 69 gfx::Rect original_bounds = *vk_restore_bounds; |
| 70 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); | 70 ::wm::ConvertRectFromScreen(window->GetRootWindow(), &original_bounds); |
| 71 window->SetBounds(original_bounds); | 71 window->SetBounds(original_bounds); |
| 72 } | 72 } |
| 73 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey); | 73 window->ClearProperty(wm::kVirtualKeyboardRestoreBoundsKey); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void EnsureWindowNotInRect(aura::Window* window, | 76 void EnsureWindowNotInRect(aura::Window* window, |
| 77 const gfx::Rect& rect_in_screen) { | 77 const gfx::Rect& rect_in_screen) { |
| 78 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 78 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 79 ::switches::kUseNewVirtualKeyboardBehavior)) | 79 ::switches::kDisableNewVirtualKeyboardBehavior)) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 gfx::Rect original_window_bounds = window->GetBoundsInScreen(); | 82 gfx::Rect original_window_bounds = window->GetBoundsInScreen(); |
| 83 if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) { | 83 if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) { |
| 84 original_window_bounds = | 84 original_window_bounds = |
| 85 *window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey); | 85 *window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey); |
| 86 } | 86 } |
| 87 | 87 |
| 88 gfx::Rect hidden_window_bounds_in_screen = | 88 gfx::Rect hidden_window_bounds_in_screen = |
| 89 gfx::IntersectRects(rect_in_screen, original_window_bounds); | 89 gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| 90 if (hidden_window_bounds_in_screen.IsEmpty()) { | 90 if (hidden_window_bounds_in_screen.IsEmpty()) { |
| 91 // The window isn't covered by the keyboard, restore the window position if | 91 // The window isn't covered by the keyboard, restore the window position if |
| 92 // necessary. | 92 // necessary. |
| 93 RestoreWindowBoundsOnClientFocusLost(window); | 93 RestoreWindowBoundsOnClientFocusLost(window); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 MoveWindowToEnsureCaretNotInRect(window, rect_in_screen); | 97 MoveWindowToEnsureCaretNotInRect(window, rect_in_screen); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace wm | 100 } // namespace wm |
| OLD | NEW |