In article <[email protected]>,
   Lukasz Sromek <[email protected]> wrote:
> Hello everyone,

> I want to use libcss in my own project.

Cool.

> I tried my best to get it to work, but after two days of trying I'm
> stuck. I figured you guys could give me some helpful pointers on how to
> use your lib.

>From LibCSS's point of view, stylesheets are just opaque collections of
selectors and associated property descriptors.  Unfortunately there isn't
a proper example of how to use the library at the moment, which is
something we should address.

[snip example]

> style_text is some example css file body. I think it is parsed correctly
> (I get CSS_NEEDDATA as a result of css_stylesheet_append_data), but I
> have no idea how to actually get the parsed data? How to read
> background-color of the body element? Do I have to somehow convert
> css_stylesheet to css_computed style?

You need to create a selection context.  So you need to:

  + Create a selection context.
  + Add stylesheet(s) to it.

Then:

  + Create blank computed style for the element you're selecting for.
  + Select style for the element using the selection context, the
    blank computed style for the element, and the DOM node handlers.

Finally:

  + Cleanup.

Note that the order that the style sheets are added can have an effect on
the eventual computed style for the element, as it affects the cascade (as
per the CSS spec).

Once you have performed the selection for an element, then the computed
style for it is populated with the style info.  You can find out the the
value of any property using the appropriate function from computed.h.

For example: to get the background-color of the element, call
css_computed_background_color() with the element's computed style.

You shouldn't ever use the content of a computed style directly yourself,
but rather use the functions in computed.h to get property values.  The
computed style is in a compact bytecode to reduce memory usage.

> Could you please give me some hints?

I hope that helps.  Currently the simplest example of it is probably
run_test() in test/select-auto.c. 

Sorry it took a while for someone to reply.  If you have further queries,
don't hesitate to ask.

-- 

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


Reply via email to