diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 17:41:44 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 17:41:44 +0000 |
commit | 078a10a1c64458e5f5c4fdf57edbbc935dd145ca (patch) | |
tree | ac6514112513237e157d5fa859509750bc022872 | |
parent | 799185ae9f4d034fd11b052cd3ff7ed1e12c10c2 (diff) | |
download | chromium_src-078a10a1c64458e5f5c4fdf57edbbc935dd145ca.zip chromium_src-078a10a1c64458e5f5c4fdf57edbbc935dd145ca.tar.gz chromium_src-078a10a1c64458e5f5c4fdf57edbbc935dd145ca.tar.bz2 |
Fix browser side handling of moveTo by resizing the content area; not the window.
BUG=27365
TEST=none
Review URL: http://codereview.chromium.org/661187
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40386 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser_window.h | 12 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.mm | 22 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/filebrowse_ui.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_tabs_module.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 7 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 17 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 2 | ||||
-rw-r--r-- | chrome/test/test_browser_window.h | 2 |
14 files changed, 74 insertions, 33 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 7246061..5b962e0 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1775,7 +1775,8 @@ void Browser::DuplicateContentsAt(int index) { // been given an offset by the OS, so we shouldn't copy the old bounds. BrowserWindow* new_window = browser->window(); new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), - window()->GetRestoredBounds().size())); + window()->GetRestoredBounds().size()), + BrowserWindow::WINDOW_BOUNDS); // We need to show the browser now. Otherwise ContainerWin assumes the // TabContents is invisible and won't size it. @@ -2116,7 +2117,8 @@ void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { NOTREACHED() << "moving invalid browser type"; return; } - window_->SetBounds(pos); + + window_->SetBounds(pos, BrowserWindow::CONTENT_BOUNDS); } void Browser::DetachContents(TabContents* source) { diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index ab38295..152e7dc 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -35,11 +35,19 @@ class Rect; // NOTE: All getters may return NULL. class BrowserWindow { public: + enum BoundsType { + WINDOW_BOUNDS = 0, + CONTENT_BOUNDS + }; + // Show the window, or activates it if it's already visible. virtual void Show() = 0; - // Sets the window's size and position to the specified values. - virtual void SetBounds(const gfx::Rect& bounds) = 0; + // Sets the window's size and position to the specified values. SetBounds + // will always move the window so its window origin is bounds.origin(), but + // will change either the size of the window or the content area based on + // |bounds_type|. + virtual void SetBounds(const gfx::Rect& bounds, BoundsType bounds_type) = 0; // Closes the frame as soon as possible. If the frame is not in a drag // session, it will close immediately; otherwise, it will move offscreen (so diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 2b2d0c3..2b5fb44 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -30,7 +30,7 @@ class BrowserWindowCocoa : public BrowserWindow, // Overridden from BrowserWindow virtual void Show(); - virtual void SetBounds(const gfx::Rect& bounds); + virtual void SetBounds(const gfx::Rect& bounds, BoundsType bounds_type); virtual void Close(); virtual void Activate(); virtual bool IsActive() const; diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index b3dd1f4..2ebda45 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -64,13 +64,27 @@ void BrowserWindowCocoa::Show() { [window() makeKeyAndOrderFront:controller_]; } -void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { - NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0, bounds.width(), - bounds.height()); +void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds, + BoundsType bounds_type) { + gfx::Rect win_bounds = bounds; + if (bounds_type == BrowserWindow::CONTENT_BOUNDS) { + // Fetch the size of the content area in the NSWindow. + NSSize content_area_size = [controller_ tabContentsFrame].size; + int width_offset = bounds.width() - content_area_size.width; + int height_offset = bounds.height() - content_area_size.height; + + // Adjust the size relative to the current frame size. + NSSize current_frame = [window() frame].size; + win_bounds.set_width(current_frame.width + width_offset); + win_bounds.set_height(current_frame.height + height_offset); + } + + NSRect cocoa_bounds = NSMakeRect(win_bounds.x(), 0, win_bounds.width(), + win_bounds.height()); // Flip coordinates based on the primary screen. NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; cocoa_bounds.origin.y = - [screen frame].size.height - bounds.height() - bounds.y(); + [screen frame].size.height - win_bounds.height() - win_bounds.y(); [window() setFrame:cocoa_bounds display:YES]; } diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index f3207f3..72edd91 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -155,6 +155,9 @@ class TabStripModelObserverBridge; // Sets whether or not the current page in the frontmost tab is bookmarked. - (void)setStarredState:(BOOL)isStarred; +// Returns the current frame of the the content area. +- (NSRect)tabContentsFrame; + // Return the rect, in WebKit coordinates (flipped), of the window's grow box // in the coordinate system of the content area of the currently selected tab. - (NSRect)selectedTabGrowBoxRect; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f795ce9..3eb0300 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -215,7 +215,7 @@ windowRect.set_origin(WindowSizer::GetDefaultPopupOrigin(size)); } - windowShim_->SetBounds(windowRect); + windowShim_->SetBounds(windowRect, BrowserWindow::WINDOW_BOUNDS); // Puts the incognito badge on the window frame, if necessary. Do this // before creating the tab strip to avoid redundant tab layout. @@ -976,6 +976,10 @@ [toolbarController_ setStarredState:isStarred]; } +- (NSRect)tabContentsFrame { + return [[self tabContentArea] frame]; +} + // Return the rect, in WebKit coordinates (flipped), of the window's grow box // in the coordinate system of the content area of the currently selected tab. // |windowGrowBox| needs to be in the window's coordinate system. diff --git a/chrome/browser/dom_ui/filebrowse_ui.cc b/chrome/browser/dom_ui/filebrowse_ui.cc index 618573a..0ad904f 100644 --- a/chrome/browser/dom_ui/filebrowse_ui.cc +++ b/chrome/browser/dom_ui/filebrowse_ui.cc @@ -511,9 +511,11 @@ void FilebrowseHandler::OpenNewWindow(const Value* value, bool popup) { if (popup) { // TODO(dhg): Remove these from being hardcoded. Allow javascript // to specify. - browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300)); + browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300), + BrowserWindow::WINDOW_BOUNDS); } else { - browser->window()->SetBounds(gfx::Rect(0, 0, 800, 600)); + browser->window()->SetBounds(gfx::Rect(0, 0, 800, 600), + BrowserWindow::WINDOW_BOUNDS); } browser->window()->Show(); } else { @@ -830,7 +832,8 @@ Browser* FileBrowseUI::OpenPopup(Profile* profile, browser->window()->SetBounds(gfx::Rect(kPopupLeft, kPopupTop, kPopupWidth, - kPopupHeight)); + kPopupHeight), + BrowserWindow::WINDOW_BOUNDS); browser->window()->Show(); } diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 85f6fc2..925863e 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -348,7 +348,7 @@ bool CreateWindowFunction::RunImpl() { new_window->AddTabWithURL(*(url.get()), GURL(), PageTransition::LINK, true, -1, false, NULL); - new_window->window()->SetBounds(bounds); + new_window->window()->SetBounds(bounds, BrowserWindow::WINDOW_BOUNDS); new_window->window()->Show(); // TODO(rafaelw): support |focused|, |zIndex| @@ -402,7 +402,7 @@ bool UpdateWindowFunction::RunImpl() { bounds.set_height(bounds_val); } - browser->window()->SetBounds(bounds); + browser->window()->SetBounds(bounds, BrowserWindow::WINDOW_BOUNDS); // TODO(rafaelw): Support |focused|. result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 8e47ad4..d96a9a9 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -490,7 +490,8 @@ void BrowserTitlebar::MaximizeButtonClicked() { height = screen_rect.height; } - browser_window_->SetBounds(gfx::Rect(x, y, width, height)); + browser_window_->SetBounds(gfx::Rect(x, y, width, height), + BrowserWindow::WINDOW_BOUNDS); } gdk_event_free(event); } diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 8fdd70f..2de3b84 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -581,7 +581,8 @@ void BrowserWindowGtk::Show() { gtk_widget_set_size_request(contents_container_->widget(), -1, -1); } -void BrowserWindowGtk::SetBoundsImpl(const gfx::Rect& bounds, bool exterior) { +void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds, + BoundsType bounds_type) { gint x = static_cast<gint>(bounds.x()); gint y = static_cast<gint>(bounds.y()); gint width = static_cast<gint>(bounds.width()); @@ -589,7 +590,7 @@ void BrowserWindowGtk::SetBoundsImpl(const gfx::Rect& bounds, bool exterior) { gtk_window_move(window_, x, y); - if (exterior) { + if (bounds_type == WINDOW_BOUNDS) { SetWindowSize(window_, width, height); } else { gtk_widget_set_size_request(contents_container_->widget(), @@ -597,10 +598,6 @@ void BrowserWindowGtk::SetBoundsImpl(const gfx::Rect& bounds, bool exterior) { } } -void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { - SetBoundsImpl(bounds, true); -} - void BrowserWindowGtk::Close() { // We're already closing. Do nothing. if (!window_) @@ -1395,7 +1392,8 @@ void BrowserWindowGtk::SetGeometryHints() { if (browser_->bounds_overridden()) { // For popups, bounds are set in terms of the client area rather than the // entire window. - SetBoundsImpl(bounds, !(browser_->type() & Browser::TYPE_POPUP)); + SetBounds(bounds, (browser_->type() & Browser::TYPE_POPUP) ? + BrowserWindow::CONTENT_BOUNDS : BrowserWindow::WINDOW_BOUNDS); } else { // Ignore the position but obey the size. SetWindowSize(window_, bounds.width(), bounds.height()); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 69805c7..1cbfab0 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -48,7 +48,7 @@ class BrowserWindowGtk : public BrowserWindow, // Overridden from BrowserWindow virtual void Show(); - virtual void SetBounds(const gfx::Rect& bounds); + virtual void SetBounds(const gfx::Rect& bounds, BoundsType bounds_type); virtual void Close(); virtual void Activate(); virtual bool IsActive() const; @@ -247,11 +247,6 @@ class BrowserWindowGtk : public BrowserWindow, // Save the window position in the prefs. void SaveWindowPosition(); - // Set the bounds of the current window. If |exterior| is true, set the size - // of the window itself, otherwise set the bounds of the web contents. In - // either case, set the position of the window. - void SetBoundsImpl(const gfx::Rect& bounds, bool exterior); - // Callback for when the custom frame alignment needs to be redrawn. // The content area includes the toolbar and web page but not the tab strip. static gboolean OnCustomFrameExpose(GtkWidget* widget, GdkEventExpose* event, diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index aab1ac8..7e7aece 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -691,8 +691,21 @@ void BrowserView::Show() { frame_->GetWindow()->Show(); } -void BrowserView::SetBounds(const gfx::Rect& bounds) { - GetWidget()->SetBounds(bounds); +void BrowserView::SetBounds(const gfx::Rect& bounds, BoundsType bounds_type) { + gfx::Rect new_bounds = bounds; + if (bounds_type == CONTENT_BOUNDS) { + // Caluclate how much larger the window needs to be to accomidate |bounds|. + gfx::Rect container_bounds = contents_container_->bounds(); + int width_offset = bounds.width() - container_bounds.width(); + int height_offset = bounds.height() - container_bounds.height(); + + gfx::Rect win_bounds; + GetWidget()->GetBounds(&win_bounds, true); + new_bounds.set_width(win_bounds.width() + width_offset); + new_bounds.set_height(win_bounds.height() + height_offset); + } + + GetWidget()->SetBounds(new_bounds); } void BrowserView::Close() { diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 1cf958f..f2d1978 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -238,7 +238,7 @@ class BrowserView : public BrowserBubbleHost, // Overridden from BrowserWindow: virtual void Show(); - virtual void SetBounds(const gfx::Rect& bounds); + virtual void SetBounds(const gfx::Rect& bounds, BoundsType bounds_type); virtual void Close(); virtual void Activate(); virtual bool IsActive() const; diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index 58ef32d..e1a1be1 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -19,7 +19,7 @@ class TestBrowserWindow : public BrowserWindow { virtual void Init() {} virtual void Show() {} - virtual void SetBounds(const gfx::Rect& bounds) {} + virtual void SetBounds(const gfx::Rect& bounds, BoundsType bounds_type) {} virtual void Close() {} virtual void Activate() {} virtual bool IsActive() const { return false; } |