Commit fb228a96 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

Fix style in ui/event/event.{h,cc}

No functional change, just fixing coding style and a couple cleanups.

R=sadrul@chromium.org

Bug: None
Change-Id: I437a973ad6a50957c642923e8e088c2c3744e782
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216710
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774628}
parent f9e92628
...@@ -6,14 +6,16 @@ ...@@ -6,14 +6,16 @@
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <memory>
#include <string>
#include <utility> #include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
...@@ -40,9 +42,8 @@ namespace ui { ...@@ -40,9 +42,8 @@ namespace ui {
namespace { namespace {
constexpr int kChangedButtonFlagMask = constexpr int kChangedButtonFlagMask =
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON | ui::EF_BACK_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | EF_FORWARD_MOUSE_BUTTON;
ui::EF_FORWARD_MOUSE_BUTTON;
SourceEventType EventTypeToLatencySourceEventType(EventType type) { SourceEventType EventTypeToLatencySourceEventType(EventType type) {
switch (type) { switch (type) {
...@@ -72,8 +73,8 @@ SourceEventType EventTypeToLatencySourceEventType(EventType type) { ...@@ -72,8 +73,8 @@ SourceEventType EventTypeToLatencySourceEventType(EventType type) {
case ET_SCROLL_FLING_CANCEL: case ET_SCROLL_FLING_CANCEL:
return SourceEventType::UNKNOWN; return SourceEventType::UNKNOWN;
case ui::ET_KEY_PRESSED: case ET_KEY_PRESSED:
return ui::SourceEventType::KEY_PRESS; return SourceEventType::KEY_PRESS;
case ET_MOUSE_PRESSED: case ET_MOUSE_PRESSED:
case ET_MOUSE_DRAGGED: case ET_MOUSE_DRAGGED:
...@@ -141,7 +142,7 @@ std::string ScrollEventPhaseToString(ScrollEventPhase phase) { ...@@ -141,7 +142,7 @@ std::string ScrollEventPhaseToString(ScrollEventPhase phase) {
#if defined(USE_OZONE) #if defined(USE_OZONE)
uint32_t ScanCodeFromNative(const PlatformEvent& native_event) { uint32_t ScanCodeFromNative(const PlatformEvent& native_event) {
const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event); const KeyEvent* event = static_cast<const KeyEvent*>(native_event);
DCHECK(event->IsKeyEvent()); DCHECK(event->IsKeyEvent());
return event->scan_code(); return event->scan_code();
} }
...@@ -320,7 +321,7 @@ Event::Event(EventType type, base::TimeTicks time_stamp, int flags) ...@@ -320,7 +321,7 @@ Event::Event(EventType type, base::TimeTicks time_stamp, int flags)
native_event_(PlatformEvent()), native_event_(PlatformEvent()),
delete_native_event_(false), delete_native_event_(false),
cancelable_(true), cancelable_(true),
target_(NULL), target_(nullptr),
phase_(EP_PREDISPATCH), phase_(EP_PREDISPATCH),
result_(ER_UNHANDLED), result_(ER_UNHANDLED),
source_device_id_(ED_UNKNOWN_DEVICE) { source_device_id_(ED_UNKNOWN_DEVICE) {
...@@ -335,7 +336,7 @@ Event::Event(const PlatformEvent& native_event, EventType type, int flags) ...@@ -335,7 +336,7 @@ Event::Event(const PlatformEvent& native_event, EventType type, int flags)
native_event_(native_event), native_event_(native_event),
delete_native_event_(false), delete_native_event_(false),
cancelable_(true), cancelable_(true),
target_(NULL), target_(nullptr),
phase_(EP_PREDISPATCH), phase_(EP_PREDISPATCH),
result_(ER_UNHANDLED), result_(ER_UNHANDLED),
source_device_id_(ED_UNKNOWN_DEVICE) { source_device_id_(ED_UNKNOWN_DEVICE) {
...@@ -358,7 +359,7 @@ Event::Event(const Event& copy) ...@@ -358,7 +359,7 @@ Event::Event(const Event& copy)
native_event_(CopyNativeEvent(copy.native_event_)), native_event_(CopyNativeEvent(copy.native_event_)),
delete_native_event_(true), delete_native_event_(true),
cancelable_(true), cancelable_(true),
target_(NULL), target_(nullptr),
phase_(EP_PREDISPATCH), phase_(EP_PREDISPATCH),
result_(ER_UNHANDLED), result_(ER_UNHANDLED),
source_device_id_(copy.source_device_id_), source_device_id_(copy.source_device_id_),
...@@ -387,7 +388,7 @@ Event& Event::operator=(const Event& rhs) { ...@@ -387,7 +388,7 @@ Event& Event::operator=(const Event& rhs) {
else else
properties_.reset(); properties_.reset();
} }
latency_.set_source_event_type(ui::SourceEventType::OTHER); latency_.set_source_event_type(SourceEventType::OTHER);
return *this; return *this;
} }
...@@ -405,8 +406,7 @@ CancelModeEvent::CancelModeEvent() ...@@ -405,8 +406,7 @@ CancelModeEvent::CancelModeEvent()
set_cancelable(false); set_cancelable(false);
} }
CancelModeEvent::~CancelModeEvent() { CancelModeEvent::~CancelModeEvent() = default;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocatedEvent // LocatedEvent
...@@ -466,7 +466,7 @@ MouseEvent::MouseEvent(const PlatformEvent& native_event) ...@@ -466,7 +466,7 @@ MouseEvent::MouseEvent(const PlatformEvent& native_event)
: LocatedEvent(native_event), : LocatedEvent(native_event),
changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)),
pointer_details_(GetMousePointerDetailsFromNative(native_event)) { pointer_details_(GetMousePointerDetailsFromNative(native_event)) {
latency()->set_source_event_type(ui::SourceEventType::MOUSE); latency()->set_source_event_type(SourceEventType::MOUSE);
latency()->AddLatencyNumberWithTimestamp( latency()->AddLatencyNumberWithTimestamp(
INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, time_stamp()); INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, time_stamp());
latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT); latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT);
...@@ -486,7 +486,7 @@ MouseEvent::MouseEvent(EventType type, ...@@ -486,7 +486,7 @@ MouseEvent::MouseEvent(EventType type,
DCHECK_NE(ET_MOUSEWHEEL, type); DCHECK_NE(ET_MOUSEWHEEL, type);
DCHECK_EQ(changed_button_flags_, DCHECK_EQ(changed_button_flags_,
changed_button_flags_ & kChangedButtonFlagMask); changed_button_flags_ & kChangedButtonFlagMask);
latency()->set_source_event_type(ui::SourceEventType::MOUSE); latency()->set_source_event_type(SourceEventType::MOUSE);
latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT); latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT);
if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
SetType(ET_MOUSE_DRAGGED); SetType(ET_MOUSE_DRAGGED);
...@@ -525,8 +525,7 @@ bool MouseEvent::IsRepeatedClickEvent(const MouseEvent& event1, ...@@ -525,8 +525,7 @@ bool MouseEvent::IsRepeatedClickEvent(const MouseEvent& event1,
static const int kDoubleClickWidth = 4; static const int kDoubleClickWidth = 4;
static const int kDoubleClickHeight = 4; static const int kDoubleClickHeight = 4;
if (event1.type() != ET_MOUSE_PRESSED || if (event1.type() != ET_MOUSE_PRESSED || event2.type() != ET_MOUSE_PRESSED)
event2.type() != ET_MOUSE_PRESSED)
return false; return false;
// Compare flags, but ignore EF_IS_DOUBLE_CLICK to allow triple clicks. // Compare flags, but ignore EF_IS_DOUBLE_CLICK to allow triple clicks.
...@@ -556,7 +555,7 @@ bool MouseEvent::IsRepeatedClickEvent(const MouseEvent& event1, ...@@ -556,7 +555,7 @@ bool MouseEvent::IsRepeatedClickEvent(const MouseEvent& event1,
int MouseEvent::GetRepeatCount(const MouseEvent& event) { int MouseEvent::GetRepeatCount(const MouseEvent& event) {
int click_count = 1; int click_count = 1;
if (last_click_event_) { if (last_click_event_) {
if (event.type() == ui::ET_MOUSE_RELEASED) { if (event.type() == ET_MOUSE_RELEASED) {
if (event.changed_button_flags() == if (event.changed_button_flags() ==
last_click_event_->changed_button_flags()) { last_click_event_->changed_button_flags()) {
return last_click_event_->GetClickCount(); return last_click_event_->GetClickCount();
...@@ -584,12 +583,12 @@ int MouseEvent::GetRepeatCount(const MouseEvent& event) { ...@@ -584,12 +583,12 @@ int MouseEvent::GetRepeatCount(const MouseEvent& event) {
void MouseEvent::ResetLastClickForTest() { void MouseEvent::ResetLastClickForTest() {
if (last_click_event_) { if (last_click_event_) {
delete last_click_event_; delete last_click_event_;
last_click_event_ = NULL; last_click_event_ = nullptr;
} }
} }
// static // static
MouseEvent* MouseEvent::last_click_event_ = NULL; MouseEvent* MouseEvent::last_click_event_ = nullptr;
int MouseEvent::GetClickCount() const { int MouseEvent::GetClickCount() const {
if (type() != ET_MOUSE_PRESSED && type() != ET_MOUSE_RELEASED) if (type() != ET_MOUSE_PRESSED && type() != ET_MOUSE_RELEASED)
...@@ -649,8 +648,7 @@ MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event, ...@@ -649,8 +648,7 @@ MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event,
} }
MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event)
: MouseEvent(mouse_wheel_event), : MouseEvent(mouse_wheel_event), offset_(mouse_wheel_event.offset()) {
offset_(mouse_wheel_event.offset()) {
DCHECK_EQ(ET_MOUSEWHEEL, type()); DCHECK_EQ(ET_MOUSEWHEEL, type());
} }
...@@ -660,7 +658,7 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, ...@@ -660,7 +658,7 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
base::TimeTicks time_stamp, base::TimeTicks time_stamp,
int flags, int flags,
int changed_button_flags) int changed_button_flags)
: MouseEvent(ui::ET_UNKNOWN, : MouseEvent(ET_UNKNOWN,
location, location,
root_location, root_location,
time_stamp, time_stamp,
...@@ -670,7 +668,7 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, ...@@ -670,7 +668,7 @@ MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
// Set event type to ET_UNKNOWN initially in MouseEvent() to pass the // Set event type to ET_UNKNOWN initially in MouseEvent() to pass the
// DCHECK for type to enforce that we use MouseWheelEvent() to create // DCHECK for type to enforce that we use MouseWheelEvent() to create
// a MouseWheelEvent. // a MouseWheelEvent.
SetType(ui::ET_MOUSEWHEEL); SetType(ET_MOUSEWHEEL);
} }
MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
...@@ -822,10 +820,7 @@ KeyEvent::KeyEvent(EventType type, ...@@ -822,10 +820,7 @@ KeyEvent::KeyEvent(EventType type,
KeyboardCode key_code, KeyboardCode key_code,
DomCode code, DomCode code,
int flags) int flags)
: Event(type, EventTimeForNow(), flags), : Event(type, EventTimeForNow(), flags), key_code_(key_code), code_(code) {}
key_code_(key_code),
code_(code) {
}
KeyEvent::KeyEvent(EventType type, KeyEvent::KeyEvent(EventType type,
KeyboardCode key_code, KeyboardCode key_code,
...@@ -888,7 +883,7 @@ void KeyEvent::InitializeNative() { ...@@ -888,7 +883,7 @@ void KeyEvent::InitializeNative() {
// Check if this is a key repeat. This must be called before initial flags // Check if this is a key repeat. This must be called before initial flags
// processing, e.g: NormalizeFlags(), to avoid issues like crbug.com/1069690. // processing, e.g: NormalizeFlags(), to avoid issues like crbug.com/1069690.
if (IsRepeated(GetLastKeyEvent())) if (IsRepeated(GetLastKeyEvent()))
set_flags(flags() | ui::EF_IS_REPEAT); set_flags(flags() | EF_IS_REPEAT);
#if defined(USE_X11) #if defined(USE_X11)
NormalizeFlags(); NormalizeFlags();
...@@ -906,7 +901,7 @@ void KeyEvent::InitializeNative() { ...@@ -906,7 +901,7 @@ void KeyEvent::InitializeNative() {
} }
void KeyEvent::ApplyLayout() const { void KeyEvent::ApplyLayout() const {
ui::DomCode code = code_; DomCode code = code_;
if (code == DomCode::NONE) { if (code == DomCode::NONE) {
// Catch old code that tries to do layout without a physical key, and try // Catch old code that tries to do layout without a physical key, and try
// to recover using the KeyboardCode. Once key events are fully defined // to recover using the KeyboardCode. Once key events are fully defined
...@@ -947,13 +942,13 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) { ...@@ -947,13 +942,13 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) {
if (is_char()) if (is_char())
return false; return false;
if (type() == ui::ET_KEY_RELEASED) { if (type() == ET_KEY_RELEASED) {
delete *last_key_event; delete *last_key_event;
*last_key_event = nullptr; *last_key_event = nullptr;
return false; return false;
} }
CHECK_EQ(ui::ET_KEY_PRESSED, type()); CHECK_EQ(ET_KEY_PRESSED, type());
KeyEvent* last = *last_key_event; KeyEvent* last = *last_key_event;
if (!last) { if (!last) {
...@@ -961,7 +956,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) { ...@@ -961,7 +956,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) {
return false; return false;
} else if (time_stamp() == last->time_stamp()) { } else if (time_stamp() == last->time_stamp()) {
// The KeyEvent is created from the same native event. // The KeyEvent is created from the same native event.
return (last->flags() & ui::EF_IS_REPEAT) != 0; return (last->flags() & EF_IS_REPEAT) != 0;
} }
DCHECK(last); DCHECK(last);
...@@ -976,7 +971,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) { ...@@ -976,7 +971,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) {
#endif #endif
if (!is_repeat) { if (!is_repeat) {
if (key_code() == last->key_code() && if (key_code() == last->key_code() &&
flags() == (last->flags() & ~ui::EF_IS_REPEAT) && flags() == (last->flags() & ~EF_IS_REPEAT) &&
(time_stamp() - last->time_stamp()).InMilliseconds() < (time_stamp() - last->time_stamp()).InMilliseconds() <
kMaxAutoRepeatTimeMs) { kMaxAutoRepeatTimeMs) {
is_repeat = true; is_repeat = true;
...@@ -985,7 +980,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) { ...@@ -985,7 +980,7 @@ bool KeyEvent::IsRepeated(KeyEvent** last_key_event) {
if (is_repeat) { if (is_repeat) {
last->set_time_stamp(time_stamp()); last->set_time_stamp(time_stamp());
last->set_flags(last->flags() | ui::EF_IS_REPEAT); last->set_flags(last->flags() | EF_IS_REPEAT);
return true; return true;
} }
...@@ -1043,8 +1038,8 @@ base::char16 KeyEvent::GetCharacter() const { ...@@ -1043,8 +1038,8 @@ base::char16 KeyEvent::GetCharacter() const {
base::char16 KeyEvent::GetText() const { base::char16 KeyEvent::GetText() const {
if ((flags() & EF_CONTROL_DOWN) != 0) { if ((flags() & EF_CONTROL_DOWN) != 0) {
ui::DomKey key; DomKey key;
ui::KeyboardCode key_code; KeyboardCode key_code;
if (DomCodeToControlCharacter(code_, flags(), &key, &key_code)) if (DomCodeToControlCharacter(code_, flags(), &key, &key_code))
return key.ToCharacter(); return key.ToCharacter();
} }
...@@ -1131,18 +1126,16 @@ ScrollEvent::ScrollEvent(const PlatformEvent& native_event) ...@@ -1131,18 +1126,16 @@ ScrollEvent::ScrollEvent(const PlatformEvent& native_event)
&y_offset_ordinal_, &finger_count_, &momentum_phase_); &y_offset_ordinal_, &finger_count_, &momentum_phase_);
} else if (type() == ET_SCROLL_FLING_START || } else if (type() == ET_SCROLL_FLING_START ||
type() == ET_SCROLL_FLING_CANCEL) { type() == ET_SCROLL_FLING_CANCEL) {
GetFlingData(native_event, GetFlingData(native_event, &x_offset_, &y_offset_, &x_offset_ordinal_,
&x_offset_, &y_offset_, &y_offset_ordinal_, nullptr);
&x_offset_ordinal_, &y_offset_ordinal_,
NULL);
} else { } else {
NOTREACHED() << "Unexpected event type " << type() NOTREACHED() << "Unexpected event type " << type()
<< " when constructing a ScrollEvent."; << " when constructing a ScrollEvent.";
} }
if (IsScrollEvent()) if (IsScrollEvent())
latency()->set_source_event_type(ui::SourceEventType::WHEEL); latency()->set_source_event_type(SourceEventType::WHEEL);
else else
latency()->set_source_event_type(ui::SourceEventType::TOUCH); latency()->set_source_event_type(SourceEventType::TOUCH);
} }
ScrollEvent::ScrollEvent(EventType type, ScrollEvent::ScrollEvent(EventType type,
...@@ -1166,7 +1159,7 @@ ScrollEvent::ScrollEvent(EventType type, ...@@ -1166,7 +1159,7 @@ ScrollEvent::ScrollEvent(EventType type,
momentum_phase_(momentum_phase), momentum_phase_(momentum_phase),
scroll_event_phase_(scroll_event_phase) { scroll_event_phase_(scroll_event_phase) {
CHECK(IsScrollEvent()); CHECK(IsScrollEvent());
latency()->set_source_event_type(ui::SourceEventType::WHEEL); latency()->set_source_event_type(SourceEventType::WHEEL);
} }
ScrollEvent::ScrollEvent(EventType type, ScrollEvent::ScrollEvent(EventType type,
...@@ -1231,11 +1224,11 @@ GestureEvent::GestureEvent(float x, ...@@ -1231,11 +1224,11 @@ GestureEvent::GestureEvent(float x,
flags | EF_FROM_TOUCH), flags | EF_FROM_TOUCH),
details_(details), details_(details),
unique_touch_event_id_(unique_touch_event_id) { unique_touch_event_id_(unique_touch_event_id) {
latency()->set_source_event_type(ui::SourceEventType::TOUCH); latency()->set_source_event_type(SourceEventType::TOUCH);
// TODO(crbug.com/868056) Other touchpad gesture should report as TOUCHPAD. // TODO(crbug.com/868056) Other touchpad gesture should report as TOUCHPAD.
if (IsPinchEvent() && if (IsPinchEvent() &&
details.device_type() == ui::GestureDeviceType::DEVICE_TOUCHPAD) { details.device_type() == GestureDeviceType::DEVICE_TOUCHPAD) {
latency()->set_source_event_type(ui::SourceEventType::TOUCHPAD); latency()->set_source_event_type(SourceEventType::TOUCHPAD);
} }
} }
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
#ifndef UI_EVENTS_EVENT_H_ #ifndef UI_EVENTS_EVENT_H_
#define UI_EVENTS_EVENT_H_ #define UI_EVENTS_EVENT_H_
#include <stdint.h> #include <cstdint>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -18,7 +17,6 @@ ...@@ -18,7 +17,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "ui/events/event_constants.h" #include "ui/events/event_constants.h"
#include "ui/events/gesture_event_details.h" #include "ui/events/gesture_event_details.h"
#include "ui/events/gestures/gesture_types.h" #include "ui/events/gestures/gesture_types.h"
...@@ -36,6 +34,7 @@ class Transform; ...@@ -36,6 +34,7 @@ class Transform;
} }
namespace ui { namespace ui {
class CancelModeEvent; class CancelModeEvent;
class Event; class Event;
class EventTarget; class EventTarget;
...@@ -62,9 +61,7 @@ class EVENTS_EXPORT Event { ...@@ -62,9 +61,7 @@ class EVENTS_EXPORT Event {
public: public:
explicit DispatcherApi(Event* event) : event_(event) {} explicit DispatcherApi(Event* event) : event_(event) {}
void set_target(EventTarget* target) { void set_target(EventTarget* target) { event_->target_ = target; }
event_->target_ = target;
}
void set_phase(EventPhase phase) { event_->phase_ = phase; } void set_phase(EventPhase phase) { event_->phase_ = phase; }
void set_result(int result) { void set_result(int result) {
...@@ -130,9 +127,7 @@ class EVENTS_EXPORT Event { ...@@ -130,9 +127,7 @@ class EVENTS_EXPORT Event {
bool IsSynthesized() const { return (flags_ & EF_IS_SYNTHESIZED) != 0; } bool IsSynthesized() const { return (flags_ & EF_IS_SYNTHESIZED) != 0; }
bool IsCancelModeEvent() const { bool IsCancelModeEvent() const { return type_ == ET_CANCEL_MODE; }
return type_ == ET_CANCEL_MODE;
}
bool IsKeyEvent() const { bool IsKeyEvent() const {
return type_ == ET_KEY_PRESSED || type_ == ET_KEY_RELEASED; return type_ == ET_KEY_PRESSED || type_ == ET_KEY_RELEASED;
...@@ -195,12 +190,12 @@ class EVENTS_EXPORT Event { ...@@ -195,12 +190,12 @@ class EVENTS_EXPORT Event {
// An ending event is paired with the event which started it. Setting capture // An ending event is paired with the event which started it. Setting capture
// should not prevent ending events from getting to their initial target. // should not prevent ending events from getting to their initial target.
bool IsEndingEvent() const { bool IsEndingEvent() const {
switch(type_) { switch (type_) {
case ui::ET_TOUCH_CANCELLED: case ET_TOUCH_CANCELLED:
case ui::ET_GESTURE_TAP_CANCEL: case ET_GESTURE_TAP_CANCEL:
case ui::ET_GESTURE_END: case ET_GESTURE_END:
case ui::ET_GESTURE_SCROLL_END: case ET_GESTURE_SCROLL_END:
case ui::ET_GESTURE_PINCH_END: case ET_GESTURE_PINCH_END:
return true; return true;
default: default:
return false; return false;
...@@ -210,8 +205,7 @@ class EVENTS_EXPORT Event { ...@@ -210,8 +205,7 @@ class EVENTS_EXPORT Event {
bool IsScrollEvent() const { bool IsScrollEvent() const {
// Flings can be GestureEvents too. EF_FROM_TOUCH determines if they're // Flings can be GestureEvents too. EF_FROM_TOUCH determines if they're
// Gesture or Scroll events. // Gesture or Scroll events.
return type_ == ET_SCROLL || return type_ == ET_SCROLL || ((type_ == ET_SCROLL_FLING_START ||
((type_ == ET_SCROLL_FLING_START ||
type_ == ET_SCROLL_FLING_CANCEL) && type_ == ET_SCROLL_FLING_CANCEL) &&
!(flags() & EF_FROM_TOUCH)); !(flags() & EF_FROM_TOUCH));
} }
...@@ -223,18 +217,14 @@ class EVENTS_EXPORT Event { ...@@ -223,18 +217,14 @@ class EVENTS_EXPORT Event {
bool IsScrollGestureEvent() const { bool IsScrollGestureEvent() const {
return type_ == ET_GESTURE_SCROLL_BEGIN || return type_ == ET_GESTURE_SCROLL_BEGIN ||
type_ == ET_GESTURE_SCROLL_UPDATE || type_ == ET_GESTURE_SCROLL_UPDATE || type_ == ET_GESTURE_SCROLL_END;
type_ == ET_GESTURE_SCROLL_END;
} }
bool IsFlingScrollEvent() const { bool IsFlingScrollEvent() const {
return type_ == ET_SCROLL_FLING_CANCEL || return type_ == ET_SCROLL_FLING_CANCEL || type_ == ET_SCROLL_FLING_START;
type_ == ET_SCROLL_FLING_START;
} }
bool IsMouseWheelEvent() const { bool IsMouseWheelEvent() const { return type_ == ET_MOUSEWHEEL; }
return type_ == ET_MOUSEWHEEL;
}
bool IsLocatedEvent() const { bool IsLocatedEvent() const {
return IsMouseEvent() || IsScrollEvent() || IsTouchEvent() || return IsMouseEvent() || IsScrollEvent() || IsTouchEvent() ||
...@@ -313,9 +303,7 @@ class EVENTS_EXPORT Event { ...@@ -313,9 +303,7 @@ class EVENTS_EXPORT Event {
void SetType(EventType type); void SetType(EventType type);
void set_cancelable(bool cancelable) { cancelable_ = cancelable; } void set_cancelable(bool cancelable) { cancelable_ = cancelable; }
void set_time_stamp(base::TimeTicks time_stamp) { void set_time_stamp(base::TimeTicks time_stamp) { time_stamp_ = time_stamp; }
time_stamp_ = time_stamp;
}
private: private:
friend class EventTestApi; friend class EventTestApi;
...@@ -348,7 +336,7 @@ class EVENTS_EXPORT LocatedEvent : public Event { ...@@ -348,7 +336,7 @@ class EVENTS_EXPORT LocatedEvent : public Event {
public: public:
// Convenience function that casts |event| to a LocatedEvent if it is one, // Convenience function that casts |event| to a LocatedEvent if it is one,
// otherwise returns null. // otherwise returns null.
static const ui::LocatedEvent* FromIfValid(const ui::Event* event) { static const LocatedEvent* FromIfValid(const Event* event) {
return event && event->IsLocatedEvent() ? event->AsLocatedEvent() : nullptr; return event && event->IsLocatedEvent() ? event->AsLocatedEvent() : nullptr;
} }
...@@ -371,9 +359,7 @@ class EVENTS_EXPORT LocatedEvent : public Event { ...@@ -371,9 +359,7 @@ class EVENTS_EXPORT LocatedEvent : public Event {
gfx::Point root_location() const { gfx::Point root_location() const {
return gfx::ToFlooredPoint(root_location_); return gfx::ToFlooredPoint(root_location_);
} }
const gfx::PointF& root_location_f() const { const gfx::PointF& root_location_f() const { return root_location_; }
return root_location_;
}
// Transform the locations using |inverted_root_transform| and // Transform the locations using |inverted_root_transform| and
// |inverted_local_transform|. |inverted_local_transform| is only used if // |inverted_local_transform|. |inverted_local_transform| is only used if
...@@ -529,9 +515,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { ...@@ -529,9 +515,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0; return (flags() & EF_RIGHT_MOUSE_BUTTON) != 0;
} }
bool IsAnyButton() const { bool IsAnyButton() const { return button_flags() != 0; }
return button_flags() != 0;
}
// Returns the flags for the mouse buttons. // Returns the flags for the mouse buttons.
int button_flags() const { int button_flags() const {
...@@ -542,8 +526,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent { ...@@ -542,8 +526,7 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
// Compares two mouse down events and returns true if the second one should // Compares two mouse down events and returns true if the second one should
// be considered a repeat of the first. // be considered a repeat of the first.
static bool IsRepeatedClickEvent( static bool IsRepeatedClickEvent(const MouseEvent& event1,
const MouseEvent& event1,
const MouseEvent& event2); const MouseEvent& event2);
// Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
...@@ -607,12 +590,9 @@ class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { ...@@ -607,12 +590,9 @@ class EVENTS_EXPORT MouseWheelEvent : public MouseEvent {
~MouseWheelEvent() override; ~MouseWheelEvent() override;
template <class T> template <class T>
MouseWheelEvent(const MouseWheelEvent& model, MouseWheelEvent(const MouseWheelEvent& model, T* source, T* target)
T* source,
T* target)
: MouseEvent(model, source, target, model.type(), model.flags()), : MouseEvent(model, source, target, model.type(), model.flags()),
offset_(model.x_offset(), model.y_offset()) { offset_(model.x_offset(), model.y_offset()) {}
}
// Used for synthetic events in testing and by the gesture recognizer. // Used for synthetic events in testing and by the gesture recognizer.
MouseWheelEvent(const gfx::Vector2d& offset, MouseWheelEvent(const gfx::Vector2d& offset,
...@@ -800,10 +780,7 @@ class EVENTS_EXPORT KeyEvent : public Event { ...@@ -800,10 +780,7 @@ class EVENTS_EXPORT KeyEvent : public Event {
// Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA') // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
// See also: ui/events/keycodes/dom/dom_values.txt // See also: ui/events/keycodes/dom/dom_values.txt
KeyEvent(EventType type, KeyEvent(EventType type, KeyboardCode key_code, DomCode code, int flags);
KeyboardCode key_code,
DomCode code,
int flags);
KeyEvent(const KeyEvent& rhs); KeyEvent(const KeyEvent& rhs);
...@@ -1032,17 +1009,13 @@ class EVENTS_EXPORT GestureEvent : public LocatedEvent { ...@@ -1032,17 +1009,13 @@ class EVENTS_EXPORT GestureEvent : public LocatedEvent {
// converted from |source| coordinate system to |target| coordinate system. // converted from |source| coordinate system to |target| coordinate system.
template <typename T> template <typename T>
GestureEvent(const GestureEvent& model, T* source, T* target) GestureEvent(const GestureEvent& model, T* source, T* target)
: LocatedEvent(model, source, target), : LocatedEvent(model, source, target), details_(model.details_) {}
details_(model.details_) {
}
GestureEvent(const GestureEvent& copy); GestureEvent(const GestureEvent& copy);
~GestureEvent() override; ~GestureEvent() override;
const GestureEventDetails& details() const { return details_; } const GestureEventDetails& details() const { return details_; }
uint32_t unique_touch_event_id() const { uint32_t unique_touch_event_id() const { return unique_touch_event_id_; }
return unique_touch_event_id_;
}
private: private:
GestureEventDetails details_; GestureEventDetails 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