summaryrefslogtreecommitdiff
path: root/src/cr-cascade.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cr-cascade.c')
-rw-r--r--src/cr-cascade.c188
1 files changed, 81 insertions, 107 deletions
diff --git a/src/cr-cascade.c b/src/cr-cascade.c
index a9b579b..ccb32c2 100644
--- a/src/cr-cascade.c
+++ b/src/cr-cascade.c
@@ -31,19 +31,17 @@
#define PRIVATE(a_this) ((a_this)->priv)
-struct _CRCascadePriv
-{
- /**
+struct _CRCascadePriv {
+ /**
*the 3 style sheets of the cascade:
*author, user, and useragent sheet.
*Intended to be addressed by
*sheets[ORIGIN_AUTHOR] or sheets[ORIGIN_USER]
*of sheets[ORIGIN_UA] ;
*/
- CRStyleSheet *sheets[3] ;
- guint ref_count ;
-} ;
-
+ CRStyleSheet *sheets[3];
+ guint ref_count;
+};
/**
*Constructor of the #CRCascade class.
@@ -60,45 +58,36 @@ struct _CRCascadePriv
*an error arose during constrution.
*/
CRCascade *
-cr_cascade_new (CRStyleSheet *a_author_sheet,
- CRStyleSheet *a_user_sheet,
- CRStyleSheet *a_ua_sheet)
+cr_cascade_new (CRStyleSheet * a_author_sheet,
+ CRStyleSheet * a_user_sheet, CRStyleSheet * a_ua_sheet)
{
- CRCascade *result = NULL ;
-
- result = g_try_malloc (sizeof (CRCascade)) ;
- if (!result)
- {
- cr_utils_trace_info ("Out of memory") ;
- return NULL ;
- }
- memset (result, 0, sizeof (CRCascade)) ;
-
- PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv)) ;
- if (!PRIVATE (result))
- {
- cr_utils_trace_info ("Out of memory") ;
- return NULL ;
- }
- memset (PRIVATE (result), 0, sizeof (CRCascadePriv)) ;
-
- if (a_author_sheet)
- {
- cr_cascade_set_sheet (result, a_author_sheet,
- ORIGIN_AUTHOR) ;
- }
- if (a_user_sheet)
- {
- cr_cascade_set_sheet (result, a_user_sheet,
- ORIGIN_USER) ;
- }
- if (a_ua_sheet)
- {
- cr_cascade_set_sheet (result, a_ua_sheet,
- ORIGIN_UA) ;
- }
-
- return result ;
+ CRCascade *result = NULL;
+
+ result = g_try_malloc (sizeof (CRCascade));
+ if (!result) {
+ cr_utils_trace_info ("Out of memory");
+ return NULL;
+ }
+ memset (result, 0, sizeof (CRCascade));
+
+ PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv));
+ if (!PRIVATE (result)) {
+ cr_utils_trace_info ("Out of memory");
+ return NULL;
+ }
+ memset (PRIVATE (result), 0, sizeof (CRCascadePriv));
+
+ if (a_author_sheet) {
+ cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR);
+ }
+ if (a_user_sheet) {
+ cr_cascade_set_sheet (result, a_user_sheet, ORIGIN_USER);
+ }
+ if (a_ua_sheet) {
+ cr_cascade_set_sheet (result, a_ua_sheet, ORIGIN_UA);
+ }
+
+ return result;
}
/**
@@ -115,18 +104,15 @@ cr_cascade_new (CRStyleSheet *a_author_sheet,
*exist.
*/
CRStyleSheet *
-cr_cascade_get_sheet (CRCascade *a_this,
- enum CRStyleOrigin a_origin)
+cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin)
{
- g_return_val_if_fail (a_this
- && a_origin >= ORIGIN_UA
- && a_origin < NB_ORIGINS,
- NULL) ;
+ g_return_val_if_fail (a_this
+ && a_origin >= ORIGIN_UA
+ && a_origin < NB_ORIGINS, NULL);
- return PRIVATE (a_this)->sheets[a_origin] ;
+ return PRIVATE (a_this)->sheets[a_origin];
}
-
/**
*Sets a stylesheet in the cascade
*@param a_this the current instance of #CRCascade.
@@ -136,23 +122,20 @@ cr_cascade_get_sheet (CRCascade *a_this,
*code otherwise.
*/
enum CRStatus
-cr_cascade_set_sheet (CRCascade *a_this,
- CRStyleSheet *a_sheet,
- enum CRStyleOrigin a_origin)
+cr_cascade_set_sheet (CRCascade * a_this,
+ CRStyleSheet * a_sheet, enum CRStyleOrigin a_origin)
{
- g_return_val_if_fail (a_this
- && a_sheet
- && a_origin >= ORIGIN_UA
- && a_origin < NB_ORIGINS,
- CR_BAD_PARAM_ERROR) ;
-
- if (PRIVATE (a_this)->sheets[a_origin])
- cr_stylesheet_unref
- (PRIVATE (a_this)->sheets[a_origin]) ;
- PRIVATE (a_this)->sheets[a_origin] = a_sheet ;
- cr_stylesheet_ref (a_sheet) ;
- a_sheet->origin = a_origin ;
- return CR_OK ;
+ g_return_val_if_fail (a_this
+ && a_sheet
+ && a_origin >= ORIGIN_UA
+ && a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR);
+
+ if (PRIVATE (a_this)->sheets[a_origin])
+ cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]);
+ PRIVATE (a_this)->sheets[a_origin] = a_sheet;
+ cr_stylesheet_ref (a_sheet);
+ a_sheet->origin = a_origin;
+ return CR_OK;
}
/**
@@ -162,11 +145,11 @@ cr_cascade_set_sheet (CRCascade *a_this,
*
*/
void
-cr_cascade_ref (CRCascade *a_this)
+cr_cascade_ref (CRCascade * a_this)
{
- g_return_if_fail (a_this && PRIVATE (a_this)) ;
-
- PRIVATE (a_this)->ref_count++ ;
+ g_return_if_fail (a_this && PRIVATE (a_this));
+
+ PRIVATE (a_this)->ref_count++;
}
/**
@@ -177,16 +160,15 @@ cr_cascade_ref (CRCascade *a_this)
*@param a_this the current instance of
*#CRCascade.
*/
-void
-cr_cascade_unref (CRCascade *a_this)
+void
+cr_cascade_unref (CRCascade * a_this)
{
- g_return_if_fail (a_this && PRIVATE (a_this)) ;
+ g_return_if_fail (a_this && PRIVATE (a_this));
if (PRIVATE (a_this)->ref_count)
- PRIVATE (a_this)->ref_count -- ;
- if (!PRIVATE (a_this)->ref_count)
- {
- cr_cascade_destroy (a_this) ;
+ PRIVATE (a_this)->ref_count--;
+ if (!PRIVATE (a_this)->ref_count) {
+ cr_cascade_destroy (a_this);
}
}
@@ -194,32 +176,24 @@ cr_cascade_unref (CRCascade *a_this)
*Destructor of #CRCascade.
*/
void
-cr_cascade_destroy (CRCascade *a_this)
+cr_cascade_destroy (CRCascade * a_this)
{
- g_return_if_fail (a_this) ;
-
- if (PRIVATE (a_this))
- {
- gulong i = 0 ;
-
- for (i = 0 ;
- PRIVATE (a_this)->sheets
- && i < NB_ORIGINS ;
- i++)
- {
- if (PRIVATE (a_this)->sheets[i])
- {
- if (cr_stylesheet_unref
- (PRIVATE (a_this)->sheets[i])
- == TRUE)
- {
- PRIVATE (a_this)->sheets[i] =
- NULL ;
- }
- }
- }
- g_free (PRIVATE (a_this)) ;
- PRIVATE (a_this) = NULL ;
- }
- g_free (a_this) ;
+ g_return_if_fail (a_this);
+
+ if (PRIVATE (a_this)) {
+ gulong i = 0;
+
+ for (i = 0; PRIVATE (a_this)->sheets && i < NB_ORIGINS; i++) {
+ if (PRIVATE (a_this)->sheets[i]) {
+ if (cr_stylesheet_unref
+ (PRIVATE (a_this)->sheets[i])
+ == TRUE) {
+ PRIVATE (a_this)->sheets[i] = NULL;
+ }
+ }
+ }
+ g_free (PRIVATE (a_this));
+ PRIVATE (a_this) = NULL;
+ }
+ g_free (a_this);
}