diff options
Diffstat (limited to 'chrome/browser/ui/panels')
22 files changed, 255 insertions, 278 deletions
diff --git a/chrome/browser/ui/panels/base_panel_browser_test.cc b/chrome/browser/ui/panels/base_panel_browser_test.cc index 0b04b91..0dd7bfe 100644 --- a/chrome/browser/ui/panels/base_panel_browser_test.cc +++ b/chrome/browser/ui/panels/base_panel_browser_test.cc @@ -360,7 +360,7 @@ Panel* BasePanelBrowserTest::CreatePanelWithParams( ui::GuessWindowManager() == ui::WM_ICE_WM) { last_active_browser_to_restore = BrowserList::GetLastActive(); EXPECT_TRUE(last_active_browser_to_restore); - EXPECT_NE(last_active_browser_to_restore, panel->browser()); + EXPECT_NE(last_active_browser_to_restore, panel_browser); } #endif @@ -468,17 +468,18 @@ void BasePanelBrowserTest::SetTestingAreas(const gfx::Rect& primary_screen_area, work_area.IsEmpty() ? primary_screen_area : work_area); } -void BasePanelBrowserTest::CloseWindowAndWait(Browser* browser) { - // Closing a browser window may involve several async tasks. Need to use +void BasePanelBrowserTest::CloseWindowAndWait(Panel* panel) { + // Closing a panel may involve several async tasks. Need to use // message pump and wait for the notification. - size_t browser_count = BrowserList::size(); + PanelManager* manager = PanelManager::GetInstance(); + int panel_count = manager->num_panels(); ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(browser)); - browser->CloseWindow(); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); + panel->Close(); signal.Wait(); - // Now we have one less browser instance. - EXPECT_EQ(browser_count - 1, BrowserList::size()); + // Now we have one less panel. + EXPECT_EQ(panel_count - 1, manager->num_panels()); #if defined(OS_MACOSX) // Mac window controllers may be autoreleased, and in the non-test diff --git a/chrome/browser/ui/panels/base_panel_browser_test.h b/chrome/browser/ui/panels/base_panel_browser_test.h index 61561f4..f845151 100644 --- a/chrome/browser/ui/panels/base_panel_browser_test.h +++ b/chrome/browser/ui/panels/base_panel_browser_test.h @@ -100,7 +100,7 @@ class BasePanelBrowserTest : public InProcessBrowserTest { void MoveMouseAndWaitForExpansionStateChange(Panel* panel, const gfx::Point& position); static void MoveMouse(const gfx::Point& position); - void CloseWindowAndWait(Browser* browser); + void CloseWindowAndWait(Panel* panel); static std::string MakePanelName(int index); // |primary_screen_area| must contain |work_area|. If empty rect is passed diff --git a/chrome/browser/ui/panels/docked_panel_strip.cc b/chrome/browser/ui/panels/docked_panel_strip.cc index 55b7ffa..6e48d7b 100644 --- a/chrome/browser/ui/panels/docked_panel_strip.cc +++ b/chrome/browser/ui/panels/docked_panel_strip.cc @@ -19,10 +19,6 @@ #include "content/public/browser/notification_source.h" namespace { -// Width to height ratio is used to compute the default width or height -// when only one value is provided. -const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio - // Occasionally some system, like Windows, might not bring up or down the bottom // bar when the mouse enters or leaves the bottom screen area. This is the // maximum time we will wait for the bottom bar visibility change notification. @@ -46,15 +42,6 @@ const int kNumPanelsToAnimateSimultaneously = 3; } // namespace -// static -// These numbers are semi-arbitrary. -// Motivation for 'width' is to make main buttons on the titlebar functional. -// Motivation for height is to allow autosized tightly-wrapped panel with a -// single line of text - so the height is set to be likely less then a titlebar, -// to make sure even small content is tightly wrapped. -const int DockedPanelStrip::kPanelMinWidth = 80; -const int DockedPanelStrip::kPanelMinHeight = 20; - DockedPanelStrip::DockedPanelStrip(PanelManager* panel_manager) : PanelStrip(PanelStrip::DOCKED), panel_manager_(panel_manager), @@ -101,24 +88,32 @@ void DockedPanelStrip::AddPanel(Panel* panel, // This method does not handle minimized panels. DCHECK_EQ(Panel::EXPANDED, panel->expansion_state()); + DCHECK(panel->initialized()); DCHECK_NE(this, panel->panel_strip()); panel->set_panel_strip(this); - bool known_position = (positioning_mask & KNOWN_POSITION) != 0; + bool default_position = (positioning_mask & KNOWN_POSITION) == 0; bool update_bounds = (positioning_mask & DO_NOT_UPDATE_BOUNDS) == 0; - if (!panel->initialized()) { - DCHECK(!known_position && update_bounds); - InsertNewlyCreatedPanel(panel); - ScheduleLayoutRefresh(); - } else if (known_position) { - DCHECK(update_bounds); - InsertExistingPanelAtKnownPosition(panel); - RefreshLayout(); + if (default_position) { + gfx::Size full_size = panel->full_size(); + gfx::Point pt = GetDefaultPositionForPanel(full_size); + panel->SetPanelBounds(gfx::Rect(pt, full_size)); + panels_.push_back(panel); } else { - DCHECK(!known_position); - InsertExistingPanelAtDefaultPosition(panel); - if (update_bounds) + DCHECK(update_bounds); + int x = panel->GetBounds().x(); + Panels::iterator iter = panels_.begin(); + for (; iter != panels_.end(); ++iter) + if (x > (*iter)->GetBounds().x()) + break; + panels_.insert(iter, panel); + } + + if (update_bounds) { + if ((positioning_mask & DELAY_LAYOUT_REFRESH) != 0) + ScheduleLayoutRefresh(); + else RefreshLayout(); } } @@ -146,72 +141,6 @@ gfx::Point DockedPanelStrip::GetDefaultPositionForPanel( return gfx::Point(x, display_area_.bottom() - full_size.height()); } -void DockedPanelStrip::InsertNewlyCreatedPanel(Panel* panel) { - DCHECK(!panel->initialized()); - - int max_panel_width = panel_manager_->GetMaxPanelWidth(); - int max_panel_height = panel_manager_->GetMaxPanelHeight(); - gfx::Size full_size = panel->full_size(); - int height = full_size.height(); - int width = full_size.width(); - - // Initialize the newly created panel. Does not bump any panels from strip. - // We need to come up with some temporary position and dimensions - // for this panel -- they may be changed at RefreshLayout time. - if (height == 0 && width == 0 && panel_manager_->auto_sizing_enabled()) { - // Auto resizable is enabled only if no initial size is provided. - panel->SetAutoResizable(true); - } else { - if (height == 0) - height = width / kPanelDefaultWidthToHeightRatio; - if (width == 0) - width = height * kPanelDefaultWidthToHeightRatio; - } - - // Constrain sizes to limits. - if (width < kPanelMinWidth) - width = kPanelMinWidth; - else if (width > max_panel_width) - width = max_panel_width; - - if (height < kPanelMinHeight) - height = kPanelMinHeight; - else if (height > max_panel_height) - height = max_panel_height; - - full_size = gfx::Size(width, height); - panel->set_full_size(full_size); - gfx::Point pt = GetDefaultPositionForPanel(full_size); - - panel->Initialize(gfx::Rect(pt.x(), pt.y(), width, height)); - - panel->SetSizeRange(gfx::Size(kPanelMinWidth, kPanelMinHeight), - gfx::Size(max_panel_width, max_panel_height)); - - InsertExistingPanelAtKnownPosition(panel); -} - -void DockedPanelStrip::InsertExistingPanelAtKnownPosition(Panel* panel) { - DCHECK(panel->initialized()); - - int x = panel->GetBounds().x(); - Panels::iterator iter = panels_.begin(); - for (; iter != panels_.end(); ++iter) - if (x > (*iter)->GetBounds().x()) - break; - panels_.insert(iter, panel); -} - -void DockedPanelStrip::InsertExistingPanelAtDefaultPosition(Panel* panel) { - DCHECK(panel->initialized()); - - gfx::Size full_size = panel->full_size(); - gfx::Point pt = GetDefaultPositionForPanel(full_size); - panel->SetPanelBounds(gfx::Rect(pt, full_size)); - - panels_.push_back(panel); -} - int DockedPanelStrip::StartingRightPosition() const { return display_area_.right(); } @@ -456,7 +385,7 @@ void DockedPanelStrip::AdjustPanelBoundsPerExpansionState(Panel* panel, break; case Panel::MINIMIZED: - bounds->set_height(Panel::kMinimizedPanelHeight); + bounds->set_height(panel::kMinimizedPanelHeight); break; default: @@ -888,7 +817,7 @@ int DockedPanelStrip::WidthToDisplayPanelInStrip(bool is_for_active_panel, double squeeze_factor, int full_width) const { return is_for_active_panel ? full_width : - std::max(kPanelMinWidth, + std::max(panel::kPanelMinWidth, static_cast<int>(floor(full_width * squeeze_factor))); } diff --git a/chrome/browser/ui/panels/docked_panel_strip.h b/chrome/browser/ui/panels/docked_panel_strip.h index c83c179..b6bc82a 100644 --- a/chrome/browser/ui/panels/docked_panel_strip.h +++ b/chrome/browser/ui/panels/docked_panel_strip.h @@ -87,6 +87,10 @@ class DockedPanelStrip : public PanelStrip, // Brings up or down the titlebars for all minimized panels. void BringUpOrDownTitlebars(bool bring_up); + // Compute default bounds for a panel of |full_size| that would be used + // when adding the panel to the collection. + gfx::Point GetDefaultPositionForPanel(const gfx::Size& full_size) const; + // Returns the bottom position for the panel per its expansion state. If auto- // hide bottom bar is present, we want to move the minimized panel to the // bottom of the screen, not the bottom of the work area. @@ -141,12 +145,6 @@ class DockedPanelStrip : public PanelStrip, DisplaySettingsProvider::DesktopBarAlignment alignment, DisplaySettingsProvider::DesktopBarVisibility visibility) OVERRIDE; - // Helper methods to put the panel to the collection. - gfx::Point GetDefaultPositionForPanel(const gfx::Size& full_size) const; - void InsertNewlyCreatedPanel(Panel* panel); - void InsertExistingPanelAtKnownPosition(Panel* panel); - void InsertExistingPanelAtDefaultPosition(Panel* panel); - // Schedules a layout refresh with a short delay to avoid too much flicker. void ScheduleLayoutRefresh(); @@ -202,12 +200,6 @@ class DockedPanelStrip : public PanelStrip, static const int kPanelsHorizontalSpacing = 4; - // Absolute minimum width and height for panels, including non-client area. - // Should only be big enough to accomodate a close button on the reasonably - // recognisable titlebar. - static const int kPanelMinWidth; - static const int kPanelMinHeight; - DISALLOW_COPY_AND_ASSIGN(DockedPanelStrip); }; diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 73e1c30..36b94db 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -21,13 +21,12 @@ #include "ui/gfx/rect.h" using content::RenderViewHost; -using content::WebContents; -Panel::Panel(Browser* browser, const gfx::Size& requested_size) - : browser_(browser), - panel_strip_(NULL), +Panel::Panel(const gfx::Size& min_size, const gfx::Size& max_size) + : panel_strip_(NULL), initialized_(false), - full_size_(requested_size), + min_size_(min_size), + max_size_(max_size), max_size_policy_(DEFAULT_MAX_SIZE), auto_resizable_(false), always_on_top_(false), @@ -41,15 +40,16 @@ Panel::~Panel() { // Invoked by native panel destructor. Do not access native_panel_ here. } -void Panel::Initialize(const gfx::Rect& bounds) { +void Panel::Initialize(const gfx::Rect& bounds, Browser* browser) { DCHECK(!initialized_); + DCHECK(!panel_strip_); // Cannot be added to a strip until fully created. + DCHECK_EQ(EXPANDED, expansion_state_); DCHECK(!bounds.IsEmpty()); initialized_ = true; - native_panel_ = CreateNativePanel(browser_, this, bounds); + full_size_ = bounds.size(); + native_panel_ = CreateNativePanel(browser, this, bounds); panel_browser_window_.reset( - new PanelBrowserWindow(browser_, this, native_panel_)); - if (panel_strip_ != NULL) - native_panel_->PreventActivationByOS(panel_strip_->IsPanelMinimized(this)); + new PanelBrowserWindow(browser, this, native_panel_)); } void Panel::OnNativePanelClosed() { @@ -61,10 +61,18 @@ PanelManager* Panel::manager() const { return PanelManager::GetInstance(); } +Browser* Panel::browser() const { + return native_panel_->GetPanelBrowser(); +} + BrowserWindow* Panel::browser_window() const { return panel_browser_window_.get(); } +content::WebContents* Panel::WebContents() const { + return native_panel_->GetPanelBrowser()->GetSelectedWebContents(); +} + bool Panel::CanMinimize() const { return panel_strip_ && panel_strip_->CanMinimizePanel(this) && !IsMinimized(); } @@ -124,7 +132,7 @@ void Panel::SetAutoResizable(bool resizable) { return; auto_resizable_ = resizable; - WebContents* web_contents = browser()->GetSelectedWebContents(); + content::WebContents* web_contents = WebContents(); if (auto_resizable_) { if (web_contents) EnableWebContentsAutoResize(web_contents); @@ -149,7 +157,7 @@ void Panel::SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size) { min_size_ = min_size; max_size_ = max_size; - ConfigureAutoResize(browser()->GetSelectedWebContents()); + ConfigureAutoResize(WebContents()); } void Panel::IncreaseMaxSize(const gfx::Size& desired_panel_size) { @@ -353,7 +361,7 @@ void Panel::OnWindowResizedByMouse(const gfx::Rect& new_bounds) { panel_strip_->OnPanelResizedByMouse(this, new_bounds); } -void Panel::EnableWebContentsAutoResize(WebContents* web_contents) { +void Panel::EnableWebContentsAutoResize(content::WebContents* web_contents) { DCHECK(web_contents); ConfigureAutoResize(web_contents); @@ -363,14 +371,14 @@ void Panel::EnableWebContentsAutoResize(WebContents* web_contents) { registrar_.Add( this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, - content::Source<WebContents>(web_contents)); + content::Source<content::WebContents>(web_contents)); } void Panel::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_SWAPPED, type); - ConfigureAutoResize(content::Source<WebContents>(source).ptr()); + ConfigureAutoResize(content::Source<content::WebContents>(source).ptr()); } void Panel::OnActiveStateChanged(bool active) { @@ -392,7 +400,7 @@ void Panel::OnActiveStateChanged(bool active) { content::NotificationService::NoDetails()); } -void Panel::ConfigureAutoResize(WebContents* web_contents) { +void Panel::ConfigureAutoResize(content::WebContents* web_contents) { if (!auto_resizable_ || !web_contents) return; @@ -407,7 +415,7 @@ void Panel::ConfigureAutoResize(WebContents* web_contents) { } void Panel::OnWindowSizeAvailable() { - ConfigureAutoResize(browser()->GetSelectedWebContents()); + ConfigureAutoResize(WebContents()); } void Panel::OnTitlebarClicked(panel::ClickModifier modifier) { diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h index 65dbc3a..b3b5323 100644 --- a/chrome/browser/ui/panels/panel.h +++ b/chrome/browser/ui/panels/panel.h @@ -57,14 +57,15 @@ class Panel : public BaseWindow, USE_SYSTEM_ATTENTION = 0x02 }; - // The panel can be minimized to 4-pixel lines. - static const int kMinimizedPanelHeight = 4; - virtual ~Panel(); // Returns the PanelManager associated with this panel. PanelManager* manager() const; + // Returns web contents of the panel, if any. There may be none if web + // contents have not been added to the panel yet. + content::WebContents* WebContents() const; + void SetExpansionState(ExpansionState new_expansion_state); bool IsDrawingAttention() const; @@ -132,8 +133,9 @@ class Panel : public BaseWindow, // Asynchronous completion of panel close request. void OnNativePanelClosed(); - NativePanel* native_panel() { return native_panel_; } - Browser* browser() const { return browser_; } + // Legacy accessors. + Browser* browser() const; + NativePanel* native_panel() const { return native_panel_; } BrowserWindow* browser_window() const; // May be NULL if: @@ -167,7 +169,7 @@ class Panel : public BaseWindow, // Panel must be initialized to be "fully created" and ready for use. // Only called by PanelManager. bool initialized() const { return initialized_; } - void Initialize(const gfx::Rect& bounds); + void Initialize(const gfx::Rect& bounds, Browser* browser); // This is different from BrowserWindow::SetBounds(): // * SetPanelBounds() is only called by PanelManager to manage its position. @@ -239,7 +241,6 @@ class Panel : public BaseWindow, private: friend class PanelManager; friend class PanelBrowserTest; - FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, RestoredBounds); enum MaxSizePolicy { // Default maximum size is proportional to the work area. @@ -249,15 +250,11 @@ class Panel : public BaseWindow, }; // Panel can only be created using PanelManager::CreatePanel(). - // |requested_size| is the desired size for the panel, but actual - // size may differ after panel layout. - Panel(Browser* browser, const gfx::Size& requested_size); + explicit Panel(const gfx::Size& min_size, const gfx::Size& max_size); // Configures the renderer for auto resize (if auto resize is enabled). void ConfigureAutoResize(content::WebContents* web_contents); - Browser* browser_; // Weak, owned by native panel. - // A BrowserWindow for the browser to interact with. scoped_ptr<PanelBrowserWindow> panel_browser_window_; diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc index 70be53c..d4164b3 100644 --- a/chrome/browser/ui/panels/panel_browser_frame_view.cc +++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc @@ -615,7 +615,7 @@ bool PanelBrowserFrameView::UsingDefaultTheme(PaintState paint_state) const { return true; ThemeService* theme_service = ThemeServiceFactory::GetForProfile( - panel_browser_view_->panel()->browser()->profile()); + panel_browser_view_->browser()->profile()); return theme_service->UsingDefaultTheme(); } diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc index 8a6dc80..99db94d 100644 --- a/chrome/browser/ui/panels/panel_browser_view.cc +++ b/chrome/browser/ui/panels/panel_browser_view.cc @@ -105,7 +105,7 @@ void PanelBrowserView::Deactivate() { #if defined(OS_WIN) && !defined(USE_AURA) gfx::NativeWindow native_window = NULL; BrowserWindow* browser_window = - panel_->manager()->GetNextBrowserWindowToActivate(panel_.get()); + panel_->manager()->GetNextBrowserWindowToActivate(GetPanelBrowser()); if (browser_window) native_window = browser_window->GetNativeHandle(); else diff --git a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc index d04512b..37d08d0 100644 --- a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc @@ -119,8 +119,8 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { void ClosePanelAndWaitForNotification(Panel* panel) { ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel->browser())); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); panel->Close(); signal.Wait(); } diff --git a/chrome/browser/ui/panels/panel_browser_window.cc b/chrome/browser/ui/panels/panel_browser_window.cc index 7404d23..e839497 100644 --- a/chrome/browser/ui/panels/panel_browser_window.cc +++ b/chrome/browser/ui/panels/panel_browser_window.cc @@ -476,5 +476,3 @@ void PanelBrowserWindow::TabInsertedAt(TabContentsWrapper* contents, panel_->EnableWebContentsAutoResize(contents->web_contents()); } } - - diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.h b/chrome/browser/ui/panels/panel_browser_window_cocoa.h index 1d541a7..c51c304 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa.h +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.h @@ -88,7 +88,6 @@ class PanelBrowserWindowCocoa : public NativePanel, const content::NotificationDetails& details) OVERRIDE; Panel* panel() { return panel_.get(); } - Browser* browser() const { return browser_.get(); } // Callback from PanelWindowControllerCocoa that native window was actually // closed. The window may not close right away because of onbeforeunload diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm index b35136b..818e4f5f 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm @@ -77,7 +77,7 @@ void PanelBrowserWindowCocoa::ShowPanel() { // until we return to the runloop. Therefore any calls to // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return // the previous browser instead if we don't explicitly set it here. - BrowserList::SetLastActive(browser()); + BrowserList::SetLastActive(GetPanelBrowser()); ShowPanelInactive(); ActivatePanel(); @@ -261,7 +261,7 @@ bool PanelBrowserWindowCocoa::PreHandlePanelKeyboardEvent( if (id == -1) return false; - if (browser()->IsReservedCommandOrKey(id, event)) { + if (GetPanelBrowser()->IsReservedCommandOrKey(id, event)) { return [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:GetNativePanelHandle()]; } @@ -285,7 +285,7 @@ void PanelBrowserWindowCocoa::FullScreenModeChanged( } Browser* PanelBrowserWindowCocoa::GetPanelBrowser() const { - return browser(); + return browser_.get(); } void PanelBrowserWindowCocoa::DestroyPanelBrowser() { diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm index 5ec48a5..694b49c 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm @@ -97,18 +97,19 @@ class PanelBrowserWindowCocoaTest : public CocoaProfileTest { EXPECT_EQ(NSHeight([[titlebar superview] bounds]), NSMaxY(titlebar_frame)); } - void ClosePanelAndWait(Browser* browser) { - EXPECT_TRUE(browser); - // Closing a browser window may involve several async tasks. Need to use + void ClosePanelAndWait(Panel* panel) { + EXPECT_TRUE(panel); + // Closing a panel may involve several async tasks. Need to use // message pump and wait for the notification. - size_t browser_count = BrowserList::size(); + PanelManager* manager = PanelManager::GetInstance(); + int panel_count = manager->num_panels(); ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(browser)); - browser->CloseWindow(); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); + panel->Close(); signal.Wait(); - // Now we have one less browser instance. - EXPECT_EQ(browser_count - 1, BrowserList::size()); + // Now we have one less panel. + EXPECT_EQ(panel_count - 1, manager->num_panels()); } NSMenuItem* CreateMenuItem(NSMenu* menu, int command_id) { @@ -139,8 +140,7 @@ TEST_F(PanelBrowserWindowCocoaTest, CreateClose) { // their NIB has it. The controller's lifetime is the window's lifetime. EXPECT_EQ(NO, [[native_window->controller_ window] isReleasedWhenClosed]); - ASSERT_TRUE(panel->browser()); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); EXPECT_EQ(0, manager->num_panels()); } @@ -161,15 +161,15 @@ TEST_F(PanelBrowserWindowCocoaTest, AssignedBounds) { EXPECT_EQ(bounds2.y(), bounds3.y()); // After panel2 is closed, panel3 should take its place. - ClosePanelAndWait(panel2->browser()); + ClosePanelAndWait(panel2); bounds3 = panel3->GetBounds(); EXPECT_EQ(bounds2, bounds3); // After panel1 is closed, panel3 should take its place. - ClosePanelAndWait(panel1->browser()); + ClosePanelAndWait(panel1); EXPECT_EQ(bounds1, panel3->GetBounds()); - ClosePanelAndWait(panel3->browser()); + ClosePanelAndWait(panel3); } // Same test as AssignedBounds, but checks actual bounds on native OS windows. @@ -197,7 +197,7 @@ TEST_F(PanelBrowserWindowCocoaTest, NativeBounds) { { // After panel2 is closed, panel3 should take its place. PanelAnimatedBoundsObserver bounds_observer(panel3); - ClosePanelAndWait(panel2->browser()); + ClosePanelAndWait(panel2); bounds_observer.Wait(); bounds3 = [[native_window3->controller_ window] frame]; EXPECT_EQ(bounds2.origin.x, bounds3.origin.x); @@ -209,7 +209,7 @@ TEST_F(PanelBrowserWindowCocoaTest, NativeBounds) { { // After panel1 is closed, panel3 should take its place. PanelAnimatedBoundsObserver bounds_observer(panel3); - ClosePanelAndWait(panel1->browser()); + ClosePanelAndWait(panel1); bounds_observer.Wait(); bounds3 = [[native_window3->controller_ window] frame]; EXPECT_EQ(bounds1.origin.x, bounds3.origin.x); @@ -218,7 +218,7 @@ TEST_F(PanelBrowserWindowCocoaTest, NativeBounds) { EXPECT_EQ(bounds1.size.height, bounds3.size.height); } - ClosePanelAndWait(panel3->browser()); + ClosePanelAndWait(panel3); } // Verify the titlebar is being created. @@ -232,7 +232,7 @@ TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewCreate) { EXPECT_TRUE(titlebar); EXPECT_EQ(native_window->controller_, [titlebar controller]); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } // Verify the sizing of titlebar - should be affixed on top of regular titlebar. @@ -283,7 +283,7 @@ TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewSizing) { EXPECT_NE(newTitleFrame.origin.x, oldTitleFrame.origin.x); EXPECT_NE(newIconFrame.origin.x, oldIconFrame.origin.x); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } // Verify closing behavior of titlebar close button. @@ -300,8 +300,8 @@ TEST_F(PanelBrowserWindowCocoaTest, TitlebarViewClose) { EXPECT_EQ(1, manager->num_panels()); // Simulate clicking Close Button and wait until the Panel closes. ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel->browser())); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); [titlebar simulateCloseButtonClick]; signal.Wait(); EXPECT_EQ(0, manager->num_panels()); @@ -338,7 +338,7 @@ TEST_F(PanelBrowserWindowCocoaTest, MenuItems) { EXPECT_FALSE([presentation_menu_item isEnabled]); EXPECT_FALSE([sync_menu_item isEnabled]); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } TEST_F(PanelBrowserWindowCocoaTest, KeyEvent) { @@ -357,7 +357,7 @@ TEST_F(PanelBrowserWindowCocoaTest, KeyEvent) { static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); [BrowserWindowUtils handleKeyboardEvent:event inWindow:[native_window->controller_ window]]; - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } // Verify that the theme provider is properly plumbed through. @@ -369,7 +369,7 @@ TEST_F(PanelBrowserWindowCocoaTest, ThemeProvider) { static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); ASSERT_TRUE(native_window); EXPECT_TRUE(NULL != [[native_window->controller_ window] themeProvider]); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } TEST_F(PanelBrowserWindowCocoaTest, SetTitle) { @@ -384,7 +384,7 @@ TEST_F(PanelBrowserWindowCocoaTest, SetTitle) { chrome::testing::NSRunLoopRunAllPending(); EXPECT_NSEQ(@"Untitled", [[native_window->controller_ window] title]); EXPECT_NSNE([[native_window->controller_ window] title], previousTitle); - ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel); } TEST_F(PanelBrowserWindowCocoaTest, ActivatePanel) { @@ -411,6 +411,6 @@ TEST_F(PanelBrowserWindowCocoaTest, ActivatePanel) { frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; EXPECT_NSEQ(frontmostWindow, [native_window2->controller_ window]); - ClosePanelAndWait(panel->browser()); - ClosePanelAndWait(panel2->browser()); + ClosePanelAndWait(panel); + ClosePanelAndWait(panel2); } diff --git a/chrome/browser/ui/panels/panel_browser_window_gtk.cc b/chrome/browser/ui/panels/panel_browser_window_gtk.cc index 722f703..ca21de9 100644 --- a/chrome/browser/ui/panels/panel_browser_window_gtk.cc +++ b/chrome/browser/ui/panels/panel_browser_window_gtk.cc @@ -233,7 +233,7 @@ void PanelBrowserWindowGtk::SaveWindowPosition() { void PanelBrowserWindowGtk::SetGeometryHints() { // Set minimum height the window can be set to. GdkGeometry hints; - hints.min_height = Panel::kMinimizedPanelHeight; + hints.min_height = panel::kMinimizedPanelHeight; hints.min_width = kMinWindowWidth; gtk_window_set_geometry_hints( window(), GTK_WIDGET(window()), &hints, GDK_HINT_MIN_SIZE); @@ -292,7 +292,7 @@ const gfx::Image* PanelBrowserWindowGtk::GetThemeFrameImage() const { return GetAttentionBackgroundImage(); GtkThemeService* theme_provider = GtkThemeService::GetFrom( - browser()->profile()); + GetPanelBrowser()->profile()); if (theme_provider->UsingDefaultTheme()) { // We choose to use the window frame theme to paint panels for the default // theme. This is because the default tab theme does not work well for the @@ -399,7 +399,7 @@ void PanelBrowserWindowGtk::ActivatePanel() { void PanelBrowserWindowGtk::DeactivatePanel() { BrowserWindow* browser_window = - panel_->manager()->GetNextBrowserWindowToActivate(panel_.get()); + panel_->manager()->GetNextBrowserWindowToActivate(GetPanelBrowser()); if (browser_window) { browser_window->Activate(); } else { diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index 9132c6e..0947bc2 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -161,10 +161,10 @@ class PanelBrowserTest : public BasePanelBrowserTest { // Minimize all panels for next stage in test. for (size_t index = 0; index < panels.size(); ++index) { panels[index]->Minimize(); - expected_bounds[index].set_height(Panel::kMinimizedPanelHeight); + expected_bounds[index].set_height(panel::kMinimizedPanelHeight); expected_bounds[index].set_y( test_begin_bounds[index].y() + - test_begin_bounds[index].height() - Panel::kMinimizedPanelHeight); + test_begin_bounds[index].height() - panel::kMinimizedPanelHeight); expected_expansion_states[index] = Panel::MINIMIZED; EXPECT_EQ(expected_bounds, GetAllPanelBounds()); EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); @@ -347,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { EXPECT_EQ(bounds.right(), panel_manager->docked_strip()->StartingRightPosition()); - CloseWindowAndWait(panel->browser()); + CloseWindowAndWait(panel); EXPECT_EQ(0, panel_manager->num_panels()); } @@ -364,16 +364,6 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) { panel->Close(); } -IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { - Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 400, 400)); - Browser* browser = panel->browser(); - // FindBar needs tab contents. - CreateTestTabContents(browser); - browser->ShowFindBar(); - ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); - panel->Close(); -} - // Flaky: http://crbug.com/105445 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { PanelManager* panel_manager = PanelManager::GetInstance(); @@ -395,7 +385,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, content::Source<Panel>(panel)); EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( - panel->browser()->GetSelectedWebContents()->GetRenderViewHost(), + panel->WebContents()->GetRenderViewHost(), std::wstring(), L"changeSize(50);")); enlarge.Wait(); @@ -408,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, content::Source<Panel>(panel)); EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( - panel->browser()->GetSelectedWebContents()->GetRenderViewHost(), + panel->WebContents()->GetRenderViewHost(), std::wstring(), L"changeSize(-30);")); shrink.Wait(); @@ -822,6 +812,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) { Panel* panel1 = CreatePanelWithParams(params1); CreatePanelParams params2("Panel2", gfx::Rect(), SHOW_AS_ACTIVE); Panel* panel2 = CreatePanelWithParams(params2); + // Need tab contents in order to trigger deactivation upon close. CreateTestTabContents(panel2->browser()); @@ -839,7 +830,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) { browser()->window()->Activate(); WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); // Close the main tabbed window. That should move focus back to panel. - CloseWindowAndWait(browser()); + browser()->CloseWindow(); WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); // Activate another panel. @@ -853,7 +844,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) { WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); // Close active panel, focus should move to the remaining one. - CloseWindowAndWait(panel2->browser()); + CloseWindowAndWait(panel2); WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); panel1->Close(); } @@ -892,7 +883,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) { #endif IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) { - BrowserWindow* tabbed_window = BrowserList::GetLastActive()->window(); + BrowserWindow* tabbed_window = browser()->window(); // Create 4 panels in the following screen layout: // P3 P2 P1 P0 @@ -1262,7 +1253,11 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, Panel* panel2 = CreatePanelWithParams(params); // Close main tabbed window. - CloseWindowAndWait(browser()); + ui_test_utils::WindowedNotificationObserver signal( + chrome::NOTIFICATION_BROWSER_CLOSED, + content::Source<Browser>(browser())); + browser()->CloseWindow(); + signal.Wait(); EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); @@ -1329,11 +1324,11 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, Panel* panel_other = CreatePanel(extension_app_name_other); ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel->browser())); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); ui_test_utils::WindowedNotificationObserver signal1( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel1->browser())); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel1)); // Send unload notification on the first extension. extensions::UnloadedExtensionInfo details(extension, @@ -1367,7 +1362,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { FilePath(FILE_PATH_LITERAL("onbeforeunload.html"))); Panel* panel = CreatePanelWithParams(params); EXPECT_EQ(1, panel_manager->num_panels()); - WebContents* web_contents = panel->browser()->GetSelectedWebContents(); + WebContents* web_contents = panel->WebContents(); // Close panel and respond to the onbeforeunload dialog with cancel. This is // equivalent to clicking "Stay on this page" @@ -1391,13 +1386,13 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { // Close panel and respond to the onbeforeunload dialog with accept. This is // equivalent to clicking "Leave this page". - ui_test_utils::WindowedNotificationObserver browser_closed( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel->browser())); + ui_test_utils::WindowedNotificationObserver signal( + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); panel->Close(); alert = ui_test_utils::WaitForAppModalDialog(); alert->native_dialog()->AcceptAppModalDialog(); - browser_closed.Wait(); + signal.Wait(); EXPECT_EQ(0, panel_manager->num_panels()); } @@ -1445,8 +1440,8 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_CreateWithExistingContents) { // Swapping tab contents back to the browser should close the panel. ui_test_utils::WindowedNotificationObserver signal( - chrome::NOTIFICATION_BROWSER_CLOSED, - content::Source<Browser>(panel_browser)); + chrome::NOTIFICATION_PANEL_CLOSED, + content::Source<Panel>(panel)); panel_browser->ConvertPopupToTabbedBrowser(); signal.Wait(); EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); @@ -1503,7 +1498,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, TightAutosizeAroundSingleLine) { chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, content::Source<Panel>(panel)); EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( - panel->browser()->GetSelectedWebContents()->GetRenderViewHost(), + panel->WebContents()->GetRenderViewHost(), std::wstring(), L"document.body.innerHTML =" L"'<nobr>line of text and a <button>Button</button>';")); @@ -1903,12 +1898,12 @@ IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, FAILS_NoOverlapping) { // Closing short panel should move the notification balloon down to the same // position when tall panel brings up its titlebar. - CloseWindowAndWait(panel1->browser()); + CloseWindowAndWait(panel1); EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, GetBalloonBottomPosition(balloon)); // Closing the remaining tall panel should move the notification balloon back // to its original position. - CloseWindowAndWait(panel2->browser()); + CloseWindowAndWait(panel2); EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); } diff --git a/chrome/browser/ui/panels/panel_constants.h b/chrome/browser/ui/panels/panel_constants.h index 040b05e..3a640da 100644 --- a/chrome/browser/ui/panels/panel_constants.h +++ b/chrome/browser/ui/panels/panel_constants.h @@ -8,33 +8,47 @@ namespace panel { - // Different platforms use different modifier keys to change the behavior - // of a mouse click. This enum captures the meaning of the modifier rather - // than the actual modifier key to generalize across platforms. - enum ClickModifier { - NO_MODIFIER, - APPLY_TO_ALL, // Apply the click behavior to all panels in the strip. - }; - - // Edge at which a panel is being resized using the mouse. - enum ResizingSides { - RESIZE_NONE = 0, - RESIZE_TOP, - RESIZE_TOP_RIGHT, - RESIZE_RIGHT, - RESIZE_BOTTOM_RIGHT, - RESIZE_BOTTOM, - RESIZE_BOTTOM_LEFT, - RESIZE_LEFT, - RESIZE_TOP_LEFT - }; - - // Ways a panel can be resized. - enum Resizability { - NOT_RESIZABLE, - RESIZABLE_ALL_SIDES, - RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM - }; +// Absolute minimum width and height for panels, including non-client area. +// Should only be big enough to accomodate a close button on the reasonably +// recognisable titlebar. +// These numbers are semi-arbitrary. +// Motivation for 'width' is to make main buttons on the titlebar functional. +// Motivation for height is to allow autosized tightly-wrapped panel with a +// single line of text - so the height is set to be likely less then a titlebar, +// to make sure even small content is tightly wrapped. +const int kPanelMinWidth = 80; +const int kPanelMinHeight = 20; + +// The panel can be minimized to 4-pixel lines. +static const int kMinimizedPanelHeight = 4; + +// Different platforms use different modifier keys to change the behavior +// of a mouse click. This enum captures the meaning of the modifier rather +// than the actual modifier key to generalize across platforms. +enum ClickModifier { + NO_MODIFIER, + APPLY_TO_ALL, // Apply the click behavior to all panels in the strip. +}; + +// Edge at which a panel is being resized using the mouse. +enum ResizingSides { + RESIZE_NONE = 0, + RESIZE_TOP, + RESIZE_TOP_RIGHT, + RESIZE_RIGHT, + RESIZE_BOTTOM_RIGHT, + RESIZE_BOTTOM, + RESIZE_BOTTOM_LEFT, + RESIZE_LEFT, + RESIZE_TOP_LEFT +}; + +// Ways a panel can be resized. +enum Resizability { + NOT_RESIZABLE, + RESIZABLE_ALL_SIDES, + RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM +}; } // namespace panel diff --git a/chrome/browser/ui/panels/panel_drag_browsertest.cc b/chrome/browser/ui/panels/panel_drag_browsertest.cc index 85dff1e..a9b551e1 100644 --- a/chrome/browser/ui/panels/panel_drag_browsertest.cc +++ b/chrome/browser/ui/panels/panel_drag_browsertest.cc @@ -541,7 +541,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { // Closing another panel while dragging in progress will keep the dragging // panel intact. // We have: P1* P4 P3 - CloseWindowAndWait(panel2->browser()); + CloseWindowAndWait(panel2); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -596,7 +596,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { // Closing another panel while dragging in progress will keep the dragging // panel intact. // We have: P1* P4 - CloseWindowAndWait(panel3->browser()); + CloseWindowAndWait(panel3); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -644,7 +644,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDockedPanelOnDrag) { // Closing the dragging panel should end the drag. // We have: P4 - CloseWindowAndWait(panel1->browser()); + CloseWindowAndWait(panel1); EXPECT_FALSE(drag_controller->IsDragging()); ASSERT_EQ(1, docked_strip->num_panels()); @@ -744,7 +744,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) { // Closing another panel while dragging in progress will keep the dragging // panel intact. - CloseWindowAndWait(panel2->browser()); + CloseWindowAndWait(panel2); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -791,7 +791,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) { // Closing another panel while dragging in progress will keep the dragging // panel intact. - CloseWindowAndWait(panel3->browser()); + CloseWindowAndWait(panel3); EXPECT_TRUE(drag_controller->IsDragging()); EXPECT_EQ(panel1, drag_controller->dragging_panel()); @@ -830,7 +830,7 @@ IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, CloseDetachedPanelOnDrag) { EXPECT_EQ(panel4_position, panel4->GetBounds().origin()); // Closing the dragging panel should end the drag. - CloseWindowAndWait(panel1->browser()); + CloseWindowAndWait(panel1); EXPECT_FALSE(drag_controller->IsDragging()); ASSERT_EQ(1, detached_strip->num_panels()); diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc index f9b933a..0a3a8e0 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -43,6 +43,10 @@ const double kPanelMaxWidthFactor = 0.35; // Maxmium height of a panel is based on a factor of the working area. const double kPanelMaxHeightFactor = 0.5; + +// Width to height ratio is used to compute the default width or height +// when only one value is provided. +const double kPanelDefaultWidthToHeightRatio = 1.62; // golden ratio } // namespace // static @@ -138,13 +142,51 @@ Panel* PanelManager::CreatePanel(Browser* browser) { // 2) On windows, display settings notification is tied to a window. When // display settings are changed at the time that no panel exists, we do // not receive any notification. - if (num_panels() == 0) + if (num_panels() == 0) { display_settings_provider_->OnDisplaySettingsChanged(); + display_settings_provider_->AddFullScreenObserver(this); + } + + // Compute initial bounds for the panel. + gfx::Size requested_size(browser->override_bounds().size()); + int width = requested_size.width(); + int height = requested_size.height(); + if (width == 0) + width = height * kPanelDefaultWidthToHeightRatio; + else if (height == 0) + height = width / kPanelDefaultWidthToHeightRatio; + + gfx::Size min_size(panel::kPanelMinWidth, panel::kPanelMinHeight); + gfx::Size max_size(GetMaxPanelWidth(), GetMaxPanelHeight()); + if (width < min_size.width()) + width = min_size.width(); + else if (width > max_size.width()) + width = max_size.width(); + + if (height < min_size.height()) + height = min_size.height(); + else if (height > max_size.height()) + height = max_size.height(); + + gfx::Size panel_size(width, height); + gfx::Rect bounds(docked_strip_->GetDefaultPositionForPanel(panel_size), + panel_size); + + // Create the (legacy) panel. + Panel* panel = new Panel(min_size, max_size); + panel->Initialize(bounds, browser); + + // Auto resizable feature is enabled only if no initial size is requested. + if (auto_sizing_enabled() && requested_size.width() == 0 && + requested_size.height() == 0) { + panel->SetAutoResizable(true); + } - int width = browser->override_bounds().width(); - int height = browser->override_bounds().height(); - Panel* panel = new Panel(browser, gfx::Size(width, height)); - docked_strip_->AddPanel(panel, PanelStrip::DEFAULT_POSITION); + // Add the panel to the docked strip. + // Delay layout refreshes in case multiple panels are created within + // a short time of one another or the focus changes shortly after panel + // is created to avoid excessive screen redraws. + docked_strip_->AddPanel(panel, PanelStrip::DELAY_LAYOUT_REFRESH); docked_strip_->UpdatePanelOnStripChange(panel); content::NotificationService::current()->Notify( @@ -152,10 +194,6 @@ Panel* PanelManager::CreatePanel(Browser* browser) { content::Source<Panel>(panel), content::NotificationService::NoDetails()); - if (num_panels() == 1) { - display_settings_provider_->AddFullScreenObserver(this); - } - return panel; } @@ -252,13 +290,13 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { } BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( - Panel* panel) const { + Browser* current_browser) const { // Find the last active browser window that is not minimized. BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active(); BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); for (; (iter != end); ++iter) { Browser* browser = *iter; - if (panel->browser() != browser && !browser->window()->IsMinimized()) + if (current_browser != browser && !browser->window()->IsMinimized()) return browser->window(); } diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h index 9eb76dd..4b1f192 100644 --- a/chrome/browser/ui/panels/panel_manager.h +++ b/chrome/browser/ui/panels/panel_manager.h @@ -80,7 +80,7 @@ class PanelManager : public DisplaySettingsProvider::DisplayAreaObserver, // Returns the next browser window which could be either panel window or // tabbed window, to switch to if the given panel is going to be deactivated. // Returns NULL if such window cannot be found. - BrowserWindow* GetNextBrowserWindowToActivate(Panel* panel) const; + BrowserWindow* GetNextBrowserWindowToActivate(Browser* current_browser) const; int num_panels() const; std::vector<Panel*> panels() const; diff --git a/chrome/browser/ui/panels/panel_resize_browsertest.cc b/chrome/browser/ui/panels/panel_resize_browsertest.cc index 0b9ea8d..7ca7ea3 100644 --- a/chrome/browser/ui/panels/panel_resize_browsertest.cc +++ b/chrome/browser/ui/panels/panel_resize_browsertest.cc @@ -288,7 +288,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, CloseDetachedPanelOnResize) { panel1_bounds.Offset(-10, 0); EXPECT_EQ(panel1_bounds, panel1->GetBounds()); - CloseWindowAndWait(panel2->browser()); + CloseWindowAndWait(panel2); EXPECT_TRUE(resize_controller->IsResizing()); EXPECT_EQ(2, detached_strip->num_panels()); @@ -308,7 +308,7 @@ IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, CloseDetachedPanelOnResize) { panel3_bounds.height() - 12)); EXPECT_EQ(panel3_bounds, panel3->GetBounds()); - CloseWindowAndWait(panel3->browser()); + CloseWindowAndWait(panel3); EXPECT_EQ(1, detached_strip->num_panels()); // Since we closed the panel we were resizing, we should be out of the // resizing mode by now. diff --git a/chrome/browser/ui/panels/panel_strip.h b/chrome/browser/ui/panels/panel_strip.h index 60a1a1b..e18dbb3 100644 --- a/chrome/browser/ui/panels/panel_strip.h +++ b/chrome/browser/ui/panels/panel_strip.h @@ -29,8 +29,12 @@ class PanelStrip { DEFAULT_POSITION = 0x0, // The panel is being added based on its current known position. KNOWN_POSITION = 0x1, - // Do not update panel bounds. Only valid with DEFAULT_POSITION. - DO_NOT_UPDATE_BOUNDS = 0x2 + // Do not update panel bounds. Only valid with DEFAULT_POSIITON. + DO_NOT_UPDATE_BOUNDS = 0x2, + // Wait for a brief delay before refreshing layout of the strip after + // adding panel to the strip. If not set, the strip will refresh its layout + // immediately. + DELAY_LAYOUT_REFRESH = 0x4, }; Type type() const { return type_; } diff --git a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm index 22dfdd6..87a7fb0 100644 --- a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm +++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm @@ -443,12 +443,13 @@ enum { } - (ui::ThemeProvider*)themeProvider { - return ThemeServiceFactory::GetForProfile(windowShim_->browser()->profile()); + return ThemeServiceFactory::GetForProfile( + windowShim_->GetPanelBrowser()->profile()); } - (ThemedWindowStyle)themedWindowStyle { ThemedWindowStyle style = THEMED_POPUP; - if (windowShim_->browser()->profile()->IsOffTheRecord()) + if (windowShim_->GetPanelBrowser()->profile()->IsOffTheRecord()) style |= THEMED_INCOGNITO; return style; } @@ -547,7 +548,7 @@ enum { - (void)updateTitleBar { NSString* newTitle = base::SysUTF16ToNSString( - windowShim_->browser()->GetWindowTitleForCurrentTab()); + windowShim_->GetPanelBrowser()->GetWindowTitleForCurrentTab()); pendingWindowTitle_.reset( [BrowserWindowUtils scheduleReplaceOldTitle:pendingWindowTitle_.get() withNewTitle:newTitle @@ -570,7 +571,7 @@ enum { image:iconImage]; } else { NSImage* iconImage = mac::FaviconForTabContents( - windowShim_->browser()->GetSelectedTabContentsWrapper()); + windowShim_->GetPanelBrowser()->GetSelectedTabContentsWrapper()); if (!iconImage) iconImage = gfx::GetCachedImageWithName(@"nav.pdf"); NSImageView* iconView = @@ -635,7 +636,8 @@ enum { if (action == @selector(commandDispatch:) || action == @selector(commandDispatchUsingKeyModifiers:)) { NSInteger tag = [item tag]; - CommandUpdater* command_updater = windowShim_->browser()->command_updater(); + CommandUpdater* command_updater = + windowShim_->GetPanelBrowser()->command_updater(); if (command_updater->SupportsCommand(tag)) { enable = command_updater->IsCommandEnabled(tag); // Disable commands that do not apply to Panels. @@ -667,7 +669,7 @@ enum { // disabled in the UI in validateUserInterfaceItem:. - (void)commandDispatch:(id)sender { DCHECK(sender); - windowShim_->browser()->ExecuteCommand([sender tag]); + windowShim_->GetPanelBrowser()->ExecuteCommand([sender tag]); } // Same as |-commandDispatch:|, but executes commands using a disposition @@ -678,12 +680,12 @@ enum { WindowOpenDisposition disposition = event_utils::WindowOpenDispositionFromNSEventWithFlags( event, [event modifierFlags]); - windowShim_->browser()->ExecuteCommandWithDisposition( + windowShim_->GetPanelBrowser()->ExecuteCommandWithDisposition( [sender tag], disposition); } - (void)executeCommand:(int)command { - windowShim_->browser()->ExecuteCommandIfEnabled(command); + windowShim_->GetPanelBrowser()->ExecuteCommandIfEnabled(command); } // Handler for the custom Close button. @@ -714,7 +716,7 @@ enum { // finally ready. // This callback is only called if the standard Close button is enabled in XIB. - (BOOL)windowShouldClose:(id)sender { - Browser* browser = windowShim_->browser(); + Browser* browser = windowShim_->GetPanelBrowser(); // Give beforeunload handlers the chance to cancel the close before we hide // the window below. if (!browser->ShouldCloseWindow()) @@ -739,7 +741,7 @@ enum { // When windowShouldClose returns YES (or if controller receives direct 'close' // signal), window will be unconditionally closed. Clean up. - (void)windowWillClose:(NSNotification*)notification { - DCHECK(windowShim_->browser()->tab_strip_model()->empty()); + DCHECK(windowShim_->GetPanelBrowser()->tab_strip_model()->empty()); // Avoid callbacks from a nonblocking animation in progress, if any. [self terminateBoundsAnimation]; windowShim_->DidCloseNativeWindow(); @@ -899,7 +901,7 @@ enum { // whether it's refactoring more things into BrowserWindowUtils or making a // common base controller for browser windows. - (void)windowDidBecomeKey:(NSNotification*)notification { - BrowserList::SetLastActive(windowShim_->browser()); + BrowserList::SetLastActive(windowShim_->GetPanelBrowser()); // We need to activate the controls (in the "WebView"). To do this, get the // selected WebContents's RenderWidgetHostView and tell it to activate. @@ -936,7 +938,7 @@ enum { return; BrowserWindow* browser_window = windowShim_->panel()->manager()->GetNextBrowserWindowToActivate( - windowShim_->panel()); + windowShim_->GetPanelBrowser()); if (browser_window) browser_window->Activate(); |