1 #include "CssData.h"
2 
3 
4 #include <map>
5 #include "Wt/Render/Block.h"
6 #include "Wt/Render/CssData_p.h"
7 #include "web/WebUtils.h"
8 
9 using namespace Wt::Render;
10 
setValue(const std::string & value)11 void Wt::Render::Term::setValue(const std::string& value)
12 {
13   value_ = value;
14 }
15 
16 ///////////////////////////////////////////////////////////////////////////////
17 ///// isMatch                                                             /////
18 ///////////////////////////////////////////////////////////////////////////////
19 
isMatch(const Block * block,const SimpleSelector & s)20 bool Wt::Render::Match::isMatch(const Block* block, const SimpleSelector& s)
21 {
22   const DomElementType tag = block->type();
23   const std::string id = block->id();
24   const std::vector<std::string>& classes = block->classes();
25   const std::vector<std::string>& requiredClasses = s.classes();
26 
27   //cout << "isMatch? block:" << tag << " " << id
28   //               << "; s: " << s.elementName() << " " << s.hashId();
29 
30   // Match tagname?
31   if (!s.elementName().empty() &&
32       s.elementName() != "*" &&
33       tag != s.elementType())
34   {
35     //cout << "; NO! tag" << endl;
36     return false;
37   }
38 
39   // Match Id?
40   if (s.hashId().size() && id != s.hashId())
41   {
42     //cout << "; NO! id" << endl;
43     return false;
44   }
45 
46   // Match all classes?
47   for (unsigned int i = 0; i < requiredClasses.size(); ++i)
48   {
49     if (Wt::Utils::indexOf(classes, requiredClasses[i]) == -1)
50     {
51       //cout << "; NO! classes" << r << endl;
52       return false;
53     }
54   }
55 
56   // Done!
57   //cout << "; YES!" << endl;
58   return true;
59 }
60 
isMatch(const Block * block,const Selector & selector)61 Specificity Wt::Render::Match::isMatch(const Block* block, const Selector& selector)
62 {
63   if(!selector.size())
64     return Specificity(false);
65 
66   if(!isMatch(block, selector.at(selector.size()-1)))
67     return Specificity(false);
68   const Block* parent = block->parent();
69   for(int i = selector.size()-2; i >= 0; --i)
70   {
71     bool matchFound = false;
72     while(parent)
73     {
74       matchFound = isMatch(parent, selector.at(i));
75       parent = parent->parent();
76       if(matchFound)
77         break;
78     }
79 
80     if(!matchFound && !parent)
81       return Specificity(false);
82   }
83   return selector.specificity();
84 }
85 
86 
87