diff options
Diffstat (limited to 'ui/display')
18 files changed, 81 insertions, 414 deletions
diff --git a/ui/display/BUILD.gn b/ui/display/BUILD.gn index d9fa8ec..809d200 100644 --- a/ui/display/BUILD.gn +++ b/ui/display/BUILD.gn @@ -22,8 +22,6 @@ component("display") { "chromeos/x11/native_display_delegate_x11.h", "chromeos/x11/native_display_event_dispatcher_x11.cc", "chromeos/x11/native_display_event_dispatcher_x11.h", - "chromeos/x11/touchscreen_device_manager_x11.cc", - "chromeos/x11/touchscreen_device_manager_x11.h", "display_export.h", "display_switches.cc", "display_switches.h", @@ -46,6 +44,7 @@ component("display") { "//build/config/linux:xrandr", ] deps += [ + "//ui/events:events_base", "//ui/events/platform", ] } diff --git a/ui/display/chromeos/DEPS b/ui/display/chromeos/DEPS new file mode 100644 index 0000000..fe1d98e --- /dev/null +++ b/ui/display/chromeos/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ui/events", +] diff --git a/ui/display/chromeos/display_configurator.cc b/ui/display/chromeos/display_configurator.cc index f25f05a..65c5402 100644 --- a/ui/display/chromeos/display_configurator.cc +++ b/ui/display/chromeos/display_configurator.cc @@ -11,6 +11,7 @@ #include "base/strings/stringprintf.h" #include "base/sys_info.h" #include "base/time/time.h" +#include "ui/display/chromeos/touchscreen_delegate_impl.h" #include "ui/display/display_switches.h" #include "ui/display/types/chromeos/display_mode.h" #include "ui/display/types/chromeos/display_snapshot.h" @@ -199,7 +200,7 @@ void DisplayConfigurator::Init(bool is_panel_fitting_enabled) { } if (!touchscreen_delegate_) - touchscreen_delegate_ = CreatePlatformTouchscreenDelegate(); + touchscreen_delegate_.reset(new TouchscreenDelegateImpl()); } void DisplayConfigurator::ForceInitialConfigure( diff --git a/ui/display/chromeos/display_configurator.h b/ui/display/chromeos/display_configurator.h index 33b378e..cae4086 100644 --- a/ui/display/chromeos/display_configurator.h +++ b/ui/display/chromeos/display_configurator.h @@ -257,7 +257,6 @@ class DISPLAY_EXPORT DisplayConfigurator : public NativeDisplayObserver { // Performs platform specific delegate initialization. scoped_ptr<NativeDisplayDelegate> CreatePlatformNativeDisplayDelegate(); - scoped_ptr<TouchscreenDelegate> CreatePlatformTouchscreenDelegate(); // Updates |cached_displays_| to contain currently-connected displays. Calls // |delegate_->GetDisplays()| and then does additional work, like finding the diff --git a/ui/display/chromeos/ozone/display_configurator_ozone.cc b/ui/display/chromeos/ozone/display_configurator_ozone.cc index 451a6a8..ea8f2de 100644 --- a/ui/display/chromeos/ozone/display_configurator_ozone.cc +++ b/ui/display/chromeos/ozone/display_configurator_ozone.cc @@ -4,9 +4,7 @@ #include "ui/display/chromeos/display_configurator.h" -#include "ui/display/chromeos/touchscreen_delegate_impl.h" #include "ui/display/types/chromeos/native_display_delegate.h" -#include "ui/display/types/chromeos/touchscreen_device_manager.h" #include "ui/ozone/public/ozone_platform.h" namespace ui { @@ -16,10 +14,4 @@ DisplayConfigurator::CreatePlatformNativeDisplayDelegate() { return ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); } -scoped_ptr<DisplayConfigurator::TouchscreenDelegate> -DisplayConfigurator::CreatePlatformTouchscreenDelegate() { - return scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateImpl( - ui::OzonePlatform::GetInstance()->CreateTouchscreenDeviceManager())); -} - } // namespace ui diff --git a/ui/display/chromeos/touchscreen_delegate_impl.cc b/ui/display/chromeos/touchscreen_delegate_impl.cc index dc60e3f..4114756 100644 --- a/ui/display/chromeos/touchscreen_delegate_impl.cc +++ b/ui/display/chromeos/touchscreen_delegate_impl.cc @@ -9,20 +9,20 @@ #include "ui/display/types/chromeos/display_mode.h" #include "ui/display/types/chromeos/display_snapshot.h" -#include "ui/display/types/chromeos/touchscreen_device_manager.h" +#include "ui/events/device_data_manager.h" namespace ui { -TouchscreenDelegateImpl::TouchscreenDelegateImpl( - scoped_ptr<TouchscreenDeviceManager> touch_device_manager) - : touch_device_manager_(touch_device_manager.Pass()) {} +TouchscreenDelegateImpl::TouchscreenDelegateImpl() { +} TouchscreenDelegateImpl::~TouchscreenDelegateImpl() {} void TouchscreenDelegateImpl::AssociateTouchscreens( std::vector<DisplayConfigurator::DisplayState>* displays) { std::set<int> no_match_touchscreen; - std::vector<TouchscreenDevice> devices = touch_device_manager_->GetDevices(); + const std::vector<TouchscreenDevice>& devices = + DeviceDataManager::GetInstance()->touchscreen_devices(); int internal_touchscreen = -1; for (size_t i = 0; i < devices.size(); ++i) { diff --git a/ui/display/chromeos/touchscreen_delegate_impl.h b/ui/display/chromeos/touchscreen_delegate_impl.h index 32e0b174..2ac2b18 100644 --- a/ui/display/chromeos/touchscreen_delegate_impl.h +++ b/ui/display/chromeos/touchscreen_delegate_impl.h @@ -8,17 +8,13 @@ #include "base/memory/scoped_ptr.h" #include "ui/display/chromeos/display_configurator.h" #include "ui/display/display_export.h" -#include "ui/display/types/chromeos/touchscreen_device.h" namespace ui { -class TouchscreenDeviceManager; - class DISPLAY_EXPORT TouchscreenDelegateImpl : public DisplayConfigurator::TouchscreenDelegate { public: - explicit TouchscreenDelegateImpl( - scoped_ptr<TouchscreenDeviceManager> touch_device_manager); + TouchscreenDelegateImpl(); virtual ~TouchscreenDelegateImpl(); // DisplayConfigurator::TouchscreenDelegate overrides: @@ -26,8 +22,6 @@ class DISPLAY_EXPORT TouchscreenDelegateImpl std::vector<DisplayConfigurator::DisplayState>* displays) OVERRIDE; private: - scoped_ptr<TouchscreenDeviceManager> touch_device_manager_; - DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImpl); }; diff --git a/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc b/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc index 9e80712..d480e20 100644 --- a/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc +++ b/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc @@ -10,43 +10,21 @@ #include "ui/display/chromeos/display_configurator.h" #include "ui/display/chromeos/test/test_display_snapshot.h" #include "ui/display/chromeos/touchscreen_delegate_impl.h" -#include "ui/display/types/chromeos/touchscreen_device_manager.h" +#include "ui/events/device_data_manager.h" +#include "ui/events/device_hotplug_event_observer.h" namespace ui { -namespace { - -class MockTouchscreenDeviceManager : public TouchscreenDeviceManager { - public: - MockTouchscreenDeviceManager() {} - virtual ~MockTouchscreenDeviceManager() {} - - void AddDevice(const TouchscreenDevice& device) { - devices_.push_back(device); - } - - // TouchscreenDeviceManager overrides: - virtual std::vector<TouchscreenDevice> GetDevices() OVERRIDE { - return devices_; - } - - private: - std::vector<TouchscreenDevice> devices_; - - DISALLOW_COPY_AND_ASSIGN(MockTouchscreenDeviceManager); -}; - -} // namespace - class TouchscreenDelegateImplTest : public testing::Test { public: - TouchscreenDelegateImplTest() {} + TouchscreenDelegateImplTest() { + DeviceDataManager::CreateInstance(); + device_delegate_ = DeviceDataManager::GetInstance(); + } virtual ~TouchscreenDelegateImplTest() {} virtual void SetUp() OVERRIDE { - device_manager_ = new MockTouchscreenDeviceManager(); - delegate_.reset(new TouchscreenDelegateImpl( - scoped_ptr<TouchscreenDeviceManager>(device_manager_))); + touchscreen_delegate_.reset(new TouchscreenDelegateImpl()); // Internal display will always match to internal touchscreen. If internal // touchscreen can't be detected, it is then associated to a touch screen @@ -82,6 +60,8 @@ class TouchscreenDelegateImplTest : public testing::Test { } displays_.clear(); + device_delegate_->OnTouchscreenDevicesUpdated( + std::vector<TouchscreenDevice>()); } std::vector<DisplayConfigurator::DisplayState> GetDisplayStates() { @@ -93,9 +73,9 @@ class TouchscreenDelegateImplTest : public testing::Test { } protected: - MockTouchscreenDeviceManager* device_manager_; // Not owned. - scoped_ptr<TouchscreenDelegateImpl> delegate_; + scoped_ptr<TouchscreenDelegateImpl> touchscreen_delegate_; ScopedVector<DisplaySnapshot> displays_; + DeviceHotplugEventObserver* device_delegate_; // Not owned. private: DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImplTest); @@ -104,19 +84,21 @@ class TouchscreenDelegateImplTest : public testing::Test { TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) { std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); for (size_t i = 0; i < display_states.size(); ++i) EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id); } TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) { - device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(800, 600), false)); - device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); + std::vector<TouchscreenDevice> devices; + devices.push_back(TouchscreenDevice(1, gfx::Size(800, 600), false)); + devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false)); + device_delegate_->OnTouchscreenDevicesUpdated(devices); std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); EXPECT_EQ(1, display_states[1].touch_device_id); @@ -125,11 +107,13 @@ TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) { } TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) { - device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); + std::vector<TouchscreenDevice> devices; + devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false)); + device_delegate_->OnTouchscreenDevicesUpdated(devices); std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id); @@ -138,12 +122,14 @@ TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) { } TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) { - device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(801, 600), false)); - device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1023, 768), false)); + std::vector<TouchscreenDevice> devices; + devices.push_back(TouchscreenDevice(1, gfx::Size(801, 600), false)); + devices.push_back(TouchscreenDevice(2, gfx::Size(1023, 768), false)); + device_delegate_->OnTouchscreenDevicesUpdated(devices); std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); EXPECT_EQ(1, display_states[1].touch_device_id); @@ -152,12 +138,14 @@ TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) { } TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) { - device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(1022, 768), false)); - device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(802, 600), false)); + std::vector<TouchscreenDevice> devices; + devices.push_back(TouchscreenDevice(1, gfx::Size(1022, 768), false)); + devices.push_back(TouchscreenDevice(2, gfx::Size(802, 600), false)); + device_delegate_->OnTouchscreenDevicesUpdated(devices); std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); EXPECT_EQ(1, display_states[1].touch_device_id); @@ -166,13 +154,14 @@ TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) { } TEST_F(TouchscreenDelegateImplTest, MapInternalTouchscreen) { - device_manager_->AddDevice( - TouchscreenDevice(1, gfx::Size(1920, 1080), false)); - device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(9999, 888), true)); + std::vector<TouchscreenDevice> devices; + devices.push_back(TouchscreenDevice(1, gfx::Size(1920, 1080), false)); + devices.push_back(TouchscreenDevice(2, gfx::Size(9999, 888), true)); + device_delegate_->OnTouchscreenDevicesUpdated(devices); std::vector<DisplayConfigurator::DisplayState> display_states = GetDisplayStates(); - delegate_->AssociateTouchscreens(&display_states); + touchscreen_delegate_->AssociateTouchscreens(&display_states); // Internal touchscreen is always mapped to internal display. EXPECT_EQ(2, display_states[0].touch_device_id); diff --git a/ui/display/chromeos/x11/display_configurator_x11.cc b/ui/display/chromeos/x11/display_configurator_x11.cc index 8d8fa5a..93c056c 100644 --- a/ui/display/chromeos/x11/display_configurator_x11.cc +++ b/ui/display/chromeos/x11/display_configurator_x11.cc @@ -4,9 +4,7 @@ #include "ui/display/chromeos/display_configurator.h" -#include "ui/display/chromeos/touchscreen_delegate_impl.h" #include "ui/display/chromeos/x11/native_display_delegate_x11.h" -#include "ui/display/chromeos/x11/touchscreen_device_manager_x11.h" namespace ui { @@ -15,11 +13,4 @@ DisplayConfigurator::CreatePlatformNativeDisplayDelegate() { return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateX11()); } -scoped_ptr<DisplayConfigurator::TouchscreenDelegate> -DisplayConfigurator::CreatePlatformTouchscreenDelegate() { - return scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateImpl( - scoped_ptr<TouchscreenDeviceManager>( - new TouchscreenDeviceManagerX11()))); -} - } // namespace ui diff --git a/ui/display/chromeos/x11/native_display_delegate_x11.cc b/ui/display/chromeos/x11/native_display_delegate_x11.cc index 5f19ae6..8e84538 100644 --- a/ui/display/chromeos/x11/native_display_delegate_x11.cc +++ b/ui/display/chromeos/x11/native_display_delegate_x11.cc @@ -20,7 +20,8 @@ #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" #include "ui/display/types/chromeos/native_display_observer.h" #include "ui/display/util/x11/edid_parser_x11.h" -#include "ui/events/platform/platform_event_observer.h" +#include "ui/events/device_data_manager.h" +#include "ui/events/input_device_event_observer.h" #include "ui/events/platform/platform_event_source.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/x/x11_error_tracker.h" @@ -71,6 +72,24 @@ XRRCrtcGamma* ResampleGammaRamp(XRRCrtcGamma* gamma_ramp, int gamma_ramp_size) { return resampled; } +class InputHotplugEventObserver : public InputDeviceEventObserver { + public: + explicit InputHotplugEventObserver( + NativeDisplayDelegateX11::HelperDelegate* delegate) + : delegate_(delegate) {} + virtual ~InputHotplugEventObserver() {} + + // InputDeviceEventObserver: + virtual void OnInputDeviceConfigurationChanged() OVERRIDE { + delegate_->NotifyDisplayObservers(); + } + + private: + NativeDisplayDelegateX11::HelperDelegate* delegate_; // Not owned. + + DISALLOW_COPY_AND_ASSIGN(InputHotplugEventObserver); +}; + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -103,48 +122,6 @@ class NativeDisplayDelegateX11::HelperDelegateX11 }; //////////////////////////////////////////////////////////////////////////////// -// NativeDisplayDelegateX11::PlatformEventObserverX11 - -class NativeDisplayDelegateX11::PlatformEventObserverX11 - : public PlatformEventObserver { - public: - PlatformEventObserverX11(HelperDelegate* delegate); - virtual ~PlatformEventObserverX11(); - - // PlatformEventObserverX11: - virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; - virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; - - private: - HelperDelegate* delegate_; // Not owned. - - DISALLOW_COPY_AND_ASSIGN(PlatformEventObserverX11); -}; - -NativeDisplayDelegateX11::PlatformEventObserverX11::PlatformEventObserverX11( - HelperDelegate* delegate) - : delegate_(delegate) {} - -NativeDisplayDelegateX11::PlatformEventObserverX11:: - ~PlatformEventObserverX11() {} - -void NativeDisplayDelegateX11::PlatformEventObserverX11::WillProcessEvent( - const ui::PlatformEvent& event) { - // XI_HierarchyChanged events are special. There is no window associated with - // these events. So process them directly from here. - if (event->type == GenericEvent && - event->xgeneric.evtype == XI_HierarchyChanged) { - VLOG(1) << "Received XI_HierarchyChanged event"; - // Defer configuring outputs to not stall event processing. - // This also takes care of same event being received twice. - delegate_->NotifyDisplayObservers(); - } -} - -void NativeDisplayDelegateX11::PlatformEventObserverX11::DidProcessEvent( - const ui::PlatformEvent& event) {} - -//////////////////////////////////////////////////////////////////////////////// // NativeDisplayDelegateX11 implementation: NativeDisplayDelegateX11::NativeDisplayDelegateX11() @@ -157,8 +134,11 @@ NativeDisplayDelegateX11::~NativeDisplayDelegateX11() { if (ui::PlatformEventSource::GetInstance()) { ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher( platform_event_dispatcher_.get()); - ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver( - platform_event_observer_.get()); + } + + if (input_hotplug_observer_) { + ui::DeviceDataManager::GetInstance()->RemoveObserver( + input_hotplug_observer_.get()); } STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end()); @@ -172,17 +152,14 @@ void NativeDisplayDelegateX11::Initialize() { helper_delegate_.reset(new HelperDelegateX11(this)); platform_event_dispatcher_.reset(new NativeDisplayEventDispatcherX11( helper_delegate_.get(), xrandr_event_base)); - platform_event_observer_.reset( - new PlatformEventObserverX11(helper_delegate_.get())); + input_hotplug_observer_.reset( + new InputHotplugEventObserver(helper_delegate_.get())); + ui::DeviceDataManager::GetInstance()->AddObserver( + input_hotplug_observer_.get()); if (ui::PlatformEventSource::GetInstance()) { ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher( platform_event_dispatcher_.get()); - - // We can't do this with a root window listener because XI_HierarchyChanged - // messages don't have a target window. - ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver( - platform_event_observer_.get()); } } diff --git a/ui/display/chromeos/x11/native_display_delegate_x11.h b/ui/display/chromeos/x11/native_display_delegate_x11.h index 12bed59..76a84f4 100644 --- a/ui/display/chromeos/x11/native_display_delegate_x11.h +++ b/ui/display/chromeos/x11/native_display_delegate_x11.h @@ -41,6 +41,7 @@ namespace ui { class DisplayModeX11; class DisplaySnapshotX11; +class InputDeviceEventObserver; class NativeDisplayEventDispatcherX11; class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate { @@ -96,7 +97,6 @@ class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate { private: class HelperDelegateX11; - class PlatformEventObserverX11; // Parses all the modes made available by |screen_|. void InitModes(); @@ -150,7 +150,7 @@ class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate { scoped_ptr<NativeDisplayEventDispatcherX11> platform_event_dispatcher_; // Processes X11 display events that have no X11 window associated with it. - scoped_ptr<PlatformEventObserverX11> platform_event_observer_; + scoped_ptr<InputDeviceEventObserver> input_hotplug_observer_; // List of observers waiting for display configuration change events. ObserverList<NativeDisplayObserver> observers_; diff --git a/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc b/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc deleted file mode 100644 index f613532..0000000 --- a/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2014 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/display/chromeos/x11/touchscreen_device_manager_x11.h" - -#include <X11/extensions/XInput.h> -#include <X11/extensions/XInput2.h> - -#include <cmath> -#include <set> -#include <string> -#include <vector> - -#include "base/command_line.h" -#include "base/files/file_enumerator.h" -#include "base/logging.h" -#include "base/process/launch.h" -#include "base/strings/string_util.h" -#include "base/sys_info.h" -#include "ui/gfx/x/x11_types.h" - -namespace { - -// We consider the touchscreen to be internal if it is an I2c device. -// With the device id, we can query X to get the device's dev input -// node eventXXX. Then we search all the dev input nodes registered -// by I2C devices to see if we can find eventXXX. -bool IsTouchscreenInternal(XDisplay* dpy, int device_id) { - using base::FileEnumerator; - using base::FilePath; - - if (!base::SysInfo::IsRunningOnChromeOS()) - return false; - - // Input device has a property "Device Node" pointing to its dev input node, - // e.g. Device Node (250): "/dev/input/event8" - Atom device_node = XInternAtom(dpy, "Device Node", False); - if (device_node == None) - return false; - - Atom actual_type; - int actual_format; - unsigned long nitems, bytes_after; - unsigned char* data; - XDevice* dev = XOpenDevice(dpy, device_id); - if (!dev) - return false; - - if (XGetDeviceProperty(dpy, dev, device_node, 0, 1000, False, - AnyPropertyType, &actual_type, &actual_format, - &nitems, &bytes_after, &data) != Success) { - XCloseDevice(dpy, dev); - return false; - } - base::FilePath dev_node_path(reinterpret_cast<char*>(data)); - XFree(data); - XCloseDevice(dpy, dev); - - std::string event_node = dev_node_path.BaseName().value(); - if (event_node.empty() || - !StartsWithASCII(event_node, "event", false)) { - return false; - } - - // Extract id "XXX" from "eventXXX" - std::string event_node_id = event_node.substr(5); - - // I2C input device registers its dev input node at - // /sys/bus/i2c/devices/*/input/inputXXX/eventXXX - FileEnumerator i2c_enum(FilePath(FILE_PATH_LITERAL("/sys/bus/i2c/devices/")), - false, - base::FileEnumerator::DIRECTORIES); - for (FilePath i2c_name = i2c_enum.Next(); - !i2c_name.empty(); - i2c_name = i2c_enum.Next()) { - FileEnumerator input_enum(i2c_name.Append(FILE_PATH_LITERAL("input")), - false, - base::FileEnumerator::DIRECTORIES, - FILE_PATH_LITERAL("input*")); - for (base::FilePath input = input_enum.Next(); - !input.empty(); - input = input_enum.Next()) { - if (input.BaseName().value().substr(5) == event_node_id) - return true; - } - } - - return false; -} - -} // namespace - -namespace ui { - -TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11() - : display_(gfx::GetXDisplay()) {} - -TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {} - -std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() { - std::vector<TouchscreenDevice> devices; - int num_devices = 0; - Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); - Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False); - if (valuator_x == None || valuator_y == None) - return devices; - - std::set<int> no_match_touchscreen; - XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &num_devices); - for (int i = 0; i < num_devices; i++) { - if (!info[i].enabled || info[i].use != XIFloatingSlave) - continue; // Assume all touchscreens are floating slaves - - double width = -1.0; - double height = -1.0; - bool is_direct_touch = false; - - for (int j = 0; j < info[i].num_classes; j++) { - XIAnyClassInfo* class_info = info[i].classes[j]; - - if (class_info->type == XIValuatorClass) { - XIValuatorClassInfo* valuator_info = - reinterpret_cast<XIValuatorClassInfo*>(class_info); - - if (valuator_x == valuator_info->label) { - // Ignore X axis valuator with unexpected properties - if (valuator_info->number == 0 && valuator_info->mode == Absolute && - valuator_info->min == 0.0) { - width = valuator_info->max; - } - } else if (valuator_y == valuator_info->label) { - // Ignore Y axis valuator with unexpected properties - if (valuator_info->number == 1 && valuator_info->mode == Absolute && - valuator_info->min == 0.0) { - height = valuator_info->max; - } - } - } -#if defined(USE_XI2_MT) - if (class_info->type == XITouchClass) { - XITouchClassInfo* touch_info = - reinterpret_cast<XITouchClassInfo*>(class_info); - is_direct_touch = touch_info->mode == XIDirectTouch; - } -#endif - } - - // Touchscreens should have absolute X and Y axes, and be direct touch - // devices. - if (width > 0.0 && height > 0.0 && is_direct_touch) { - bool is_internal = IsTouchscreenInternal(display_, info[i].deviceid); - devices.push_back(TouchscreenDevice(info[i].deviceid, - gfx::Size(width, height), - is_internal)); - } - } - - XIFreeDeviceInfo(info); - return devices; -} - -} // namespace ui diff --git a/ui/display/chromeos/x11/touchscreen_device_manager_x11.h b/ui/display/chromeos/x11/touchscreen_device_manager_x11.h deleted file mode 100644 index 594ef03..0000000 --- a/ui/display/chromeos/x11/touchscreen_device_manager_x11.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 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_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_ -#define UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_ - -#include "base/macros.h" -#include "ui/display/types/chromeos/touchscreen_device_manager.h" - -struct _XDisplay; -typedef struct _XDisplay Display; - -namespace ui { - -class TouchscreenDeviceManagerX11 : public TouchscreenDeviceManager { - public: - TouchscreenDeviceManagerX11(); - virtual ~TouchscreenDeviceManagerX11(); - - // TouchscreenDeviceManager implementation: - virtual std::vector<TouchscreenDevice> GetDevices() OVERRIDE; - - private: - Display* display_; - - DISALLOW_COPY_AND_ASSIGN(TouchscreenDeviceManagerX11); -}; - -} // namespace ui - -#endif // UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_ diff --git a/ui/display/display.gyp b/ui/display/display.gyp index ef2dddf..b407051 100644 --- a/ui/display/display.gyp +++ b/ui/display/display.gyp @@ -26,9 +26,6 @@ 'types/chromeos/display_snapshot.h', 'types/chromeos/native_display_delegate.h', 'types/chromeos/native_display_observer.h', - 'types/chromeos/touchscreen_device.cc', - 'types/chromeos/touchscreen_device.h', - 'types/chromeos/touchscreen_device_manager.h', 'types/display_constants.h', 'types/display_types_export.h', ], @@ -64,8 +61,6 @@ 'chromeos/x11/native_display_delegate_x11.h', 'chromeos/x11/native_display_event_dispatcher_x11.cc', 'chromeos/x11/native_display_event_dispatcher_x11.h', - 'chromeos/x11/touchscreen_device_manager_x11.cc', - 'chromeos/x11/touchscreen_device_manager_x11.h', 'display_export.h', 'display_switches.cc', 'display_switches.h', @@ -77,6 +72,7 @@ '../../build/linux/system.gyp:xext', '../../build/linux/system.gyp:xi', '../../build/linux/system.gyp:xrandr', + '../../ui/events/events.gyp:events_base', '../../ui/events/platform/events_platform.gyp:events_platform', ], }], @@ -179,6 +175,7 @@ 'display', 'display_test_util', 'display_types', + '../../ui/events/events.gyp:events_base', ], }], ], diff --git a/ui/display/types/BUILD.gn b/ui/display/types/BUILD.gn index 527bedf..8f4dfc9 100644 --- a/ui/display/types/BUILD.gn +++ b/ui/display/types/BUILD.gn @@ -11,9 +11,6 @@ component("types") { "chromeos/display_snapshot.h", "chromeos/native_display_delegate.h", "chromeos/native_display_observer.h", - "chromeos/touchscreen_device.cc", - "chromeos/touchscreen_device.h", - "chromeos/touchscreen_device_manager.h", "display_constants.h", "display_types_export.h", ] diff --git a/ui/display/types/chromeos/touchscreen_device.cc b/ui/display/types/chromeos/touchscreen_device.cc deleted file mode 100644 index 714b8f9..0000000 --- a/ui/display/types/chromeos/touchscreen_device.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2014 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/display/types/chromeos/touchscreen_device.h" - -namespace ui { - -// static -const int TouchscreenDevice::kInvalidId = 0; - -TouchscreenDevice::TouchscreenDevice(int id, - const gfx::Size& size, - bool is_internal) - : id(id), - size(size), - is_internal(is_internal) {} - -} // namespace ui diff --git a/ui/display/types/chromeos/touchscreen_device.h b/ui/display/types/chromeos/touchscreen_device.h deleted file mode 100644 index 3a471fa..0000000 --- a/ui/display/types/chromeos/touchscreen_device.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2014 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_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_H_ -#define UI_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_H_ - -#include "ui/display/types/display_types_export.h" -#include "ui/gfx/geometry/size.h" - -namespace ui { - -// Represents a Touchscreen device state. -struct DISPLAY_TYPES_EXPORT TouchscreenDevice { - static const int kInvalidId; - - TouchscreenDevice(int id, const gfx::Size& size, bool is_internal); - - // ID of the touch screen. This ID must uniquely identify the touch screen. - int id; - - // Size of the touch screen area. - gfx::Size size; - - // True if this is an internal touchscreen. - bool is_internal; -}; - -} // namespace ui - -#endif // UI_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_H_ diff --git a/ui/display/types/chromeos/touchscreen_device_manager.h b/ui/display/types/chromeos/touchscreen_device_manager.h deleted file mode 100644 index ef99c28..0000000 --- a/ui/display/types/chromeos/touchscreen_device_manager.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 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_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_MANAGER_H_ -#define UI_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_MANAGER_H_ - -#include <vector> - -#include "ui/display/types/chromeos/touchscreen_device.h" - -namespace ui { - -// Implementations are responsible for querying and returning a list of avalable -// touchscreen devices. -class DISPLAY_TYPES_EXPORT TouchscreenDeviceManager { - public: - virtual ~TouchscreenDeviceManager() {} - - // Returns a list of available touchscreen devices. This call will query the - // underlying system for an updated list of devices. - virtual std::vector<TouchscreenDevice> GetDevices() = 0; -}; - -} // namespace ui - -#endif // UI_DISPLAY_TYPES_CHROMEOS_TOUCHSCREEN_DEVICE_MANAGER_H_ |