Skip to content

Commit

Permalink
keyboard: Install a masked window-targeter in the keyboard container.
Browse files Browse the repository at this point in the history
Install a masked window-targeter in the keyboard container so that event
targetting works correctly when used with EventProcessor for dispatching
events.

BUG=318879
[email protected]

Review URL: https://codereview.chromium.org/139613003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245048 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Jan 16, 2014
1 parent 7fd098a commit 8b2db13
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions ui/keyboard/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include_rules = [
"+ui/compositor",
"+ui/gfx",
"+ui/test",
"+ui/wm",
]
1 change: 1 addition & 0 deletions ui/keyboard/keyboard.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
'../ui.gyp:ui',
'../wm/wm.gyp:wm_public',
'keyboard_resources',
],
'defines': [
Expand Down
28 changes: 28 additions & 0 deletions ui/keyboard/keyboard_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions ui/keyboard/keyboard_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions ui/wm/public/masked_window_targeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8b2db13

Please sign in to comment.