Commit f2430d30 authored by James Cook's avatar James Cook Committed by Commit Bot

ui: Add copy constructors to event types

We rely on the implicit copy constructors in a large number of places
in the code. However, the existance of ui::Event::Clone() makes people
think they have to use that method to copy events -- they don't, if
they have an event with a known type.

Write out the copy constructors to make that clear.

Bug: none
Test: existing events_unittests, other existing UI unittests
Change-Id: I18cd94bdc1cdec9d91c2987da3dd28356edd8568
Reviewed-on: https://chromium-review.googlesource.com/830674Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524488}
parent 038ddeca
......@@ -457,8 +457,7 @@ CancelModeEvent::~CancelModeEvent() {
////////////////////////////////////////////////////////////////////////////////
// LocatedEvent
LocatedEvent::~LocatedEvent() {
}
LocatedEvent::~LocatedEvent() = default;
LocatedEvent::LocatedEvent(const base::NativeEvent& native_event)
: Event(native_event,
......@@ -476,6 +475,8 @@ LocatedEvent::LocatedEvent(EventType type,
location_(location),
root_location_(root_location) {}
LocatedEvent::LocatedEvent(const LocatedEvent& copy) = default;
void LocatedEvent::UpdateForRootTransform(
const gfx::Transform& reversed_root_transform,
const gfx::Transform& reversed_local_transform) {
......@@ -542,17 +543,7 @@ PointerDetails::PointerDetails(EventPointerType pointer_type,
offset = pointer_offset;
}
PointerDetails::PointerDetails(const PointerDetails& other)
: pointer_type(other.pointer_type),
radius_x(other.radius_x),
radius_y(other.radius_y),
force(other.force),
tilt_x(other.tilt_x),
tilt_y(other.tilt_y),
tangential_pressure(other.tangential_pressure),
twist(other.twist),
id(other.id),
offset(other.offset) {}
PointerDetails::PointerDetails(const PointerDetails& other) = default;
const PointerId PointerDetails::kUnknownPointerId = -1;
......@@ -636,6 +627,10 @@ MouseEvent::MouseEvent(EventType type,
SetType(ET_MOUSE_DRAGGED);
}
MouseEvent::MouseEvent(const MouseEvent& other) = default;
MouseEvent::~MouseEvent() = default;
// static
bool MouseEvent::IsRepeatedClickEvent(
const MouseEvent& event1,
......@@ -811,6 +806,8 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
SetType(ui::ET_MOUSEWHEEL);
}
MouseWheelEvent::~MouseWheelEvent() = default;
#if defined(OS_WIN)
// This value matches windows WHEEL_DELTA.
// static
......@@ -1449,6 +1446,10 @@ ScrollEvent::ScrollEvent(EventType type,
latency()->set_source_event_type(ui::SourceEventType::WHEEL);
}
ScrollEvent::ScrollEvent(const ScrollEvent& other) = default;
ScrollEvent::~ScrollEvent() = default;
void ScrollEvent::Scale(const float factor) {
x_offset_ *= factor;
y_offset_ *= factor;
......@@ -1475,7 +1476,8 @@ GestureEvent::GestureEvent(float x,
latency()->set_source_event_type(ui::SourceEventType::TOUCH);
}
GestureEvent::~GestureEvent() {
}
GestureEvent::GestureEvent(const GestureEvent& other) = default;
GestureEvent::~GestureEvent() = default;
} // namespace ui
......@@ -51,6 +51,8 @@ using PointerId = int32_t;
class EVENTS_EXPORT Event {
public:
// Copies an arbitrary event. If you have a typed event (e.g. a MouseEvent)
// just use its copy constructor.
static std::unique_ptr<Event> Clone(const Event& event);
virtual ~Event();
......@@ -390,6 +392,8 @@ class EVENTS_EXPORT LocatedEvent : public Event {
protected:
friend class LocatedEventTestApi;
LocatedEvent(const LocatedEvent& copy);
explicit LocatedEvent(const base::NativeEvent& native_event);
// Create a new LocatedEvent which is identical to the provided model.
......@@ -496,6 +500,8 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
public:
static const PointerId kMousePointerId;
// NOTE: On some platforms this will allow an event to be constructed from a
// void*, see base::NativeEvent.
explicit MouseEvent(const base::NativeEvent& native_event);
// |pointer_event.IsMousePointerEvent()| must be true.
......@@ -539,6 +545,9 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
PointerDetails(EventPointerType::POINTER_TYPE_MOUSE,
kMousePointerId));
MouseEvent(const MouseEvent& copy);
~MouseEvent() override;
// Conveniences to quickly test what button is down
bool IsOnlyLeftMouseButton() const {
return button_flags() == EF_LEFT_MOUSE_BUTTON;
......@@ -635,7 +644,8 @@ class EVENTS_EXPORT MouseWheelEvent : public MouseEvent {
explicit MouseWheelEvent(const ScrollEvent& scroll_event);
explicit MouseWheelEvent(const PointerEvent& pointer_event);
MouseWheelEvent(const MouseEvent& mouse_event, int x_offset, int y_offset);
MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event);
MouseWheelEvent(const MouseWheelEvent& copy);
~MouseWheelEvent() override;
template <class T>
MouseWheelEvent(const MouseWheelEvent& model,
......@@ -998,6 +1008,9 @@ class EVENTS_EXPORT ScrollEvent : public MouseEvent {
int finger_count,
EventMomentumPhase momentum_phase = EventMomentumPhase::NONE);
ScrollEvent(const ScrollEvent& copy);
~ScrollEvent() override;
// Scale the scroll event's offset value.
// This is useful in the multi-monitor setup where it needs to be scaled
// to provide a consistent user experience.
......@@ -1044,7 +1057,7 @@ class EVENTS_EXPORT GestureEvent : public LocatedEvent {
: LocatedEvent(model, source, target),
details_(model.details_) {
}
GestureEvent(const GestureEvent& copy);
~GestureEvent() override;
const GestureEventDetails& details() const { return details_; }
......
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