WidgetDropDown.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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-2023 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 "WidgetDropDown.h"
  29. #include "../../../Include/RmlUi/Core/ComputedValues.h"
  30. #include "../../../Include/RmlUi/Core/Context.h"
  31. #include "../../../Include/RmlUi/Core/ElementDocument.h"
  32. #include "../../../Include/RmlUi/Core/ElementUtilities.h"
  33. #include "../../../Include/RmlUi/Core/Elements/ElementFormControl.h"
  34. #include "../../../Include/RmlUi/Core/Event.h"
  35. #include "../../../Include/RmlUi/Core/Factory.h"
  36. #include "../../../Include/RmlUi/Core/Input.h"
  37. #include "../../../Include/RmlUi/Core/Math.h"
  38. #include "../../../Include/RmlUi/Core/Profiling.h"
  39. #include "../../../Include/RmlUi/Core/Property.h"
  40. #include "../DataModel.h"
  41. namespace Rml {
  42. WidgetDropDown::WidgetDropDown(ElementFormControl* element)
  43. {
  44. parent_element = element;
  45. lock_selection = false;
  46. selection_dirty = false;
  47. box_layout_dirty = false;
  48. box_opened_since_last_format = false;
  49. value_rml_dirty = false;
  50. value_layout_dirty = false;
  51. box_visible = false;
  52. // Create the button and selection elements.
  53. button_element = parent_element->AppendChild(Factory::InstanceElement(parent_element, "*", "selectarrow", XMLAttributes()), false);
  54. value_element = parent_element->AppendChild(Factory::InstanceElement(parent_element, "*", "selectvalue", XMLAttributes()), false);
  55. selection_element = parent_element->AppendChild(Factory::InstanceElement(parent_element, "*", "selectbox", XMLAttributes()), false);
  56. value_element->SetProperty(PropertyId::OverflowX, Property(Style::Overflow::Hidden));
  57. value_element->SetProperty(PropertyId::OverflowY, Property(Style::Overflow::Hidden));
  58. selection_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
  59. selection_element->SetProperty(PropertyId::ZIndex, Property(1.0f, Unit::NUMBER));
  60. selection_element->SetProperty(PropertyId::Clip, Property(Style::Clip::Type::None));
  61. selection_element->SetProperty(PropertyId::OverflowY, Property(Style::Overflow::Auto));
  62. // Prevent scrolling in the parent document when the mouse is inside the selection box.
  63. selection_element->SetProperty(PropertyId::OverscrollBehavior, Property(Style::OverscrollBehavior::Contain));
  64. parent_element->AddEventListener(EventId::Click, this, true);
  65. parent_element->AddEventListener(EventId::Blur, this);
  66. parent_element->AddEventListener(EventId::Focus, this);
  67. parent_element->AddEventListener(EventId::Keydown, this, true);
  68. }
  69. WidgetDropDown::~WidgetDropDown()
  70. {
  71. // We shouldn't clear the options ourselves, as removing the element will automatically clear children.
  72. // However, we do need to remove events of children.
  73. const int num_options = selection_element->GetNumChildren();
  74. for (int i = 0; i < num_options; i++)
  75. selection_element->GetChild(i)->RemoveEventListener(EventId::Click, this);
  76. parent_element->RemoveEventListener(EventId::Click, this, true);
  77. parent_element->RemoveEventListener(EventId::Blur, this);
  78. parent_element->RemoveEventListener(EventId::Focus, this);
  79. parent_element->RemoveEventListener(EventId::Keydown, this, true);
  80. DetachScrollEvent();
  81. }
  82. void WidgetDropDown::OnUpdate()
  83. {
  84. if (selection_dirty)
  85. {
  86. // Find the best option element to select in the following priority:
  87. // 1. First option with 'selected' attribute.
  88. // 2. An option whose 'value' attribute matches the select 'value' attribute.
  89. // 3. The first option.
  90. // The select element's value may change as a result of this.
  91. const String select_value = parent_element->GetAttribute("value", String());
  92. Element* select_option = selection_element->GetFirstChild();
  93. const int num_options = selection_element->GetNumChildren();
  94. for (int i = 0; i < num_options; i++)
  95. {
  96. Element* option = selection_element->GetChild(i);
  97. if (option->HasAttribute("selected"))
  98. {
  99. select_option = option;
  100. break;
  101. }
  102. else if (!select_value.empty() && select_value == option->GetAttribute("value", String()))
  103. {
  104. select_option = option;
  105. }
  106. }
  107. if (select_option)
  108. SetSelection(select_option);
  109. selection_dirty = false;
  110. }
  111. if (value_rml_dirty)
  112. {
  113. String value_rml;
  114. const int selection = GetSelection();
  115. if (Element* option = selection_element->GetChild(selection))
  116. {
  117. option->GetInnerRML(value_rml);
  118. if (auto model = value_element->GetDataModel())
  119. model->CopyAliases(option, value_element);
  120. }
  121. else
  122. {
  123. if (auto model = value_element->GetDataModel())
  124. model->EraseAliases(value_element);
  125. value_rml = parent_element->GetValue();
  126. }
  127. value_element->SetInnerRML(value_rml);
  128. value_rml_dirty = false;
  129. value_layout_dirty = true;
  130. }
  131. }
  132. void WidgetDropDown::OnRender()
  133. {
  134. if (box_visible && box_layout_dirty)
  135. {
  136. // Layout the selection box.
  137. // The following procedure should ensure that the selection box is never (partly) outside of the context's window.
  138. // This is achieved by positioning the box either above or below the 'select' element, and possibly shrinking
  139. // the element's height.
  140. // We try to respect user values of 'height', 'min-height', and 'max-height'. However, when we need to shrink the box
  141. // we will override the 'height' property.
  142. // Previously set 'height' property from this procedure must be removed for the calculations below to work as intended.
  143. if (selection_element->GetLocalStyleProperties().count(PropertyId::Height) == 1)
  144. {
  145. selection_element->RemoveProperty(PropertyId::Height);
  146. selection_element->GetOwnerDocument()->UpdateDocument();
  147. }
  148. Box box;
  149. ElementUtilities::BuildBox(box, parent_element->GetBox().GetSize(), selection_element);
  150. // The user can use 'margin-left/top/bottom' to offset the box away from the 'select' element, respectively
  151. // horizontally, vertically when box below, and vertically when box above.
  152. const float offset_x = box.GetEdge(BoxArea::Margin, BoxEdge::Left);
  153. const float offset_y_below = parent_element->GetBox().GetSize(BoxArea::Border).y + box.GetEdge(BoxArea::Margin, BoxEdge::Top);
  154. const float offset_y_above = -box.GetEdge(BoxArea::Margin, BoxEdge::Bottom);
  155. float window_height = 100'000.f;
  156. if (Context* context = parent_element->GetContext())
  157. window_height = float(context->GetDimensions().y);
  158. const float absolute_y = parent_element->GetAbsoluteOffset(BoxArea::Border).y;
  159. const float height_below = window_height - absolute_y - offset_y_below;
  160. const float height_above = absolute_y + offset_y_above;
  161. // Format the selection box and retrieve the 'native' height occupied by all the options, while respecting
  162. // the 'min/max-height' properties.
  163. ElementUtilities::FormatElement(selection_element, parent_element->GetBox().GetSize(BoxArea::Border));
  164. const float content_height = selection_element->GetOffsetHeight();
  165. if (content_height < height_below)
  166. {
  167. // Position box below
  168. selection_element->SetOffset(Vector2f(offset_x, offset_y_below), parent_element);
  169. }
  170. else if (content_height < height_above)
  171. {
  172. // Position box above
  173. selection_element->SetOffset(Vector2f(offset_x, -content_height + offset_y_above), parent_element);
  174. }
  175. else
  176. {
  177. // Shrink box and position either below or above
  178. const float padding_border_size = box.GetEdge(BoxArea::Border, BoxEdge::Top) + box.GetEdge(BoxArea::Border, BoxEdge::Bottom) +
  179. box.GetEdge(BoxArea::Padding, BoxEdge::Top) + box.GetEdge(BoxArea::Padding, BoxEdge::Bottom);
  180. float height = 0.f;
  181. float offset_y = 0.f;
  182. if (height_below > height_above)
  183. {
  184. // Position below
  185. height = height_below - padding_border_size;
  186. offset_y = offset_y_below;
  187. }
  188. else
  189. {
  190. // Position above
  191. height = height_above - padding_border_size;
  192. offset_y = offset_y_above - height_above;
  193. }
  194. // Set the height and re-format the selection box.
  195. selection_element->SetProperty(PropertyId::Height, Property(height, Unit::PX));
  196. selection_element->GetOwnerDocument()->UpdateDocument();
  197. ElementUtilities::FormatElement(selection_element, parent_element->GetBox().GetSize(BoxArea::Border));
  198. selection_element->SetOffset(Vector2f(offset_x, offset_y), parent_element);
  199. }
  200. int selection = GetSelection();
  201. // Scroll selected element into view, if we have one
  202. if (selection != -1)
  203. {
  204. ScrollIntoViewOptions scroll_options = {
  205. box_opened_since_last_format ? ScrollAlignment::Center : ScrollAlignment::Nearest,
  206. ScrollAlignment::Nearest,
  207. ScrollBehavior::Instant,
  208. ScrollParentage::Closest,
  209. };
  210. GetOption(selection)->ScrollIntoView(scroll_options);
  211. }
  212. box_opened_since_last_format = false;
  213. box_layout_dirty = false;
  214. }
  215. if (value_layout_dirty)
  216. {
  217. ElementUtilities::FormatElement(value_element, parent_element->GetBox().GetSize(BoxArea::Border));
  218. value_element->SetOffset(parent_element->GetBox().GetPosition(BoxArea::Content), parent_element);
  219. value_layout_dirty = false;
  220. }
  221. }
  222. void WidgetDropDown::OnLayout()
  223. {
  224. RMLUI_ZoneScopedNC("DropDownLayout", 0x7FFF00);
  225. if (parent_element->IsDisabled())
  226. {
  227. // Propagate disabled state to selectvalue and selectarrow
  228. value_element->SetPseudoClass("disabled", true);
  229. button_element->SetPseudoClass("disabled", true);
  230. }
  231. // Layout the button and selection boxes.
  232. Box parent_box = parent_element->GetBox();
  233. ElementUtilities::PositionElement(button_element, Vector2f(0, 0), ElementUtilities::TOP_RIGHT);
  234. ElementUtilities::PositionElement(selection_element, Vector2f(0, 0), ElementUtilities::TOP_LEFT);
  235. // Calculate the value element position and size.
  236. Vector2f size;
  237. size.x = parent_element->GetBox().GetSize(BoxArea::Content).x - button_element->GetBox().GetSize(BoxArea::Margin).x;
  238. size.y = parent_element->GetBox().GetSize(BoxArea::Content).y;
  239. value_element->SetOffset(parent_element->GetBox().GetPosition(BoxArea::Content), parent_element);
  240. value_element->SetBox(Box(size));
  241. box_layout_dirty = true;
  242. value_layout_dirty = true;
  243. }
  244. void WidgetDropDown::OnValueChange(const String& value)
  245. {
  246. if (!lock_selection)
  247. {
  248. Element* select_option = nullptr;
  249. const int num_options = selection_element->GetNumChildren();
  250. for (int i = 0; i < num_options; i++)
  251. {
  252. Element* option = selection_element->GetChild(i);
  253. Variant* variant = option->GetAttribute("value");
  254. if (variant && variant->Get<String>() == value)
  255. {
  256. select_option = option;
  257. break;
  258. }
  259. }
  260. if (select_option && !select_option->HasAttribute("selected"))
  261. SetSelection(select_option);
  262. }
  263. Dictionary parameters;
  264. parameters["value"] = value;
  265. parent_element->DispatchEvent(EventId::Change, parameters);
  266. value_rml_dirty = true;
  267. }
  268. void WidgetDropDown::SetSelection(Element* select_option, bool force)
  269. {
  270. const String old_value = parent_element->GetAttribute("value", String());
  271. const String new_value = select_option ? select_option->GetAttribute("value", String()) : String();
  272. bool newly_selected = false;
  273. const int num_options = selection_element->GetNumChildren();
  274. for (int i = 0; i < num_options; i++)
  275. {
  276. Element* option = selection_element->GetChild(i);
  277. if (select_option == option)
  278. {
  279. if (!option->IsPseudoClassSet("checked"))
  280. newly_selected = true;
  281. option->SetAttribute("selected", String());
  282. option->SetPseudoClass("checked", true);
  283. }
  284. else
  285. {
  286. option->RemoveAttribute("selected");
  287. option->SetPseudoClass("checked", false);
  288. }
  289. }
  290. if (force || newly_selected || (old_value != new_value))
  291. {
  292. lock_selection = true;
  293. parent_element->SetAttribute("value", new_value);
  294. lock_selection = false;
  295. }
  296. value_rml_dirty = true;
  297. }
  298. void WidgetDropDown::SeekSelection(bool seek_forward)
  299. {
  300. const int selected_option = GetSelection();
  301. const int num_options = selection_element->GetNumChildren();
  302. const int seek_direction = (seek_forward ? 1 : -1);
  303. for (int i = selected_option + seek_direction; i >= 0 && i < num_options; i += seek_direction)
  304. {
  305. Element* element = selection_element->GetChild(i);
  306. if (!element->HasAttribute("disabled") && element->IsVisible())
  307. {
  308. SetSelection(element);
  309. return;
  310. }
  311. }
  312. // No valid option found, leave selection unchanged.
  313. }
  314. int WidgetDropDown::GetSelection() const
  315. {
  316. const int num_options = selection_element->GetNumChildren();
  317. for (int i = 0; i < num_options; i++)
  318. {
  319. if (selection_element->GetChild(i)->HasAttribute("selected"))
  320. return i;
  321. }
  322. return -1;
  323. }
  324. int WidgetDropDown::AddOption(const String& rml, const String& option_value, int before, bool select, bool selectable)
  325. {
  326. ElementPtr element = Factory::InstanceElement(selection_element, "*", "option", XMLAttributes());
  327. element->SetInnerRML(rml);
  328. element->SetAttribute("value", option_value);
  329. if (select)
  330. element->SetAttribute("selected", String());
  331. if (!selectable)
  332. element->SetAttribute("disabled", String());
  333. int result = AddOption(std::move(element), before);
  334. return result;
  335. }
  336. int WidgetDropDown::AddOption(ElementPtr element, int before)
  337. {
  338. if (element->GetTagName() != "option")
  339. {
  340. Log::Message(Log::LT_WARNING, "A child of '%s' must be of type 'option' but '%s' was given. See element '%s'.",
  341. parent_element->GetTagName().c_str(), element->GetTagName().c_str(), parent_element->GetAddress().c_str());
  342. return -1;
  343. }
  344. const int num_children_before = selection_element->GetNumChildren();
  345. int option_index;
  346. if (before < 0 || before >= num_children_before)
  347. {
  348. selection_element->AppendChild(std::move(element));
  349. option_index = num_children_before;
  350. }
  351. else
  352. {
  353. selection_element->InsertBefore(std::move(element), selection_element->GetChild(before));
  354. option_index = before;
  355. }
  356. return option_index;
  357. }
  358. void WidgetDropDown::RemoveOption(int index)
  359. {
  360. Element* element = selection_element->GetChild(index);
  361. if (!element)
  362. return;
  363. selection_element->RemoveChild(element);
  364. }
  365. void WidgetDropDown::ClearOptions()
  366. {
  367. while (Element* element = selection_element->GetLastChild())
  368. selection_element->RemoveChild(element);
  369. }
  370. Element* WidgetDropDown::GetOption(int index)
  371. {
  372. return selection_element->GetChild(index);
  373. }
  374. int WidgetDropDown::GetNumOptions() const
  375. {
  376. return selection_element->GetNumChildren();
  377. }
  378. void WidgetDropDown::OnChildAdd(Element* element)
  379. {
  380. // We have a special case for 'data-for' here, since that element must remain hidden.
  381. if (element->GetParentNode() != selection_element || element->HasAttribute("data-for") || element->GetTagName() != "option")
  382. return;
  383. // Force to block display. Register a click handler so we can be notified of selection.
  384. element->SetProperty(PropertyId::Display, Property(Style::Display::Block));
  385. element->SetProperty(PropertyId::Clip, Property(Style::Clip::Type::Auto));
  386. element->AddEventListener(EventId::Click, this);
  387. // Select the option if appropriate.
  388. if (element->HasAttribute("selected"))
  389. SetSelection(element, true);
  390. selection_dirty = true;
  391. box_layout_dirty = true;
  392. }
  393. void WidgetDropDown::OnChildRemove(Element* element)
  394. {
  395. if (element->GetParentNode() != selection_element)
  396. return;
  397. element->RemoveEventListener(EventId::Click, this);
  398. if (element->HasAttribute("selected"))
  399. SetSelection(nullptr);
  400. selection_dirty = true;
  401. box_layout_dirty = true;
  402. }
  403. void WidgetDropDown::AttachScrollEvent()
  404. {
  405. if (ElementDocument* document = parent_element->GetOwnerDocument())
  406. document->AddEventListener(EventId::Scroll, this, true);
  407. }
  408. void WidgetDropDown::DetachScrollEvent()
  409. {
  410. if (ElementDocument* document = parent_element->GetOwnerDocument())
  411. document->RemoveEventListener(EventId::Scroll, this, true);
  412. }
  413. void WidgetDropDown::ProcessEvent(Event& event)
  414. {
  415. if (parent_element->IsDisabled())
  416. return;
  417. // Process the button onclick
  418. switch (event.GetId())
  419. {
  420. case EventId::Click:
  421. {
  422. if (event.GetCurrentElement()->GetParentNode() == selection_element)
  423. {
  424. const int num_options = selection_element->GetNumChildren();
  425. // Find the element in the options and fire the selection event
  426. for (int i = 0; i < num_options; i++)
  427. {
  428. Element* current_element = event.GetCurrentElement();
  429. if (selection_element->GetChild(i) == current_element)
  430. {
  431. if (!event.GetCurrentElement()->HasAttribute("disabled"))
  432. {
  433. SetSelection(current_element);
  434. event.StopPropagation();
  435. HideSelectBox();
  436. parent_element->Focus();
  437. }
  438. }
  439. }
  440. }
  441. else
  442. {
  443. // We have to check that this event isn't targeted to an element
  444. // inside the selection box as we'll get all events coming from our
  445. // root level select element as well as the ones coming from options (which
  446. // get caught in the above if)
  447. Element* element = event.GetTargetElement();
  448. while (element && element != parent_element)
  449. {
  450. if (element == selection_element)
  451. return;
  452. element = element->GetParentNode();
  453. }
  454. if (selection_element->GetComputedValues().visibility() == Style::Visibility::Hidden)
  455. ShowSelectBox();
  456. else
  457. HideSelectBox();
  458. }
  459. }
  460. break;
  461. case EventId::Focus:
  462. {
  463. if (event.GetTargetElement() == parent_element)
  464. {
  465. value_element->SetPseudoClass("focus", true);
  466. button_element->SetPseudoClass("focus", true);
  467. }
  468. }
  469. break;
  470. case EventId::Blur:
  471. {
  472. if (event.GetTargetElement() == parent_element)
  473. {
  474. HideSelectBox();
  475. value_element->SetPseudoClass("focus", false);
  476. button_element->SetPseudoClass("focus", false);
  477. }
  478. }
  479. break;
  480. case EventId::Keydown:
  481. {
  482. Input::KeyIdentifier key_identifier = (Input::KeyIdentifier)event.GetParameter<int>("key_identifier", 0);
  483. auto HasVerticalNavigation = [this](PropertyId id) {
  484. if (const Property* p = parent_element->GetProperty(id))
  485. {
  486. if (p->unit != Unit::KEYWORD)
  487. return true;
  488. const Style::Nav nav = static_cast<Style::Nav>(p->Get<int>());
  489. if (nav == Style::Nav::Auto || nav == Style::Nav::Vertical)
  490. return true;
  491. }
  492. return false;
  493. };
  494. switch (key_identifier)
  495. {
  496. case Input::KI_UP:
  497. if (!box_visible && HasVerticalNavigation(PropertyId::NavUp))
  498. break;
  499. SeekSelection(false);
  500. event.StopPropagation();
  501. break;
  502. case Input::KI_DOWN:
  503. if (!box_visible && HasVerticalNavigation(PropertyId::NavDown))
  504. break;
  505. SeekSelection(true);
  506. event.StopPropagation();
  507. break;
  508. case Input::KI_RETURN:
  509. case Input::KI_NUMPADENTER:
  510. parent_element->Click();
  511. event.StopPropagation();
  512. break;
  513. default: break;
  514. }
  515. }
  516. break;
  517. case EventId::Scroll:
  518. {
  519. if (box_visible)
  520. {
  521. // Close the select box if we scroll outside the select box.
  522. bool scrolls_selection_box = false;
  523. for (Element* element = event.GetTargetElement(); element; element = element->GetParentNode())
  524. {
  525. if (element == selection_element)
  526. {
  527. scrolls_selection_box = true;
  528. break;
  529. }
  530. }
  531. if (!scrolls_selection_box)
  532. HideSelectBox();
  533. }
  534. }
  535. break;
  536. default: break;
  537. }
  538. }
  539. void WidgetDropDown::ShowSelectBox()
  540. {
  541. selection_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
  542. selection_element->SetPseudoClass("checked", true);
  543. value_element->SetPseudoClass("checked", true);
  544. button_element->SetPseudoClass("checked", true);
  545. box_layout_dirty = true;
  546. box_opened_since_last_format = true;
  547. AttachScrollEvent();
  548. box_visible = true;
  549. }
  550. void WidgetDropDown::HideSelectBox()
  551. {
  552. selection_element->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Hidden));
  553. selection_element->RemoveProperty(PropertyId::Height);
  554. selection_element->SetPseudoClass("checked", false);
  555. value_element->SetPseudoClass("checked", false);
  556. button_element->SetPseudoClass("checked", false);
  557. DetachScrollEvent();
  558. box_visible = false;
  559. }
  560. bool WidgetDropDown::IsSelectBoxVisible()
  561. {
  562. return box_visible;
  563. }
  564. } // namespace Rml