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

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

Issue 487253003: Keep virtual keyboard visibility the same after enable an IME in a different extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "content/public/browser/render_widget_host.h" 9 #include "content/public/browser/render_widget_host.h"
10 #include "content/public/browser/render_widget_host_iterator.h" 10 #include "content/public/browser/render_widget_host_iterator.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void CallbackAnimationObserver::OnLayerAnimationAborted( 199 void CallbackAnimationObserver::OnLayerAnimationAborted(
200 ui::LayerAnimationSequence* seq) { 200 ui::LayerAnimationSequence* seq) {
201 animator_->RemoveObserver(this); 201 animator_->RemoveObserver(this);
202 } 202 }
203 203
204 class WindowBoundsChangeObserver : public aura::WindowObserver { 204 class WindowBoundsChangeObserver : public aura::WindowObserver {
205 public: 205 public:
206 virtual void OnWindowBoundsChanged(aura::Window* window, 206 virtual void OnWindowBoundsChanged(aura::Window* window,
207 const gfx::Rect& old_bounds, 207 const gfx::Rect& old_bounds,
208 const gfx::Rect& new_bounds) OVERRIDE; 208 const gfx::Rect& new_bounds) OVERRIDE;
209 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
209 }; 210 };
210 211
211 void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window, 212 void WindowBoundsChangeObserver::OnWindowBoundsChanged(aura::Window* window,
212 const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { 213 const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) {
213 KeyboardController* controller = KeyboardController::GetInstance(); 214 KeyboardController* controller = KeyboardController::GetInstance();
214 if (controller) 215 if (controller)
215 controller->UpdateWindowInsets(window); 216 controller->UpdateWindowInsets(window);
216 } 217 }
217 218
219 void WindowBoundsChangeObserver::OnWindowDestroyed(aura::Window* window) {
220 if (window->HasObserver(this))
221 window->RemoveObserver(this);
222 }
223
218 // static 224 // static
219 KeyboardController* KeyboardController::instance_ = NULL; 225 KeyboardController* KeyboardController::instance_ = NULL;
220 226
221 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) 227 KeyboardController::KeyboardController(KeyboardControllerProxy* proxy)
222 : proxy_(proxy), 228 : proxy_(proxy),
223 input_method_(NULL), 229 input_method_(NULL),
224 keyboard_visible_(false), 230 keyboard_visible_(false),
225 lock_keyboard_(false), 231 lock_keyboard_(false),
226 type_(ui::TEXT_INPUT_TYPE_NONE), 232 type_(ui::TEXT_INPUT_TYPE_NONE),
227 weak_factory_(this) { 233 weak_factory_(this) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 scoped_ptr<content::RenderWidgetHostIterator> widgets( 287 scoped_ptr<content::RenderWidgetHostIterator> widgets(
282 content::RenderWidgetHost::GetRenderWidgetHosts()); 288 content::RenderWidgetHost::GetRenderWidgetHosts());
283 aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); 289 aura::Window *keyboard_window = proxy_->GetKeyboardWindow();
284 aura::Window *root_window = keyboard_window->GetRootWindow(); 290 aura::Window *root_window = keyboard_window->GetRootWindow();
285 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { 291 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
286 content::RenderWidgetHostView* view = widget->GetView(); 292 content::RenderWidgetHostView* view = widget->GetView();
287 // Can be NULL, e.g. if the RenderWidget is being destroyed or 293 // Can be NULL, e.g. if the RenderWidget is being destroyed or
288 // the render process crashed. 294 // the render process crashed.
289 if (view) { 295 if (view) {
290 aura::Window *window = view->GetNativeView(); 296 aura::Window *window = view->GetNativeView();
291 if (window != keyboard_window && 297 if (window->GetRootWindow() == root_window) {
kevers 2014/08/20 14:02:29 Not clear to me why we need a bounds changed obser
bshe 2014/08/20 14:59:59 Sorry. It shouldn't be removed. I thought I could
292 window->GetRootWindow() == root_window) {
293 gfx::Rect window_bounds = window->GetBoundsInScreen(); 298 gfx::Rect window_bounds = window->GetBoundsInScreen();
294 gfx::Rect intersect = gfx::IntersectRects(window_bounds, 299 gfx::Rect intersect = gfx::IntersectRects(window_bounds,
295 new_bounds); 300 new_bounds);
296 int overlap = intersect.height(); 301 int overlap = intersect.height();
297 if (overlap > 0 && overlap < window_bounds.height()) 302 if (overlap > 0 && overlap < window_bounds.height())
298 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); 303 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
299 else 304 else
300 view->SetInsets(gfx::Insets()); 305 view->SetInsets(gfx::Insets());
301 AddBoundsChangedObserver(window); 306 AddBoundsChangedObserver(window);
302 } 307 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 ShowKeyboardInternal(); 356 ShowKeyboardInternal();
352 } 357 }
353 358
354 void KeyboardController::OnWindowHierarchyChanged( 359 void KeyboardController::OnWindowHierarchyChanged(
355 const HierarchyChangeParams& params) { 360 const HierarchyChangeParams& params) {
356 if (params.new_parent && params.target == container_.get()) 361 if (params.new_parent && params.target == container_.get())
357 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); 362 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient());
358 } 363 }
359 364
360 void KeyboardController::Reload() { 365 void KeyboardController::Reload() {
361 if (proxy_->HasKeyboardWindow()) 366 if (proxy_->HasKeyboardWindow()) {
367 // A reload should never try to show virtual keyboard. If keyboard is not
368 // visible before reload, it should keep invisible after reload.
369 wait_for_resize_to_show_ = false;
362 proxy_->ReloadKeyboardIfNeeded(); 370 proxy_->ReloadKeyboardIfNeeded();
371 }
363 } 372 }
364 373
365 void KeyboardController::OnTextInputStateChanged( 374 void KeyboardController::OnTextInputStateChanged(
366 const ui::TextInputClient* client) { 375 const ui::TextInputClient* client) {
367 if (!container_.get()) 376 if (!container_.get())
368 return; 377 return;
369 378
370 if (IsKeyboardUsabilityExperimentEnabled()) { 379 if (IsKeyboardUsabilityExperimentEnabled()) {
371 ShowKeyboardInternal(); 380 ShowKeyboardInternal();
372 return; 381 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (container_->children().empty()) { 453 if (container_->children().empty()) {
445 keyboard::MarkKeyboardLoadStarted(); 454 keyboard::MarkKeyboardLoadStarted();
446 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 455 aura::Window* keyboard = proxy_->GetKeyboardWindow();
447 keyboard->Show(); 456 keyboard->Show();
448 container_->AddChild(keyboard); 457 container_->AddChild(keyboard);
449 keyboard->set_owned_by_parent(false); 458 keyboard->set_owned_by_parent(false);
450 } 459 }
451 460
452 proxy_->ReloadKeyboardIfNeeded(); 461 proxy_->ReloadKeyboardIfNeeded();
453 462
454 if (keyboard_visible_ || proxy_->GetKeyboardWindow()->bounds().height() == 0) 463 if (keyboard_visible_) {
455 return; 464 return;
465 } else if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
466 wait_for_resize_to_show_ = true;
467 return;
468 }
456 469
457 keyboard_visible_ = true; 470 keyboard_visible_ = true;
458 471
459 // If the controller is in the process of hiding the keyboard, do not log 472 // If the controller is in the process of hiding the keyboard, do not log
460 // the stat here since the keyboard will not actually be shown. 473 // the stat here since the keyboard will not actually be shown.
461 if (!WillHideKeyboard()) 474 if (!WillHideKeyboard())
462 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); 475 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
463 476
464 weak_factory_.InvalidateWeakPtrs(); 477 weak_factory_.InvalidateWeakPtrs();
465 478
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); 544 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds());
532 proxy_->EnsureCaretInWorkArea(); 545 proxy_->EnsureCaretInWorkArea();
533 } 546 }
534 547
535 void KeyboardController::HideAnimationFinished() { 548 void KeyboardController::HideAnimationFinished() {
536 proxy_->HideKeyboardContainer(container_.get()); 549 proxy_->HideKeyboardContainer(container_.get());
537 } 550 }
538 551
539 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { 552 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
540 aura::Window* target_window = GetFrameWindow(window); 553 aura::Window* target_window = GetFrameWindow(window);
541 if (target_window && 554 if (target_window && target_window != proxy_->GetKeyboardWindow() &&
542 !target_window->HasObserver(window_bounds_observer_.get())) { 555 !target_window->HasObserver(window_bounds_observer_.get())) {
543 target_window->AddObserver(window_bounds_observer_.get()); 556 target_window->AddObserver(window_bounds_observer_.get());
544 } 557 }
545 } 558 }
546 559
547 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) { 560 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) {
548 aura::Window* target_window = GetFrameWindow(window); 561 aura::Window* target_window = GetFrameWindow(window);
549 if (target_window && 562 if (target_window &&
550 target_window->HasObserver(window_bounds_observer_.get())) { 563 target_window->HasObserver(window_bounds_observer_.get())) {
551 target_window->RemoveObserver(window_bounds_observer_.get()); 564 target_window->RemoveObserver(window_bounds_observer_.get());
552 } 565 }
553 } 566 }
554 567
555 } // namespace keyboard 568 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698