|
|
Donner
C++20 SVG rendering library
|
A CSS specificity value (id, class, type), as defined in https://www.w3.org/TR/selectors-4/#specificity-rules, which is used during cascading to determine which style takes precedence. More...
#include "donner/css/Specificity.h"
Classes | |
| struct | ABC |
| A 3-tuple of integers representing the specificity before modifiers such as the "!important" flag have been applied. More... | |
Public Types | |
| enum class | SpecialType { UserAgent , None , StyleAttribute , Important , Override } |
| Special values for specificity, which take precedence over the 3-tuple. More... | |
Public Member Functions | |
| constexpr | Specificity ()=default |
| Default constructor, creates a specificity of (0, 0, 0). | |
| constexpr | Specificity (const ABC &abc) |
| Constructs a specificity from a ABC 3-tuple. | |
| ~Specificity ()=default | |
| Destructor. | |
| Specificity (const Specificity &other)=default | |
| Copy constructor. | |
| Specificity (Specificity &&other) noexcept=default | |
| Move constructor. | |
| Specificity & | operator= (const Specificity &other)=default |
| Assignment operator. | |
| Specificity & | operator= (Specificity &&other) noexcept=default |
| Move assignment operator. | |
| auto | operator<=> (const Specificity &other) const |
| Spaceship operator. | |
| bool | operator== (const Specificity &other) const |
| Equality operator, for gtest. | |
| const ABC & | abc () const |
| Gets the 3-tuple of integers. | |
| SpecialType | specialValue () const |
| Gets the special value of the specificity, defaults to SpecialType::None. | |
| Specificity | toUserAgentSpecificity () const |
| Converts this Specificity into a UserAgent-specific Specificity (lowering the priority). | |
Static Public Member Functions | |
| static constexpr Specificity | FromABC (uint32_t a, uint32_t b, uint32_t c) |
| Creates a specificity from the 3-tuple of integers. | |
| static constexpr Specificity | Important () |
| Creates a specificity for an !important declaration. | |
| static constexpr Specificity | StyleAttribute () |
| Creates a specificity for a style attribute. | |
| static constexpr Specificity | Override () |
| Creates a specificity that overrides any other value, for overriding styles from the C++ API. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const SpecialType &type) |
| Output stream operator. | |
| std::ostream & | operator<< (std::ostream &os, const Specificity &obj) |
| Ostream output operator. | |
A CSS specificity value (id, class, type), as defined in https://www.w3.org/TR/selectors-4/#specificity-rules, which is used during cascading to determine which style takes precedence.
The specificity is a 3-tuple of integers, where the first integer is the most significant, plus a few special values such as "!important" which override.
The 3-tuple is defined as:
Examples
| Selector | Specificity |
|---|---|
| #id | (1, 0, 0) |
| .class | (0, 1, 0) |
| div | (0, 0, 1) |
| #id.class | (1, 1, 0) |
| #id.class div | (1, 1, 1) |
| #id.class > div | (1, 1, 1) |
| [class=~"class"] | (1, 1, 1) |
For example, the selector #id.class has a specificity of (1, 1, 0), while div > p has a specificity of (0, 0, 2).
To construct from a 3-tuple:
To construct from "!important":
|
strong |
Special values for specificity, which take precedence over the 3-tuple.
The order of these values is important, since operator<=> considers later enum values to be greater.
| Enumerator | |
|---|---|
| UserAgent | User agent stylesheet, lowest precedence in CSS. |
| None | No special value. |
| StyleAttribute | Style attribute, second highest precedence in CSS. |
| Important | !important declaration, highest precedence in CSS. |
| Override | Values set from C++ API, which overrides all other values. |
|
inlinestaticconstexpr |
Creates a specificity from the 3-tuple of integers.
| a | The number of ID selectors in the selector. |
| b | The number of class selectors, attributes selectors, and pseudo-classes in the selector. |
| c | The number of type selectors and pseudo-elements in the selector. |
|
friend |
Ostream output operator.
Example output:
or
| os | Output stream. |
| obj | Specificity to output. |