| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 input_method_ = ui_->GetInputMethod(); | 181 input_method_ = ui_->GetInputMethod(); |
| 182 input_method_->AddObserver(this); | 182 input_method_->AddObserver(this); |
| 183 ui_->SetController(this); | 183 ui_->SetController(this); |
| 184 } | 184 } |
| 185 | 185 |
| 186 KeyboardController::~KeyboardController() { | 186 KeyboardController::~KeyboardController() { |
| 187 if (container_) { | 187 if (container_) { |
| 188 if (container_->GetRootWindow()) | 188 if (container_->GetRootWindow()) |
| 189 container_->GetRootWindow()->RemoveObserver(this); | 189 container_->GetRootWindow()->RemoveObserver(this); |
| 190 container_->RemoveObserver(this); | 190 container_->RemoveObserver(this); |
| 191 container_->RemovePreTargetHandler(&event_filter_); |
| 191 } | 192 } |
| 192 if (input_method_) | 193 if (input_method_) |
| 193 input_method_->RemoveObserver(this); | 194 input_method_->RemoveObserver(this); |
| 194 for (KeyboardControllerObserver& observer : observer_list_) | 195 for (KeyboardControllerObserver& observer : observer_list_) |
| 195 observer.OnKeyboardClosed(); | 196 observer.OnKeyboardClosed(); |
| 196 ui_->SetController(nullptr); | 197 ui_->SetController(nullptr); |
| 197 } | 198 } |
| 198 | 199 |
| 199 // static | 200 // static |
| 200 void KeyboardController::ResetInstance(KeyboardController* controller) { | 201 void KeyboardController::ResetInstance(KeyboardController* controller) { |
| 201 if (instance_ && instance_ != controller) | 202 if (instance_ && instance_ != controller) |
| 202 delete instance_; | 203 delete instance_; |
| 203 instance_ = controller; | 204 instance_ = controller; |
| 204 } | 205 } |
| 205 | 206 |
| 206 // static | 207 // static |
| 207 KeyboardController* KeyboardController::GetInstance() { | 208 KeyboardController* KeyboardController::GetInstance() { |
| 208 return instance_; | 209 return instance_; |
| 209 } | 210 } |
| 210 | 211 |
| 211 aura::Window* KeyboardController::GetContainerWindow() { | 212 aura::Window* KeyboardController::GetContainerWindow() { |
| 212 if (!container_.get()) { | 213 if (!container_.get()) { |
| 213 container_.reset(new aura::Window(new KeyboardWindowDelegate())); | 214 container_.reset(new aura::Window(new KeyboardWindowDelegate())); |
| 214 container_->SetName("KeyboardContainer"); | 215 container_->SetName("KeyboardContainer"); |
| 215 container_->set_owned_by_parent(false); | 216 container_->set_owned_by_parent(false); |
| 216 container_->Init(ui::LAYER_NOT_DRAWN); | 217 container_->Init(ui::LAYER_NOT_DRAWN); |
| 217 container_->AddObserver(this); | 218 container_->AddObserver(this); |
| 218 container_->SetLayoutManager(new KeyboardLayoutManager(this)); | 219 container_->SetLayoutManager(new KeyboardLayoutManager(this)); |
| 220 container_->AddPreTargetHandler(&event_filter_); |
| 219 } | 221 } |
| 220 return container_.get(); | 222 return container_.get(); |
| 221 } | 223 } |
| 222 | 224 |
| 223 void KeyboardController::NotifyKeyboardBoundsChanging( | 225 void KeyboardController::NotifyKeyboardBoundsChanging( |
| 224 const gfx::Rect& new_bounds) { | 226 const gfx::Rect& new_bounds) { |
| 225 current_keyboard_bounds_ = new_bounds; | 227 current_keyboard_bounds_ = new_bounds; |
| 226 if (ui_->HasKeyboardWindow() && ui_->GetKeyboardWindow()->IsVisible()) { | 228 if (ui_->HasKeyboardWindow() && ui_->GetKeyboardWindow()->IsVisible()) { |
| 227 for (KeyboardControllerObserver& observer : observer_list_) | 229 for (KeyboardControllerObserver& observer : observer_list_) |
| 228 observer.OnKeyboardBoundsChanging(new_bounds); | 230 observer.OnKeyboardBoundsChanging(new_bounds); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 int keyboard_height = GetContainerWindow()->bounds().height(); | 518 int keyboard_height = GetContainerWindow()->bounds().height(); |
| 517 const gfx::Rect& root_bounds = container_->GetRootWindow()->bounds(); | 519 const gfx::Rect& root_bounds = container_->GetRootWindow()->bounds(); |
| 518 gfx::Rect new_bounds = root_bounds; | 520 gfx::Rect new_bounds = root_bounds; |
| 519 new_bounds.set_y(root_bounds.height() - keyboard_height); | 521 new_bounds.set_y(root_bounds.height() - keyboard_height); |
| 520 new_bounds.set_height(keyboard_height); | 522 new_bounds.set_height(keyboard_height); |
| 521 GetContainerWindow()->SetBounds(new_bounds); | 523 GetContainerWindow()->SetBounds(new_bounds); |
| 522 } | 524 } |
| 523 } | 525 } |
| 524 | 526 |
| 525 } // namespace keyboard | 527 } // namespace keyboard |
| OLD | NEW |