11 #include <unordered_map>
16 struct GStyleMap :
public std::unordered_map<GId,GStyle*> {
18 GStyle* findStyle(GId selid);
19 GStyle& obtainStyle(GId selid);
36 InlineSpecif = 1'000
'000,
37 InterSpecif = 10'000
'000,
38 CondSpecif = 20'000
'000,
39 AnimSpecif = 30'000
'000
42 struct PropMap : public std::unordered_map<int, gptr<GProp>> {
43 void apply(Gadget* g, GRender& r, GProp::Specif specif) {
44 for (auto& p : *this) p.second->apply(g, r, specif);
49 GStyle(GId selector_id);
56 void addProp(GProp* prop);
57 GStyle& operator<<(GProp* prop) {addProp(prop); return *this;}
58 GStyle& operator<<(GProp& prop) {addProp(&prop); return *this;}
63 GProp* findProp(GPropType&) const;
64 template <class T> auto* findProp() const {return dynamic_cast<T*>(findProp(T::Type()));}
69 void removeProp(GProp&);
70 void removeProp(GPropType&);
73 PropMap const& props() const {return props_;}
75 void apply(Gadget* g, GRender& r) {
76 if (!realized_) realize();
77 if (!props_.empty()) props_.apply(g, r, specif_);
78 if (!pseudos_.empty()) applyPseudos(g, r);
81 void applyPseudos(Gadget* g, GRender& r);
83 // calls realize() if style if alraedy realized_, otherwise just adds decl block
84 void addStyleDecl(GString const& decl, GProp::Specif, GPseudoStyle* ps);
85 GStyle* addStyleDecl2(GString const& decl, GProp::Specif, GPseudoStyle* ps,
86 GString const& desc, char reltype, bool is_subrule);
90 enum RelType {DirectChild = 1};
91 void addDecl(GString const& decl);
92 bool realized_{}, has_desc_{}, any_desc_{}, direct_desc_{}, has_subrule_{}, is_pseudo_{};
94 GProp::Specif specif_{};
98 GStyleMap* stylemap_{};
99 std::forward_list<GPseudoStyle*> pseudos_;
103 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109 static GStyleBase& instance();
112 bool loadFile(GString const& css_filename);
115 bool loadBuffer(GString const& css_buffer);
118 bool load(std::istream& in, GString const& stream_name);
123 GStyle* findStyle(GId selector_id);
124 GStyle* findStyle(GString const& selector_name);
125 GStyle& obtainStyle(GId selector_id);
126 GStyle& obtainStyle(GString const& selector_name);
130 bool addStyle(GStrings& seltab, GString const& decl_block);
134 void addCoreStyle(GString const& name, GStyle&);
135 void error(GString const& msg);
136 bool parseStyle(std::istream&);
139 //bool parseSelName(GString const& sel, GString& name,
140 // GStrings& pseudos, GProp::Specif&);
143 bool parseSelName(GString const& sel, GString& name,
144 GProp::Specif& spec, GPseudoStyle*& ps);