OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // changing the settings while the system is still configurating | 75 // changing the settings while the system is still configurating |
76 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| | 76 // displays. It will be overriden by |kAfterDisplayChangeThrottleTimeoutMs| |
77 // when the display change happens, so the actual timeout is much shorter. | 77 // when the display change happens, so the actual timeout is much shorter. |
78 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; | 78 const int64 kAfterDisplayChangeThrottleTimeoutMs = 500; |
79 const int64 kCycleDisplayThrottleTimeoutMs = 4000; | 79 const int64 kCycleDisplayThrottleTimeoutMs = 4000; |
80 const int64 kSwapDisplayThrottleTimeoutMs = 500; | 80 const int64 kSwapDisplayThrottleTimeoutMs = 500; |
81 | 81 |
82 // Persistent key names | 82 // Persistent key names |
83 const char kPositionKey[] = "position"; | 83 const char kPositionKey[] = "position"; |
84 const char kOffsetKey[] = "offset"; | 84 const char kOffsetKey[] = "offset"; |
| 85 const char kMirroredKey[] = "mirrored"; |
85 | 86 |
86 bool GetPositionFromString(const base::StringPiece& position, | 87 bool GetPositionFromString(const base::StringPiece& position, |
87 DisplayLayout::Position* field) { | 88 DisplayLayout::Position* field) { |
88 if (position == "top") { | 89 if (position == "top") { |
89 *field = DisplayLayout::TOP; | 90 *field = DisplayLayout::TOP; |
90 return true; | 91 return true; |
91 } else if (position == "bottom") { | 92 } else if (position == "bottom") { |
92 *field = DisplayLayout::BOTTOM; | 93 *field = DisplayLayout::BOTTOM; |
93 return true; | 94 return true; |
94 } else if (position == "right") { | 95 } else if (position == "right") { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 #endif | 199 #endif |
199 RotateRootWindow(root, display, info); | 200 RotateRootWindow(root, display, info); |
200 } | 201 } |
201 | 202 |
202 } // namespace | 203 } // namespace |
203 | 204 |
204 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
205 // DisplayLayout | 206 // DisplayLayout |
206 | 207 |
207 // static | 208 // static |
208 DisplayLayout DisplayLayout::FromInts(int position, int offsets) { | 209 DisplayLayout DisplayLayout::FromInts(int position, int offsets, bool mirror) { |
209 return DisplayLayout(static_cast<Position>(position), offsets); | 210 return DisplayLayout(static_cast<Position>(position), offsets, mirror); |
210 } | 211 } |
211 | 212 |
212 DisplayLayout::DisplayLayout() | 213 DisplayLayout::DisplayLayout() |
213 : position(RIGHT), | 214 : position(RIGHT), |
214 offset(0) {} | 215 offset(0), |
| 216 mirrored(false) {} |
215 | 217 |
216 DisplayLayout::DisplayLayout(DisplayLayout::Position position, int offset) | 218 DisplayLayout::DisplayLayout(DisplayLayout::Position position, |
| 219 int offset, |
| 220 bool mirrored) |
217 : position(position), | 221 : position(position), |
218 offset(offset) { | 222 offset(offset), |
| 223 mirrored(mirrored) { |
219 DCHECK_LE(TOP, position); | 224 DCHECK_LE(TOP, position); |
220 DCHECK_GE(LEFT, position); | 225 DCHECK_GE(LEFT, position); |
221 | 226 |
222 // Set the default value to |position| in case position is invalid. DCHECKs | 227 // Set the default value to |position| in case position is invalid. DCHECKs |
223 // above doesn't stop in Release builds. | 228 // above doesn't stop in Release builds. |
224 if (TOP > position || LEFT < position) | 229 if (TOP > position || LEFT < position) |
225 this->position = RIGHT; | 230 this->position = RIGHT; |
226 | 231 |
227 DCHECK_GE(kMaxValidOffset, abs(offset)); | 232 DCHECK_GE(kMaxValidOffset, abs(offset)); |
228 } | 233 } |
229 | 234 |
230 DisplayLayout DisplayLayout::Invert() const { | 235 DisplayLayout DisplayLayout::Invert() const { |
231 Position inverted_position = RIGHT; | 236 Position inverted_position = RIGHT; |
232 switch (position) { | 237 switch (position) { |
233 case TOP: | 238 case TOP: |
234 inverted_position = BOTTOM; | 239 inverted_position = BOTTOM; |
235 break; | 240 break; |
236 case BOTTOM: | 241 case BOTTOM: |
237 inverted_position = TOP; | 242 inverted_position = TOP; |
238 break; | 243 break; |
239 case RIGHT: | 244 case RIGHT: |
240 inverted_position = LEFT; | 245 inverted_position = LEFT; |
241 break; | 246 break; |
242 case LEFT: | 247 case LEFT: |
243 inverted_position = RIGHT; | 248 inverted_position = RIGHT; |
244 break; | 249 break; |
245 } | 250 } |
246 return DisplayLayout(inverted_position, -offset); | 251 return DisplayLayout(inverted_position, -offset, mirrored); |
247 } | 252 } |
248 | 253 |
249 // static | 254 // static |
250 bool DisplayLayout::ConvertFromValue(const base::Value& value, | 255 bool DisplayLayout::ConvertFromValue(const base::Value& value, |
251 DisplayLayout* layout) { | 256 DisplayLayout* layout) { |
252 base::JSONValueConverter<DisplayLayout> converter; | 257 base::JSONValueConverter<DisplayLayout> converter; |
253 return converter.Convert(value, layout); | 258 return converter.Convert(value, layout); |
254 } | 259 } |
255 | 260 |
256 // static | 261 // static |
257 bool DisplayLayout::ConvertToValue(const DisplayLayout& layout, | 262 bool DisplayLayout::ConvertToValue(const DisplayLayout& layout, |
258 base::Value* value) { | 263 base::Value* value) { |
259 base::DictionaryValue* dict_value = NULL; | 264 base::DictionaryValue* dict_value = NULL; |
260 if (!value->GetAsDictionary(&dict_value) || dict_value == NULL) | 265 if (!value->GetAsDictionary(&dict_value) || dict_value == NULL) |
261 return false; | 266 return false; |
262 | 267 |
263 const std::string position_str = GetStringFromPosition(layout.position); | 268 const std::string position_str = GetStringFromPosition(layout.position); |
264 dict_value->SetString(kPositionKey, position_str); | 269 dict_value->SetString(kPositionKey, position_str); |
265 dict_value->SetInteger(kOffsetKey, layout.offset); | 270 dict_value->SetInteger(kOffsetKey, layout.offset); |
| 271 dict_value->SetBoolean(kMirroredKey, layout.mirrored); |
266 return true; | 272 return true; |
267 } | 273 } |
268 | 274 |
269 std::string DisplayLayout::ToString() const { | 275 std::string DisplayLayout::ToString() const { |
270 const std::string position_str = GetStringFromPosition(position); | 276 const std::string position_str = GetStringFromPosition(position); |
271 return base::StringPrintf("%s, %d", position_str.c_str(), offset); | 277 return base::StringPrintf("%s, %d", position_str.c_str(), offset); |
272 } | 278 } |
273 | 279 |
274 // static | 280 // static |
275 void DisplayLayout::RegisterJSONConverter( | 281 void DisplayLayout::RegisterJSONConverter( |
276 base::JSONValueConverter<DisplayLayout>* converter) { | 282 base::JSONValueConverter<DisplayLayout>* converter) { |
277 converter->RegisterCustomField<Position>( | 283 converter->RegisterCustomField<Position>( |
278 kPositionKey, &DisplayLayout::position, &GetPositionFromString); | 284 kPositionKey, &DisplayLayout::position, &GetPositionFromString); |
279 converter->RegisterIntField(kOffsetKey, &DisplayLayout::offset); | 285 converter->RegisterIntField(kOffsetKey, &DisplayLayout::offset); |
| 286 converter->RegisterBoolField(kMirroredKey, &DisplayLayout::mirrored); |
280 } | 287 } |
281 | 288 |
282 //////////////////////////////////////////////////////////////////////////////// | 289 //////////////////////////////////////////////////////////////////////////////// |
283 // DisplayChangeLimiter | 290 // DisplayChangeLimiter |
284 | 291 |
285 DisplayController::DisplayChangeLimiter::DisplayChangeLimiter() | 292 DisplayController::DisplayChangeLimiter::DisplayChangeLimiter() |
286 : throttle_timeout_(base::Time::Now()) { | 293 : throttle_timeout_(base::Time::Now()) { |
287 } | 294 } |
288 | 295 |
289 void DisplayController::DisplayChangeLimiter::SetThrottleTimeout( | 296 void DisplayController::DisplayChangeLimiter::SetThrottleTimeout( |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 secondary_display->set_bounds( | 870 secondary_display->set_bounds( |
864 gfx::Rect(new_secondary_origin, secondary_bounds.size())); | 871 gfx::Rect(new_secondary_origin, secondary_bounds.size())); |
865 secondary_display->UpdateWorkAreaFromInsets(insets); | 872 secondary_display->UpdateWorkAreaFromInsets(insets); |
866 } | 873 } |
867 | 874 |
868 void DisplayController::NotifyDisplayConfigurationChanging() { | 875 void DisplayController::NotifyDisplayConfigurationChanging() { |
869 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 876 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
870 } | 877 } |
871 | 878 |
872 void DisplayController::NotifyDisplayConfigurationChanged() { | 879 void DisplayController::NotifyDisplayConfigurationChanged() { |
| 880 internal::DisplayManager* display_manager = GetDisplayManager(); |
| 881 if (display_manager->num_connected_displays() > 1) { |
| 882 bool mirrored = display_manager->IsMirrored(); |
| 883 DisplayIdPair pair = mirrored ? |
| 884 std::make_pair(GetPrimaryDisplay().id(), |
| 885 display_manager->mirrored_display_id()) : |
| 886 GetCurrentDisplayIdPair(); |
| 887 paired_layouts_[pair].mirrored = mirrored; |
| 888 } |
873 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); | 889 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); |
874 } | 890 } |
875 | 891 |
876 void DisplayController::RegisterLayoutForDisplayIdPairInternal( | 892 void DisplayController::RegisterLayoutForDisplayIdPairInternal( |
877 int64 id1, | 893 int64 id1, |
878 int64 id2, | 894 int64 id2, |
879 const DisplayLayout& layout, | 895 const DisplayLayout& layout, |
880 bool override) { | 896 bool override) { |
881 DisplayIdPair pair = std::make_pair(id1, id2); | 897 DisplayIdPair pair = std::make_pair(id1, id2); |
882 if (override || paired_layouts_.find(pair) == paired_layouts_.end()) | 898 if (override || paired_layouts_.find(pair) == paired_layouts_.end()) |
883 paired_layouts_[pair] = layout; | 899 paired_layouts_[pair] = layout; |
884 } | 900 } |
885 | 901 |
886 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 902 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
887 #if defined(OS_CHROMEOS) | 903 #if defined(OS_CHROMEOS) |
888 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 904 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); |
889 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 905 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
890 #endif | 906 #endif |
891 } | 907 } |
892 | 908 |
893 } // namespace ash | 909 } // namespace ash |
OLD | NEW |