diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 01:26:49 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-16 01:26:49 +0000 |
commit | 8b2db132ea44487e7c480e18377fad63b61484d3 (patch) | |
tree | 57c3aea58932c9b2877fd9f67f47c46aa0a8f465 /ui | |
parent | 7fd098a6ab5903a93b080c15f094dcbbe20294cc (diff) | |
download | chromium_src-8b2db132ea44487e7c480e18377fad63b61484d3.zip chromium_src-8b2db132ea44487e7c480e18377fad63b61484d3.tar.gz chromium_src-8b2db132ea44487e7c480e18377fad63b61484d3.tar.bz2 |
keyboard: Install a masked window-targeter in the keyboard container.
Install a masked window-targeter in the keyboard container so that event
targetting works correctly when used with EventProcessor for dispatching
events.
BUG=318879
R=ben@chromium.org
Review URL: https://codereview.chromium.org/139613003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245048 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/keyboard/DEPS | 1 | ||||
-rw-r--r-- | ui/keyboard/keyboard.gyp | 1 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller.cc | 28 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_unittest.cc | 39 | ||||
-rw-r--r-- | ui/wm/public/masked_window_targeter.h | 1 |
5 files changed, 70 insertions, 0 deletions
diff --git a/ui/keyboard/DEPS b/ui/keyboard/DEPS index 69c820c..defb61d 100644 --- a/ui/keyboard/DEPS +++ b/ui/keyboard/DEPS @@ -7,4 +7,5 @@ include_rules = [ "+ui/compositor", "+ui/gfx", "+ui/test", + "+ui/wm", ] diff --git a/ui/keyboard/keyboard.gyp b/ui/keyboard/keyboard.gyp index fe19bd7..a9f41f9 100644 --- a/ui/keyboard/keyboard.gyp +++ b/ui/keyboard/keyboard.gyp @@ -48,6 +48,7 @@ '../gfx/gfx.gyp:gfx', '../gfx/gfx.gyp:gfx_geometry', '../ui.gyp:ui', + '../wm/wm.gyp:wm_public', 'keyboard_resources', ], 'defines': [ diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc index 6648a78..042c786 100644 --- a/ui/keyboard/keyboard_controller.cc +++ b/ui/keyboard/keyboard_controller.cc @@ -21,6 +21,7 @@ #include "ui/keyboard/keyboard_controller_proxy.h" #include "ui/keyboard/keyboard_switches.h" #include "ui/keyboard/keyboard_util.h" +#include "ui/wm/public/masked_window_targeter.h" namespace { @@ -36,6 +37,31 @@ gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds) { window_bounds.height() * kKeyboardHeightRatio); } +// Event targeter for the keyboard container. +class KeyboardContainerTargeter : public wm::MaskedWindowTargeter { + public: + KeyboardContainerTargeter(aura::Window* container, + keyboard::KeyboardControllerProxy* proxy) + : wm::MaskedWindowTargeter(container), + proxy_(proxy) { + } + + virtual ~KeyboardContainerTargeter() {} + + private: + // wm::MaskedWindowTargeter: + virtual void GetHitTestMask(aura::Window* window, + gfx::Path* mask) const OVERRIDE { + gfx::Rect keyboard_bounds = proxy_ ? proxy_->GetKeyboardWindow()->bounds() : + KeyboardBoundsFromWindowBounds(window->bounds()); + mask->addRect(RectToSkRect(keyboard_bounds)); + } + + keyboard::KeyboardControllerProxy* proxy_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardContainerTargeter); +}; + // The KeyboardWindowDelegate makes sure the keyboard-window does not get focus. // This is necessary to make sure that the synthetic key-events reach the target // window. @@ -166,6 +192,8 @@ aura::Window* KeyboardController::GetContainerWindow() { if (!container_.get()) { container_.reset(new aura::Window( new KeyboardWindowDelegate(proxy_.get()))); + container_->set_event_targeter(scoped_ptr<ui::EventTargeter>( + new KeyboardContainerTargeter(container_.get(), proxy_.get()))); container_->SetName("KeyboardContainer"); container_->set_owned_by_parent(false); container_->Init(aura::WINDOW_LAYER_NOT_DRAWN); diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc index 71f9017..88a36478 100644 --- a/ui/keyboard/keyboard_controller_unittest.cc +++ b/ui/keyboard/keyboard_controller_unittest.cc @@ -297,6 +297,45 @@ TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { keyboard_container->RemovePreTargetHandler(&observer); } +TEST_F(KeyboardControllerTest, EventHitTestingInContainer) { + const gfx::Rect& root_bounds = root_window()->bounds(); + aura::test::EventCountDelegate delegate; + scoped_ptr<aura::Window> window(new aura::Window(&delegate)); + window->Init(aura::WINDOW_LAYER_NOT_DRAWN); + window->SetBounds(root_bounds); + root_window()->AddChild(window.get()); + window->Show(); + window->Focus(); + + aura::Window* keyboard_container(controller()->GetContainerWindow()); + keyboard_container->SetBounds(root_bounds); + + root_window()->AddChild(keyboard_container); + keyboard_container->Show(); + + ShowKeyboard(); + + EXPECT_TRUE(window->IsVisible()); + EXPECT_TRUE(keyboard_container->IsVisible()); + EXPECT_TRUE(window->HasFocus()); + EXPECT_FALSE(keyboard_container->HasFocus()); + + // Make sure hit testing works correctly while the keyboard is visible. + aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); + ui::EventTarget* root = root_window(); + ui::EventTargeter* targeter = root->GetEventTargeter(); + gfx::Point location = keyboard_window->bounds().CenterPoint(); + ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, + ui::EF_NONE); + EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); + + + location.set_y(keyboard_window->bounds().y() - 5); + ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, + ui::EF_NONE); + EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); +} + TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { const gfx::Rect& root_bounds = root_window()->bounds(); diff --git a/ui/wm/public/masked_window_targeter.h b/ui/wm/public/masked_window_targeter.h index c5b4d88..edb050f 100644 --- a/ui/wm/public/masked_window_targeter.h +++ b/ui/wm/public/masked_window_targeter.h @@ -28,6 +28,7 @@ class MaskedWindowTargeter : public aura::WindowTargeter { aura::Window* window, const ui::LocatedEvent& event) const OVERRIDE; + private: aura::Window* masked_window_; DISALLOW_COPY_AND_ASSIGN(MaskedWindowTargeter); |