Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_H_ | 5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_H_ |
| 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_H_ | 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 14 | 12 |
| 15 class Browser; | 13 class Browser; |
| 16 | 14 |
| 15 // An interface implemented by an object that can retrieve information about | |
| 16 // the monitors on the system. | |
| 17 class MonitorInfoProvider { | |
| 18 public: | |
| 19 virtual ~MonitorInfoProvider() {} | |
| 20 | |
| 21 // Returns the bounds of the work area of the primary monitor. | |
| 22 virtual gfx::Rect GetPrimaryMonitorWorkArea() const = 0; | |
| 23 | |
| 24 // Returns the bounds of the primary monitor. | |
| 25 virtual gfx::Rect GetPrimaryMonitorBounds() const = 0; | |
| 26 | |
| 27 // Returns the bounds of the work area of the monitor that most closely | |
| 28 // intersects the provided bounds. | |
| 29 virtual gfx::Rect GetMonitorWorkAreaMatching( | |
| 30 const gfx::Rect& match_rect) const = 0; | |
| 31 }; | |
| 32 | |
| 17 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// |
| 18 // WindowSizer | 34 // WindowSizer |
| 19 // | 35 // |
| 20 // A class that determines the best new size and position for a window to be | 36 // A class that determines the best new size and position for a window to be |
| 21 // shown at based several factors, including the position and size of the last | 37 // shown at based several factors, including the position and size of the last |
| 22 // window of the same type, the last saved bounds of the window from the | 38 // window of the same type, the last saved bounds of the window from the |
| 23 // previous session, and default system metrics if neither of the above two | 39 // previous session, and default system metrics if neither of the above two |
| 24 // conditions exist. The system has built-in providers for monitor metrics | 40 // conditions exist. The system has built-in providers for monitor metrics |
| 25 // and persistent storage (using preferences) but can be overrided with mocks | 41 // and persistent storage (using preferences) but can be overrided with mocks |
| 26 // for testing. | 42 // for testing. |
| 27 // | 43 // |
| 28 class WindowSizer { | 44 class WindowSizer { |
| 29 public: | 45 public: |
| 30 class MonitorInfoProvider; | |
| 31 class StateProvider; | 46 class StateProvider; |
| 32 | 47 |
| 33 // The WindowSizer assumes ownership of these objects. | 48 // WindowSizer owns |state_provider| and |monitor_info_provider|. |
|
Ben Goodger (Google)
2011/12/07 17:17:35
Also add this comment for the first function:
Win
| |
| 49 explicit WindowSizer(StateProvider* state_provider); | |
| 34 WindowSizer(StateProvider* state_provider, | 50 WindowSizer(StateProvider* state_provider, |
| 35 MonitorInfoProvider* monitor_info_provider); | 51 MonitorInfoProvider* monitor_info_provider); |
| 36 virtual ~WindowSizer(); | 52 virtual ~WindowSizer(); |
| 37 | 53 |
| 38 // Static factory methods to create default MonitorInfoProvider | |
| 39 // instances. The returned object is owned by the caller. | |
| 40 static MonitorInfoProvider* CreateDefaultMonitorInfoProvider(); | |
| 41 | |
| 42 // An interface implemented by an object that can retrieve information about | |
| 43 // the monitors on the system. | |
| 44 class MonitorInfoProvider { | |
| 45 public: | |
| 46 MonitorInfoProvider() {} | |
| 47 virtual ~MonitorInfoProvider() {} | |
| 48 | |
| 49 // Returns the bounds of the work area of the primary monitor. | |
| 50 virtual gfx::Rect GetPrimaryMonitorWorkArea() const = 0; | |
| 51 | |
| 52 // Returns the bounds of the primary monitor. | |
| 53 virtual gfx::Rect GetPrimaryMonitorBounds() const = 0; | |
| 54 | |
| 55 // Returns the bounds of the work area of the monitor that most closely | |
| 56 // intersects the provided bounds. | |
| 57 virtual gfx::Rect GetMonitorWorkAreaMatching( | |
| 58 const gfx::Rect& match_rect) const = 0; | |
| 59 | |
| 60 // Ensures number and coordinates of work areas are up-to-date. You must | |
| 61 // call this before calling either of the below functions, as work areas can | |
| 62 // change while the program is running. | |
| 63 virtual void UpdateWorkAreas() = 0; | |
| 64 | |
| 65 // Returns the number of monitors on the system. | |
| 66 size_t GetMonitorCount() const { | |
| 67 return work_areas_.size(); | |
| 68 } | |
| 69 | |
| 70 // Returns the bounds of the work area of the monitor at the specified | |
| 71 // index. | |
| 72 gfx::Rect GetWorkAreaAt(size_t index) const { | |
| 73 return work_areas_[index]; | |
| 74 } | |
| 75 | |
| 76 protected: | |
| 77 std::vector<gfx::Rect> work_areas_; | |
| 78 }; | |
| 79 | |
| 80 // An interface implemented by an object that can retrieve state from either a | 54 // An interface implemented by an object that can retrieve state from either a |
| 81 // persistent store or an existing window. | 55 // persistent store or an existing window. |
| 82 class StateProvider { | 56 class StateProvider { |
| 83 public: | 57 public: |
| 84 virtual ~StateProvider() {} | 58 virtual ~StateProvider() {} |
| 85 | 59 |
| 86 // Retrieve the persisted bounds of the window. Returns true if there was | 60 // Retrieve the persisted bounds of the window. Returns true if there was |
| 87 // persisted data to retrieve state information, false otherwise. | 61 // persisted data to retrieve state information, false otherwise. |
| 88 virtual bool GetPersistentState(gfx::Rect* bounds, | 62 virtual bool GetPersistentState(gfx::Rect* bounds, |
| 89 gfx::Rect* work_area) const = 0; | 63 gfx::Rect* work_area) const = 0; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // in local state preferences. Returns true if local state exists containing | 107 // in local state preferences. Returns true if local state exists containing |
| 134 // this information, false if this information does not exist and a default | 108 // this information, false if this information does not exist and a default |
| 135 // size should be used. | 109 // size should be used. |
| 136 bool GetSavedWindowBounds(gfx::Rect* bounds) const; | 110 bool GetSavedWindowBounds(gfx::Rect* bounds) const; |
| 137 | 111 |
| 138 // Gets the default window position and size if there is no last window and | 112 // Gets the default window position and size if there is no last window and |
| 139 // no saved window placement in prefs. This function determines the default | 113 // no saved window placement in prefs. This function determines the default |
| 140 // size based on monitor size, etc. | 114 // size based on monitor size, etc. |
| 141 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const; | 115 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const; |
| 142 | 116 |
| 143 // Returns true if the specified position is "offscreen" for the given edge, | |
| 144 // meaning that it's outside all work areas in the direction of that edge. | |
| 145 bool PositionIsOffscreen(int position, Edge edge) const; | |
| 146 | |
| 147 // Adjusts |bounds| to be visible onscreen, biased toward the work area of the | 117 // Adjusts |bounds| to be visible onscreen, biased toward the work area of the |
| 148 // monitor containing |other_bounds|. Despite the name, this doesn't | 118 // monitor containing |other_bounds|. Despite the name, this doesn't |
| 149 // guarantee the bounds are fully contained within this monitor's work rect; | 119 // guarantee the bounds are fully contained within this monitor's work rect; |
| 150 // it just tried to ensure the edges are visible on _some_ work rect. | 120 // it just tried to ensure the edges are visible on _some_ work rect. |
| 151 // If |saved_work_area| is non-empty, it is used to determine whether the | 121 // If |saved_work_area| is non-empty, it is used to determine whether the |
| 152 // monitor cofiguration has changed. If it has, bounds are repositioned and | 122 // monitor cofiguration has changed. If it has, bounds are repositioned and |
| 153 // resized if necessary to make them completely contained in the current work | 123 // resized if necessary to make them completely contained in the current work |
| 154 // area. | 124 // area. |
| 155 void AdjustBoundsToBeVisibleOnMonitorContaining( | 125 void AdjustBoundsToBeVisibleOnMonitorContaining( |
| 156 const gfx::Rect& other_bounds, | 126 const gfx::Rect& other_bounds, |
| 157 const gfx::Rect& saved_work_area, | 127 const gfx::Rect& saved_work_area, |
| 158 gfx::Rect* bounds) const; | 128 gfx::Rect* bounds) const; |
| 159 | 129 |
| 160 // Providers for persistent storage and monitor metrics. | 130 // Providers for persistent storage and monitor metrics. |
| 161 scoped_ptr<StateProvider> state_provider_; | 131 scoped_ptr<StateProvider> state_provider_; |
| 162 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; | 132 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; |
| 163 | 133 |
| 164 DISALLOW_COPY_AND_ASSIGN(WindowSizer); | 134 DISALLOW_COPY_AND_ASSIGN(WindowSizer); |
| 165 }; | 135 }; |
| 166 | 136 |
| 167 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_H_ | 137 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_H_ |
| OLD | NEW |