extending libcss through properties.gen

Michael Drake tlsa at netsurf-browser.org
Tue May 21 12:37:46 BST 2013


In article <6E64952A914E43E6B743E3CBCDF54ADA at gmail.com>,
   Hoà V. Dinh <dinh.viet.hoa at gmail.com> wrote:

> I'd like to extend libcss to parse additional CSS properties

The first thing to do is to define the byte code for the properties you
want to add.  See docs/Bytecode:

  http://source.netsurf-browser.org/libcss.git/tree/docs/Bytecode

Then there's two parts to adding support for a property.  You need the
code to parse the property into bytecode, in src/parse/, and the code to
handle selection (cascade, computed value calculation, etc of the
property), in src/select/.

Here are some examples:

Adding new properties to the parser:

http://source.netsurf-browser.org/libcss.git/commit/?id=32ed7d0984f0dd872b4aaac0ac12c18471f291a0

Adding new shorthand properties to the parser:

http://source.netsurf-browser.org/libcss.git/commit/?id=bd8ef0f5e2ec383b528b825eba4724b90643cbef

Note that the shorthand properties just set the values for other
properties, so they don't have their own bytecode.

Adding new properties to the selection engine:

http://source.netsurf-browser.org/libcss.git/commit/?id=89ef7a8acf13143ac0283aa1cfa5ea504b92324b


> such as border-radius. I'd also like to add overflow-x, overflow-y.
> "overflow" is implemented but not -x, -y variants.

You need to know and understand the spec.  Note that the overflow-x and -y
properties are still at an early draft stage.  Also, the overflow property
has to change from an actual property to a shorthand property that sets
the values for both overflow-x and -y.

> I had a quick look at the following file:
> libcss/src/parse/properties/properties.gen But I couldn't figure quite
> right what was the syntax of this file even with the whole list of
> examples.  Could you help me figure out?

Sure.  It's easier to follow once you come up with the byte code.

Taking the overflow one as an example:

overflow:CSS_PROP_OVERFLOW IDENT:( INHERIT: VISIBLE:0,OVERFLOW_VISIBLE
HIDDEN:0,OVERFLOW_HIDDEN SCROLL:0,OVERFLOW_SCROLL AUTO:0,OVERFLOW_AUTO 
IDENT:)

"overflow" is the property, which is used for the file/function name of
the generated parser.

"CSS_PROP_OVERFLOW" is the css_properties_e enum value from
include/libcss/properties.h  Note enum the value is the number of the
bytecode for the property.

Then in the brackets, you have INHERIT: because the property may be
inherited.

And then a list of the other values the property may take.

So VISIBLE:0,OVERFLOW_VISIBLE means if the value matches the VISIBLE
string defined in parser/propstrings.{c|h}, then set the property to the
enum value OVERFLOW_VISIBLE which is in src/bytecode/opcodes.h.  That
opcodes enum is set up according to the bytecode design in docs/Bytecode. 
The 0 is for the flags, a part of the bytecode.  That's always 0.

Anyway, given the state of the spec, especially ISSUE 1, I'd be tempted
not to add supprt for the paged-* and fragments values at this stage.  So
in that case, you just need to rename the overflow property handler to
overflow-x, add an overflow-y which behaves the same, add a parser for the
shorthand overflow property, and update the selection code to handle the
two overflow-x and overflow-y properties instead of overflow.

-- 

Michael Drake (tlsa)                  http://www.netsurf-browser.org/



More information about the netsurf-dev mailing list