OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/display_change_observer_chromeos.h" | 5 #include "ash/display/display_change_observer_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
13 #include "ash/display/display_info.h" | 13 #include "ash/display/display_info.h" |
14 #include "ash/display/display_layout_store.h" | 14 #include "ash/display/display_layout_store.h" |
15 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/touch/touchscreen_util.h" |
17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/compositor/dip_util.h" | 22 #include "ui/compositor/dip_util.h" |
22 #include "ui/display/types/chromeos/display_mode.h" | 23 #include "ui/display/types/chromeos/display_mode.h" |
23 #include "ui/display/types/chromeos/display_snapshot.h" | 24 #include "ui/display/types/chromeos/display_snapshot.h" |
24 #include "ui/display/util/display_util.h" | 25 #include "ui/display/util/display_util.h" |
| 26 #include "ui/events/device_data_manager.h" |
| 27 #include "ui/events/touchscreen_device.h" |
25 #include "ui/gfx/display.h" | 28 #include "ui/gfx/display.h" |
26 | 29 |
27 namespace ash { | 30 namespace ash { |
28 | 31 |
29 using ui::DisplayConfigurator; | 32 using ui::DisplayConfigurator; |
30 | 33 |
31 namespace { | 34 namespace { |
32 | 35 |
33 // The DPI threshold to determine the device scale factor. | 36 // The DPI threshold to determine the device scale factor. |
34 // DPI higher than |dpi| will use |device_scale_factor|. | 37 // DPI higher than |dpi| will use |device_scale_factor|. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 143 } |
141 } | 144 } |
142 | 145 |
143 std::sort( | 146 std::sort( |
144 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); | 147 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter()); |
145 return display_mode_list; | 148 return display_mode_list; |
146 } | 149 } |
147 | 150 |
148 DisplayChangeObserver::DisplayChangeObserver() { | 151 DisplayChangeObserver::DisplayChangeObserver() { |
149 Shell::GetInstance()->AddShellObserver(this); | 152 Shell::GetInstance()->AddShellObserver(this); |
| 153 ui::DeviceDataManager::GetInstance()->AddObserver(this); |
150 } | 154 } |
151 | 155 |
152 DisplayChangeObserver::~DisplayChangeObserver() { | 156 DisplayChangeObserver::~DisplayChangeObserver() { |
| 157 ui::DeviceDataManager::GetInstance()->RemoveObserver(this); |
153 Shell::GetInstance()->RemoveShellObserver(this); | 158 Shell::GetInstance()->RemoveShellObserver(this); |
154 } | 159 } |
155 | 160 |
156 ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( | 161 ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( |
157 const std::vector<int64>& display_ids) const { | 162 const std::vector<int64>& display_ids) const { |
158 CHECK_EQ(2U, display_ids.size()); | 163 CHECK_EQ(2U, display_ids.size()); |
159 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); | 164 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); |
160 DisplayLayout layout = Shell::GetInstance()->display_manager()-> | 165 DisplayLayout layout = Shell::GetInstance()->display_manager()-> |
161 layout_store()->GetRegisteredDisplayLayout(pair); | 166 layout_store()->GetRegisteredDisplayLayout(pair); |
162 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR : | 167 return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR : |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 220 |
216 bool has_overscan = state.display->has_overscan(); | 221 bool has_overscan = state.display->has_overscan(); |
217 int64 id = state.display->display_id(); | 222 int64 id = state.display->display_id(); |
218 ids.insert(id); | 223 ids.insert(id); |
219 | 224 |
220 displays.push_back(DisplayInfo(id, name, has_overscan)); | 225 displays.push_back(DisplayInfo(id, name, has_overscan)); |
221 DisplayInfo& new_info = displays.back(); | 226 DisplayInfo& new_info = displays.back(); |
222 new_info.set_device_scale_factor(device_scale_factor); | 227 new_info.set_device_scale_factor(device_scale_factor); |
223 new_info.SetBounds(display_bounds); | 228 new_info.SetBounds(display_bounds); |
224 new_info.set_native(true); | 229 new_info.set_native(true); |
225 new_info.set_touch_support(state.touch_device_id == 0 ? | |
226 gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : | |
227 gfx::Display::TOUCH_SUPPORT_AVAILABLE); | |
228 new_info.set_touch_device_id(state.touch_device_id); | |
229 new_info.set_is_aspect_preserving_scaling( | 230 new_info.set_is_aspect_preserving_scaling( |
230 state.display->is_aspect_preserving_scaling()); | 231 state.display->is_aspect_preserving_scaling()); |
231 | 232 |
232 std::vector<DisplayMode> display_modes = | 233 std::vector<DisplayMode> display_modes = |
233 (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) ? | 234 (state.display->type() == ui::DISPLAY_CONNECTION_TYPE_INTERNAL) ? |
234 GetInternalDisplayModeList(new_info, state) : | 235 GetInternalDisplayModeList(new_info, state) : |
235 GetExternalDisplayModeList(state); | 236 GetExternalDisplayModeList(state); |
236 new_info.set_display_modes(display_modes); | 237 new_info.set_display_modes(display_modes); |
237 | 238 |
238 new_info.set_available_color_profiles( | 239 new_info.set_available_color_profiles( |
239 Shell::GetInstance() | 240 Shell::GetInstance() |
240 ->display_configurator() | 241 ->display_configurator() |
241 ->GetAvailableColorCalibrationProfiles(id)); | 242 ->GetAvailableColorCalibrationProfiles(id)); |
242 } | 243 } |
243 | 244 |
| 245 AssociateTouchscreens(&displays); |
244 // DisplayManager can be null during the boot. | 246 // DisplayManager can be null during the boot. |
245 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); | 247 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
246 } | 248 } |
247 | 249 |
248 void DisplayChangeObserver::OnAppTerminating() { | 250 void DisplayChangeObserver::OnAppTerminating() { |
249 #if defined(USE_ASH) | 251 #if defined(USE_ASH) |
250 // Stop handling display configuration events once the shutdown | 252 // Stop handling display configuration events once the shutdown |
251 // process starts. crbug.com/177014. | 253 // process starts. crbug.com/177014. |
252 Shell::GetInstance()->display_configurator()->PrepareForExit(); | 254 Shell::GetInstance()->display_configurator()->PrepareForExit(); |
253 #endif | 255 #endif |
254 } | 256 } |
255 | 257 |
256 // static | 258 // static |
257 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { | 259 float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { |
258 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { | 260 for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { |
259 if (dpi > kThresholdTable[i].dpi) | 261 if (dpi > kThresholdTable[i].dpi) |
260 return kThresholdTable[i].device_scale_factor; | 262 return kThresholdTable[i].device_scale_factor; |
261 } | 263 } |
262 return 1.0f; | 264 return 1.0f; |
263 } | 265 } |
264 | 266 |
| 267 void DisplayChangeObserver::OnInputDeviceConfigurationChanged() { |
| 268 std::vector<DisplayInfo> display_infos; |
| 269 DisplayManager* display_manager = |
| 270 ash::Shell::GetInstance()->display_manager(); |
| 271 const std::vector<gfx::Display>& displays = display_manager->displays(); |
| 272 // Reuse the current state in DisplayManager and re-associate the displays |
| 273 // with the touchscreens. |
| 274 for (size_t i = 0; i < displays.size(); ++i) { |
| 275 DisplayInfo display = display_manager->GetDisplayInfo(displays[i].id()); |
| 276 // Unset the touchscreen configuration since we'll be rematching them from |
| 277 // scratch. |
| 278 display.set_touch_device_id(ui::TouchscreenDevice::kInvalidId); |
| 279 display.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNKNOWN); |
| 280 |
| 281 display_infos.push_back(display); |
| 282 } |
| 283 |
| 284 AssociateTouchscreens(&display_infos); |
| 285 display_manager->OnNativeDisplaysChanged(display_infos); |
| 286 } |
| 287 |
265 } // namespace ash | 288 } // namespace ash |
OLD | NEW |