Context.cpp 38 KB

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