ElementInfo.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  207. else
  208. {
  209. int element_index;
  210. if (sscanf(target_element->GetId().c_str(), "a %d", &element_index) == 1)
  211. {
  212. Element* new_source_element = source_element;
  213. for (int i = 0; i < element_index; i++)
  214. {
  215. if (new_source_element != nullptr)
  216. new_source_element = new_source_element->GetParentNode();
  217. }
  218. SetSourceElement(new_source_element);
  219. }
  220. else if (sscanf(target_element->GetId().c_str(), "c %d", &element_index) == 1)
  221. {
  222. if (source_element != nullptr)
  223. SetSourceElement(source_element->GetChild(element_index));
  224. }
  225. }
  226. event.StopPropagation();
  227. }
  228. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  229. else if (enable_element_select && target_element->GetOwnerDocument() != nullptr && !IsDebuggerElement(target_element))
  230. {
  231. Element* new_source_element = target_element;
  232. if (new_source_element != source_element)
  233. {
  234. SetSourceElement(new_source_element);
  235. event.StopPropagation();
  236. }
  237. }
  238. }
  239. else if (event == EventId::Mouseover)
  240. {
  241. Element* target_element = event.GetTargetElement();
  242. ElementDocument* owner_document = target_element->GetOwnerDocument();
  243. if (owner_document == this)
  244. {
  245. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  246. const String& id = target_element->GetId();
  247. int element_index;
  248. if (sscanf(id.c_str(), "a %d", &element_index) == 1)
  249. {
  250. hover_element = source_element;
  251. for (int i = 0; i < element_index; i++)
  252. {
  253. if (hover_element != nullptr)
  254. hover_element = hover_element->GetParentNode();
  255. }
  256. }
  257. else if (sscanf(id.c_str(), "c %d", &element_index) == 1)
  258. {
  259. if (source_element != nullptr)
  260. hover_element = source_element->GetChild(element_index);
  261. }
  262. else
  263. {
  264. hover_element = nullptr;
  265. }
  266. if (id == "show_source" && !show_source_element)
  267. {
  268. // Preview the source element view while hovering
  269. show_source_element = true;
  270. }
  271. if (id == "show_source" || id == "update_source" || id == "enable_element_select")
  272. {
  273. title_dirty = true;
  274. }
  275. }
  276. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  277. else if (enable_element_select && owner_document != nullptr && owner_document->GetId().find("rmlui-debug-") != 0)
  278. {
  279. hover_element = target_element;
  280. }
  281. }
  282. else if (event == EventId::Mouseout)
  283. {
  284. Element* target_element = event.GetTargetElement();
  285. ElementDocument* owner_document = target_element->GetOwnerDocument();
  286. if (owner_document == this)
  287. {
  288. const String& id = target_element->GetId();
  289. if (id == "show_source")
  290. {
  291. // Disable the preview of the source element view
  292. if (show_source_element && !target_element->IsClassSet("active"))
  293. show_source_element = false;
  294. }
  295. if (id == "show_source" || id == "update_source" || id == "enable_element_select")
  296. {
  297. title_dirty = true;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. void ElementInfo::SetSourceElement(Element* new_source_element)
  304. {
  305. source_element = new_source_element;
  306. force_update_once = true;
  307. }
  308. void ElementInfo::UpdateSourceElement()
  309. {
  310. previous_update_time = GetSystemInterface()->GetElapsedTime();
  311. title_dirty = true;
  312. // Set the pseudo classes
  313. if (Element* pseudo = GetElementById("pseudo"))
  314. {
  315. PseudoClassList list;
  316. if (source_element)
  317. list = source_element->GetActivePseudoClasses();
  318. // There are some fixed pseudo classes that we always show and iterate through to determine if they are set.
  319. // We also want to show other pseudo classes when they are set, they are added under the #extra element last.
  320. for (int i = 0; i < pseudo->GetNumChildren(); i++)
  321. {
  322. Element* child = pseudo->GetChild(i);
  323. const String name = child->GetAttribute<String>("name", "");
  324. if (!name.empty())
  325. {
  326. bool active = (list.erase(name) == 1);
  327. child->SetClass("active", active);
  328. }
  329. else if(child->GetId() == "extra")
  330. {
  331. // First, we iterate through the extra elements and remove those that are no longer active.
  332. for (int j = 0; j < child->GetNumChildren(); j++)
  333. {
  334. Element* grandchild = child->GetChild(j);
  335. const String grandchild_name = grandchild->GetAttribute<String>("name", "");
  336. bool active = (list.erase(grandchild_name) == 1);
  337. if(!active)
  338. child->RemoveChild(grandchild);
  339. }
  340. // Finally, create new pseudo buttons for the rest of the active pseudo classes.
  341. for (auto& extra_pseudo : list)
  342. {
  343. Element* grandchild = child->AppendChild(CreateElement("pseudo"));
  344. grandchild->SetClass("active", true);
  345. grandchild->SetAttribute("name", extra_pseudo);
  346. grandchild->SetInnerRML(":" + extra_pseudo);
  347. }
  348. }
  349. }
  350. }
  351. // Set the attributes
  352. if (Element* attributes_content = GetElementById("attributes-content"))
  353. {
  354. String attributes;
  355. if (source_element != nullptr)
  356. {
  357. {
  358. String name;
  359. String value;
  360. // The element's attribute list is not always synchronized with its internal values, fetch
  361. // them manually here (see e.g. Element::OnAttributeChange for relevant attributes)
  362. {
  363. name = "id";
  364. value = source_element->GetId();
  365. if (!value.empty())
  366. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  367. }
  368. {
  369. name = "class";
  370. value = source_element->GetClassNames();
  371. if (!value.empty())
  372. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  373. }
  374. }
  375. for(const auto& pair : source_element->GetAttributes())
  376. {
  377. auto& name = pair.first;
  378. auto& variant = pair.second;
  379. String value = StringUtilities::EncodeRml(variant.Get<String>());
  380. if(name != "class" && name != "style" && name != "id")
  381. attributes += CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  382. }
  383. // Text is not an attribute but useful nonetheless
  384. if (auto text_element = rmlui_dynamic_cast<ElementText*>(source_element))
  385. {
  386. const String& text_content = text_element->GetText();
  387. attributes += CreateString(text_content.size() + 32, "Text: <em>%s</em><br />", text_content.c_str());
  388. }
  389. }
  390. if (attributes.empty())
  391. {
  392. while (attributes_content->HasChildNodes())
  393. attributes_content->RemoveChild(attributes_content->GetChild(0));
  394. attributes_rml.clear();
  395. }
  396. else if (attributes != attributes_rml)
  397. {
  398. attributes_content->SetInnerRML(attributes);
  399. attributes_rml = std::move(attributes);
  400. }
  401. }
  402. // Set the properties
  403. if (Element* properties_content = GetElementById("properties-content"))
  404. {
  405. String properties;
  406. if (source_element != nullptr)
  407. BuildElementPropertiesRML(properties, source_element, source_element);
  408. if (properties.empty())
  409. {
  410. while (properties_content->HasChildNodes())
  411. properties_content->RemoveChild(properties_content->GetChild(0));
  412. properties_rml.clear();
  413. }
  414. else if (properties != properties_rml)
  415. {
  416. properties_content->SetInnerRML(properties);
  417. properties_rml = std::move(properties);
  418. }
  419. }
  420. // Set the events
  421. if (Element* events_content = GetElementById("events-content"))
  422. {
  423. String events;
  424. if (source_element != nullptr)
  425. {
  426. events = source_element->GetEventDispatcherSummary();
  427. }
  428. if (events.empty())
  429. {
  430. while (events_content->HasChildNodes())
  431. events_content->RemoveChild(events_content->GetChild(0));
  432. events_rml.clear();
  433. }
  434. else if (events != events_rml)
  435. {
  436. events_content->SetInnerRML(events);
  437. events_rml = std::move(events);
  438. }
  439. }
  440. // Set the position
  441. if (Element* position_content = GetElementById("position-content"))
  442. {
  443. // left, top, width, height.
  444. if (source_element != nullptr)
  445. {
  446. const Vector2f element_offset = source_element->GetRelativeOffset(Box::BORDER);
  447. const Vector2f element_size = source_element->GetBox().GetSize(Box::BORDER);
  448. const String positions =
  449. "<span class='name'>left: </span><em>" + ToString(element_offset.x) + "px</em><br/>" +
  450. "<span class='name'>top: </span><em>" + ToString(element_offset.y) + "px</em><br/>" +
  451. "<span class='name'>width: </span><em>" + ToString(element_size.x) + "px</em><br/>" +
  452. "<span class='name'>height: </span><em>" + ToString(element_size.y) + "px</em><br/>";
  453. position_content->SetInnerRML( positions );
  454. }
  455. else
  456. {
  457. while (position_content->HasChildNodes())
  458. position_content->RemoveChild(position_content->GetFirstChild());
  459. }
  460. }
  461. // Set the ancestors
  462. if (Element* ancestors_content = GetElementById("ancestors-content"))
  463. {
  464. String ancestors;
  465. Element* element_ancestor = nullptr;
  466. if (source_element != nullptr)
  467. element_ancestor = source_element->GetParentNode();
  468. int ancestor_depth = 1;
  469. while (element_ancestor)
  470. {
  471. String ancestor_name = element_ancestor->GetAddress(false, false);
  472. ancestors += CreateString(ancestor_name.size() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.c_str());
  473. element_ancestor = element_ancestor->GetParentNode();
  474. ancestor_depth++;
  475. }
  476. if (ancestors.empty())
  477. {
  478. while (ancestors_content->HasChildNodes())
  479. ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
  480. ancestors_rml.clear();
  481. }
  482. else if (ancestors != ancestors_rml)
  483. {
  484. ancestors_content->SetInnerRML(ancestors);
  485. ancestors_rml = std::move(ancestors);
  486. }
  487. }
  488. // Set the children
  489. if (Element* children_content = GetElementById("children-content"))
  490. {
  491. String children;
  492. if (source_element != nullptr)
  493. {
  494. const int num_dom_children = (source_element->GetNumChildren(false));
  495. for (int i = 0; i < source_element->GetNumChildren(true); i++)
  496. {
  497. Element* child = source_element->GetChild(i);
  498. // If this is a debugger document, do not show it.
  499. if (IsDebuggerElement(child))
  500. continue;
  501. String child_name = child->GetTagName();
  502. const String child_id = child->GetId();
  503. if (!child_id.empty())
  504. {
  505. child_name += "#";
  506. child_name += child_id;
  507. }
  508. const char* non_dom_string = (i >= num_dom_children ? " class=\"non_dom\"" : "");
  509. children += CreateString(child_name.size() + 40, "<p id=\"c %d\"%s>%s</p>", i, non_dom_string, child_name.c_str());
  510. }
  511. }
  512. if (children.empty())
  513. {
  514. while (children_content->HasChildNodes())
  515. children_content->RemoveChild(children_content->GetChild(0));
  516. children_rml.clear();
  517. }
  518. else if(children != children_rml)
  519. {
  520. children_content->SetInnerRML(children);
  521. children_rml = std::move(children);
  522. }
  523. }
  524. }
  525. void ElementInfo::BuildElementPropertiesRML(String& property_rml, Element* element, Element* primary_element)
  526. {
  527. NamedPropertyList property_list;
  528. for(auto it = element->IterateLocalProperties(); !it.AtEnd(); ++it)
  529. {
  530. PropertyId property_id = it.GetId();
  531. const String& property_name = it.GetName();
  532. const Property* prop = &it.GetProperty();
  533. // Check that this property isn't overridden or just not inherited.
  534. if (primary_element->GetProperty(property_id) != prop)
  535. continue;
  536. property_list.push_back(NamedProperty{ property_name, prop });
  537. }
  538. std::sort(property_list.begin(), property_list.end(),
  539. [](const NamedProperty& a, const NamedProperty& b) {
  540. if (a.second->source && !b.second->source) return false;
  541. if (!a.second->source && b.second->source) return true;
  542. if (a.second->specificity < b.second->specificity) return false;
  543. if (a.second->specificity > b.second->specificity) return true;
  544. if (a.second->definition && !b.second->definition) return false;
  545. if (!a.second->definition && b.second->definition) return true;
  546. const String& a_name = StyleSheetSpecification::GetPropertyName(a.second->definition->GetId());
  547. const String& b_name = StyleSheetSpecification::GetPropertyName(b.second->definition->GetId());
  548. return a_name < b_name;
  549. }
  550. );
  551. if (!property_list.empty())
  552. {
  553. // Print the 'inherited from ...' header if we're not the primary element.
  554. if (element != primary_element)
  555. {
  556. property_rml += "<h3 class='strong'>inherited from " + element->GetAddress(false, false) + "</h3>";
  557. }
  558. const PropertySource* previous_source = nullptr;
  559. bool first_iteration = true;
  560. for (auto& named_property : property_list)
  561. {
  562. auto& source = named_property.second->source;
  563. if(source.get() != previous_source || first_iteration)
  564. {
  565. previous_source = source.get();
  566. first_iteration = false;
  567. // Print the rule name header.
  568. if (source)
  569. {
  570. String str_line_number;
  571. TypeConverter<int, String>::Convert(source->line_number, str_line_number);
  572. property_rml += "<h3>" + source->rule_name + "</h3>";
  573. property_rml += "<h4>" + source->path + " : " + str_line_number + "</h4>";
  574. }
  575. else
  576. {
  577. property_rml += "<h3><em>inline</em></h3>";
  578. }
  579. }
  580. BuildPropertyRML(property_rml, named_property.first, named_property.second);
  581. }
  582. }
  583. if (element->GetParentNode() != nullptr)
  584. BuildElementPropertiesRML(property_rml, element->GetParentNode(), primary_element);
  585. }
  586. void ElementInfo::BuildPropertyRML(String& property_rml, const String& name, const Property* property)
  587. {
  588. const String property_value = property->ToString();
  589. property_rml += "<span class='name'>" + name + "</span>: " + property_value + "<br/>";
  590. }
  591. void ElementInfo::UpdateTitle()
  592. {
  593. auto title_content = GetElementById("title-content");
  594. auto enable_select = GetElementById("enable_element_select");
  595. auto show_source = GetElementById("show_source");
  596. auto update_source = GetElementById("update_source");
  597. if (title_content && enable_select && show_source && update_source)
  598. {
  599. if (enable_select->IsPseudoClassSet("hover"))
  600. title_content->SetInnerRML("<em>(select elements)</em>");
  601. else if (show_source->IsPseudoClassSet("hover"))
  602. title_content->SetInnerRML("<em>(draw element dimensions)</em>");
  603. else if (update_source->IsPseudoClassSet("hover"))
  604. title_content->SetInnerRML("<em>(update info continuously)</em>");
  605. else if (source_element)
  606. title_content->SetInnerRML(source_element->GetTagName());
  607. else
  608. title_content->SetInnerRML("Element Information");
  609. }
  610. }
  611. bool ElementInfo::IsDebuggerElement(Element* element)
  612. {
  613. return element->GetOwnerDocument()->GetId().find("rmlui-debug-") == 0;
  614. }
  615. }
  616. }