| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/test/multi_display_manager_test_api.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "ash/display/multi_display_manager.h" | |
| 10 #include "ash/shell.h" | |
| 11 #include "base/string_split.h" | |
| 12 #include "ui/aura/root_window.h" | |
| 13 #include "ui/gfx/display.h" | |
| 14 | |
| 15 namespace ash { | |
| 16 namespace test { | |
| 17 namespace { | |
| 18 | |
| 19 std::vector<gfx::Display> CreateDisplaysFromString( | |
| 20 const std::string specs) { | |
| 21 std::vector<gfx::Display> displays; | |
| 22 std::vector<std::string> parts; | |
| 23 base::SplitString(specs, ',', &parts); | |
| 24 for (std::vector<std::string>::const_iterator iter = parts.begin(); | |
| 25 iter != parts.end(); ++iter) { | |
| 26 displays.push_back(aura::DisplayManager::CreateDisplayFromSpec(*iter)); | |
| 27 } | |
| 28 return displays; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 MultiDisplayManagerTestApi::MultiDisplayManagerTestApi( | |
| 34 internal::MultiDisplayManager* display_manager) | |
| 35 : display_manager_(display_manager) { | |
| 36 } | |
| 37 | |
| 38 MultiDisplayManagerTestApi::~MultiDisplayManagerTestApi() {} | |
| 39 | |
| 40 void MultiDisplayManagerTestApi::UpdateDisplay( | |
| 41 const std::string& display_specs) { | |
| 42 std::vector<gfx::Display> displays = CreateDisplaysFromString(display_specs); | |
| 43 display_manager_->SetDisplayIdsForTest(&displays); | |
| 44 display_manager_->OnNativeDisplaysChanged(displays); | |
| 45 | |
| 46 bool is_host_origin_set = false; | |
| 47 for (size_t i = 0; i < displays.size(); ++i) { | |
| 48 if (displays[i].bounds_in_pixel().origin() != gfx::Point(0, 0)) { | |
| 49 is_host_origin_set = true; | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 // On non-testing environment, when a secondary display is connected, a new | |
| 55 // native (i.e. X) window for the display is always created below the | |
| 56 // previous one for GPU performance reasons. Try to emulate the behavior | |
| 57 // unless host origins are explicitly set. | |
| 58 if (!is_host_origin_set) { | |
| 59 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 60 int next_y = 0; | |
| 61 for (size_t i = 0; i < root_windows.size(); ++i) { | |
| 62 const gfx::Size size = root_windows[i]->GetHostSize(); | |
| 63 root_windows[i]->SetHostBounds(gfx::Rect(gfx::Point(0, next_y), size)); | |
| 64 next_y += size.height(); | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 | |
| 70 } // namespace test | |
| 71 } // namespace ash | |
| OLD | NEW |