Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7698)

Unified Diff: chrome/browser/ui/window_sizer/window_sizer_ash.cc

Issue 10911274: Adding new window management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/window_sizer/window_sizer_ash.cc
diff --git a/chrome/browser/ui/window_sizer/window_sizer_ash.cc b/chrome/browser/ui/window_sizer/window_sizer_ash.cc
index fc07742570e11f10fbfdac1564a03df0ae374f67..102aaa4c1576e72f3dd15f3ccced38ae85a0fec6 100644
--- a/chrome/browser/ui/window_sizer/window_sizer_ash.cc
+++ b/chrome/browser/ui/window_sizer/window_sizer_ash.cc
@@ -18,15 +18,18 @@
namespace {
-// Check if the window was not created as popup or as panel.
-bool IsValidToplevelWindow(aura::Window* window) {
+// Check if the window was not created as popup or as panel, it is
+// on the screen defined by |bounds| and visible.
+bool IsValidToplevelWindow(aura::Window* window, const gfx::Rect& bounds) {
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end();
++iter) {
Browser* browser = *iter;
if (browser && browser->window() &&
browser->window()->GetNativeWindow() == window) {
- return (!(browser->is_type_popup() || browser->is_type_panel()));
+ return (!(browser->is_type_popup() || browser->is_type_panel()) &&
+ !browser->window()->IsMinimized() &&
+ bounds.Intersects(browser->window()->GetBounds()));
}
}
// A window which has no browser associated with it is probably not a window
@@ -34,12 +37,13 @@ bool IsValidToplevelWindow(aura::Window* window) {
return false;
}
-// Get the first open window in the stack on the screen.
-aura::Window* GetTopWindow() {
+// Get the first open (non minimized) window which is on the screen defined
+// by |bounds| and visible.
+aura::Window* GetTopWindow(const gfx::Rect& bounds) {
sky 2012/09/13 15:44:51 The coordinates you pass in here are in screen coo
Mr4D (OOO till 08-26) 2012/09/13 16:45:08 Right! Done.
// Get the active window.
aura::Window* window = ash::wm::GetActiveWindow();
if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL &&
- window->IsVisible() && IsValidToplevelWindow(window))
+ window->IsVisible() && IsValidToplevelWindow(window, bounds))
return window;
// Get a list of all windows.
@@ -63,34 +67,89 @@ aura::Window* GetTopWindow() {
for (int i = index + windows.size(); i >= 0; i--) {
aura::Window* window = windows[i % windows.size()];
if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL &&
- window->IsVisible() && IsValidToplevelWindow(window))
+ bounds.Intersects(window->bounds()) &&
+ window->IsVisible() && IsValidToplevelWindow(window, bounds))
return window;
}
return NULL;
}
+// Return the number of valid top level windows on the screen defined by
+// the |bounds| rectangle.
+int GetNumberOfValidTopLevelWindows(const gfx::Rect& bounds) {
sky 2012/09/13 15:44:51 This method is named as though it wants all top le
Mr4D (OOO till 08-26) 2012/09/13 16:45:08 Done.
+ int count = 0;
+ for (BrowserList::const_iterator iter = BrowserList::begin();
+ iter != BrowserList::end();
+ ++iter) {
+ Browser* browser = *iter;
+
+ if (browser && browser->window() &&
sky 2012/09/13 15:44:51 Can this and IsToplevelWindow share code?
Mr4D (OOO till 08-26) 2012/09/13 16:45:08 Done.
+ bounds.Intersects(browser->window()->GetBounds()) &&
+ !browser->window()->IsMinimized() &&
+ !(browser->is_type_popup() || browser->is_type_panel()))
+ count++;
+ }
+ return count;
+}
+
+// Move the given |bounds| on the available |work_area| to the direction.
+// If |move_right| is true, the rectangle gets moved to the right corner.
+// otherwise to the left side.
+bool MoveRect(const gfx::Rect& work_area, gfx::Rect& bounds, bool move_right) {
+ if (move_right) {
+ if (work_area.right() > bounds.right()) {
+ bounds.set_x(work_area.right() - bounds.width());
+ return true;
+ }
+ } else {
+ if (work_area.x() < bounds.x()) {
+ bounds.set_x(work_area.x());
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
-bool WindowSizer::GetBoundsIgnoringPreviousStateAsh(
- const gfx::Rect& specified_bounds,
- gfx::Rect* bounds) const {
+bool WindowSizer::GetBoundsOverrideAsh(const gfx::Rect& specified_bounds,
+ gfx::Rect* bounds) const {
*bounds = specified_bounds;
DCHECK(bounds->IsEmpty());
+
+ if (!GetSavedWindowBounds(bounds))
+ GetDefaultWindowBounds(bounds);
+
if (browser_ != NULL && browser_->type() == Browser::TYPE_TABBED) {
+ gfx::Rect work_area =
+ monitor_info_provider_->GetMonitorWorkAreaMatching(*bounds);
// This is a window / app. See if there is no window and try to place it.
- aura::Window* top_window = GetTopWindow();
- // If there are no windows we have a special case and try to
- // maximize which leaves a 'border' which shows the desktop.
- if (top_window == NULL) {
- GetDefaultWindowBounds(bounds);
- } else {
- *bounds = top_window->GetBoundsInScreen();
- gfx::Rect work_area =
- monitor_info_provider_->GetMonitorWorkAreaMatching(*bounds);
- *bounds = bounds->AdjustToFit(work_area);
+ int count = GetNumberOfValidTopLevelWindows(work_area);
+ aura::Window* top_window = GetTopWindow(work_area);
+
+ // If there is no valid other window we take the coordinates as is.
+ if (!count || !top_window || ash::wm::IsWindowMaximized(top_window))
+ return true;
+
+ gfx::Rect other_bounds = top_window->bounds();
+ bool move_right =
+ other_bounds.CenterPoint().x() < work_area.CenterPoint().x();
+
+ // In case we have only one window, we move the other window fully to the
+ // "other side" - making room for this new window.
+ if (count == 1) {
+ if (MoveRect(work_area, other_bounds, !move_right))
+ top_window->SetBounds(other_bounds);
}
+ // Use the size of the other window, and mirror the location to the
+ // opposite side. Then make sure that it is inside our work area
+ // (if possible).
+ *bounds = other_bounds;
+ MoveRect(work_area, *bounds, move_right);
+ if (bounds->bottom() > work_area.bottom())
+ bounds->set_y(std::max(work_area.y(),
+ work_area.bottom() - bounds->height()));
return true;
- // If both fail we will continue the default path.
}
return false;
« no previous file with comments | « chrome/browser/ui/window_sizer/window_sizer.cc ('k') | chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698