Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: ui/keyboard/keyboard_controller.cc

Issue 527153002: Fix the issue that GetFrameWindow() may change between AddObserver and RemoveObserver in KeyboardCo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised per comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
230 observed_windows_.erase(window);
231 }
232
233 void WindowBoundsChangeObserver::AddObservedWindow(aura::Window* window) {
234 if (!window->HasObserver(this)) {
235 window->AddObserver(this);
236 observed_windows_.insert(window);
237 }
238 }
239
240 void WindowBoundsChangeObserver::RemoveAllObservedWindows() {
241 for (std::set<aura::Window*>::iterator it = observed_windows_.begin();
242 it != observed_windows_.end(); ++it)
243 (*it)->RemoveObserver(this);
244 observed_windows_.clear();
222 } 245 }
223 246
224 // static 247 // static
225 KeyboardController* KeyboardController::instance_ = NULL; 248 KeyboardController* KeyboardController::instance_ = NULL;
226 249
227 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) 250 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy)
228 : proxy_(proxy), 251 : proxy_(proxy),
229 input_method_(NULL), 252 input_method_(NULL),
230 keyboard_visible_(false), 253 keyboard_visible_(false),
231 show_on_resize_(false), 254 show_on_resize_(false),
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 container_->layer()->SetOpacity(1.0); 549 container_->layer()->SetOpacity(1.0);
527 } 550 }
528 } 551 }
529 552
530 void KeyboardController::ResetWindowInsets() { 553 void KeyboardController::ResetWindowInsets() {
531 const gfx::Insets insets; 554 const gfx::Insets insets;
532 scoped_ptr<content::RenderWidgetHostIterator> widgets( 555 scoped_ptr<content::RenderWidgetHostIterator> widgets(
533 content::RenderWidgetHost::GetRenderWidgetHosts()); 556 content::RenderWidgetHost::GetRenderWidgetHosts());
534 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { 557 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
535 content::RenderWidgetHostView* view = widget->GetView(); 558 content::RenderWidgetHostView* view = widget->GetView();
536 if (view) { 559 if (view)
537 view->SetInsets(insets); 560 view->SetInsets(insets);
538 aura::Window *window = view->GetNativeView();
539 RemoveBoundsChangedObserver(window);
540 }
541 } 561 }
562 window_bounds_observer_->RemoveAllObservedWindows();
542 } 563 }
543 564
544 bool KeyboardController::WillHideKeyboard() const { 565 bool KeyboardController::WillHideKeyboard() const {
545 return weak_factory_.HasWeakPtrs(); 566 return weak_factory_.HasWeakPtrs();
546 } 567 }
547 568
548 void KeyboardController::ShowAnimationFinished() { 569 void KeyboardController::ShowAnimationFinished() {
549 // Notify observers after animation finished to prevent reveal desktop 570 // Notify observers after animation finished to prevent reveal desktop
550 // background during animation. 571 // background during animation.
551 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); 572 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds());
552 proxy_->EnsureCaretInWorkArea(); 573 proxy_->EnsureCaretInWorkArea();
553 } 574 }
554 575
555 void KeyboardController::HideAnimationFinished() { 576 void KeyboardController::HideAnimationFinished() {
556 proxy_->HideKeyboardContainer(container_.get()); 577 proxy_->HideKeyboardContainer(container_.get());
557 } 578 }
558 579
559 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { 580 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
560 aura::Window* target_window = GetFrameWindow(window); 581 aura::Window* target_window = GetFrameWindow(window);
561 if (target_window && 582 if (target_window)
562 !target_window->HasObserver(window_bounds_observer_.get())) { 583 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 } 584 }
574 585
575 } // namespace keyboard 586 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698