Remove BrowserList::GetLastActive calls from window_sizer.cc et al.

BUG=129187
TEST=NONE


Review URL: https://chromiumcodereview.appspot.com/10836218

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151665 0039d316-1c4b-4281-b951-d872f2087c98
parent f706df57
......@@ -6,6 +6,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_impl.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
......@@ -161,6 +162,14 @@ Browser* FindLastActiveWithProfile(Profile* profile) {
Browser::FEATURE_NONE, kMatchAny);
}
Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) {
chrome::BrowserListImpl* browser_list_impl =
chrome::BrowserListImpl::GetInstance(type);
if (browser_list_impl)
return browser_list_impl->GetLastActive();
return NULL;
}
size_t GetBrowserCount(Profile* profile) {
return GetBrowserCountImpl(profile, kMatchAny);
}
......
......@@ -57,6 +57,12 @@ Browser* FindBrowserWithWebContents(const content::WebContents* web_contents);
// NULL. WARNING: see warnings in BrowserList::GetLastActive().
Browser* FindLastActiveWithProfile(Profile* profile);
// Identical in behavior to BrowserList::GetLastActive(), except that the most
// recently open browser owned on the desktop described by |type| is returned.
// If none exist, returns NULL. WARNING: see warnings in
// BrowserList::GetLastActive().
Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type);
// Returns the number of browsers with the Profile |profile|.
size_t GetBrowserCount(Profile* profile);
......
......@@ -277,7 +277,9 @@ enum {
if ((browser_->is_type_popup() || browser_->is_type_panel()) &&
windowRect.x() == 0 && windowRect.y() == 0) {
gfx::Size size = windowRect.size();
windowRect.set_origin(WindowSizer::GetDefaultPopupOrigin(size));
windowRect.set_origin(
WindowSizer::GetDefaultPopupOrigin(size,
browser_->host_desktop_type()));
}
// Size and position the window. Note that it is not yet onscreen. Popup
......
......@@ -1636,7 +1636,9 @@ bool BrowserView::GetSavedWindowPlacement(
// assume none were given by the window.open() command.
if (window_rect.x() == 0 && window_rect.y() == 0) {
gfx::Size size = window_rect.size();
window_rect.set_origin(WindowSizer::GetDefaultPopupOrigin(size));
window_rect.set_origin(
WindowSizer::GetDefaultPopupOrigin(size,
browser_->host_desktop_type()));
}
*bounds = window_rect;
......
......@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/host_desktop.h"
#include "ui/gfx/rect.h"
class Browser;
......@@ -93,7 +94,8 @@ class WindowSizer {
gfx::Rect* window_bounds);
// Returns the default origin for popups of the given size.
static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size);
static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size,
chrome::HostDesktopType type);
// The number of pixels which are kept free top, left and right when a window
// gets positioned to its default location.
......
......@@ -4,12 +4,15 @@
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/ui/host_desktop.h"
// This doesn't matter for aura, which has different tiling.
// static
const int WindowSizer::kWindowTilePixels = 10;
// static
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) {
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size,
chrome::HostDesktopType type) {
// TODO(skuhne): Check if this isn't needed anymore (since it is implemented
// in WindowPositioner) and remove it.
return gfx::Point();
......
......@@ -8,8 +8,9 @@
#include "base/logging.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "ui/gfx/screen.h"
// Used to pad the default new window size. On Windows, this is also used for
......@@ -19,10 +20,12 @@
const int WindowSizer::kWindowTilePixels = 10;
// static
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) {
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size,
chrome::HostDesktopType type) {
gfx::Rect monitor_bounds = gfx::Screen::GetPrimaryDisplay().work_area();
gfx::Point corner(monitor_bounds.x(), monitor_bounds.y());
if (Browser* browser = BrowserList::GetLastActive()) {
if (Browser* browser = browser::FindLastActiveWithHostDesktopType(type)) {
GtkWindow* window =
reinterpret_cast<GtkWindow*>(browser->window()->GetNativeWindow());
int x = 0, y = 0;
......
......@@ -7,21 +7,23 @@
#import <Cocoa/Cocoa.h>
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
// How much horizontal and vertical offset there is between newly
// opened windows.
const int WindowSizer::kWindowTilePixels = 22;
// static
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) {
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size,
chrome::HostDesktopType type) {
NSRect work_area = [[NSScreen mainScreen] visibleFrame];
NSRect main_area = [[[NSScreen screens] objectAtIndex:0] frame];
NSPoint corner = NSMakePoint(NSMinX(work_area), NSMaxY(work_area));
if (Browser* b = BrowserList::GetLastActive()) {
NSWindow* window = b->window()->GetNativeWindow();
if (Browser* browser = browser::FindLastActiveWithHostDesktopType(type)) {
NSWindow* window = browser->window()->GetNativeWindow();
NSRect window_frame = [window frame];
// Limit to not overflow the work area right and bottom edges.
......
......@@ -5,27 +5,31 @@
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
// How much horizontal and vertical offset there is between newly
// opened windows.
const int WindowSizer::kWindowTilePixels = 10;
// static
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) {
gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size,
chrome::HostDesktopType type) {
RECT area;
SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0);
gfx::Point corner(area.left, area.top);
if (Browser* b = BrowserList::GetLastActive()) {
RECT browser;
HWND window = reinterpret_cast<HWND>(b->window()->GetNativeWindow());
if (GetWindowRect(window, &browser)) {
if (Browser* browser = browser::FindLastActiveWithHostDesktopType(type)) {
RECT browser_rect;
HWND window = reinterpret_cast<HWND>(browser->window()->GetNativeWindow());
if (GetWindowRect(window, &browser_rect)) {
// Limit to not overflow the work area right and bottom edges.
gfx::Point limit(
std::min(browser.left + kWindowTilePixels, area.right-size.width()),
std::min(browser.top + kWindowTilePixels, area.bottom-size.height())
std::min(browser_rect.left + kWindowTilePixels,
area.right-size.width()),
std::min(browser_rect.top + kWindowTilePixels,
area.bottom-size.height())
);
// Adjust corner to now overflow the work area left and top edges, so
// that if a popup does not fit the title-bar is remains visible.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment