| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_util.h" | 5 #include "ash/display/display_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 gfx::Rect* b_edge_in_screen) { | 228 gfx::Rect* b_edge_in_screen) { |
| 229 const gfx::Rect& a_bounds = a_display.bounds(); | 229 const gfx::Rect& a_bounds = a_display.bounds(); |
| 230 const gfx::Rect& b_bounds = b_display.bounds(); | 230 const gfx::Rect& b_bounds = b_display.bounds(); |
| 231 | 231 |
| 232 // Find touching side. | 232 // Find touching side. |
| 233 int rx = std::max(a_bounds.x(), b_bounds.x()); | 233 int rx = std::max(a_bounds.x(), b_bounds.x()); |
| 234 int ry = std::max(a_bounds.y(), b_bounds.y()); | 234 int ry = std::max(a_bounds.y(), b_bounds.y()); |
| 235 int rr = std::min(a_bounds.right(), b_bounds.right()); | 235 int rr = std::min(a_bounds.right(), b_bounds.right()); |
| 236 int rb = std::min(a_bounds.bottom(), b_bounds.bottom()); | 236 int rb = std::min(a_bounds.bottom(), b_bounds.bottom()); |
| 237 | 237 |
| 238 DisplayPlacement::Position position; | 238 display::DisplayPlacement::Position position; |
| 239 if ((rb - ry) == 0) { | 239 if ((rb - ry) == 0) { |
| 240 // top bottom | 240 // top bottom |
| 241 if (a_bounds.bottom() == b_bounds.y()) { | 241 if (a_bounds.bottom() == b_bounds.y()) { |
| 242 position = DisplayPlacement::BOTTOM; | 242 position = display::DisplayPlacement::BOTTOM; |
| 243 } else if (a_bounds.y() == b_bounds.bottom()) { | 243 } else if (a_bounds.y() == b_bounds.bottom()) { |
| 244 position = DisplayPlacement::TOP; | 244 position = display::DisplayPlacement::TOP; |
| 245 } else { | 245 } else { |
| 246 return false; | 246 return false; |
| 247 } | 247 } |
| 248 } else { | 248 } else { |
| 249 // left right | 249 // left right |
| 250 if (a_bounds.right() == b_bounds.x()) { | 250 if (a_bounds.right() == b_bounds.x()) { |
| 251 position = DisplayPlacement::RIGHT; | 251 position = display::DisplayPlacement::RIGHT; |
| 252 } else if (a_bounds.x() == b_bounds.right()) { | 252 } else if (a_bounds.x() == b_bounds.right()) { |
| 253 position = DisplayPlacement::LEFT; | 253 position = display::DisplayPlacement::LEFT; |
| 254 } else { | 254 } else { |
| 255 DCHECK_NE(rr, rx); | 255 DCHECK_NE(rr, rx); |
| 256 return false; | 256 return false; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 switch (position) { | 260 switch (position) { |
| 261 case DisplayPlacement::TOP: | 261 case display::DisplayPlacement::TOP: |
| 262 case DisplayPlacement::BOTTOM: { | 262 case display::DisplayPlacement::BOTTOM: { |
| 263 int left = std::max(a_bounds.x(), b_bounds.x()); | 263 int left = std::max(a_bounds.x(), b_bounds.x()); |
| 264 int right = std::min(a_bounds.right(), b_bounds.right()); | 264 int right = std::min(a_bounds.right(), b_bounds.right()); |
| 265 if (position == DisplayPlacement::TOP) { | 265 if (position == display::DisplayPlacement::TOP) { |
| 266 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1); | 266 a_edge_in_screen->SetRect(left, a_bounds.y(), right - left, 1); |
| 267 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1); | 267 b_edge_in_screen->SetRect(left, b_bounds.bottom() - 1, right - left, 1); |
| 268 } else { | 268 } else { |
| 269 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1); | 269 a_edge_in_screen->SetRect(left, a_bounds.bottom() - 1, right - left, 1); |
| 270 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1); | 270 b_edge_in_screen->SetRect(left, b_bounds.y(), right - left, 1); |
| 271 } | 271 } |
| 272 break; | 272 break; |
| 273 } | 273 } |
| 274 case DisplayPlacement::LEFT: | 274 case display::DisplayPlacement::LEFT: |
| 275 case DisplayPlacement::RIGHT: { | 275 case display::DisplayPlacement::RIGHT: { |
| 276 int top = std::max(a_bounds.y(), b_bounds.y()); | 276 int top = std::max(a_bounds.y(), b_bounds.y()); |
| 277 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom()); | 277 int bottom = std::min(a_bounds.bottom(), b_bounds.bottom()); |
| 278 if (position == DisplayPlacement::LEFT) { | 278 if (position == display::DisplayPlacement::LEFT) { |
| 279 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top); | 279 a_edge_in_screen->SetRect(a_bounds.x(), top, 1, bottom - top); |
| 280 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top); | 280 b_edge_in_screen->SetRect(b_bounds.right() - 1, top, 1, bottom - top); |
| 281 } else { | 281 } else { |
| 282 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top); | 282 a_edge_in_screen->SetRect(a_bounds.right() - 1, top, 1, bottom - top); |
| 283 b_edge_in_screen->SetRect(b_bounds.x(), top, 1, bottom - top); | 283 b_edge_in_screen->SetRect(b_bounds.x(), top, 1, bottom - top); |
| 284 } | 284 } |
| 285 break; | 285 break; |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 return true; | 288 return true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, | 368 int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, |
| 369 const gfx::Point& point_in_screen) { | 369 const gfx::Point& point_in_screen) { |
| 370 auto iter = std::find_if(displays.begin(), displays.end(), | 370 auto iter = std::find_if(displays.begin(), displays.end(), |
| 371 [point_in_screen](const gfx::Display& display) { | 371 [point_in_screen](const gfx::Display& display) { |
| 372 return display.bounds().Contains(point_in_screen); | 372 return display.bounds().Contains(point_in_screen); |
| 373 }); | 373 }); |
| 374 return iter == displays.end() ? -1 : (iter - displays.begin()); | 374 return iter == displays.end() ? -1 : (iter - displays.begin()); |
| 375 } | 375 } |
| 376 | 376 |
| 377 DisplayIdList CreateDisplayIdList(const DisplayList& list) { | 377 display::DisplayIdList CreateDisplayIdList(const display::DisplayList& list) { |
| 378 return GenerateDisplayIdList( | 378 return GenerateDisplayIdList( |
| 379 list.begin(), list.end(), | 379 list.begin(), list.end(), |
| 380 [](const gfx::Display& display) { return display.id(); }); | 380 [](const gfx::Display& display) { return display.id(); }); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void SortDisplayIdList(DisplayIdList* ids) { | 383 void SortDisplayIdList(display::DisplayIdList* ids) { |
| 384 std::sort(ids->begin(), ids->end(), | 384 std::sort(ids->begin(), ids->end(), |
| 385 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); | 385 [](int64_t a, int64_t b) { return CompareDisplayIds(a, b); }); |
| 386 } | 386 } |
| 387 | 387 |
| 388 std::string DisplayIdListToString(const ash::DisplayIdList& list) { | 388 std::string DisplayIdListToString(const display::DisplayIdList& list) { |
| 389 std::stringstream s; | 389 std::stringstream s; |
| 390 const char* sep = ""; | 390 const char* sep = ""; |
| 391 for (int64_t id : list) { | 391 for (int64_t id : list) { |
| 392 s << sep << id; | 392 s << sep << id; |
| 393 sep = ","; | 393 sep = ","; |
| 394 } | 394 } |
| 395 return s.str(); | 395 return s.str(); |
| 396 } | 396 } |
| 397 | 397 |
| 398 bool CompareDisplayIds(int64_t id1, int64_t id2) { | 398 bool CompareDisplayIds(int64_t id1, int64_t id2) { |
| 399 DCHECK_NE(id1, id2); | 399 DCHECK_NE(id1, id2); |
| 400 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | 400 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID |
| 401 // in edid_parser.cc. | 401 // in edid_parser.cc. |
| 402 int index_1 = id1 & 0xFF; | 402 int index_1 = id1 & 0xFF; |
| 403 int index_2 = id2 & 0xFF; | 403 int index_2 = id2 & 0xFF; |
| 404 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | 404 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; |
| 405 return gfx::Display::IsInternalDisplayId(id1) || | 405 return gfx::Display::IsInternalDisplayId(id1) || |
| 406 (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); | 406 (index_1 < index_2 && !gfx::Display::IsInternalDisplayId(id2)); |
| 407 } | 407 } |
| 408 | 408 |
| 409 } // namespace ash | 409 } // namespace ash |
| OLD | NEW |