mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
LibWeb: Apply style rules in order of specificity (kinda)
We now sort the matched rules by the specificity of the first selector in them. This is not perfect, since a rule can have multiple selectors, but it is a nice chin-related progression on ACID2. :^)
This commit is contained in:
parent
4e1939c635
commit
7fe2f5f170
2 changed files with 11 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibWeb/CSS/SelectorEngine.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/CSS/StyleSheet.h>
|
||||
|
@ -439,6 +440,13 @@ NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& eleme
|
|||
element.apply_presentational_hints(*style);
|
||||
|
||||
auto matching_rules = collect_matching_rules(element);
|
||||
|
||||
// FIXME: We need to look at the specificity of the matching *selector*, not just the matched *rule*!
|
||||
// FIXME: It's really awkward that NonnullRefPtrVector cannot be quick_sort()'ed
|
||||
quick_sort(reinterpret_cast<Vector<NonnullRefPtr<StyleRule>>&>(matching_rules), [&](auto& a, auto& b) {
|
||||
return a->selectors().first().specificity() < b->selectors().first().specificity();
|
||||
});
|
||||
|
||||
for (auto& rule : matching_rules) {
|
||||
for (auto& property : rule.declaration().properties()) {
|
||||
set_property_expanding_shorthands(style, property.property_id, property.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue