diff options
author | Dodji Seketeli <dodji@src.gnome.org> | 2003-05-05 22:44:04 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-05-05 22:44:04 +0000 |
commit | cca5c1f335c380ad6bfcbbc8fe29022b646376d6 (patch) | |
tree | 0d6895a066db0bf7186c37aac364a684968ebd42 | |
parent | 80919cfd996be5bc05d4ef2f33022225f7ae0f52 (diff) | |
download | libcroco-cca5c1f335c380ad6bfcbbc8fe29022b646376d6.tar.gz |
started to add the support of the "color" and "background-color"
* src/layeng/cr-style.[ch]: started to add the support of
the "color" and "background-color" properties.
* src/layeng/cr-lay-eng.c:
(style_specified_2_computed_value()) updated this function to
compute also the new colors properties (color and background-color).
* src/layeng/cr-box-view.c:
(set_background_color ())
(set_foreground_color ())added these functions to set the box
inner/padding edge color.
also started to use these two functions to test them.
Dodji.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | src/layeng/cr-box-view.c | 89 | ||||
-rw-r--r-- | src/layeng/cr-lay-eng.c | 6 | ||||
-rw-r--r-- | src/layeng/cr-style.c | 99 | ||||
-rw-r--r-- | src/layeng/cr-style.h | 12 |
6 files changed, 208 insertions, 21 deletions
@@ -1,3 +1,18 @@ +2003-05-06 Dodji <dodji@seketeli.org> + + * src/layeng/cr-style.[ch]: started to add the support of + the "color" and "background-color" properties. + + * src/layeng/cr-lay-eng.c: + (style_specified_2_computed_value()) updated this function to + compute also the new colors properties (color and background-color). + + * src/layeng/cr-box-view.c: + (set_background_color ()) + (set_foreground_color ())added these functions to set the box + inner/padding edge color. + also started to use these two functions to test them. + 2003-05-05 Dodji <dodji@seketeli.org> * tests/test7-main.c: small update for debug purposes. @@ -3,9 +3,11 @@ Go forward in the box layout (positioning) code. (hard, very hard). This is gonna take me a coupe of months I think. - Implement the style properties (of the 4 edges of the box model. - Start by implementing the border-color-x prop. - Make sure not to systematically hardwire the drawing of the 4 edges. + Implement the style properties (of the 4 edges of the box model). + implementing the border-color-x prop. + Make sure not to systematically hardwire the sadly drawing of + padding edge. + *Doc:) diff --git a/src/layeng/cr-box-view.c b/src/layeng/cr-box-view.c index ab237de..84aa20e 100644 --- a/src/layeng/cr-box-view.c +++ b/src/layeng/cr-box-view.c @@ -33,7 +33,18 @@ struct _CRBoxViewPriv { CRBoxModel *box_model ; + /* + *The default graphical context + *Function willing to modify this gc + *should save it firts, then modify it, + *draw what they have to draw and then restore it !! + */ GdkGC *gc ; + + /** + * a boolean used by some drawing functions. + *greping PRIVATE (a_this)->draw should tell you who uses it :) + */ gboolean draw ; } ; @@ -229,6 +240,76 @@ set_border_line_attrs (CRBoxView *a_this, return CR_OK ; } + +static enum CRStatus +set_background_color (CRBoxView *a_this, CRBox *a_box) +{ + g_return_val_if_fail (a_this && a_box, CR_BAD_PARAM_ERROR) ; + + /* + *this code is inspired by gtkhtml2's set_foreground_color()'s code + *in htmlgdkpainter.c + */ + if (a_box->style) + { + GdkColor gdk_color ; + CRRgb *rgb_color = &a_box->style-> + rgb_props[RGB_PROP_BACKGROUND_COLOR].cv ; + + gdk_color.red = (rgb_color->red << 8) | rgb_color->red ; + gdk_color.green = (rgb_color->green << 8) | rgb_color->green ; + gdk_color.blue = (rgb_color->blue << 8) | rgb_color->blue ; + + gdk_rgb_find_color + (gdk_drawable_get_colormap + (GDK_DRAWABLE (GTK_LAYOUT (a_this)->bin_window)), + &gdk_color) ; + + gdk_gc_set_background (PRIVATE (a_this)->gc, &gdk_color) ; + } + + return CR_OK ; +} + +static enum CRStatus +set_foreground_color (CRBoxView *a_this, CRBox *a_box) +{ + g_return_val_if_fail (a_this && a_box, CR_BAD_PARAM_ERROR) ; + + /* + *this code is inspired by gtkhtml2's set_foreground_color()'s code + *in htmlgdkpainter.c + */ + if (a_box->style) + { + GdkColor gdk_color ; + CRRgb *rgb_color = &a_box->style-> + rgb_props[RGB_PROP_COLOR].cv ; + + gdk_color.red = (rgb_color->red << 8) | rgb_color->red ; + gdk_color.green = (rgb_color->green << 8) | rgb_color->green ; + gdk_color.blue = (rgb_color->blue << 8) | rgb_color->blue ; + + gdk_rgb_find_color + (gdk_drawable_get_colormap + (GDK_DRAWABLE (GTK_LAYOUT (a_this)->bin_window)), + &gdk_color) ; + + gdk_gc_set_foreground (PRIVATE (a_this)->gc, &gdk_color) ; + } + + return CR_OK ; +} + +/** + *Draws the margin rectangle. + *Note: This is only for debug purpose because + *margins are always transparent. + *@param a_this the bow view to draw on. + *@param a_box the box to draw. + *@return CR_OK upon successfull completion, an error code + *otherwise. + */ static enum CRStatus draw_margins (CRBoxView *a_this, CRBox *a_box) @@ -242,7 +323,7 @@ draw_margins (CRBoxView *a_this, && CR_IS_BOX_VIEW (a_this) && a_box, CR_BAD_PARAM_ERROR) ; - + widget = GTK_WIDGET (a_this) ; window = GTK_LAYOUT (a_this)->bin_window ; g_return_val_if_fail (window, CR_ERROR) ; @@ -278,7 +359,6 @@ draw_margins (CRBoxView *a_this, FALSE, rect.x, rect.y, rect.width, rect.height) ; - /* *draw top margin rectangle. */ @@ -423,6 +503,9 @@ draw_paddings (CRBoxView *a_this, box = a_box ; g_return_val_if_fail (box, CR_ERROR) ; + set_background_color (a_this, a_box) ; + set_foreground_color (a_this, a_box) ; + /* *draw the left padding */ @@ -554,7 +637,7 @@ draw_box (CRBoxView *a_this, for (cur_box = a_box; cur_box ; cur_box = cur_box->next) { - draw_margins (a_this, cur_box) ; + /*draw_margins (a_this, cur_box) ;*/ draw_borders (a_this, cur_box) ; draw_paddings (a_this, cur_box) ; draw_inner_box (a_this, cur_box) ; diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c index 4002a7e..a5db5b2 100644 --- a/src/layeng/cr-lay-eng.c +++ b/src/layeng/cr-lay-eng.c @@ -435,6 +435,12 @@ style_specified_2_computed_values (CRLayEng *a_this, } } + for (i = 0 ; i < NB_RGB_PROPS; i++) + { + cr_rgb_set_from_rgb (&a_style->rgb_props[i].cv, + &a_style->rgb_props[i].sv) ; + } + /************************************* *Now compute the specific css2 specification recommendations. *This can seem ugly, but it needs to be done. I do it here untill diff --git a/src/layeng/cr-style.c b/src/layeng/cr-style.c index bf125a8..83b2d55 100644 --- a/src/layeng/cr-style.c +++ b/src/layeng/cr-style.c @@ -36,15 +36,15 @@ /** *A property ID. - *Each css property has an ID which is - *en entry into a property "population" jump table. + *Each supported css property has an ID which is + *an entry into a property "population" jump table. *each entry of the property population jump table *contains code to tranform the literal form of *a property value into a strongly typed value. */ enum CRPropertyID { - PROP_ID_NOT_KNOWN, + PROP_ID_NOT_KNOWN = 0, PROP_ID_PADDING_TOP, PROP_ID_PADDING_RIGHT, PROP_ID_PADDING_BOTTOM, @@ -68,7 +68,12 @@ enum CRPropertyID PROP_ID_BOTTOM, PROP_ID_LEFT, PROP_ID_FLOAT, - PROP_ID_WIDTH + PROP_ID_WIDTH, + PROP_ID_COLOR, + PROP_ID_BACKGROUND_COLOR, + + /*should be the last one.*/ + NB_PROP_IDS } ; @@ -107,7 +112,11 @@ static CRPropertyDesc gv_prop_table [] = {"left", PROP_ID_LEFT}, {"float", PROP_ID_FLOAT}, {"width", PROP_ID_WIDTH}, - {NULL, 0} + {"color", PROP_ID_COLOR}, + {"background-color", PROP_ID_BACKGROUND_COLOR}, + + /*must be the last one*/ + {NULL, 0} } ; /** @@ -243,7 +252,7 @@ cr_style_set_props_to_defaults (CRStyle *a_this) case NUM_PROP_MARGIN_TOP: case NUM_PROP_MARGIN_RIGHT: case NUM_PROP_MARGIN_BOTTOM: - case NUM_PROP_MARGIN_LEFT: + case NUM_PROP_MARGIN_LEFT: cr_num_set (&a_this->num_props[i].sv, 0, NUM_LENGTH_PX) ; break ; @@ -256,9 +265,26 @@ cr_style_set_props_to_defaults (CRStyle *a_this) for (i = 0 ; i < NB_RGB_PROPS ; i++) { - /*default color is black*/ - cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, - FALSE) ; + + switch (i) + { + /*default foreground color is black*/ + case RGB_PROP_COLOR: + cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, + FALSE) ; + break ; + + /*default background color is white*/ + case RGB_PROP_BACKGROUND_COLOR: + cr_rgb_set (&a_this->rgb_props[i].sv, + 255, 255, 255, FALSE) ; + break ; + + default: + cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, + FALSE) ; + break ; + } } for (i = 0 ; i < NB_BORDER_STYLE_PROPS ; i++) @@ -1005,7 +1031,8 @@ set_prop_width (CRStyle *a_style, CRTerm *a_value) a_value->content.str->str, strlen ("auto"))) { - a_style->num_props[NUM_PROP_WIDTH].sv.type = NUM_AUTO ; + a_style->num_props[NUM_PROP_WIDTH].sv.type = + NUM_AUTO ; } else if (!strncmp ("inherit", a_value->content.str->str, @@ -1031,6 +1058,50 @@ set_prop_width (CRStyle *a_style, CRTerm *a_value) return CR_OK ; } +static enum CRStatus +set_prop_color (CRStyle *a_style, CRTerm *a_value) +{ + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + if (a_value->type == TERM_RGB) + { + if (a_value->content.rgb) + { + cr_rgb_set_from_rgb + (&a_style->rgb_props[RGB_PROP_COLOR].sv, + a_value->content.rgb) ; + } + + } + + return CR_OK ; +} + +static enum CRStatus +set_prop_background_color (CRStyle *a_style, CRTerm *a_value) +{ + g_return_val_if_fail (a_style && a_value, + CR_BAD_PARAM_ERROR) ; + + if (a_value->type == TERM_RGB) + { + if (a_value->content.rgb) + { + cr_rgb_set_from_rgb + (&a_style-> + rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, + a_value->content.rgb) ; + } + } + + return CR_OK ; +} + + +/****************** + *Public methods + ******************/ /** *Default constructor of #CRStyle. @@ -1282,8 +1353,16 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl, status = set_prop_width (a_this, value) ; break ; + case PROP_ID_COLOR: + status = set_prop_color (a_this, value) ; + break ; + + case PROP_ID_BACKGROUND_COLOR: + status = set_prop_background_color (a_this, value) ; + default: return CR_UNKNOWN_TYPE_ERROR ; + } return status ; diff --git a/src/layeng/cr-style.h b/src/layeng/cr-style.h index ff2e331..6c45c84 100644 --- a/src/layeng/cr-style.h +++ b/src/layeng/cr-style.h @@ -164,10 +164,12 @@ enum CRNumProp enum CRRgbProp { - RGB_PROP_TOP_COLOR = 0, - RGB_PROP_RIGHT_COLOR, - RGB_PROP_BOTTOM_COLOR, - RGB_PROP_LEFT_COLOR, + RGB_PROP_BORDER_TOP_COLOR = 0, + RGB_PROP_BORDER_RIGHT_COLOR, + RGB_PROP_BORDER_BOTTOM_COLOR, + RGB_PROP_BORDER_LEFT_COLOR, + RGB_PROP_COLOR, + RGB_PROP_BACKGROUND_COLOR, /*must be last*/ NB_RGB_PROPS @@ -180,7 +182,7 @@ enum CRBorderStyleProp BORDER_STYLE_PROP_RIGHT, BORDER_STYLE_PROP_BOTTOM, BORDER_STYLE_PROP_LEFT, - + /*must be last*/ NB_BORDER_STYLE_PROPS } ; |