ElementStyle.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "ElementStyle.h"
  29. #include "ElementStyleCache.h"
  30. #include <algorithm>
  31. #include "../../Include/Rocket/Core/ElementDocument.h"
  32. #include "../../Include/Rocket/Core/ElementUtilities.h"
  33. #include "../../Include/Rocket/Core/Log.h"
  34. #include "../../Include/Rocket/Core/Math.h"
  35. #include "../../Include/Rocket/Core/Property.h"
  36. #include "../../Include/Rocket/Core/PropertyDefinition.h"
  37. #include "../../Include/Rocket/Core/PropertyDictionary.h"
  38. #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
  39. #include "../../Include/Rocket/Core/TransformPrimitive.h"
  40. #include "ElementBackground.h"
  41. #include "ElementBorder.h"
  42. #include "ElementDecoration.h"
  43. #include "ElementDefinition.h"
  44. #include "FontFaceHandle.h"
  45. #include "RCSS.h"
  46. namespace Rocket {
  47. namespace Core {
  48. static const Style::ComputedValues DefaultComputedValues;
  49. ElementStyle::ElementStyle(Element* _element)
  50. {
  51. local_properties = NULL;
  52. em_properties = NULL;
  53. definition = NULL;
  54. element = _element;
  55. cache = new ElementStyleCache(this);
  56. definition_dirty = true;
  57. }
  58. ElementStyle::~ElementStyle()
  59. {
  60. if (local_properties != NULL)
  61. delete local_properties;
  62. if (em_properties != NULL)
  63. delete em_properties;
  64. if (definition != NULL)
  65. definition->RemoveReference();
  66. delete cache;
  67. }
  68. // Returns the element's definition, updating if necessary.
  69. const ElementDefinition* ElementStyle::GetDefinition()
  70. {
  71. return definition;
  72. }
  73. // Returns one of this element's properties.
  74. const Property* ElementStyle::GetLocalProperty(const String& name, PropertyDictionary* local_properties, ElementDefinition* definition, const PseudoClassList& pseudo_classes)
  75. {
  76. // Check for overriding local properties.
  77. if (local_properties != NULL)
  78. {
  79. const Property* property = local_properties->GetProperty(name);
  80. if (property != NULL)
  81. return property;
  82. }
  83. // Check for a property defined in an RCSS rule.
  84. if (definition != NULL)
  85. return definition->GetProperty(name, pseudo_classes);
  86. return NULL;
  87. }
  88. // Returns one of this element's properties.
  89. const Property* ElementStyle::GetProperty(const String& name, Element* element, PropertyDictionary* local_properties, ElementDefinition* definition, const PseudoClassList& pseudo_classes)
  90. {
  91. const Property* local_property = GetLocalProperty(name, local_properties, definition, pseudo_classes);
  92. if (local_property != NULL)
  93. return local_property;
  94. // Fetch the property specification.
  95. const PropertyDefinition* property = StyleSheetSpecification::GetProperty(name);
  96. if (property == NULL)
  97. return NULL;
  98. // If we can inherit this property, return our parent's property.
  99. if (property->IsInherited())
  100. {
  101. Element* parent = element->GetParentNode();
  102. while (parent != NULL)
  103. {
  104. const Property* parent_property = parent->GetStyle()->GetLocalProperty(name);
  105. if (parent_property)
  106. return parent_property;
  107. parent = parent->GetParentNode();
  108. }
  109. }
  110. // No property available! Return the default value.
  111. return property->GetDefaultValue();
  112. }
  113. // Apply transition to relevant properties if a transition is defined on element.
  114. // Properties that are part of a transition are removed from the properties list.
  115. void ElementStyle::TransitionPropertyChanges(Element* element, PropertyNameList& properties, PropertyDictionary* local_properties, ElementDefinition* old_definition, ElementDefinition* new_definition,
  116. const PseudoClassList& pseudo_classes_before, const PseudoClassList& pseudo_classes_after)
  117. {
  118. ROCKET_ASSERT(element);
  119. if (!old_definition || !new_definition || properties.empty())
  120. return;
  121. if (const Property* transition_property = GetLocalProperty(TRANSITION, local_properties, new_definition, pseudo_classes_after))
  122. {
  123. auto transition_list = transition_property->Get<TransitionList>();
  124. if (!transition_list.none)
  125. {
  126. auto add_transition = [&](const Transition& transition) {
  127. bool transition_added = false;
  128. const Property* start_value = GetProperty(transition.name, element, local_properties, old_definition, pseudo_classes_before);
  129. const Property* target_value = GetProperty(transition.name, element, nullptr, new_definition, pseudo_classes_after);
  130. if (start_value && target_value && (*start_value != *target_value))
  131. transition_added = element->StartTransition(transition, *start_value, *target_value);
  132. return transition_added;
  133. };
  134. if (transition_list.all)
  135. {
  136. Transition transition = transition_list.transitions[0];
  137. for (auto it = properties.begin(); it != properties.end(); )
  138. {
  139. transition.name = *it;
  140. if (add_transition(transition))
  141. it = properties.erase(it);
  142. else
  143. ++it;
  144. }
  145. }
  146. else
  147. {
  148. for (auto& transition : transition_list.transitions)
  149. {
  150. if (auto it = properties.find(transition.name); it != properties.end())
  151. {
  152. if (add_transition(transition))
  153. properties.erase(it);
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. void ElementStyle::UpdateDefinition()
  161. {
  162. if (definition_dirty)
  163. {
  164. definition_dirty = false;
  165. ElementDefinition* new_definition = NULL;
  166. const StyleSheet* style_sheet = GetStyleSheet();
  167. if (style_sheet != NULL)
  168. {
  169. new_definition = style_sheet->GetElementDefinition(element);
  170. }
  171. // Switch the property definitions if the definition has changed.
  172. if (new_definition != definition || new_definition == NULL)
  173. {
  174. PropertyNameList properties;
  175. if (definition != NULL)
  176. definition->GetDefinedProperties(properties, pseudo_classes);
  177. if (new_definition != NULL)
  178. new_definition->GetDefinedProperties(properties, pseudo_classes);
  179. TransitionPropertyChanges(element, properties, local_properties, definition, new_definition, pseudo_classes, pseudo_classes);
  180. if (definition != NULL)
  181. definition->RemoveReference();
  182. definition = new_definition;
  183. DirtyProperties(properties);
  184. element->GetElementDecoration()->DirtyDecorators(true);
  185. }
  186. else if (new_definition != NULL)
  187. {
  188. new_definition->RemoveReference();
  189. }
  190. }
  191. }
  192. // Sets or removes a pseudo-class on the element.
  193. void ElementStyle::SetPseudoClass(const String& pseudo_class, bool activate)
  194. {
  195. size_t num_pseudo_classes = pseudo_classes.size();
  196. auto pseudo_classes_before = pseudo_classes;
  197. if (activate)
  198. pseudo_classes.push_back(pseudo_class);
  199. else
  200. {
  201. // In case of duplicates, we do a loop here. We could do a sort and unique instead,
  202. // but that might even be slower for a small list with few duplicates, which
  203. // is probably the most common case.
  204. auto it = std::find(pseudo_classes.begin(), pseudo_classes.end(), pseudo_class);
  205. while(it != pseudo_classes.end())
  206. {
  207. pseudo_classes.erase(it);
  208. it = std::find(pseudo_classes.begin(), pseudo_classes.end(), pseudo_class);
  209. }
  210. }
  211. if (pseudo_classes.size() != num_pseudo_classes)
  212. {
  213. element->GetElementDecoration()->DirtyDecorators(false);
  214. if (definition != NULL)
  215. {
  216. PropertyNameList properties;
  217. definition->GetDefinedProperties(properties, pseudo_classes, pseudo_class);
  218. TransitionPropertyChanges(element, properties, local_properties, definition, definition, pseudo_classes_before, pseudo_classes);
  219. DirtyProperties(properties);
  220. switch (definition->GetPseudoClassVolatility(pseudo_class))
  221. {
  222. case ElementDefinition::FONT_VOLATILE:
  223. element->DirtyFont();
  224. break;
  225. case ElementDefinition::STRUCTURE_VOLATILE:
  226. DirtyChildDefinitions();
  227. break;
  228. default:
  229. break;
  230. }
  231. }
  232. }
  233. }
  234. // Checks if a specific pseudo-class has been set on the element.
  235. bool ElementStyle::IsPseudoClassSet(const String& pseudo_class) const
  236. {
  237. return (std::find(pseudo_classes.begin(), pseudo_classes.end(), pseudo_class) != pseudo_classes.end());
  238. }
  239. const PseudoClassList& ElementStyle::GetActivePseudoClasses() const
  240. {
  241. return pseudo_classes;
  242. }
  243. // Sets or removes a class on the element.
  244. void ElementStyle::SetClass(const String& class_name, bool activate)
  245. {
  246. StringList::iterator class_location = std::find(classes.begin(), classes.end(), class_name);
  247. if (activate)
  248. {
  249. if (class_location == classes.end())
  250. {
  251. classes.push_back(class_name);
  252. DirtyDefinition();
  253. }
  254. }
  255. else
  256. {
  257. if (class_location != classes.end())
  258. {
  259. classes.erase(class_location);
  260. DirtyDefinition();
  261. }
  262. }
  263. }
  264. // Checks if a class is set on the element.
  265. bool ElementStyle::IsClassSet(const String& class_name) const
  266. {
  267. return std::find(classes.begin(), classes.end(), class_name) != classes.end();
  268. }
  269. // Specifies the entire list of classes for this element. This will replace any others specified.
  270. void ElementStyle::SetClassNames(const String& class_names)
  271. {
  272. classes.clear();
  273. StringUtilities::ExpandString(classes, class_names, ' ');
  274. DirtyDefinition();
  275. }
  276. // Returns the list of classes specified for this element.
  277. String ElementStyle::GetClassNames() const
  278. {
  279. String class_names;
  280. for (size_t i = 0; i < classes.size(); i++)
  281. {
  282. if (i != 0)
  283. {
  284. class_names += " ";
  285. }
  286. class_names += classes[i];
  287. }
  288. return class_names;
  289. }
  290. // Sets a local property override on the element.
  291. bool ElementStyle::SetProperty(const String& name, const String& value)
  292. {
  293. if (local_properties == NULL)
  294. local_properties = new PropertyDictionary();
  295. if (StyleSheetSpecification::ParsePropertyDeclaration(*local_properties, name, value))
  296. {
  297. DirtyProperty(name);
  298. return true;
  299. }
  300. else
  301. {
  302. Log::Message(Log::LT_WARNING, "Syntax error parsing inline property declaration '%s: %s;'.", name.c_str(), value.c_str());
  303. return false;
  304. }
  305. }
  306. // Sets a local property override on the element to a pre-parsed value.
  307. bool ElementStyle::SetProperty(const String& name, const Property& property)
  308. {
  309. Property new_property = property;
  310. new_property.definition = StyleSheetSpecification::GetProperty(name);
  311. if (new_property.definition == NULL)
  312. return false;
  313. if (local_properties == NULL)
  314. local_properties = new PropertyDictionary();
  315. local_properties->SetProperty(name, new_property);
  316. DirtyProperty(name);
  317. return true;
  318. }
  319. // Removes a local property override on the element.
  320. void ElementStyle::RemoveProperty(const String& name)
  321. {
  322. if (local_properties == NULL)
  323. return;
  324. if (local_properties->GetProperty(name) != NULL)
  325. {
  326. local_properties->RemoveProperty(name);
  327. DirtyProperty(name);
  328. }
  329. }
  330. // Returns one of this element's properties.
  331. const Property* ElementStyle::GetProperty(const String& name)
  332. {
  333. return GetProperty(name, element, local_properties, definition, pseudo_classes);
  334. }
  335. // Returns one of this element's properties.
  336. const Property* ElementStyle::GetLocalProperty(const String& name)
  337. {
  338. return GetLocalProperty(name, local_properties, definition, pseudo_classes);
  339. }
  340. const PropertyMap * ElementStyle::GetLocalProperties() const
  341. {
  342. if (local_properties)
  343. return &local_properties->GetProperties();
  344. return NULL;
  345. }
  346. float ElementStyle::ResolveLength(const Property * property)
  347. {
  348. if (!property)
  349. {
  350. ROCKET_ERROR;
  351. return 0.0f;
  352. }
  353. if (!(property->unit & Property::LENGTH))
  354. {
  355. ROCKET_ERRORMSG("Trying to resolve length on a non-length property.");
  356. return 0.0f;
  357. }
  358. switch (property->unit)
  359. {
  360. case Property::NUMBER:
  361. case Property::PX:
  362. return property->value.Get< float >();
  363. case Property::EM:
  364. return property->value.Get< float >() * ElementUtilities::GetFontSize(element);
  365. case Property::REM:
  366. return property->value.Get< float >() * ElementUtilities::GetFontSize(element->GetOwnerDocument());
  367. case Property::DP:
  368. return property->value.Get< float >() * ElementUtilities::GetDensityIndependentPixelRatio(element);
  369. }
  370. // Values based on pixels-per-inch.
  371. if (property->unit & Property::PPI_UNIT)
  372. {
  373. float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
  374. switch (property->unit)
  375. {
  376. case Property::INCH: // inch
  377. return inch;
  378. case Property::CM: // centimeter
  379. return inch * (1.0f / 2.54f);
  380. case Property::MM: // millimeter
  381. return inch * (1.0f / 25.4f);
  382. case Property::PT: // point
  383. return inch * (1.0f / 72.0f);
  384. case Property::PC: // pica
  385. return inch * (1.0f / 6.0f);
  386. }
  387. }
  388. // We're not a numeric property; return 0.
  389. return 0.0f;
  390. }
  391. float ElementStyle::ResolveAngle(const Property * property)
  392. {
  393. switch (property->unit)
  394. {
  395. case Property::NUMBER:
  396. case Property::DEG:
  397. return Math::DegreesToRadians(property->value.Get< float >());
  398. case Property::RAD:
  399. return property->value.Get< float >();
  400. case Property::PERCENT:
  401. return property->value.Get< float >() * 0.01f * 2.0f * Math::ROCKET_PI;
  402. }
  403. ROCKET_ERRORMSG("Trying to resolve angle on a non-angle property.");
  404. return 0.0f;
  405. }
  406. float ElementStyle::ResolveNumericProperty(const String& property_name, const Property * property)
  407. {
  408. if ((property->unit & Property::LENGTH) && !(property->unit == Property::EM && property_name == FONT_SIZE))
  409. {
  410. return ResolveLength(property);
  411. }
  412. auto definition = property->definition;
  413. if (!definition) definition = StyleSheetSpecification::GetProperty(property_name);
  414. if (!definition) return 0.0f;
  415. auto relative_target = definition->GetRelativeTarget();
  416. return ResolveNumericProperty(property, relative_target);
  417. }
  418. float ElementStyle::ResolveNumericProperty(const Property * property, RelativeTarget relative_target)
  419. {
  420. // There is an exception on font-size properties, as 'em' units here refer to parent font size instead
  421. if ((property->unit & Property::LENGTH) && !(property->unit == Property::EM && relative_target == RelativeTarget::ParentFontSize))
  422. {
  423. return ResolveLength(property);
  424. }
  425. float base_value = 0.0f;
  426. switch (relative_target)
  427. {
  428. case RelativeTarget::None:
  429. base_value = 1.0f;
  430. break;
  431. case RelativeTarget::ContainingBlockWidth:
  432. base_value = element->GetContainingBlock().x;
  433. break;
  434. case RelativeTarget::ContainingBlockHeight:
  435. base_value = element->GetContainingBlock().y;
  436. break;
  437. case RelativeTarget::FontSize:
  438. base_value = (float)ElementUtilities::GetFontSize(element);
  439. break;
  440. case RelativeTarget::ParentFontSize:
  441. base_value = (float)ElementUtilities::GetFontSize(element->GetParentNode());
  442. break;
  443. case RelativeTarget::LineHeight:
  444. base_value = (float)ElementUtilities::GetLineHeight(element);
  445. break;
  446. default:
  447. break;
  448. }
  449. float scale_value = 0.0f;
  450. switch (property->unit)
  451. {
  452. case Property::EM:
  453. case Property::NUMBER:
  454. scale_value = property->value.Get< float >();
  455. break;
  456. case Property::PERCENT:
  457. scale_value = property->value.Get< float >() * 0.01f;
  458. break;
  459. }
  460. return base_value * scale_value;
  461. }
  462. // Resolves one of this element's properties.
  463. float ElementStyle::ResolveProperty(const Property* property, float base_value)
  464. {
  465. if (!property)
  466. {
  467. ROCKET_ERROR;
  468. return 0.0f;
  469. }
  470. switch (property->unit)
  471. {
  472. case Property::NUMBER:
  473. case Property::PX:
  474. case Property::RAD:
  475. return property->value.Get< float >();
  476. case Property::PERCENT:
  477. return base_value * property->value.Get< float >() * 0.01f;
  478. case Property::EM:
  479. return property->value.Get< float >() * (float)ElementUtilities::GetFontSize(element);
  480. case Property::REM:
  481. return property->value.Get< float >() * (float)ElementUtilities::GetFontSize(element->GetOwnerDocument());
  482. case Property::DP:
  483. return property->value.Get< float >() * ElementUtilities::GetDensityIndependentPixelRatio(element);
  484. case Property::DEG:
  485. return Math::DegreesToRadians(property->value.Get< float >());
  486. }
  487. // Values based on pixels-per-inch.
  488. if (property->unit & Property::PPI_UNIT)
  489. {
  490. float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
  491. switch (property->unit)
  492. {
  493. case Property::INCH: // inch
  494. return inch;
  495. case Property::CM: // centimeter
  496. return inch * (1.0f / 2.54f);
  497. case Property::MM: // millimeter
  498. return inch * (1.0f / 25.4f);
  499. case Property::PT: // point
  500. return inch * (1.0f / 72.0f);
  501. case Property::PC: // pica
  502. return inch * (1.0f / 6.0f);
  503. }
  504. }
  505. // We're not a numeric property; return 0.
  506. return 0.0f;
  507. }
  508. // Resolves one of this element's properties.
  509. float ElementStyle::ResolveProperty(const String& name, float base_value)
  510. {
  511. const Property* property = GetProperty(name);
  512. if (!property)
  513. {
  514. ROCKET_ERROR;
  515. return 0.0f;
  516. }
  517. // The calculated value of the font-size property is inherited, so we need to check if this
  518. // is an inherited property. If so, then we return our parent's font size instead.
  519. if (name == FONT_SIZE && property->unit & Property::RELATIVE_UNIT)
  520. {
  521. // If the rem unit is used, the font-size is inherited directly from the document,
  522. // otherwise we use the parent's font size.
  523. if (property->unit & Property::REM)
  524. {
  525. Rocket::Core::ElementDocument* owner_document = element->GetOwnerDocument();
  526. if (owner_document == NULL)
  527. return 0;
  528. base_value = owner_document->ResolveProperty(FONT_SIZE, 0);
  529. }
  530. else
  531. {
  532. Rocket::Core::Element* parent = element->GetParentNode();
  533. if (parent == NULL)
  534. return 0;
  535. if (GetLocalProperty(FONT_SIZE) == NULL)
  536. return parent->ResolveProperty(FONT_SIZE, 0);
  537. // The base value for font size is always the height of *this* element's parent's font.
  538. base_value = parent->ResolveProperty(FONT_SIZE, 0);
  539. }
  540. switch (property->unit)
  541. {
  542. case Property::PERCENT:
  543. return base_value * property->value.Get< float >() * 0.01f;
  544. case Property::EM:
  545. return property->value.Get< float >() * base_value;
  546. case Property::REM:
  547. // If an rem-relative font size is specified, it is expressed relative to the document's
  548. // font height.
  549. return property->value.Get< float >() * ElementUtilities::GetFontSize(element->GetOwnerDocument());
  550. }
  551. }
  552. return ResolveProperty(property, base_value);
  553. }
  554. // Iterates over the properties defined on the element.
  555. bool ElementStyle::IterateProperties(int& index, String& name, const Property*& property, const PseudoClassList** property_pseudo_classes)
  556. {
  557. // First check for locally defined properties.
  558. if (local_properties != NULL)
  559. {
  560. if (index < local_properties->GetNumProperties())
  561. {
  562. PropertyMap::const_iterator i = local_properties->GetProperties().begin();
  563. for (int count = 0; count < index; ++count)
  564. ++i;
  565. name = (*i).first;
  566. property = &((*i).second);
  567. if (property_pseudo_classes)
  568. * property_pseudo_classes = nullptr;
  569. ++index;
  570. return true;
  571. }
  572. }
  573. const ElementDefinition* definition = GetDefinition();
  574. if (definition != NULL)
  575. {
  576. int index_offset = 0;
  577. if (local_properties != NULL)
  578. index_offset = local_properties->GetNumProperties();
  579. // Offset the index to be relative to the definition before we start indexing. When we do get a property back,
  580. // check that it hasn't been overridden by the element's local properties; if so, continue on to the next one.
  581. index -= index_offset;
  582. while (definition->IterateProperties(index, pseudo_classes, name, property, property_pseudo_classes))
  583. {
  584. if (local_properties == NULL ||
  585. local_properties->GetProperty(name) == NULL)
  586. {
  587. index += index_offset;
  588. return true;
  589. }
  590. }
  591. return false;
  592. }
  593. return false;
  594. }
  595. // Returns the active style sheet for this element. This may be NULL.
  596. StyleSheet* ElementStyle::GetStyleSheet() const
  597. {
  598. ElementDocument* document = element->GetOwnerDocument();
  599. if (document != NULL)
  600. return document->GetStyleSheet();
  601. return NULL;
  602. }
  603. void ElementStyle::DirtyDefinition()
  604. {
  605. definition_dirty = true;
  606. DirtyChildDefinitions();
  607. }
  608. void ElementStyle::DirtyChildDefinitions()
  609. {
  610. for (int i = 0; i < element->GetNumChildren(true); i++)
  611. element->GetChild(i)->GetStyle()->DirtyDefinition();
  612. }
  613. // Dirties every property.
  614. void ElementStyle::DirtyProperties()
  615. {
  616. const PropertyNameList &properties = StyleSheetSpecification::GetRegisteredProperties();
  617. DirtyProperties(properties);
  618. }
  619. // Dirties em-relative properties.
  620. void ElementStyle::DirtyEmProperties()
  621. {
  622. if (!em_properties)
  623. {
  624. // Check if any of these are currently em-relative. If so, dirty them.
  625. em_properties = new PropertyNameList;
  626. for (auto& property : StyleSheetSpecification::GetRegisteredProperties())
  627. {
  628. // Skip font-size; this is relative to our parent's em, not ours.
  629. if (property == FONT_SIZE)
  630. continue;
  631. // Get this property from this element. If this is em-relative, then add it to the list to
  632. // dirty.
  633. if (element->GetProperty(property)->unit == Property::EM)
  634. em_properties->insert(property);
  635. }
  636. }
  637. if (!em_properties->empty())
  638. DirtyProperties(*em_properties, false);
  639. // Now dirty all of our descendant's font-size properties that are relative to ems.
  640. int num_children = element->GetNumChildren(true);
  641. for (int i = 0; i < num_children; ++i)
  642. element->GetChild(i)->GetStyle()->DirtyInheritedEmProperties();
  643. }
  644. // Dirties font-size on child elements if appropriate.
  645. void ElementStyle::DirtyInheritedEmProperties()
  646. {
  647. const Property* font_size = element->GetLocalProperty(FONT_SIZE);
  648. if (font_size == NULL)
  649. {
  650. int num_children = element->GetNumChildren(true);
  651. for (int i = 0; i < num_children; ++i)
  652. element->GetChild(i)->GetStyle()->DirtyInheritedEmProperties();
  653. }
  654. else
  655. {
  656. if (font_size->unit & Property::RELATIVE_UNIT)
  657. DirtyProperty(FONT_SIZE);
  658. }
  659. }
  660. // Dirties rem properties.
  661. void ElementStyle::DirtyRemProperties()
  662. {
  663. const PropertyNameList &properties = StyleSheetSpecification::GetRegisteredProperties();
  664. PropertyNameList rem_properties;
  665. // Dirty all the properties of this element that use the rem unit.
  666. for (PropertyNameList::const_iterator list_iterator = properties.begin(); list_iterator != properties.end(); ++list_iterator)
  667. {
  668. if (element->GetProperty(*list_iterator)->unit == Property::REM)
  669. rem_properties.insert(*list_iterator);
  670. }
  671. if (!rem_properties.empty())
  672. DirtyProperties(rem_properties, false);
  673. // Now dirty all of our descendant's properties that use the rem unit.
  674. int num_children = element->GetNumChildren(true);
  675. for (int i = 0; i < num_children; ++i)
  676. element->GetChild(i)->GetStyle()->DirtyRemProperties();
  677. }
  678. void ElementStyle::DirtyDpProperties()
  679. {
  680. const PropertyNameList &properties = StyleSheetSpecification::GetRegisteredProperties();
  681. PropertyNameList dp_properties;
  682. // Dirty all the properties of this element that use the dp unit.
  683. for (PropertyNameList::const_iterator list_iterator = properties.begin(); list_iterator != properties.end(); ++list_iterator)
  684. {
  685. if (element->GetProperty(*list_iterator)->unit == Property::DP)
  686. dp_properties.insert(*list_iterator);
  687. }
  688. if (!dp_properties.empty())
  689. DirtyProperties(dp_properties, false);
  690. // Now dirty all of our descendant's properties that use the dp unit.
  691. int num_children = element->GetNumChildren(true);
  692. for (int i = 0; i < num_children; ++i)
  693. element->GetChild(i)->GetStyle()->DirtyDpProperties();
  694. }
  695. // Sets a single property as dirty.
  696. void ElementStyle::DirtyProperty(const String& property)
  697. {
  698. PropertyNameList properties;
  699. properties.insert(String(property));
  700. DirtyProperties(properties);
  701. }
  702. // Sets a list of properties as dirty.
  703. void ElementStyle::DirtyProperties(const PropertyNameList& properties, bool clear_em_properties)
  704. {
  705. if (properties.empty())
  706. return;
  707. bool all_inherited_dirty =
  708. &properties == &StyleSheetSpecification::GetRegisteredProperties() ||
  709. StyleSheetSpecification::GetRegisteredProperties() == properties ||
  710. StyleSheetSpecification::GetRegisteredInheritedProperties() == properties;
  711. if (all_inherited_dirty)
  712. {
  713. const PropertyNameList &all_inherited_properties = StyleSheetSpecification::GetRegisteredInheritedProperties();
  714. for (int i = 0; i < element->GetNumChildren(true); i++)
  715. element->GetChild(i)->GetStyle()->DirtyInheritedProperties(all_inherited_properties);
  716. }
  717. else
  718. {
  719. PropertyNameList inherited_properties;
  720. for (PropertyNameList::const_iterator i = properties.begin(); i != properties.end(); ++i)
  721. {
  722. // If this property is an inherited property, then push it into the list to be passed onto our children.
  723. const PropertyDefinition* property = StyleSheetSpecification::GetProperty(*i);
  724. if (property != NULL &&
  725. property->IsInherited())
  726. inherited_properties.insert(*i);
  727. }
  728. // Pass the list of those properties that are inherited onto our children.
  729. if (!inherited_properties.empty())
  730. {
  731. for (int i = 0; i < element->GetNumChildren(true); i++)
  732. element->GetChild(i)->GetStyle()->DirtyInheritedProperties(inherited_properties);
  733. }
  734. }
  735. // Clear all cached properties.
  736. cache->Clear();
  737. cache->ClearInherited();
  738. // clear the list of EM-properties, we will refill it in DirtyEmProperties
  739. if (clear_em_properties && em_properties != NULL)
  740. {
  741. delete em_properties;
  742. em_properties = NULL;
  743. }
  744. // And send the event.
  745. element->DirtyProperties(properties);
  746. }
  747. // Sets a list of our potentially inherited properties as dirtied by an ancestor.
  748. void ElementStyle::DirtyInheritedProperties(const PropertyNameList& properties)
  749. {
  750. bool clear_em_properties = em_properties != NULL;
  751. PropertyNameList inherited_properties;
  752. for (PropertyNameList::const_iterator i = properties.begin(); i != properties.end(); ++i)
  753. {
  754. const Property *property = GetLocalProperty((*i));
  755. if (property == NULL)
  756. {
  757. inherited_properties.insert(*i);
  758. if (!clear_em_properties && em_properties != NULL && em_properties->find((*i)) != em_properties->end()) {
  759. clear_em_properties = true;
  760. }
  761. }
  762. }
  763. if (inherited_properties.empty())
  764. return;
  765. // clear the list of EM-properties, we will refill it in DirtyEmProperties
  766. if (clear_em_properties && em_properties != NULL)
  767. {
  768. delete em_properties;
  769. em_properties = NULL;
  770. }
  771. // Clear cached inherited properties.
  772. cache->ClearInherited();
  773. // Pass the list of those properties that this element doesn't override onto our children.
  774. for (int i = 0; i < element->GetNumChildren(true); i++)
  775. element->GetChild(i)->GetStyle()->DirtyInheritedProperties(inherited_properties);
  776. element->DirtyProperties(properties);
  777. }
  778. void ElementStyle::GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right )
  779. {
  780. cache->GetOffsetProperties(top, bottom, left, right);
  781. }
  782. void ElementStyle::GetBorderWidthProperties(const Property **border_top_width, const Property **border_bottom_width, const Property **border_left_width, const Property **bottom_right_width)
  783. {
  784. cache->GetBorderWidthProperties(border_top_width, border_bottom_width, border_left_width, bottom_right_width);
  785. }
  786. void ElementStyle::GetMarginProperties(const Property **margin_top, const Property **margin_bottom, const Property **margin_left, const Property **margin_right)
  787. {
  788. cache->GetMarginProperties(margin_top, margin_bottom, margin_left, margin_right);
  789. }
  790. void ElementStyle::GetPaddingProperties(const Property **padding_top, const Property **padding_bottom, const Property **padding_left, const Property **padding_right)
  791. {
  792. cache->GetPaddingProperties(padding_top, padding_bottom, padding_left, padding_right);
  793. }
  794. void ElementStyle::GetDimensionProperties(const Property **width, const Property **height)
  795. {
  796. cache->GetDimensionProperties(width, height);
  797. }
  798. void ElementStyle::GetLocalDimensionProperties(const Property **width, const Property **height)
  799. {
  800. cache->GetLocalDimensionProperties(width, height);
  801. }
  802. void ElementStyle::GetOverflow(int *overflow_x, int *overflow_y)
  803. {
  804. cache->GetOverflow(overflow_x, overflow_y);
  805. }
  806. int ElementStyle::GetPosition()
  807. {
  808. return cache->GetPosition();
  809. }
  810. int ElementStyle::GetFloat()
  811. {
  812. return cache->GetFloat();
  813. }
  814. int ElementStyle::GetDisplay()
  815. {
  816. return cache->GetDisplay();
  817. }
  818. int ElementStyle::GetWhitespace()
  819. {
  820. return cache->GetWhitespace();
  821. }
  822. int ElementStyle::GetPointerEvents()
  823. {
  824. return cache->GetPointerEvents();
  825. }
  826. const Property *ElementStyle::GetLineHeightProperty()
  827. {
  828. return cache->GetLineHeightProperty();
  829. }
  830. int ElementStyle::GetTextAlign()
  831. {
  832. return cache->GetTextAlign();
  833. }
  834. int ElementStyle::GetTextTransform()
  835. {
  836. return cache->GetTextTransform();
  837. }
  838. const Property *ElementStyle::GetVerticalAlignProperty()
  839. {
  840. return cache->GetVerticalAlignProperty();
  841. }
  842. // Returns 'perspective' property value from element's style or local cache.
  843. const Property *ElementStyle::GetPerspective()
  844. {
  845. return element->GetProperty(PERSPECTIVE);
  846. }
  847. // Returns 'perspective-origin-x' property value from element's style or local cache.
  848. const Property *ElementStyle::GetPerspectiveOriginX()
  849. {
  850. return element->GetProperty(PERSPECTIVE_ORIGIN_X);
  851. }
  852. // Returns 'perspective-origin-y' property value from element's style or local cache.
  853. const Property *ElementStyle::GetPerspectiveOriginY()
  854. {
  855. return element->GetProperty(PERSPECTIVE_ORIGIN_Y);
  856. }
  857. // Returns 'transform' property value from element's style or local cache.
  858. const Property *ElementStyle::GetTransform()
  859. {
  860. return element->GetProperty(TRANSFORM);
  861. }
  862. // Returns 'transform-origin-x' property value from element's style or local cache.
  863. const Property *ElementStyle::GetTransformOriginX()
  864. {
  865. return element->GetProperty(TRANSFORM_ORIGIN_X);
  866. }
  867. // Returns 'transform-origin-y' property value from element's style or local cache.
  868. const Property *ElementStyle::GetTransformOriginY()
  869. {
  870. return element->GetProperty(TRANSFORM_ORIGIN_Y);
  871. }
  872. // Returns 'transform-origin-z' property value from element's style or local cache.
  873. const Property *ElementStyle::GetTransformOriginZ()
  874. {
  875. return element->GetProperty(TRANSFORM_ORIGIN_Z);
  876. }
  877. static float ComputeLength(const Property* property, float font_size, float document_font_size, float dp_ratio, float pixels_per_inch)
  878. {
  879. // Note that percentages are not lengths! They have to be resolved elsewhere.
  880. if (!property)
  881. {
  882. ROCKET_ERROR;
  883. return 0.0f;
  884. }
  885. switch (property->unit)
  886. {
  887. case Property::NUMBER:
  888. case Property::PX:
  889. case Property::RAD:
  890. return property->value.Get< float >();
  891. case Property::EM:
  892. return property->value.Get< float >() * font_size;
  893. case Property::REM:
  894. return property->value.Get< float >() * document_font_size;
  895. case Property::DP:
  896. return property->value.Get< float >() * dp_ratio;
  897. case Property::DEG:
  898. return Math::DegreesToRadians(property->value.Get< float >());
  899. default:
  900. break;
  901. }
  902. // Values based on pixels-per-inch.
  903. if (property->unit & Property::PPI_UNIT)
  904. {
  905. float inch = property->value.Get< float >() * pixels_per_inch;
  906. switch (property->unit)
  907. {
  908. case Property::INCH: // inch
  909. return inch;
  910. case Property::CM: // centimeter
  911. return inch * (1.0f / 2.54f);
  912. case Property::MM: // millimeter
  913. return inch * (1.0f / 25.4f);
  914. case Property::PT: // point
  915. return inch * (1.0f / 72.0f);
  916. case Property::PC: // pica
  917. return inch * (1.0f / 6.0f);
  918. default:
  919. break;
  920. }
  921. }
  922. // We're not a numeric property; return 0.
  923. return 0.0f;
  924. }
  925. static float ComputeAbsoluteLength(const Property& property, float dp_ratio, float pixels_per_inch)
  926. {
  927. ROCKET_ASSERT(property.unit & Property::ABSOLUTE_LENGTH);
  928. switch (property.unit)
  929. {
  930. case Property::PX:
  931. return property.value.Get< float >();
  932. case Property::DP:
  933. return property.value.Get< float >()* dp_ratio;
  934. default:
  935. // Values based on pixels-per-inch.
  936. if (property.unit & Property::PPI_UNIT)
  937. {
  938. float inch = property.value.Get< float >() * pixels_per_inch;
  939. switch (property.unit)
  940. {
  941. case Property::INCH: // inch
  942. return inch;
  943. case Property::CM: // centimeter
  944. return inch * (1.0f / 2.54f);
  945. case Property::MM: // millimeter
  946. return inch * (1.0f / 25.4f);
  947. case Property::PT: // point
  948. return inch * (1.0f / 72.0f);
  949. case Property::PC: // pica
  950. return inch * (1.0f / 6.0f);
  951. }
  952. }
  953. }
  954. ROCKET_ERROR;
  955. return 0.0f;
  956. }
  957. // Resolves one of this element's properties.
  958. static float ComputeFontsize(const Property& property, const Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, float dp_ratio, float pixels_per_inch)
  959. {
  960. // The calculated value of the font-size property is inherited, so we need to check if this
  961. // is an inherited property. If so, then we return our parent's font size instead.
  962. if (property.unit & Property::RELATIVE_UNIT)
  963. {
  964. float multiplier = 1.0f;
  965. switch (property.unit)
  966. {
  967. case Property::PERCENT:
  968. multiplier = 0.01f;
  969. [[fallthrough]];
  970. case Property::EM:
  971. if (!parent_values)
  972. return 0;
  973. return property.value.Get< float >() * multiplier * parent_values->font_size;
  974. case Property::REM:
  975. if (!document_values)
  976. return 0;
  977. // If the current element is a document, the rem unit is relative to the default size
  978. if(&values == document_values)
  979. return property.value.Get< float >() * DefaultComputedValues.font_size;
  980. // Otherwise it is relative to the document font size
  981. return property.value.Get< float >() * document_values->font_size;
  982. default:
  983. ROCKET_ERRORMSG("A relative unit must be percentage, em or rem.");
  984. }
  985. }
  986. return ComputeAbsoluteLength(property, dp_ratio, pixels_per_inch);
  987. }
  988. static inline Style::Clip ComputeClip(const Property* property)
  989. {
  990. int value = property->Get<int>();
  991. if (property->unit == Property::KEYWORD)
  992. return (value == CLIP_NONE ? Style::Clip::None : Style::Clip::Auto);
  993. else if (property->unit == Property::NUMBER)
  994. return (Style::Clip)value;
  995. ROCKET_ERRORMSG("Invalid clip type");
  996. return Style::Clip::Auto;
  997. }
  998. static inline LengthPercentage ComputeLengthPercentage(const Property* property, float font_size, float document_font_size, float dp_ratio, float pixels_per_inch)
  999. {
  1000. if (property->unit & Property::PERCENT)
  1001. return LengthPercentage(LengthPercentage::Percentage, property->Get<float>());
  1002. return LengthPercentage(LengthPercentage::Length, ComputeLength(property, font_size, document_font_size, dp_ratio, pixels_per_inch));
  1003. }
  1004. static inline LengthPercentageAuto ComputeLengthPercentageAuto(const Property* property, float font_size, float document_font_size, float dp_ratio, float pixels_per_inch)
  1005. {
  1006. // Assuming here that 'auto' is the only possible keyword
  1007. if (property->unit & Property::PERCENT)
  1008. return LengthPercentageAuto(LengthPercentageAuto::Percentage, property->Get<float>());
  1009. else if (property->unit & Property::KEYWORD)
  1010. return LengthPercentageAuto(LengthPercentageAuto::Auto);
  1011. return LengthPercentageAuto(LengthPercentageAuto::Length, ComputeLength(property, font_size, document_font_size, dp_ratio, pixels_per_inch));
  1012. }
  1013. // Must be called in correct order, from document root to children elements.
  1014. void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, float dp_ratio, float pixels_per_inch)
  1015. {
  1016. // TODO: Iterate through dirty values, and compute corresponding properties.
  1017. // Important: Always do font-size first if dirty, because of em-relative values.
  1018. // Whenever the font-size changes, we need to dirty all properties making use of em!
  1019. if (auto p = GetLocalProperty(FONT_SIZE))
  1020. values.font_size = ComputeFontsize(*p, values, parent_values, document_values, dp_ratio, pixels_per_inch);
  1021. else if (parent_values)
  1022. values.font_size = parent_values->font_size;
  1023. const float font_size = values.font_size;
  1024. const float document_font_size = (document_values ? document_values->font_size : DefaultComputedValues.font_size);
  1025. if (parent_values)
  1026. {
  1027. // Properties that are inherited if not defined locally
  1028. values.font_family = parent_values->font_family;
  1029. values.font_charset = parent_values->font_charset;
  1030. values.font_style = parent_values->font_style;
  1031. values.font_weight = parent_values->font_weight;
  1032. values.text_decoration = parent_values->text_decoration;
  1033. values.clip = parent_values->clip;
  1034. values.opacity = parent_values->opacity;
  1035. values.color = parent_values->color;
  1036. values.focus = parent_values->focus;
  1037. }
  1038. int index = 0;
  1039. String name;
  1040. const Property* p = nullptr;
  1041. while (IterateProperties(index, name, p))
  1042. {
  1043. // @performance: Can use a switch-case with constexpr hashing function
  1044. if (name == FONT_FAMILY)
  1045. values.font_family = p->Get<String>();
  1046. else if (name == FONT_CHARSET)
  1047. values.font_charset = p->Get<String>();
  1048. else if (name == FONT_STYLE)
  1049. values.font_style = (Style::FontStyle)p->Get< int >();
  1050. else if (name == FONT_WEIGHT)
  1051. values.font_weight = (Style::FontWeight)p->Get< int >();
  1052. else if (name == TEXT_DECORATION)
  1053. values.text_decoration = (Style::TextDecoration)p->Get< int >();
  1054. else if (name == OVERFLOW_X)
  1055. values.overflow_x = (Style::Overflow)p->Get< int >();
  1056. else if (name == OVERFLOW_Y)
  1057. values.overflow_y = (Style::Overflow)p->Get< int >();
  1058. else if (name == CLIP)
  1059. values.clip = ComputeClip(p);
  1060. else if (name == VISIBILITY)
  1061. values.visibility = (Style::Visibility)p->Get< int >();
  1062. else if (name == OPACITY)
  1063. values.opacity = p->Get<float>();
  1064. else if (name == BACKGROUND_COLOR)
  1065. values.background_color = p->Get<Colourb>();
  1066. else if (name == IMAGE_COLOR)
  1067. values.image_color = p->Get<Colourb>();
  1068. else if (name == COLOR)
  1069. values.color = p->Get<Colourb>();
  1070. else if (name == MARGIN_TOP)
  1071. values.margin_top = ComputeLengthPercentageAuto(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1072. else if (name == MARGIN_RIGHT)
  1073. values.margin_right = ComputeLengthPercentageAuto(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1074. else if (name == MARGIN_BOTTOM)
  1075. values.margin_bottom = ComputeLengthPercentageAuto(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1076. else if (name == MARGIN_LEFT)
  1077. values.margin_top = ComputeLengthPercentageAuto(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1078. else if (name == PADDING_TOP)
  1079. values.padding_top = ComputeLengthPercentage(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1080. else if (name == PADDING_RIGHT)
  1081. values.padding_right = ComputeLengthPercentage(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1082. else if (name == PADDING_BOTTOM)
  1083. values.padding_bottom = ComputeLengthPercentage(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1084. else if (name == PADDING_LEFT)
  1085. values.padding_top = ComputeLengthPercentage(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1086. else if (name == BORDER_TOP_WIDTH)
  1087. values.border_top_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1088. else if (name == BORDER_RIGHT_WIDTH)
  1089. values.border_right_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1090. else if (name == BORDER_BOTTOM_WIDTH)
  1091. values.border_bottom_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1092. else if (name == BORDER_LEFT_WIDTH)
  1093. values.border_top_width = ComputeLength(p, font_size, document_font_size, dp_ratio, pixels_per_inch);
  1094. else if (name == FOCUS)
  1095. values.focus = (Style::Focus)p->Get<int>();
  1096. else if (name == Z_INDEX)
  1097. values.z_index = (p->unit == Property::KEYWORD ? NumberAuto(NumberAuto::Auto) : NumberAuto(NumberAuto::Number, p->Get<float>()));
  1098. }
  1099. }
  1100. }
  1101. }