| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/display/manager/display_layout.h" | 5 #include "ui/display/display_layout.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 16 #include "ui/gfx/geometry/insets.h" | 16 #include "ui/gfx/geometry/insets.h" |
| 17 | 17 |
| 18 namespace display { | 18 namespace display { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // DisplayPlacement Positions | 21 // DisplayPlacement Positions |
| 22 const char kTop[] = "top"; | 22 const char kTop[] = "top"; |
| 23 const char kRight[] = "right"; | 23 const char kRight[] = "right"; |
| 24 const char kBottom[] = "bottom"; | 24 const char kBottom[] = "bottom"; |
| 25 const char kLeft[] = "left"; | 25 const char kLeft[] = "left"; |
| 26 const char kUnknown[] = "unknown"; | 26 const char kUnknown[] = "unknown"; |
| 27 | 27 |
| 28 // The maximum value for 'offset' in DisplayLayout in case of outliers. Need | 28 // The maximum value for 'offset' in DisplayLayout in case of outliers. Need |
| 29 // to change this value in case to support even larger displays. | 29 // to change this value in case to support even larger displays. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 std::vector<int64_t>* updated_ids, | 184 std::vector<int64_t>* updated_ids, |
| 185 int minimum_offset_overlap) const { | 185 int minimum_offset_overlap) const { |
| 186 // Layout from primary, then dependent displays. | 186 // Layout from primary, then dependent displays. |
| 187 std::set<int64_t> parents; | 187 std::set<int64_t> parents; |
| 188 parents.insert(primary_id); | 188 parents.insert(primary_id); |
| 189 while (parents.size()) { | 189 while (parents.size()) { |
| 190 int64_t parent_id = *parents.begin(); | 190 int64_t parent_id = *parents.begin(); |
| 191 parents.erase(parent_id); | 191 parents.erase(parent_id); |
| 192 for (const DisplayPlacement& placement : placement_list) { | 192 for (const DisplayPlacement& placement : placement_list) { |
| 193 if (placement.parent_display_id == parent_id) { | 193 if (placement.parent_display_id == parent_id) { |
| 194 if (ApplyDisplayPlacement(placement, | 194 if (ApplyDisplayPlacement(placement, display_list, |
| 195 display_list, | |
| 196 minimum_offset_overlap) && | 195 minimum_offset_overlap) && |
| 197 updated_ids) { | 196 updated_ids) { |
| 198 updated_ids->push_back(placement.display_id); | 197 updated_ids->push_back(placement.display_id); |
| 199 } | 198 } |
| 200 parents.insert(placement.display_id); | 199 parents.insert(placement.display_id); |
| 201 } | 200 } |
| 202 } | 201 } |
| 203 } | 202 } |
| 204 } | 203 } |
| 205 | 204 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 DisplayPlacement::Position position = placement.position; | 323 DisplayPlacement::Position position = placement.position; |
| 325 | 324 |
| 326 // Ignore the offset in case the target display doesn't share edges with | 325 // Ignore the offset in case the target display doesn't share edges with |
| 327 // the parent display. | 326 // the parent display. |
| 328 int offset = placement.offset; | 327 int offset = placement.offset; |
| 329 if (position == DisplayPlacement::TOP || | 328 if (position == DisplayPlacement::TOP || |
| 330 position == DisplayPlacement::BOTTOM) { | 329 position == DisplayPlacement::BOTTOM) { |
| 331 if (placement.offset_reference == DisplayPlacement::BOTTOM_RIGHT) | 330 if (placement.offset_reference == DisplayPlacement::BOTTOM_RIGHT) |
| 332 offset = parent_bounds.width() - offset - target_bounds.width(); | 331 offset = parent_bounds.width() - offset - target_bounds.width(); |
| 333 | 332 |
| 334 offset = std::min( | 333 offset = std::min(offset, parent_bounds.width() - minimum_offset_overlap); |
| 335 offset, parent_bounds.width() - minimum_offset_overlap); | 334 offset = std::max(offset, -target_bounds.width() + minimum_offset_overlap); |
| 336 offset = std::max( | |
| 337 offset, -target_bounds.width() + minimum_offset_overlap); | |
| 338 } else { | 335 } else { |
| 339 if (placement.offset_reference == DisplayPlacement::BOTTOM_RIGHT) | 336 if (placement.offset_reference == DisplayPlacement::BOTTOM_RIGHT) |
| 340 offset = parent_bounds.height() - offset - target_bounds.height(); | 337 offset = parent_bounds.height() - offset - target_bounds.height(); |
| 341 | 338 |
| 342 offset = std::min( | 339 offset = std::min(offset, parent_bounds.height() - minimum_offset_overlap); |
| 343 offset, parent_bounds.height() - minimum_offset_overlap); | 340 offset = std::max(offset, -target_bounds.height() + minimum_offset_overlap); |
| 344 offset = std::max( | |
| 345 offset, -target_bounds.height() + minimum_offset_overlap); | |
| 346 } | 341 } |
| 347 switch (position) { | 342 switch (position) { |
| 348 case DisplayPlacement::TOP: | 343 case DisplayPlacement::TOP: |
| 349 new_target_origin.Offset(offset, -target_bounds.height()); | 344 new_target_origin.Offset(offset, -target_bounds.height()); |
| 350 break; | 345 break; |
| 351 case DisplayPlacement::RIGHT: | 346 case DisplayPlacement::RIGHT: |
| 352 new_target_origin.Offset(parent_bounds.width(), offset); | 347 new_target_origin.Offset(parent_bounds.width(), offset); |
| 353 break; | 348 break; |
| 354 case DisplayPlacement::BOTTOM: | 349 case DisplayPlacement::BOTTOM: |
| 355 new_target_origin.Offset(offset, parent_bounds.height()); | 350 new_target_origin.Offset(offset, parent_bounds.height()); |
| 356 break; | 351 break; |
| 357 case DisplayPlacement::LEFT: | 352 case DisplayPlacement::LEFT: |
| 358 new_target_origin.Offset(-target_bounds.width(), offset); | 353 new_target_origin.Offset(-target_bounds.width(), offset); |
| 359 break; | 354 break; |
| 360 } | 355 } |
| 361 | 356 |
| 362 gfx::Insets insets = target_display->GetWorkAreaInsets(); | 357 gfx::Insets insets = target_display->GetWorkAreaInsets(); |
| 363 target_display->set_bounds( | 358 target_display->set_bounds( |
| 364 gfx::Rect(new_target_origin, target_bounds.size())); | 359 gfx::Rect(new_target_origin, target_bounds.size())); |
| 365 target_display->UpdateWorkAreaFromInsets(insets); | 360 target_display->UpdateWorkAreaFromInsets(insets); |
| 366 | 361 |
| 367 return old_bounds != target_display->bounds(); | 362 return old_bounds != target_display->bounds(); |
| 368 } | 363 } |
| 369 | 364 |
| 370 } // namespace display | 365 } // namespace display |
| OLD | NEW |