| 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 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
| 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/ui/host_desktop.h" | 10 #include "chrome/browser/ui/host_desktop.h" |
| 11 #include "ui/base/ui_base_types.h" |
| 11 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 12 | 13 |
| 13 class Browser; | 14 class Browser; |
| 14 | 15 |
| 15 // An interface implemented by an object that can retrieve information about | 16 // An interface implemented by an object that can retrieve information about |
| 16 // the monitors on the system. | 17 // the monitors on the system. |
| 17 class MonitorInfoProvider { | 18 class MonitorInfoProvider { |
| 18 public: | 19 public: |
| 19 virtual ~MonitorInfoProvider() {} | 20 virtual ~MonitorInfoProvider() {} |
| 20 | 21 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 virtual ~WindowSizer(); | 59 virtual ~WindowSizer(); |
| 59 | 60 |
| 60 // An interface implemented by an object that can retrieve state from either a | 61 // An interface implemented by an object that can retrieve state from either a |
| 61 // persistent store or an existing window. | 62 // persistent store or an existing window. |
| 62 class StateProvider { | 63 class StateProvider { |
| 63 public: | 64 public: |
| 64 virtual ~StateProvider() {} | 65 virtual ~StateProvider() {} |
| 65 | 66 |
| 66 // Retrieve the persisted bounds of the window. Returns true if there was | 67 // Retrieve the persisted bounds of the window. Returns true if there was |
| 67 // persisted data to retrieve state information, false otherwise. | 68 // persisted data to retrieve state information, false otherwise. |
| 69 // The |show_state| variable will only be touched if there was persisted |
| 70 // data and the |show_state| variable is SHOW_STATE_DEFAULT. |
| 68 virtual bool GetPersistentState(gfx::Rect* bounds, | 71 virtual bool GetPersistentState(gfx::Rect* bounds, |
| 69 gfx::Rect* work_area) const = 0; | 72 gfx::Rect* work_area, |
| 73 ui::WindowShowState* show_state) const = 0; |
| 70 | 74 |
| 71 // Retrieve the bounds of the most recent window of the matching type. | 75 // Retrieve the bounds of the most recent window of the matching type. |
| 72 // Returns true if there was a last active window to retrieve state | 76 // Returns true if there was a last active window to retrieve state |
| 73 // information from, false otherwise. | 77 // information from, false otherwise. |
| 74 virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const = 0; | 78 // The |show_state| variable will only be touched if we have found a |
| 79 // suitable window and the |show_state| variable is SHOW_STATE_DEFAULT. |
| 80 virtual bool GetLastActiveWindowState( |
| 81 gfx::Rect* bounds, |
| 82 ui::WindowShowState* show_state) const = 0; |
| 75 }; | 83 }; |
| 76 | 84 |
| 77 // Determines the position and size for a window as it is created. This | 85 // Determines the position and size for a window as it is created as well |
| 78 // function uses several strategies to figure out optimal size and placement, | 86 // as the initial state. This function uses several strategies to figure out |
| 79 // first looking for an existing active window, then falling back to persisted | 87 // optimal size and placement, first looking for an existing active window, |
| 80 // data from a previous session, finally utilizing a default | 88 // then falling back to persisted data from a previous session, finally |
| 81 // algorithm. If |specified_bounds| are non-empty, this value is returned | 89 // utilizing a default algorithm. If |specified_bounds| are non-empty, this |
| 82 // instead. For use only in testing. | 90 // value is returned instead. For use only in testing. |
| 83 void DetermineWindowBounds(const gfx::Rect& specified_bounds, | 91 // |show_state| will be overwritten and return the initial visual state of |
| 84 gfx::Rect* bounds) const; | 92 // the window to use. |
| 93 void DetermineWindowBoundsAndShowState( |
| 94 const gfx::Rect& specified_bounds, |
| 95 gfx::Rect* bounds, |
| 96 ui::WindowShowState* show_state) const; |
| 85 | 97 |
| 86 // Determines the size, position and maximized state for the browser window. | 98 // Determines the size, position and maximized state for the browser window. |
| 87 // See documentation for DetermineWindowBounds above. Normally, | 99 // See documentation for DetermineWindowBounds above. Normally, |
| 88 // |window_bounds| is calculated by calling GetLastActiveWindowState(). To | 100 // |window_bounds| is calculated by calling GetLastActiveWindowState(). To |
| 89 // explicitly specify a particular window to base the bounds on, pass in a | 101 // explicitly specify a particular window to base the bounds on, pass in a |
| 90 // non-NULL value for |browser|. | 102 // non-NULL value for |browser|. |
| 91 static void GetBrowserWindowBounds(const std::string& app_name, | 103 static void GetBrowserWindowBoundsAndShowState( |
| 92 const gfx::Rect& specified_bounds, | 104 const std::string& app_name, |
| 93 const Browser* browser, | 105 const gfx::Rect& specified_bounds, |
| 94 gfx::Rect* window_bounds); | 106 const Browser* browser, |
| 107 gfx::Rect* window_bounds, |
| 108 ui::WindowShowState* show_state); |
| 95 | 109 |
| 96 // Returns the default origin for popups of the given size. | 110 // Returns the default origin for popups of the given size. |
| 97 static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size, | 111 static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size, |
| 98 chrome::HostDesktopType type); | 112 chrome::HostDesktopType type); |
| 99 | 113 |
| 100 // The number of pixels which are kept free top, left and right when a window | 114 // The number of pixels which are kept free top, left and right when a window |
| 101 // gets positioned to its default location. | 115 // gets positioned to its default location. |
| 102 static const int kDesktopBorderSize; | 116 static const int kDesktopBorderSize; |
| 103 | 117 |
| 104 // Maximum width of a window even if there is more room on the desktop. | 118 // Maximum width of a window even if there is more room on the desktop. |
| 105 static const int kMaximumWindowWidth; | 119 static const int kMaximumWindowWidth; |
| 106 | 120 |
| 107 // How much horizontal and vertical offset there is between newly | 121 // How much horizontal and vertical offset there is between newly |
| 108 // opened windows. This value may be different on each platform. | 122 // opened windows. This value may be different on each platform. |
| 109 static const int kWindowTilePixels; | 123 static const int kWindowTilePixels; |
| 110 | 124 |
| 111 private: | 125 private: |
| 112 // The edge of the screen to check for out-of-bounds. | 126 // The edge of the screen to check for out-of-bounds. |
| 113 enum Edge { TOP, LEFT, BOTTOM, RIGHT }; | 127 enum Edge { TOP, LEFT, BOTTOM, RIGHT }; |
| 114 | 128 |
| 115 // Gets the size and placement of the last window. Returns true if this data | 129 // Gets the size and placement of the last window. Returns true if this data |
| 116 // is valid, false if there is no last window and the application should | 130 // is valid, false if there is no last window and the application should |
| 117 // restore saved state from preferences using RestoreWindowPosition. | 131 // restore saved state from preferences using RestoreWindowPosition. |
| 118 bool GetLastWindowBounds(gfx::Rect* bounds) const; | 132 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
| 133 bool GetLastWindowBounds(gfx::Rect* bounds, |
| 134 ui::WindowShowState* show_state) const; |
| 119 | 135 |
| 120 // Gets the size and placement of the last window in the last session, saved | 136 // Gets the size and placement of the last window in the last session, saved |
| 121 // in local state preferences. Returns true if local state exists containing | 137 // in local state preferences. Returns true if local state exists containing |
| 122 // this information, false if this information does not exist and a default | 138 // this information, false if this information does not exist and a default |
| 123 // size should be used. | 139 // size should be used. |
| 124 bool GetSavedWindowBounds(gfx::Rect* bounds) const; | 140 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
| 141 bool GetSavedWindowBounds(gfx::Rect* bounds, |
| 142 ui::WindowShowState* show_state) const; |
| 125 | 143 |
| 126 // Gets the default window position and size if there is no last window and | 144 // Gets the default window position and size if there is no last window and |
| 127 // no saved window placement in prefs. This function determines the default | 145 // no saved window placement in prefs. This function determines the default |
| 128 // size based on monitor size, etc. | 146 // size based on monitor size, etc. |
| 129 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const; | 147 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const; |
| 130 #if defined(USE_ASH) | 148 #if defined(USE_ASH) |
| 131 void GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const; | 149 void GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const; |
| 132 #endif | 150 #endif |
| 133 | 151 |
| 134 // Adjusts |bounds| to be visible on-screen, biased toward the work area of | 152 // Adjusts |bounds| to be visible on-screen, biased toward the work area of |
| 135 // the monitor containing |other_bounds|. Despite the name, this doesn't | 153 // the monitor containing |other_bounds|. Despite the name, this doesn't |
| 136 // guarantee the bounds are fully contained within this monitor's work rect; | 154 // guarantee the bounds are fully contained within this monitor's work rect; |
| 137 // it just tried to ensure the edges are visible on _some_ work rect. | 155 // it just tried to ensure the edges are visible on _some_ work rect. |
| 138 // If |saved_work_area| is non-empty, it is used to determine whether the | 156 // If |saved_work_area| is non-empty, it is used to determine whether the |
| 139 // monitor configuration has changed. If it has, bounds are repositioned and | 157 // monitor configuration has changed. If it has, bounds are repositioned and |
| 140 // resized if necessary to make them completely contained in the current work | 158 // resized if necessary to make them completely contained in the current work |
| 141 // area. | 159 // area. |
| 142 void AdjustBoundsToBeVisibleOnMonitorContaining( | 160 void AdjustBoundsToBeVisibleOnMonitorContaining( |
| 143 const gfx::Rect& other_bounds, | 161 const gfx::Rect& other_bounds, |
| 144 const gfx::Rect& saved_work_area, | 162 const gfx::Rect& saved_work_area, |
| 145 gfx::Rect* bounds) const; | 163 gfx::Rect* bounds) const; |
| 146 | 164 |
| 147 // Determines the position and size for a window as it gets created. This | 165 // Determines the position and size for a window as it gets created. This |
| 148 // will be called before DetermineWindowBounds. It will return true when the | 166 // will be called before DetermineWindowBounds. It will return true when the |
| 149 // function was setting the bounds structure to the desired size. Otherwise | 167 // function was setting the bounds structure to the desired size. Otherwise |
| 150 // another algorithm should get used to determine the correct bounds. | 168 // another algorithm should get used to determine the correct bounds. |
| 169 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
| 151 bool GetBoundsOverride(const gfx::Rect& specified_bounds, | 170 bool GetBoundsOverride(const gfx::Rect& specified_bounds, |
| 152 gfx::Rect* bounds) const; | 171 gfx::Rect* bounds, |
| 172 ui::WindowShowState* show_state) const; |
| 153 #if defined(USE_ASH) | 173 #if defined(USE_ASH) |
| 154 bool GetBoundsOverrideAsh(const gfx::Rect& specified_bounds, | 174 bool GetBoundsOverrideAsh(const gfx::Rect& specified_bounds, |
| 155 gfx::Rect* bounds_in_screen) const; | 175 gfx::Rect* bounds_in_screen, |
| 176 ui::WindowShowState* show_state) const; |
| 156 #endif | 177 #endif |
| 157 | 178 |
| 179 // Determine the default show state for the window - not looking at other |
| 180 // windows or at persistent information. |
| 181 ui::WindowShowState GetWindowDefaultShowState() const; |
| 182 |
| 158 // Providers for persistent storage and monitor metrics. | 183 // Providers for persistent storage and monitor metrics. |
| 159 scoped_ptr<StateProvider> state_provider_; | 184 scoped_ptr<StateProvider> state_provider_; |
| 160 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; | 185 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; |
| 161 | 186 |
| 162 // Note that this browser handle might be NULL. | 187 // Note that this browser handle might be NULL. |
| 163 const Browser* browser_; | 188 const Browser* browser_; |
| 164 | 189 |
| 165 DISALLOW_COPY_AND_ASSIGN(WindowSizer); | 190 DISALLOW_COPY_AND_ASSIGN(WindowSizer); |
| 166 }; | 191 }; |
| 167 | 192 |
| 168 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 193 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
| OLD | NEW |