diff options
Diffstat (limited to 'chrome/browser')
22 files changed, 161 insertions, 72 deletions
diff --git a/chrome/browser/chromeos/main_menu.h b/chrome/browser/chromeos/main_menu.h index 2d896fc..11e9942 100644 --- a/chrome/browser/chromeos/main_menu.h +++ b/chrome/browser/chromeos/main_menu.h @@ -18,6 +18,9 @@ class Browser; class RenderWidgetHostViewGtk; class SiteInstance; +namespace gfx { +class Size; +} namespace views { class WidgetGtk; } @@ -162,7 +165,7 @@ class MainMenu : public RenderViewHostDelegate, virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} virtual void HandleMouseEvent() {} virtual void HandleMouseLeave() {} - virtual void UpdatePreferredWidth(int pref_width) {} + virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} // The currently active browser. We use this to open urls. Browser* browser_; diff --git a/chrome/browser/cocoa/extension_view_mac.h b/chrome/browser/cocoa/extension_view_mac.h index 8abb481..4ce4c13 100644 --- a/chrome/browser/cocoa/extension_view_mac.h +++ b/chrome/browser/cocoa/extension_view_mac.h @@ -7,6 +7,7 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" +#include "base/gfx/size.h" #include "third_party/skia/include/core/SkBitmap.h" class Browser; @@ -40,9 +41,9 @@ class ExtensionViewMac { // Sets the extensions's background image. void SetBackground(const SkBitmap& background); - // Method for the ExtensionHost to notify us about the correct width for + // Method for the ExtensionHost to notify us about the correct size for // extension contents. - void UpdatePreferredWidth(int pref_width); + void UpdatePreferredSize(const gfx::Size& new_size); // Method for the ExtensionHost to notify us when the RenderViewHost has a // connection. diff --git a/chrome/browser/cocoa/extension_view_mac.mm b/chrome/browser/cocoa/extension_view_mac.mm index c9844b3..171cc30 100644 --- a/chrome/browser/cocoa/extension_view_mac.mm +++ b/chrome/browser/cocoa/extension_view_mac.mm @@ -44,7 +44,7 @@ void ExtensionViewMac::SetBackground(const SkBitmap& background) { } } -void ExtensionViewMac::UpdatePreferredWidth(int pref_width) { +void ExtensionViewMac::UpdatePreferredSize(const gfx::Size& new_size) { // TODO(thakis, erikkay): Windows does some tricks to resize the extension // view not before it's visible. Do something similar here. @@ -52,7 +52,7 @@ void ExtensionViewMac::UpdatePreferredWidth(int pref_width) { // resizing. NSView* view = native_view(); NSRect frame = [view frame]; - frame.size.width = pref_width; + frame.size.width = new_size.width(); // RenderWidgetHostViewCocoa overrides setFrame but not setFrameSize. [view setFrame:frame]; diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc index 692e74e..5a7c086 100644 --- a/chrome/browser/extensions/browser_action_apitest.cc +++ b/chrome/browser/extensions/browser_action_apitest.cc @@ -11,6 +11,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/browser_actions_container.h" +#include "chrome/browser/views/extensions/extension_popup.h" #include "chrome/browser/views/toolbar_view.h" #include "chrome/common/extensions/extension_action.h" #include "chrome/test/ui_test_utils.h" @@ -62,7 +63,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserAction) { ASSERT_TRUE(result); } - IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DynamicBrowserAction) { ASSERT_TRUE(RunExtensionTest("browser_action_no_icon")) << message_; @@ -84,3 +84,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DynamicBrowserAction) { ExtensionActionState* action_state = extension->browser_action_state(); ASSERT_TRUE(action_state->icon()); } + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserActionPopup) { + ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("popup"))); + + ResultCatcher catcher; + BrowserActionsContainer* browser_actions = + browser()->window()->GetBrowserWindowTesting()->GetToolbarView()-> + browser_actions(); + + // Simulate a click on the browser action and verify the size of the resulting + // popup. + browser_actions->TestExecuteBrowserAction(0); + EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); + ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); + gfx::Rect bounds = browser_actions->TestGetPopup()->view()->bounds(); + EXPECT_EQ(100, bounds.width()); + EXPECT_EQ(100, bounds.height()); + browser_actions->HidePopup(); + EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); + + // Do it again, and verify the new bigger size (the popup grows each time it's + // opened). + browser_actions->TestExecuteBrowserAction(0); + EXPECT_TRUE(browser_actions->TestGetPopup() != NULL); + ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); + bounds = browser_actions->TestGetPopup()->view()->bounds(); + EXPECT_EQ(200, bounds.width()); + EXPECT_EQ(200, bounds.height()); + browser_actions->HidePopup(); + EXPECT_TRUE(browser_actions->TestGetPopup() == NULL); +} diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index 8b45d4c..5413cd7 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -213,9 +213,9 @@ void ExtensionHost::Observe(NotificationType type, } } -void ExtensionHost::UpdatePreferredWidth(int pref_width) { +void ExtensionHost::UpdatePreferredSize(const gfx::Size& new_size) { if (view_.get()) - view_->UpdatePreferredWidth(pref_width); + view_->UpdatePreferredSize(new_size); } void ExtensionHost::RenderViewGone(RenderViewHost* render_view_host) { @@ -503,7 +503,7 @@ void ExtensionHost::RenderViewCreated(RenderViewHost* render_view_host) { extension_function_dispatcher_.reset( new ExtensionFunctionDispatcher(render_view_host, this, url_)); - render_view_host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode( + render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode( render_view_host->routing_id())); } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index ba145b4..0c43067 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -134,7 +134,7 @@ class ExtensionHost : public RenderViewHostDelegate, virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); virtual void HandleMouseEvent(); virtual void HandleMouseLeave(); - virtual void UpdatePreferredWidth(int pref_width); + virtual void UpdatePreferredSize(const gfx::Size& new_size); // NotificationObserver virtual void Observe(NotificationType type, diff --git a/chrome/browser/gtk/extension_view_gtk.cc b/chrome/browser/gtk/extension_view_gtk.cc index 55f7883..d7a4fca 100644 --- a/chrome/browser/gtk/extension_view_gtk.cc +++ b/chrome/browser/gtk/extension_view_gtk.cc @@ -36,8 +36,8 @@ void ExtensionViewGtk::SetBackground(const SkBitmap& background) { } } -void ExtensionViewGtk::UpdatePreferredWidth(int pref_width) { - gtk_widget_set_size_request(native_view(), pref_width, -1); +void ExtensionViewGtk::UpdatePreferredSize(const gfx::Size& new_size) { + gtk_widget_set_size_request(native_view(), new_size.width(), -1); } void ExtensionViewGtk::CreateWidgetHostView() { diff --git a/chrome/browser/gtk/extension_view_gtk.h b/chrome/browser/gtk/extension_view_gtk.h index 6f67f53..16b7892 100644 --- a/chrome/browser/gtk/extension_view_gtk.h +++ b/chrome/browser/gtk/extension_view_gtk.h @@ -7,6 +7,7 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" +#include "base/gfx/size.h" #include "third_party/skia/include/core/SkBitmap.h" class Browser; @@ -29,9 +30,9 @@ class ExtensionViewGtk { void SetBackground(const SkBitmap& background); - // Method for the ExtensionHost to notify us about the correct width for + // Method for the ExtensionHost to notify us about the correct size for // extension contents. - void UpdatePreferredWidth(int pref_width); + void UpdatePreferredSize(const gfx::Size& new_size); // Method for the ExtensionHost to notify us when the RenderViewHost has a // connection. diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 5ebe328..d8b86a7 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -764,8 +764,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavIcon, OnMsgDidDownloadFavIcon) IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu) IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL) - IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredWidthChange, - OnMsgDidContentsPreferredWidthChange) + IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, + OnMsgDidContentsPreferredSizeChange) IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, OnMsgDomOperationResponse) IPC_MESSAGE_HANDLER(ViewHostMsg_DOMUISend, @@ -1189,11 +1189,12 @@ void RenderViewHost::OnMsgOpenURL(const GURL& url, delegate_->RequestOpenURL(validated_url, referrer, disposition); } -void RenderViewHost::OnMsgDidContentsPreferredWidthChange(int pref_width) { +void RenderViewHost::OnMsgDidContentsPreferredSizeChange( + const gfx::Size& new_size) { RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); if (!view) return; - view->UpdatePreferredWidth(pref_width); + view->UpdatePreferredSize(new_size); } void RenderViewHost::OnMsgDomOperationResponse( diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index acb1833..f6c1733 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -503,7 +503,7 @@ class RenderViewHost : public RenderWidgetHost, void OnMsgContextMenu(const ContextMenuParams& params); void OnMsgOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition); - void OnMsgDidContentsPreferredWidthChange(int pref_width); + void OnMsgDidContentsPreferredSizeChange(const gfx::Size& new_size); void OnMsgDomOperationResponse(const std::string& json_string, int automation_id); void OnMsgDOMUISend(const std::string& message, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index cb1d008..0e054d4 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -42,6 +42,7 @@ class WaitableEvent; namespace gfx { class Rect; +class Size; } namespace IPC { @@ -140,8 +141,8 @@ class RenderViewHostDelegate { virtual void HandleMouseEvent() = 0; virtual void HandleMouseLeave() = 0; - // The content's intrinsic width (prefWidth) changed. - virtual void UpdatePreferredWidth(int pref_width) = 0; + // The contents' preferred size changed. + virtual void UpdatePreferredSize(const gfx::Size& pref_size) = 0; }; // RendererManagerment ------------------------------------------------------- diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 042801a..cb6648a 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -105,7 +105,7 @@ class InterstitialPage::InterstitialPageRVHViewDelegate const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update); - virtual void UpdatePreferredWidth(int pref_width); + virtual void UpdatePreferredSize(const gfx::Size& pref_size); private: InterstitialPage* interstitial_page_; @@ -569,8 +569,8 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::UpdateDragCursor( void InterstitialPage::InterstitialPageRVHViewDelegate::GotFocus() { } -void InterstitialPage::InterstitialPageRVHViewDelegate::UpdatePreferredWidth( - int pref_width) { +void InterstitialPage::InterstitialPageRVHViewDelegate::UpdatePreferredSize( + const gfx::Size& pref_size) { } void InterstitialPage::InterstitialPageRVHViewDelegate::TakeFocus( diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index 99a052a..2b8ae76 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -23,8 +23,8 @@ void TabContentsView::RenderViewCreated(RenderViewHost* host) { // Default implementation does nothing. Platforms may override. } -void TabContentsView::UpdatePreferredWidth(int pref_width) { - preferred_width_ = pref_width; +void TabContentsView::UpdatePreferredSize(const gfx::Size& pref_size) { + preferred_width_ = pref_size.width(); } void TabContentsView::CreateNewWindow(int route_id) { diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index fcef017..db5fff8 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -123,7 +123,7 @@ class TabContentsView : public RenderViewHostDelegate::View { virtual void HandleMouseLeave() {} // Set and return the content's intrinsic width. - virtual void UpdatePreferredWidth(int pref_width); + virtual void UpdatePreferredSize(const gfx::Size& pref_size); int preferred_width() const { return preferred_width_; } diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index c966ee8..3740a49 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -131,7 +131,7 @@ void TabContentsViewMac::RenderViewCreated(RenderViewHost* host) { // We want updates whenever the intrinsic width of the webpage // changes. Put the RenderView into that mode. int routing_id = host->routing_id(); - host->Send(new ViewMsg_EnableIntrinsicWidthChangedMode(routing_id)); + host->Send(new ViewMsg_EnablePreferredSizeChangedMode(routing_id)); } void TabContentsViewMac::SetPageTitle(const std::wstring& title) { diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 4ce1197..aac8caf 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -271,6 +271,8 @@ class BrowserActionView : public views::View { BrowserActionView(ExtensionAction* browser_action, Extension* extension, BrowserActionsContainer* panel); + BrowserActionButton* button() { return button_; } + private: virtual void Layout(); @@ -445,15 +447,30 @@ void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { void BrowserActionsContainer::HidePopup() { if (popup_) { - popup_->DetachFromBrowser(); - delete popup_; + // This sometimes gets called via a timer (See BubbleLostFocus), so clear + // the task factory. in case one is pending. + task_factory_.RevokeAll(); + + // Save these variables in local temporaries since destroying the popup + // calls BubbleLostFocus to be called, which will try to call HidePopup() + // again if popup_ is non-null. + ExtensionPopup* closing_popup = popup_; + BrowserActionButton* closing_button = popup_button_; popup_ = NULL; - popup_button_->PopupDidHide(); popup_button_ = NULL; + + closing_popup->DetachFromBrowser(); + delete closing_popup; + closing_button->PopupDidHide(); return; } } +void BrowserActionsContainer::TestExecuteBrowserAction(int index) { + BrowserActionButton* button = browser_action_views_[index]->button(); + OnBrowserActionExecuted(button); +} + void BrowserActionsContainer::OnBrowserActionExecuted( BrowserActionButton* button) { const ExtensionAction& browser_action = button->browser_action(); @@ -478,8 +495,7 @@ void BrowserActionsContainer::OnBrowserActionExecuted( rect.set_y(origin.y()); popup_ = ExtensionPopup::Show(browser_action.popup_url(), toolbar_->browser(), - rect, - browser_action.popup_height()); + rect); popup_->set_delegate(this); popup_button_ = button; popup_button_->PopupDidShow(); @@ -539,6 +555,9 @@ void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) { } void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble) { + if (!popup_) + return; + // This is a bit annoying. If you click on the button that generated the // current popup, then we first get this lost focus message, and then // we get the click action. This results in the popup being immediately diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h index f3b3863..c849d44 100644 --- a/chrome/browser/views/browser_actions_container.h +++ b/chrome/browser/views/browser_actions_container.h @@ -69,11 +69,17 @@ class BrowserActionsContainer : public views::View, // by default irrespective of the available space to draw them. int GetClippedPreferredWidth(int available_width); - private: - // Hide the current popup. void HidePopup(); + // Simulate a click on a browser action button. This should only be + // used by unit tests. + void TestExecuteBrowserAction(int index); + + // Retrieve the current popup. This should only be used by unit tests. + ExtensionPopup* TestGetPopup() { return popup_; } + + private: // The vector of browser actions (icons/image buttons for each action). std::vector<BrowserActionView*> browser_action_views_; diff --git a/chrome/browser/views/extensions/extension_popup.cc b/chrome/browser/views/extensions/extension_popup.cc index 0588664..53025e9 100644 --- a/chrome/browser/views/extensions/extension_popup.cc +++ b/chrome/browser/views/extensions/extension_popup.cc @@ -22,6 +22,7 @@ ExtensionPopup::ExtensionPopup(ExtensionHost* host, : BrowserBubble(host->view(), frame, gfx::Point()), relative_to_(relative_to), extension_host_(host) { + host->view()->SetContainer(this); registrar_.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, Source<Profile>(host->profile())); @@ -51,8 +52,19 @@ void ExtensionPopup::Hide() { } void ExtensionPopup::Show() { + if (visible()) + return; + ResizeToView(); + // Show the border first, then the popup overlaid on top. + border_widget_->Show(); + BrowserBubble::Show(true); +} + +void ExtensionPopup::ResizeToView() { + BrowserBubble::ResizeToView(); + // The rounded corners cut off more of the view than the border insets claim. // Since we can't clip the ExtensionView's corners, we need to increase the // inset by half the corner radius as well as lying about the size of the @@ -73,10 +85,6 @@ void ExtensionPopup::Show() { origin.set_x(origin.x() + border_insets.left() + corner_inset); origin.set_y(origin.y() + border_insets.top() + corner_inset); MoveTo(origin.x(), origin.y()); - - // Show the border first, then the popup overlaid on top. - border_widget_->Show(); - BrowserBubble::Show(true); } void ExtensionPopup::Observe(NotificationType type, @@ -92,10 +100,14 @@ void ExtensionPopup::Observe(NotificationType type, } } +void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { + view->SizeToPreferredSize(); + ResizeToView(); +} + // static ExtensionPopup* ExtensionPopup::Show(const GURL& url, Browser* browser, - const gfx::Rect& relative_to, - int height) { + const gfx::Rect& relative_to) { ExtensionProcessManager* manager = browser->profile()->GetExtensionProcessManager(); DCHECK(manager); @@ -106,9 +118,6 @@ ExtensionPopup* ExtensionPopup::Show(const GURL& url, Browser* browser, views::Widget* frame = BrowserView::GetBrowserViewForNativeWindow( browser->window()->GetNativeHandle())->GetWidget(); ExtensionPopup* popup = new ExtensionPopup(host, frame, relative_to); - gfx::Size sz = host->view()->GetPreferredSize(); - sz.set_height(height); - host->view()->SetPreferredSize(sz); // If the host had somehow finished loading, then we'd miss the notification // and not show. This seems to happen in single-process mode. diff --git a/chrome/browser/views/extensions/extension_popup.h b/chrome/browser/views/extensions/extension_popup.h index 1e2ff73..5915f59 100644 --- a/chrome/browser/views/extensions/extension_popup.h +++ b/chrome/browser/views/extensions/extension_popup.h @@ -16,7 +16,8 @@ class Browser; class ExtensionHost; class ExtensionPopup : public BrowserBubble, - public NotificationObserver { + public NotificationObserver, + public ExtensionView::Container { public: virtual ~ExtensionPopup(); @@ -27,20 +28,25 @@ class ExtensionPopup : public BrowserBubble, // The actual display of the popup is delayed until the page contents // finish loading in order to minimize UI flashing and resizing. static ExtensionPopup* Show(const GURL& url, Browser* browser, - const gfx::Rect& relative_to, - int height); + const gfx::Rect& relative_to); ExtensionHost* host() const { return extension_host_.get(); } // BrowserBubble overrides. - virtual void Show(); virtual void Hide(); + virtual void Show(); + virtual void ResizeToView(); // NotificationObserver overrides. virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); + // ExtensionView::Container overrides. + virtual void OnExtensionMouseEvent(ExtensionView* view) { }; + virtual void OnExtensionMouseLeave(ExtensionView* view) { }; + virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); + private: ExtensionPopup(ExtensionHost* host, views::Widget* frame, diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h index 08de605..3be5791 100644 --- a/chrome/browser/views/extensions/extension_shelf.h +++ b/chrome/browser/views/extensions/extension_shelf.h @@ -22,7 +22,7 @@ namespace views { // A shelf that contains Extension toolstrips. class ExtensionShelf : public DetachableToolbarView, - public ExtensionContainer, + public ExtensionView::Container, public ExtensionShelfModelObserver, public AnimationDelegate, public NotificationObserver { diff --git a/chrome/browser/views/extensions/extension_view.cc b/chrome/browser/views/extensions/extension_view.cc index f59d1a4..1d0cfc5 100644 --- a/chrome/browser/views/extensions/extension_view.cc +++ b/chrome/browser/views/extensions/extension_view.cc @@ -13,8 +13,10 @@ #include "views/widget/widget.h" ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) - : host_(host), browser_(browser), - initialized_(false), pending_preferred_width_(0), container_(NULL), + : host_(host), + browser_(browser), + initialized_(false), + container_(NULL), is_clipped_(false) { host_->set_view(this); } @@ -110,7 +112,8 @@ void ExtensionView::ShowIfCompletelyLoaded() { return; } SetVisible(true); - UpdatePreferredWidth(pending_preferred_width_); + + UpdatePreferredSize(pending_preferred_size_); } } @@ -131,17 +134,17 @@ void ExtensionView::SetBackground(const SkBitmap& background) { ShowIfCompletelyLoaded(); } -void ExtensionView::UpdatePreferredWidth(int pref_width) { +void ExtensionView::UpdatePreferredSize(const gfx::Size& new_size) { // Don't actually do anything with this information until we have been shown. // Size changes will not be honored by lower layers while we are hidden. - gfx::Size preferred_size = GetPreferredSize(); if (!IsVisible()) { - pending_preferred_width_ = pref_width; - } else if (pref_width > 0 && pref_width != preferred_size.width()) { - if (preferred_size.height() == 0) - preferred_size.set_height(height()); - SetPreferredSize(gfx::Size(pref_width, preferred_size.height())); + pending_preferred_size_ = new_size; + return; } + + gfx::Size preferred_size = GetPreferredSize(); + if (new_size != preferred_size) + SetPreferredSize(new_size); } void ExtensionView::ViewHierarchyChanged(bool is_add, @@ -168,3 +171,9 @@ void ExtensionView::RenderViewCreated() { pending_background_.reset(); } } + +void ExtensionView::SetPreferredSize(const gfx::Size& size) { + views::NativeViewHost::SetPreferredSize(size); + if (container_) + container_->OnExtensionPreferredSizeChanged(this); +} diff --git a/chrome/browser/views/extensions/extension_view.h b/chrome/browser/views/extensions/extension_view.h index 39b5851..8227771 100644 --- a/chrome/browser/views/extensions/extension_view.h +++ b/chrome/browser/views/extensions/extension_view.h @@ -17,21 +17,22 @@ class ExtensionHost; class ExtensionView; class RenderViewHost; -// A class that represents the container that this view is in. -// (bottom shelf, side bar, etc.) -class ExtensionContainer { - public: - // Mouse event notifications from the view. (useful for hover UI). - virtual void OnExtensionMouseEvent(ExtensionView* view) = 0; - virtual void OnExtensionMouseLeave(ExtensionView* view) = 0; -}; - // This handles the display portion of an ExtensionHost. class ExtensionView : public views::NativeViewHost { public: ExtensionView(ExtensionHost* host, Browser* browser); ~ExtensionView(); + // A class that represents the container that this view is in. + // (bottom shelf, side bar, etc.) + class Container { + public: + // Mouse event notifications from the view. (useful for hover UI). + virtual void OnExtensionMouseEvent(ExtensionView* view) = 0; + virtual void OnExtensionMouseLeave(ExtensionView* view) = 0; + virtual void OnExtensionPreferredSizeChanged(ExtensionView* view) {} + }; + ExtensionHost* host() const { return host_; } Browser* browser() const { return browser_; } Extension* extension() const; @@ -40,7 +41,7 @@ class ExtensionView : public views::NativeViewHost { void SetIsClipped(bool is_clipped); // Notification from ExtensionHost. - void UpdatePreferredWidth(int pref_width); + void UpdatePreferredSize(const gfx::Size& new_size); void HandleMouseEvent(); void HandleMouseLeave(); @@ -52,7 +53,7 @@ class ExtensionView : public views::NativeViewHost { void SetBackground(const SkBitmap& background); // Sets the container for this view. - void SetContainer(ExtensionContainer* container) { container_ = container; } + void SetContainer(Container* container) { container_ = container; } // Overridden from views::NativeViewHost: virtual void SetVisible(bool is_visible); @@ -60,6 +61,7 @@ class ExtensionView : public views::NativeViewHost { const gfx::Rect& current); virtual void ViewHierarchyChanged(bool is_add, views::View *parent, views::View *child); + virtual void SetPreferredSize(const gfx::Size& size); private: friend class ExtensionHost; @@ -90,11 +92,11 @@ class ExtensionView : public views::NativeViewHost { // What we should set the preferred width to once the ExtensionView has // loaded. - int pending_preferred_width_; + gfx::Size pending_preferred_size_; // The container this view is in (not necessarily its direct superview). // Note: the view does not own its container. - ExtensionContainer* container_; + Container* container_; // Whether this extension view is clipped. bool is_clipped_; |