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