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/display_manager_test_api.h" 6 7 #include <vector> 8 9 #include "ash/display/display_info.h" 10 #include "ash/display/display_manager.h" 11 #include "ash/shell.h" 12 #include "base/strings/string_split.h" 13 #include "ui/aura/root_window.h" 14 #include "ui/gfx/display.h" 15 16 namespace ash { 17 namespace test { 18 typedef std::vector<gfx::Display> DisplayList; 19 typedef internal::DisplayInfo DisplayInfo; 20 typedef std::vector<DisplayInfo> DisplayInfoList; 21 22 namespace { 23 24 std::vector<DisplayInfo> CreateDisplayInfoListFromString( 25 const std::string specs, 26 internal::DisplayManager* display_manager) { 27 std::vector<DisplayInfo> display_info_list; 28 std::vector<std::string> parts; 29 base::SplitString(specs, ',', &parts); 30 size_t index = 0; 31 for (std::vector<std::string>::const_iterator iter = parts.begin(); 32 iter != parts.end(); ++iter, ++index) { 33 int64 id = index < display_manager->GetNumDisplays() ? 34 display_manager->GetDisplayAt(index).id() : 35 gfx::Display::kInvalidDisplayID; 36 display_info_list.push_back( 37 DisplayInfo::CreateFromSpecWithID(*iter, id)); 38 } 39 return display_info_list; 40 } 41 42 } // namespace 43 44 DisplayManagerTestApi::DisplayManagerTestApi( 45 internal::DisplayManager* display_manager) 46 : display_manager_(display_manager) { 47 } 48 49 DisplayManagerTestApi::~DisplayManagerTestApi() {} 50 51 void DisplayManagerTestApi::UpdateDisplay( 52 const std::string& display_specs) { 53 std::vector<DisplayInfo> display_info_list = 54 CreateDisplayInfoListFromString(display_specs, display_manager_); 55 bool is_host_origin_set = false; 56 for (size_t i = 0; i < display_info_list.size(); ++i) { 57 const DisplayInfo& display_info = display_info_list[i]; 58 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) { 59 is_host_origin_set = true; 60 break; 61 } 62 } 63 64 // On non-testing environment, when a secondary display is connected, a new 65 // native (i.e. X) window for the display is always created below the 66 // previous one for GPU performance reasons. Try to emulate the behavior 67 // unless host origins are explicitly set. 68 if (!is_host_origin_set) { 69 // Sart from (1,1) so that windows won't overlap with native mouse cursor. 70 // See |AshTestBase::SetUp()|. 71 int next_y = 1; 72 for (std::vector<DisplayInfo>::iterator iter = display_info_list.begin(); 73 iter != display_info_list.end(); ++iter) { 74 gfx::Rect bounds(iter->bounds_in_native().size()); 75 bounds.set_x(1); 76 bounds.set_y(next_y); 77 next_y += bounds.height(); 78 iter->SetBounds(bounds); 79 } 80 } 81 82 display_manager_->OnNativeDisplaysChanged(display_info_list); 83 } 84 85 int64 DisplayManagerTestApi::SetFirstDisplayAsInternalDisplay() { 86 const gfx::Display& internal = display_manager_->displays_[0]; 87 gfx::Display::SetInternalDisplayId(internal.id()); 88 return gfx::Display::InternalDisplayId(); 89 } 90 91 void DisplayManagerTestApi::DisableChangeDisplayUponHostResize() { 92 display_manager_->set_change_display_upon_host_resize(false); 93 } 94 95 } // namespace test 96 } // namespace ash 97