ElementInfo.cpp 22 KB

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