Context.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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 "../../Include/RmlUi/Core/Context.h"
  29. #include "../../Include/RmlUi/Core/ContextInstancer.h"
  30. #include "../../Include/RmlUi/Core/Core.h"
  31. #include "../../Include/RmlUi/Core/DataModelHandle.h"
  32. #include "../../Include/RmlUi/Core/ElementDocument.h"
  33. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  34. #include "../../Include/RmlUi/Core/Factory.h"
  35. #include "../../Include/RmlUi/Core/Profiling.h"
  36. #include "../../Include/RmlUi/Core/RenderInterface.h"
  37. #include "../../Include/RmlUi/Core/StreamMemory.h"
  38. #include "../../Include/RmlUi/Core/SystemInterface.h"
  39. #include "../../Include/RmlUi/Core/StreamMemory.h"
  40. #include "DataModel.h"
  41. #include "EventDispatcher.h"
  42. #include "PluginRegistry.h"
  43. #include "StreamFile.h"
  44. #include <algorithm>
  45. #include <iterator>
  46. namespace Rml {
  47. static constexpr float DOUBLE_CLICK_TIME = 0.5f; // [s]
  48. static constexpr float DOUBLE_CLICK_MAX_DIST = 3.f; // [dp]
  49. Context::Context(const String& name) : name(name), dimensions(0, 0), density_independent_pixel_ratio(1.0f), mouse_position(0, 0), clip_origin(-1, -1), clip_dimensions(-1, -1)
  50. {
  51. instancer = nullptr;
  52. // Initialise this to nullptr; this will be set in Rml::CreateContext().
  53. render_interface = nullptr;
  54. root = Factory::InstanceElement(nullptr, "*", "#root", XMLAttributes());
  55. root->SetId(name);
  56. root->SetOffset(Vector2f(0, 0), nullptr);
  57. root->SetProperty(PropertyId::ZIndex, Property(0, Property::NUMBER));
  58. cursor_proxy = Factory::InstanceElement(nullptr, documents_base_tag, documents_base_tag, XMLAttributes());
  59. ElementDocument* cursor_proxy_document = rmlui_dynamic_cast< ElementDocument* >(cursor_proxy.get());
  60. RMLUI_ASSERT(cursor_proxy_document);
  61. cursor_proxy_document->context = this;
  62. enable_cursor = true;
  63. document_focus_history.push_back(root.get());
  64. focus = root.get();
  65. hover = nullptr;
  66. active = nullptr;
  67. drag = nullptr;
  68. drag_started = false;
  69. drag_verbose = false;
  70. drag_clone = nullptr;
  71. drag_hover = nullptr;
  72. last_click_element = nullptr;
  73. last_click_time = 0;
  74. last_click_mouse_position = Vector2i(0, 0);
  75. }
  76. Context::~Context()
  77. {
  78. PluginRegistry::NotifyContextDestroy(this);
  79. UnloadAllDocuments();
  80. ReleaseUnloadedDocuments();
  81. root.reset();
  82. cursor_proxy.reset();
  83. instancer = nullptr;
  84. render_interface = nullptr;
  85. }
  86. // Returns the name of the context.
  87. const String& Context::GetName() const
  88. {
  89. return name;
  90. }
  91. // Changes the dimensions of the screen.
  92. void Context::SetDimensions(const Vector2i _dimensions)
  93. {
  94. if (dimensions != _dimensions)
  95. {
  96. dimensions = _dimensions;
  97. root->SetBox(Box(Vector2f(dimensions)));
  98. root->DirtyLayout();
  99. for (int i = 0; i < root->GetNumChildren(); ++i)
  100. {
  101. ElementDocument* document = root->GetChild(i)->GetOwnerDocument();
  102. if (document != nullptr)
  103. {
  104. document->DirtyMediaQueries();
  105. document->DirtyVwAndVhProperties();
  106. document->DirtyLayout();
  107. document->DirtyPosition();
  108. document->DispatchEvent(EventId::Resize, Dictionary());
  109. }
  110. }
  111. clip_dimensions = dimensions;
  112. }
  113. }
  114. // Returns the dimensions of the screen.
  115. Vector2i Context::GetDimensions() const
  116. {
  117. return dimensions;
  118. }
  119. void Context::SetDensityIndependentPixelRatio(float _density_independent_pixel_ratio)
  120. {
  121. if (density_independent_pixel_ratio != _density_independent_pixel_ratio)
  122. {
  123. density_independent_pixel_ratio = _density_independent_pixel_ratio;
  124. for (int i = 0; i < root->GetNumChildren(true); ++i)
  125. {
  126. ElementDocument* document = root->GetChild(i)->GetOwnerDocument();
  127. if (document)
  128. {
  129. document->DirtyMediaQueries();
  130. document->OnDpRatioChangeRecursive();
  131. }
  132. }
  133. }
  134. }
  135. float Context::GetDensityIndependentPixelRatio() const
  136. {
  137. return density_independent_pixel_ratio;
  138. }
  139. // Updates all elements in the element tree.
  140. bool Context::Update()
  141. {
  142. RMLUI_ZoneScoped;
  143. // Update all data models first
  144. for (auto& data_model : data_models)
  145. data_model.second->Update(true);
  146. root->Update(density_independent_pixel_ratio, Vector2f(dimensions));
  147. for (int i = 0; i < root->GetNumChildren(); ++i)
  148. if (auto doc = root->GetChild(i)->GetOwnerDocument())
  149. {
  150. doc->UpdateLayout();
  151. doc->UpdatePosition();
  152. }
  153. // Release any documents that were unloaded during the update.
  154. ReleaseUnloadedDocuments();
  155. return true;
  156. }
  157. // Renders all visible elements in the element tree.
  158. bool Context::Render()
  159. {
  160. RMLUI_ZoneScoped;
  161. RenderInterface* render_interface = GetRenderInterface();
  162. if (render_interface == nullptr)
  163. return false;
  164. render_interface->context = this;
  165. ElementUtilities::ApplyActiveClipRegion(this, render_interface);
  166. root->Render();
  167. ElementUtilities::SetClippingRegion(nullptr, this);
  168. // Render the cursor proxy so that any attached drag clone will be rendered below the cursor.
  169. if (drag_clone)
  170. {
  171. static_cast<ElementDocument&>(*cursor_proxy).UpdateDocument();
  172. cursor_proxy->SetOffset(Vector2f((float)Math::Clamp(mouse_position.x, 0, dimensions.x),
  173. (float)Math::Clamp(mouse_position.y, 0, dimensions.y)),
  174. nullptr);
  175. cursor_proxy->Render();
  176. }
  177. render_interface->context = nullptr;
  178. return true;
  179. }
  180. // Creates a new, empty document and places it into this context.
  181. ElementDocument* Context::CreateDocument(const String& instancer_name)
  182. {
  183. ElementPtr element = Factory::InstanceElement(nullptr, instancer_name, documents_base_tag, XMLAttributes());
  184. if (!element)
  185. {
  186. Log::Message(Log::LT_ERROR, "Failed to instance document on instancer_name '%s', instancer returned nullptr.", instancer_name.c_str());
  187. return nullptr;
  188. }
  189. ElementDocument* document = rmlui_dynamic_cast< ElementDocument* >(element.get());
  190. if (!document)
  191. {
  192. Log::Message(Log::LT_ERROR, "Failed to instance document on instancer_name '%s', Found type '%s', was expecting derivative of ElementDocument.", instancer_name.c_str(), rmlui_type_name(*element));
  193. return nullptr;
  194. }
  195. document->context = this;
  196. root->AppendChild(std::move(element));
  197. PluginRegistry::NotifyDocumentLoad(document);
  198. return document;
  199. }
  200. // Load a document into the context.
  201. ElementDocument* Context::LoadDocument(const String& document_path)
  202. {
  203. auto stream = MakeUnique<StreamFile>();
  204. if (!stream->Open(document_path))
  205. return nullptr;
  206. ElementDocument* document = LoadDocument(stream.get());
  207. return document;
  208. }
  209. // Load a document into the context.
  210. ElementDocument* Context::LoadDocument(Stream* stream)
  211. {
  212. PluginRegistry::NotifyDocumentOpen(this, stream->GetSourceURL().GetURL());
  213. ElementPtr element = Factory::InstanceDocumentStream(this, stream, GetDocumentsBaseTag());
  214. if (!element)
  215. return nullptr;
  216. ElementDocument* document = static_cast<ElementDocument*>(element.get());
  217. root->AppendChild(std::move(element));
  218. ElementUtilities::BindEventAttributes(document);
  219. // The 'load' event is fired before updating the document, because the user might
  220. // need to initalize things before running an update. The drawback is that computed
  221. // values and layouting are not performed yet, resulting in default values when
  222. // querying such information in the event handler.
  223. PluginRegistry::NotifyDocumentLoad(document);
  224. document->DispatchEvent(EventId::Load, Dictionary());
  225. // Data models are updated after the 'load' event so that the user has a chance to change
  226. // any data variables first. We do not clear dirty variables here, since users may need to
  227. // retrieve whether or not eg. a data variable has changed in a controller.
  228. for (auto& data_model : data_models)
  229. data_model.second->Update(false);
  230. document->UpdateDocument();
  231. return document;
  232. }
  233. // Load a document into the context.
  234. ElementDocument* Context::LoadDocumentFromMemory(const String& string, const String& source_url)
  235. {
  236. // Open the stream based on the string contents.
  237. auto stream = MakeUnique<StreamMemory>((byte*)string.c_str(), string.size());
  238. stream->SetSourceURL( source_url );
  239. // Load the document from the stream.
  240. ElementDocument* document = LoadDocument(stream.get());
  241. return document;
  242. }
  243. // Unload the given document
  244. void Context::UnloadDocument(ElementDocument* _document)
  245. {
  246. // Has this document already been unloaded?
  247. for (size_t i = 0; i < unloaded_documents.size(); ++i)
  248. {
  249. if (unloaded_documents[i].get() == _document)
  250. return;
  251. }
  252. ElementDocument* document = _document;
  253. if (document->GetParentNode() == root.get())
  254. {
  255. // Dispatch the unload notifications.
  256. document->DispatchEvent(EventId::Unload, Dictionary());
  257. PluginRegistry::NotifyDocumentUnload(document);
  258. // Move document to a temporary location to be released later.
  259. unloaded_documents.push_back( root->RemoveChild(document) );
  260. }
  261. // Remove the item from the focus history.
  262. ElementList::iterator itr = std::find(document_focus_history.begin(), document_focus_history.end(), document);
  263. if (itr != document_focus_history.end())
  264. document_focus_history.erase(itr);
  265. // Focus to the previous document if the old document is the current focus.
  266. if (focus && focus->GetOwnerDocument() == document)
  267. {
  268. focus = nullptr;
  269. document_focus_history.back()->GetFocusLeafNode()->Focus();
  270. }
  271. // Clear the active element if the old document is the active element.
  272. if (active && active->GetOwnerDocument() == document)
  273. {
  274. active = nullptr;
  275. }
  276. // Clear other pointers to elements whose owner was deleted
  277. if (drag && drag->GetOwnerDocument() == document)
  278. {
  279. drag = nullptr;
  280. ReleaseDragClone();
  281. }
  282. if (drag_hover && drag_hover->GetOwnerDocument() == document)
  283. {
  284. drag_hover = nullptr;
  285. }
  286. // Rebuild the hover state.
  287. UpdateHoverChain(Dictionary(), Dictionary(), mouse_position);
  288. }
  289. // Unload all the currently loaded documents
  290. void Context::UnloadAllDocuments()
  291. {
  292. // Unload all children.
  293. while (root->GetNumChildren(true) > 0)
  294. UnloadDocument(root->GetChild(0)->GetOwnerDocument());
  295. // The element lists may point to elements that are getting removed.
  296. active_chain.clear();
  297. hover_chain.clear();
  298. drag_hover_chain.clear();
  299. }
  300. // Enables or disables the mouse cursor.
  301. void Context::EnableMouseCursor(bool enable)
  302. {
  303. // The cursor is set to an invalid name so that it is forced to update in the next update loop.
  304. cursor_name = ":reset:";
  305. enable_cursor = enable;
  306. }
  307. void Context::ActivateTheme(const String& theme_name, bool activate)
  308. {
  309. bool theme_changed = false;
  310. if (activate)
  311. theme_changed = active_themes.insert(theme_name).second;
  312. else
  313. theme_changed = (active_themes.erase(theme_name) > 0);
  314. if (theme_changed)
  315. {
  316. for (int i = 0; i < root->GetNumChildren(true); ++i)
  317. {
  318. if (ElementDocument* document = root->GetChild(i)->GetOwnerDocument())
  319. document->DirtyMediaQueries();
  320. }
  321. }
  322. }
  323. bool Context::IsThemeActive(const String& theme_name) const
  324. {
  325. return active_themes.count(theme_name);
  326. }
  327. // Returns the first document found in the root with the given id.
  328. ElementDocument* Context::GetDocument(const String& id)
  329. {
  330. for (int i = 0; i < root->GetNumChildren(); i++)
  331. {
  332. ElementDocument* document = root->GetChild(i)->GetOwnerDocument();
  333. if (document == nullptr)
  334. continue;
  335. if (document->GetId() == id)
  336. return document;
  337. }
  338. return nullptr;
  339. }
  340. // Returns a document in the context by index.
  341. ElementDocument* Context::GetDocument(int index)
  342. {
  343. Element* element = root->GetChild(index);
  344. if (element == nullptr)
  345. return nullptr;
  346. return element->GetOwnerDocument();
  347. }
  348. // Returns the number of documents in the context.
  349. int Context::GetNumDocuments() const
  350. {
  351. return root->GetNumChildren();
  352. }
  353. // Returns the hover element.
  354. Element* Context::GetHoverElement()
  355. {
  356. return hover;
  357. }
  358. // Returns the focus element.
  359. Element* Context::GetFocusElement()
  360. {
  361. return focus;
  362. }
  363. // Returns the root element.
  364. Element* Context::GetRootElement()
  365. {
  366. return root.get();
  367. }
  368. // Brings the document to the front of the document stack.
  369. void Context::PullDocumentToFront(ElementDocument* document)
  370. {
  371. if (document != root->GetLastChild())
  372. {
  373. // Calling RemoveChild() / AppendChild() would be cleaner, but that dirties the document's layout
  374. // unnecessarily, so we'll go under the hood here.
  375. for (int i = 0; i < root->GetNumChildren(); ++i)
  376. {
  377. if (root->GetChild(i) == document)
  378. {
  379. ElementPtr element = std::move(root->children[i]);
  380. root->children.erase(root->children.begin() + i);
  381. root->children.insert(root->children.begin() + root->GetNumChildren(), std::move(element));
  382. root->DirtyStackingContext();
  383. }
  384. }
  385. }
  386. }
  387. // Sends the document to the back of the document stack.
  388. void Context::PushDocumentToBack(ElementDocument* document)
  389. {
  390. if (document != root->GetFirstChild())
  391. {
  392. // See PullDocumentToFront().
  393. for (int i = 0; i < root->GetNumChildren(); ++i)
  394. {
  395. if (root->GetChild(i) == document)
  396. {
  397. ElementPtr element = std::move(root->children[i]);
  398. root->children.erase(root->children.begin() + i);
  399. root->children.insert(root->children.begin(), std::move(element));
  400. root->DirtyStackingContext();
  401. }
  402. }
  403. }
  404. }
  405. void Context::UnfocusDocument(ElementDocument* document)
  406. {
  407. auto it = std::find(document_focus_history.begin(), document_focus_history.end(), document);
  408. if (it != document_focus_history.end())
  409. document_focus_history.erase(it);
  410. if (!document_focus_history.empty())
  411. document_focus_history.back()->GetFocusLeafNode()->Focus();
  412. }
  413. // Adds an event listener to the root element.
  414. void Context::AddEventListener(const String& event, EventListener* listener, bool in_capture_phase)
  415. {
  416. root->AddEventListener(event, listener, in_capture_phase);
  417. }
  418. // Removes an event listener from the root element.
  419. void Context::RemoveEventListener(const String& event, EventListener* listener, bool in_capture_phase)
  420. {
  421. root->RemoveEventListener(event, listener, in_capture_phase);
  422. }
  423. // Sends a key down event into RmlUi.
  424. bool Context::ProcessKeyDown(Input::KeyIdentifier key_identifier, int key_modifier_state)
  425. {
  426. // Generate the parameters for the key event.
  427. Dictionary parameters;
  428. GenerateKeyEventParameters(parameters, key_identifier);
  429. GenerateKeyModifierEventParameters(parameters, key_modifier_state);
  430. if (focus)
  431. return focus->DispatchEvent(EventId::Keydown, parameters);
  432. else
  433. return root->DispatchEvent(EventId::Keydown, parameters);
  434. }
  435. // Sends a key up event into RmlUi.
  436. bool Context::ProcessKeyUp(Input::KeyIdentifier key_identifier, int key_modifier_state)
  437. {
  438. // Generate the parameters for the key event.
  439. Dictionary parameters;
  440. GenerateKeyEventParameters(parameters, key_identifier);
  441. GenerateKeyModifierEventParameters(parameters, key_modifier_state);
  442. if (focus)
  443. return focus->DispatchEvent(EventId::Keyup, parameters);
  444. else
  445. return root->DispatchEvent(EventId::Keyup, parameters);
  446. }
  447. bool Context::ProcessTextInput(char character)
  448. {
  449. // Only the standard ASCII character set is a valid subset of UTF-8.
  450. if (static_cast<unsigned char>(character) > 127)
  451. return false;
  452. return ProcessTextInput(static_cast<Character>(character));
  453. }
  454. // Sends a single character of text as text input into RmlUi.
  455. bool Context::ProcessTextInput(Character character)
  456. {
  457. // Generate the parameters for the key event.
  458. String text = StringUtilities::ToUTF8(character);
  459. return ProcessTextInput(text);
  460. }
  461. // Sends a string of text as text input into RmlUi.
  462. bool Context::ProcessTextInput(const String& string)
  463. {
  464. Element* target = (focus ? focus : root.get());
  465. Dictionary parameters;
  466. parameters["text"] = string;
  467. bool consumed = target->DispatchEvent(EventId::Textinput, parameters);
  468. return consumed;
  469. }
  470. // Sends a mouse movement event into RmlUi.
  471. bool Context::ProcessMouseMove(int x, int y, int key_modifier_state)
  472. {
  473. // Check whether the mouse moved since the last event came through.
  474. Vector2i old_mouse_position = mouse_position;
  475. bool mouse_moved = (x != mouse_position.x) || (y != mouse_position.y);
  476. if (mouse_moved)
  477. {
  478. mouse_position.x = x;
  479. mouse_position.y = y;
  480. }
  481. // Generate the parameters for the mouse events (there could be a few!).
  482. Dictionary parameters;
  483. GenerateMouseEventParameters(parameters, -1);
  484. GenerateKeyModifierEventParameters(parameters, key_modifier_state);
  485. Dictionary drag_parameters;
  486. GenerateMouseEventParameters(drag_parameters);
  487. GenerateDragEventParameters(drag_parameters);
  488. GenerateKeyModifierEventParameters(drag_parameters, key_modifier_state);
  489. // Update the current hover chain. This will send all necessary 'onmouseout', 'onmouseover', 'ondragout' and
  490. // 'ondragover' messages.
  491. UpdateHoverChain(parameters, drag_parameters, old_mouse_position);
  492. // Dispatch any 'onmousemove' events.
  493. if (mouse_moved)
  494. {
  495. if (hover)
  496. {
  497. hover->DispatchEvent(EventId::Mousemove, parameters);
  498. if (drag_hover &&
  499. drag_verbose)
  500. drag_hover->DispatchEvent(EventId::Dragmove, drag_parameters);
  501. }
  502. }
  503. return !IsMouseInteracting();
  504. }
  505. static Element* FindFocusElement(Element* element)
  506. {
  507. ElementDocument* owner_document = element->GetOwnerDocument();
  508. if (!owner_document || owner_document->GetComputedValues().focus == Style::Focus::None)
  509. return nullptr;
  510. while (element && element->GetComputedValues().focus == Style::Focus::None)
  511. {
  512. element = element->GetParentNode();
  513. }
  514. return element;
  515. }
  516. // Sends a mouse-button down event into RmlUi.
  517. bool Context::ProcessMouseButtonDown(int button_index, int key_modifier_state)
  518. {
  519. Dictionary parameters;
  520. GenerateMouseEventParameters(parameters, button_index);
  521. GenerateKeyModifierEventParameters(parameters, key_modifier_state);
  522. if (button_index == 0)
  523. {
  524. Element* new_focus = hover;
  525. // Set the currently hovered element to focus if it isn't already the focus.
  526. if (hover)
  527. {
  528. new_focus = FindFocusElement(hover);
  529. if (new_focus && new_focus != focus)
  530. {
  531. if (!new_focus->Focus())
  532. return !IsMouseInteracting();
  533. }
  534. }
  535. // Save the just-pressed-on element as the pressed element.
  536. active = new_focus;
  537. bool propagate = true;
  538. // Call 'onmousedown' on every item in the hover chain, and copy the hover chain to the active chain.
  539. if (hover)
  540. propagate = hover->DispatchEvent(EventId::Mousedown, parameters);
  541. if (propagate)
  542. {
  543. // Check for a double-click on an element; if one has occured, we send the 'dblclick' event to the hover
  544. // element. If not, we'll start a timer to catch the next one.
  545. float mouse_distance_squared = float((mouse_position - last_click_mouse_position).SquaredMagnitude());
  546. float max_mouse_distance = DOUBLE_CLICK_MAX_DIST * density_independent_pixel_ratio;
  547. double click_time = GetSystemInterface()->GetElapsedTime();
  548. if (active == last_click_element &&
  549. float(click_time - last_click_time) < DOUBLE_CLICK_TIME &&
  550. mouse_distance_squared < max_mouse_distance * max_mouse_distance)
  551. {
  552. if (hover)
  553. propagate = hover->DispatchEvent(EventId::Dblclick, parameters);
  554. last_click_element = nullptr;
  555. last_click_time = 0;
  556. }
  557. else
  558. {
  559. last_click_element = active;
  560. last_click_time = click_time;
  561. }
  562. }
  563. last_click_mouse_position = mouse_position;
  564. active_chain.insert(active_chain.end(), hover_chain.begin(), hover_chain.end());
  565. if (propagate)
  566. {
  567. // Traverse down the hierarchy of the newly focused element (if any), and see if we can begin dragging it.
  568. drag_started = false;
  569. drag = hover;
  570. while (drag)
  571. {
  572. Style::Drag drag_style = drag->GetComputedValues().drag;
  573. switch (drag_style)
  574. {
  575. case Style::Drag::None: drag = drag->GetParentNode(); continue;
  576. case Style::Drag::Block: drag = nullptr; continue;
  577. default: drag_verbose = (drag_style == Style::Drag::DragDrop || drag_style == Style::Drag::Clone);
  578. }
  579. break;
  580. }
  581. }
  582. }
  583. else
  584. {
  585. // Not the primary mouse button, so we're not doing any special processing.
  586. if (hover)
  587. hover->DispatchEvent(EventId::Mousedown, parameters);
  588. }
  589. return !IsMouseInteracting();
  590. }
  591. // Sends a mouse-button up event into RmlUi.
  592. bool Context::ProcessMouseButtonUp(int button_index, int key_modifier_state)
  593. {
  594. Dictionary parameters;
  595. GenerateMouseEventParameters(parameters, button_index);
  596. GenerateKeyModifierEventParameters(parameters, key_modifier_state);
  597. // We want to return the interaction state before handling the mouse up events, so that any active element that is released is considered to capture the event.
  598. const bool result = !IsMouseInteracting();
  599. // Process primary click.
  600. if (button_index == 0)
  601. {
  602. // The elements in the new hover chain have the 'onmouseup' event called on them.
  603. if (hover)
  604. hover->DispatchEvent(EventId::Mouseup, parameters);
  605. // If the active element (the one that was being hovered over when the mouse button was pressed) is still being
  606. // hovered over, we click it.
  607. if (hover && active && active == FindFocusElement(hover))
  608. {
  609. active->DispatchEvent(EventId::Click, parameters);
  610. }
  611. // Unset the 'active' pseudo-class on all the elements in the active chain; because they may not necessarily
  612. // have had 'onmouseup' called on them, we can't guarantee this has happened already.
  613. std::for_each(active_chain.begin(), active_chain.end(), [](Element* element) {
  614. element->SetPseudoClass("active", false);
  615. });
  616. active_chain.clear();
  617. active = nullptr;
  618. if (drag)
  619. {
  620. if (drag_started)
  621. {
  622. Dictionary drag_parameters;
  623. GenerateMouseEventParameters(drag_parameters);
  624. GenerateDragEventParameters(drag_parameters);
  625. GenerateKeyModifierEventParameters(drag_parameters, key_modifier_state);
  626. if (drag_hover)
  627. {
  628. if (drag_verbose)
  629. {
  630. drag_hover->DispatchEvent(EventId::Dragdrop, drag_parameters);
  631. // User may have removed the element, do an extra check.
  632. if(drag_hover)
  633. drag_hover->DispatchEvent(EventId::Dragout, drag_parameters);
  634. }
  635. }
  636. if(drag)
  637. drag->DispatchEvent(EventId::Dragend, drag_parameters);
  638. ReleaseDragClone();
  639. }
  640. drag = nullptr;
  641. drag_hover = nullptr;
  642. drag_hover_chain.clear();
  643. // We may have changes under our mouse, this ensures that the hover chain is properly updated
  644. ProcessMouseMove(mouse_position.x, mouse_position.y, key_modifier_state);
  645. }
  646. }
  647. else
  648. {
  649. // Not the left mouse button, so we're not doing any special processing.
  650. if (hover)
  651. hover->DispatchEvent(EventId::Mouseup, parameters);
  652. }
  653. return result;
  654. }
  655. // Sends a mouse-wheel movement event into RmlUi.
  656. bool Context::ProcessMouseWheel(float wheel_delta, int key_modifier_state)
  657. {
  658. if (hover)
  659. {
  660. Dictionary scroll_parameters;
  661. GenerateKeyModifierEventParameters(scroll_parameters, key_modifier_state);
  662. scroll_parameters["wheel_delta"] = wheel_delta;
  663. return hover->DispatchEvent(EventId::Mousescroll, scroll_parameters);
  664. }
  665. return true;
  666. }
  667. bool Context::IsMouseInteracting() const
  668. {
  669. return (hover && hover != root.get()) || (active && active != root.get());
  670. }
  671. // Gets the context's render interface.
  672. RenderInterface* Context::GetRenderInterface() const
  673. {
  674. return render_interface;
  675. }
  676. // Gets the current clipping region for the render traversal
  677. bool Context::GetActiveClipRegion(Vector2i& origin, Vector2i& dimensions) const
  678. {
  679. if (clip_dimensions.x < 0 || clip_dimensions.y < 0)
  680. return false;
  681. origin = clip_origin;
  682. dimensions = clip_dimensions;
  683. return true;
  684. }
  685. // Sets the current clipping region for the render traversal
  686. void Context::SetActiveClipRegion(const Vector2i origin, const Vector2i dimensions)
  687. {
  688. clip_origin = origin;
  689. clip_dimensions = dimensions;
  690. }
  691. // Sets the instancer to use for releasing this object.
  692. void Context::SetInstancer(ContextInstancer* _instancer)
  693. {
  694. RMLUI_ASSERT(instancer == nullptr);
  695. instancer = _instancer;
  696. }
  697. DataModelConstructor Context::CreateDataModel(const String& name)
  698. {
  699. if (!data_type_register)
  700. data_type_register = MakeUnique<DataTypeRegister>();
  701. auto result = data_models.emplace(name, MakeUnique<DataModel>(data_type_register->GetTransformFuncRegister()));
  702. bool inserted = result.second;
  703. if (inserted)
  704. return DataModelConstructor(result.first->second.get(), data_type_register.get());
  705. Log::Message(Log::LT_ERROR, "Data model name '%s' already exists.", name.c_str());
  706. return DataModelConstructor();
  707. }
  708. DataModelConstructor Context::GetDataModel(const String& name)
  709. {
  710. if (data_type_register)
  711. {
  712. if (DataModel* model = GetDataModelPtr(name))
  713. return DataModelConstructor(model, data_type_register.get());
  714. }
  715. Log::Message(Log::LT_ERROR, "Data model name '%s' could not be found.", name.c_str());
  716. return DataModelConstructor();
  717. }
  718. bool Context::RemoveDataModel(const String& name)
  719. {
  720. auto it = data_models.find(name);
  721. if (it == data_models.end())
  722. return false;
  723. DataModel* model = it->second.get();
  724. ElementList elements = model->GetAttachedModelRootElements();
  725. for (Element* element : elements)
  726. element->SetDataModel(nullptr);
  727. data_models.erase(it);
  728. return true;
  729. }
  730. // Internal callback for when an element is removed from the hierarchy.
  731. void Context::OnElementDetach(Element* element)
  732. {
  733. auto it_hover = hover_chain.find(element);
  734. if (it_hover != hover_chain.end())
  735. {
  736. Dictionary parameters;
  737. GenerateMouseEventParameters(parameters, -1);
  738. element->DispatchEvent(EventId::Mouseout, parameters);
  739. hover_chain.erase(it_hover);
  740. if (hover == element)
  741. hover = nullptr;
  742. }
  743. auto it_active = std::find(active_chain.begin(), active_chain.end(), element);
  744. if (it_active != active_chain.end())
  745. {
  746. active_chain.erase(it_active);
  747. if (active == element)
  748. active = nullptr;
  749. }
  750. if (drag)
  751. {
  752. auto it = drag_hover_chain.find(element);
  753. if (it != drag_hover_chain.end())
  754. {
  755. drag_hover_chain.erase(it);
  756. if (drag_hover == element)
  757. drag_hover = nullptr;
  758. }
  759. if (drag == element)
  760. {
  761. // The dragged element is being removed, silently cancel the drag operation
  762. if (drag_started)
  763. ReleaseDragClone();
  764. drag = nullptr;
  765. drag_hover = nullptr;
  766. drag_hover_chain.clear();
  767. }
  768. }
  769. // Focus normally cleared and set by parent during Element::RemoveChild.
  770. // However, there are some exceptions, such as when an there are multiple
  771. // ElementDocuments in the hierarchy above the current element.
  772. if (element == focus)
  773. focus = nullptr;
  774. // If the element is a document lower down in the hierarchy, we may need to remove it from the focus history.
  775. if (element->GetOwnerDocument() == element)
  776. {
  777. auto it = std::find(document_focus_history.begin(), document_focus_history.end(), element);
  778. if (it != document_focus_history.end())
  779. document_focus_history.erase(it);
  780. }
  781. }
  782. // Internal callback for when a new element gains focus
  783. bool Context::OnFocusChange(Element* new_focus)
  784. {
  785. RMLUI_ASSERT(new_focus);
  786. ElementSet old_chain;
  787. ElementSet new_chain;
  788. Element* old_focus = focus;
  789. ElementDocument* old_document = old_focus ? old_focus->GetOwnerDocument() : nullptr;
  790. ElementDocument* new_document = new_focus->GetOwnerDocument();
  791. // If the current focus is modal and the new focus is not modal, deny the request
  792. if (old_document && old_document->IsModal() && (!new_document || !new_document->GetOwnerDocument()->IsModal()))
  793. return false;
  794. // Build the old chains
  795. Element* element = old_focus;
  796. while (element)
  797. {
  798. old_chain.insert(element);
  799. element = element->GetParentNode();
  800. }
  801. // Build the new chain
  802. element = new_focus;
  803. while (element)
  804. {
  805. new_chain.insert(element);
  806. element = element->GetParentNode();
  807. }
  808. Dictionary parameters;
  809. // Send out blur/focus events.
  810. SendEvents(old_chain, new_chain, EventId::Blur, parameters);
  811. SendEvents(new_chain, old_chain, EventId::Focus, parameters);
  812. focus = new_focus;
  813. // Raise the element's document to the front, if desired.
  814. ElementDocument* document = focus->GetOwnerDocument();
  815. if (document != nullptr)
  816. {
  817. Style::ZIndex z_index_property = document->GetComputedValues().z_index;
  818. if (z_index_property.type == Style::ZIndex::Auto)
  819. document->PullToFront();
  820. }
  821. // Update the focus history
  822. if (old_document != new_document)
  823. {
  824. // If documents have changed, add the new document to the end of the history
  825. ElementList::iterator itr = std::find(document_focus_history.begin(), document_focus_history.end(), new_document);
  826. if (itr != document_focus_history.end())
  827. document_focus_history.erase(itr);
  828. if (new_document != nullptr)
  829. document_focus_history.push_back(new_document);
  830. }
  831. return true;
  832. }
  833. // Generates an event for faking clicks on an element.
  834. void Context::GenerateClickEvent(Element* element)
  835. {
  836. Dictionary parameters;
  837. GenerateMouseEventParameters(parameters, 0);
  838. element->DispatchEvent(EventId::Click, parameters);
  839. }
  840. // Updates the current hover elements, sending required events.
  841. void Context::UpdateHoverChain(const Dictionary& parameters, const Dictionary& drag_parameters, const Vector2i old_mouse_position)
  842. {
  843. const Vector2f position(mouse_position);
  844. // Send out drag events.
  845. if (drag)
  846. {
  847. if (mouse_position != old_mouse_position)
  848. {
  849. if (!drag_started)
  850. {
  851. Dictionary drag_start_parameters = drag_parameters;
  852. drag_start_parameters["mouse_x"] = old_mouse_position.x;
  853. drag_start_parameters["mouse_y"] = old_mouse_position.y;
  854. drag->DispatchEvent(EventId::Dragstart, drag_start_parameters);
  855. drag_started = true;
  856. if (drag->GetComputedValues().drag == Style::Drag::Clone)
  857. {
  858. // Clone the element and attach it to the mouse cursor.
  859. CreateDragClone(drag);
  860. }
  861. }
  862. drag->DispatchEvent(EventId::Drag, drag_parameters);
  863. }
  864. }
  865. hover = GetElementAtPoint(position);
  866. if(enable_cursor)
  867. {
  868. String new_cursor_name;
  869. if(drag)
  870. new_cursor_name = drag->GetComputedValues().cursor;
  871. else if (hover)
  872. new_cursor_name = hover->GetComputedValues().cursor;
  873. if(new_cursor_name != cursor_name)
  874. {
  875. GetSystemInterface()->SetMouseCursor(new_cursor_name);
  876. cursor_name = new_cursor_name;
  877. }
  878. }
  879. // Build the new hover chain.
  880. ElementSet new_hover_chain;
  881. Element* element = hover;
  882. while (element != nullptr)
  883. {
  884. new_hover_chain.insert(element);
  885. element = element->GetParentNode();
  886. }
  887. // Send mouseout / mouseover events.
  888. SendEvents(hover_chain, new_hover_chain, EventId::Mouseout, parameters);
  889. SendEvents(new_hover_chain, hover_chain, EventId::Mouseover, parameters);
  890. // Send out drag events.
  891. if (drag)
  892. {
  893. drag_hover = GetElementAtPoint(position, drag);
  894. ElementSet new_drag_hover_chain;
  895. element = drag_hover;
  896. while (element != nullptr)
  897. {
  898. new_drag_hover_chain.insert(element);
  899. element = element->GetParentNode();
  900. }
  901. if (drag_started &&
  902. drag_verbose)
  903. {
  904. // Send out ondragover and ondragout events as appropriate.
  905. SendEvents(drag_hover_chain, new_drag_hover_chain, EventId::Dragout, drag_parameters);
  906. SendEvents(new_drag_hover_chain, drag_hover_chain, EventId::Dragover, drag_parameters);
  907. }
  908. drag_hover_chain.swap(new_drag_hover_chain);
  909. }
  910. // Swap the new chain in.
  911. hover_chain.swap(new_hover_chain);
  912. }
  913. // Returns the youngest descendent of the given element which is under the given point in screen coodinates.
  914. Element* Context::GetElementAtPoint(Vector2f point, const Element* ignore_element, Element* element) const
  915. {
  916. if (element == nullptr)
  917. {
  918. if (ignore_element == root.get())
  919. return nullptr;
  920. element = root.get();
  921. }
  922. // Check if any documents have modal focus; if so, only check down than document.
  923. if (element == root.get())
  924. {
  925. if (focus)
  926. {
  927. ElementDocument* focus_document = focus->GetOwnerDocument();
  928. if (focus_document != nullptr &&
  929. focus_document->IsModal())
  930. {
  931. element = focus_document;
  932. }
  933. }
  934. }
  935. // Check any elements within our stacking context. We want to return the lowest-down element
  936. // that is under the cursor.
  937. if (element->local_stacking_context)
  938. {
  939. if (element->stacking_context_dirty)
  940. element->BuildLocalStackingContext();
  941. for (int i = (int) element->stacking_context.size() - 1; i >= 0; --i)
  942. {
  943. if (ignore_element != nullptr)
  944. {
  945. Element* element_hierarchy = element->stacking_context[i];
  946. while (element_hierarchy != nullptr)
  947. {
  948. if (element_hierarchy == ignore_element)
  949. break;
  950. element_hierarchy = element_hierarchy->GetParentNode();
  951. }
  952. if (element_hierarchy != nullptr)
  953. continue;
  954. }
  955. Element* child_element = GetElementAtPoint(point, ignore_element, element->stacking_context[i]);
  956. if (child_element != nullptr)
  957. return child_element;
  958. }
  959. }
  960. // Ignore elements whose pointer events are disabled.
  961. if (element->GetComputedValues().pointer_events == Style::PointerEvents::None)
  962. return nullptr;
  963. // Projection may fail if we have a singular transformation matrix.
  964. bool projection_result = element->Project(point);
  965. // Check if the point is actually within this element.
  966. bool within_element = (projection_result && element->IsPointWithinElement(point));
  967. if (within_element)
  968. {
  969. Vector2i clip_origin, clip_dimensions;
  970. if (ElementUtilities::GetClippingRegion(clip_origin, clip_dimensions, element))
  971. {
  972. within_element = point.x >= clip_origin.x &&
  973. point.y >= clip_origin.y &&
  974. point.x <= (clip_origin.x + clip_dimensions.x) &&
  975. point.y <= (clip_origin.y + clip_dimensions.y);
  976. }
  977. }
  978. if (within_element)
  979. return element;
  980. return nullptr;
  981. }
  982. // Creates the drag clone from the given element.
  983. void Context::CreateDragClone(Element* element)
  984. {
  985. RMLUI_ASSERTMSG(cursor_proxy, "Unable to create drag clone, no cursor proxy document.");
  986. ReleaseDragClone();
  987. // Instance the drag clone.
  988. ElementPtr element_drag_clone = element->Clone();
  989. if (!element_drag_clone)
  990. {
  991. Log::Message(Log::LT_ERROR, "Unable to duplicate drag clone.");
  992. return;
  993. }
  994. drag_clone = element_drag_clone.get();
  995. // Append the clone to the cursor proxy element.
  996. cursor_proxy->AppendChild(std::move(element_drag_clone));
  997. // Set the style sheet on the cursor proxy.
  998. if (ElementDocument* document = element->GetOwnerDocument())
  999. {
  1000. // Borrow the target document's style sheet. Sharing style sheet containers should be used with care, and
  1001. // only within the same context.
  1002. static_cast<ElementDocument&>(*cursor_proxy).SetStyleSheetContainer(document->style_sheet_container);
  1003. }
  1004. // Set all the required properties and pseudo-classes on the clone.
  1005. drag_clone->SetPseudoClass("drag", true);
  1006. drag_clone->SetProperty(PropertyId::Position, Property(Style::Position::Absolute));
  1007. drag_clone->SetProperty(PropertyId::Left, Property(element->GetAbsoluteLeft() - element->GetBox().GetEdge(Box::MARGIN, Box::LEFT) - mouse_position.x, Property::PX));
  1008. drag_clone->SetProperty(PropertyId::Top, Property(element->GetAbsoluteTop() - element->GetBox().GetEdge(Box::MARGIN, Box::TOP) - mouse_position.y, Property::PX));
  1009. }
  1010. // Releases the drag clone, if one exists.
  1011. void Context::ReleaseDragClone()
  1012. {
  1013. if (drag_clone)
  1014. {
  1015. cursor_proxy->RemoveChild(drag_clone);
  1016. drag_clone = nullptr;
  1017. static_cast<ElementDocument&>(*cursor_proxy).SetStyleSheetContainer(nullptr);
  1018. }
  1019. }
  1020. DataModel* Context::GetDataModelPtr(const String& name) const
  1021. {
  1022. auto it = data_models.find(name);
  1023. if (it != data_models.end())
  1024. return it->second.get();
  1025. return nullptr;
  1026. }
  1027. // Builds the parameters for a generic key event.
  1028. void Context::GenerateKeyEventParameters(Dictionary& parameters, Input::KeyIdentifier key_identifier)
  1029. {
  1030. parameters["key_identifier"] = (int)key_identifier;
  1031. }
  1032. // Builds the parameters for a generic mouse event.
  1033. void Context::GenerateMouseEventParameters(Dictionary& parameters, int button_index)
  1034. {
  1035. parameters.reserve(3);
  1036. parameters["mouse_x"] = mouse_position.x;
  1037. parameters["mouse_y"] = mouse_position.y;
  1038. if (button_index >= 0)
  1039. parameters["button"] = button_index;
  1040. }
  1041. // Builds the parameters for the key modifier state.
  1042. void Context::GenerateKeyModifierEventParameters(Dictionary& parameters, int key_modifier_state)
  1043. {
  1044. static const String property_names[] = {
  1045. "ctrl_key",
  1046. "shift_key",
  1047. "alt_key",
  1048. "meta_key",
  1049. "caps_lock_key",
  1050. "num_lock_key",
  1051. "scroll_lock_key"
  1052. };
  1053. for (int i = 0; i < 7; i++)
  1054. parameters[property_names[i]] = (int)((key_modifier_state & (1 << i)) > 0);
  1055. }
  1056. // Builds the parameters for a drag event.
  1057. void Context::GenerateDragEventParameters(Dictionary& parameters)
  1058. {
  1059. parameters["drag_element"] = (void*)drag;
  1060. }
  1061. // Releases all unloaded documents pending destruction.
  1062. void Context::ReleaseUnloadedDocuments()
  1063. {
  1064. if (!unloaded_documents.empty())
  1065. {
  1066. OwnedElementList documents = std::move(unloaded_documents);
  1067. unloaded_documents.clear();
  1068. // Clear the deleted list.
  1069. for (size_t i = 0; i < documents.size(); ++i)
  1070. documents[i]->GetEventDispatcher()->DetachAllEvents();
  1071. documents.clear();
  1072. }
  1073. }
  1074. using ElementObserverList = Vector< ObserverPtr<Element> >;
  1075. class ElementObserverListBackInserter {
  1076. public:
  1077. using iterator_category = std::output_iterator_tag;
  1078. using value_type = void;
  1079. using difference_type = void;
  1080. using pointer = void;
  1081. using reference = void;
  1082. using container_type = ElementObserverList;
  1083. ElementObserverListBackInserter(ElementObserverList& elements) : elements(&elements) {}
  1084. ElementObserverListBackInserter& operator=(Element* element) {
  1085. elements->push_back(element->GetObserverPtr());
  1086. return *this;
  1087. }
  1088. ElementObserverListBackInserter& operator*() { return *this; }
  1089. ElementObserverListBackInserter& operator++() { return *this; }
  1090. ElementObserverListBackInserter& operator++(int) { return *this; }
  1091. private:
  1092. ElementObserverList* elements;
  1093. };
  1094. // Sends the specified event to all elements in new_items that don't appear in old_items.
  1095. void Context::SendEvents(const ElementSet& old_items, const ElementSet& new_items, EventId id, const Dictionary& parameters)
  1096. {
  1097. // We put our elements in observer pointers in case some of them are deleted during dispatch.
  1098. ElementObserverList elements;
  1099. std::set_difference(old_items.begin(), old_items.end(), new_items.begin(), new_items.end(), ElementObserverListBackInserter(elements));
  1100. for (auto& element : elements)
  1101. {
  1102. if (element)
  1103. element->DispatchEvent(id, parameters);
  1104. }
  1105. }
  1106. void Context::Release()
  1107. {
  1108. if (instancer)
  1109. {
  1110. instancer->ReleaseContext(this);
  1111. }
  1112. }
  1113. void Context::SetDocumentsBaseTag(const String& tag)
  1114. {
  1115. documents_base_tag = tag;
  1116. }
  1117. const String& Context::GetDocumentsBaseTag()
  1118. {
  1119. return documents_base_tag;
  1120. }
  1121. } // namespace Rml