Commit 6b3d6841 authored by Blake O'Hare's avatar Blake O'Hare Committed by Commit Bot

Floating Keyboard stops propagation of drag handle events

If a touch/mouse event occurs and it is interpreted as a floating
keyboard drag event, do not propagate the event to the javascript
keyboard extension as there is no reason to.

This was causing the drag event to cause the gesture swiping to be
active while dragging the keyboard around, particularly if the keyboard
was bounded to the bottom of the screen and the user's finger is able
to move around on the keys while still moving the keyboard (see
attached bug for repro/video).

Bug: 826078
Change-Id: I40c859f979d41a5d61e88ff0bd41808dcf3940c2
Reviewed-on: https://chromium-review.googlesource.com/997195Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548374}
parent d0edd7ea
...@@ -64,7 +64,8 @@ class KEYBOARD_EXPORT ContainerBehavior { ...@@ -64,7 +64,8 @@ class KEYBOARD_EXPORT ContainerBehavior {
virtual void SavePosition(const gfx::Rect& keyboard_bounds, virtual void SavePosition(const gfx::Rect& keyboard_bounds,
const gfx::Size& screen_size) = 0; const gfx::Size& screen_size) = 0;
virtual void HandlePointerEvent(const ui::LocatedEvent& event, // Returns true if propagation should be stopped.
virtual bool HandlePointerEvent(const ui::LocatedEvent& event,
const gfx::Rect& display_bounds) = 0; const gfx::Rect& display_bounds) = 0;
virtual ContainerType GetType() const = 0; virtual ContainerType GetType() const = 0;
......
...@@ -179,7 +179,7 @@ bool ContainerFloatingBehavior::IsDragHandle( ...@@ -179,7 +179,7 @@ bool ContainerFloatingBehavior::IsDragHandle(
return draggable_area_.Contains(offset.x(), offset.y()); return draggable_area_.Contains(offset.x(), offset.y());
} }
void ContainerFloatingBehavior::HandlePointerEvent( bool ContainerFloatingBehavior::HandlePointerEvent(
const ui::LocatedEvent& event, const ui::LocatedEvent& event,
const gfx::Rect& display_bounds) { const gfx::Rect& display_bounds) {
// Cannot call UI-backed operations without a KeyboardController // Cannot call UI-backed operations without a KeyboardController
...@@ -192,7 +192,9 @@ void ContainerFloatingBehavior::HandlePointerEvent( ...@@ -192,7 +192,9 @@ void ContainerFloatingBehavior::HandlePointerEvent(
// Don't handle events if this runs in a partially initialized state. // Don't handle events if this runs in a partially initialized state.
if (keyboard_bounds.height() <= 0) if (keyboard_bounds.height() <= 0)
return; return false;
bool handled = false;
const ui::EventType type = event.type(); const ui::EventType type = event.type();
switch (type) { switch (type) {
...@@ -204,11 +206,13 @@ void ContainerFloatingBehavior::HandlePointerEvent( ...@@ -204,11 +206,13 @@ void ContainerFloatingBehavior::HandlePointerEvent(
!((const ui::MouseEvent*)&event)->IsOnlyLeftMouseButton()) { !((const ui::MouseEvent*)&event)->IsOnlyLeftMouseButton()) {
// Mouse events are limited to just the left mouse button. // Mouse events are limited to just the left mouse button.
drag_descriptor_ = nullptr; drag_descriptor_ = nullptr;
handled = true;
} else if (!drag_descriptor_) { } else if (!drag_descriptor_) {
// If there is no active drag descriptor, start a new one. // If there is no active drag descriptor, start a new one.
bool drag_started_by_touch = (type == ui::ET_TOUCH_PRESSED); bool drag_started_by_touch = (type == ui::ET_TOUCH_PRESSED);
drag_descriptor_.reset(new DragDescriptor( drag_descriptor_.reset(new DragDescriptor(
keyboard_bounds.origin(), kb_offset, drag_started_by_touch)); keyboard_bounds.origin(), kb_offset, drag_started_by_touch));
handled = true;
} }
break; break;
...@@ -239,6 +243,7 @@ void ContainerFloatingBehavior::HandlePointerEvent( ...@@ -239,6 +243,7 @@ void ContainerFloatingBehavior::HandlePointerEvent(
gfx::Rect(new_keyboard_location, keyboard_bounds.size()); gfx::Rect(new_keyboard_location, keyboard_bounds.size());
controller_->MoveKeyboard(new_bounds); controller_->MoveKeyboard(new_bounds);
SavePosition(container->bounds(), display_bounds.size()); SavePosition(container->bounds(), display_bounds.size());
handled = true;
} }
break; break;
...@@ -246,6 +251,7 @@ void ContainerFloatingBehavior::HandlePointerEvent( ...@@ -246,6 +251,7 @@ void ContainerFloatingBehavior::HandlePointerEvent(
drag_descriptor_ = nullptr; drag_descriptor_ = nullptr;
break; break;
} }
return handled;
} }
void ContainerFloatingBehavior::SetCanonicalBounds( void ContainerFloatingBehavior::SetCanonicalBounds(
......
...@@ -49,7 +49,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior { ...@@ -49,7 +49,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior {
const gfx::Size& keyboard_size) const override; const gfx::Size& keyboard_size) const override;
void SavePosition(const gfx::Rect& keyboard_bounds, void SavePosition(const gfx::Rect& keyboard_bounds,
const gfx::Size& screen_size) override; const gfx::Size& screen_size) override;
void HandlePointerEvent(const ui::LocatedEvent& event, bool HandlePointerEvent(const ui::LocatedEvent& event,
const gfx::Rect& display_bounds) override; const gfx::Rect& display_bounds) override;
void SetCanonicalBounds(aura::Window* container, void SetCanonicalBounds(aura::Window* container,
const gfx::Rect& display_bounds) override; const gfx::Rect& display_bounds) override;
......
...@@ -93,10 +93,11 @@ bool ContainerFullWidthBehavior::IsDragHandle( ...@@ -93,10 +93,11 @@ bool ContainerFullWidthBehavior::IsDragHandle(
return false; return false;
} }
void ContainerFullWidthBehavior::HandlePointerEvent( bool ContainerFullWidthBehavior::HandlePointerEvent(
const ui::LocatedEvent& event, const ui::LocatedEvent& event,
const gfx::Rect& display_bounds) { const gfx::Rect& display_bounds) {
// No-op. Nothing special to do for pointer events. // No-op. Nothing special to do for pointer events.
return false;
} }
void ContainerFullWidthBehavior::SetCanonicalBounds( void ContainerFullWidthBehavior::SetCanonicalBounds(
......
...@@ -41,7 +41,7 @@ class KEYBOARD_EXPORT ContainerFullWidthBehavior : public ContainerBehavior { ...@@ -41,7 +41,7 @@ class KEYBOARD_EXPORT ContainerFullWidthBehavior : public ContainerBehavior {
const gfx::Size& keyboard_size) const override; const gfx::Size& keyboard_size) const override;
void SavePosition(const gfx::Rect& keyboard_bounds, void SavePosition(const gfx::Rect& keyboard_bounds,
const gfx::Size& screen_size) override; const gfx::Size& screen_size) override;
void HandlePointerEvent(const ui::LocatedEvent& event, bool HandlePointerEvent(const ui::LocatedEvent& event,
const gfx::Rect& display_bounds) override; const gfx::Rect& display_bounds) override;
void SetCanonicalBounds(aura::Window* container, void SetCanonicalBounds(aura::Window* container,
const gfx::Rect& display_bounds) override; const gfx::Rect& display_bounds) override;
......
...@@ -779,9 +779,9 @@ bool KeyboardController::IsOverscrollAllowed() const { ...@@ -779,9 +779,9 @@ bool KeyboardController::IsOverscrollAllowed() const {
return container_behavior_->IsOverscrollAllowed(); return container_behavior_->IsOverscrollAllowed();
} }
void KeyboardController::HandlePointerEvent(const ui::LocatedEvent& event) { bool KeyboardController::HandlePointerEvent(ui::LocatedEvent* event) {
container_behavior_->HandlePointerEvent( return container_behavior_->HandlePointerEvent(
event, container_->GetRootWindow()->bounds()); *event, container_->GetRootWindow()->bounds());
} }
void KeyboardController::SetContainerType( void KeyboardController::SetContainerType(
......
...@@ -167,9 +167,9 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, ...@@ -167,9 +167,9 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
// container behavior. // container behavior.
bool IsOverscrollAllowed() const; bool IsOverscrollAllowed() const;
// Handle mouse and touch events on the keyboard. The effects of this method // Handle mouse and touch events on the keyboard. Returns true if the event
// will not stop propagation to the keyboard extension. // has been handled and propagation should be stopped.
void HandlePointerEvent(const ui::LocatedEvent& event); bool HandlePointerEvent(ui::LocatedEvent* event);
// Moves an already loaded keyboard. // Moves an already loaded keyboard.
void MoveKeyboard(const gfx::Rect new_bounds); void MoveKeyboard(const gfx::Rect new_bounds);
......
...@@ -23,17 +23,17 @@ void KeyboardEventFilter::OnGestureEvent(ui::GestureEvent* event) { ...@@ -23,17 +23,17 @@ void KeyboardEventFilter::OnGestureEvent(ui::GestureEvent* event) {
} }
void KeyboardEventFilter::OnMouseEvent(ui::MouseEvent* event) { void KeyboardEventFilter::OnMouseEvent(ui::MouseEvent* event) {
ProcessPointerEvent(*event); ProcessPointerEvent(event);
} }
void KeyboardEventFilter::OnTouchEvent(ui::TouchEvent* event) { void KeyboardEventFilter::OnTouchEvent(ui::TouchEvent* event) {
ProcessPointerEvent(*event); ProcessPointerEvent(event);
} }
void KeyboardEventFilter::ProcessPointerEvent(const ui::LocatedEvent& event) { void KeyboardEventFilter::ProcessPointerEvent(ui::LocatedEvent* event) {
KeyboardController* controller = KeyboardController::GetInstance(); KeyboardController* controller = KeyboardController::GetInstance();
if (controller) if (controller && controller->HandlePointerEvent(event))
controller->HandlePointerEvent(event); event->SetHandled();
} }
} // nemespace keyboard } // nemespace keyboard
...@@ -25,7 +25,7 @@ class KEYBOARD_EXPORT KeyboardEventFilter : public ui::EventHandler { ...@@ -25,7 +25,7 @@ class KEYBOARD_EXPORT KeyboardEventFilter : public ui::EventHandler {
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
private: private:
void ProcessPointerEvent(const ui::LocatedEvent& event); void ProcessPointerEvent(ui::LocatedEvent* event);
DISALLOW_COPY_AND_ASSIGN(KeyboardEventFilter); DISALLOW_COPY_AND_ASSIGN(KeyboardEventFilter);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment