Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: services/ui/ws/test_utils.cc

Issue 2692863009: Remove usage of ws::Display in ws::UserDisplayManager. (Closed)
Patch Set: Fix mash_browser_tests. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/ui/ws/test_utils.h" 5 #include "services/ui/ws/test_utils.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ClientWindowId client_id; 80 ClientWindowId client_id;
81 for (ClientSpecificId id = 1;; ++id) { 81 for (ClientSpecificId id = 1;; ++id) {
82 // Used the id of the client in the upper bits to simplify things. 82 // Used the id of the client in the upper bits to simplify things.
83 const ClientWindowId client_id = 83 const ClientWindowId client_id =
84 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id))); 84 ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), id)));
85 if (!tree->GetWindowByClientId(client_id)) 85 if (!tree->GetWindowByClientId(client_id))
86 return client_id; 86 return client_id;
87 } 87 }
88 } 88 }
89 89
90 // Creates a Display with |id| and same attributes as |metrics|.
91 display::Display CreateDisplay(int64_t id,
92 const display::ViewportMetrics& metrics) {
93 display::Display display(id);
94 display.set_bounds(metrics.bounds);
95 display.set_work_area(metrics.work_area);
96 display.set_device_scale_factor(metrics.device_scale_factor);
97 display.set_rotation(metrics.rotation);
98 display.set_touch_support(metrics.touch_support);
99 return display;
100 }
101
90 } // namespace 102 } // namespace
91 103
92 // TestScreenManager ------------------------------------------------- 104 // TestScreenManager -------------------------------------------------
93 105
94 TestScreenManager::TestScreenManager() {} 106 TestScreenManager::TestScreenManager() {}
95 107
96 TestScreenManager::~TestScreenManager() {} 108 TestScreenManager::~TestScreenManager() {
109 display::Screen::SetScreenInstance(nullptr);
110 }
97 111
98 int64_t TestScreenManager::AddDisplay() { 112 int64_t TestScreenManager::AddDisplay() {
99 return AddDisplay(MakeViewportMetrics(0, 0, 100, 100, 1.0f)); 113 return AddDisplay(MakeViewportMetrics(0, 0, 100, 100, 1.0f));
100 } 114 }
101 115
102 int64_t TestScreenManager::AddDisplay(const display::ViewportMetrics& metrics) { 116 int64_t TestScreenManager::AddDisplay(const display::ViewportMetrics& metrics) {
103 // Generate a unique display id. 117 // Generate a unique display id.
104 int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1; 118 int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1;
105 display_ids_.insert(display_id); 119 display_ids_.insert(display_id);
106 120
121 // First display added will be the primary display.
122 display::DisplayList::Type type = display::DisplayList::Type::NOT_PRIMARY;
123 if (display_ids_.size() == 1)
124 type = display::DisplayList::Type::PRIMARY;
125
126 screen_->display_list().AddDisplay(CreateDisplay(display_id, metrics), type);
107 delegate_->OnDisplayAdded(display_id, metrics); 127 delegate_->OnDisplayAdded(display_id, metrics);
108 128
109 // First display added will be the primary display. 129 if (type == display::DisplayList::Type::PRIMARY)
110 if (primary_display_id_ == display::kInvalidDisplayId) {
111 primary_display_id_ = display_id;
112 delegate_->OnPrimaryDisplayChanged(display_id); 130 delegate_->OnPrimaryDisplayChanged(display_id);
113 }
114 131
115 return display_id; 132 return display_id;
116 } 133 }
117 134
118 void TestScreenManager::ModifyDisplay(int64_t id, 135 void TestScreenManager::ModifyDisplay(int64_t display_id,
119 const display::ViewportMetrics& metrics) { 136 const display::ViewportMetrics& metrics) {
120 DCHECK(display_ids_.count(id) == 1); 137 DCHECK(display_ids_.count(display_id) == 1);
121 delegate_->OnDisplayModified(id, metrics); 138 screen_->display_list().UpdateDisplay(CreateDisplay(display_id, metrics));
139 delegate_->OnDisplayModified(display_id, metrics);
122 } 140 }
123 141
124 void TestScreenManager::RemoveDisplay(int64_t id) { 142 void TestScreenManager::RemoveDisplay(int64_t display_id) {
125 DCHECK(display_ids_.count(id) == 1); 143 DCHECK(display_ids_.count(display_id) == 1);
126 delegate_->OnDisplayRemoved(id); 144 screen_->display_list().RemoveDisplay(display_id);
127 display_ids_.erase(id); 145 delegate_->OnDisplayRemoved(display_id);
146 display_ids_.erase(display_id);
128 } 147 }
129 148
130 void TestScreenManager::Init(display::ScreenManagerDelegate* delegate) { 149 void TestScreenManager::Init(display::ScreenManagerDelegate* delegate) {
131 // Reset
132 delegate_ = delegate; 150 delegate_ = delegate;
151
152 // Reset everything.
133 display_ids_.clear(); 153 display_ids_.clear();
134 primary_display_id_ = display::kInvalidDisplayId; 154 display::Screen::SetScreenInstance(nullptr);
135 } 155 screen_ = base::MakeUnique<display::ScreenBase>();
136 156 display::Screen::SetScreenInstance(screen_.get());
137 int64_t TestScreenManager::GetPrimaryDisplayId() const {
138 return primary_display_id_;
139 } 157 }
140 158
141 // TestPlatformDisplayFactory ------------------------------------------------- 159 // TestPlatformDisplayFactory -------------------------------------------------
142 160
143 TestPlatformDisplayFactory::TestPlatformDisplayFactory( 161 TestPlatformDisplayFactory::TestPlatformDisplayFactory(
144 mojom::Cursor* cursor_storage) 162 mojom::Cursor* cursor_storage)
145 : cursor_storage_(cursor_storage) {} 163 : cursor_storage_(cursor_storage) {}
146 164
147 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {} 165 TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {}
148 166
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 if (!tree->AddWindow(parent_client_id, client_window_id)) 656 if (!tree->AddWindow(parent_client_id, client_window_id))
639 return nullptr; 657 return nullptr;
640 if (client_id) 658 if (client_id)
641 *client_id = client_window_id; 659 *client_id = client_window_id;
642 return tree->GetWindowByClientId(client_window_id); 660 return tree->GetWindowByClientId(client_window_id);
643 } 661 }
644 662
645 } // namespace test 663 } // namespace test
646 } // namespace ws 664 } // namespace ws
647 } // namespace ui 665 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/test_utils.h ('k') | services/ui/ws/user_display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698