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" | 13 #include "ui/gfx/display.h" |
14 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
15 | 15 |
16 #if defined(USE_AURA) | 16 #if defined(USE_AURA) |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #endif | 18 #endif |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class TestScreen : public gfx::Screen { | 22 class TestScreen : public gfx::Screen { |
23 public: | 23 public: |
24 TestScreen() {} | 24 TestScreen() {} |
25 virtual ~TestScreen() {} | 25 ~TestScreen() override {} |
26 | 26 |
27 // Overridden from gfx::Screen: | 27 // Overridden from gfx::Screen: |
28 virtual bool IsDIPEnabled() override { | 28 bool IsDIPEnabled() override { |
29 NOTREACHED(); | 29 NOTREACHED(); |
30 return false; | 30 return false; |
31 } | 31 } |
32 | 32 |
33 virtual gfx::Point GetCursorScreenPoint() override { | 33 gfx::Point GetCursorScreenPoint() override { |
34 NOTREACHED(); | 34 NOTREACHED(); |
35 return gfx::Point(); | 35 return gfx::Point(); |
36 } | 36 } |
37 | 37 |
38 virtual gfx::NativeWindow GetWindowUnderCursor() override { | 38 gfx::NativeWindow GetWindowUnderCursor() override { |
39 NOTREACHED(); | 39 NOTREACHED(); |
40 return NULL; | 40 return NULL; |
41 } | 41 } |
42 | 42 |
43 virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) | 43 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
44 override { | |
45 NOTREACHED(); | 44 NOTREACHED(); |
46 return NULL; | 45 return NULL; |
47 } | 46 } |
48 | 47 |
49 virtual int GetNumDisplays() const override { | 48 int GetNumDisplays() const override { return displays_.size(); } |
50 return displays_.size(); | |
51 } | |
52 | 49 |
53 virtual std::vector<gfx::Display> GetAllDisplays() const override { | 50 std::vector<gfx::Display> GetAllDisplays() const override { |
54 return displays_; | 51 return displays_; |
55 } | 52 } |
56 | 53 |
57 virtual gfx::Display GetDisplayNearestWindow( | 54 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { |
58 gfx::NativeView view) const override { | |
59 #if defined(USE_AURA) | 55 #if defined(USE_AURA) |
60 return GetDisplayMatching(view->GetBoundsInScreen()); | 56 return GetDisplayMatching(view->GetBoundsInScreen()); |
61 #else | 57 #else |
62 NOTREACHED(); | 58 NOTREACHED(); |
63 return gfx::Display(); | 59 return gfx::Display(); |
64 #endif | 60 #endif |
65 } | 61 } |
66 | 62 |
67 virtual gfx::Display GetDisplayNearestPoint( | 63 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
68 const gfx::Point& point) const override { | |
69 NOTREACHED(); | 64 NOTREACHED(); |
70 return gfx::Display(); | 65 return gfx::Display(); |
71 } | 66 } |
72 | 67 |
73 virtual gfx::Display GetDisplayMatching( | 68 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { |
74 const gfx::Rect& match_rect) const override { | |
75 int max_area = 0; | 69 int max_area = 0; |
76 size_t max_area_index = 0; | 70 size_t max_area_index = 0; |
77 | 71 |
78 for (size_t i = 0; i < displays_.size(); ++i) { | 72 for (size_t i = 0; i < displays_.size(); ++i) { |
79 gfx::Rect overlap = displays_[i].bounds(); | 73 gfx::Rect overlap = displays_[i].bounds(); |
80 overlap.Intersect(match_rect); | 74 overlap.Intersect(match_rect); |
81 int area = overlap.width() * overlap.height(); | 75 int area = overlap.width() * overlap.height(); |
82 if (area > max_area) { | 76 if (area > max_area) { |
83 max_area = area; | 77 max_area = area; |
84 max_area_index = i; | 78 max_area_index = i; |
85 } | 79 } |
86 } | 80 } |
87 return displays_[max_area_index]; | 81 return displays_[max_area_index]; |
88 } | 82 } |
89 | 83 |
90 virtual gfx::Display GetPrimaryDisplay() const override { | 84 gfx::Display GetPrimaryDisplay() const override { return displays_[0]; } |
91 return displays_[0]; | |
92 } | |
93 | 85 |
94 virtual void AddObserver(gfx::DisplayObserver* observer) override { | 86 void AddObserver(gfx::DisplayObserver* observer) override { NOTREACHED(); } |
95 NOTREACHED(); | |
96 } | |
97 | 87 |
98 virtual void RemoveObserver(gfx::DisplayObserver* observer) override { | 88 void RemoveObserver(gfx::DisplayObserver* observer) override { NOTREACHED(); } |
99 NOTREACHED(); | |
100 } | |
101 | 89 |
102 void AddDisplay(const gfx::Rect& bounds, | 90 void AddDisplay(const gfx::Rect& bounds, |
103 const gfx::Rect& work_area) { | 91 const gfx::Rect& work_area) { |
104 gfx::Display display(displays_.size(), bounds); | 92 gfx::Display display(displays_.size(), bounds); |
105 display.set_work_area(work_area); | 93 display.set_work_area(work_area); |
106 displays_.push_back(display); | 94 displays_.push_back(display); |
107 } | 95 } |
108 | 96 |
109 private: | 97 private: |
110 std::vector<gfx::Display> displays_; | 98 std::vector<gfx::Display> displays_; |
111 | 99 |
112 DISALLOW_COPY_AND_ASSIGN(TestScreen); | 100 DISALLOW_COPY_AND_ASSIGN(TestScreen); |
113 }; | 101 }; |
114 | 102 |
115 class TestTargetDisplayProvider : public WindowSizer::TargetDisplayProvider { | 103 class TestTargetDisplayProvider : public WindowSizer::TargetDisplayProvider { |
116 public: | 104 public: |
117 TestTargetDisplayProvider() {} | 105 TestTargetDisplayProvider() {} |
118 virtual ~TestTargetDisplayProvider() {} | 106 ~TestTargetDisplayProvider() override {} |
119 | 107 |
120 virtual gfx::Display GetTargetDisplay( | 108 gfx::Display GetTargetDisplay(const gfx::Screen* screen, |
121 const gfx::Screen* screen, | 109 const gfx::Rect& bounds) const override { |
122 const gfx::Rect& bounds) const override { | |
123 // On ash, the bounds is used as a indicator to specify | 110 // On ash, the bounds is used as a indicator to specify |
124 // the target display. | 111 // the target display. |
125 return screen->GetDisplayMatching(bounds); | 112 return screen->GetDisplayMatching(bounds); |
126 } | 113 } |
127 | 114 |
128 private: | 115 private: |
129 DISALLOW_COPY_AND_ASSIGN(TestTargetDisplayProvider); | 116 DISALLOW_COPY_AND_ASSIGN(TestTargetDisplayProvider); |
130 }; | 117 }; |
131 | 118 |
132 } // namespace | 119 } // namespace |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 { // Check that a window which hangs out of the screen get moved back in. | 447 { // Check that a window which hangs out of the screen get moved back in. |
461 gfx::Rect window_bounds; | 448 gfx::Rect window_bounds; |
462 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), | 449 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), |
463 gfx::Rect(), DEFAULT, NULL, | 450 gfx::Rect(), DEFAULT, NULL, |
464 gfx::Rect(1020, 700, 100, 100), &window_bounds); | 451 gfx::Rect(1020, 700, 100, 100), &window_bounds); |
465 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); | 452 EXPECT_EQ("924,668 100x100", window_bounds.ToString()); |
466 } | 453 } |
467 } | 454 } |
468 | 455 |
469 #endif // defined(OS_MACOSX) | 456 #endif // defined(OS_MACOSX) |
OLD | NEW |