Chromium Code Reviews| Index: ash/display/display_change_observer_chromeos.cc |
| diff --git a/ash/display/display_change_observer_chromeos.cc b/ash/display/display_change_observer_chromeos.cc |
| index 54b39dce7c9e4d1237eaca3b4250dae863df0371..0d93df146ef07fcc4f480ef8cc854aa059a4d471 100644 |
| --- a/ash/display/display_change_observer_chromeos.cc |
| +++ b/ash/display/display_change_observer_chromeos.cc |
| @@ -22,6 +22,8 @@ |
| #include "ui/display/types/chromeos/display_mode.h" |
| #include "ui/display/types/chromeos/display_snapshot.h" |
| #include "ui/display/util/display_util.h" |
| +#include "ui/events/device_data_manager.h" |
| +#include "ui/events/touchscreen_device.h" |
| #include "ui/gfx/display.h" |
| namespace ash { |
| @@ -48,6 +50,76 @@ struct DisplayModeSorter { |
| } |
| }; |
| +gfx::Size GetNativeModeSize(const DisplayInfo& display) { |
| + const std::vector<DisplayMode>& modes = display.display_modes(); |
| + for (size_t i = 0; i < modes.size(); ++i) { |
| + if (modes[i].native) { |
|
Daniel Erat
2014/06/17 21:59:18
nit: omit curly brackets on this one
dnicoara
2014/06/20 17:01:05
Done.
|
| + return modes[i].size; |
| + } |
| + } |
| + |
| + return gfx::Size(); |
| +} |
| + |
| +void AssociateTouchscreens(std::vector<DisplayInfo>* displays) { |
| + std::set<int> no_match_touchscreen; |
| + std::vector<ui::TouchscreenDevice> devices = |
| + ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices(); |
| + for (size_t i = 0; i < devices.size(); ++i) { |
| + bool found_mapping = false; |
| + for (size_t j = 0; j < displays->size(); ++j) { |
| + DisplayInfo* state = &(*displays)[j]; |
| + gfx::Size native_size = GetNativeModeSize(*state);; |
|
Daniel Erat
2014/06/17 21:59:18
nit: const
dnicoara
2014/06/20 17:01:05
Done.
|
| + if (state->touch_support() == gfx::Display::TOUCH_SUPPORT_AVAILABLE || |
| + native_size.IsEmpty()) |
| + continue; |
| + |
| + // Allow 1 pixel difference between screen and touchscreen |
| + // resolutions. Because in some cases for monitor resolution |
| + // 1024x768 touchscreen's resolution would be 1024x768, but for |
| + // some 1023x767. It really depends on touchscreen's firmware |
| + // configuration. |
| + if (std::abs(native_size.width() - devices[i].size.width()) <= 1 && |
| + std::abs(native_size.height() - devices[i].size.height()) <= 1) { |
| + state->set_touch_device_id(devices[i].id); |
| + |
| + VLOG(2) << "Found touchscreen for display " << state->id() |
| + << " touch_device_id " << state->touch_device_id() << " size " |
| + << devices[i].size.ToString(); |
| + found_mapping = true; |
| + break; |
| + } |
| + } |
| + |
| + if (!found_mapping) { |
| + no_match_touchscreen.insert(devices[i].id); |
| + VLOG(2) << "No matching display for touch_device_id " |
| + << devices[i].id << " size " << devices[i].size.ToString(); |
| + } |
| + } |
| + |
| + // Sometimes we can't find a matching screen for the touchscreen, e.g. |
| + // due to the touchscreen's reporting range having no correlation with the |
| + // screen's resolution. In this case, we arbitrarily assign unmatched |
| + // touchscreens to unmatched screens. |
| + for (std::set<int>::iterator it = no_match_touchscreen.begin(); |
| + it != no_match_touchscreen.end(); |
| + ++it) { |
| + for (size_t i = 0; i < displays->size(); ++i) { |
| + DisplayInfo* state = &(*displays)[i]; |
| + if (state->id() != gfx::Display::InternalDisplayId() && |
| + !GetNativeModeSize(*state).IsEmpty() && |
| + state->touch_support() == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE) { |
| + state->set_touch_device_id(*it); |
| + VLOG(2) << "Arbitrarily matching touchscreen " |
| + << state->touch_device_id() << " to display " |
| + << state->id(); |
| + break; |
| + } |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| // static |
| @@ -90,9 +162,11 @@ std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList( |
| DisplayChangeObserver::DisplayChangeObserver() { |
| Shell::GetInstance()->AddShellObserver(this); |
| + ui::DeviceDataManager::GetInstance()->AddObserver(this); |
| } |
| DisplayChangeObserver::~DisplayChangeObserver() { |
| + ui::DeviceDataManager::GetInstance()->RemoveObserver(this); |
| Shell::GetInstance()->RemoveShellObserver(this); |
| } |
| @@ -160,10 +234,6 @@ void DisplayChangeObserver::OnDisplayModeChanged( |
| new_info.SetBounds(display_bounds); |
| new_info.set_native(true); |
| new_info.set_display_modes(display_modes); |
| - new_info.set_touch_support(state.touch_device_id == 0 ? |
| - gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : |
| - gfx::Display::TOUCH_SUPPORT_AVAILABLE); |
| - new_info.set_touch_device_id(state.touch_device_id); |
| new_info.set_is_aspect_preserving_scaling( |
| state.display->is_aspect_preserving_scaling()); |
| new_info.set_available_color_profiles( |
| @@ -172,6 +242,7 @@ void DisplayChangeObserver::OnDisplayModeChanged( |
| ->GetAvailableColorCalibrationProfiles(id)); |
| } |
| + AssociateTouchscreens(&displays); |
| // DisplayManager can be null during the boot. |
| Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| } |
| @@ -184,4 +255,25 @@ void DisplayChangeObserver::OnAppTerminating() { |
| #endif |
| } |
| +void DisplayChangeObserver::OnInputDeviceConfigurationChanged() { |
| + std::vector<DisplayInfo> display_infos; |
| + DisplayManager* display_manager = |
| + ash::Shell::GetInstance()->display_manager(); |
| + const std::vector<gfx::Display>& displays = display_manager->displays(); |
| + // Reuse the current state in DisplayManager and re-associate the displays |
| + // with the touchscreens. |
| + for (size_t i = 0; i < displays.size(); ++i) { |
| + DisplayInfo display = display_manager->GetDisplayInfo(displays[i].id()); |
|
dnicoara
2014/06/13 18:47:58
Bleh, I hate that we need to get the gfx::Displays
|
| + // Unset the touchscreen configuration since we'll be rematching them from |
| + // scratch. |
| + display.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNAVAILABLE); |
| + display.set_touch_device_id(ui::TouchscreenDevice::kInvalidId); |
| + |
| + display_infos.push_back(display); |
| + } |
| + |
| + AssociateTouchscreens(&display_infos); |
| + display_manager->OnNativeDisplaysChanged(display_infos); |
| +} |
| + |
| } // namespace ash |