ElementInfo.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 "ElementInfo.h"
  29. #include "../../Include/RmlUi/Core/Core.h"
  30. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  31. #include "../../Include/RmlUi/Core/ElementText.h"
  32. #include "../../Include/RmlUi/Core/Factory.h"
  33. #include "../../Include/RmlUi/Core/Property.h"
  34. #include "../../Include/RmlUi/Core/PropertiesIteratorView.h"
  35. #include "../../Include/RmlUi/Core/StyleSheet.h"
  36. #include "../../Include/RmlUi/Core/StyleSheetSpecification.h"
  37. #include "../../Include/RmlUi/Core/SystemInterface.h"
  38. #include "../../Include/RmlUi/Core/PropertyDefinition.h"
  39. #include "Geometry.h"
  40. #include "CommonSource.h"
  41. #include "InfoSource.h"
  42. #include <algorithm>
  43. namespace Rml {
  44. namespace Debugger {
  45. ElementInfo::ElementInfo(const String& tag) : ElementDocument(tag)
  46. {
  47. hover_element = nullptr;
  48. source_element = nullptr;
  49. enable_element_select = true;
  50. show_source_element = true;
  51. update_source_element = true;
  52. force_update_once = false;
  53. title_dirty = true;
  54. previous_update_time = 0.0;
  55. }
  56. ElementInfo::~ElementInfo()
  57. {
  58. }
  59. // Initialises the info element.
  60. bool ElementInfo::Initialise()
  61. {
  62. SetInnerRML(info_rml);
  63. SetId("rmlui-debug-info");
  64. AddEventListener(EventId::Click, this);
  65. AddEventListener(EventId::Mouseover, this);
  66. AddEventListener(EventId::Mouseout, this);
  67. SharedPtr<StyleSheet> style_sheet = Factory::InstanceStyleSheetString(String(common_rcss) + String(info_rcss));
  68. if (!style_sheet)
  69. return false;
  70. SetStyleSheet(std::move(style_sheet));
  71. return true;
  72. }
  73. // Clears the element references.
  74. void ElementInfo::Reset()
  75. {
  76. hover_element = nullptr;
  77. show_source_element = true;
  78. update_source_element = true;
  79. SetSourceElement(nullptr);
  80. }
  81. void ElementInfo::OnUpdate()
  82. {
  83. if (source_element && (update_source_element || force_update_once) && IsVisible())
  84. {
  85. const double t = GetSystemInterface()->GetElapsedTime();
  86. const float dt = (float)(t - previous_update_time);
  87. constexpr float update_interval = 0.3f;
  88. if (dt > update_interval || (force_update_once))
  89. {
  90. if (force_update_once && source_element)
  91. {
  92. // Since an update is being forced, it is possibly because we are reacting to an event and made some changes.
  93. // Update the source element's document to reflect any recent changes.
  94. if (auto document = source_element->GetOwnerDocument())
  95. document->UpdateDocument();
  96. }
  97. force_update_once = false;
  98. UpdateSourceElement();
  99. }
  100. }
  101. if (title_dirty)
  102. {
  103. UpdateTitle();
  104. title_dirty = false;
  105. }
  106. }
  107. // Called when an element is destroyed.
  108. void ElementInfo::OnElementDestroy(Element* element)
  109. {
  110. if (hover_element == element)
  111. hover_element = nullptr;
  112. if (source_element == element)
  113. source_element = nullptr;
  114. }
  115. void ElementInfo::RenderHoverElement()
  116. {
  117. if (hover_element)
  118. {
  119. ElementUtilities::ApplyTransform(*hover_element);
  120. for (int i = 0; i < hover_element->GetNumBoxes(); i++)
  121. {
  122. // Render the content area.
  123. const Box element_box = hover_element->GetBox(i);
  124. Vector2f size = element_box.GetSize(Box::BORDER);
  125. size = Vector2f(std::max(size.x, 2.0f), std::max(size.y, 2.0f));
  126. Geometry::RenderOutline(
  127. hover_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::BORDER),
  128. size,
  129. Colourb(255, 0, 0, 255),
  130. 1
  131. );
  132. }
  133. }
  134. }
  135. void ElementInfo::RenderSourceElement()
  136. {
  137. if (source_element && show_source_element)
  138. {
  139. ElementUtilities::ApplyTransform(*source_element);
  140. for (int i = 0; i < source_element->GetNumBoxes(); i++)
  141. {
  142. const Box element_box = source_element->GetBox(i);
  143. // Content area:
  144. Geometry::RenderBox(source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::CONTENT), element_box.GetSize(), Colourb(158, 214, 237, 128));
  145. // Padding area:
  146. Geometry::RenderBox(source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::PADDING), element_box.GetSize(Box::PADDING), source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::CONTENT), element_box.GetSize(), Colourb(135, 122, 214, 128));
  147. // Border area:
  148. Geometry::RenderBox(source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::BORDER), element_box.GetSize(Box::BORDER), source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::PADDING), element_box.GetSize(Box::PADDING), Colourb(133, 133, 133, 128));
  149. // Border area:
  150. Geometry::RenderBox(source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::MARGIN), element_box.GetSize(Box::MARGIN), source_element->GetAbsoluteOffset(Box::BORDER) + element_box.GetPosition(Box::BORDER), element_box.GetSize(Box::BORDER), Colourb(240, 255, 131, 128));
  151. }
  152. }
  153. }
  154. void ElementInfo::ProcessEvent(Event& event)
  155. {
  156. // Only process events if we're visible
  157. if (IsVisible())
  158. {
  159. if (event == EventId::Click)
  160. {
  161. Element* target_element = event.GetTargetElement();
  162. // Deal with clicks on our own elements differently.
  163. if (target_element->GetOwnerDocument() == this)
  164. {
  165. const String& id = event.GetTargetElement()->GetId();
  166. if (id == "close_button")
  167. {
  168. if (IsVisible())
  169. SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
  170. }
  171. else if (id == "update_source")
  172. {
  173. update_source_element = !update_source_element;
  174. target_element->SetClass("active", update_source_element);
  175. }
  176. else if (id == "show_source")
  177. {
  178. show_source_element = !target_element->IsClassSet("active");;
  179. target_element->SetClass("active", show_source_element);
  180. }
  181. else if (id == "enable_element_select")
  182. {
  183. enable_element_select = !target_element->IsClassSet("active");;
  184. target_element->SetClass("active", enable_element_select);
  185. }
  186. else if (target_element->GetTagName() == "pseudo" && source_element)
  187. {
  188. const String name = target_element->GetAttribute<String>("name", "");
  189. if (!name.empty())
  190. {
  191. bool pseudo_active = target_element->IsClassSet("active");
  192. if (name == "focus")
  193. {
  194. if (!pseudo_active)
  195. source_element->Focus();
  196. else if (auto document = source_element->GetOwnerDocument())
  197. document->Focus();
  198. }
  199. else
  200. {
  201. source_element->SetPseudoClass(name, !pseudo_active);
  202. }
  203. force_update_once = true;
  204. }
  205. }
  206. else if (id == "offset_parent")
  207. {
  208. if (source_element)
  209. {
  210. Element* offset_parent = source_element->GetOffsetParent();
  211. if (offset_parent)
  212. SetSourceElement(offset_parent);
  213. }
  214. }
  215. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  216. else
  217. {
  218. int element_index;
  219. if (sscanf(target_element->GetId().c_str(), "a %d", &element_index) == 1)
  220. {
  221. Element* new_source_element = source_element;
  222. for (int i = 0; i < element_index; i++)
  223. {
  224. if (new_source_element != nullptr)
  225. new_source_element = new_source_element->GetParentNode();
  226. }
  227. SetSourceElement(new_source_element);
  228. }
  229. else if (sscanf(target_element->GetId().c_str(), "c %d", &element_index) == 1)
  230. {
  231. if (source_element != nullptr)
  232. SetSourceElement(source_element->GetChild(element_index));
  233. }
  234. }
  235. event.StopPropagation();
  236. }
  237. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  238. else if (enable_element_select && target_element->GetOwnerDocument() != nullptr && !IsDebuggerElement(target_element))
  239. {
  240. Element* new_source_element = target_element;
  241. if (new_source_element != source_element)
  242. {
  243. SetSourceElement(new_source_element);
  244. event.StopPropagation();
  245. }
  246. }
  247. }
  248. else if (event == EventId::Mouseover)
  249. {
  250. Element* target_element = event.GetTargetElement();
  251. ElementDocument* owner_document = target_element->GetOwnerDocument();
  252. if (owner_document == this)
  253. {
  254. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  255. const String& id = target_element->GetId();
  256. int element_index;
  257. if (sscanf(id.c_str(), "a %d", &element_index) == 1)
  258. {
  259. hover_element = source_element;
  260. for (int i = 0; i < element_index; i++)
  261. {
  262. if (hover_element != nullptr)
  263. hover_element = hover_element->GetParentNode();
  264. }
  265. }
  266. else if (sscanf(id.c_str(), "c %d", &element_index) == 1)
  267. {
  268. if (source_element != nullptr)
  269. hover_element = source_element->GetChild(element_index);
  270. }
  271. else if (id == "offset_parent")
  272. {
  273. if (source_element)
  274. hover_element = source_element->GetOffsetParent();
  275. }
  276. else
  277. {
  278. hover_element = nullptr;
  279. }
  280. if (id == "show_source" && !show_source_element)
  281. {
  282. // Preview the source element view while hovering
  283. show_source_element = true;
  284. }
  285. if (id == "show_source" || id == "update_source" || id == "enable_element_select")
  286. {
  287. title_dirty = true;
  288. }
  289. }
  290. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  291. else if (enable_element_select && owner_document != nullptr && owner_document->GetId().find("rmlui-debug-") != 0)
  292. {
  293. hover_element = target_element;
  294. }
  295. }
  296. else if (event == EventId::Mouseout)
  297. {
  298. Element* target_element = event.GetTargetElement();
  299. ElementDocument* owner_document = target_element->GetOwnerDocument();
  300. if (owner_document == this)
  301. {
  302. const String& id = target_element->GetId();
  303. if (id == "show_source")
  304. {
  305. // Disable the preview of the source element view
  306. if (show_source_element && !target_element->IsClassSet("active"))
  307. show_source_element = false;
  308. }
  309. if (id == "show_source" || id == "update_source" || id == "enable_element_select")
  310. {
  311. title_dirty = true;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. void ElementInfo::SetSourceElement(Element* new_source_element)
  318. {
  319. source_element = new_source_element;
  320. force_update_once = true;
  321. }
  322. void ElementInfo::UpdateSourceElement()
  323. {
  324. previous_update_time = GetSystemInterface()->GetElapsedTime();
  325. title_dirty = true;
  326. // Set the pseudo classes
  327. if (Element* pseudo = GetElementById("pseudo"))
  328. {
  329. PseudoClassList list;
  330. if (source_element)
  331. list = source_element->GetActivePseudoClasses();
  332. // There are some fixed pseudo classes that we always show and iterate through to determine if they are set.
  333. // We also want to show other pseudo classes when they are set, they are added under the #extra element last.
  334. for (int i = 0; i < pseudo->GetNumChildren(); i++)
  335. {
  336. Element* child = pseudo->GetChild(i);
  337. const String name = child->GetAttribute<String>("name", "");
  338. if (!name.empty())
  339. {
  340. bool active = (list.erase(name) == 1);
  341. child->SetClass("active", active);
  342. }
  343. else if(child->GetId() == "extra")
  344. {
  345. // First, we iterate through the extra elements and remove those that are no longer active.
  346. for (int j = 0; j < child->GetNumChildren(); j++)
  347. {
  348. Element* grandchild = child->GetChild(j);
  349. const String grandchild_name = grandchild->GetAttribute<String>("name", "");
  350. bool active = (list.erase(grandchild_name) == 1);
  351. if(!active)
  352. child->RemoveChild(grandchild);
  353. }
  354. // Finally, create new pseudo buttons for the rest of the active pseudo classes.
  355. for (auto& extra_pseudo : list)
  356. {
  357. Element* grandchild = child->AppendChild(CreateElement("pseudo"));
  358. grandchild->SetClass("active", true);
  359. grandchild->SetAttribute("name", extra_pseudo);
  360. grandchild->SetInnerRML(":" + extra_pseudo);
  361. }
  362. }
  363. }
  364. }
  365. // Set the attributes
  366. if (Element* attributes_content = GetElementById("attributes-content"))
  367. {
  368. String attributes;
  369. if (source_element != nullptr)
  370. {
  371. {
  372. String name;
  373. String value;
  374. // The element's attribute list is not always synchronized with its internal values, fetch
  375. // them manually here (see e.g. Element::OnAttributeChange for relevant attributes)
  376. {
  377. name = "id";
  378. value = source_element->GetId();
  379. if (!value.empty())
  380. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  381. }
  382. {
  383. name = "class";
  384. value = source_element->GetClassNames();
  385. if (!value.empty())
  386. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  387. }
  388. }
  389. for(const auto& pair : source_element->GetAttributes())
  390. {
  391. auto& name = pair.first;
  392. auto& variant = pair.second;
  393. String value = StringUtilities::EncodeRml(variant.Get<String>());
  394. if(name != "class" && name != "style" && name != "id")
  395. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  396. }
  397. // Text is not an attribute but useful nonetheless
  398. if (auto text_element = rmlui_dynamic_cast<ElementText*>(source_element))
  399. {
  400. const String& text_content = text_element->GetText();
  401. attributes += CreateString(text_content.size() + 32, "Text: <em>%s</em><br />", text_content.c_str());
  402. }
  403. }
  404. if (attributes.empty())
  405. {
  406. while (attributes_content->HasChildNodes())
  407. attributes_content->RemoveChild(attributes_content->GetChild(0));
  408. attributes_rml.clear();
  409. }
  410. else if (attributes != attributes_rml)
  411. {
  412. attributes_content->SetInnerRML(attributes);
  413. attributes_rml = std::move(attributes);
  414. }
  415. }
  416. // Set the properties
  417. if (Element* properties_content = GetElementById("properties-content"))
  418. {
  419. String properties;
  420. if (source_element != nullptr)
  421. BuildElementPropertiesRML(properties, source_element, source_element);
  422. if (properties.empty())
  423. {
  424. while (properties_content->HasChildNodes())
  425. properties_content->RemoveChild(properties_content->GetChild(0));
  426. properties_rml.clear();
  427. }
  428. else if (properties != properties_rml)
  429. {
  430. properties_content->SetInnerRML(properties);
  431. properties_rml = std::move(properties);
  432. }
  433. }
  434. // Set the events
  435. if (Element* events_content = GetElementById("events-content"))
  436. {
  437. String events;
  438. if (source_element != nullptr)
  439. {
  440. events = source_element->GetEventDispatcherSummary();
  441. }
  442. if (events.empty())
  443. {
  444. while (events_content->HasChildNodes())
  445. events_content->RemoveChild(events_content->GetChild(0));
  446. events_rml.clear();
  447. }
  448. else if (events != events_rml)
  449. {
  450. events_content->SetInnerRML(events);
  451. events_rml = std::move(events);
  452. }
  453. }
  454. // Set the position
  455. if (Element* position_content = GetElementById("position-content"))
  456. {
  457. String position;
  458. // left, top, width, height.
  459. if (source_element != nullptr)
  460. {
  461. const Vector2f element_offset = source_element->GetRelativeOffset(Box::BORDER);
  462. const Vector2f element_size = source_element->GetBox().GetSize(Box::BORDER);
  463. Element* offset_parent = source_element->GetOffsetParent();
  464. const String offset_parent_rml = (offset_parent ? StringUtilities::EncodeRml(offset_parent->GetAddress(false, false)) : String("<em>none</em>"));
  465. position =
  466. "<span class='name'>left: </span><em>" + ToString(element_offset.x) + "px</em><br/>" +
  467. "<span class='name'>top: </span><em>" + ToString(element_offset.y) + "px</em><br/>" +
  468. "<span class='name'>width: </span><em>" + ToString(element_size.x) + "px</em><br/>" +
  469. "<span class='name'>height: </span><em>" + ToString(element_size.y) + "px</em><br/>" +
  470. "<span class='name'>offset parent: </span><p style='display: inline' id='offset_parent'>" + offset_parent_rml + "</p>";
  471. }
  472. else
  473. {
  474. while (position_content->HasChildNodes())
  475. position_content->RemoveChild(position_content->GetFirstChild());
  476. }
  477. if (position.empty())
  478. {
  479. while (position_content->HasChildNodes())
  480. position_content->RemoveChild(position_content->GetFirstChild());
  481. position_rml.clear();
  482. }
  483. else if (position != position_rml)
  484. {
  485. position_content->SetInnerRML(position);
  486. position_rml = std::move(position);
  487. }
  488. }
  489. // Set the ancestors
  490. if (Element* ancestors_content = GetElementById("ancestors-content"))
  491. {
  492. String ancestors;
  493. Element* element_ancestor = nullptr;
  494. if (source_element != nullptr)
  495. element_ancestor = source_element->GetParentNode();
  496. int ancestor_depth = 1;
  497. while (element_ancestor)
  498. {
  499. String ancestor_name = element_ancestor->GetAddress(false, false);
  500. ancestors += CreateString(ancestor_name.size() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.c_str());
  501. element_ancestor = element_ancestor->GetParentNode();
  502. ancestor_depth++;
  503. }
  504. if (ancestors.empty())
  505. {
  506. while (ancestors_content->HasChildNodes())
  507. ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
  508. ancestors_rml.clear();
  509. }
  510. else if (ancestors != ancestors_rml)
  511. {
  512. ancestors_content->SetInnerRML(ancestors);
  513. ancestors_rml = std::move(ancestors);
  514. }
  515. }
  516. // Set the children
  517. if (Element* children_content = GetElementById("children-content"))
  518. {
  519. String children;
  520. if (source_element != nullptr)
  521. {
  522. const int num_dom_children = (source_element->GetNumChildren(false));
  523. for (int i = 0; i < source_element->GetNumChildren(true); i++)
  524. {
  525. Element* child = source_element->GetChild(i);
  526. // If this is a debugger document, do not show it.
  527. if (IsDebuggerElement(child))
  528. continue;
  529. String child_name = child->GetTagName();
  530. const String child_id = child->GetId();
  531. if (!child_id.empty())
  532. {
  533. child_name += "#";
  534. child_name += child_id;
  535. }
  536. const char* non_dom_string = (i >= num_dom_children ? " class=\"non_dom\"" : "");
  537. children += CreateString(child_name.size() + 40, "<p id=\"c %d\"%s>%s</p>", i, non_dom_string, child_name.c_str());
  538. }
  539. }
  540. if (children.empty())
  541. {
  542. while (children_content->HasChildNodes())
  543. children_content->RemoveChild(children_content->GetChild(0));
  544. children_rml.clear();
  545. }
  546. else if(children != children_rml)
  547. {
  548. children_content->SetInnerRML(children);
  549. children_rml = std::move(children);
  550. }
  551. }
  552. }
  553. void ElementInfo::BuildElementPropertiesRML(String& property_rml, Element* element, Element* primary_element)
  554. {
  555. NamedPropertyList property_list;
  556. for(auto it = element->IterateLocalProperties(); !it.AtEnd(); ++it)
  557. {
  558. PropertyId property_id = it.GetId();
  559. const String& property_name = it.GetName();
  560. const Property* prop = &it.GetProperty();
  561. // Check that this property isn't overridden or just not inherited.
  562. if (primary_element->GetProperty(property_id) != prop)
  563. continue;
  564. property_list.push_back(NamedProperty{ property_name, prop });
  565. }
  566. std::sort(property_list.begin(), property_list.end(),
  567. [](const NamedProperty& a, const NamedProperty& b) {
  568. if (a.second->source && !b.second->source) return false;
  569. if (!a.second->source && b.second->source) return true;
  570. if (a.second->specificity < b.second->specificity) return false;
  571. if (a.second->specificity > b.second->specificity) return true;
  572. if (a.second->definition && !b.second->definition) return false;
  573. if (!a.second->definition && b.second->definition) return true;
  574. const String& a_name = StyleSheetSpecification::GetPropertyName(a.second->definition->GetId());
  575. const String& b_name = StyleSheetSpecification::GetPropertyName(b.second->definition->GetId());
  576. return a_name < b_name;
  577. }
  578. );
  579. if (!property_list.empty())
  580. {
  581. // Print the 'inherited from ...' header if we're not the primary element.
  582. if (element != primary_element)
  583. {
  584. property_rml += "<h3 class='strong'>inherited from " + element->GetAddress(false, false) + "</h3>";
  585. }
  586. const PropertySource* previous_source = nullptr;
  587. bool first_iteration = true;
  588. for (auto& named_property : property_list)
  589. {
  590. auto& source = named_property.second->source;
  591. if(source.get() != previous_source || first_iteration)
  592. {
  593. previous_source = source.get();
  594. first_iteration = false;
  595. // Print the rule name header.
  596. if (source)
  597. {
  598. String str_line_number;
  599. TypeConverter<int, String>::Convert(source->line_number, str_line_number);
  600. property_rml += "<h3>" + source->rule_name + "</h3>";
  601. property_rml += "<h4>" + source->path + " : " + str_line_number + "</h4>";
  602. }
  603. else
  604. {
  605. property_rml += "<h3><em>inline</em></h3>";
  606. }
  607. }
  608. BuildPropertyRML(property_rml, named_property.first, named_property.second);
  609. }
  610. }
  611. if (element->GetParentNode() != nullptr)
  612. BuildElementPropertiesRML(property_rml, element->GetParentNode(), primary_element);
  613. }
  614. void ElementInfo::BuildPropertyRML(String& property_rml, const String& name, const Property* property)
  615. {
  616. const String property_value = property->ToString();
  617. property_rml += "<span class='name'>" + name + "</span>: " + property_value + "<br/>";
  618. }
  619. void ElementInfo::UpdateTitle()
  620. {
  621. auto title_content = GetElementById("title-content");
  622. auto enable_select = GetElementById("enable_element_select");
  623. auto show_source = GetElementById("show_source");
  624. auto update_source = GetElementById("update_source");
  625. if (title_content && enable_select && show_source && update_source)
  626. {
  627. if (enable_select->IsPseudoClassSet("hover"))
  628. title_content->SetInnerRML("<em>(select elements)</em>");
  629. else if (show_source->IsPseudoClassSet("hover"))
  630. title_content->SetInnerRML("<em>(draw element dimensions)</em>");
  631. else if (update_source->IsPseudoClassSet("hover"))
  632. title_content->SetInnerRML("<em>(update info continuously)</em>");
  633. else if (source_element)
  634. title_content->SetInnerRML(source_element->GetTagName());
  635. else
  636. title_content->SetInnerRML("Element Information");
  637. }
  638. }
  639. bool ElementInfo::IsDebuggerElement(Element* element)
  640. {
  641. return element->GetOwnerDocument()->GetId().find("rmlui-debug-") == 0;
  642. }
  643. }
  644. }