Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Unified Diff: components/exo/pointer.cc

Issue 2153503005: exo: Implement support for zwp_stylus_v1 protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@protocol
Patch Set: fixed nits and cleanup Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/exo/pointer.cc
diff --git a/components/exo/pointer.cc b/components/exo/pointer.cc
index 5640ae93c59f81a7630688fa04c4b1cd93872a17..485551aab8760464887e7f6f29b793a40911b634 100644
--- a/components/exo/pointer.cc
+++ b/components/exo/pointer.cc
@@ -9,6 +9,7 @@
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "components/exo/pointer_delegate.h"
+#include "components/exo/pointer_stylus_delegate.h"
#include "components/exo/surface.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
@@ -51,6 +52,8 @@ Pointer::Pointer(PointerDelegate* delegate)
Pointer::~Pointer() {
delegate_->OnPointerDestroying(this);
+ if (stylus_delegate_)
+ stylus_delegate_->OnPointerDestroying(this);
if (surface_)
surface_->RemoveSurfaceObserver(this);
if (focus_) {
@@ -119,6 +122,10 @@ void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) {
focus_->window()->GetCursor(gfx::ToFlooredPoint(location_)));
}
+void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) {
+ stylus_delegate_ = delegate;
+}
+
////////////////////////////////////////////////////////////////////////////////
// ui::EventHandler overrides:
@@ -142,12 +149,25 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
delegate_->OnPointerEnter(target, event->location_f(),
event->button_flags());
location_ = event->location_f();
+ // Defaulting pointer_type to POINTER_TYPE_MOUSE prevents the tool change
+ // event from being fired when using a mouse.
+ pointer_type_ = ui::EventPointerType::POINTER_TYPE_MOUSE;
+
focus_ = target;
focus_->AddSurfaceObserver(this);
}
delegate_->OnPointerFrame();
}
+ // Report changes in pointer type. We treat unknown devices as a mouse.
+ auto new_pointer_type = event->pointer_details().pointer_type;
+ if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN)
+ new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE;
+ if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) {
+ stylus_delegate_->OnPointerToolChange(new_pointer_type);
+ pointer_type_ = new_pointer_type;
+ }
+
switch (event->type()) {
case ui::ET_MOUSE_PRESSED:
case ui::ET_MOUSE_RELEASED:
@@ -160,14 +180,38 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
break;
case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_DRAGGED:
- // Generate motion event if location changed. We need to check location
- // here as mouse movement can generate both "moved" and "entered" events
- // but OnPointerMotion should only be called if location changed since
- // OnPointerEnter was called.
- if (focus_ && !SameLocation(event, location_)) {
- delegate_->OnPointerMotion(event->time_stamp(), event->location_f());
- delegate_->OnPointerFrame();
- location_ = event->location_f();
+ if (focus_) {
+ bool send_frame = false;
+ // Generate motion event if location changed. We need to check location
+ // here as mouse movement can generate both "moved" and "entered" events
+ // but OnPointerMotion should only be called if location changed since
+ // OnPointerEnter was called.
+ if (!SameLocation(event, location_)) {
+ location_ = event->location_f();
+ delegate_->OnPointerMotion(event->time_stamp(), location_);
+ send_frame = true;
+ }
+ if (stylus_delegate_ &&
+ pointer_type_ != ui::EventPointerType::POINTER_TYPE_MOUSE) {
+ constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
reveman 2016/07/28 04:01:45 is this useful? why are these type of events not f
denniskempin 2016/07/28 17:17:39 as discussed we will keep this for consistency wit
+ gfx::Vector2dF new_tilt = gfx::Vector2dF(
+ event->pointer_details().tilt_x, event->pointer_details().tilt_y);
+ if (std::abs(new_tilt.x() - tilt_.x()) > kEpsilon ||
+ std::abs(new_tilt.y() - tilt_.y()) > kEpsilon) {
+ tilt_ = new_tilt;
+ stylus_delegate_->OnPointerTilt(event->time_stamp(), new_tilt);
+ send_frame = true;
+ }
+
+ float new_force = event->pointer_details().force;
+ if (std::abs(new_force - force_) > kEpsilon) {
+ force_ = new_force;
+ stylus_delegate_->OnPointerForce(event->time_stamp(), new_force);
+ send_frame = true;
+ }
+ }
+ if (send_frame)
+ delegate_->OnPointerFrame();
}
break;
case ui::ET_SCROLL:

Powered by Google App Engine
This is Rietveld 408576698