ElementInfo.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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.h"
  30. #include "../../Include/RmlUi/Core/Property.h"
  31. #include "../../Include/RmlUi/Core/PropertiesIteratorView.h"
  32. #include "../../Include/RmlUi/Core/Factory.h"
  33. #include "../../Include/RmlUi/Core/StyleSheet.h"
  34. #include "../../Include/RmlUi/Core/StyleSheetSpecification.h"
  35. #include "Geometry.h"
  36. #include "CommonSource.h"
  37. #include "InfoSource.h"
  38. namespace Rml {
  39. namespace Debugger {
  40. static void PrettyFormatNumbers(Core::String& string)
  41. {
  42. // Removes trailing zeros and truncates decimal digits to the specified number of significant digits.
  43. constexpr int num_significant_digits = 4;
  44. if (string.empty())
  45. return;
  46. // First, check for a decimal point. No point, no chance of trailing zeroes!
  47. size_t decimal_point_position = 0;
  48. while ((decimal_point_position = string.find('.', decimal_point_position + 1)) != Core::String::npos)
  49. {
  50. // Find the left-most digit.
  51. int pos_left = (int)decimal_point_position - 1; // non-inclusive
  52. while (pos_left >= 0 && string[pos_left] >= '0' && string[pos_left] <= '9')
  53. pos_left--;
  54. // Significant digits left of the decimal point. We also consider all zero digits significant on the left side.
  55. const int significant_left = (int)decimal_point_position - (pos_left + 1);
  56. // Let's not touch numbers that don't start with a digit before the decimal.
  57. if (significant_left == 0)
  58. continue;
  59. const int max_significant_right = std::max(num_significant_digits - significant_left, 0);
  60. // Find the right-most digit and number of non-zero digits less than our maximum.
  61. int pos_right = (int)decimal_point_position + 1; // non-inclusive
  62. int significant_right = 0;
  63. while (pos_right < (int)string.size() && string[pos_right] >= '0' && string[pos_right] <= '9')
  64. {
  65. const int current_digit_right = pos_right - (int)decimal_point_position;
  66. if (string[pos_right] != '0' && current_digit_right <= max_significant_right)
  67. significant_right = current_digit_right;
  68. pos_right++;
  69. }
  70. size_t pos_cut_start = decimal_point_position + (size_t)(significant_right + 1);
  71. size_t pos_cut_end = (size_t)pos_right;
  72. // Remove the decimal point if we don't have any right digits.
  73. if (pos_cut_start == decimal_point_position + 1)
  74. pos_cut_start = decimal_point_position;
  75. string.erase(string.begin() + pos_cut_start, string.begin() + pos_cut_end);
  76. }
  77. return;
  78. }
  79. static bool TestPrettyFormat(Core::String string, Core::String should_be)
  80. {
  81. Core::String original = string;
  82. PrettyFormatNumbers(string);
  83. bool result = (string == should_be);
  84. if (!result)
  85. Core::Log::Message(Core::Log::LT_ERROR, "Remove trailing string failed. PrettyFormatNumbers('%s') == '%s' != '%s'", original.c_str(), string.c_str(), should_be.c_str());
  86. return result;
  87. }
  88. ElementInfo::ElementInfo(const Core::String& tag) : Core::ElementDocument(tag)
  89. {
  90. hover_element = nullptr;
  91. source_element = nullptr;
  92. previous_update_time = 0.0;
  93. RMLUI_ASSERT(TestPrettyFormat("0.15", "0.15"));
  94. RMLUI_ASSERT(TestPrettyFormat("0.150", "0.15"));
  95. RMLUI_ASSERT(TestPrettyFormat("1.15", "1.15"));
  96. RMLUI_ASSERT(TestPrettyFormat("1.150", "1.15"));
  97. RMLUI_ASSERT(TestPrettyFormat("123.15", "123.1"));
  98. RMLUI_ASSERT(TestPrettyFormat("1234.5", "1234"));
  99. RMLUI_ASSERT(TestPrettyFormat("12.15", "12.15"));
  100. RMLUI_ASSERT(TestPrettyFormat("12.154", "12.15"));
  101. RMLUI_ASSERT(TestPrettyFormat("12.154666", "12.15"));
  102. RMLUI_ASSERT(TestPrettyFormat("15889", "15889"));
  103. RMLUI_ASSERT(TestPrettyFormat("15889.1", "15889"));
  104. RMLUI_ASSERT(TestPrettyFormat("0.00660", "0.006"));
  105. RMLUI_ASSERT(TestPrettyFormat("0.000001", "0"));
  106. RMLUI_ASSERT(TestPrettyFormat("0.00000100", "0"));
  107. RMLUI_ASSERT(TestPrettyFormat("a .", "a ."));
  108. RMLUI_ASSERT(TestPrettyFormat("a .0", "a .0"));
  109. RMLUI_ASSERT(TestPrettyFormat("a 0.0", "a 0"));
  110. RMLUI_ASSERT(TestPrettyFormat("hello.world: 14.5600 1.1 0.55623 more.values: 0.1544 0.", "hello.world: 14.56 1.1 0.556 more.values: 0.154 0"));
  111. }
  112. ElementInfo::~ElementInfo()
  113. {
  114. }
  115. // Initialises the info element.
  116. bool ElementInfo::Initialise()
  117. {
  118. SetInnerRML(info_rml);
  119. SetId("rmlui-debug-info");
  120. AddEventListener(Core::EventId::Click, this);
  121. AddEventListener(Core::EventId::Mouseover, this);
  122. Core::SharedPtr<Core::StyleSheet> style_sheet = Core::Factory::InstanceStyleSheetString(Core::String(common_rcss) + Core::String(info_rcss));
  123. if (!style_sheet)
  124. return false;
  125. SetStyleSheet(std::move(style_sheet));
  126. return true;
  127. }
  128. // Clears the element references.
  129. void ElementInfo::Reset()
  130. {
  131. hover_element = nullptr;
  132. SetSourceElement(nullptr);
  133. }
  134. void ElementInfo::OnUpdate()
  135. {
  136. if (source_element && IsVisible())
  137. {
  138. const double t = Core::GetSystemInterface()->GetElapsedTime();
  139. const float dt = (float)(t - previous_update_time);
  140. constexpr float update_interval = 0.3f;
  141. if (dt > update_interval)
  142. {
  143. UpdateSourceElement();
  144. }
  145. }
  146. }
  147. // Called when an element is destroyed.
  148. void ElementInfo::OnElementDestroy(Core::Element* element)
  149. {
  150. if (hover_element == element)
  151. hover_element = nullptr;
  152. if (source_element == element)
  153. source_element = nullptr;
  154. }
  155. void ElementInfo::RenderHoverElement()
  156. {
  157. if (hover_element)
  158. {
  159. Core::ElementUtilities::ApplyTransform(*hover_element);
  160. for (int i = 0; i < hover_element->GetNumBoxes(); i++)
  161. {
  162. // Render the content area.
  163. const Core::Box element_box = hover_element->GetBox(i);
  164. Geometry::RenderOutline(
  165. hover_element->GetAbsoluteOffset(Core::Box::BORDER) + element_box.GetPosition(Core::Box::BORDER),
  166. element_box.GetSize(Core::Box::BORDER),
  167. Core::Colourb(255, 0, 0, 255),
  168. 1
  169. );
  170. }
  171. Core::ElementUtilities::UnapplyTransform(*hover_element);
  172. }
  173. }
  174. void ElementInfo::RenderSourceElement()
  175. {
  176. if (source_element)
  177. {
  178. Core::ElementUtilities::ApplyTransform(*source_element);
  179. for (int i = 0; i < source_element->GetNumBoxes(); i++)
  180. {
  181. const Core::Box element_box = source_element->GetBox(i);
  182. // Content area:
  183. Geometry::RenderBox(source_element->GetAbsoluteOffset(Core::Box::BORDER) + element_box.GetPosition(Core::Box::CONTENT), element_box.GetSize(), Core::Colourb(158, 214, 237, 128));
  184. // Padding area:
  185. 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));
  186. // Border area:
  187. 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));
  188. // Border area:
  189. 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));
  190. }
  191. Core::ElementUtilities::UnapplyTransform(*source_element);
  192. }
  193. }
  194. void ElementInfo::ProcessEvent(Core::Event& event)
  195. {
  196. // Only process events if we're visible
  197. if (IsVisible())
  198. {
  199. if (event == Core::EventId::Click)
  200. {
  201. Core::Element* target_element = event.GetTargetElement();
  202. // Deal with clicks on our own elements differently.
  203. if (target_element->GetOwnerDocument() == this)
  204. {
  205. // If it's a pane title, then we need to toggle the visibility of its sibling (the contents pane underneath it).
  206. if (target_element->GetTagName() == "h2")
  207. {
  208. Core::Element* panel = target_element->GetNextSibling();
  209. if (panel->IsVisible())
  210. panel->SetProperty(Core::PropertyId::Display, Core::Property(Core::Style::Display::None));
  211. else
  212. panel->SetProperty(Core::PropertyId::Display, Core::Property(Core::Style::Display::Block));
  213. event.StopPropagation();
  214. }
  215. else if (event.GetTargetElement()->GetId() == "close_button")
  216. {
  217. if (IsVisible())
  218. SetProperty(Core::PropertyId::Visibility, Core::Property(Core::Style::Visibility::Hidden));
  219. }
  220. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  221. else
  222. {
  223. int element_index;
  224. if (sscanf(target_element->GetId().c_str(), "a %d", &element_index) == 1)
  225. {
  226. Core::Element* new_source_element = source_element;
  227. for (int i = 0; i < element_index; i++)
  228. {
  229. if (new_source_element != nullptr)
  230. new_source_element = new_source_element->GetParentNode();
  231. }
  232. SetSourceElement(new_source_element);
  233. }
  234. else if (sscanf(target_element->GetId().c_str(), "c %d", &element_index) == 1)
  235. {
  236. if (source_element != nullptr)
  237. SetSourceElement(source_element->GetChild(element_index));
  238. }
  239. event.StopPropagation();
  240. }
  241. }
  242. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  243. else if (target_element->GetOwnerDocument() != nullptr && !IsDebuggerElement(target_element))
  244. {
  245. Core::Element* new_source_element = target_element;
  246. if (new_source_element != source_element)
  247. {
  248. SetSourceElement(new_source_element);
  249. event.StopPropagation();
  250. }
  251. }
  252. }
  253. else if (event == Core::EventId::Mouseover)
  254. {
  255. Core::Element* target_element = event.GetTargetElement();
  256. // Deal with clicks on our own elements differently.
  257. Core::ElementDocument* owner_document = target_element->GetOwnerDocument();
  258. if (owner_document == this)
  259. {
  260. // Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
  261. int element_index;
  262. if (sscanf(target_element->GetId().c_str(), "a %d", &element_index) == 1)
  263. {
  264. hover_element = source_element;
  265. for (int i = 0; i < element_index; i++)
  266. {
  267. if (hover_element != nullptr)
  268. hover_element = hover_element->GetParentNode();
  269. }
  270. }
  271. else if (sscanf(target_element->GetId().c_str(), "c %d", &element_index) == 1)
  272. {
  273. if (source_element != nullptr)
  274. hover_element = source_element->GetChild(element_index);
  275. }
  276. }
  277. // Otherwise we just want to focus on the clicked element (unless it's on a debug element)
  278. else if (owner_document != nullptr && owner_document->GetId().find("rmlui-debug-") != 0)
  279. {
  280. hover_element = target_element;
  281. }
  282. }
  283. }
  284. }
  285. void ElementInfo::SetSourceElement(Core::Element* new_source_element)
  286. {
  287. source_element = new_source_element;
  288. UpdateSourceElement();
  289. }
  290. void ElementInfo::UpdateSourceElement()
  291. {
  292. previous_update_time = Core::GetSystemInterface()->GetElapsedTime();
  293. // Set the title:
  294. Core::Element* title_content = GetElementById("title-content");
  295. if (title_content != nullptr)
  296. {
  297. if (source_element != nullptr)
  298. title_content->SetInnerRML(source_element->GetTagName());
  299. else
  300. title_content->SetInnerRML("Element Information");
  301. }
  302. // Set the attributes:
  303. Core::Element* attributes_content = GetElementById("attributes-content");
  304. if (attributes_content)
  305. {
  306. Core::String attributes;
  307. if (source_element != nullptr)
  308. {
  309. {
  310. Core::String name;
  311. Core::String value;
  312. // The element's attribute list is not always synchronized with its internal values, fetch
  313. // them manually here (see e.g. Element::OnAttributeChange for relevant attributes)
  314. {
  315. name = "id";
  316. value = source_element->GetId();
  317. if (!value.empty())
  318. attributes += Core::CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  319. }
  320. {
  321. name = "class";
  322. value = source_element->GetClassNames();
  323. if (!value.empty())
  324. attributes += Core::CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  325. }
  326. {
  327. // Not actually an attribute, but may be useful
  328. name = "pseudo";
  329. value.clear();
  330. for (auto str : source_element->GetActivePseudoClasses())
  331. value += " :" + str;
  332. if (!value.empty())
  333. attributes += Core::CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  334. }
  335. }
  336. for(const auto& pair : source_element->GetAttributes())
  337. {
  338. auto& name = pair.first;
  339. auto& variant = pair.second;
  340. Core::String value = variant.Get<Core::String>();
  341. if(name != "class" && name != "style" && name != "id")
  342. attributes += Core::CreateString(name.size() + value.size() + 32, "%s: <em>%s</em><br />", name.c_str(), value.c_str());
  343. }
  344. }
  345. if (attributes.empty())
  346. {
  347. while (attributes_content->HasChildNodes())
  348. attributes_content->RemoveChild(attributes_content->GetChild(0));
  349. attributes_rml.clear();
  350. }
  351. else if (attributes != attributes_rml)
  352. {
  353. attributes_content->SetInnerRML(attributes);
  354. attributes_rml = std::move(attributes);
  355. }
  356. }
  357. // Set the properties:
  358. Core::Element* properties_content = GetElementById("properties-content");
  359. if (properties_content)
  360. {
  361. Core::String properties;
  362. if (source_element != nullptr)
  363. BuildElementPropertiesRML(properties, source_element, source_element);
  364. if (properties.empty())
  365. {
  366. while (properties_content->HasChildNodes())
  367. properties_content->RemoveChild(properties_content->GetChild(0));
  368. properties_rml.clear();
  369. }
  370. else if (properties != properties_rml)
  371. {
  372. properties_content->SetInnerRML(properties);
  373. properties_rml = std::move(properties);
  374. }
  375. }
  376. // Set the events:
  377. Core::Element* events_content = GetElementById("events-content");
  378. if (events_content)
  379. {
  380. Core::String events;
  381. if (source_element != nullptr)
  382. {
  383. events = source_element->GetEventDispatcherSummary();
  384. }
  385. if (events.empty())
  386. {
  387. while (events_content->HasChildNodes())
  388. events_content->RemoveChild(events_content->GetChild(0));
  389. events_rml.clear();
  390. }
  391. else if (events != events_rml)
  392. {
  393. events_content->SetInnerRML(events);
  394. events_rml = std::move(events);
  395. }
  396. }
  397. // Set the position:
  398. Core::Element* position_content = GetElementById("position-content");
  399. if (position_content)
  400. {
  401. // left, top, width, height.
  402. if (source_element != nullptr)
  403. {
  404. Core::Vector2f element_offset = source_element->GetRelativeOffset(Core::Box::BORDER);
  405. Core::Vector2f element_size = source_element->GetBox().GetSize(Core::Box::BORDER);
  406. Core::String positions;
  407. positions += Core::CreateString(64, "left: <em>%.0fpx</em><br />", element_offset.x);
  408. positions += Core::CreateString(64, "top: <em>%.0fpx</em><br />", element_offset.y);
  409. positions += Core::CreateString(64, "width: <em>%.0fpx</em><br />", element_size.x);
  410. positions += Core::CreateString(64, "height: <em>%.0fpx</em><br />", element_size.y);
  411. position_content->SetInnerRML(positions);
  412. }
  413. else
  414. {
  415. while (position_content->HasChildNodes())
  416. position_content->RemoveChild(position_content->GetFirstChild());
  417. }
  418. }
  419. // Set the ancestors:
  420. Core::Element* ancestors_content = GetElementById("ancestors-content");
  421. if (ancestors_content)
  422. {
  423. Core::String ancestors;
  424. Core::Element* element_ancestor = nullptr;
  425. if (source_element != nullptr)
  426. element_ancestor = source_element->GetParentNode();
  427. int ancestor_depth = 1;
  428. while (element_ancestor)
  429. {
  430. Core::String ancestor_name = element_ancestor->GetAddress(false, false);
  431. ancestors += Core::CreateString(ancestor_name.size() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.c_str());
  432. element_ancestor = element_ancestor->GetParentNode();
  433. ancestor_depth++;
  434. }
  435. if (ancestors.empty())
  436. {
  437. while (ancestors_content->HasChildNodes())
  438. ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
  439. ancestors_rml.clear();
  440. }
  441. else if (ancestors != ancestors_rml)
  442. {
  443. ancestors_content->SetInnerRML(ancestors);
  444. ancestors_rml = std::move(ancestors);
  445. }
  446. }
  447. // Set the children:
  448. Core::Element* children_content = GetElementById("children-content");
  449. if (children_content)
  450. {
  451. Core::String children;
  452. if (source_element != nullptr)
  453. {
  454. for (int i = 0; i < source_element->GetNumChildren(); i++)
  455. {
  456. Core::Element* child = source_element->GetChild(i);
  457. // If this is a debugger document, do not show it.
  458. if (IsDebuggerElement(child))
  459. continue;
  460. Core::String child_name = child->GetTagName();
  461. const Core::String child_id = child->GetId();
  462. if (!child_id.empty())
  463. {
  464. child_name += "#";
  465. child_name += child_id;
  466. }
  467. children += Core::CreateString(child_name.size() + 32, "<p id=\"c %d\">%s</p>", i, child_name.c_str());
  468. }
  469. }
  470. if (children.empty())
  471. {
  472. while (children_content->HasChildNodes())
  473. children_content->RemoveChild(children_content->GetChild(0));
  474. children_rml.clear();
  475. }
  476. else if(children != children_rml)
  477. {
  478. children_content->SetInnerRML(children);
  479. children_rml = std::move(children);
  480. }
  481. }
  482. }
  483. void ElementInfo::BuildElementPropertiesRML(Core::String& property_rml, Core::Element* element, Core::Element* primary_element)
  484. {
  485. NamedPropertyList property_list;
  486. for(auto it = element->IterateLocalProperties(); !it.AtEnd(); ++it)
  487. {
  488. Core::PropertyId property_id = it.GetId();
  489. const Core::String& property_name = it.GetName();
  490. const Core::Property* prop = &it.GetProperty();
  491. // Check that this property isn't overridden or just not inherited.
  492. if (primary_element->GetLocalProperty(property_id) != prop)
  493. continue;
  494. property_list.push_back(NamedProperty{ property_name, prop });
  495. }
  496. std::sort(property_list.begin(), property_list.end(),
  497. [](const NamedProperty& a, const NamedProperty& b) {
  498. if (a.second->source && !b.second->source) return false;
  499. if (!a.second->source && b.second->source) return true;
  500. return a.second->specificity > b.second->specificity;
  501. }
  502. );
  503. if (!property_list.empty())
  504. {
  505. // Print the 'inherited from ...' header if we're not the primary element.
  506. if (element != primary_element)
  507. {
  508. property_rml += "<h3 class='mark'>inherited from " + element->GetAddress(false, false) + "</h3>";
  509. }
  510. const Core::PropertySource* previous_source = nullptr;
  511. bool first_iteration = true;
  512. for (auto& named_property : property_list)
  513. {
  514. auto& source = named_property.second->source;
  515. if(source.get() != previous_source || first_iteration)
  516. {
  517. previous_source = source.get();
  518. first_iteration = false;
  519. // Print the rule name header.
  520. if(source)
  521. {
  522. Core::String str_line_number;
  523. Core::TypeConverter<int, Core::String>::Convert(source->line_number, str_line_number);
  524. property_rml += "<h3>" + source->rule_name + "</h3>";
  525. property_rml += "<h4>" + source->path + " : " + str_line_number + "</h4>";
  526. }
  527. else
  528. {
  529. property_rml += "<h3><em>inline</em></h3>";
  530. }
  531. }
  532. BuildPropertyRML(property_rml, named_property.first, named_property.second);
  533. }
  534. }
  535. if (element->GetParentNode() != nullptr)
  536. BuildElementPropertiesRML(property_rml, element->GetParentNode(), primary_element);
  537. }
  538. void ElementInfo::BuildPropertyRML(Core::String& property_rml, const Core::String& name, const Core::Property* property)
  539. {
  540. Core::String property_value = property->ToString();
  541. PrettyFormatNumbers(property_value);
  542. property_rml += Core::CreateString(name.size() + property_value.size() + 32, "%s: <em>%s;</em><br />", name.c_str(), property_value.c_str());
  543. }
  544. bool ElementInfo::IsDebuggerElement(Core::Element* element)
  545. {
  546. return element->GetOwnerDocument()->GetId().find("rmlui-debug-") == 0;
  547. }
  548. }
  549. }