summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-28 23:56:54 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-28 23:56:54 +0000
commit35a9e196778a2b95347cb6d5f5c9eee4c674dcee (patch)
tree021bf187e31dfd4e0f9f3bf471ca6ffc31c079b9 /chrome
parent0fbcaf09ed18f665d966ef6c0c4955656b716484 (diff)
downloadchromium_src-35a9e196778a2b95347cb6d5f5c9eee4c674dcee.zip
chromium_src-35a9e196778a2b95347cb6d5f5c9eee4c674dcee.tar.gz
chromium_src-35a9e196778a2b95347cb6d5f5c9eee4c674dcee.tar.bz2
ExtensionInfobarGtk now take up available width.
This patch allows ExtensionInfoBarGtk to use the actual width of the infobar for display of the content. This involves factoring out of ExtensionViewGtk a similar pattern that exists on Views -- namely a Container interface that allows containers to decide how to react to PreferredWidthChanged notifications BUG=39916 TEST=none Review URL: http://codereview.chromium.org/2877003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/browser_action_test_util_gtk.cc4
-rw-r--r--chrome/browser/gtk/extension_infobar_gtk.cc13
-rw-r--r--chrome/browser/gtk/extension_infobar_gtk.h8
-rw-r--r--chrome/browser/gtk/extension_popup_gtk.cc22
-rw-r--r--chrome/browser/gtk/extension_popup_gtk.h14
-rw-r--r--chrome/browser/gtk/extension_view_gtk.cc23
-rw-r--r--chrome/browser/gtk/extension_view_gtk.h19
7 files changed, 76 insertions, 27 deletions
diff --git a/chrome/browser/extensions/browser_action_test_util_gtk.cc b/chrome/browser/extensions/browser_action_test_util_gtk.cc
index 55e6224..7761946 100644
--- a/chrome/browser/extensions/browser_action_test_util_gtk.cc
+++ b/chrome/browser/extensions/browser_action_test_util_gtk.cc
@@ -81,10 +81,10 @@ bool BrowserActionTestUtil::HidePopup() {
// static
gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
// On Linux we actually just limit the size of the extension view.
- return gfx::Size(ExtensionViewGtk::kMinWidth, ExtensionViewGtk::kMinHeight);
+ return gfx::Size(ExtensionPopupGtk::kMinWidth, ExtensionPopupGtk::kMinHeight);
}
// static
gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
- return gfx::Size(ExtensionViewGtk::kMaxWidth, ExtensionViewGtk::kMaxHeight);
+ return gfx::Size(ExtensionPopupGtk::kMaxWidth, ExtensionPopupGtk::kMaxHeight);
}
diff --git a/chrome/browser/gtk/extension_infobar_gtk.cc b/chrome/browser/gtk/extension_infobar_gtk.cc
index f800e4a..cdc9561 100644
--- a/chrome/browser/gtk/extension_infobar_gtk.cc
+++ b/chrome/browser/gtk/extension_infobar_gtk.cc
@@ -6,6 +6,8 @@
#include "app/resource_bundle.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_resource.h"
#include "gfx/gtk_util.h"
@@ -16,6 +18,7 @@ ExtensionInfoBarGtk::ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate)
tracker_(this),
delegate_(delegate),
view_(NULL) {
+ delegate_->extension_host()->view()->SetContainer(this);
BuildWidgets();
}
@@ -69,7 +72,15 @@ void ExtensionInfoBarGtk::OnSizeAllocate(GtkWidget* widget,
GtkAllocation* allocation) {
gfx::Size new_size(allocation->width, allocation->height);
- // TODO(finnur): Size the infobar based on HTML content (up to 72 pixels).
+ delegate_->extension_host()->view()->render_view_host()->view()
+ ->SetSize(new_size);
+}
+
+void ExtensionInfoBarGtk::OnExtensionPreferredSizeChanged(
+ ExtensionViewGtk* view,
+ const gfx::Size& new_size) {
+ // TODO(rafaelw) - Size the InfobarGtk vertically based on the preferred size
+ // of the content.
}
InfoBar* ExtensionInfoBarDelegate::CreateInfoBar() {
diff --git a/chrome/browser/gtk/extension_infobar_gtk.h b/chrome/browser/gtk/extension_infobar_gtk.h
index 63ec1e1..2fff977 100644
--- a/chrome/browser/gtk/extension_infobar_gtk.h
+++ b/chrome/browser/gtk/extension_infobar_gtk.h
@@ -7,6 +7,7 @@
#include <gtk/gtk.h>
+#include "chrome/browser/gtk/extension_view_gtk.h"
#include "chrome/browser/gtk/infobar_gtk.h"
#include "chrome/browser/extensions/extension_infobar_delegate.h"
#include "chrome/browser/extensions/image_loading_tracker.h"
@@ -17,7 +18,8 @@ class ExtensionResource;
class ExtensionViewGtk;
class ExtensionInfoBarGtk : public InfoBar,
- public ImageLoadingTracker::Observer {
+ public ImageLoadingTracker::Observer,
+ public ExtensionViewGtk::Container {
public:
explicit ExtensionInfoBarGtk(ExtensionInfoBarDelegate* delegate);
virtual ~ExtensionInfoBarGtk();
@@ -26,6 +28,10 @@ class ExtensionInfoBarGtk : public InfoBar,
virtual void OnImageLoaded(
SkBitmap* image, ExtensionResource resource, int index);
+ // ExtensionViewGtk::Container implementation
+ virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view,
+ const gfx::Size& new_size);
+
private:
// Build the widgets of the Infobar.
void BuildWidgets();
diff --git a/chrome/browser/gtk/extension_popup_gtk.cc b/chrome/browser/gtk/extension_popup_gtk.cc
index c2a68ec..32b32bc 100644
--- a/chrome/browser/gtk/extension_popup_gtk.cc
+++ b/chrome/browser/gtk/extension_popup_gtk.cc
@@ -15,11 +15,21 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
ExtensionPopupGtk* ExtensionPopupGtk::current_extension_popup_ = NULL;
+// The minimum/maximum dimensions of the extension popup.
+// The minimum is just a little larger than the size of a browser action button.
+// The maximum is an arbitrary number that should be smaller than most screens.
+const int ExtensionPopupGtk::kMinWidth = 25;
+const int ExtensionPopupGtk::kMinHeight = 25;
+const int ExtensionPopupGtk::kMaxWidth = 800;
+const int ExtensionPopupGtk::kMaxHeight = 600;
+
ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser,
ExtensionHost* host,
GtkWidget* anchor,
@@ -30,6 +40,8 @@ ExtensionPopupGtk::ExtensionPopupGtk(Browser* browser,
anchor_(anchor),
being_inspected_(inspect),
method_factory_(this) {
+ host_->view()->SetContainer(this);
+
// If the host had somehow finished loading, then we'd miss the notification
// and not show. This seems to happen in single-process mode.
if (host->did_stop_loading()) {
@@ -129,6 +141,16 @@ void ExtensionPopupGtk::InfoBubbleClosing(InfoBubbleGtk* bubble,
delete this;
}
+void ExtensionPopupGtk::OnExtensionPreferredSizeChanged(
+ ExtensionViewGtk* view,
+ const gfx::Size& new_size) {
+ int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width()));
+ int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height()));
+
+ view->render_view_host()->view()->SetSize(gfx::Size(width, height));
+ gtk_widget_set_size_request(view->native_view(), width, height);
+}
+
// static
void ExtensionPopupGtk::Show(const GURL& url, Browser* browser,
GtkWidget* anchor, bool inspect) {
diff --git a/chrome/browser/gtk/extension_popup_gtk.h b/chrome/browser/gtk/extension_popup_gtk.h
index 846f4dc..fcf7015 100644
--- a/chrome/browser/gtk/extension_popup_gtk.h
+++ b/chrome/browser/gtk/extension_popup_gtk.h
@@ -7,6 +7,7 @@
#include "base/scoped_ptr.h"
#include "base/task.h"
+#include "chrome/browser/gtk/extension_view_gtk.h"
#include "chrome/browser/gtk/info_bubble_gtk.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -17,7 +18,8 @@ class ExtensionHost;
class GURL;
class ExtensionPopupGtk : public NotificationObserver,
- public InfoBubbleGtkDelegate {
+ public InfoBubbleGtkDelegate,
+ public ExtensionViewGtk::Container {
public:
ExtensionPopupGtk(Browser* browser,
ExtensionHost* host,
@@ -39,6 +41,10 @@ class ExtensionPopupGtk : public NotificationObserver,
virtual void InfoBubbleClosing(InfoBubbleGtk* bubble,
bool closed_by_escape);
+ // ExtensionViewGtk::Container implementation
+ virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view,
+ const gfx::Size& new_size);
+
// Destroys the popup widget. This will in turn destroy us since we delete
// ourselves when the info bubble closes. Returns true if we successfully
// closed the bubble.
@@ -53,6 +59,12 @@ class ExtensionPopupGtk : public NotificationObserver,
return being_inspected_;
}
+ // Declared here for testing.
+ static const int kMinWidth;
+ static const int kMinHeight;
+ static const int kMaxWidth;
+ static const int kMaxHeight;
+
private:
// Shows the popup widget. Called after loading completes.
void ShowPopup();
diff --git a/chrome/browser/gtk/extension_view_gtk.cc b/chrome/browser/gtk/extension_view_gtk.cc
index cb03bc9..f2e49c3 100644
--- a/chrome/browser/gtk/extension_view_gtk.cc
+++ b/chrome/browser/gtk/extension_view_gtk.cc
@@ -5,22 +5,16 @@
#include "chrome/browser/gtk/extension_view_gtk.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/gtk/extension_popup_gtk.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
-// The minimum/maximum dimensions of the extension view.
-// The minimum is just a little larger than the size of a browser action button.
-// The maximum is an arbitrary number that should be smaller than most screens.
-const int ExtensionViewGtk::kMinWidth = 25;
-const int ExtensionViewGtk::kMinHeight = 25;
-const int ExtensionViewGtk::kMaxWidth = 800;
-const int ExtensionViewGtk::kMaxHeight = 600;
-
ExtensionViewGtk::ExtensionViewGtk(ExtensionHost* extension_host,
Browser* browser)
: browser_(browser),
extension_host_(extension_host),
- render_widget_host_view_(NULL) {
+ render_widget_host_view_(NULL),
+ container_(NULL) {
}
void ExtensionViewGtk::Init() {
@@ -44,11 +38,8 @@ void ExtensionViewGtk::SetBackground(const SkBitmap& background) {
}
void ExtensionViewGtk::UpdatePreferredSize(const gfx::Size& new_size) {
- int width = std::max(kMinWidth, std::min(kMaxWidth, new_size.width()));
- int height = std::max(kMinHeight, std::min(kMaxHeight, new_size.height()));
-
- render_widget_host_view_->SetSize(gfx::Size(width, height));
- gtk_widget_set_size_request(native_view(), width, height);
+ if (container_)
+ container_->OnExtensionPreferredSizeChanged(this, new_size);
}
void ExtensionViewGtk::CreateWidgetHostView() {
@@ -67,7 +58,7 @@ void ExtensionViewGtk::RenderViewCreated() {
// Tell the renderer not to draw scrollbars in popups unless the
// popups are at the maximum allowed size.
- gfx::Size largest_popup_size(ExtensionViewGtk::kMaxWidth,
- ExtensionViewGtk::kMaxHeight);
+ gfx::Size largest_popup_size(ExtensionPopupGtk::kMaxWidth,
+ ExtensionPopupGtk::kMaxHeight);
extension_host_->DisableScrollbarsForSmallWindows(largest_popup_size);
}
diff --git a/chrome/browser/gtk/extension_view_gtk.h b/chrome/browser/gtk/extension_view_gtk.h
index 2d815d7..26dd8d1 100644
--- a/chrome/browser/gtk/extension_view_gtk.h
+++ b/chrome/browser/gtk/extension_view_gtk.h
@@ -20,6 +20,13 @@ class ExtensionViewGtk {
public:
ExtensionViewGtk(ExtensionHost* extension_host, Browser* browser);
+ class Container {
+ public:
+ virtual ~Container() {}
+ virtual void OnExtensionPreferredSizeChanged(ExtensionViewGtk* view,
+ const gfx::Size& new_size) {}
+ };
+
void Init();
gfx::NativeView native_view();
@@ -27,6 +34,9 @@ class ExtensionViewGtk {
void SetBackground(const SkBitmap& background);
+ // Sets the container for this view.
+ void SetContainer(Container* container) { container_ = container; }
+
// Method for the ExtensionHost to notify us about the correct size for
// extension contents.
void UpdatePreferredSize(const gfx::Size& new_size);
@@ -37,12 +47,6 @@ class ExtensionViewGtk {
RenderViewHost* render_view_host() const;
- // Declared here for testing.
- static const int kMinWidth;
- static const int kMinHeight;
- static const int kMaxWidth;
- static const int kMaxHeight;
-
private:
void CreateWidgetHostView();
@@ -56,6 +60,9 @@ class ExtensionViewGtk {
// when the view has a custom background, but hasn't been initialized yet.
SkBitmap pending_background_;
+ // This view's container.
+ Container* container_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionViewGtk);
};