| 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 "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" |
| 6 | 6 |
| 7 #include "ash/wm/window_resizer.h" | 7 #include "ash/wm/window_resizer.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/display.h" |
| 14 #include "ui/gfx/screen.h" |
| 13 | 15 |
| 14 TestMonitorInfoProvider::TestMonitorInfoProvider() {}; | 16 namespace { |
| 15 | 17 |
| 16 TestMonitorInfoProvider::~TestMonitorInfoProvider() {}; | 18 class TestScreen : public gfx::Screen { |
| 19 public: |
| 20 TestScreen() {} |
| 21 virtual ~TestScreen() {} |
| 17 | 22 |
| 18 void TestMonitorInfoProvider::AddMonitor(const gfx::Rect& bounds, | 23 // Overridden from gfx::Screen: |
| 19 const gfx::Rect& work_area) { | 24 virtual bool IsDIPEnabled() OVERRIDE { |
| 20 DCHECK(bounds.Contains(work_area)); | 25 NOTREACHED(); |
| 21 monitor_bounds_.push_back(bounds); | 26 return false; |
| 22 work_areas_.push_back(work_area); | 27 } |
| 23 } | |
| 24 | 28 |
| 25 // Overridden from WindowSizer::MonitorInfoProvider: | 29 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { |
| 26 gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayWorkArea() const { | 30 NOTREACHED(); |
| 27 return work_areas_[0]; | 31 return gfx::Point(); |
| 28 } | 32 } |
| 29 | 33 |
| 30 gfx::Rect TestMonitorInfoProvider::GetPrimaryDisplayBounds() const { | 34 virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE { |
| 31 return monitor_bounds_[0]; | 35 NOTREACHED(); |
| 32 } | 36 return NULL; |
| 37 } |
| 33 | 38 |
| 34 gfx::Rect TestMonitorInfoProvider::GetMonitorWorkAreaMatching( | 39 virtual int GetNumDisplays() const OVERRIDE { |
| 35 const gfx::Rect& match_rect) const { | 40 return displays_.size(); |
| 36 return work_areas_[GetMonitorIndexMatchingBounds(match_rect)]; | 41 } |
| 37 } | |
| 38 | 42 |
| 39 size_t TestMonitorInfoProvider::GetMonitorIndexMatchingBounds( | 43 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { |
| 40 const gfx::Rect& match_rect) const { | 44 return displays_; |
| 41 int max_area = 0; | 45 } |
| 42 size_t max_area_index = 0; | 46 |
| 43 // Loop through all the monitors, finding the one that intersects the | 47 virtual gfx::Display GetDisplayNearestWindow( |
| 44 // largest area of the supplied match rect. | 48 gfx::NativeView view) const OVERRIDE { |
| 45 for (size_t i = 0; i < work_areas_.size(); ++i) { | 49 NOTREACHED(); |
| 46 gfx::Rect overlap = work_areas_[i]; | 50 return gfx::Display(); |
| 47 overlap.Intersect(match_rect); | 51 } |
| 48 int area = overlap.width() * overlap.height(); | 52 |
| 49 if (area > max_area) { | 53 virtual gfx::Display GetDisplayNearestPoint( |
| 50 max_area = area; | 54 const gfx::Point& point) const OVERRIDE { |
| 51 max_area_index = i; | 55 NOTREACHED(); |
| 56 return gfx::Display(); |
| 57 } |
| 58 |
| 59 virtual gfx::Display GetDisplayMatching( |
| 60 const gfx::Rect& match_rect) const OVERRIDE { |
| 61 int max_area = 0; |
| 62 size_t max_area_index = 0; |
| 63 |
| 64 for (size_t i = 0; i < displays_.size(); ++i) { |
| 65 gfx::Rect overlap = displays_[i].bounds(); |
| 66 overlap.Intersect(match_rect); |
| 67 int area = overlap.width() * overlap.height(); |
| 68 if (area > max_area) { |
| 69 max_area = area; |
| 70 max_area_index = i; |
| 71 } |
| 52 } | 72 } |
| 73 return displays_[max_area_index]; |
| 53 } | 74 } |
| 54 return max_area_index; | 75 |
| 55 } | 76 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { |
| 77 return displays_[0]; |
| 78 } |
| 79 |
| 80 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE { |
| 81 NOTREACHED(); |
| 82 } |
| 83 |
| 84 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE { |
| 85 NOTREACHED(); |
| 86 } |
| 87 |
| 88 void AddDisplay(const gfx::Rect& bounds, |
| 89 const gfx::Rect& work_area) { |
| 90 gfx::Display display(displays_.size(), bounds); |
| 91 display.set_work_area(work_area); |
| 92 displays_.push_back(display); |
| 93 } |
| 94 |
| 95 private: |
| 96 std::vector<gfx::Display> displays_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(TestScreen); |
| 99 }; |
| 100 |
| 101 } // namespace |
| 56 | 102 |
| 57 TestStateProvider::TestStateProvider(): | 103 TestStateProvider::TestStateProvider(): |
| 58 has_persistent_data_(false), | 104 has_persistent_data_(false), |
| 59 persistent_show_state_(ui::SHOW_STATE_DEFAULT), | 105 persistent_show_state_(ui::SHOW_STATE_DEFAULT), |
| 60 has_last_active_data_(false), | 106 has_last_active_data_(false), |
| 61 last_active_show_state_(ui::SHOW_STATE_DEFAULT) { | 107 last_active_show_state_(ui::SHOW_STATE_DEFAULT) { |
| 62 } | 108 } |
| 63 | 109 |
| 64 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds, | 110 void TestStateProvider::SetPersistentState(const gfx::Rect& bounds, |
| 65 const gfx::Rect& work_area, | 111 const gfx::Rect& work_area, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const gfx::Rect& bounds, | 157 const gfx::Rect& bounds, |
| 112 const gfx::Rect& work_area, | 158 const gfx::Rect& work_area, |
| 113 ui::WindowShowState show_state_persisted, | 159 ui::WindowShowState show_state_persisted, |
| 114 ui::WindowShowState show_state_last, | 160 ui::WindowShowState show_state_last, |
| 115 Source source, | 161 Source source, |
| 116 const Browser* browser, | 162 const Browser* browser, |
| 117 const gfx::Rect& passed_in, | 163 const gfx::Rect& passed_in, |
| 118 gfx::Rect* out_bounds, | 164 gfx::Rect* out_bounds, |
| 119 ui::WindowShowState* out_show_state) { | 165 ui::WindowShowState* out_show_state) { |
| 120 DCHECK(out_show_state); | 166 DCHECK(out_show_state); |
| 121 TestMonitorInfoProvider* mip = new TestMonitorInfoProvider; | 167 TestScreen test_screen; |
| 122 mip->AddMonitor(monitor1_bounds, monitor1_work_area); | 168 test_screen.AddDisplay(monitor1_bounds, monitor1_work_area); |
| 123 if (!monitor2_bounds.IsEmpty()) | 169 if (!monitor2_bounds.IsEmpty()) |
| 124 mip->AddMonitor(monitor2_bounds, monitor2_bounds); | 170 test_screen.AddDisplay(monitor2_bounds, monitor2_bounds); |
| 125 TestStateProvider* sp = new TestStateProvider; | 171 TestStateProvider* sp = new TestStateProvider; |
| 126 if (source == PERSISTED || source == BOTH) | 172 if (source == PERSISTED || source == BOTH) |
| 127 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); | 173 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); |
| 128 if (source == LAST_ACTIVE || source == BOTH) | 174 if (source == LAST_ACTIVE || source == BOTH) |
| 129 sp->SetLastActiveState(bounds, show_state_last, true); | 175 sp->SetLastActiveState(bounds, show_state_last, true); |
| 130 | 176 |
| 131 WindowSizer sizer(sp, mip, browser); | 177 WindowSizer sizer(sp, &test_screen, browser); |
| 132 sizer.DetermineWindowBoundsAndShowState(passed_in, | 178 sizer.DetermineWindowBoundsAndShowState(passed_in, |
| 133 out_bounds, | 179 out_bounds, |
| 134 out_show_state); | 180 out_show_state); |
| 135 } | 181 } |
| 136 | 182 |
| 137 void GetWindowBounds(const gfx::Rect& monitor1_bounds, | 183 void GetWindowBounds(const gfx::Rect& monitor1_bounds, |
| 138 const gfx::Rect& monitor1_work_area, | 184 const gfx::Rect& monitor1_work_area, |
| 139 const gfx::Rect& monitor2_bounds, | 185 const gfx::Rect& monitor2_bounds, |
| 140 const gfx::Rect& bounds, | 186 const gfx::Rect& bounds, |
| 141 const gfx::Rect& work_area, | 187 const gfx::Rect& work_area, |
| 142 Source source, | 188 Source source, |
| 143 const Browser* browser, | 189 const Browser* browser, |
| 144 const gfx::Rect& passed_in, | 190 const gfx::Rect& passed_in, |
| 145 gfx::Rect* out_bounds) { | 191 gfx::Rect* out_bounds) { |
| 146 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; | 192 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; |
| 147 GetWindowBoundsAndShowState( | 193 GetWindowBoundsAndShowState( |
| 148 monitor1_bounds, monitor1_work_area, monitor2_bounds, bounds, work_area, | 194 monitor1_bounds, monitor1_work_area, monitor2_bounds, bounds, work_area, |
| 149 ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_DEFAULT, source, browser, | 195 ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_DEFAULT, source, browser, |
| 150 passed_in, out_bounds, &out_show_state); | 196 passed_in, out_bounds, &out_show_state); |
| 151 } | 197 } |
| 152 | 198 |
| 153 ui::WindowShowState GetWindowShowState( | 199 ui::WindowShowState GetWindowShowState( |
| 154 ui::WindowShowState show_state_persisted, | 200 ui::WindowShowState show_state_persisted, |
| 155 ui::WindowShowState show_state_last, | 201 ui::WindowShowState show_state_last, |
| 156 Source source, | 202 Source source, |
| 157 const Browser* browser, | 203 const Browser* browser, |
| 158 const gfx::Rect& display_config) { | 204 const gfx::Rect& display_config) { |
| 159 gfx::Rect bounds = display_config; | 205 gfx::Rect bounds = display_config; |
| 160 gfx::Rect work_area = display_config; | 206 gfx::Rect work_area = display_config; |
| 161 TestMonitorInfoProvider* mip = new TestMonitorInfoProvider; | 207 TestScreen test_screen; |
| 162 mip->AddMonitor(display_config, display_config); | 208 test_screen.AddDisplay(display_config, display_config); |
| 163 TestStateProvider* sp = new TestStateProvider; | 209 TestStateProvider* sp = new TestStateProvider; |
| 164 if (source == PERSISTED || source == BOTH) | 210 if (source == PERSISTED || source == BOTH) |
| 165 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); | 211 sp->SetPersistentState(bounds, work_area, show_state_persisted, true); |
| 166 if (source == LAST_ACTIVE || source == BOTH) | 212 if (source == LAST_ACTIVE || source == BOTH) |
| 167 sp->SetLastActiveState(bounds, show_state_last, true); | 213 sp->SetLastActiveState(bounds, show_state_last, true); |
| 168 | 214 |
| 169 WindowSizer sizer(sp, mip, browser); | 215 WindowSizer sizer(sp, &test_screen, browser); |
| 170 | 216 |
| 171 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; | 217 ui::WindowShowState out_show_state = ui::SHOW_STATE_DEFAULT; |
| 172 gfx::Rect out_bounds; | 218 gfx::Rect out_bounds; |
| 173 sizer.DetermineWindowBoundsAndShowState( | 219 sizer.DetermineWindowBoundsAndShowState( |
| 174 gfx::Rect(), | 220 gfx::Rect(), |
| 175 &out_bounds, | 221 &out_bounds, |
| 176 &out_show_state); | 222 &out_show_state); |
| 177 return out_show_state; | 223 return out_show_state; |
| 178 } | 224 } |
| 179 | 225 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 { // Check that a window which hangs out of the screen get moved back in. | 425 { // Check that a window which hangs out of the screen get moved back in. |
| 380 gfx::Rect window_bounds; | 426 gfx::Rect window_bounds; |
| 381 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), | 427 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), |
| 382 gfx::Rect(), DEFAULT, NULL, | 428 gfx::Rect(), DEFAULT, NULL, |
| 383 gfx::Rect(1020, 700, 100, 100), &window_bounds); | 429 gfx::Rect(1020, 700, 100, 100), &window_bounds); |
| 384 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); | 430 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
| 385 } | 431 } |
| 386 } | 432 } |
| 387 | 433 |
| 388 #endif // defined(OS_MACOSX) | 434 #endif // defined(OS_MACOSX) |
| OLD | NEW |