summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 21:52:48 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 21:52:48 +0000
commit0a2aeb81a06170cf4d99392b683736c46212f9ef (patch)
tree1c491dcbe56474ad5bbbd6da0cd47c75eca414d3 /chrome/browser/tab_contents
parent26ee7556422eb077a813c9a15a03867779bb8188 (diff)
downloadchromium_src-0a2aeb81a06170cf4d99392b683736c46212f9ef.zip
chromium_src-0a2aeb81a06170cf4d99392b683736c46212f9ef.tar.gz
chromium_src-0a2aeb81a06170cf4d99392b683736c46212f9ef.tar.bz2
Linux: Take download shelf and infobar close animations into account during render view sizing.
http://crbug.com/11080 Review URL: http://codereview.chromium.org/113322 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc10
-rw-r--r--chrome/browser/tab_contents/tab_contents.h5
-rw-r--r--chrome/browser/tab_contents/tab_contents_delegate.h7
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.cc41
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.h17
5 files changed, 70 insertions, 10 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 9042518..af83bfd 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -919,7 +919,7 @@ void TabContents::SetDownloadShelfVisible(bool visible) {
if (shelf_visible_ != visible) {
if (visible) {
// Invoke GetDownloadShelf to force the shelf to be created.
- GetDownloadShelf();
+ GetDownloadShelf(true);
}
shelf_visible_ = visible;
@@ -951,7 +951,7 @@ void TabContents::OnStartDownload(DownloadItem* download) {
TabContents* tab_contents = delegate()->GetConstrainingContents(this);
// GetDownloadShelf creates the download shelf if it was not yet created.
- tab_contents->GetDownloadShelf()->AddDownload(
+ tab_contents->GetDownloadShelf(true)->AddDownload(
new DownloadItemModel(download));
tab_contents->SetDownloadShelfVisible(true);
@@ -966,14 +966,14 @@ void TabContents::OnStartDownload(DownloadItem* download) {
#endif
}
-DownloadShelf* TabContents::GetDownloadShelf() {
- if (!download_shelf_.get())
+DownloadShelf* TabContents::GetDownloadShelf(bool create) {
+ if (!download_shelf_.get() && create)
download_shelf_.reset(DownloadShelf::Create(this));
return download_shelf_.get();
}
void TabContents::MigrateShelfFrom(TabContents* tab_contents) {
- download_shelf_.reset(tab_contents->GetDownloadShelf());
+ download_shelf_.reset(tab_contents->GetDownloadShelf(true));
download_shelf_->ChangeTabContents(tab_contents, this);
tab_contents->ReleaseDownloadShelf();
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index cf25aba..3b749e6 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -415,8 +415,9 @@ class TabContents : public PageNavigator,
// Displays the download shelf and animation when a download occurs.
void OnStartDownload(DownloadItem* download);
- // Returns the DownloadShelf, creating it if necessary.
- DownloadShelf* GetDownloadShelf();
+ // Returns the DownloadShelf. If the shelf doesn't exist and |create| is true,
+ // this function will create the shelf.
+ DownloadShelf* GetDownloadShelf(bool create);
// Transfer the shelf view from |tab_contents| to the receiving TabContents.
// |tab_contents| no longer owns the shelf after this call. The shelf is owned
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h
index 3485fb8..4ba9553 100644
--- a/chrome/browser/tab_contents/tab_contents_delegate.h
+++ b/chrome/browser/tab_contents/tab_contents_delegate.h
@@ -167,6 +167,13 @@ class TabContentsDelegate {
return false;
}
+ // Return much extra vertical space should be allotted to the
+ // render view widget during various animations (e.g. infobar closing).
+ // This is used to make painting look smoother.
+ virtual int GetExtraRenderViewHeight() {
+ return 0;
+ }
+
protected:
~TabContentsDelegate() {}
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
index b9671be..59065ed 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
@@ -10,6 +10,8 @@
#include "base/string_util.h"
#include "base/gfx/point.h"
#include "base/gfx/rect.h"
+#include "base/gfx/size.h"
+#include "chrome/browser/download/download_shelf.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/sad_tab_gtk.h"
#include "chrome/browser/renderer_host/render_view_host.h"
@@ -58,6 +60,16 @@ gboolean OnMouseMove(GtkWidget* widget, GdkEventMotion* event,
return FALSE;
}
+// Used with gtk_container_foreach to change the sizes of the children of
+// |fixed_|.
+void SetSizeRequest(GtkWidget* widget, gpointer userdata) {
+ gfx::Size* size = static_cast<gfx::Size*>(userdata);
+ if (widget->allocation.width != size->width() ||
+ widget->allocation.height != size->height()) {
+ gtk_widget_set_size_request(widget, size->width(), size->height());
+ }
+}
+
} // namespace
// static
@@ -68,6 +80,11 @@ TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
: TabContentsView(tab_contents),
vbox_(gtk_vbox_new(FALSE, 0)) {
+ fixed_ = gtk_fixed_new();
+ gtk_box_pack_start(GTK_BOX(vbox_.get()), fixed_, TRUE, TRUE, 0);
+ g_signal_connect(fixed_, "size-allocate",
+ G_CALLBACK(OnSizeAllocate), this);
+ gtk_widget_show(fixed_);
registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
Source<TabContents>(tab_contents));
registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
@@ -108,7 +125,8 @@ RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget(
GDK_POINTER_MOTION_MASK);
g_signal_connect(content_view, "button-press-event",
G_CALLBACK(OnMouseDown), this);
- gtk_box_pack_start(GTK_BOX(vbox_.get()), content_view, TRUE, TRUE, 0);
+
+ InsertIntoContentArea(content_view);
return view;
}
@@ -250,8 +268,7 @@ void TabContentsViewGtk::Observe(NotificationType type,
}
case NotificationType::TAB_CONTENTS_DISCONNECTED: {
sad_tab_.reset(new SadTabGtk);
- gtk_box_pack_start(
- GTK_BOX(vbox_.get()), sad_tab_->widget(), TRUE, TRUE, 0);
+ InsertIntoContentArea(sad_tab_->widget());
gtk_widget_show(sad_tab_->widget());
break;
}
@@ -278,8 +295,26 @@ void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) {
tab_contents()->render_view_host()->DragSourceSystemDragEnded();
}
+void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) {
+ gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0);
+}
+
gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget,
GdkEventButton* event, TabContentsViewGtk* view) {
view->last_mouse_down_time_ = event->time;
return FALSE;
}
+
+gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget,
+ GtkAllocation* allocation,
+ TabContentsViewGtk* view) {
+ int width = allocation->width;
+ DownloadShelf* shelf = view->tab_contents()->GetDownloadShelf(false);
+ int height = shelf && shelf->IsClosing() ?
+ widget->parent->allocation.height : allocation->height;
+ height += view->tab_contents()->delegate()->GetExtraRenderViewHeight();
+ gfx::Size size(width, height);
+ gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size);
+
+ return FALSE;
+}
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h
index 3120cc3..cebb637a 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.h
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
#define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
+#include <gtk/gtk.h>
+
#include "base/scoped_ptr.h"
#include "chrome/browser/gtk/focus_store_gtk.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
@@ -68,13 +70,28 @@ class TabContentsViewGtk : public TabContentsView,
const NotificationDetails& details);
private:
+ // Insert the given widget into the content area. Should only be used for
+ // web pages and the like (including interstitials and sad tab). Note that
+ // this will be perfectly happy to insert overlapping render views, so care
+ // should be taken that the correct one is hidden/shown.
+ void InsertIntoContentArea(GtkWidget* widget);
+
// We keep track of the timestamp of the latest mousedown event.
static gboolean OnMouseDown(GtkWidget* widget,
GdkEventButton* event, TabContentsViewGtk* view);
+ // Used to propagate size changes on |fixed_| to its children.
+ static gboolean OnSizeAllocate(GtkWidget* widget,
+ GtkAllocation* config,
+ TabContentsViewGtk* view);
+
// The native widget for the tab.
OwnedWidgetGtk vbox_;
+ // This container holds the tab's web page views. It is a GtkFixed so that we
+ // can control the size of the web pages.
+ GtkWidget* fixed_;
+
// The context menu is reset every time we show it, but we keep a pointer to
// between uses so that it won't go out of scope before we're done with it.
scoped_ptr<RenderViewContextMenuGtk> context_menu_;