summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 22:33:51 +0000
committerscottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-20 22:33:51 +0000
commit101747a964502501506c2903983b14b2e741d230 (patch)
tree0e952fa7ca99fb91dbfa58982afe49076d5d0464 /views/widget
parentc6a7b86c54d8b920943c97d990268ba1aee7b04b (diff)
downloadchromium_src-101747a964502501506c2903983b14b2e741d230.zip
chromium_src-101747a964502501506c2903983b14b2e741d230.tar.gz
chromium_src-101747a964502501506c2903983b14b2e741d230.tar.bz2
Add in a browser test for dialog resizing, which was catching an issue with the way we were using GTK in toolkit views. Possibly related to 27365 or 38785.
http://code.google.com/p/chromium-os/issues/detail?id=4126 BUG=chromium-os:4126 TEST=HtmlDialogBrowserTest.SizeWindow Review URL: http://codereview.chromium.org/2768006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/gtk_views_fixed.cc37
-rw-r--r--views/widget/gtk_views_fixed.h16
-rw-r--r--views/widget/widget_gtk.cc18
-rw-r--r--views/widget/widget_gtk.h5
4 files changed, 61 insertions, 15 deletions
diff --git a/views/widget/gtk_views_fixed.cc b/views/widget/gtk_views_fixed.cc
index 0b322bb..a2a3f2f 100644
--- a/views/widget/gtk_views_fixed.cc
+++ b/views/widget/gtk_views_fixed.cc
@@ -4,12 +4,16 @@
#include "views/widget/gtk_views_fixed.h"
+#include "base/logging.h"
+
// We store whether we use the widget's allocated size as a property. Ideally
// we would stash this in GtkFixedChild, but GtkFixed doesn't allow subclassing
// gtk_fixed_put. Alternatively we could subclass GtkContainer and use our own
// API (effectively duplicating GtkFixed), but that means folks could no longer
// use the GtkFixed API else where in Chrome. For now I'm going with this route.
static const char* kUseAllocatedSize = "__VIEWS_USE_ALLOCATED_SIZE__";
+static const char* kRequisitionWidth = "__VIEWS_REQUISITION_WIDTH__";
+static const char* kRequisitionHeight = "__VIEWS_REQUISITION_HEIGHT__";
G_BEGIN_DECLS
@@ -32,13 +36,14 @@ static void gtk_views_fixed_size_allocate(GtkWidget* widget,
if (GTK_WIDGET_VISIBLE(child->widget)) {
GtkAllocation child_allocation;
- gpointer use_allocated_size = g_object_get_data(G_OBJECT(child->widget),
- kUseAllocatedSize);
+ int width, height;
+ bool use_allocated_size =
+ gtk_views_fixed_get_widget_size(child->widget, &width, &height);
if (use_allocated_size) {
// NOTE: even though the size isn't changing, we have to call
// size_allocate, otherwise things like buttons won't repaint.
- child_allocation.width = child->widget->allocation.width;
- child_allocation.height = child->widget->allocation.height;
+ child_allocation.width = width;
+ child_allocation.height = height;
} else {
GtkRequisition child_requisition;
gtk_widget_get_child_requisition(child->widget, &child_requisition);
@@ -71,9 +76,29 @@ GtkWidget* gtk_views_fixed_new(void) {
return GTK_WIDGET(g_object_new(GTK_TYPE_VIEWS_FIXED, NULL));
}
-void gtk_views_fixed_set_use_allocated_size(GtkWidget* widget, bool value) {
+void gtk_views_fixed_set_widget_size(GtkWidget* widget,
+ int width, int height) {
+ // Remember the allocation request, and set this widget up to use it.
+ bool use_requested_size = (width != 0 && height != 0);
g_object_set_data(G_OBJECT(widget), kUseAllocatedSize,
- reinterpret_cast<gpointer>(value ? 1 : 0));
+ reinterpret_cast<gpointer>(use_requested_size ? 1 : 0));
+ g_object_set_data(G_OBJECT(widget), kRequisitionWidth,
+ reinterpret_cast<gpointer>(width));
+ g_object_set_data(G_OBJECT(widget), kRequisitionHeight,
+ reinterpret_cast<gpointer>(height));
+
+ gtk_widget_queue_resize(widget);
+}
+
+bool gtk_views_fixed_get_widget_size(GtkWidget* widget,
+ int* width, int* height) {
+ DCHECK(width);
+ DCHECK(height);
+ *width = reinterpret_cast<glong>(g_object_get_data(G_OBJECT(widget),
+ kRequisitionWidth));
+ *height = reinterpret_cast<glong>(g_object_get_data(G_OBJECT(widget),
+ kRequisitionHeight));
+ return (g_object_get_data(G_OBJECT(widget), kUseAllocatedSize) != 0);
}
G_END_DECLS
diff --git a/views/widget/gtk_views_fixed.h b/views/widget/gtk_views_fixed.h
index a03c67b..e9f3fe7 100644
--- a/views/widget/gtk_views_fixed.h
+++ b/views/widget/gtk_views_fixed.h
@@ -9,10 +9,11 @@
#include <gdk/gdk.h>
#include <gtk/gtkfixed.h>
-// GtkViewsFixed is a subclass of GtkFixed that can give child widgets their
-// current size rather than their requested size. This behavior is controlled
-// by gtk_views_fixed_set_use_allocated_size; the default is to use the
-// Widget's requested size.
+// GtkViewsFixed is a subclass of GtkFixed that can give child widgets
+// a set size rather than their requisitioned size (which is actually
+// a minimum size, and that can cause issues). This behavior is
+// controlled by gtk_views_fixed_set_widget_size; the default is to
+// use the Widget's requisitioned size.
G_BEGIN_DECLS
@@ -43,7 +44,12 @@ GtkWidget* gtk_views_fixed_new();
GType gtk_views_fixed_get_type();
-void gtk_views_fixed_set_use_allocated_size(GtkWidget* widget, bool value);
+// If width and height are 0, go back to using the requisitioned size.
+// Queues up a re-size on the widget.
+void gtk_views_fixed_set_widget_size(GtkWidget* widget, int width, int height);
+
+bool gtk_views_fixed_get_widget_size(GtkWidget* widget,
+ int* width, int* height);
G_END_DECLS
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 1f7afb2..f74eef13 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -331,7 +331,7 @@ void WidgetGtk::RemoveChild(GtkWidget* child) {
// closed.
if (GTK_IS_CONTAINER(window_contents_)) {
gtk_container_remove(GTK_CONTAINER(window_contents_), child);
- gtk_views_fixed_set_use_allocated_size(child, false);
+ gtk_views_fixed_set_widget_size(child, 0, 0);
}
}
@@ -340,9 +340,7 @@ void WidgetGtk::ReparentChild(GtkWidget* child) {
}
void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) {
- GtkAllocation alloc = { x, y, w, h };
- gtk_widget_size_allocate(child, &alloc);
- gtk_views_fixed_set_use_allocated_size(child, true);
+ gtk_views_fixed_set_widget_size(child, w, h);
gtk_fixed_move(GTK_FIXED(window_contents_), child, x, y);
}
@@ -429,6 +427,18 @@ RootView* WidgetGtk::GetRootViewForWidget(GtkWidget* widget) {
return static_cast<RootView*>(user_data);
}
+void WidgetGtk::GetRequestedSize(gfx::Size* out) const {
+ int width, height;
+ if (GTK_IS_VIEWS_FIXED(widget_) &&
+ gtk_views_fixed_get_widget_size(GetNativeView(), &width, &height)) {
+ out->SetSize(width, height);
+ } else {
+ GtkRequisition requisition;
+ gtk_widget_get_child_requisition(GetNativeView(), &requisition);
+ out->SetSize(requisition.width, requisition.height);
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// WidgetGtk, ActiveWindowWatcherX::Observer implementation:
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 7e1bdd1..7a2820e 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -149,6 +149,11 @@ class WidgetGtk
// Returns the RootView for |widget|.
static RootView* GetRootViewForWidget(GtkWidget* widget);
+ // Gets the requested size of the widget. This can be the size
+ // stored in properties for a GtkViewsFixed, or in the requisitioned
+ // size of other kinds of widgets.
+ void GetRequestedSize(gfx::Size* out) const;
+
// Overriden from ActiveWindowWatcherX::Observer.
virtual void ActiveWindowChanged(GdkWindow* active_window);