summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 16:56:52 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 16:56:52 +0000
commitff043d8475259c7fb700d529b82a964ad51c8d9a (patch)
tree64a46a45460f80cc7ecc167831a7de7d3265605e /chrome/browser/views
parent279f3f1a1dcc979cc9509a707f0389a8f9c74fc7 (diff)
downloadchromium_src-ff043d8475259c7fb700d529b82a964ad51c8d9a.zip
chromium_src-ff043d8475259c7fb700d529b82a964ad51c8d9a.tar.gz
chromium_src-ff043d8475259c7fb700d529b82a964ad51c8d9a.tar.bz2
Lands http://codereview.chromium.org/306039 for Sean:
Adding support for constrained dialogs with toolkit_views. BUG=none TEST=none Review URL: http://codereview.chromium.org/322002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_gtk.cc45
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_gtk.h18
2 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
index 7cb7bdb..f466290 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
@@ -14,6 +14,7 @@
#include "base/gfx/size.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_shelf.h"
+#include "chrome/browser/gtk/constrained_window_gtk.h"
#include "chrome/browser/gtk/tab_contents_drag_source.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_factory.h"
@@ -121,6 +122,29 @@ TabContentsViewGtk::~TabContentsViewGtk() {
CloseNow();
}
+void TabContentsViewGtk::AttachConstrainedWindow(
+ ConstrainedWindowGtk* constrained_window) {
+ DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(),
+ constrained_window) == constrained_windows_.end());
+
+ constrained_windows_.push_back(constrained_window);
+ AddChild(constrained_window->widget());
+
+ gfx::Rect bounds;
+ GetContainerBounds(&bounds);
+ SetFloatingPosition(bounds.size());
+}
+
+void TabContentsViewGtk::RemoveConstrainedWindow(
+ ConstrainedWindowGtk* constrained_window) {
+ std::vector<ConstrainedWindowGtk*>::iterator item =
+ find(constrained_windows_.begin(), constrained_windows_.end(),
+ constrained_window);
+ DCHECK(item != constrained_windows_.end());
+ RemoveChild((*item)->widget());
+ constrained_windows_.erase(item);
+}
+
void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) {
set_delete_on_destroy(false);
WidgetGtk::Init(NULL, gfx::Rect(0, 0, initial_size.width(),
@@ -378,4 +402,25 @@ void TabContentsViewGtk::WasSized(const gfx::Size& size) {
// TODO(brettw) this function can probably be moved to this class.
tab_contents()->RepositionSupressedPopupsToFit();
+
+ SetFloatingPosition(size);
}
+
+void TabContentsViewGtk::SetFloatingPosition(const gfx::Size& size) {
+ // Place each ConstrainedWindow in the center of the view.
+ int half_view_width = size.width() / 2;
+
+ typedef std::vector<ConstrainedWindowGtk*>::iterator iterator;
+
+ for (iterator f = constrained_windows_.begin(),
+ l = constrained_windows_.end(); f != l; ++f) {
+ GtkWidget* widget = (*f)->widget();
+
+ GtkRequisition requisition;
+ gtk_widget_size_request(widget, &requisition);
+
+ int child_x = std::max(half_view_width - (requisition.width / 2), 0);
+ PositionChild(widget, child_x, 0, requisition.width, requisition.height);
+ }
+}
+
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h
index 142c7b3..7177737 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h
+++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h
@@ -5,11 +5,15 @@
#ifndef CHROME_BROWSER_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_
+#include <vector>
+
#include "base/gfx/size.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "views/widget/widget_gtk.h"
+class ConstrainedWindowGtk;
+typedef struct _GtkFloatingContainer GtkFloatingContainer;
class RenderViewContextMenuWin;
class SadTabView;
class TabContentsDragSource;
@@ -30,6 +34,11 @@ class TabContentsViewGtk : public TabContentsView,
explicit TabContentsViewGtk(TabContents* tab_contents);
virtual ~TabContentsViewGtk();
+ // Unlike Windows, ConstrainedWindows need to collaborate with the
+ // TabContentsViewGtk to position the dialogs.
+ void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window);
+ void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window);
+
// TabContentsView implementation --------------------------------------------
virtual void CreateView(const gfx::Size& initial_size);
@@ -73,6 +82,11 @@ class TabContentsViewGtk : public TabContentsView,
// of the change, reposition popups, and the find in page bar.
void WasSized(const gfx::Size& size);
+ // For any floating views (ConstrainedDialogs) this function centers them
+ // within this view. It's called whem a ConstrainedDialog is attached and
+ // when this view is resized.
+ void SetFloatingPosition(const gfx::Size& size);
+
// ---------------------------------------------------------------------------
// Used to render the sad tab. This will be non-NULL only when the sad tab is
@@ -101,6 +115,10 @@ class TabContentsViewGtk : public TabContentsView,
// Current size. See comment in WidgetGtk as to why this is cached.
gfx::Size size_;
+ // Each individual UI for constrained dialogs currently displayed. The
+ // objects in this vector are owned by the TabContents, not the view.
+ std::vector<ConstrainedWindowGtk*> constrained_windows_;
+
DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk);
};