Commit 9fd3a232 authored by Blake O'Hare's avatar Blake O'Hare Committed by Commit Bot

Fix bug where floating keyboard jitters when dragging with multi-touch

When you use multiple fingers to drag the keyboard around, the events
for these get sent to the event filter sequentially. Check for a
pointer ID (which is unique per touch point) and include it in the
active drag descriptor. Ignore non-matching pointer events.

Bug: 802992
Change-Id: I5a3948719e5c103ee1aa618afc3fe36939567326
Reviewed-on: https://chromium-review.googlesource.com/979739Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549424}
parent 4d1bbb3f
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/keyboard/container_floating_behavior.h" #include "ui/keyboard/container_floating_behavior.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -194,6 +195,12 @@ bool ContainerFloatingBehavior::HandlePointerEvent( ...@@ -194,6 +195,12 @@ bool ContainerFloatingBehavior::HandlePointerEvent(
if (keyboard_bounds.height() <= 0) if (keyboard_bounds.height() <= 0)
return false; return false;
ui::PointerId pointer_id = -1;
if (event.IsTouchEvent()) {
const ui::TouchEvent* te = event.AsTouchEvent();
pointer_id = te->pointer_details().id;
}
bool handled = false; bool handled = false;
const ui::EventType type = event.type(); const ui::EventType type = event.type();
...@@ -210,8 +217,9 @@ bool ContainerFloatingBehavior::HandlePointerEvent( ...@@ -210,8 +217,9 @@ bool ContainerFloatingBehavior::HandlePointerEvent(
} 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(
keyboard_bounds.origin(), kb_offset, drag_started_by_touch)); new DragDescriptor(keyboard_bounds.origin(), kb_offset,
drag_started_by_touch, pointer_id));
handled = true; handled = true;
} }
break; break;
...@@ -225,6 +233,8 @@ bool ContainerFloatingBehavior::HandlePointerEvent( ...@@ -225,6 +233,8 @@ bool ContainerFloatingBehavior::HandlePointerEvent(
// If the event isn't of the same type that started the drag, end the // If the event isn't of the same type that started the drag, end the
// drag to prevent confusion. // drag to prevent confusion.
drag_descriptor_ = nullptr; drag_descriptor_ = nullptr;
} else if (drag_descriptor_->pointer_id() != pointer_id) {
// do nothing.
} else { } else {
// Drag continues. // Drag continues.
// If there is an active drag, use it to determine the new location // If there is an active drag, use it to determine the new location
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/keyboard/drag_descriptor.h" #include "ui/keyboard/drag_descriptor.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/geometry/vector2d.h"
...@@ -11,9 +12,11 @@ namespace keyboard { ...@@ -11,9 +12,11 @@ namespace keyboard {
DragDescriptor::DragDescriptor(const gfx::Point& keyboard_location, DragDescriptor::DragDescriptor(const gfx::Point& keyboard_location,
const gfx::Vector2d& click_offset, const gfx::Vector2d& click_offset,
bool is_touch_drag) bool is_touch_drag,
ui::PointerId pointer_id)
: original_keyboard_location_(keyboard_location), : original_keyboard_location_(keyboard_location),
original_click_offset_(click_offset), original_click_offset_(click_offset),
is_touch_drag_(is_touch_drag) {} is_touch_drag_(is_touch_drag),
pointer_id_(pointer_id) {}
} // namespace keyboard } // namespace keyboard
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef UI_KEYBOARD_DRAG_DESCRIPTOR_H_ #ifndef UI_KEYBOARD_DRAG_DESCRIPTOR_H_
#define UI_KEYBOARD_DRAG_DESCRIPTOR_H_ #define UI_KEYBOARD_DRAG_DESCRIPTOR_H_
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/geometry/vector2d.h"
...@@ -19,13 +20,15 @@ class DragDescriptor { ...@@ -19,13 +20,15 @@ class DragDescriptor {
public: public:
DragDescriptor(const gfx::Point& keyboard_location, DragDescriptor(const gfx::Point& keyboard_location,
const gfx::Vector2d& click_offset, const gfx::Vector2d& click_offset,
bool is_touch_drag); bool is_touch_drag,
ui::PointerId pointer_id);
gfx::Point original_keyboard_location() const { gfx::Point original_keyboard_location() const {
return original_keyboard_location_; return original_keyboard_location_;
} }
gfx::Vector2d original_click_offset() const { return original_click_offset_; } gfx::Vector2d original_click_offset() const { return original_click_offset_; }
bool is_touch_drag() { return is_touch_drag_; } bool is_touch_drag() { return is_touch_drag_; }
ui::PointerId pointer_id() { return pointer_id_; }
private: private:
const gfx::Point original_keyboard_location_; const gfx::Point original_keyboard_location_;
...@@ -34,6 +37,10 @@ class DragDescriptor { ...@@ -34,6 +37,10 @@ class DragDescriptor {
// Distinguish whether the current drag is from a touch event or mouse event, // Distinguish whether the current drag is from a touch event or mouse event,
// so drag/move events can be filtered accordingly // so drag/move events can be filtered accordingly
const bool is_touch_drag_; const bool is_touch_drag_;
// The pointer ID provided by the touch event to disambiguate multiple
// touch points. If this is a mouse event, then this value is -1.
const ui::PointerId pointer_id_;
}; };
} // namespace keyboard } // namespace keyboard
......
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