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

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: reviews 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();
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.
291 if (window != keyboard_window && 300 if (window != keyboard_window &&
301 GetFrameWindow(window) != keyboard_window &&
kevers 2014/08/20 15:16:04 Think you only need second check.
bshe 2014/08/20 15:29:23 Done.
292 window->GetRootWindow() == root_window) { 302 window->GetRootWindow() == root_window) {
293 gfx::Rect window_bounds = window->GetBoundsInScreen(); 303 gfx::Rect window_bounds = window->GetBoundsInScreen();
294 gfx::Rect intersect = gfx::IntersectRects(window_bounds, 304 gfx::Rect intersect = gfx::IntersectRects(window_bounds,
295 new_bounds); 305 new_bounds);
296 int overlap = intersect.height(); 306 int overlap = intersect.height();
297 if (overlap > 0 && overlap < window_bounds.height()) 307 if (overlap > 0 && overlap < window_bounds.height())
298 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); 308 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
299 else 309 else
300 view->SetInsets(gfx::Insets()); 310 view->SetInsets(gfx::Insets());
301 AddBoundsChangedObserver(window); 311 AddBoundsChangedObserver(window);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 ShowKeyboardInternal(); 361 ShowKeyboardInternal();
352 } 362 }
353 363
354 void KeyboardController::OnWindowHierarchyChanged( 364 void KeyboardController::OnWindowHierarchyChanged(
355 const HierarchyChangeParams& params) { 365 const HierarchyChangeParams& params) {
356 if (params.new_parent && params.target == container_.get()) 366 if (params.new_parent && params.target == container_.get())
357 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); 367 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient());
358 } 368 }
359 369
360 void KeyboardController::Reload() { 370 void KeyboardController::Reload() {
361 if (proxy_->HasKeyboardWindow()) 371 if (proxy_->HasKeyboardWindow()) {
372 // A reload should never try to show virtual keyboard. If keyboard is not
373 // visible before reload, it should keep invisible after reload.
374 show_on_resize_ = false;
362 proxy_->ReloadKeyboardIfNeeded(); 375 proxy_->ReloadKeyboardIfNeeded();
376 }
363 } 377 }
364 378
365 void KeyboardController::OnTextInputStateChanged( 379 void KeyboardController::OnTextInputStateChanged(
366 const ui::TextInputClient* client) { 380 const ui::TextInputClient* client) {
367 if (!container_.get()) 381 if (!container_.get())
368 return; 382 return;
369 383
370 if (IsKeyboardUsabilityExperimentEnabled()) { 384 if (IsKeyboardUsabilityExperimentEnabled()) {
371 ShowKeyboardInternal(); 385 ShowKeyboardInternal();
372 return; 386 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (container_->children().empty()) { 458 if (container_->children().empty()) {
445 keyboard::MarkKeyboardLoadStarted(); 459 keyboard::MarkKeyboardLoadStarted();
446 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 460 aura::Window* keyboard = proxy_->GetKeyboardWindow();
447 keyboard->Show(); 461 keyboard->Show();
448 container_->AddChild(keyboard); 462 container_->AddChild(keyboard);
449 keyboard->set_owned_by_parent(false); 463 keyboard->set_owned_by_parent(false);
450 } 464 }
451 465
452 proxy_->ReloadKeyboardIfNeeded(); 466 proxy_->ReloadKeyboardIfNeeded();
453 467
454 if (keyboard_visible_ || proxy_->GetKeyboardWindow()->bounds().height() == 0) 468 if (keyboard_visible_) {
455 return; 469 return;
470 } else if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
471 show_on_resize_ = true;
472 return;
473 }
456 474
457 keyboard_visible_ = true; 475 keyboard_visible_ = true;
458 476
459 // If the controller is in the process of hiding the keyboard, do not log 477 // 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. 478 // the stat here since the keyboard will not actually be shown.
461 if (!WillHideKeyboard()) 479 if (!WillHideKeyboard())
462 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); 480 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
463 481
464 weak_factory_.InvalidateWeakPtrs(); 482 weak_factory_.InvalidateWeakPtrs();
465 483
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 564
547 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) { 565 void KeyboardController::RemoveBoundsChangedObserver(aura::Window* window) {
548 aura::Window* target_window = GetFrameWindow(window); 566 aura::Window* target_window = GetFrameWindow(window);
549 if (target_window && 567 if (target_window &&
550 target_window->HasObserver(window_bounds_observer_.get())) { 568 target_window->HasObserver(window_bounds_observer_.get())) {
551 target_window->RemoveObserver(window_bounds_observer_.get()); 569 target_window->RemoveObserver(window_bounds_observer_.get());
552 } 570 }
553 } 571 }
554 572
555 } // namespace keyboard 573 } // 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