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

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: nit and rebase 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
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | ui/keyboard/keyboard_layout_manager.cc » ('j') | 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 "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 virtual keyboard failed to load, a widget that displays error
298 // message will be created and adds as a child of the virtual keyboard
299 // window. We want to avoid add BoundsChangedObserver to that window.
300 if (GetFrameWindow(window) != keyboard_window &&
292 window->GetRootWindow() == root_window) { 301 window->GetRootWindow() == root_window) {
293 gfx::Rect window_bounds = window->GetBoundsInScreen(); 302 gfx::Rect window_bounds = window->GetBoundsInScreen();
294 gfx::Rect intersect = gfx::IntersectRects(window_bounds, 303 gfx::Rect intersect = gfx::IntersectRects(window_bounds,
295 new_bounds); 304 new_bounds);
296 int overlap = intersect.height(); 305 int overlap = intersect.height();
297 if (overlap > 0 && overlap < window_bounds.height()) 306 if (overlap > 0 && overlap < window_bounds.height())
298 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); 307 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
299 else 308 else
300 view->SetInsets(gfx::Insets()); 309 view->SetInsets(gfx::Insets());
301 AddBoundsChangedObserver(window); 310 AddBoundsChangedObserver(window);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 ShowKeyboardInternal(); 362 ShowKeyboardInternal();
354 } 363 }
355 364
356 void KeyboardController::OnWindowHierarchyChanged( 365 void KeyboardController::OnWindowHierarchyChanged(
357 const HierarchyChangeParams& params) { 366 const HierarchyChangeParams& params) {
358 if (params.new_parent && params.target == container_.get()) 367 if (params.new_parent && params.target == container_.get())
359 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); 368 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient());
360 } 369 }
361 370
362 void KeyboardController::Reload() { 371 void KeyboardController::Reload() {
363 if (proxy_->HasKeyboardWindow()) 372 if (proxy_->HasKeyboardWindow()) {
373 // A reload should never try to show virtual keyboard. If keyboard is not
374 // visible before reload, it should keep invisible after reload.
375 show_on_resize_ = false;
364 proxy_->ReloadKeyboardIfNeeded(); 376 proxy_->ReloadKeyboardIfNeeded();
377 }
365 } 378 }
366 379
367 void KeyboardController::OnTextInputStateChanged( 380 void KeyboardController::OnTextInputStateChanged(
368 const ui::TextInputClient* client) { 381 const ui::TextInputClient* client) {
369 if (!container_.get()) 382 if (!container_.get())
370 return; 383 return;
371 384
372 if (IsKeyboardUsabilityExperimentEnabled()) { 385 if (IsKeyboardUsabilityExperimentEnabled()) {
373 ShowKeyboardInternal(); 386 ShowKeyboardInternal();
374 return; 387 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (container_->children().empty()) { 459 if (container_->children().empty()) {
447 keyboard::MarkKeyboardLoadStarted(); 460 keyboard::MarkKeyboardLoadStarted();
448 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 461 aura::Window* keyboard = proxy_->GetKeyboardWindow();
449 keyboard->Show(); 462 keyboard->Show();
450 container_->AddChild(keyboard); 463 container_->AddChild(keyboard);
451 keyboard->set_owned_by_parent(false); 464 keyboard->set_owned_by_parent(false);
452 } 465 }
453 466
454 proxy_->ReloadKeyboardIfNeeded(); 467 proxy_->ReloadKeyboardIfNeeded();
455 468
456 if (keyboard_visible_ || proxy_->GetKeyboardWindow()->bounds().height() == 0) 469 if (keyboard_visible_) {
457 return; 470 return;
471 } else if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
472 show_on_resize_ = true;
473 return;
474 }
458 475
459 keyboard_visible_ = true; 476 keyboard_visible_ = true;
460 477
461 // If the controller is in the process of hiding the keyboard, do not log 478 // If the controller is in the process of hiding the keyboard, do not log
462 // the stat here since the keyboard will not actually be shown. 479 // the stat here since the keyboard will not actually be shown.
463 if (!WillHideKeyboard()) 480 if (!WillHideKeyboard())
464 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); 481 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
465 482
466 weak_factory_.InvalidateWeakPtrs(); 483 weak_factory_.InvalidateWeakPtrs();
467 484
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 565
549 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) { 566 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) {
550 aura::Window* target_window = GetFrameWindow(window); 567 aura::Window* target_window = GetFrameWindow(window);
551 if (target_window && 568 if (target_window &&
552 target_window->HasObserver(window_bounds_observer_.get())) { 569 target_window->HasObserver(window_bounds_observer_.get())) {
553 target_window->RemoveObserver(window_bounds_observer_.get()); 570 target_window->RemoveObserver(window_bounds_observer_.get());
554 } 571 }
555 } 572 }
556 573
557 } // namespace keyboard 574 } // namespace keyboard
OLDNEW
« no previous file with comments | « ui/keyboard/keyboard_controller.h ('k') | ui/keyboard/keyboard_layout_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698