summaryrefslogtreecommitdiffstats
path: root/ui/base/touch
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 06:55:09 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 06:55:09 +0000
commita6147a2157592761fd071b91b87d65f63baf0f5b (patch)
treeb65ae215f3fde65c431d97a3a1fa880f21d549a3 /ui/base/touch
parentdf9430603f01bc5710ab44cec32c3b60e45c459c (diff)
downloadchromium_src-a6147a2157592761fd071b91b87d65f63baf0f5b.zip
chromium_src-a6147a2157592761fd071b91b87d65f63baf0f5b.tar.gz
chromium_src-a6147a2157592761fd071b91b87d65f63baf0f5b.tar.bz2
events: Move all references to ui/base/ from ui/events.
Notable changes: * Move TouchFactory from ui/base/ into ui/events/x/. * Split out some switches from ui/base/ into ui/events/. * Move SequentialIDGenerator from ui/base/ into ui/gfx/. BUG=none R=ben@chromium.org Review URL: https://codereview.chromium.org/24692003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/touch')
-rw-r--r--ui/base/touch/touch_device_aurax11.cc2
-rw-r--r--ui/base/touch/touch_enabled.cc1
-rw-r--r--ui/base/touch/touch_factory_x11.cc271
-rw-r--r--ui/base/touch/touch_factory_x11.h136
4 files changed, 2 insertions, 408 deletions
diff --git a/ui/base/touch/touch_device_aurax11.cc b/ui/base/touch/touch_device_aurax11.cc
index 2e34b32..04d435e 100644
--- a/ui/base/touch/touch_device_aurax11.cc
+++ b/ui/base/touch/touch_device_aurax11.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "ui/base/touch/touch_device.h"
-#include "ui/base/touch/touch_factory_x11.h"
+#include "ui/events/x/touch_factory_x11.h"
namespace ui {
diff --git a/ui/base/touch/touch_enabled.cc b/ui/base/touch/touch_enabled.cc
index 79655df..6d2aebf 100644
--- a/ui/base/touch/touch_enabled.cc
+++ b/ui/base/touch/touch_enabled.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "ui/base/touch/touch_device.h"
#include "ui/base/ui_base_switches.h"
+#include "ui/events/event_switches.h"
namespace ui {
diff --git a/ui/base/touch/touch_factory_x11.cc b/ui/base/touch/touch_factory_x11.cc
deleted file mode 100644
index 4314eed..0000000
--- a/ui/base/touch/touch_factory_x11.cc
+++ /dev/null
@@ -1,271 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/base/touch/touch_factory_x11.h"
-
-#include <X11/cursorfont.h>
-#include <X11/extensions/XInput.h>
-#include <X11/extensions/XInput2.h>
-#include <X11/extensions/XIproto.h>
-
-#include "base/basictypes.h"
-#include "base/command_line.h"
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "base/memory/singleton.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "ui/base/ui_base_switches.h"
-#include "ui/events/x/device_list_cache_x.h"
-#include "ui/gfx/x/x11_types.h"
-
-namespace ui {
-
-TouchFactory::TouchFactory()
- : pointer_device_lookup_(),
- touch_device_available_(false),
- touch_events_disabled_(false),
- touch_device_list_(),
-#if defined(USE_XI2_MT)
- id_generator_(0),
-#endif
- slots_used_() {
-#if defined(USE_AURA)
- if (!base::MessagePumpForUI::HasXInput2())
- return;
-#endif
-
- XDisplay* display = gfx::GetXDisplay();
- UpdateDeviceList(display);
-
- CommandLine* cmdline = CommandLine::ForCurrentProcess();
- touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) &&
- cmdline->GetSwitchValueASCII(switches::kTouchEvents) ==
- switches::kTouchEventsDisabled;
-}
-
-TouchFactory::~TouchFactory() {
-}
-
-// static
-TouchFactory* TouchFactory::GetInstance() {
- return Singleton<TouchFactory>::get();
-}
-
-// static
-void TouchFactory::SetTouchDeviceListFromCommandLine() {
-#if defined(TOOLKIT_VIEWS)
- // Get a list of pointer-devices that should be treated as touch-devices.
- // This is primarily used for testing/debugging touch-event processing when a
- // touch-device isn't available.
- std::string touch_devices =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kTouchDevices);
-
- if (!touch_devices.empty()) {
- std::vector<std::string> devs;
- std::vector<unsigned int> device_ids;
- unsigned int devid;
- base::SplitString(touch_devices, ',', &devs);
- for (std::vector<std::string>::iterator iter = devs.begin();
- iter != devs.end(); ++iter) {
- if (base::StringToInt(*iter, reinterpret_cast<int*>(&devid)))
- device_ids.push_back(devid);
- else
- DLOG(WARNING) << "Invalid touch-device id: " << *iter;
- }
- ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids);
- }
-#endif
-}
-
-void TouchFactory::UpdateDeviceList(Display* display) {
- // Detect touch devices.
- touch_device_available_ = false;
- touch_device_lookup_.reset();
- touch_device_list_.clear();
-
-#if !defined(USE_XI2_MT)
- // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does
- // not provide enough information to detect a touch device. As a result, the
- // old version of query function (XListInputDevices) is used instead.
- // If XInput2 is not supported, this will return null (with count of -1) so
- // we assume there cannot be any touch devices.
- // With XI2.1 or older, we allow only single touch devices.
- XDeviceList dev_list =
- DeviceListCacheX::GetInstance()->GetXDeviceList(display);
- for (int i = 0; i < dev_list.count; i++) {
- if (dev_list[i].type) {
- XScopedString devtype(XGetAtomName(display, dev_list[i].type));
- if (devtype.string() && !strcmp(devtype.string(), XI_TOUCHSCREEN)) {
- touch_device_lookup_[dev_list[i].id] = true;
- touch_device_list_[dev_list[i].id] = false;
- touch_device_available_ = true;
- }
- }
- }
-#endif
-
- // Instead of asking X for the list of devices all the time, let's maintain a
- // list of pointer devices we care about.
- // It should not be necessary to select for slave devices. XInput2 provides
- // enough information to the event callback to decide which slave device
- // triggered the event, thus decide whether the 'pointer event' is a
- // 'mouse event' or a 'touch event'.
- // However, on some desktops, some events from a master pointer are
- // not delivered to the client. So we select for slave devices instead.
- // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which
- // is possible), then the device is detected as a floating device, and a
- // floating device is not connected to a master device. So it is necessary to
- // also select on the floating devices.
- pointer_device_lookup_.reset();
- XIDeviceList xi_dev_list =
- DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
- for (int i = 0; i < xi_dev_list.count; i++) {
- XIDeviceInfo* devinfo = xi_dev_list.devices + i;
- if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) {
-#if defined(USE_XI2_MT)
- for (int k = 0; k < devinfo->num_classes; ++k) {
- XIAnyClassInfo* xiclassinfo = devinfo->classes[k];
- if (xiclassinfo->type == XITouchClass) {
- XITouchClassInfo* tci =
- reinterpret_cast<XITouchClassInfo *>(xiclassinfo);
- // Only care direct touch device (such as touch screen) right now
- if (tci->mode == XIDirectTouch) {
- touch_device_lookup_[devinfo->deviceid] = true;
- touch_device_list_[devinfo->deviceid] = true;
- touch_device_available_ = true;
- }
- }
- }
-#endif
- pointer_device_lookup_[devinfo->deviceid] = true;
- }
- }
-}
-
-bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) {
- DCHECK_EQ(GenericEvent, xev->type);
- XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data);
- XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event);
-
-#if defined(USE_XI2_MT)
- if (event->evtype == XI_TouchBegin ||
- event->evtype == XI_TouchUpdate ||
- event->evtype == XI_TouchEnd) {
- return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid);
- }
-#endif
- if (event->evtype != XI_ButtonPress &&
- event->evtype != XI_ButtonRelease &&
- event->evtype != XI_Motion)
- return true;
-
- if (!pointer_device_lookup_[xiev->deviceid])
- return false;
-
- return IsTouchDevice(xiev->deviceid) ? !touch_events_disabled_ : true;
-}
-
-void TouchFactory::SetupXI2ForXWindow(Window window) {
- // Setup mask for mouse events. It is possible that a device is loaded/plugged
- // in after we have setup XInput2 on a window. In such cases, we need to
- // either resetup XInput2 for the window, so that we get events from the new
- // device, or we need to listen to events from all devices, and then filter
- // the events from uninteresting devices. We do the latter because that's
- // simpler.
-
- XDisplay* display = gfx::GetXDisplay();
-
- unsigned char mask[XIMaskLen(XI_LASTEVENT)];
- memset(mask, 0, sizeof(mask));
-
-#if defined(USE_XI2_MT)
- XISetMask(mask, XI_TouchBegin);
- XISetMask(mask, XI_TouchUpdate);
- XISetMask(mask, XI_TouchEnd);
-#endif
- XISetMask(mask, XI_ButtonPress);
- XISetMask(mask, XI_ButtonRelease);
- XISetMask(mask, XI_Motion);
-
- XIEventMask evmask;
- evmask.deviceid = XIAllDevices;
- evmask.mask_len = sizeof(mask);
- evmask.mask = mask;
- XISelectEvents(display, window, &evmask, 1);
- XFlush(display);
-}
-
-void TouchFactory::SetTouchDeviceList(
- const std::vector<unsigned int>& devices) {
- touch_device_lookup_.reset();
- touch_device_list_.clear();
- for (std::vector<unsigned int>::const_iterator iter = devices.begin();
- iter != devices.end(); ++iter) {
- DCHECK(*iter < touch_device_lookup_.size());
- touch_device_lookup_[*iter] = true;
- touch_device_list_[*iter] = false;
- }
-}
-
-bool TouchFactory::IsTouchDevice(unsigned deviceid) const {
- return deviceid < touch_device_lookup_.size() ?
- touch_device_lookup_[deviceid] : false;
-}
-
-bool TouchFactory::IsMultiTouchDevice(unsigned int deviceid) const {
- return (deviceid < touch_device_lookup_.size() &&
- touch_device_lookup_[deviceid]) ?
- touch_device_list_.find(deviceid)->second :
- false;
-}
-
-#if defined(USE_XI2_MT)
-bool TouchFactory::QuerySlotForTrackingID(uint32 tracking_id, int* slot) {
- if (!id_generator_.HasGeneratedIDFor(tracking_id))
- return false;
- *slot = static_cast<int>(id_generator_.GetGeneratedID(tracking_id));
- return true;
-}
-
-int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) {
- return id_generator_.GetGeneratedID(tracking_id);
-}
-
-void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) {
- id_generator_.ReleaseNumber(tracking_id);
-}
-#endif
-
-bool TouchFactory::IsSlotUsed(int slot) const {
- CHECK_LT(slot, kMaxTouchPoints);
- return slots_used_[slot];
-}
-
-void TouchFactory::SetSlotUsed(int slot, bool used) {
- CHECK_LT(slot, kMaxTouchPoints);
- slots_used_[slot] = used;
-}
-
-bool TouchFactory::IsTouchDevicePresent() {
- return !touch_events_disabled_ && touch_device_available_;
-}
-
-void TouchFactory::SetTouchDeviceForTest(
- const std::vector<unsigned int>& devices) {
- touch_device_lookup_.reset();
- touch_device_list_.clear();
- for (std::vector<unsigned int>::const_iterator iter = devices.begin();
- iter != devices.end(); ++iter) {
- DCHECK(*iter < touch_device_lookup_.size());
- touch_device_lookup_[*iter] = true;
- touch_device_list_[*iter] = true;
- }
- touch_device_available_ = true;
- touch_events_disabled_ = false;
-}
-
-} // namespace ui
diff --git a/ui/base/touch/touch_factory_x11.h b/ui/base/touch/touch_factory_x11.h
deleted file mode 100644
index fbbf963..0000000
--- a/ui/base/touch/touch_factory_x11.h
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_BASE_TOUCH_TOUCH_FACTORY_X11_H_
-#define UI_BASE_TOUCH_TOUCH_FACTORY_X11_H_
-
-#include <bitset>
-#include <map>
-#include <vector>
-
-#include "base/timer/timer.h"
-#include "ui/base/sequential_id_generator.h"
-#include "ui/base/ui_export.h"
-
-template <typename T> struct DefaultSingletonTraits;
-
-typedef unsigned long Cursor;
-typedef unsigned long Window;
-typedef struct _XDisplay Display;
-typedef union _XEvent XEvent;
-
-namespace ui {
-
-// Functions related to determining touch devices.
-class UI_EXPORT TouchFactory {
- private:
- TouchFactory();
- ~TouchFactory();
-
- public:
- // Returns the TouchFactory singleton.
- static TouchFactory* GetInstance();
-
- // Sets the touch devices from the command line.
- static void SetTouchDeviceListFromCommandLine();
-
- // Updates the list of devices.
- void UpdateDeviceList(Display* display);
-
- // Checks whether an XI2 event should be processed or not (i.e. if the event
- // originated from a device we are interested in).
- bool ShouldProcessXI2Event(XEvent* xevent);
-
- // Setup an X Window for XInput2 events.
- void SetupXI2ForXWindow(::Window xid);
-
- // Keeps a list of touch devices so that it is possible to determine if a
- // pointer event is a touch-event or a mouse-event. The list is reset each
- // time this is called.
- void SetTouchDeviceList(const std::vector<unsigned int>& devices);
-
- // Is the device a touch-device?
- bool IsTouchDevice(unsigned int deviceid) const;
-
- // Is the device a real multi-touch-device? (see doc. for |touch_device_list_|
- // below for more explanation.)
- bool IsMultiTouchDevice(unsigned int deviceid) const;
-
-#if defined(USE_XI2_MT)
- // Tries to find an existing slot ID mapping to tracking ID. Returns true
- // if the slot is found and it is saved in |slot|, false if no such slot
- // can be found.
- bool QuerySlotForTrackingID(uint32 tracking_id, int* slot);
-
- // Tries to find an existing slot ID mapping to tracking ID. If there
- // isn't one already, allocates a new slot ID and sets up the mapping.
- int GetSlotForTrackingID(uint32 tracking_id);
-
- // Releases the slot ID mapping to tracking ID.
- void ReleaseSlotForTrackingID(uint32 tracking_id);
-#endif
-
- // Is the slot ID currently used?
- bool IsSlotUsed(int slot) const;
-
- // Marks a slot as being used/unused.
- void SetSlotUsed(int slot, bool used);
-
- // Whether any touch device is currently present and enabled.
- bool IsTouchDevicePresent();
-
- // Sets up the device id in the list |devices| as multi-touch capable
- // devices and enables touch events processing. This function is only
- // for test purpose, and it does not query from X server.
- void SetTouchDeviceForTest(const std::vector<unsigned int>& devices);
-
- private:
- // Requirement for Singleton
- friend struct DefaultSingletonTraits<TouchFactory>;
-
- // NOTE: To keep track of touch devices, we currently maintain a lookup table
- // to quickly decide if a device is a touch device or not. We also maintain a
- // list of the touch devices. Ideally, there will be only one touch device,
- // and instead of having the lookup table and the list, there will be a single
- // identifier for the touch device. This can be completed after enough testing
- // on real touch devices.
-
- static const int kMaxDeviceNum = 128;
-
- // A quick lookup table for determining if events from the pointer device
- // should be processed.
- std::bitset<kMaxDeviceNum> pointer_device_lookup_;
-
- // A quick lookup table for determining if a device is a touch device.
- std::bitset<kMaxDeviceNum> touch_device_lookup_;
-
- // Indicates whether a touch device is currently available or not.
- bool touch_device_available_;
-
- // Indicates whether touch events are explicitly disabled.
- bool touch_events_disabled_;
-
- // The list of touch devices. For testing/debugging purposes, a single-pointer
- // device (mouse or touch screen without sufficient X/driver support for MT)
- // can sometimes be treated as a touch device. The key in the map represents
- // the device id, and the value represents if the device is multi-touch
- // capable.
- std::map<int, bool> touch_device_list_;
-
- // Maximum simultaneous touch points.
- static const int kMaxTouchPoints = 32;
-
-#if defined(USE_XI2_MT)
- SequentialIDGenerator id_generator_;
-#endif
-
- // A lookup table for slots in use for a touch event.
- std::bitset<kMaxTouchPoints> slots_used_;
-
- DISALLOW_COPY_AND_ASSIGN(TouchFactory);
-};
-
-} // namespace ui
-
-#endif // UI_BASE_TOUCH_TOUCH_FACTORY_X11_H_