radkovo / jStyleParser

jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.
http://cssbox.sourceforge.net/jstyleparser/
GNU Lesser General Public License v3.0
92 stars 49 forks source link

support `transparent` color keyword #45

Closed hrj closed 8 years ago

hrj commented 8 years ago

Quoting from CSS3-color spec:

CSS1 introduced the ‘transparent’ value for the background-color property. CSS2 allowed border-color to also accept the ‘transparent’ value. The Open eBook(tm) Publication Structure 1.0.1 [OEB101] extended the ‘color’ property to also accept the ‘transparent’ keyword. CSS3 extends the color value to include the ‘transparent’ keyword to allow its use with all properties that accept a value. This simplifies the definition of those properties in CSS3.

Some of the CSS tests depend on it. For example, this test

Currently, jStyleParser doesn't recognize transparent as a value in the node data; it has to be accessed as a property. I am not sure if this is intentional; but I think it causes unnecessary overhead: because the client code has to first try getting a value, and if null, then try getting the property. I can see a noticeable slowdown (30%) in the tests.

radkovo commented 8 years ago

It seems to me that the transparent keyword is already supported by the parser for all the background-color, border-color and color properties. However, the expected way of retrieving the style is the following:

I believe this behavior is consistent for all the properties (see vertical-align or font-size for a typical example). In some cases, we could map the keyword to some resulting value as well but generally, the exact behavior should be implemented by the client application. E.g. with the background-color property, it makes sense not to paint the background at all instead of using a transparent color.

hrj commented 8 years ago

Ah ok.. We couldn't use the NodeData API to its full extent in gngr, because we are accessing it through multiple layers: the CSS OM api and our own internal RenderState API. And at that time, we took a simpler path of just brute-force trying the getValue() first, followed by getProperty().

Will have a deeper look at this on our side; thanks!