StyleSheetNode.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include "precompiled.h"
  29. #include "StyleSheetNode.h"
  30. #include <algorithm>
  31. #include "../../Include/RmlUi/Core/Element.h"
  32. #include "StyleSheetFactory.h"
  33. #include "StyleSheetNodeSelector.h"
  34. namespace Rml {
  35. namespace Core {
  36. StyleSheetNode::StyleSheetNode(const String& name, NodeType _type, StyleSheetNode* _parent) : name(name)
  37. {
  38. type = _type;
  39. parent = _parent;
  40. specificity = CalculateSpecificity();
  41. selector = NULL;
  42. a = 0;
  43. b = 0;
  44. is_structurally_volatile = true;
  45. }
  46. // Constructs a structural style-sheet node.
  47. StyleSheetNode::StyleSheetNode(const String& name, StyleSheetNode* _parent, StyleSheetNodeSelector* _selector, int _a, int _b) : name(name)
  48. {
  49. type = STRUCTURAL_PSEUDO_CLASS;
  50. parent = _parent;
  51. specificity = CalculateSpecificity();
  52. selector = _selector;
  53. a = _a;
  54. b = _b;
  55. }
  56. StyleSheetNode::~StyleSheetNode()
  57. {
  58. for (int i = 0; i < NUM_NODE_TYPES; i++)
  59. {
  60. for (NodeMap::iterator j = children[i].begin(); j != children[i].end(); ++j)
  61. delete (*j).second;
  62. }
  63. }
  64. // Writes the style sheet node (and all ancestors) into the stream.
  65. void StyleSheetNode::Write(Stream* stream)
  66. {
  67. if (properties.GetNumProperties() > 0)
  68. {
  69. String rule;
  70. StyleSheetNode* hierarchy = this;
  71. while (hierarchy != NULL)
  72. {
  73. switch (hierarchy->type)
  74. {
  75. case TAG:
  76. rule = " " + hierarchy->name + rule;
  77. break;
  78. case CLASS:
  79. rule = "." + hierarchy->name + rule;
  80. break;
  81. case ID:
  82. rule = "#" + hierarchy->name + rule;
  83. break;
  84. case PSEUDO_CLASS:
  85. rule = ":" + hierarchy->name + rule;
  86. break;
  87. case STRUCTURAL_PSEUDO_CLASS:
  88. rule = ":" + hierarchy->name + rule;
  89. break;
  90. default:
  91. break;
  92. }
  93. hierarchy = hierarchy->parent;
  94. }
  95. stream->Write(CreateString(1024, "%s /* specificity: %d */\n", StringUtilities::StripWhitespace(rule).c_str(), specificity));
  96. stream->Write("{\n");
  97. const Rml::Core::PropertyMap& property_map = properties.GetProperties();
  98. for (Rml::Core::PropertyMap::const_iterator i = property_map.begin(); i != property_map.end(); ++i)
  99. {
  100. const String& name = StyleSheetSpecification::GetPropertyName(i->first);
  101. const Rml::Core::Property& property = i->second;
  102. stream->Write(CreateString(1024, "\t%s: %s; /* specificity: %d */\n", name.c_str(), property.value.Get< String >().c_str(), property.specificity));
  103. }
  104. stream->Write("}\n\n");
  105. }
  106. for (size_t i = 0; i < NUM_NODE_TYPES; ++i)
  107. {
  108. for (NodeMap::iterator j = children[i].begin(); j != children[i].end(); ++j)
  109. (*j).second->Write(stream);
  110. }
  111. }
  112. // Merges an entire tree hierarchy into our hierarchy.
  113. bool StyleSheetNode::MergeHierarchy(StyleSheetNode* node, int specificity_offset)
  114. {
  115. // Merge the other node's properties into ours.
  116. MergeProperties(node->properties, specificity_offset);
  117. selector = node->selector;
  118. a = node->a;
  119. b = node->b;
  120. for (int i = 0; i < NUM_NODE_TYPES; i++)
  121. {
  122. for (NodeMap::iterator iterator = node->children[i].begin(); iterator != node->children[i].end(); ++iterator)
  123. {
  124. StyleSheetNode* local_node = GetChildNode((*iterator).second->name, (NodeType) i);
  125. local_node->MergeHierarchy((*iterator).second, specificity_offset);
  126. }
  127. }
  128. return true;
  129. }
  130. // Builds up a style sheet's index recursively.
  131. void StyleSheetNode::BuildIndexAndOptimizeProperties(StyleSheet::NodeIndex& styled_index, StyleSheet::NodeIndex& complete_index, const StyleSheet& style_sheet)
  132. {
  133. // If this is a tag node, then we insert it into the list of all tag nodes. Makes sense, neh?
  134. if (type == TAG)
  135. {
  136. StyleSheet::NodeIndex::iterator iterator = complete_index.find(name);
  137. if (iterator == complete_index.end())
  138. (*complete_index.insert(StyleSheet::NodeIndex::value_type(name, StyleSheet::NodeList())).first).second.insert(this);
  139. else
  140. (*iterator).second.insert(this);
  141. }
  142. // If we are a styled node (ie, have some style attributes attached), then we insert our closest parent tag node
  143. // into the list of styled tag nodes.
  144. if (properties.GetNumProperties() > 0)
  145. {
  146. StyleSheetNode* tag_node = this;
  147. while (tag_node != NULL &&
  148. tag_node->type != TAG)
  149. tag_node = tag_node->parent;
  150. if (tag_node != NULL)
  151. {
  152. StyleSheet::NodeIndex::iterator iterator = styled_index.find(tag_node->name);
  153. if (iterator == styled_index.end())
  154. (*styled_index.insert(StyleSheet::NodeIndex::value_type(tag_node->name, StyleSheet::NodeList())).first).second.insert(tag_node);
  155. else
  156. (*iterator).second.insert(tag_node);
  157. }
  158. // Turn any decorator properties from String to DecoratorList.
  159. // This is essentially an optimization, it will work fine to skip this step and let ElementStyle::ComputeValues() do all the work.
  160. // However, when we do it here, we only need to do it once.
  161. // Note, since the user may set a new decorator through its style, we still do the conversion as necessary again in ComputeValues.
  162. if (const Property* property = properties.GetProperty(PropertyId::Decorator))
  163. {
  164. if (property->unit == Property::STRING)
  165. {
  166. const String string_value = property->Get<String>();
  167. DecoratorList decorator_list = style_sheet.InstanceDecoratorsFromString(string_value, property->source, property->source_line_number);
  168. Property new_property = *property;
  169. new_property.value = std::move(decorator_list);
  170. new_property.unit = Property::DECORATOR;
  171. properties.SetProperty(PropertyId::Decorator, new_property);
  172. }
  173. }
  174. // Turn any font-effect properties from String to FontEffectListPtr. See comments for decorator, they apply here as well.
  175. if (const Property * property = properties.GetProperty(PropertyId::FontEffect))
  176. {
  177. if (property->unit == Property::STRING)
  178. {
  179. const String string_value = property->Get<String>();
  180. FontEffectListPtr font_effects = style_sheet.InstanceFontEffectsFromString(string_value, property->source, property->source_line_number);
  181. Property new_property = *property;
  182. new_property.value = std::move(font_effects);
  183. new_property.unit = Property::FONTEFFECT;
  184. properties.SetProperty(PropertyId::FontEffect, new_property);
  185. }
  186. }
  187. }
  188. for (int i = 0; i < NUM_NODE_TYPES; i++)
  189. {
  190. for (NodeMap::iterator j = children[i].begin(); j != children[i].end(); ++j)
  191. (*j).second->BuildIndexAndOptimizeProperties(styled_index, complete_index, style_sheet);
  192. }
  193. }
  194. bool StyleSheetNode::SetStructurallyVolatileRecursive(bool ancestor_is_structural_pseudo_class)
  195. {
  196. // If any ancestor or descendant is a structural pseudo class, then we are structurally volatile.
  197. bool self_is_structural_pseudo_class = (type == STRUCTURAL_PSEUDO_CLASS);
  198. // Check our children for structural pseudo-classes.
  199. bool descendant_is_structural_pseudo_class = false;
  200. for (int i = 0; i < NUM_NODE_TYPES; ++i)
  201. {
  202. for (auto& child_name_node : children[i])
  203. {
  204. if (child_name_node.second->SetStructurallyVolatileRecursive(self_is_structural_pseudo_class || ancestor_is_structural_pseudo_class))
  205. descendant_is_structural_pseudo_class = true;
  206. }
  207. }
  208. is_structurally_volatile = (self_is_structural_pseudo_class || ancestor_is_structural_pseudo_class || descendant_is_structural_pseudo_class);
  209. return (self_is_structural_pseudo_class || descendant_is_structural_pseudo_class);
  210. }
  211. // Returns the name of this node.
  212. const String& StyleSheetNode::GetName() const
  213. {
  214. return name;
  215. }
  216. // Returns the specificity of this node.
  217. int StyleSheetNode::GetSpecificity() const
  218. {
  219. return specificity;
  220. }
  221. // Imports properties from a single rule definition (ie, with a shared specificity) into the node's
  222. // properties.
  223. void StyleSheetNode::ImportProperties(const PropertyDictionary& _properties, int rule_specificity)
  224. {
  225. properties.Import(_properties, specificity + rule_specificity);
  226. }
  227. // Merges properties from another node (ie, with potentially differing specificities) into the
  228. // node's properties.
  229. void StyleSheetNode::MergeProperties(const PropertyDictionary& _properties, int rule_specificity_offset)
  230. {
  231. properties.Merge(_properties, rule_specificity_offset);
  232. }
  233. // Returns the node's default properties.
  234. const PropertyDictionary& StyleSheetNode::GetProperties() const
  235. {
  236. return properties;
  237. }
  238. // Builds the properties of all of the pseudo-classes of this style sheet node into a single map.
  239. void StyleSheetNode::GetPseudoClassProperties(PseudoClassPropertyMap& pseudo_class_properties) const
  240. {
  241. PseudoClassList pseudo_class_list;
  242. for (NodeMap::const_iterator i = children[PSEUDO_CLASS].begin(); i != children[PSEUDO_CLASS].end(); ++i)
  243. (*i).second->GetPseudoClassProperties(pseudo_class_properties, pseudo_class_list);
  244. }
  245. // Adds to a list the names of this node's pseudo-classes which are deemed volatile.
  246. bool StyleSheetNode::GetVolatilePseudoClasses(PseudoClassList& volatile_pseudo_classes) const
  247. {
  248. if (type == PSEUDO_CLASS)
  249. {
  250. bool self_volatile = !children[TAG].empty();
  251. for (NodeMap::const_iterator i = children[PSEUDO_CLASS].begin(); i != children[PSEUDO_CLASS].end(); ++i)
  252. self_volatile = (*i).second->GetVolatilePseudoClasses(volatile_pseudo_classes) | self_volatile;
  253. if (self_volatile)
  254. {
  255. volatile_pseudo_classes.insert(name);
  256. }
  257. return self_volatile;
  258. }
  259. else
  260. {
  261. for (NodeMap::const_iterator i = children[PSEUDO_CLASS].begin(); i != children[PSEUDO_CLASS].end(); ++i)
  262. (*i).second->GetVolatilePseudoClasses(volatile_pseudo_classes);
  263. }
  264. return false;
  265. }
  266. // Returns a direct child node of this node of the requested type.
  267. StyleSheetNode* StyleSheetNode::GetChildNode(const String& child_name, NodeType child_type, bool create)
  268. {
  269. // Look for a node with given name.
  270. NodeMap::iterator iterator = children[child_type].find(child_name);
  271. if (iterator != children[child_type].end())
  272. {
  273. // Traverse into node.
  274. return (*iterator).second;
  275. }
  276. else
  277. {
  278. if (create)
  279. {
  280. StyleSheetNode* new_node = NULL;
  281. // Create the node; structural pseudo-classes require a little extra leg-work.
  282. if (child_type == STRUCTURAL_PSEUDO_CLASS)
  283. new_node = CreateStructuralChild(child_name);
  284. else
  285. new_node = new StyleSheetNode(child_name, child_type, this);
  286. if (new_node != NULL)
  287. {
  288. children[child_type][child_name] = new_node;
  289. return new_node;
  290. }
  291. }
  292. return NULL;
  293. }
  294. }
  295. // Returns true if this node is applicable to the given element, given its IDs, classes and heritage.
  296. bool StyleSheetNode::IsApplicable(const Element* element) const
  297. {
  298. // This function is called with an element that matches a style node only with the tag name. We have to determine
  299. // here whether or not it also matches the required hierarchy.
  300. // We must have a parent; if not, something's amok with the style tree.
  301. if (parent == NULL)
  302. {
  303. RMLUI_ERRORMSG("Invalid RCSS hierarchy.");
  304. return false;
  305. }
  306. // If we've hit a child of the root of the style sheet tree, then we're done; no more lineage to resolve.
  307. if (parent->type == ROOT)
  308. return true;
  309. // Determine the tag (and possibly id / class as well) of the next required parent in the RCSS hierarchy.
  310. const StyleSheetNode* parent_node = parent;
  311. const String* ancestor_id = nullptr;
  312. static std::vector<const String*> ancestor_classes;
  313. static std::vector<const String*> ancestor_pseudo_classes;
  314. static std::vector< const StyleSheetNode* > ancestor_structural_pseudo_classes;
  315. ancestor_classes.clear();
  316. ancestor_pseudo_classes.clear();
  317. ancestor_structural_pseudo_classes.clear();
  318. while (parent_node != NULL && parent_node->type != TAG)
  319. {
  320. switch (parent_node->type)
  321. {
  322. case ID: ancestor_id = &parent_node->name; break;
  323. case CLASS: ancestor_classes.push_back(&parent_node->name); break;
  324. case PSEUDO_CLASS: ancestor_pseudo_classes.push_back(&parent_node->name); break;
  325. case STRUCTURAL_PSEUDO_CLASS: ancestor_structural_pseudo_classes.push_back(parent_node); break;
  326. default: RMLUI_ERRORMSG("Invalid RCSS hierarchy."); return false;
  327. }
  328. parent_node = parent_node->parent;
  329. }
  330. // Check for an invalid RCSS hierarchy.
  331. if (parent_node == NULL)
  332. {
  333. RMLUI_ERRORMSG("Invalid RCSS hierarchy.");
  334. return false;
  335. }
  336. // Now we know the name / class / ID / pseudo-class / structural requirements for the next ancestor requirement of
  337. // the element. So we look back through the element's ancestors to find one that matches.
  338. for (const Element* ancestor_element = element->GetParentNode(); ancestor_element != NULL; ancestor_element = ancestor_element->GetParentNode())
  339. {
  340. // Skip this ancestor if the name of the next style node doesn't match its tag name, and one was specified.
  341. if (!parent_node->name.empty()
  342. && parent_node->name != ancestor_element->GetTagName())
  343. continue;
  344. // Skip this ancestor if the ID of the next style node doesn't match its ID, and one was specified.
  345. if (ancestor_id &&
  346. *ancestor_id != ancestor_element->GetId())
  347. continue;
  348. // Skip this ancestor if the class of the next style node don't match its classes.
  349. bool resolved_requirements = true;
  350. for (size_t i = 0; i < ancestor_classes.size(); ++i)
  351. {
  352. if (!ancestor_element->IsClassSet(*ancestor_classes[i]))
  353. {
  354. resolved_requirements = false;
  355. break;
  356. }
  357. }
  358. if (!resolved_requirements)
  359. continue;
  360. // Skip this ancestor if the required pseudo-classes of the style node aren't set on it.
  361. resolved_requirements = true;
  362. for (size_t i = 0; i < ancestor_pseudo_classes.size(); ++i)
  363. {
  364. if (!ancestor_element->IsPseudoClassSet(*ancestor_pseudo_classes[i]))
  365. {
  366. resolved_requirements = false;
  367. break;
  368. }
  369. }
  370. if (!resolved_requirements)
  371. continue;
  372. // Skip this ancestor if the required structural pseudo-classes of the style node aren't applicable to it.
  373. resolved_requirements = true;
  374. for (size_t i = 0; i < ancestor_structural_pseudo_classes.size(); ++i)
  375. {
  376. if (!ancestor_structural_pseudo_classes[i]->selector->IsApplicable(ancestor_element, ancestor_structural_pseudo_classes[i]->a, ancestor_structural_pseudo_classes[i]->b))
  377. {
  378. resolved_requirements = false;
  379. break;
  380. }
  381. }
  382. if (!resolved_requirements)
  383. continue;
  384. return parent_node->IsApplicable(ancestor_element);
  385. }
  386. // We hit the end of the hierarchy before matching the required ancestor, so bail.
  387. return false;
  388. }
  389. // Appends all applicable non-tag descendants of this node into the given element list.
  390. void StyleSheetNode::GetApplicableDescendants(std::vector< const StyleSheetNode* >& applicable_nodes, const Element* element) const
  391. {
  392. // Check if this node matches this element.
  393. switch (type)
  394. {
  395. RMLUI_UNUSED_SWITCH_ENUM(NUM_NODE_TYPES);
  396. case ROOT:
  397. case TAG:
  398. {
  399. // These nodes always match.
  400. }
  401. break;
  402. case CLASS:
  403. {
  404. if (!element->IsClassSet(name))
  405. return;
  406. }
  407. break;
  408. case ID:
  409. {
  410. if (name != element->GetId())
  411. return;
  412. }
  413. break;
  414. case PSEUDO_CLASS:
  415. {
  416. if (!element->IsPseudoClassSet(name))
  417. return;
  418. }
  419. break;
  420. case STRUCTURAL_PSEUDO_CLASS:
  421. {
  422. if (selector == NULL)
  423. return;
  424. if (!selector->IsApplicable(element, a, b))
  425. return;
  426. }
  427. break;
  428. }
  429. if (properties.GetNumProperties() > 0)
  430. applicable_nodes.push_back(this);
  431. for (int i = CLASS; i < NUM_NODE_TYPES; i++)
  432. {
  433. for (auto& child_tag_node : children[i])
  434. child_tag_node.second->GetApplicableDescendants(applicable_nodes, element);
  435. }
  436. }
  437. bool StyleSheetNode::IsStructurallyVolatile() const
  438. {
  439. return is_structurally_volatile;
  440. }
  441. // Constructs a structural pseudo-class child node.
  442. StyleSheetNode* StyleSheetNode::CreateStructuralChild(const String& child_name)
  443. {
  444. StyleSheetNodeSelector* child_selector = StyleSheetFactory::GetSelector(child_name);
  445. if (child_selector == NULL)
  446. return NULL;
  447. // Parse the 'a' and 'b' values.
  448. int child_a = 1;
  449. int child_b = 0;
  450. size_t parameter_start = child_name.find("(");
  451. size_t parameter_end = child_name.find(")");
  452. if (parameter_start != String::npos &&
  453. parameter_end != String::npos)
  454. {
  455. String parameters = child_name.substr(parameter_start + 1, parameter_end - (parameter_start + 1));
  456. // Check for 'even' or 'odd' first.
  457. if (parameters == "even")
  458. {
  459. child_a = 2;
  460. child_b = 0;
  461. }
  462. else if (parameters == "odd")
  463. {
  464. child_a = 2;
  465. child_b = 1;
  466. }
  467. else
  468. {
  469. // Alrighty; we've got an equation in the form of [[+/-]an][(+/-)b]. So, foist up, we split on 'n'.
  470. size_t n_index = parameters.find('n');
  471. if (n_index != String::npos)
  472. {
  473. // The equation is 0n + b. So a = 0, and we only have to parse b.
  474. child_a = 0;
  475. child_b = atoi(parameters.c_str());
  476. }
  477. else
  478. {
  479. if (n_index == 0)
  480. child_a = 1;
  481. else
  482. {
  483. String a_parameter = parameters.substr(0, n_index);
  484. if (StringUtilities::StripWhitespace(a_parameter) == "-")
  485. child_a = -1;
  486. else
  487. child_a = atoi(a_parameter.c_str());
  488. }
  489. if (n_index == parameters.size() - 1)
  490. child_b = 0;
  491. else
  492. child_b = atoi(parameters.substr(n_index + 1).c_str());
  493. }
  494. }
  495. }
  496. return new StyleSheetNode(child_name, this, child_selector, child_a, child_b);
  497. }
  498. // Recursively builds up a list of all pseudo-classes branching from a single node.
  499. void StyleSheetNode::GetPseudoClassProperties(PseudoClassPropertyMap& pseudo_class_properties, const PseudoClassList& ancestor_pseudo_classes)
  500. {
  501. PseudoClassList pseudo_classes(ancestor_pseudo_classes);
  502. pseudo_classes.insert(name);
  503. if (properties.GetNumProperties() > 0)
  504. {
  505. RMLUI_ASSERT(pseudo_class_properties.count(pseudo_classes) == 0);
  506. pseudo_class_properties[pseudo_classes] = properties;
  507. }
  508. for (NodeMap::const_iterator i = children[PSEUDO_CLASS].begin(); i != children[PSEUDO_CLASS].end(); ++i)
  509. (*i).second->GetPseudoClassProperties(pseudo_class_properties, pseudo_classes);
  510. }
  511. int StyleSheetNode::CalculateSpecificity()
  512. {
  513. // Calculate the specificity of just this node; tags are worth 10,000, IDs 1,000,000 and other specifiers (classes
  514. // and pseudo-classes) 100,000.
  515. int specificity = 0;
  516. switch (type)
  517. {
  518. case TAG:
  519. {
  520. if (!name.empty())
  521. specificity = 10000;
  522. }
  523. break;
  524. case CLASS:
  525. case PSEUDO_CLASS:
  526. case STRUCTURAL_PSEUDO_CLASS:
  527. {
  528. specificity = 100000;
  529. }
  530. break;
  531. case ID:
  532. {
  533. specificity = 1000000;
  534. }
  535. break;
  536. default:
  537. {
  538. specificity = 0;
  539. }
  540. break;
  541. }
  542. // Add our parent's specificity onto ours.
  543. if (parent != NULL)
  544. specificity += parent->CalculateSpecificity();
  545. return specificity;
  546. }
  547. }
  548. }