OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/ui/window_sizer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // The work area for 1024x768 monitors with different taskbar orientations. | 36 // The work area for 1024x768 monitors with different taskbar orientations. |
37 static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); | 37 static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734); |
38 static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734); | 38 static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734); |
39 static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768); | 39 static const gfx::Rect taskbar_left_work_area(107, 0, 917, 768); |
40 static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768); | 40 static const gfx::Rect taskbar_right_work_area(0, 0, 917, 768); |
41 | 41 |
42 static int kWindowTilePixels = WindowSizer::kWindowTilePixels; | 42 static int kWindowTilePixels = WindowSizer::kWindowTilePixels; |
43 | 43 |
44 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use | 44 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use |
45 // to fake various monitor layouts and sizes. | 45 // to fake various monitor layouts and sizes. |
46 class TestMonitorInfoProvider : public WindowSizer::MonitorInfoProvider { | 46 class TestMonitorInfoProvider : public MonitorInfoProvider { |
47 public: | 47 public: |
48 TestMonitorInfoProvider() {} | 48 TestMonitorInfoProvider() {} |
49 virtual ~TestMonitorInfoProvider() {} | 49 virtual ~TestMonitorInfoProvider() {} |
50 | 50 |
51 void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area) { | 51 void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area) { |
52 DCHECK(bounds.Contains(work_area)); | 52 DCHECK(bounds.Contains(work_area)); |
53 monitor_bounds_.push_back(bounds); | 53 monitor_bounds_.push_back(bounds); |
54 work_areas_.push_back(work_area); | 54 work_areas_.push_back(work_area); |
55 } | 55 } |
56 | 56 |
57 // Overridden from WindowSizer::MonitorInfoProvider: | 57 // Overridden from WindowSizer::MonitorInfoProvider: |
58 virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE { | 58 virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE { |
59 return work_areas_[0]; | 59 return work_areas_[0]; |
60 } | 60 } |
61 | 61 |
62 virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE { | 62 virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE { |
63 return monitor_bounds_[0]; | 63 return monitor_bounds_[0]; |
64 } | 64 } |
65 | 65 |
66 virtual gfx::Rect GetMonitorWorkAreaMatching( | 66 virtual gfx::Rect GetMonitorWorkAreaMatching( |
67 const gfx::Rect& match_rect) const OVERRIDE { | 67 const gfx::Rect& match_rect) const OVERRIDE { |
68 return work_areas_[GetMonitorIndexMatchingBounds(match_rect)]; | 68 return work_areas_[GetMonitorIndexMatchingBounds(match_rect)]; |
69 } | 69 } |
70 | 70 |
71 virtual void UpdateWorkAreas() OVERRIDE {} | |
72 | |
73 private: | 71 private: |
74 size_t GetMonitorIndexMatchingBounds(const gfx::Rect& match_rect) const { | 72 size_t GetMonitorIndexMatchingBounds(const gfx::Rect& match_rect) const { |
75 int max_area = 0; | 73 int max_area = 0; |
76 size_t max_area_index = 0; | 74 size_t max_area_index = 0; |
77 // Loop through all the monitors, finding the one that intersects the | 75 // Loop through all the monitors, finding the one that intersects the |
78 // largest area of the supplied match rect. | 76 // largest area of the supplied match rect. |
79 for (size_t i = 0; i < work_areas_.size(); ++i) { | 77 for (size_t i = 0; i < work_areas_.size(); ++i) { |
80 gfx::Rect overlap(match_rect.Intersect(work_areas_[i])); | 78 gfx::Rect overlap(match_rect.Intersect(work_areas_[i])); |
81 int area = overlap.width() * overlap.height(); | 79 int area = overlap.width() * overlap.height(); |
82 if (area > max_area) { | 80 if (area > max_area) { |
83 max_area = area; | 81 max_area = area; |
84 max_area_index = i; | 82 max_area_index = i; |
85 } | 83 } |
86 } | 84 } |
87 return max_area_index; | 85 return max_area_index; |
88 } | 86 } |
89 | 87 |
90 std::vector<gfx::Rect> monitor_bounds_; | 88 std::vector<gfx::Rect> monitor_bounds_; |
| 89 std::vector<gfx::Rect> work_areas_; |
91 | 90 |
92 DISALLOW_COPY_AND_ASSIGN(TestMonitorInfoProvider); | 91 DISALLOW_COPY_AND_ASSIGN(TestMonitorInfoProvider); |
93 }; | 92 }; |
94 | 93 |
95 // Testing implementation of WindowSizer::StateProvider that we use to fake | 94 // Testing implementation of WindowSizer::StateProvider that we use to fake |
96 // persistent storage and existing windows. | 95 // persistent storage and existing windows. |
97 class TestStateProvider : public WindowSizer::StateProvider { | 96 class TestStateProvider : public WindowSizer::StateProvider { |
98 public: | 97 public: |
99 TestStateProvider() | 98 TestStateProvider() |
100 : has_persistent_data_(false), | 99 : has_persistent_data_(false), |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 828 |
830 { // entirely off bottom (monitor was detached since last run) | 829 { // entirely off bottom (monitor was detached since last run) |
831 gfx::Rect window_bounds; | 830 gfx::Rect window_bounds; |
832 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 831 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
833 gfx::Rect(50, 800, 500, 400), bottom_nonprimary, | 832 gfx::Rect(50, 800, 500, 400), bottom_nonprimary, |
834 PERSISTED, &window_bounds); | 833 PERSISTED, &window_bounds); |
835 EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); | 834 EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); |
836 } | 835 } |
837 } | 836 } |
838 #endif //defined(OS_MACOSX) | 837 #endif //defined(OS_MACOSX) |
OLD | NEW |