HTMLSelectElement.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_HTMLSelectElement_h
  6. #define mozilla_dom_HTMLSelectElement_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsGenericHTMLElement.h"
  9. #include "nsIDOMHTMLSelectElement.h"
  10. #include "nsIConstraintValidation.h"
  11. #include "mozilla/dom/BindingDeclarations.h"
  12. #include "mozilla/dom/HTMLOptionsCollection.h"
  13. #include "mozilla/ErrorResult.h"
  14. #include "nsCheapSets.h"
  15. #include "nsCOMPtr.h"
  16. #include "nsError.h"
  17. #include "mozilla/dom/HTMLFormElement.h"
  18. #include "nsContentUtils.h"
  19. class nsContentList;
  20. class nsIDOMHTMLOptionElement;
  21. class nsIHTMLCollection;
  22. class nsISelectControlFrame;
  23. class nsPresState;
  24. namespace mozilla {
  25. class EventChainPostVisitor;
  26. class EventChainPreVisitor;
  27. namespace dom {
  28. class HTMLFormSubmission;
  29. class HTMLSelectElement;
  30. #define NS_SELECT_STATE_IID \
  31. { /* 4db54c7c-d159-455f-9d8e-f60ee466dbf3 */ \
  32. 0x4db54c7c, \
  33. 0xd159, \
  34. 0x455f, \
  35. {0x9d, 0x8e, 0xf6, 0x0e, 0xe4, 0x66, 0xdb, 0xf3} \
  36. }
  37. /**
  38. * The restore state used by select
  39. */
  40. class SelectState : public nsISupports
  41. {
  42. public:
  43. SelectState()
  44. {
  45. }
  46. NS_DECLARE_STATIC_IID_ACCESSOR(NS_SELECT_STATE_IID)
  47. NS_DECL_ISUPPORTS
  48. void PutOption(int32_t aIndex, const nsAString& aValue)
  49. {
  50. // If the option is empty, store the index. If not, store the value.
  51. if (aValue.IsEmpty()) {
  52. mIndices.Put(aIndex);
  53. } else {
  54. mValues.Put(aValue);
  55. }
  56. }
  57. bool ContainsOption(int32_t aIndex, const nsAString& aValue)
  58. {
  59. return mValues.Contains(aValue) || mIndices.Contains(aIndex);
  60. }
  61. private:
  62. virtual ~SelectState()
  63. {
  64. }
  65. nsCheapSet<nsStringHashKey> mValues;
  66. nsCheapSet<nsUint32HashKey> mIndices;
  67. };
  68. NS_DEFINE_STATIC_IID_ACCESSOR(SelectState, NS_SELECT_STATE_IID)
  69. class MOZ_STACK_CLASS SafeOptionListMutation
  70. {
  71. public:
  72. /**
  73. * @param aSelect The select element which option list is being mutated.
  74. * Can be null.
  75. * @param aParent The content object which is being mutated.
  76. * @param aKid If not null, a new child element is being inserted to
  77. * aParent. Otherwise a child element will be removed.
  78. * @param aIndex The index of the content object in the parent.
  79. */
  80. SafeOptionListMutation(nsIContent* aSelect, nsIContent* aParent,
  81. nsIContent* aKid, uint32_t aIndex, bool aNotify);
  82. ~SafeOptionListMutation();
  83. void MutationFailed() { mNeedsRebuild = true; }
  84. private:
  85. static void* operator new(size_t) CPP_THROW_NEW { return 0; }
  86. static void operator delete(void*, size_t) {}
  87. /** The select element which option list is being mutated. */
  88. RefPtr<HTMLSelectElement> mSelect;
  89. /** true if the current mutation is the first one in the stack. */
  90. bool mTopLevelMutation;
  91. /** true if it is known that the option list must be recreated. */
  92. bool mNeedsRebuild;
  93. /** Option list must be recreated if more than one mutation is detected. */
  94. nsMutationGuard mGuard;
  95. };
  96. /**
  97. * Implementation of &lt;select&gt;
  98. */
  99. class HTMLSelectElement final : public nsGenericHTMLFormElementWithState,
  100. public nsIDOMHTMLSelectElement,
  101. public nsIConstraintValidation
  102. {
  103. public:
  104. /**
  105. * IS_SELECTED whether to set the option(s) to true or false
  106. *
  107. * CLEAR_ALL whether to clear all other options (for example, if you
  108. * are normal-clicking on the current option)
  109. *
  110. * SET_DISABLED whether it is permissible to set disabled options
  111. * (for JavaScript)
  112. *
  113. * NOTIFY whether to notify frames and such
  114. */
  115. enum OptionType {
  116. IS_SELECTED = 1 << 0,
  117. CLEAR_ALL = 1 << 1,
  118. SET_DISABLED = 1 << 2,
  119. NOTIFY = 1 << 3
  120. };
  121. using nsIConstraintValidation::GetValidationMessage;
  122. explicit HTMLSelectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
  123. FromParser aFromParser = NOT_FROM_PARSER);
  124. NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLSelectElement, select)
  125. // nsISupports
  126. NS_DECL_ISUPPORTS_INHERITED
  127. virtual int32_t TabIndexDefault() override;
  128. // Element
  129. virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override
  130. {
  131. return true;
  132. }
  133. // nsIDOMHTMLSelectElement
  134. NS_DECL_NSIDOMHTMLSELECTELEMENT
  135. // WebIdl HTMLSelectElement
  136. bool Autofocus() const
  137. {
  138. return GetBoolAttr(nsGkAtoms::autofocus);
  139. }
  140. void SetAutofocus(bool aVal, ErrorResult& aRv)
  141. {
  142. SetHTMLBoolAttr(nsGkAtoms::autofocus, aVal, aRv);
  143. }
  144. void GetAutocomplete(DOMString& aValue);
  145. void SetAutocomplete(const nsAString& aValue, ErrorResult& aRv)
  146. {
  147. SetHTMLAttr(nsGkAtoms::autocomplete, aValue, aRv);
  148. }
  149. bool Disabled() const
  150. {
  151. return GetBoolAttr(nsGkAtoms::disabled);
  152. }
  153. void SetDisabled(bool aVal, ErrorResult& aRv)
  154. {
  155. SetHTMLBoolAttr(nsGkAtoms::disabled, aVal, aRv);
  156. }
  157. HTMLFormElement* GetForm() const
  158. {
  159. return nsGenericHTMLFormElementWithState::GetForm();
  160. }
  161. bool Multiple() const
  162. {
  163. return GetBoolAttr(nsGkAtoms::multiple);
  164. }
  165. void SetMultiple(bool aVal, ErrorResult& aRv)
  166. {
  167. SetHTMLBoolAttr(nsGkAtoms::multiple, aVal, aRv);
  168. }
  169. // Uses XPCOM GetName.
  170. void SetName(const nsAString& aName, ErrorResult& aRv)
  171. {
  172. SetHTMLAttr(nsGkAtoms::name, aName, aRv);
  173. }
  174. bool Required() const
  175. {
  176. return GetBoolAttr(nsGkAtoms::required);
  177. }
  178. void SetRequired(bool aVal, ErrorResult& aRv)
  179. {
  180. SetHTMLBoolAttr(nsGkAtoms::required, aVal, aRv);
  181. }
  182. uint32_t Size() const
  183. {
  184. return GetUnsignedIntAttr(nsGkAtoms::size, 0);
  185. }
  186. void SetSize(uint32_t aSize, ErrorResult& aRv)
  187. {
  188. SetUnsignedIntAttr(nsGkAtoms::size, aSize, 0, aRv);
  189. }
  190. // Uses XPCOM GetType.
  191. HTMLOptionsCollection* Options() const
  192. {
  193. return mOptions;
  194. }
  195. uint32_t Length() const
  196. {
  197. return mOptions->Length();
  198. }
  199. void SetLength(uint32_t aLength, ErrorResult& aRv);
  200. Element* IndexedGetter(uint32_t aIdx, bool& aFound) const
  201. {
  202. return mOptions->IndexedGetter(aIdx, aFound);
  203. }
  204. HTMLOptionElement* Item(uint32_t aIdx) const
  205. {
  206. return mOptions->ItemAsOption(aIdx);
  207. }
  208. HTMLOptionElement* NamedItem(const nsAString& aName) const
  209. {
  210. return mOptions->GetNamedItem(aName);
  211. }
  212. void Add(const HTMLOptionElementOrHTMLOptGroupElement& aElement,
  213. const Nullable<HTMLElementOrLong>& aBefore,
  214. ErrorResult& aRv);
  215. // Uses XPCOM Remove.
  216. void IndexedSetter(uint32_t aIndex, HTMLOptionElement* aOption,
  217. ErrorResult& aRv)
  218. {
  219. mOptions->IndexedSetter(aIndex, aOption, aRv);
  220. }
  221. static bool MatchSelectedOptions(Element* aElement, int32_t, nsIAtom*,
  222. void*);
  223. nsIHTMLCollection* SelectedOptions();
  224. int32_t SelectedIndex() const
  225. {
  226. return mSelectedIndex;
  227. }
  228. void SetSelectedIndex(int32_t aIdx, ErrorResult& aRv)
  229. {
  230. aRv = SetSelectedIndexInternal(aIdx, true);
  231. }
  232. void GetValue(DOMString& aValue);
  233. // Uses XPCOM SetValue.
  234. // nsIConstraintValidation::WillValidate is fine.
  235. // nsIConstraintValidation::Validity() is fine.
  236. // nsIConstraintValidation::GetValidationMessage() is fine.
  237. // nsIConstraintValidation::CheckValidity() is fine.
  238. using nsIConstraintValidation::CheckValidity;
  239. using nsIConstraintValidation::ReportValidity;
  240. // nsIConstraintValidation::SetCustomValidity() is fine.
  241. using nsINode::Remove;
  242. // nsINode
  243. virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
  244. // nsIContent
  245. virtual nsresult GetEventTargetParent(
  246. EventChainPreVisitor& aVisitor) override;
  247. virtual nsresult PostHandleEvent(
  248. EventChainPostVisitor& aVisitor) override;
  249. virtual bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable, int32_t* aTabIndex) override;
  250. virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
  251. bool aNotify) override;
  252. virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
  253. // Overriden nsIFormControl methods
  254. NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_SELECT; }
  255. NS_IMETHOD Reset() override;
  256. NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
  257. NS_IMETHOD SaveState() override;
  258. virtual bool RestoreState(nsPresState* aState) override;
  259. virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override;
  260. virtual void FieldSetDisabledChanged(bool aNotify) override;
  261. EventStates IntrinsicState() const override;
  262. /**
  263. * To be called when stuff is added under a child of the select--but *before*
  264. * they are actually added.
  265. *
  266. * @param aOptions the content that was added (usually just an option, but
  267. * could be an optgroup node with many child options)
  268. * @param aParent the parent the options were added to (could be an optgroup)
  269. * @param aContentIndex the index where the options are being added within the
  270. * parent (if the parent is an optgroup, the index within the optgroup)
  271. */
  272. NS_IMETHOD WillAddOptions(nsIContent* aOptions,
  273. nsIContent* aParent,
  274. int32_t aContentIndex,
  275. bool aNotify);
  276. /**
  277. * To be called when stuff is removed under a child of the select--but
  278. * *before* they are actually removed.
  279. *
  280. * @param aParent the parent the option(s) are being removed from
  281. * @param aContentIndex the index of the option(s) within the parent (if the
  282. * parent is an optgroup, the index within the optgroup)
  283. */
  284. NS_IMETHOD WillRemoveOptions(nsIContent* aParent,
  285. int32_t aContentIndex,
  286. bool aNotify);
  287. /**
  288. * Checks whether an option is disabled (even if it's part of an optgroup)
  289. *
  290. * @param aIndex the index of the option to check
  291. * @return whether the option is disabled
  292. */
  293. NS_IMETHOD IsOptionDisabled(int32_t aIndex,
  294. bool* aIsDisabled);
  295. bool IsOptionDisabled(HTMLOptionElement* aOption);
  296. /**
  297. * Sets multiple options (or just sets startIndex if select is single)
  298. * and handles notifications and cleanup and everything under the sun.
  299. * When this method exits, the select will be in a consistent state. i.e.
  300. * if you set the last option to false, it will select an option anyway.
  301. *
  302. * @param aStartIndex the first index to set
  303. * @param aEndIndex the last index to set (set same as first index for one
  304. * option)
  305. * @param aOptionsMask determines whether to set, clear all or disable
  306. * options and whether frames are to be notified of such.
  307. * @return whether any options were actually changed
  308. */
  309. bool SetOptionsSelectedByIndex(int32_t aStartIndex,
  310. int32_t aEndIndex,
  311. uint32_t aOptionsMask);
  312. /**
  313. * Finds the index of a given option element
  314. *
  315. * @param aOption the option to get the index of
  316. * @param aStartIndex the index to start looking at
  317. * @param aForward TRUE to look forward, FALSE to look backward
  318. * @return the option index
  319. */
  320. NS_IMETHOD GetOptionIndex(nsIDOMHTMLOptionElement* aOption,
  321. int32_t aStartIndex,
  322. bool aForward,
  323. int32_t* aIndex);
  324. /**
  325. * Called when an attribute is about to be changed
  326. */
  327. virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
  328. nsIContent* aBindingParent,
  329. bool aCompileEventHandlers) override;
  330. virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
  331. virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
  332. const nsAttrValueOrString* aValue,
  333. bool aNotify) override;
  334. virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
  335. const nsAttrValue* aValue,
  336. const nsAttrValue* aOldValue,
  337. bool aNotify) override;
  338. virtual void DoneAddingChildren(bool aHaveNotified) override;
  339. virtual bool IsDoneAddingChildren() override {
  340. return mIsDoneAddingChildren;
  341. }
  342. virtual bool ParseAttribute(int32_t aNamespaceID,
  343. nsIAtom* aAttribute,
  344. const nsAString& aValue,
  345. nsAttrValue& aResult) override;
  346. virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
  347. virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
  348. int32_t aModType) const override;
  349. NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
  350. virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
  351. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLSelectElement,
  352. nsGenericHTMLFormElementWithState)
  353. HTMLOptionsCollection* GetOptions()
  354. {
  355. return mOptions;
  356. }
  357. // nsIConstraintValidation
  358. nsresult GetValidationMessage(nsAString& aValidationMessage,
  359. ValidityStateType aType) override;
  360. void UpdateValueMissingValidityState();
  361. /**
  362. * Insert aElement before the node given by aBefore
  363. */
  364. void Add(nsGenericHTMLElement& aElement, nsGenericHTMLElement* aBefore,
  365. ErrorResult& aError);
  366. void Add(nsGenericHTMLElement& aElement, int32_t aIndex, ErrorResult& aError)
  367. {
  368. // If item index is out of range, insert to last.
  369. // (since beforeElement becomes null, it is inserted to last)
  370. nsIContent* beforeContent = mOptions->GetElementAt(aIndex);
  371. return Add(aElement, nsGenericHTMLElement::FromContentOrNull(beforeContent),
  372. aError);
  373. }
  374. /**
  375. * Is this a combobox?
  376. */
  377. bool IsCombobox() const
  378. {
  379. return !Multiple() && Size() <= 1;
  380. }
  381. bool OpenInParentProcess();
  382. void SetOpenInParentProcess(bool aVal);
  383. protected:
  384. virtual ~HTMLSelectElement() = default;
  385. friend class SafeOptionListMutation;
  386. // Helper Methods
  387. /**
  388. * Check whether the option specified by the index is selected
  389. * @param aIndex the index
  390. * @return whether the option at the index is selected
  391. */
  392. bool IsOptionSelectedByIndex(int32_t aIndex);
  393. /**
  394. * Starting with (and including) aStartIndex, find the first selected index
  395. * and set mSelectedIndex to it.
  396. * @param aStartIndex the index to start with
  397. */
  398. void FindSelectedIndex(int32_t aStartIndex, bool aNotify);
  399. /**
  400. * Select some option if possible (generally the first non-disabled option).
  401. * @return true if something was selected, false otherwise
  402. */
  403. bool SelectSomething(bool aNotify);
  404. /**
  405. * Call SelectSomething(), but only if nothing is selected
  406. * @see SelectSomething()
  407. * @return true if something was selected, false otherwise
  408. */
  409. bool CheckSelectSomething(bool aNotify);
  410. /**
  411. * Called to trigger notifications of frames and fixing selected index
  412. *
  413. * @param aSelectFrame the frame for this content (could be null)
  414. * @param aIndex the index that was selected or deselected
  415. * @param aSelected whether the index was selected or deselected
  416. * @param aChangeOptionState if false, don't do anything to the
  417. * HTMLOptionElement at aIndex. If true, change
  418. * its selected state to aSelected.
  419. * @param aNotify whether to notify the style system and such
  420. */
  421. void OnOptionSelected(nsISelectControlFrame* aSelectFrame,
  422. int32_t aIndex,
  423. bool aSelected,
  424. bool aChangeOptionState,
  425. bool aNotify);
  426. /**
  427. * Restore state to a particular state string (representing the options)
  428. * @param aNewSelected the state string to restore to
  429. */
  430. void RestoreStateTo(SelectState* aNewSelected);
  431. // Adding options
  432. /**
  433. * Insert option(s) into the options[] array and perform notifications
  434. * @param aOptions the option or optgroup being added
  435. * @param aListIndex the index to start adding options into the list at
  436. * @param aDepth the depth of aOptions (1=direct child of select ...)
  437. */
  438. void InsertOptionsIntoList(nsIContent* aOptions,
  439. int32_t aListIndex,
  440. int32_t aDepth,
  441. bool aNotify);
  442. /**
  443. * Remove option(s) from the options[] array
  444. * @param aOptions the option or optgroup being added
  445. * @param aListIndex the index to start removing options from the list at
  446. * @param aDepth the depth of aOptions (1=direct child of select ...)
  447. */
  448. nsresult RemoveOptionsFromList(nsIContent* aOptions,
  449. int32_t aListIndex,
  450. int32_t aDepth,
  451. bool aNotify);
  452. // nsIConstraintValidation
  453. void UpdateBarredFromConstraintValidation();
  454. bool IsValueMissing();
  455. /**
  456. * Get the index of the first option at, under or following the content in
  457. * the select, or length of options[] if none are found
  458. * @param aOptions the content
  459. * @return the index of the first option
  460. */
  461. int32_t GetOptionIndexAt(nsIContent* aOptions);
  462. /**
  463. * Get the next option following the content in question (not at or under)
  464. * (this could include siblings of the current content or siblings of the
  465. * parent or children of siblings of the parent).
  466. * @param aOptions the content
  467. * @return the index of the next option after the content
  468. */
  469. int32_t GetOptionIndexAfter(nsIContent* aOptions);
  470. /**
  471. * Get the first option index at or under the content in question.
  472. * @param aOptions the content
  473. * @return the index of the first option at or under the content
  474. */
  475. int32_t GetFirstOptionIndex(nsIContent* aOptions);
  476. /**
  477. * Get the first option index under the content in question, within the
  478. * range specified.
  479. * @param aOptions the content
  480. * @param aStartIndex the first child to look at
  481. * @param aEndIndex the child *after* the last child to look at
  482. * @return the index of the first option at or under the content
  483. */
  484. int32_t GetFirstChildOptionIndex(nsIContent* aOptions,
  485. int32_t aStartIndex,
  486. int32_t aEndIndex);
  487. /**
  488. * Get the frame as an nsISelectControlFrame (MAY RETURN nullptr)
  489. * @return the select frame, or null
  490. */
  491. nsISelectControlFrame* GetSelectFrame();
  492. /**
  493. * Helper method for dispatching ContentReset notifications to list
  494. * and combo box frames.
  495. */
  496. void DispatchContentReset();
  497. /**
  498. * Rebuilds the options array from scratch as a fallback in error cases.
  499. */
  500. void RebuildOptionsArray(bool aNotify);
  501. #ifdef DEBUG
  502. void VerifyOptionsArray();
  503. #endif
  504. nsresult SetSelectedIndexInternal(int32_t aIndex, bool aNotify);
  505. void SetSelectionChanged(bool aValue, bool aNotify);
  506. /**
  507. * Marks the selectedOptions list as dirty, so that it'll populate itself
  508. * again.
  509. */
  510. void UpdateSelectedOptions();
  511. /**
  512. * Return whether an element should have a validity UI.
  513. * (with :-moz-ui-invalid and :-moz-ui-valid pseudo-classes).
  514. *
  515. * @return Whether the element should have a validity UI.
  516. */
  517. bool ShouldShowValidityUI() const {
  518. /**
  519. * Always show the validity UI if the form has already tried to be submitted
  520. * but was invalid.
  521. *
  522. * Otherwise, show the validity UI if the selection has been changed.
  523. */
  524. if (mForm && mForm->HasEverTriedInvalidSubmit()) {
  525. return true;
  526. }
  527. return mSelectionHasChanged;
  528. }
  529. /** The options[] array */
  530. RefPtr<HTMLOptionsCollection> mOptions;
  531. nsContentUtils::AutocompleteAttrState mAutocompleteAttrState;
  532. /** false if the parser is in the middle of adding children. */
  533. bool mIsDoneAddingChildren;
  534. /** true if our disabled state has changed from the default **/
  535. bool mDisabledChanged;
  536. /** true if child nodes are being added or removed.
  537. * Used by SafeOptionListMutation.
  538. */
  539. bool mMutating;
  540. /**
  541. * True if DoneAddingChildren will get called but shouldn't restore state.
  542. */
  543. bool mInhibitStateRestoration;
  544. /**
  545. * True if the selection has changed since the element's creation.
  546. */
  547. bool mSelectionHasChanged;
  548. /**
  549. * True if the default selected option has been set.
  550. */
  551. bool mDefaultSelectionSet;
  552. /**
  553. * True if :-moz-ui-invalid can be shown.
  554. */
  555. bool mCanShowInvalidUI;
  556. /**
  557. * True if :-moz-ui-valid can be shown.
  558. */
  559. bool mCanShowValidUI;
  560. /** The number of non-options as children of the select */
  561. uint32_t mNonOptionChildren;
  562. /** The number of optgroups anywhere under the select */
  563. uint32_t mOptGroupCount;
  564. /**
  565. * The current selected index for selectedIndex (will be the first selected
  566. * index if multiple are selected)
  567. */
  568. int32_t mSelectedIndex;
  569. /**
  570. * The temporary restore state in case we try to restore before parser is
  571. * done adding options
  572. */
  573. nsCOMPtr<SelectState> mRestoreState;
  574. /**
  575. * The live list of selected options.
  576. */
  577. RefPtr<nsContentList> mSelectedOptions;
  578. private:
  579. static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
  580. nsRuleData* aData);
  581. };
  582. } // namespace dom
  583. } // namespace mozilla
  584. #endif // mozilla_dom_HTMLSelectElement_h