| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // shown at based several factors, including the position and size of the last | 25 // shown at based several factors, including the position and size of the last |
| 26 // window of the same type, the last saved bounds of the window from the | 26 // window of the same type, the last saved bounds of the window from the |
| 27 // previous session, and default system metrics if neither of the above two | 27 // previous session, and default system metrics if neither of the above two |
| 28 // conditions exist. The system has built-in providers for monitor metrics | 28 // conditions exist. The system has built-in providers for monitor metrics |
| 29 // and persistent storage (using preferences) but can be overrided with mocks | 29 // and persistent storage (using preferences) but can be overrided with mocks |
| 30 // for testing. | 30 // for testing. |
| 31 // | 31 // |
| 32 class WindowSizer { | 32 class WindowSizer { |
| 33 public: | 33 public: |
| 34 class StateProvider; | 34 class StateProvider; |
| 35 class TargetDisplayProvider; |
| 35 | 36 |
| 36 // WindowSizer owns |state_provider| and will create a default | 37 // WindowSizer owns |state_provider| and |target_display_provider|, |
| 37 // MonitorInfoProvider using the physical screen. | 38 // and will use the platforms's gfx::Screen. |
| 38 WindowSizer(StateProvider* state_provider, const Browser* browser); | 39 WindowSizer(scoped_ptr<StateProvider> state_provider, |
| 40 scoped_ptr<TargetDisplayProvider> target_display_provider, |
| 41 const Browser* browser); |
| 39 | 42 |
| 40 // WindowSizer owns |state_provider| and will use the supplied |screen|. | 43 // WindowSizer owns |state_provider| and |target_display_provider|, |
| 41 // Used only for testing. | 44 // and will use the supplied |screen|. Used only for testing. |
| 42 WindowSizer(StateProvider* state_provider, | 45 WindowSizer(scoped_ptr<StateProvider> state_provider, |
| 46 scoped_ptr<TargetDisplayProvider> target_display_provider, |
| 43 gfx::Screen* screen, | 47 gfx::Screen* screen, |
| 44 const Browser* browser); | 48 const Browser* browser); |
| 45 | 49 |
| 46 virtual ~WindowSizer(); | 50 virtual ~WindowSizer(); |
| 47 | 51 |
| 48 // An interface implemented by an object that can retrieve state from either a | 52 // An interface implemented by an object that can retrieve state from either a |
| 49 // persistent store or an existing window. | 53 // persistent store or an existing window. |
| 50 class StateProvider { | 54 class StateProvider { |
| 51 public: | 55 public: |
| 52 virtual ~StateProvider() {} | 56 virtual ~StateProvider() {} |
| 53 | 57 |
| 54 // Retrieve the persisted bounds of the window. Returns true if there was | 58 // Retrieve the persisted bounds of the window. Returns true if there was |
| 55 // persisted data to retrieve state information, false otherwise. | 59 // persisted data to retrieve state information, false otherwise. |
| 56 // The |show_state| variable will only be touched if there was persisted | 60 // The |show_state| variable will only be touched if there was persisted |
| 57 // data and the |show_state| variable is SHOW_STATE_DEFAULT. | 61 // data and the |show_state| variable is SHOW_STATE_DEFAULT. |
| 58 virtual bool GetPersistentState(gfx::Rect* bounds, | 62 virtual bool GetPersistentState(gfx::Rect* bounds, |
| 59 gfx::Rect* work_area, | 63 gfx::Rect* work_area, |
| 60 ui::WindowShowState* show_state) const = 0; | 64 ui::WindowShowState* show_state) const = 0; |
| 61 | 65 |
| 62 // Retrieve the bounds of the most recent window of the matching type. | 66 // Retrieve the bounds of the most recent window of the matching type. |
| 63 // Returns true if there was a last active window to retrieve state | 67 // Returns true if there was a last active window to retrieve state |
| 64 // information from, false otherwise. | 68 // information from, false otherwise. |
| 65 // The |show_state| variable will only be touched if we have found a | 69 // The |show_state| variable will only be touched if we have found a |
| 66 // suitable window and the |show_state| variable is SHOW_STATE_DEFAULT. | 70 // suitable window and the |show_state| variable is SHOW_STATE_DEFAULT. |
| 67 virtual bool GetLastActiveWindowState( | 71 virtual bool GetLastActiveWindowState( |
| 68 gfx::Rect* bounds, | 72 gfx::Rect* bounds, |
| 69 ui::WindowShowState* show_state) const = 0; | 73 ui::WindowShowState* show_state) const = 0; |
| 70 }; | 74 }; |
| 71 | 75 |
| 76 // An interface implemented by an object to identify on which |
| 77 // display a new window should be located. |
| 78 class TargetDisplayProvider { |
| 79 public: |
| 80 virtual ~TargetDisplayProvider() {} |
| 81 virtual gfx::Display GetTargetDisplay(const gfx::Screen* screen, |
| 82 const gfx::Rect& bounds) const = 0; |
| 83 }; |
| 84 |
| 72 // Determines the position and size for a window as it is created as well | 85 // Determines the position and size for a window as it is created as well |
| 73 // as the initial state. This function uses several strategies to figure out | 86 // as the initial state. This function uses several strategies to figure out |
| 74 // optimal size and placement, first looking for an existing active window, | 87 // optimal size and placement, first looking for an existing active window, |
| 75 // then falling back to persisted data from a previous session, finally | 88 // then falling back to persisted data from a previous session, finally |
| 76 // utilizing a default algorithm. If |specified_bounds| are non-empty, this | 89 // utilizing a default algorithm. If |specified_bounds| are non-empty, this |
| 77 // value is returned instead. For use only in testing. | 90 // value is returned instead. For use only in testing. |
| 78 // |show_state| will be overwritten and return the initial visual state of | 91 // |show_state| will be overwritten and return the initial visual state of |
| 79 // the window to use. | 92 // the window to use. |
| 80 void DetermineWindowBoundsAndShowState( | 93 void DetermineWindowBoundsAndShowState( |
| 81 const gfx::Rect& specified_bounds, | 94 const gfx::Rect& specified_bounds, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 chrome::HostDesktopType type); | 112 chrome::HostDesktopType type); |
| 100 | 113 |
| 101 // How much horizontal and vertical offset there is between newly | 114 // How much horizontal and vertical offset there is between newly |
| 102 // opened windows. This value may be different on each platform. | 115 // opened windows. This value may be different on each platform. |
| 103 static const int kWindowTilePixels; | 116 static const int kWindowTilePixels; |
| 104 | 117 |
| 105 private: | 118 private: |
| 106 // The edge of the screen to check for out-of-bounds. | 119 // The edge of the screen to check for out-of-bounds. |
| 107 enum Edge { TOP, LEFT, BOTTOM, RIGHT }; | 120 enum Edge { TOP, LEFT, BOTTOM, RIGHT }; |
| 108 | 121 |
| 109 // Gets the size and placement of the last window. Returns true if this data | 122 // Gets the size and placement of the last active window. Returns true if this |
| 110 // is valid, false if there is no last window and the application should | 123 // data is valid, false if there is no last window and the application should |
| 111 // restore saved state from preferences using RestoreWindowPosition. | 124 // restore saved state from preferences using RestoreWindowPosition. |
| 112 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. | 125 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
| 113 bool GetLastWindowBounds(gfx::Rect* bounds, | 126 bool GetLastActiveWindowBounds(gfx::Rect* bounds, |
| 114 ui::WindowShowState* show_state) const; | 127 ui::WindowShowState* show_state) const; |
| 115 | 128 |
| 116 // Gets the size and placement of the last window in the last session, saved | 129 // Gets the size and placement of the last window in the last session, saved |
| 117 // in local state preferences. Returns true if local state exists containing | 130 // in local state preferences. Returns true if local state exists containing |
| 118 // this information, false if this information does not exist and a default | 131 // this information, false if this information does not exist and a default |
| 119 // size should be used. | 132 // size should be used. |
| 120 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. | 133 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
| 121 bool GetSavedWindowBounds(gfx::Rect* bounds, | 134 bool GetSavedWindowBounds(gfx::Rect* bounds, |
| 122 ui::WindowShowState* show_state) const; | 135 ui::WindowShowState* show_state) const; |
| 123 | 136 |
| 124 // Gets the default window position and size to be shown on | 137 // Gets the default window position and size to be shown on |
| 125 // |display| if there is no last window and no saved window | 138 // |display| if there is no last window and no saved window |
| 126 // placement in prefs. This function determines the default size | 139 // placement in prefs. This function determines the default size |
| 127 // based on monitor size, etc. | 140 // based on monitor size, etc. |
| 128 void GetDefaultWindowBounds(const gfx::Display& display, | 141 void GetDefaultWindowBounds(const gfx::Display& display, |
| 129 gfx::Rect* default_bounds) const; | 142 gfx::Rect* default_bounds) const; |
| 130 | 143 |
| 131 // Adjusts |bounds| to be visible on-screen, biased toward the work area of | 144 // Adjusts |bounds| to be visible on-screen, biased toward the work area of |
| 132 // the monitor containing |other_bounds|. Despite the name, this doesn't | 145 // the |display|. Despite the name, this doesn't |
| 133 // guarantee the bounds are fully contained within this monitor's work rect; | 146 // guarantee the bounds are fully contained within this display's work rect; |
| 134 // it just tried to ensure the edges are visible on _some_ work rect. | 147 // it just tried to ensure the edges are visible on _some_ work rect. |
| 135 // If |saved_work_area| is non-empty, it is used to determine whether the | 148 // If |saved_work_area| is non-empty, it is used to determine whether the |
| 136 // monitor configuration has changed. If it has, bounds are repositioned and | 149 // monitor configuration has changed. If it has, bounds are repositioned and |
| 137 // resized if necessary to make them completely contained in the current work | 150 // resized if necessary to make them completely contained in the current work |
| 138 // area. | 151 // area. |
| 139 void AdjustBoundsToBeVisibleOnMonitorContaining( | 152 void AdjustBoundsToBeVisibleOnDisplay( |
| 140 const gfx::Rect& other_bounds, | 153 const gfx::Display& display, |
| 141 const gfx::Rect& saved_work_area, | 154 const gfx::Rect& saved_work_area, |
| 142 gfx::Rect* bounds) const; | 155 gfx::Rect* bounds) const; |
| 143 | 156 |
| 157 // Determine the target display for a new window based on |
| 158 // |bounds|. On ash environment, this returns the display containing |
| 159 // ash's the target root window. |
| 160 gfx::Display GetTargetDisplay(const gfx::Rect& bounds) const; |
| 161 |
| 144 #if defined(USE_ASH) | 162 #if defined(USE_ASH) |
| 145 // Determines the position and size for a tabbed browser window in | 163 // Determines the position and size for a tabbed browser window in |
| 146 // ash as it gets created. This will be called before other standard | 164 // ash as it gets created. This will be called before other standard |
| 147 // placement logic. |show_state| will only be changed | 165 // placement logic. |show_state| will only be changed |
| 148 // if it was set to SHOW_STATE_DEFAULT. | 166 // if it was set to SHOW_STATE_DEFAULT. |
| 149 void GetTabbedBrowserBoundsAsh(gfx::Rect* bounds_in_screen, | 167 void GetTabbedBrowserBoundsAsh(gfx::Rect* bounds_in_screen, |
| 150 ui::WindowShowState* show_state) const; | 168 ui::WindowShowState* show_state) const; |
| 151 #endif | 169 #endif |
| 152 | 170 |
| 153 // Determine the default show state for the window - not looking at other | 171 // Determine the default show state for the window - not looking at other |
| 154 // windows or at persistent information. | 172 // windows or at persistent information. |
| 155 ui::WindowShowState GetWindowDefaultShowState() const; | 173 ui::WindowShowState GetWindowDefaultShowState() const; |
| 156 | 174 |
| 157 #if defined(USE_ASH) | 175 #if defined(USE_ASH) |
| 158 bool IsTabbedBrowserInAsh() const; | 176 bool IsTabbedBrowserInAsh() const; |
| 159 bool IsPopupBrowserInAsh() const; | 177 bool IsPopupBrowserInAsh() const; |
| 160 #endif | 178 #endif |
| 161 | 179 |
| 162 // Providers for persistent storage and monitor metrics. | 180 // Providers for persistent storage and monitor metrics. |
| 163 scoped_ptr<StateProvider> state_provider_; | 181 scoped_ptr<StateProvider> state_provider_; |
| 182 scoped_ptr<TargetDisplayProvider> target_display_provider_; |
| 164 gfx::Screen* screen_; // not owned. | 183 gfx::Screen* screen_; // not owned. |
| 165 | 184 |
| 166 // Note that this browser handle might be NULL. | 185 // Note that this browser handle might be NULL. |
| 167 const Browser* browser_; | 186 const Browser* browser_; |
| 168 | 187 |
| 169 DISALLOW_COPY_AND_ASSIGN(WindowSizer); | 188 DISALLOW_COPY_AND_ASSIGN(WindowSizer); |
| 170 }; | 189 }; |
| 171 | 190 |
| 172 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 191 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
| OLD | NEW |