| 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/window_tree_host_manager.h" | 5 #include "ash/display/window_tree_host_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/command_line.h" | 25 #include "base/command_line.h" |
| 26 #include "ui/aura/client/focus_change_observer.h" | 26 #include "ui/aura/client/focus_change_observer.h" |
| 27 #include "ui/aura/client/focus_client.h" | 27 #include "ui/aura/client/focus_client.h" |
| 28 #include "ui/aura/env.h" | 28 #include "ui/aura/env.h" |
| 29 #include "ui/aura/window_observer.h" | 29 #include "ui/aura/window_observer.h" |
| 30 #include "ui/aura/window_tracker.h" | 30 #include "ui/aura/window_tracker.h" |
| 31 #include "ui/aura/window_tree_host.h" | 31 #include "ui/aura/window_tree_host.h" |
| 32 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 33 #include "ui/display/display_observer.h" | 33 #include "ui/display/display_observer.h" |
| 34 #include "ui/display/manager/display_layout.h" | 34 #include "ui/display/manager/display_layout.h" |
| 35 #include "ui/display/manager/display_layout_builder.h" |
| 35 #include "ui/display/manager/display_layout_store.h" | 36 #include "ui/display/manager/display_layout_store.h" |
| 36 #include "ui/display/manager/display_manager.h" | 37 #include "ui/display/manager/display_manager.h" |
| 37 #include "ui/display/manager/managed_display_info.h" | 38 #include "ui/display/manager/managed_display_info.h" |
| 38 #include "ui/display/screen.h" | 39 #include "ui/display/screen.h" |
| 39 #include "ui/display/test/display_manager_test_api.h" | 40 #include "ui/display/test/display_manager_test_api.h" |
| 40 #include "ui/events/event_handler.h" | 41 #include "ui/events/event_handler.h" |
| 41 #include "ui/events/test/event_generator.h" | 42 #include "ui/events/test/event_generator.h" |
| 42 #include "ui/views/mouse_watcher.h" | 43 #include "ui/views/mouse_watcher.h" |
| 43 #include "ui/views/mouse_watcher_view_host.h" | 44 #include "ui/views/mouse_watcher_view_host.h" |
| 44 #include "ui/views/view.h" | 45 #include "ui/views/view.h" |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 975 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 975 EXPECT_EQ(third_display_info.id(), | 976 EXPECT_EQ(third_display_info.id(), |
| 976 display_manager()->GetSecondaryDisplay().id()); | 977 display_manager()->GetSecondaryDisplay().id()); |
| 977 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( | 978 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( |
| 978 primary_display.id())); | 979 primary_display.id())); |
| 979 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( | 980 EXPECT_NE(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( |
| 980 third_display_info.id())); | 981 third_display_info.id())); |
| 981 EXPECT_TRUE(primary_root->Contains(shelf_window)); | 982 EXPECT_TRUE(primary_root->Contains(shelf_window)); |
| 982 } | 983 } |
| 983 | 984 |
| 984 TEST_P(WindowTreeHostManagerTest, NoSwapPrimaryWithThreeDisplays) { | 985 TEST_P(WindowTreeHostManagerTest, SetPrimaryWithThreeDisplays) { |
| 985 if (!SupportsMultipleDisplays()) | 986 if (!SupportsMultipleDisplays()) |
| 986 return; | 987 return; |
| 987 int64_t primary = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | |
| 988 UpdateDisplay("500x400,400x300,300x200"); | 988 UpdateDisplay("500x400,400x300,300x200"); |
| 989 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 989 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 990 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( | 990 display::DisplayIdList non_primary_ids = |
| 991 display_manager()->GetSecondaryDisplay().id()); | 991 display_manager()->GetCurrentDisplayIdList(); |
| 992 EXPECT_EQ(primary, display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 992 auto itr = |
| 993 std::remove(non_primary_ids.begin(), non_primary_ids.end(), primary_id); |
| 994 ASSERT_TRUE(itr != non_primary_ids.end()); |
| 995 non_primary_ids.erase(itr, non_primary_ids.end()); |
| 996 ASSERT_EQ(2u, non_primary_ids.size()); |
| 997 |
| 998 // Build the following layout: |
| 999 // |
| 1000 // +----------------+ +--------------------+ |
| 1001 // | primary_id (P) | <---- | non_primary_ids[0] | |
| 1002 // +----------------+ +--------------------+ |
| 1003 // ^ |
| 1004 // | |
| 1005 // +--------------------+ |
| 1006 // | non_primary_ids[1] | |
| 1007 // +--------------------+ |
| 1008 display::DisplayLayoutBuilder builder(primary_id); |
| 1009 builder.AddDisplayPlacement(non_primary_ids[0], primary_id, |
| 1010 display::DisplayPlacement::RIGHT, 0); |
| 1011 builder.AddDisplayPlacement(non_primary_ids[1], primary_id, |
| 1012 display::DisplayPlacement::BOTTOM, 0); |
| 1013 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
| 1014 |
| 1015 EXPECT_EQ(primary_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1016 WindowTreeHostManager* window_tree_host_manager = |
| 1017 Shell::GetInstance()->window_tree_host_manager(); |
| 1018 |
| 1019 aura::Window* primary_root = |
| 1020 window_tree_host_manager->GetRootWindowForDisplayId(primary_id); |
| 1021 aura::Window* non_primary_root_0 = |
| 1022 window_tree_host_manager->GetRootWindowForDisplayId(non_primary_ids[0]); |
| 1023 aura::Window* non_primary_root_1 = |
| 1024 window_tree_host_manager->GetRootWindowForDisplayId(non_primary_ids[1]); |
| 1025 |
| 1026 // Make non_primary_ids[0] primary. |
| 1027 window_tree_host_manager->SetPrimaryDisplayId(non_primary_ids[0]); |
| 1028 EXPECT_EQ(non_primary_ids[0], |
| 1029 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1030 |
| 1031 // Expect the root windows to be swapped. |
| 1032 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( |
| 1033 non_primary_ids[0])); |
| 1034 EXPECT_EQ(non_primary_root_0, |
| 1035 window_tree_host_manager->GetRootWindowForDisplayId(primary_id)); |
| 1036 EXPECT_EQ( |
| 1037 non_primary_root_1, |
| 1038 window_tree_host_manager->GetRootWindowForDisplayId(non_primary_ids[1])); |
| 1039 |
| 1040 // Expect that the layout will be changed to: |
| 1041 // |
| 1042 // +----------------+ +-----------------------+ |
| 1043 // | primary_id | ----> | non_primary_ids[0] (P)| |
| 1044 // +----------------+ +-----------------------+ |
| 1045 // ^ |
| 1046 // | |
| 1047 // +--------------------+ |
| 1048 // | non_primary_ids[1] | |
| 1049 // +--------------------+ |
| 1050 { |
| 1051 const display::DisplayLayout& current_layout = |
| 1052 display_manager()->GetCurrentDisplayLayout(); |
| 1053 EXPECT_EQ(non_primary_ids[0], current_layout.primary_id); |
| 1054 ASSERT_EQ(2u, current_layout.placement_list.size()); |
| 1055 EXPECT_EQ(primary_id, current_layout.placement_list[0].display_id); |
| 1056 EXPECT_EQ(non_primary_ids[0], |
| 1057 current_layout.placement_list[0].parent_display_id); |
| 1058 EXPECT_EQ(display::DisplayPlacement::LEFT, |
| 1059 current_layout.placement_list[0].position); |
| 1060 EXPECT_EQ(non_primary_ids[1], current_layout.placement_list[1].display_id); |
| 1061 EXPECT_EQ(primary_id, current_layout.placement_list[1].parent_display_id); |
| 1062 EXPECT_EQ(display::DisplayPlacement::BOTTOM, |
| 1063 current_layout.placement_list[1].position); |
| 1064 } |
| 1065 |
| 1066 // Make non_primary_ids[1] primary. |
| 1067 window_tree_host_manager->SetPrimaryDisplayId(non_primary_ids[1]); |
| 1068 EXPECT_EQ(non_primary_ids[1], |
| 1069 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1070 |
| 1071 // Expect the root windows to be swapped. |
| 1072 EXPECT_EQ(primary_root, window_tree_host_manager->GetRootWindowForDisplayId( |
| 1073 non_primary_ids[1])); |
| 1074 EXPECT_EQ( |
| 1075 non_primary_root_1, |
| 1076 window_tree_host_manager->GetRootWindowForDisplayId(non_primary_ids[0])); |
| 1077 EXPECT_EQ(non_primary_root_0, |
| 1078 window_tree_host_manager->GetRootWindowForDisplayId(primary_id)); |
| 1079 |
| 1080 // Expect that the layout will be changed to: |
| 1081 // |
| 1082 // +----------------+ +--------------------+ |
| 1083 // | primary_id | <---- | non_primary_ids[0] | |
| 1084 // +----------------+ +--------------------+ |
| 1085 // | |
| 1086 // V |
| 1087 // +------------------------+ |
| 1088 // | non_primary_ids[1] (P) | |
| 1089 // +------------------------+ |
| 1090 { |
| 1091 const display::DisplayLayout& current_layout = |
| 1092 display_manager()->GetCurrentDisplayLayout(); |
| 1093 EXPECT_EQ(non_primary_ids[1], current_layout.primary_id); |
| 1094 ASSERT_EQ(2u, current_layout.placement_list.size()); |
| 1095 EXPECT_EQ(primary_id, current_layout.placement_list[0].display_id); |
| 1096 EXPECT_EQ(non_primary_ids[1], |
| 1097 current_layout.placement_list[0].parent_display_id); |
| 1098 EXPECT_EQ(display::DisplayPlacement::TOP, |
| 1099 current_layout.placement_list[0].position); |
| 1100 EXPECT_EQ(non_primary_ids[0], current_layout.placement_list[1].display_id); |
| 1101 EXPECT_EQ(primary_id, current_layout.placement_list[1].parent_display_id); |
| 1102 EXPECT_EQ(display::DisplayPlacement::RIGHT, |
| 1103 current_layout.placement_list[1].position); |
| 1104 } |
| 993 } | 1105 } |
| 994 | 1106 |
| 1107 TEST_P(WindowTreeHostManagerTest, SetPrimaryWithFourDisplays) { |
| 1108 if (!SupportsMultipleDisplays()) |
| 1109 return; |
| 1110 UpdateDisplay("600x500,500x400,400x300,300x200"); |
| 1111 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 1112 display::DisplayIdList non_primary_ids = |
| 1113 display_manager()->GetCurrentDisplayIdList(); |
| 1114 auto itr = |
| 1115 std::remove(non_primary_ids.begin(), non_primary_ids.end(), primary_id); |
| 1116 ASSERT_TRUE(itr != non_primary_ids.end()); |
| 1117 non_primary_ids.erase(itr, non_primary_ids.end()); |
| 1118 ASSERT_EQ(3u, non_primary_ids.size()); |
| 1119 |
| 1120 // Build the following layout: |
| 1121 // |
| 1122 // +--------------------+ +--------------------+ +--------------------+ |
| 1123 // | | | primary_id (P) | | | |
| 1124 // | | +--------------------+ | | |
| 1125 // | | ^ | | |
| 1126 // | non_primary_ids[1] | | | non_primary_ids[2] | |
| 1127 // | | +--------------------+ | | |
| 1128 // | |-->| non_primary_ids[0] |<--| | |
| 1129 // +--------------------+ +--------------------+ +--------------------+ |
| 1130 display::DisplayLayoutBuilder builder(primary_id); |
| 1131 builder.AddDisplayPlacement(non_primary_ids[0], primary_id, |
| 1132 display::DisplayPlacement::BOTTOM, 0); |
| 1133 builder.AddDisplayPlacement(non_primary_ids[1], non_primary_ids[0], |
| 1134 display::DisplayPlacement::LEFT, 0); |
| 1135 builder.AddDisplayPlacement(non_primary_ids[2], non_primary_ids[0], |
| 1136 display::DisplayPlacement::RIGHT, 0); |
| 1137 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
| 1138 |
| 1139 EXPECT_EQ(primary_id, display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1140 WindowTreeHostManager* window_tree_host_manager = |
| 1141 Shell::GetInstance()->window_tree_host_manager(); |
| 1142 |
| 1143 // Make non_primary_ids[2] primary. |
| 1144 window_tree_host_manager->SetPrimaryDisplayId(non_primary_ids[2]); |
| 1145 EXPECT_EQ(non_primary_ids[2], |
| 1146 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1147 |
| 1148 // Expect that the layout will be changed to: |
| 1149 // |
| 1150 // +--------------------+ +--------------------+ +--------------------+ |
| 1151 // | | | primary_id | | | |
| 1152 // | | +--------------------+ | | |
| 1153 // | | | | | |
| 1154 // | non_primary_ids[1] | V | non_primary_ids[2] | |
| 1155 // | | +--------------------+ | (P) | |
| 1156 // | |-->| non_primary_ids[0] |-->| | |
| 1157 // +--------------------+ +--------------------+ +--------------------+ |
| 1158 { |
| 1159 const display::DisplayLayout& current_layout = |
| 1160 display_manager()->GetCurrentDisplayLayout(); |
| 1161 EXPECT_EQ(non_primary_ids[2], current_layout.primary_id); |
| 1162 ASSERT_EQ(3u, current_layout.placement_list.size()); |
| 1163 EXPECT_EQ(primary_id, current_layout.placement_list[0].display_id); |
| 1164 EXPECT_EQ(non_primary_ids[0], |
| 1165 current_layout.placement_list[0].parent_display_id); |
| 1166 EXPECT_EQ(display::DisplayPlacement::TOP, |
| 1167 current_layout.placement_list[0].position); |
| 1168 EXPECT_EQ(non_primary_ids[0], current_layout.placement_list[1].display_id); |
| 1169 EXPECT_EQ(non_primary_ids[2], |
| 1170 current_layout.placement_list[1].parent_display_id); |
| 1171 EXPECT_EQ(display::DisplayPlacement::LEFT, |
| 1172 current_layout.placement_list[1].position); |
| 1173 EXPECT_EQ(non_primary_ids[1], current_layout.placement_list[2].display_id); |
| 1174 EXPECT_EQ(non_primary_ids[0], |
| 1175 current_layout.placement_list[2].parent_display_id); |
| 1176 EXPECT_EQ(display::DisplayPlacement::LEFT, |
| 1177 current_layout.placement_list[2].position); |
| 1178 } |
| 1179 |
| 1180 // Make non_primary_ids[1] primary. |
| 1181 window_tree_host_manager->SetPrimaryDisplayId(non_primary_ids[1]); |
| 1182 EXPECT_EQ(non_primary_ids[1], |
| 1183 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 1184 |
| 1185 // Expect that the layout will be changed to: |
| 1186 // |
| 1187 // +--------------------+ +--------------------+ +--------------------+ |
| 1188 // | | | primary_id | | | |
| 1189 // | | +--------------------+ | | |
| 1190 // | | | | | |
| 1191 // | non_primary_ids[1] | V | non_primary_ids[2] | |
| 1192 // | (P) | +--------------------+ | | |
| 1193 // | |<--| non_primary_ids[0] |<--| | |
| 1194 // +--------------------+ +--------------------+ +--------------------+ |
| 1195 { |
| 1196 const display::DisplayLayout& current_layout = |
| 1197 display_manager()->GetCurrentDisplayLayout(); |
| 1198 EXPECT_EQ(non_primary_ids[1], current_layout.primary_id); |
| 1199 ASSERT_EQ(3u, current_layout.placement_list.size()); |
| 1200 EXPECT_EQ(primary_id, current_layout.placement_list[0].display_id); |
| 1201 EXPECT_EQ(non_primary_ids[0], |
| 1202 current_layout.placement_list[0].parent_display_id); |
| 1203 EXPECT_EQ(display::DisplayPlacement::TOP, |
| 1204 current_layout.placement_list[0].position); |
| 1205 EXPECT_EQ(non_primary_ids[0], current_layout.placement_list[1].display_id); |
| 1206 EXPECT_EQ(non_primary_ids[1], |
| 1207 current_layout.placement_list[1].parent_display_id); |
| 1208 EXPECT_EQ(display::DisplayPlacement::RIGHT, |
| 1209 current_layout.placement_list[1].position); |
| 1210 EXPECT_EQ(non_primary_ids[2], current_layout.placement_list[2].display_id); |
| 1211 EXPECT_EQ(non_primary_ids[0], |
| 1212 current_layout.placement_list[2].parent_display_id); |
| 1213 EXPECT_EQ(display::DisplayPlacement::RIGHT, |
| 1214 current_layout.placement_list[2].position); |
| 1215 } |
| 1216 } |
| 1217 |
| 995 TEST_P(WindowTreeHostManagerTest, OverscanInsets) { | 1218 TEST_P(WindowTreeHostManagerTest, OverscanInsets) { |
| 996 if (!SupportsMultipleDisplays()) | 1219 if (!SupportsMultipleDisplays()) |
| 997 return; | 1220 return; |
| 998 | 1221 |
| 999 WindowTreeHostManager* window_tree_host_manager = | 1222 WindowTreeHostManager* window_tree_host_manager = |
| 1000 Shell::GetInstance()->window_tree_host_manager(); | 1223 Shell::GetInstance()->window_tree_host_manager(); |
| 1001 TestEventHandler event_handler; | 1224 TestEventHandler event_handler; |
| 1002 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 1225 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 1003 | 1226 |
| 1004 UpdateDisplay("120x200,300x400*2"); | 1227 UpdateDisplay("120x200,300x400*2"); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 widget->GetNativeWindow()->GetRootWindow()); | 1793 widget->GetNativeWindow()->GetRootWindow()); |
| 1571 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow()); | 1794 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow()); |
| 1572 | 1795 |
| 1573 UpdateDisplay("300x300"); | 1796 UpdateDisplay("300x300"); |
| 1574 watcher.Stop(); | 1797 watcher.Stop(); |
| 1575 | 1798 |
| 1576 widget->CloseNow(); | 1799 widget->CloseNow(); |
| 1577 } | 1800 } |
| 1578 | 1801 |
| 1579 } // namespace ash | 1802 } // namespace ash |
| OLD | NEW |