Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 DISALLOW_COPY_AND_ASSIGN(KeyboardWindowDelegate); | 83 DISALLOW_COPY_AND_ASSIGN(KeyboardWindowDelegate); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 namespace keyboard { | 88 namespace keyboard { |
| 89 | 89 |
| 90 // LayoutManager for the virtual keyboard container. Manages a single window | 90 // LayoutManager for the virtual keyboard container. Manages a single window |
| 91 // (the virtual keyboard) and keeps it positioned at the bottom of the | 91 // (the virtual keyboard) and keeps it positioned at the bottom of the |
| 92 // owner window. | 92 // owner window. |
| 93 class KeyboardLayoutManager : public aura::LayoutManager { | 93 class KeyboardLayoutManager : public aura::LayoutManager, |
| 94 public KeyboardResizer { | |
| 94 public: | 95 public: |
| 95 KeyboardLayoutManager(aura::Window* container) | 96 KeyboardLayoutManager(aura::Window* container) |
| 96 : container_(container), keyboard_(NULL) { | 97 : container_(container), keyboard_(NULL), resizing_(false) { |
| 97 CHECK(container_); | 98 CHECK(container_); |
| 98 } | 99 } |
| 99 | 100 |
| 101 // Overridden from KeyboardResizer | |
| 102 virtual void SetKeyboardHeight(int height) { | |
| 103 gfx::Rect rect = keyboard_->bounds(); | |
| 104 int old_height = rect.height(); | |
| 105 rect.set_height(height); | |
| 106 rect.set_y(rect.y() + old_height - height); | |
| 107 resizing_ = true; | |
| 108 keyboard_->SetBounds(rect); | |
| 109 resizing_ = false; | |
| 110 } | |
| 111 | |
| 100 // Overridden from aura::LayoutManager | 112 // Overridden from aura::LayoutManager |
| 101 virtual void OnWindowResized() OVERRIDE { | 113 virtual void OnWindowResized() OVERRIDE { |
| 102 if (!keyboard_) | 114 if (!keyboard_) |
| 103 return; | 115 return; |
| 104 SetChildBoundsDirect(keyboard_, | 116 SetChildBoundsDirect(keyboard_, |
| 105 KeyboardBoundsFromWindowBounds(container_->bounds())); | 117 KeyboardBoundsFromWindowBounds(container_->bounds())); |
| 106 } | 118 } |
| 107 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | 119 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 108 DCHECK(!keyboard_); | 120 DCHECK(!keyboard_); |
| 109 keyboard_ = child; | 121 keyboard_ = child; |
| 110 } | 122 } |
| 111 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 123 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 112 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} | 124 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 113 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 125 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 114 bool visible) OVERRIDE {} | 126 bool visible) OVERRIDE {} |
| 115 virtual void SetChildBounds(aura::Window* child, | 127 virtual void SetChildBounds(aura::Window* child, |
| 116 const gfx::Rect& requested_bounds) OVERRIDE { | 128 const gfx::Rect& requested_bounds) OVERRIDE { |
| 117 // Drop these: the size should only be set in OnWindowResized. | 129 if (resizing_) { |
| 130 SetChildBoundsDirect(child, requested_bounds); | |
| 131 } | |
| 118 } | 132 } |
| 119 | 133 |
| 120 private: | 134 private: |
| 121 aura::Window* container_; | 135 aura::Window* container_; |
| 122 aura::Window* keyboard_; | 136 aura::Window* keyboard_; |
| 137 bool resizing_; | |
| 123 | 138 |
| 124 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); | 139 DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); |
| 125 }; | 140 }; |
| 126 | 141 |
| 127 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) | 142 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
| 128 : proxy_(proxy), | 143 : proxy_(proxy), |
| 129 input_method_(NULL), | 144 input_method_(NULL), |
| 130 keyboard_visible_(false), | 145 keyboard_visible_(false), |
| 131 weak_factory_(this) { | 146 weak_factory_(this) { |
| 132 CHECK(proxy); | 147 CHECK(proxy); |
| 133 input_method_ = proxy_->GetInputMethod(); | 148 input_method_ = proxy_->GetInputMethod(); |
| 134 input_method_->AddObserver(this); | 149 input_method_->AddObserver(this); |
| 135 } | 150 } |
| 136 | 151 |
| 137 KeyboardController::~KeyboardController() { | 152 KeyboardController::~KeyboardController() { |
| 138 if (container_.get()) | 153 if (container_.get()) |
| 139 container_->RemoveObserver(this); | 154 container_->RemoveObserver(this); |
| 140 if (input_method_) | 155 if (input_method_) |
| 141 input_method_->RemoveObserver(this); | 156 input_method_->RemoveObserver(this); |
| 142 } | 157 } |
| 143 | 158 |
| 144 aura::Window* KeyboardController::GetContainerWindow() { | 159 aura::Window* KeyboardController::GetContainerWindow() { |
| 145 if (!container_.get()) { | 160 if (!container_.get()) { |
| 146 container_.reset(new aura::Window(new KeyboardWindowDelegate())); | 161 container_.reset(new aura::Window(new KeyboardWindowDelegate())); |
| 147 container_->SetName("KeyboardContainer"); | 162 container_->SetName("KeyboardContainer"); |
| 148 container_->set_owned_by_parent(false); | 163 container_->set_owned_by_parent(false); |
| 149 container_->Init(ui::LAYER_NOT_DRAWN); | 164 container_->Init(ui::LAYER_NOT_DRAWN); |
| 150 container_->AddObserver(this); | 165 container_->AddObserver(this); |
| 151 container_->SetLayoutManager(new KeyboardLayoutManager(container_.get())); | 166 KeyboardLayoutManager* layout_manager = new KeyboardLayoutManager( |
| 167 container_.get()); | |
| 168 proxy_->SetKeyboardResizer(layout_manager); | |
| 169 container_->SetLayoutManager(layout_manager); | |
|
kevers
2013/11/29 20:26:05
It looks a bit odd passing a raw pointer to 2 sepa
Shu Chen
2013/12/02 03:54:40
Done. I've refactored the changes and removed the
| |
| 152 } | 170 } |
| 153 return container_.get(); | 171 return container_.get(); |
| 154 } | 172 } |
| 155 | 173 |
| 156 void KeyboardController::HideKeyboard(HideReason reason) { | 174 void KeyboardController::HideKeyboard(HideReason reason) { |
| 157 keyboard_visible_ = false; | 175 keyboard_visible_ = false; |
| 158 | 176 |
| 159 keyboard::LogKeyboardControlEvent( | 177 keyboard::LogKeyboardControlEvent( |
| 160 reason == HIDE_REASON_AUTOMATIC ? | 178 reason == HIDE_REASON_AUTOMATIC ? |
| 161 keyboard::KEYBOARD_CONTROL_HIDE_AUTO : | 179 keyboard::KEYBOARD_CONTROL_HIDE_AUTO : |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 const ui::InputMethod* input_method) { | 268 const ui::InputMethod* input_method) { |
| 251 DCHECK_EQ(input_method_, input_method); | 269 DCHECK_EQ(input_method_, input_method); |
| 252 input_method_ = NULL; | 270 input_method_ = NULL; |
| 253 } | 271 } |
| 254 | 272 |
| 255 bool KeyboardController::WillHideKeyboard() const { | 273 bool KeyboardController::WillHideKeyboard() const { |
| 256 return weak_factory_.HasWeakPtrs(); | 274 return weak_factory_.HasWeakPtrs(); |
| 257 } | 275 } |
| 258 | 276 |
| 259 } // namespace keyboard | 277 } // namespace keyboard |
| OLD | NEW |