ElementInfo.cpp 20 KB

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