koreader / crengine

This is the KOReader CREngine fork. It cross-pollinates with the official CoolReader repository at https://github.com/buggins/coolreader, in case you were looking for that one.
70 stars 45 forks source link

CSS: add support for :is(), :where() and :not() pseudoclasses, fix CSS cascade, and other fixes #552

Closed poire-z closed 7 months ago

poire-z commented 7 months ago

Fix getToc() not cached on initial loading

getToc() is usually called once and cached by frontend, but cre.cpp's footnote popup feature may call it multiple times to check if a link is a footnote candidate, which could be expensive if not cached if the ToC is huge. See https://github.com/koreader/koreader/issues/11254#issuecomment-1872200759 Should allow closing https://github.com/koreader/koreader/issues/11254.

CSS: add support for forgotten border-style: hidden

Just so it is not ignored and we get no border displayed. Should behave as none (except on table, where it still behave as none but gets a higher priority than table cells' border when table collapse - that we don't ensure). (border-style: hidden is actually used in our html5.css.)

CSS: fix parsing of div :something and div [attr]

Fix very old oversight, since when we added support for attribute check and pseudoclasses, not having them working with ancestor rules (we were properly handling div .something and div #something).

CSS: fix checking E[foo~="value"]

It wouldn't check other "words" in the attribute: p[class~=foo] didn't match <p class="fooz foo">. Similar logic as for checking classname in a5c046c1.

CSS: order rules as written when building a selector

Keep consecutive current node check rules ordered as written when building a selector, instead of putting them always at start (only parent/ancestor/sibling checks need to put the following rule at start). The stylesheet author may intuitively write them with quicker checks first, and complex ones last, ie.: table.mytab[rules]:not([rules="none"]

CSS: fix useragent vs. author stylesheet CSS cascade

Introduce another stylesheet object in the document to hold the useragent sheet, to be applied before the author stylesheets. Per-CSS-specs, these are 2 "origins", and selectors shouldn't be mixed and ordered by relative specificity. Ie, this high specificity selector in the useragent sheet: table[align="right"] { float: right; } shouldn't result in such tables floating when an author stylesheet has one of these lower specificity selectors: table { float: none; } or * { float: none; } More details in https://github.com/koreader/crengine/issues/551#issue-2069127892. Reference: https://www.w3.org/TR/css-cascade-3/#cascading

CSS: pass useragent_sheet flag all along parse() code

So we can if needed support some private CSS syntax only for the useragent stylesheet and user style tweaks.

CSS: add private selector syntax to match against text

Allows classic attribute selectors (ie. [foo*=value i]), when the attribute name is _ (ie. [_*="some text" i]), to match against the node full inner text. Only allow this syntax when parsing the useragent stylesheet, to avoid unexpected results with author stylesheets. Might be handy with style tweaks, when the book has not enough classes distinctions to target what we want. Proposed at https://github.com/koreader/koreader/issues/11323, see some screenshots showing what this new trick could allow..

CSS: add support for :is(), :where() and :not() pseudoclasses

Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes#functional_pseudo-classes (No support for :has(), which would be a lot more complicated.)

EPUB: don't ignore any <spine> item

We were only accepting <spine> items which are declared with media-type="application/xhtml+xml. Assume all items in the <spine> are content and should have a <DocFragment>, even if unsupported or if parsing failed. Also add support for SVG items in the spine. Bump DOM_VERSION_CURRENT to 20240114 to have this change only done on new books, so old xpointers are not messed up. See https://github.com/koreader/koreader/issues/11268#issuecomment-1887141078 Should allow closing https://github.com/koreader/koreader/issues/11268.

bump CACHE_FILE_FORMAT_VERSION

Necessary with the previous commits. Also add to the hardcoded element lists some tag names that can be seen in HTML standard and Firefox stylesheets.


This change is Reviewable

poire-z commented 7 months ago

Pinging @bbshelper for info/quick review.