diff options
author | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 13:39:24 +0000 |
---|---|---|
committer | bryeung@chromium.org <bryeung@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 13:39:24 +0000 |
commit | 86459e2cef0d83b80c5efb0c932463e4dd3735ee (patch) | |
tree | d732b15a281a43554d83f753f25689411b5c47f7 /ui | |
parent | 4f629d42cc381f446f8d0544287db23d4f1d8d62 (diff) | |
download | chromium_src-86459e2cef0d83b80c5efb0c932463e4dd3735ee.zip chromium_src-86459e2cef0d83b80c5efb0c932463e4dd3735ee.tar.gz chromium_src-86459e2cef0d83b80c5efb0c932463e4dd3735ee.tar.bz2 |
Create and show the virtual keyboard.
Introduces ui/keyboard/ which contains generic code for the control of the keyboard (right now, just creation of the container window).
Also includes the necessary changes to ash so that the keyboard is (always) displayed on ChromeOS builds when the --enable-virtual-keyboard flag is present.
BUG=226986
Review URL: https://codereview.chromium.org/13164002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/keyboard/keyboard.gyp | 53 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller.cc | 78 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller.h | 41 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.h | 29 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_unittest.cc | 74 | ||||
-rw-r--r-- | ui/keyboard/keyboard_export.h | 32 | ||||
-rw-r--r-- | ui/keyboard/keyboard_switches.cc | 13 | ||||
-rw-r--r-- | ui/keyboard/keyboard_switches.h | 19 | ||||
-rw-r--r-- | ui/keyboard/keyboard_util.cc | 17 | ||||
-rw-r--r-- | ui/keyboard/keyboard_util.h | 17 |
10 files changed, 373 insertions, 0 deletions
diff --git a/ui/keyboard/keyboard.gyp b/ui/keyboard/keyboard.gyp new file mode 100644 index 0000000..83bd374 --- /dev/null +++ b/ui/keyboard/keyboard.gyp @@ -0,0 +1,53 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets': [ + { + 'target_name': 'keyboard', + 'type': '<(component)', + 'dependencies': [ + '../../base/base.gyp:base', + '../../skia/skia.gyp:skia', + '../aura/aura.gyp:aura', + '../ui.gyp:ui', + ], + 'defines': [ + 'KEYBOARD_IMPLEMENTATION', + ], + 'sources': [ + 'keyboard_controller.cc', + 'keyboard_controller.h', + 'keyboard_controller_proxy.h', + 'keyboard_export.h', + 'keyboard_switches.cc', + 'keyboard_switches.h', + 'keyboard_util.cc', + 'keyboard_util.h', + ] + }, + { + 'target_name': 'keyboard_unittests', + 'type': 'executable', + 'dependencies': [ + '../../base/base.gyp:base', + '../../base/base.gyp:test_support_base', + '../../skia/skia.gyp:skia', + '../../testing/gtest.gyp:gtest', + '../aura/aura.gyp:aura', + '../aura/aura.gyp:aura_test_support', + '../compositor/compositor.gyp:compositor', + '../ui.gyp:run_ui_unittests', + '../ui.gyp:ui', + 'keyboard', + ], + 'sources': [ + 'keyboard_controller_unittest.cc', + ], + }, + ], +} diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc new file mode 100644 index 0000000..3e01d81 --- /dev/null +++ b/ui/keyboard/keyboard_controller.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/keyboard/keyboard_controller.h" + +#include "ui/aura/layout_manager.h" +#include "ui/aura/window.h" +#include "ui/gfx/rect.h" +#include "ui/keyboard/keyboard_controller_proxy.h" + +namespace { + +// LayoutManager for the virtual keyboard container. Manages a single window +// (the virtual keyboard) and keeps it positioned at the bottom of the +// container window. +class KeyboardLayoutManager : public aura::LayoutManager { + public: + KeyboardLayoutManager(aura::Window* owner, aura::Window* keyboard) + : owner_(owner), keyboard_(keyboard) {} + + // Overridden from aura::LayoutManager + virtual void OnWindowResized() OVERRIDE { + gfx::Rect owner_bounds = owner_->bounds(); + gfx::Rect keyboard_bounds = gfx::Rect( + owner_bounds.x(), + owner_bounds.y() + owner_bounds.height() * 0.7, + owner_bounds.width(), + owner_bounds.height() * 0.3); + SetChildBoundsDirect(keyboard_, keyboard_bounds); + } + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { + CHECK(child == keyboard_); + } + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} + virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) OVERRIDE {} + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE { + // Drop these: the size should only be set in OnWindowResized. + } + + private: + aura::Window* owner_; + aura::Window* keyboard_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardLayoutManager); +}; + +} // namespace + +namespace keyboard { + +KeyboardController::KeyboardController(KeyboardControllerProxy* proxy) + : proxy_(proxy), container_(NULL) { + CHECK(proxy); +} + +KeyboardController::~KeyboardController() {} + +aura::Window* KeyboardController::GetContainerWindow() { + if (!container_) { + container_ = new aura::Window(NULL); + container_->SetName("KeyboardContainer"); + container_->Init(ui::LAYER_NOT_DRAWN); + + aura::Window* keyboard = proxy_->GetKeyboardWindow(); + keyboard->Show(); + + container_->SetLayoutManager( + new KeyboardLayoutManager(container_, keyboard)); + container_->AddChild(keyboard); + } + return container_; +} + +} // namespace keyboard diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h new file mode 100644 index 0000000..408a71f --- /dev/null +++ b/ui/keyboard/keyboard_controller.h @@ -0,0 +1,41 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ +#define UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "ui/keyboard/keyboard_export.h" + +namespace aura { +class Window; +} + +namespace keyboard { + +class KeyboardControllerProxy; + +// Provides control of the virtual keyboard, including providing a container, +// managing object lifetimes and controlling visibility. +class KEYBOARD_EXPORT KeyboardController { + public: + // Takes ownership of |proxy|. + 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. + aura::Window* GetContainerWindow(); + + private: + scoped_ptr<KeyboardControllerProxy> proxy_; + aura::Window* container_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardController); +}; + +} // namespace keyboard + +#endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h new file mode 100644 index 0000000..e1783a4d --- /dev/null +++ b/ui/keyboard/keyboard_controller_proxy.h @@ -0,0 +1,29 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ +#define UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ + +#include "ui/keyboard/keyboard_export.h" + +namespace aura { +class Window; +} + +namespace keyboard { + +// A proxy used by the KeyboardController to get access to the virtual +// keyboard window. +class KEYBOARD_EXPORT KeyboardControllerProxy { + public: + virtual ~KeyboardControllerProxy() {} + + // Get the virtual keyboard window. Ownership of the returned Window remains + // with the proxy. + virtual aura::Window* GetKeyboardWindow() = 0; +}; + +} // namespace keyboard + +#endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc new file mode 100644 index 0000000..3da30d2 --- /dev/null +++ b/ui/keyboard/keyboard_controller_unittest.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/aura/test/aura_test_helper.h" +#include "ui/aura/window.h" +#include "ui/compositor/layer_type.h" +#include "ui/gfx/rect.h" +#include "ui/keyboard/keyboard_controller.h" +#include "ui/keyboard/keyboard_controller_proxy.h" + +namespace keyboard { +namespace { + +class KeyboardControllerTest : public testing::Test { + public: + KeyboardControllerTest() {} + virtual ~KeyboardControllerTest() {} + + virtual void SetUp() OVERRIDE { + aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); + aura_test_helper_->SetUp(); + } + + virtual void TearDown() OVERRIDE { + aura_test_helper_->TearDown(); + } + + protected: + base::MessageLoopForUI message_loop_; + scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; + + private: + DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); +}; + +class TestKeyboardControllerProxy : public KeyboardControllerProxy { + public: + TestKeyboardControllerProxy() : window_(new aura::Window(NULL)) { + window_->Init(ui::LAYER_NOT_DRAWN); + window_->set_owned_by_parent(false); + } + virtual ~TestKeyboardControllerProxy() {} + virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); } + + private: + scoped_ptr<aura::Window> window_; + DISALLOW_COPY_AND_ASSIGN(TestKeyboardControllerProxy); +}; + +} // namespace + +TEST_F(KeyboardControllerTest, KeyboardSize) { + KeyboardControllerProxy* proxy = new TestKeyboardControllerProxy(); + KeyboardController controller(proxy); + + scoped_ptr<aura::Window> container(controller.GetContainerWindow()); + gfx::Rect bounds(0, 0, 100, 100); + container->SetBounds(bounds); + + const gfx::Rect& before_bounds = proxy->GetKeyboardWindow()->bounds(); + gfx::Rect new_bounds( + before_bounds.x(), before_bounds.y(), + before_bounds.width() / 2, before_bounds.height() / 2); + + // The KeyboardController's LayoutManager shouldn't let this happen + proxy->GetKeyboardWindow()->SetBounds(new_bounds); + ASSERT_EQ(before_bounds, proxy->GetKeyboardWindow()->bounds()); +} + +} // namespace keyboard diff --git a/ui/keyboard/keyboard_export.h b/ui/keyboard/keyboard_export.h new file mode 100644 index 0000000..2cb9861 --- /dev/null +++ b/ui/keyboard/keyboard_export.h @@ -0,0 +1,32 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_EXPORT_H_ +#define UI_KEYBOARD_KEYBOARD_EXPORT_H_ + +// Defines KEYBOARD_EXPORT so that functionality implemented by the +// keyboard module can be exported to consumers. + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(KEYBOARD_IMPLEMENTATION) +#define KEYBOARD_EXPORT __declspec(dllexport) +#else +#define KEYBOARD_EXPORT __declspec(dllimport) +#endif // defined(KEYBOARD_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(KEYBOARD_IMPLEMENTATION) +#define KEYBOARD_EXPORT __attribute__((visibility("default"))) +#else +#define KEYBOARD_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define KEYBOARD_EXPORT +#endif + +#endif // UI_KEYBOARD_KEYBOARD_EXPORT_H_ diff --git a/ui/keyboard/keyboard_switches.cc b/ui/keyboard/keyboard_switches.cc new file mode 100644 index 0000000..d1ea4e2 --- /dev/null +++ b/ui/keyboard/keyboard_switches.cc @@ -0,0 +1,13 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/keyboard/keyboard_switches.h" + +namespace keyboard { +namespace switches { + +const char kEnableVirtualKeyboard[] = "enable-virtual-keyboard"; + +} // namespace switches +} // namespace keyboard diff --git a/ui/keyboard/keyboard_switches.h b/ui/keyboard/keyboard_switches.h new file mode 100644 index 0000000..a7d0533 --- /dev/null +++ b/ui/keyboard/keyboard_switches.h @@ -0,0 +1,19 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_SWITCHES_H_ +#define UI_KEYBOARD_KEYBOARD_SWITCHES_H_ + +#include "ui/keyboard/keyboard_export.h" + +namespace keyboard { +namespace switches { + +// Enables the virtual keyboard. +KEYBOARD_EXPORT extern const char kEnableVirtualKeyboard[]; + +} // namespace switches +} // namespace keyboard + +#endif // UI_KEYBOARD_KEYBOARD_SWITCHES_H_ diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc new file mode 100644 index 0000000..8ccb441 --- /dev/null +++ b/ui/keyboard/keyboard_util.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/keyboard/keyboard_util.h" + +#include "base/command_line.h" +#include "ui/keyboard/keyboard_switches.h" + +namespace keyboard { + +bool IsKeyboardEnabled() { + return CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableVirtualKeyboard); +} + +} // namespace keyboard diff --git a/ui/keyboard/keyboard_util.h b/ui/keyboard/keyboard_util.h new file mode 100644 index 0000000..84510bf --- /dev/null +++ b/ui/keyboard/keyboard_util.h @@ -0,0 +1,17 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_UTIL_H_ +#define UI_KEYBOARD_KEYBOARD_UTIL_H_ + +#include "ui/keyboard/keyboard_export.h" + +namespace keyboard { + +// Returns true if the virtual keyboard is enabled. +KEYBOARD_EXPORT bool IsKeyboardEnabled(); + +} // namespace keyboard + +#endif // UI_KEYBOARD_KEYBOARD_UTIL_H_ |