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

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer_ash.cc

Issue 12213053: Plumb HostDesktopType through window_sizer_ash.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: window_sizer_ash should only work on the ash browser list Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/ui/window_sizer/window_sizer.h" 5 #include "chrome/browser/ui/window_sizer/window_sizer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/wm/window_cycle_controller.h" 8 #include "ash/wm/window_cycle_controller.h"
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list_impl.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
16 #include "chrome/browser/ui/host_desktop.h"
16 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 #include "ui/aura/window_delegate.h" 19 #include "ui/aura/window_delegate.h"
19 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
20 21
21 namespace { 22 namespace {
22 23
23 // When a window gets opened in default mode and the screen is less then this 24 // When a window gets opened in default mode and the screen is less then this
24 // width, the window will get opened in maximized mode. 25 // width, the window will get opened in maximized mode.
25 const int kForceMaximizeWidthLimit = 1450; 26 const int kForceMaximizeWidthLimit = 1450;
26 27
27 // Check if the given browser is 'valid': It is a tabbed, non minimized 28 // Check if the given browser is 'valid': It is a tabbed, non minimized
28 // window, which intersects with the |bounds_in_screen| area of a given screen. 29 // window, which intersects with the |bounds_in_screen| area of a given screen.
29 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) { 30 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) {
30 return (browser && browser->window() && 31 return (browser && browser->window() &&
31 !(browser->is_type_popup() || browser->is_type_panel()) && 32 !(browser->is_type_popup() || browser->is_type_panel()) &&
32 !browser->window()->IsMinimized() && 33 !browser->window()->IsMinimized() &&
33 browser->window()->GetNativeWindow() && 34 browser->window()->GetNativeWindow() &&
34 bounds_in_screen.Intersects( 35 bounds_in_screen.Intersects(
35 browser->window()->GetNativeWindow()->GetBoundsInScreen())); 36 browser->window()->GetNativeWindow()->GetBoundsInScreen()));
36 } 37 }
37 38
38 // Check if the window was not created as popup or as panel, it is 39 // Check if the window was not created as popup or as panel, it is
39 // on the screen defined by |bounds_in_screen| and visible. 40 // on the screen defined by |bounds_in_screen| and visible.
40 bool IsValidToplevelWindow(aura::Window* window, 41 bool IsValidToplevelWindow(aura::Window* window,
41 const gfx::Rect& bounds_in_screen) { 42 const gfx::Rect& bounds_in_screen) {
42 for (BrowserList::const_iterator iter = BrowserList::begin(); 43 const chrome::BrowserListImpl* ash_browser_list =
43 iter != BrowserList::end(); 44 chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
45 for (chrome::BrowserListImpl::const_iterator iter = ash_browser_list->begin();
46 iter != ash_browser_list->end();
44 ++iter) { 47 ++iter) {
45 Browser* browser = *iter; 48 Browser* browser = *iter;
46 if (browser && browser->window() && 49 if (browser && browser->window() &&
47 browser->window()->GetNativeWindow() == window) 50 browser->window()->GetNativeWindow() == window) {
48 return IsValidBrowser(browser, bounds_in_screen); 51 return IsValidBrowser(browser, bounds_in_screen);
52 }
49 } 53 }
50 // A window which has no browser associated with it is probably not a window 54 // A window which has no browser associated with it is probably not a window
51 // of which we want to copy the size from. 55 // of which we want to copy the size from.
52 return false; 56 return false;
53 } 57 }
54 58
55 // Get the first open (non minimized) window which is on the screen defined 59 // Get the first open (non minimized) window which is on the screen defined
56 // by |bounds_in_screen| and visible. 60 // by |bounds_in_screen| and visible.
57 aura::Window* GetTopWindow(const gfx::Rect& bounds_in_screen) { 61 aura::Window* GetTopWindow(const gfx::Rect& bounds_in_screen) {
58 // Get the active window. 62 // Get the active window.
59 aura::Window* window = ash::wm::GetActiveWindow(); 63 aura::Window* window = ash::wm::GetActiveWindow();
60 if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL && 64 if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL &&
61 window->IsVisible() && IsValidToplevelWindow(window, bounds_in_screen)) 65 window->IsVisible() && IsValidToplevelWindow(window, bounds_in_screen)) {
62 return window; 66 return window;
67 }
63 68
64 // Get a list of all windows. 69 // Get a list of all windows.
65 const std::vector<aura::Window*> windows = 70 const std::vector<aura::Window*> windows =
66 ash::WindowCycleController::BuildWindowList(NULL); 71 ash::WindowCycleController::BuildWindowList(NULL);
67 72
68 if (windows.empty()) 73 if (windows.empty())
69 return NULL; 74 return NULL;
70 75
71 aura::Window::Windows::const_iterator iter = windows.begin(); 76 aura::Window::Windows::const_iterator iter = windows.begin();
72 // Find the index of the current window. 77 // Find the index of the current window.
73 if (window) 78 if (window)
74 iter = std::find(windows.begin(), windows.end(), window); 79 iter = std::find(windows.begin(), windows.end(), window);
75 80
76 int index = (iter == windows.end()) ? 0 : (iter - windows.begin()); 81 int index = (iter == windows.end()) ? 0 : (iter - windows.begin());
77 82
78 // Scan the cycle list backwards to see which is the second topmost window 83 // Scan the cycle list backwards to see which is the second topmost window
79 // (and so on). Note that we might cycle a few indices twice if there is no 84 // (and so on). Note that we might cycle a few indices twice if there is no
80 // suitable window. However - since the list is fairly small this should be 85 // suitable window. However - since the list is fairly small this should be
81 // very fast anyways. 86 // very fast anyways.
82 for (int i = index + windows.size(); i >= 0; i--) { 87 for (int i = index + windows.size(); i >= 0; i--) {
83 aura::Window* window = windows[i % windows.size()]; 88 aura::Window* window = windows[i % windows.size()];
84 if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL && 89 if (window && window->type() == aura::client::WINDOW_TYPE_NORMAL &&
85 bounds_in_screen.Intersects(window->GetBoundsInScreen()) && 90 bounds_in_screen.Intersects(window->GetBoundsInScreen()) &&
86 window->IsVisible() && IsValidToplevelWindow(window, bounds_in_screen)) 91 window->IsVisible()
92 && IsValidToplevelWindow(window, bounds_in_screen)) {
87 return window; 93 return window;
94 }
88 } 95 }
89 return NULL; 96 return NULL;
90 } 97 }
91 98
92 // Return the number of valid top level windows on the screen defined by 99 // Return the number of valid top level windows on the screen defined by
93 // the |bounds_in_screen| rectangle. 100 // the |bounds_in_screen| rectangle.
94 int GetNumberOfValidTopLevelBrowserWindows(const gfx::Rect& bounds_in_screen) { 101 int GetNumberOfValidTopLevelBrowserWindows(const gfx::Rect& bounds_in_screen) {
95 int count = 0; 102 int count = 0;
96 for (BrowserList::const_iterator iter = BrowserList::begin(); 103 const chrome::BrowserListImpl* ash_browser_list =
97 iter != BrowserList::end(); 104 chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
105 for (chrome::BrowserListImpl::const_iterator iter = ash_browser_list->begin();
106 iter != ash_browser_list->end();
98 ++iter) { 107 ++iter) {
99 if (IsValidBrowser(*iter, bounds_in_screen)) 108 if (IsValidBrowser(*iter, bounds_in_screen))
100 count++; 109 count++;
101 } 110 }
102 return count; 111 return count;
103 } 112 }
104 113
105 // Move the given |bounds_in_screen| on the available |work_area| to the 114 // Move the given |bounds_in_screen| on the available |work_area| to the
106 // direction. If |move_right| is true, the rectangle gets moved to the right 115 // direction. If |move_right| is true, the rectangle gets moved to the right
107 // corner. Otherwise to the left side. 116 // corner. Otherwise to the left side.
(...skipping 13 matching lines...) Expand all
121 } 130 }
122 return false; 131 return false;
123 } 132 }
124 133
125 } // namespace 134 } // namespace
126 135
127 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, 136 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen,
128 ui::WindowShowState* show_state) const { 137 ui::WindowShowState* show_state) const {
129 DCHECK(show_state); 138 DCHECK(show_state);
130 DCHECK(bounds_in_screen); 139 DCHECK(bounds_in_screen);
140
141 if (browser_ &&
142 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) {
143 return false;
144 }
131 bounds_in_screen->SetRect(0, 0, 0, 0); 145 bounds_in_screen->SetRect(0, 0, 0, 0);
132 146
133 ui::WindowShowState passed_show_state = *show_state; 147 ui::WindowShowState passed_show_state = *show_state;
134 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) 148 if (!GetSavedWindowBounds(bounds_in_screen, show_state))
135 GetDefaultWindowBounds(bounds_in_screen); 149 GetDefaultWindowBounds(bounds_in_screen);
136 150
137 if (browser_ && browser_->is_type_tabbed()) { 151 if (browser_ && browser_->is_type_tabbed()) {
138 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); 152 aura::RootWindow* active = ash::Shell::GetActiveRootWindow();
139 // Always open new window in the active display. 153 // Always open new window in the active display.
140 gfx::Rect active_area = active->GetBoundsInScreen(); 154 gfx::Rect active_area = active->GetBoundsInScreen();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if (default_width > kMaximumWindowWidth) { 222 if (default_width > kMaximumWindowWidth) {
209 // The window should get centered on the screen and not follow the grid. 223 // The window should get centered on the screen and not follow the grid.
210 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; 224 offset_x = (work_area.width() - kMaximumWindowWidth) / 2;
211 default_width = kMaximumWindowWidth; 225 default_width = kMaximumWindowWidth;
212 } 226 }
213 default_bounds->SetRect(work_area.x() + offset_x, 227 default_bounds->SetRect(work_area.x() + offset_x,
214 work_area.y() + kDesktopBorderSize, 228 work_area.y() + kDesktopBorderSize,
215 default_width, 229 default_width,
216 default_height); 230 default_height);
217 } 231 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698