Chromium Code Reviews| Index: ui/keyboard/keyboard_controller.cc |
| diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc |
| index 4fdf8f0a020e5867077ccd7694263848c91f227d..f21759e3139c40fd0328bf652e65712e748918d9 100644 |
| --- a/ui/keyboard/keyboard_controller.cc |
| +++ b/ui/keyboard/keyboard_controller.cc |
| @@ -145,17 +145,6 @@ void ToggleTouchEventLogging(bool enable) { |
| #endif |
| } |
| -aura::Window *GetFrameWindow(aura::Window *window) { |
| - // Each container window has a non-negative id. Stop traversing at the child |
| - // of a container window. |
| - if (!window) |
| - return NULL; |
| - while (window->parent() && window->parent()->id() < 0) { |
| - window = window->parent(); |
| - } |
| - return window; |
| -} |
| - |
| } // namespace |
| namespace keyboard { |
| @@ -204,18 +193,30 @@ void CallbackAnimationObserver::OnLayerAnimationAborted( |
| class WindowBoundsChangeObserver : public aura::WindowObserver { |
| public: |
| + explicit WindowBoundsChangeObserver(aura::Window* window); |
| + ~WindowBoundsChangeObserver() override; |
| + |
| void OnWindowBoundsChanged(aura::Window* window, |
| const gfx::Rect& old_bounds, |
| const gfx::Rect& new_bounds) override; |
| void OnWindowDestroyed(aura::Window* window) override; |
| - void AddObservedWindow(aura::Window* window); |
| - void RemoveAllObservedWindows(); |
| - |
| private: |
| - std::set<aura::Window*> observed_windows_; |
| + aura::Window* window_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WindowBoundsChangeObserver); |
| }; |
| +WindowBoundsChangeObserver::WindowBoundsChangeObserver(aura::Window* window) |
| + : window_(window) { |
| + window_->AddObserver(this); |
| +} |
| + |
| +WindowBoundsChangeObserver::~WindowBoundsChangeObserver() { |
| + if (window_) |
| + window_->RemoveObserver(this); |
| +} |
| + |
| void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, |
| const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { |
| KeyboardController* controller = KeyboardController::GetInstance(); |
| @@ -224,23 +225,7 @@ void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, |
| } |
| void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) { |
| - if (window->HasObserver(this)) |
| - window->RemoveObserver(this); |
| - observed_windows_.erase(window); |
| -} |
| - |
| -void WindowBoundsChangeObserver::AddObservedWindow(aura::Window* window) { |
| - if (!window->HasObserver(this)) { |
| - window->AddObserver(this); |
| - observed_windows_.insert(window); |
| - } |
| -} |
| - |
| -void WindowBoundsChangeObserver::RemoveAllObservedWindows() { |
| - for (std::set<aura::Window*>::iterator it = observed_windows_.begin(); |
| - it != observed_windows_.end(); ++it) |
| - (*it)->RemoveObserver(this); |
| - observed_windows_.clear(); |
| + window_ = nullptr; |
| } |
| // static |
| @@ -257,7 +242,6 @@ KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) |
| CHECK(proxy); |
| input_method_ = proxy_->GetInputMethod(); |
| input_method_->AddObserver(this); |
| - window_bounds_observer_.reset(new WindowBoundsChangeObserver()); |
| } |
| KeyboardController::~KeyboardController() { |
| @@ -309,8 +293,8 @@ void KeyboardController::NotifyKeyboardBoundsChanging( |
| // window is created while the keyboard is visible. |
| scoped_ptr<content::RenderWidgetHostIterator> widgets( |
| content::RenderWidgetHost::GetRenderWidgetHosts()); |
| - aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); |
| - aura::Window *root_window = keyboard_window->GetRootWindow(); |
| + aura::Window* keyboard_window = proxy_->GetKeyboardWindow(); |
| + aura::Window* root_window = keyboard_window->GetRootWindow(); |
| while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
| content::RenderWidgetHostView* view = widget->GetView(); |
| // Can be NULL, e.g. if the RenderWidget is being destroyed or |
| @@ -318,9 +302,9 @@ void KeyboardController::NotifyKeyboardBoundsChanging( |
| if (view) { |
| aura::Window *window = view->GetNativeView(); |
| // If virtual keyboard failed to load, a widget that displays error |
| - // message will be created and adds as a child of the virtual keyboard |
| - // window. We want to avoid add BoundsChangedObserver to that window. |
| - if (GetFrameWindow(window) != keyboard_window && |
| + // message will be created and added as a child of the virtual |
| + // keyboard window. |
|
pkotwicz
2014/11/12 06:01:14
Kevin do you have any suggestions for comments her
|
| + if (!keyboard_window->Contains(window) && |
| window->GetRootWindow() == root_window) { |
| gfx::Rect window_bounds = window->GetBoundsInScreen(); |
| gfx::Rect intersect = gfx::IntersectRects(window_bounds, |
| @@ -330,10 +314,11 @@ void KeyboardController::NotifyKeyboardBoundsChanging( |
| view->SetInsets(gfx::Insets(0, 0, overlap, 0)); |
| else |
| view->SetInsets(gfx::Insets()); |
| - AddBoundsChangedObserver(window); |
| } |
| } |
| } |
| + root_window_bounds_observer_.reset( |
| + new WindowBoundsChangeObserver(root_window)); |
| } else { |
| ResetWindowInsets(); |
| } |
| @@ -557,7 +542,7 @@ void KeyboardController::ResetWindowInsets() { |
| if (view) |
| view->SetInsets(insets); |
| } |
| - window_bounds_observer_->RemoveAllObservedWindows(); |
| + root_window_bounds_observer_.reset(); |
| } |
| bool KeyboardController::WillHideKeyboard() const { |
| @@ -575,10 +560,4 @@ void KeyboardController::HideAnimationFinished() { |
| proxy_->HideKeyboardContainer(container_.get()); |
| } |
| -void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { |
| - aura::Window* target_window = GetFrameWindow(window); |
| - if (target_window) |
| - window_bounds_observer_->AddObservedWindow(target_window); |
| -} |
| - |
| } // namespace keyboard |