diff options
author | bshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-04 21:38:45 +0000 |
---|---|---|
committer | bshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-04 21:38:45 +0000 |
commit | b6ba05d90aaa93a4e707bdec67ba2c043a3a533f (patch) | |
tree | 94f5cecc6e48a262db4049514e610ab34a63538d /ui/keyboard | |
parent | 88645e15d7743209f5babd5574e4e30f31f277a4 (diff) | |
download | chromium_src-b6ba05d90aaa93a4e707bdec67ba2c043a3a533f.zip chromium_src-b6ba05d90aaa93a4e707bdec67ba2c043a3a533f.tar.gz chromium_src-b6ba05d90aaa93a4e707bdec67ba2c043a3a533f.tar.bz2 |
Only show virtual keyboard on primary root window
In order to display virtual keyboard(VK) only on primary root window,
this CL did
1. Shell takes ownership of keyboard controller(KC) instead of
RootWindowController
2. keyboard container window is owned by KC instead of its parent
There should only be one KC and one keyboard container at any time after
this change. keyboard container can be dynamically enabled/disabled on a
RootWindowController at runtime. If you want to do that,
you should DisableKeyboard on the previous RootWindowController first and
then EnableKeyboard on the new RootWindowController.
BUG=297858
TEST=
1. enable virtual keyboard from about::/flags on a Chromebook
2. plug in an external monitor
verify only one virtual keyboard shows
Review URL: https://codereview.chromium.org/25111002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227088 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/keyboard')
-rw-r--r-- | ui/keyboard/keyboard_controller.cc | 27 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller.h | 7 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_unittest.cc | 14 |
3 files changed, 20 insertions, 28 deletions
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc index 83e7f32..bcf6e13 100644 --- a/ui/keyboard/keyboard_controller.cc +++ b/ui/keyboard/keyboard_controller.cc @@ -122,7 +122,6 @@ class KeyboardLayoutManager : public aura::LayoutManager { KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) : proxy_(proxy), - container_(NULL), input_method_(NULL), keyboard_visible_(false), weak_factory_(this) { @@ -132,21 +131,22 @@ KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) } KeyboardController::~KeyboardController() { - if (container_) + if (container_.get()) container_->RemoveObserver(this); if (input_method_) input_method_->RemoveObserver(this); } aura::Window* KeyboardController::GetContainerWindow() { - if (!container_) { - container_ = new aura::Window(new KeyboardWindowDelegate()); + if (!container_.get()) { + container_.reset(new aura::Window(new KeyboardWindowDelegate())); container_->SetName("KeyboardContainer"); + container_->set_owned_by_parent(false); container_->Init(ui::LAYER_NOT_DRAWN); container_->AddObserver(this); - container_->SetLayoutManager(new KeyboardLayoutManager(container_)); + container_->SetLayoutManager(new KeyboardLayoutManager(container_.get())); } - return container_; + return container_.get(); } void KeyboardController::HideKeyboard() { @@ -156,7 +156,7 @@ void KeyboardController::HideKeyboard() { observer_list_, OnKeyboardBoundsChanging(gfx::Rect())); - proxy_->HideKeyboardContainer(container_); + proxy_->HideKeyboardContainer(container_.get()); } void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { @@ -169,18 +169,13 @@ void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { void KeyboardController::OnWindowHierarchyChanged( const HierarchyChangeParams& params) { - if (params.new_parent && params.target == container_) + if (params.new_parent && params.target == container_.get()) OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); } -void KeyboardController::OnWindowDestroying(aura::Window* window) { - DCHECK_EQ(container_, window); - container_ = NULL; -} - void KeyboardController::OnTextInputStateChanged( const ui::TextInputClient* client) { - if (!container_) + if (!container_.get()) return; bool was_showing = keyboard_visible_; @@ -197,7 +192,7 @@ void KeyboardController::OnTextInputStateChanged( container_->layout_manager()->OnWindowResized(); } proxy_->SetUpdateInputType(type); - container_->parent()->StackChildAtTop(container_); + container_->parent()->StackChildAtTop(container_.get()); should_show = true; } @@ -212,7 +207,7 @@ void KeyboardController::OnTextInputStateChanged( KeyboardControllerObserver, observer_list_, OnKeyboardBoundsChanging(container_->children()[0]->bounds())); - proxy_->ShowKeyboardContainer(container_); + proxy_->ShowKeyboardContainer(container_.get()); } else { // Set the visibility state here so that any queries for visibility // before the timer fires returns the correct future value. diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h index e9e5890..dd044dc 100644 --- a/ui/keyboard/keyboard_controller.h +++ b/ui/keyboard/keyboard_controller.h @@ -39,8 +39,8 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, explicit KeyboardController(KeyboardControllerProxy* proxy); virtual ~KeyboardController(); - // Returns the container for the keyboard, which is then owned by the caller. - // It is the responsibility of the caller to Show() the returned window. + // Returns the container for the keyboard, which is owned by + // KeyboardController. aura::Window* GetContainerWindow(); // Hides virtual keyboard and notifies observer bounds change. @@ -59,7 +59,6 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, // aura::WindowObserver overrides virtual void OnWindowHierarchyChanged( const HierarchyChangeParams& params) OVERRIDE; - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; // InputMethodObserver overrides virtual void OnTextInputTypeChanged( @@ -80,7 +79,7 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, bool WillHideKeyboard() const; scoped_ptr<KeyboardControllerProxy> proxy_; - aura::Window* container_; + scoped_ptr<aura::Window> container_; ui::InputMethod* input_method_; bool keyboard_visible_; base::WeakPtrFactory<KeyboardController> weak_factory_; diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc index 1d46116..3650520 100644 --- a/ui/keyboard/keyboard_controller_unittest.cc +++ b/ui/keyboard/keyboard_controller_unittest.cc @@ -227,7 +227,7 @@ class KeyboardControllerTest : public testing::Test { }; TEST_F(KeyboardControllerTest, KeyboardSize) { - scoped_ptr<aura::Window> container(controller()->GetContainerWindow()); + aura::Window* container(controller()->GetContainerWindow()); gfx::Rect bounds(0, 0, 100, 100); container->SetBounds(bounds); @@ -252,11 +252,10 @@ TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { window->Show(); window->Focus(); - scoped_ptr<aura::Window> keyboard_container( - controller()->GetContainerWindow()); + aura::Window* keyboard_container(controller()->GetContainerWindow()); keyboard_container->SetBounds(root_bounds); - root_window()->AddChild(keyboard_container.get()); + root_window()->AddChild(keyboard_container); keyboard_container->Show(); ShowKeyboard(); @@ -297,12 +296,11 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { TestTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); input_method->SetFocusedTextInputClient(&input_client_0); - scoped_ptr<aura::Window> keyboard_container( - controller()->GetContainerWindow()); + aura::Window* keyboard_container(controller()->GetContainerWindow()); scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( - new KeyboardContainerObserver(keyboard_container.get())); + new KeyboardContainerObserver(keyboard_container)); keyboard_container->SetBounds(root_bounds); - root_window()->AddChild(keyboard_container.get()); + root_window()->AddChild(keyboard_container); EXPECT_TRUE(keyboard_container->IsVisible()); |