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 <set> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "content/public/browser/render_widget_host.h" | 11 #include "content/public/browser/render_widget_host.h" |
| 10 #include "content/public/browser/render_widget_host_iterator.h" | 12 #include "content/public/browser/render_widget_host_iterator.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 14 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 15 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
| 16 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 ui::LayerAnimationSequence* seq) { | 202 ui::LayerAnimationSequence* seq) { |
| 201 animator_->RemoveObserver(this); | 203 animator_->RemoveObserver(this); |
| 202 } | 204 } |
| 203 | 205 |
| 204 class WindowBoundsChangeObserver : public aura::WindowObserver { | 206 class WindowBoundsChangeObserver : public aura::WindowObserver { |
| 205 public: | 207 public: |
| 206 virtual void OnWindowBoundsChanged(aura::Window* window, | 208 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 207 const gfx::Rect& old_bounds, | 209 const gfx::Rect& old_bounds, |
| 208 const gfx::Rect& new_bounds) OVERRIDE; | 210 const gfx::Rect& new_bounds) OVERRIDE; |
| 209 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; | 211 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; |
| 212 | |
| 213 void AddObservedWindow(aura::Window* window); | |
| 214 void RemoveAllObservedWindows(); | |
| 215 | |
| 216 private: | |
| 217 std::set<aura::Window*> observed_windows_; | |
| 210 }; | 218 }; |
| 211 | 219 |
| 212 void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, | 220 void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, |
| 213 const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { | 221 const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { |
| 214 KeyboardController* controller = KeyboardController::GetInstance(); | 222 KeyboardController* controller = KeyboardController::GetInstance(); |
| 215 if (controller) | 223 if (controller) |
| 216 controller->UpdateWindowInsets(window); | 224 controller->UpdateWindowInsets(window); |
| 217 } | 225 } |
| 218 | 226 |
| 219 void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) { | 227 void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) { |
| 220 if (window->HasObserver(this)) | 228 if (window->HasObserver(this)) |
| 221 window->RemoveObserver(this); | 229 window->RemoveObserver(this); |
|
kevers
2014/09/02 14:32:30
observed_windows_.erase(window);
Otherwise Remove
Shu Chen
2014/09/02 14:33:20
Done.
| |
| 222 } | 230 } |
| 223 | 231 |
| 232 void WindowBoundsChangeObserver::AddObservedWindow(aura::Window* window) { | |
| 233 if (!window->HasObserver(this)) { | |
| 234 window->AddObserver(this); | |
| 235 observed_windows_.insert(window); | |
| 236 } | |
| 237 } | |
| 238 | |
| 239 void WindowBoundsChangeObserver::RemoveAllObservedWindows() { | |
| 240 for (std::set<aura::Window*>::iterator it = observed_windows_.begin(); | |
| 241 it != observed_windows_.end(); ++it) | |
| 242 (*it)->RemoveObserver(this); | |
| 243 observed_windows_.clear(); | |
| 244 } | |
| 245 | |
| 224 // static | 246 // static |
| 225 KeyboardController* KeyboardController::instance_ = NULL; | 247 KeyboardController* KeyboardController::instance_ = NULL; |
| 226 | 248 |
| 227 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) | 249 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
| 228 : proxy_(proxy), | 250 : proxy_(proxy), |
| 229 input_method_(NULL), | 251 input_method_(NULL), |
| 230 keyboard_visible_(false), | 252 keyboard_visible_(false), |
| 231 show_on_resize_(false), | 253 show_on_resize_(false), |
| 232 lock_keyboard_(false), | 254 lock_keyboard_(false), |
| 233 type_(ui::TEXT_INPUT_TYPE_NONE), | 255 type_(ui::TEXT_INPUT_TYPE_NONE), |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 container_->layer()->SetOpacity(1.0); | 548 container_->layer()->SetOpacity(1.0); |
| 527 } | 549 } |
| 528 } | 550 } |
| 529 | 551 |
| 530 void KeyboardController::ResetWindowInsets() { | 552 void KeyboardController::ResetWindowInsets() { |
| 531 const gfx::Insets insets; | 553 const gfx::Insets insets; |
| 532 scoped_ptr<content::RenderWidgetHostIterator> widgets( | 554 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
| 533 content::RenderWidgetHost::GetRenderWidgetHosts()); | 555 content::RenderWidgetHost::GetRenderWidgetHosts()); |
| 534 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 556 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 535 content::RenderWidgetHostView* view = widget->GetView(); | 557 content::RenderWidgetHostView* view = widget->GetView(); |
| 536 if (view) { | 558 if (view) |
| 537 view->SetInsets(insets); | 559 view->SetInsets(insets); |
| 538 aura::Window *window = view->GetNativeView(); | |
| 539 RemoveBoundsChangedObserver(window); | |
| 540 } | |
| 541 } | 560 } |
| 561 window_bounds_observer_->RemoveAllObservedWindows(); | |
| 542 } | 562 } |
| 543 | 563 |
| 544 bool KeyboardController::WillHideKeyboard() const { | 564 bool KeyboardController::WillHideKeyboard() const { |
| 545 return weak_factory_.HasWeakPtrs(); | 565 return weak_factory_.HasWeakPtrs(); |
| 546 } | 566 } |
| 547 | 567 |
| 548 void KeyboardController::ShowAnimationFinished() { | 568 void KeyboardController::ShowAnimationFinished() { |
| 549 // Notify observers after animation finished to prevent reveal desktop | 569 // Notify observers after animation finished to prevent reveal desktop |
| 550 // background during animation. | 570 // background during animation. |
| 551 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); | 571 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); |
| 552 proxy_->EnsureCaretInWorkArea(); | 572 proxy_->EnsureCaretInWorkArea(); |
| 553 } | 573 } |
| 554 | 574 |
| 555 void KeyboardController::HideAnimationFinished() { | 575 void KeyboardController::HideAnimationFinished() { |
| 556 proxy_->HideKeyboardContainer(container_.get()); | 576 proxy_->HideKeyboardContainer(container_.get()); |
| 557 } | 577 } |
| 558 | 578 |
| 559 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { | 579 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { |
| 560 aura::Window* target_window = GetFrameWindow(window); | 580 aura::Window* target_window = GetFrameWindow(window); |
| 561 if (target_window && | 581 if (target_window) |
| 562 !target_window->HasObserver(window_bounds_observer_.get())) { | 582 window_bounds_observer_->AddObservedWindow(target_window); |
| 563 target_window->AddObserver(window_bounds_observer_.get()); | |
| 564 } | |
| 565 } | |
| 566 | |
| 567 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) { | |
| 568 aura::Window* target_window = GetFrameWindow(window); | |
| 569 if (target_window && | |
| 570 target_window->HasObserver(window_bounds_observer_.get())) { | |
| 571 target_window->RemoveObserver(window_bounds_observer_.get()); | |
| 572 } | |
| 573 } | 583 } |
| 574 | 584 |
| 575 } // namespace keyboard | 585 } // namespace keyboard |
| OLD | NEW |