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

Unified Diff: ui/events/test/events_test_utils_x11.cc

Issue 135393011: Revert of x11/test: Use a custom-deleter for the stored XEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/test/events_test_utils_x11.cc
diff --git a/ui/events/test/events_test_utils_x11.cc b/ui/events/test/events_test_utils_x11.cc
index f833c21e0fdc945134873fa710094b114768262e..20d1c17da5057eeb33216b0a5232bdd1319b671a 100644
--- a/ui/events/test/events_test_utils_x11.cc
+++ b/ui/events/test/events_test_utils_x11.cc
@@ -135,27 +135,15 @@
namespace ui {
-// XInput2 events contain additional data that need to be explicitly freed (see
-// |CreateXInput2Event()|.
-void XEventDeleter::operator()(XEvent* event) {
- if (event->type != GenericEvent)
- return;
- XIDeviceEvent* xiev =
- static_cast<XIDeviceEvent*>(event->xcookie.data);
- if (xiev) {
- delete[] xiev->valuators.mask;
- delete[] xiev->valuators.values;
- delete[] xiev->buttons.mask;
- delete xiev;
- }
-}
-
ScopedXI2Event::ScopedXI2Event() {}
-ScopedXI2Event::~ScopedXI2Event() {}
+ScopedXI2Event::~ScopedXI2Event() {
+ Cleanup();
+}
void ScopedXI2Event::InitKeyEvent(EventType type,
KeyboardCode key_code,
int flags) {
+ Cleanup();
XDisplay* display = gfx::GetXDisplay();
event_.reset(new XEvent);
memset(event_.get(), 0, sizeof(XEvent));
@@ -180,6 +168,7 @@
void ScopedXI2Event::InitGenericButtonEvent(int deviceid,
EventType type,
int flags) {
+ Cleanup();
event_.reset(CreateXInput2Event(deviceid,
XIButtonEventType(type), 0, gfx::Point()));
XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event_->xcookie.data);
@@ -190,6 +179,7 @@
void ScopedXI2Event::InitButtonEvent(EventType type,
int flags) {
+ Cleanup();
event_.reset(new XEvent);
memset(event_.get(), 0, sizeof(XEvent));
event_->type = XButtonEventType(type);
@@ -224,6 +214,7 @@
int x_offset_ordinal,
int y_offset_ordinal,
int finger_count) {
+ Cleanup();
event_.reset(CreateXInput2Event(deviceid, XI_Motion, 0, gfx::Point()));
Valuator valuators[] = {
@@ -243,6 +234,7 @@
int x_velocity_ordinal,
int y_velocity_ordinal,
bool is_cancel) {
+ Cleanup();
event_.reset(CreateXInput2Event(deviceid, XI_Motion, deviceid, gfx::Point()));
Valuator valuators[] = {
@@ -262,8 +254,23 @@
int tracking_id,
const gfx::Point& location,
const std::vector<Valuator>& valuators) {
+ Cleanup();
event_.reset(CreateXInput2Event(deviceid, evtype, tracking_id, location));
SetUpValuators(valuators);
+}
+
+void ScopedXI2Event::Cleanup() {
+ if (event_.get() && event_->type == GenericEvent) {
+ XIDeviceEvent* xiev =
+ static_cast<XIDeviceEvent*>(event_->xcookie.data);
+ if (xiev) {
+ delete[] xiev->valuators.mask;
+ delete[] xiev->valuators.values;
+ delete[] xiev->buttons.mask;
+ delete xiev;
+ }
+ }
+ event_.reset();
}
void ScopedXI2Event::SetUpValuators(const std::vector<Valuator>& valuators) {
« no previous file with comments | « ui/events/test/events_test_utils_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698