forked from AuroraMiddleware/gtk
sizerequest: Cache the request mode
... in the GtkSizeRequestCache. That way, we only need to query it once, and can remove the caching code from GtkContainer.
This commit is contained in:
parent
c98ee1ec39
commit
c08efb2b32
@ -42,6 +42,7 @@
|
||||
#include "gtkmain.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtksizerequest.h"
|
||||
#include "gtksizerequestcacheprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkwindow.h"
|
||||
#include "gtkassistant.h"
|
||||
@ -1755,6 +1756,7 @@ _gtk_container_queue_resize_internal (GtkContainer *container,
|
||||
_gtk_widget_set_alloc_needed (widget, TRUE);
|
||||
_gtk_widget_set_width_request_needed (widget, TRUE);
|
||||
_gtk_widget_set_height_request_needed (widget, TRUE);
|
||||
_gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget));
|
||||
|
||||
if (GTK_IS_RESIZE_CONTAINER (widget))
|
||||
break;
|
||||
@ -1968,27 +1970,17 @@ count_request_modes (GtkWidget *widget,
|
||||
static GtkSizeRequestMode
|
||||
gtk_container_get_request_mode (GtkWidget *widget)
|
||||
{
|
||||
GtkContainer *container = GTK_CONTAINER (widget);
|
||||
GtkContainerPrivate *priv = container->priv;
|
||||
GtkContainer *container = GTK_CONTAINER (widget);
|
||||
RequestModeCount count = { 0, 0 };
|
||||
|
||||
/* Recalculate the request mode of the children by majority
|
||||
* vote whenever the internal content changes */
|
||||
if (_gtk_widget_get_width_request_needed (widget) ||
|
||||
_gtk_widget_get_height_request_needed (widget))
|
||||
{
|
||||
RequestModeCount count = { 0, 0 };
|
||||
gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
|
||||
|
||||
gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
|
||||
|
||||
if (!count.hfw && !count.wfh)
|
||||
priv->request_mode = GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
||||
else
|
||||
priv->request_mode = count.wfh > count.hfw ?
|
||||
GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
|
||||
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
||||
}
|
||||
|
||||
return priv->request_mode;
|
||||
if (!count.hfw && !count.wfh)
|
||||
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
||||
else
|
||||
return count.wfh > count.hfw ?
|
||||
GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
|
||||
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtksizegroup-private.h"
|
||||
#include "gtksizerequestcacheprivate.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtkcontainerprivate.h"
|
||||
|
||||
@ -198,6 +199,7 @@ real_queue_resize (GtkWidget *widget,
|
||||
_gtk_widget_set_alloc_needed (widget, TRUE);
|
||||
_gtk_widget_set_width_request_needed (widget, TRUE);
|
||||
_gtk_widget_set_height_request_needed (widget, TRUE);
|
||||
_gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget));
|
||||
|
||||
container = gtk_widget_get_parent (widget);
|
||||
if (!container &&
|
||||
|
@ -84,24 +84,6 @@ pop_recursion_check (GtkWidget *widget,
|
||||
}
|
||||
|
||||
|
||||
/* This function checks if 'request_needed' flag is present
|
||||
* and resets the cache state if a request is needed for
|
||||
* a given orientation.
|
||||
*/
|
||||
static SizeRequestCache *
|
||||
init_cache (GtkWidget *widget)
|
||||
{
|
||||
SizeRequestCache *cache;
|
||||
|
||||
cache = _gtk_widget_peek_request_cache (widget);
|
||||
|
||||
if (_gtk_widget_get_width_request_needed (widget) ||
|
||||
_gtk_widget_get_height_request_needed (widget))
|
||||
_gtk_size_request_cache_clear (cache);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
/* looks for a cached size request for this for_size. If not
|
||||
* found, returns the oldest entry so it can be overwritten
|
||||
*
|
||||
@ -118,7 +100,7 @@ get_cached_size (GtkWidget *widget,
|
||||
SizeRequest **cached_sizes;
|
||||
guint i, n_sizes;
|
||||
|
||||
cache = init_cache (widget);
|
||||
cache = _gtk_widget_peek_request_cache (widget);
|
||||
|
||||
if (for_size < 0)
|
||||
{
|
||||
@ -507,9 +489,19 @@ _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
|
||||
GtkSizeRequestMode
|
||||
gtk_widget_get_request_mode (GtkWidget *widget)
|
||||
{
|
||||
SizeRequestCache *cache;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_CONSTANT_SIZE);
|
||||
|
||||
return GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
|
||||
cache = _gtk_widget_peek_request_cache (widget);
|
||||
|
||||
if (!cache->request_mode_valid)
|
||||
{
|
||||
cache->request_mode = GTK_WIDGET_GET_CLASS (widget)->get_request_mode (widget);
|
||||
cache->request_mode_valid = TRUE;
|
||||
}
|
||||
|
||||
return cache->request_mode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@
|
||||
#define __GTK_SIZE_REQUEST_CACHE_PRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtkenums.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -56,6 +57,8 @@ typedef struct {
|
||||
CachedSize cached_width;
|
||||
CachedSize cached_height;
|
||||
|
||||
GtkSizeRequestMode request_mode: 3;
|
||||
guint request_mode_valid : 1;
|
||||
guint cached_widths : 3;
|
||||
guint cached_heights : 3;
|
||||
guint last_cached_width : 3;
|
||||
|
Loading…
Reference in New Issue
Block a user