/work/obj-fuzz/dist/include/nsGenericHTMLElement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | #ifndef nsGenericHTMLElement_h___ |
7 | | #define nsGenericHTMLElement_h___ |
8 | | |
9 | | #include "mozilla/Attributes.h" |
10 | | #include "mozilla/EventForwards.h" |
11 | | #include "nsMappedAttributeElement.h" |
12 | | #include "nsNameSpaceManager.h" // for kNameSpaceID_None |
13 | | #include "nsIFormControl.h" |
14 | | #include "nsGkAtoms.h" |
15 | | #include "nsContentCreatorFunctions.h" |
16 | | #include "mozilla/ErrorResult.h" |
17 | | #include "mozilla/dom/BindingDeclarations.h" |
18 | | #include "mozilla/dom/DOMRect.h" |
19 | | #include "mozilla/dom/ValidityState.h" |
20 | | #include "mozilla/dom/Element.h" |
21 | | |
22 | | class nsDOMTokenList; |
23 | | class nsIFormControlFrame; |
24 | | class nsIFrame; |
25 | | class nsILayoutHistoryState; |
26 | | class nsIURI; |
27 | | struct nsSize; |
28 | | |
29 | | namespace mozilla { |
30 | | class EventChainPostVisitor; |
31 | | class EventChainPreVisitor; |
32 | | class EventChainVisitor; |
33 | | class EventListenerManager; |
34 | | class EventStates; |
35 | | class TextEditor; |
36 | | class PresState; |
37 | | namespace dom { |
38 | | class HTMLFormElement; |
39 | | class HTMLMenuElement; |
40 | | } // namespace dom |
41 | | } // namespace mozilla |
42 | | |
43 | | typedef nsMappedAttributeElement nsGenericHTMLElementBase; |
44 | | |
45 | | /** |
46 | | * A common superclass for HTML elements |
47 | | */ |
48 | | class nsGenericHTMLElement : public nsGenericHTMLElementBase |
49 | | { |
50 | | public: |
51 | | using Element::SetTabIndex; |
52 | | using Element::Focus; |
53 | | explicit nsGenericHTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
54 | | : nsGenericHTMLElementBase(std::move(aNodeInfo)) |
55 | | { |
56 | | NS_ASSERTION(mNodeInfo->NamespaceID() == kNameSpaceID_XHTML, |
57 | | "Unexpected namespace"); |
58 | | AddStatesSilently(NS_EVENT_STATE_LTR); |
59 | | SetFlags(NODE_HAS_DIRECTION_LTR); |
60 | | } |
61 | | |
62 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(nsGenericHTMLElement, |
63 | | nsGenericHTMLElementBase) |
64 | | |
65 | | NS_IMPL_FROMNODE(nsGenericHTMLElement, kNameSpaceID_XHTML) |
66 | | |
67 | | // From Element |
68 | | nsresult CopyInnerTo(mozilla::dom::Element* aDest); |
69 | | |
70 | | void GetTitle(mozilla::dom::DOMString& aTitle) |
71 | | { |
72 | | GetHTMLAttr(nsGkAtoms::title, aTitle); |
73 | | } |
74 | | void SetTitle(const nsAString& aTitle) |
75 | | { |
76 | | SetHTMLAttr(nsGkAtoms::title, aTitle); |
77 | | } |
78 | | void GetLang(mozilla::dom::DOMString& aLang) |
79 | | { |
80 | | GetHTMLAttr(nsGkAtoms::lang, aLang); |
81 | | } |
82 | | void SetLang(const nsAString& aLang) |
83 | | { |
84 | | SetHTMLAttr(nsGkAtoms::lang, aLang); |
85 | | } |
86 | | void GetDir(nsAString& aDir) |
87 | 0 | { |
88 | 0 | GetHTMLEnumAttr(nsGkAtoms::dir, aDir); |
89 | 0 | } |
90 | | void SetDir(const nsAString& aDir, mozilla::ErrorResult& aError) |
91 | | { |
92 | | SetHTMLAttr(nsGkAtoms::dir, aDir, aError); |
93 | | } |
94 | | bool Hidden() const |
95 | | { |
96 | | return GetBoolAttr(nsGkAtoms::hidden); |
97 | | } |
98 | | void SetHidden(bool aHidden, mozilla::ErrorResult& aError) |
99 | | { |
100 | | SetHTMLBoolAttr(nsGkAtoms::hidden, aHidden, aError); |
101 | | } |
102 | | void Click(mozilla::dom::CallerType aCallerType); |
103 | | void GetAccessKey(nsString& aAccessKey) |
104 | | { |
105 | | GetHTMLAttr(nsGkAtoms::accesskey, aAccessKey); |
106 | | } |
107 | | void SetAccessKey(const nsAString& aAccessKey, mozilla::ErrorResult& aError) |
108 | | { |
109 | | SetHTMLAttr(nsGkAtoms::accesskey, aAccessKey, aError); |
110 | | } |
111 | | void GetAccessKeyLabel(nsString& aAccessKeyLabel); |
112 | | virtual bool Draggable() const |
113 | | { |
114 | | return AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable, |
115 | | nsGkAtoms::_true, eIgnoreCase); |
116 | | } |
117 | | void SetDraggable(bool aDraggable, mozilla::ErrorResult& aError) |
118 | | { |
119 | | SetHTMLAttr(nsGkAtoms::draggable, |
120 | | aDraggable ? NS_LITERAL_STRING("true") |
121 | | : NS_LITERAL_STRING("false"), |
122 | | aError); |
123 | | } |
124 | | void GetContentEditable(nsString& aContentEditable) |
125 | | { |
126 | | ContentEditableTristate value = GetContentEditableValue(); |
127 | | if (value == eTrue) { |
128 | | aContentEditable.AssignLiteral("true"); |
129 | | } else if (value == eFalse) { |
130 | | aContentEditable.AssignLiteral("false"); |
131 | | } else { |
132 | | aContentEditable.AssignLiteral("inherit"); |
133 | | } |
134 | | } |
135 | | void SetContentEditable(const nsAString& aContentEditable, |
136 | | mozilla::ErrorResult& aError) |
137 | | { |
138 | | if (aContentEditable.LowerCaseEqualsLiteral("inherit")) { |
139 | | UnsetHTMLAttr(nsGkAtoms::contenteditable, aError); |
140 | | } else if (aContentEditable.LowerCaseEqualsLiteral("true")) { |
141 | | SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("true"), aError); |
142 | | } else if (aContentEditable.LowerCaseEqualsLiteral("false")) { |
143 | | SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("false"), aError); |
144 | | } else { |
145 | | aError.Throw(NS_ERROR_DOM_SYNTAX_ERR); |
146 | | } |
147 | | } |
148 | | bool IsContentEditable() |
149 | | { |
150 | | for (nsIContent* node = this; node; node = node->GetParent()) { |
151 | | nsGenericHTMLElement* element = FromNode(node); |
152 | | if (element) { |
153 | | ContentEditableTristate value = element->GetContentEditableValue(); |
154 | | if (value != eInherit) { |
155 | | return value == eTrue; |
156 | | } |
157 | | } |
158 | | } |
159 | | return false; |
160 | | } |
161 | | |
162 | | /** |
163 | | * Returns the count of descendants (inclusive of this node) in |
164 | | * the uncomposed document that are explicitly set as editable. |
165 | | */ |
166 | | uint32_t EditableInclusiveDescendantCount(); |
167 | | |
168 | | mozilla::dom::HTMLMenuElement* GetContextMenu() const; |
169 | | bool Spellcheck(); |
170 | | void SetSpellcheck(bool aSpellcheck, mozilla::ErrorResult& aError) |
171 | | { |
172 | | SetHTMLAttr(nsGkAtoms::spellcheck, |
173 | | aSpellcheck ? NS_LITERAL_STRING("true") |
174 | | : NS_LITERAL_STRING("false"), |
175 | | aError); |
176 | | } |
177 | | |
178 | | MOZ_CAN_RUN_SCRIPT |
179 | | void GetInnerText(mozilla::dom::DOMString& aValue, mozilla::ErrorResult& aError); |
180 | | void SetInnerText(const nsAString& aValue); |
181 | | |
182 | | /** |
183 | | * Determine whether an attribute is an event (onclick, etc.) |
184 | | * @param aName the attribute |
185 | | * @return whether the name is an event handler name |
186 | | */ |
187 | | virtual bool IsEventAttributeNameInternal(nsAtom* aName) override; |
188 | | |
189 | | #define EVENT(name_, id_, type_, struct_) /* nothing; handled by nsINode */ |
190 | | // The using nsINode::Get/SetOn* are to avoid warnings about shadowing the XPCOM |
191 | | // getter and setter on nsINode. |
192 | | #define FORWARDED_EVENT(name_, id_, type_, struct_) \ |
193 | | using nsINode::GetOn##name_; \ |
194 | | using nsINode::SetOn##name_; \ |
195 | | mozilla::dom::EventHandlerNonNull* GetOn##name_(); \ |
196 | | void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler); |
197 | | #define ERROR_EVENT(name_, id_, type_, struct_) \ |
198 | | using nsINode::GetOn##name_; \ |
199 | | using nsINode::SetOn##name_; \ |
200 | | already_AddRefed<mozilla::dom::EventHandlerNonNull> GetOn##name_(); \ |
201 | | void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler); |
202 | | #include "mozilla/EventNameList.h" // IWYU pragma: keep |
203 | | #undef ERROR_EVENT |
204 | | #undef FORWARDED_EVENT |
205 | | #undef EVENT |
206 | | mozilla::dom::Element* GetOffsetParent() |
207 | | { |
208 | | mozilla::CSSIntRect rcFrame; |
209 | | return GetOffsetRect(rcFrame); |
210 | | } |
211 | | int32_t OffsetTop() |
212 | | { |
213 | | mozilla::CSSIntRect rcFrame; |
214 | | GetOffsetRect(rcFrame); |
215 | | |
216 | | return rcFrame.y; |
217 | | } |
218 | | int32_t OffsetLeft() |
219 | | { |
220 | | mozilla::CSSIntRect rcFrame; |
221 | | GetOffsetRect(rcFrame); |
222 | | |
223 | | return rcFrame.x; |
224 | | } |
225 | | int32_t OffsetWidth() |
226 | | { |
227 | | mozilla::CSSIntRect rcFrame; |
228 | | GetOffsetRect(rcFrame); |
229 | | |
230 | | return rcFrame.Width(); |
231 | | } |
232 | | int32_t OffsetHeight() |
233 | | { |
234 | | mozilla::CSSIntRect rcFrame; |
235 | | GetOffsetRect(rcFrame); |
236 | | |
237 | | return rcFrame.Height(); |
238 | | } |
239 | | |
240 | | // These methods are already implemented in nsIContent but we want something |
241 | | // faster for HTMLElements ignoring the namespace checking. |
242 | | // This is safe because we already know that we are in the HTML namespace. |
243 | | inline bool IsHTMLElement() const |
244 | 0 | { |
245 | 0 | return true; |
246 | 0 | } |
247 | | |
248 | | inline bool IsHTMLElement(nsAtom* aTag) const |
249 | | { |
250 | | return mNodeInfo->Equals(aTag); |
251 | | } |
252 | | |
253 | | template<typename First, typename... Args> |
254 | | inline bool IsAnyOfHTMLElements(First aFirst, Args... aArgs) const |
255 | 0 | { |
256 | 0 | return IsNodeInternal(aFirst, aArgs...); |
257 | 0 | } Unexecuted instantiation: bool nsGenericHTMLElement::IsAnyOfHTMLElements<nsStaticAtom*, nsStaticAtom*>(nsStaticAtom*, nsStaticAtom*) const Unexecuted instantiation: bool nsGenericHTMLElement::IsAnyOfHTMLElements<nsStaticAtom*, nsStaticAtom*, nsStaticAtom*>(nsStaticAtom*, nsStaticAtom*, nsStaticAtom*) const |
258 | | |
259 | | protected: |
260 | 0 | virtual ~nsGenericHTMLElement() {} |
261 | | |
262 | | public: |
263 | | /** |
264 | | * Get width and height, using given image request if attributes are unset. |
265 | | * Pass a reference to the image request, since the method may change the |
266 | | * value and we want to use the updated value. |
267 | | */ |
268 | | MOZ_CAN_RUN_SCRIPT |
269 | | nsSize GetWidthHeightForImage(RefPtr<imgRequestProxy>& aImageRequest); |
270 | | |
271 | | public: |
272 | | // Implementation for nsIContent |
273 | | virtual nsresult BindToTree(nsIDocument* aDocument, |
274 | | nsIContent* aParent, |
275 | | nsIContent* aBindingParent) override; |
276 | | virtual void UnbindFromTree(bool aDeep = true, |
277 | | bool aNullParent = true) override; |
278 | | |
279 | | virtual bool IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) override |
280 | | { |
281 | | bool isFocusable = false; |
282 | | IsHTMLFocusable(aWithMouse, &isFocusable, aTabIndex); |
283 | | return isFocusable; |
284 | | } |
285 | | /** |
286 | | * Returns true if a subclass is not allowed to override the value returned |
287 | | * in aIsFocusable. |
288 | | */ |
289 | | virtual bool IsHTMLFocusable(bool aWithMouse, |
290 | | bool *aIsFocusable, |
291 | | int32_t *aTabIndex); |
292 | | virtual bool PerformAccesskey(bool aKeyCausesActivation, |
293 | | bool aIsTrustedEvent) override; |
294 | | |
295 | | /** |
296 | | * Check if an event for an anchor can be handled |
297 | | * @return true if the event can be handled, false otherwise |
298 | | */ |
299 | | bool CheckHandleEventForAnchorsPreconditions( |
300 | | mozilla::EventChainVisitor& aVisitor); |
301 | | void GetEventTargetParentForAnchors(mozilla::EventChainPreVisitor& aVisitor); |
302 | | nsresult PostHandleEventForAnchors(mozilla::EventChainPostVisitor& aVisitor); |
303 | | bool IsHTMLLink(nsIURI** aURI) const; |
304 | | |
305 | | // HTML element methods |
306 | 0 | void Compact() { mAttrs.Compact(); } |
307 | | |
308 | | virtual void UpdateEditableState(bool aNotify) override; |
309 | | |
310 | | virtual mozilla::EventStates IntrinsicState() const override; |
311 | | |
312 | | // Helper for setting our editable flag and notifying |
313 | 0 | void DoSetEditableFlag(bool aEditable, bool aNotify) { |
314 | 0 | SetEditableFlag(aEditable); |
315 | 0 | UpdateState(aNotify); |
316 | 0 | } |
317 | | |
318 | | virtual bool ParseAttribute(int32_t aNamespaceID, |
319 | | nsAtom* aAttribute, |
320 | | const nsAString& aValue, |
321 | | nsIPrincipal* aMaybeScriptedPrincipal, |
322 | | nsAttrValue& aResult) override; |
323 | | |
324 | | bool ParseBackgroundAttribute(int32_t aNamespaceID, |
325 | | nsAtom* aAttribute, |
326 | | const nsAString& aValue, |
327 | | nsAttrValue& aResult); |
328 | | |
329 | | NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; |
330 | | virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; |
331 | | |
332 | | /** |
333 | | * Get the base target for any links within this piece |
334 | | * of content. Generally, this is the document's base target, |
335 | | * but certain content carries a local base for backward |
336 | | * compatibility. |
337 | | * |
338 | | * @param aBaseTarget the base target [OUT] |
339 | | */ |
340 | | void GetBaseTarget(nsAString& aBaseTarget) const; |
341 | | |
342 | | /** |
343 | | * Get the primary form control frame for this element. Same as |
344 | | * GetPrimaryFrame(), except it QI's to nsIFormControlFrame. |
345 | | * |
346 | | * @param aFlush whether to flush out frames so that they're up to date. |
347 | | * @return the primary frame as nsIFormControlFrame |
348 | | */ |
349 | | nsIFormControlFrame* GetFormControlFrame(bool aFlushFrames); |
350 | | |
351 | | //---------------------------------------- |
352 | | |
353 | | /** |
354 | | * Parse an alignment attribute (top/middle/bottom/baseline) |
355 | | * |
356 | | * @param aString the string to parse |
357 | | * @param aResult the resulting HTMLValue |
358 | | * @return whether the value was parsed |
359 | | */ |
360 | | static bool ParseAlignValue(const nsAString& aString, |
361 | | nsAttrValue& aResult); |
362 | | |
363 | | /** |
364 | | * Parse a div align string to value (left/right/center/middle/justify) |
365 | | * |
366 | | * @param aString the string to parse |
367 | | * @param aResult the resulting HTMLValue |
368 | | * @return whether the value was parsed |
369 | | */ |
370 | | static bool ParseDivAlignValue(const nsAString& aString, |
371 | | nsAttrValue& aResult); |
372 | | |
373 | | /** |
374 | | * Convert a table halign string to value (left/right/center/char/justify) |
375 | | * |
376 | | * @param aString the string to parse |
377 | | * @param aResult the resulting HTMLValue |
378 | | * @return whether the value was parsed |
379 | | */ |
380 | | static bool ParseTableHAlignValue(const nsAString& aString, |
381 | | nsAttrValue& aResult); |
382 | | |
383 | | /** |
384 | | * Convert a table cell halign string to value |
385 | | * |
386 | | * @param aString the string to parse |
387 | | * @param aResult the resulting HTMLValue |
388 | | * @return whether the value was parsed |
389 | | */ |
390 | | static bool ParseTableCellHAlignValue(const nsAString& aString, |
391 | | nsAttrValue& aResult); |
392 | | |
393 | | /** |
394 | | * Convert a table valign string to value (left/right/center/char/justify/ |
395 | | * abscenter/absmiddle/middle) |
396 | | * |
397 | | * @param aString the string to parse |
398 | | * @param aResult the resulting HTMLValue |
399 | | * @return whether the value was parsed |
400 | | */ |
401 | | static bool ParseTableVAlignValue(const nsAString& aString, |
402 | | nsAttrValue& aResult); |
403 | | |
404 | | /** |
405 | | * Convert an image attribute to value (width, height, hspace, vspace, border) |
406 | | * |
407 | | * @param aAttribute the attribute to parse |
408 | | * @param aString the string to parse |
409 | | * @param aResult the resulting HTMLValue |
410 | | * @return whether the value was parsed |
411 | | */ |
412 | | static bool ParseImageAttribute(nsAtom* aAttribute, |
413 | | const nsAString& aString, |
414 | | nsAttrValue& aResult); |
415 | | |
416 | | static bool ParseReferrerAttribute(const nsAString& aString, |
417 | | nsAttrValue& aResult); |
418 | | |
419 | | /** |
420 | | * Convert a frameborder string to value (yes/no/1/0) |
421 | | * |
422 | | * @param aString the string to parse |
423 | | * @param aResult the resulting HTMLValue |
424 | | * @return whether the value was parsed |
425 | | */ |
426 | | static bool ParseFrameborderValue(const nsAString& aString, |
427 | | nsAttrValue& aResult); |
428 | | |
429 | | /** |
430 | | * Convert a scrolling string to value (yes/no/on/off/scroll/noscroll/auto) |
431 | | * |
432 | | * @param aString the string to parse |
433 | | * @param aResult the resulting HTMLValue |
434 | | * @return whether the value was parsed |
435 | | */ |
436 | | static bool ParseScrollingValue(const nsAString& aString, |
437 | | nsAttrValue& aResult); |
438 | | |
439 | | /* |
440 | | * Attribute Mapping Helpers |
441 | | */ |
442 | | |
443 | | /** |
444 | | * A style attribute mapping function for the most common attributes, to be |
445 | | * called by subclasses' attribute mapping functions. Currently handles |
446 | | * dir, lang and hidden, could handle others. |
447 | | * |
448 | | * @param aAttributes the list of attributes to map |
449 | | * @param aData the returned rule data [INOUT] |
450 | | * @see GetAttributeMappingFunction |
451 | | */ |
452 | | static void MapCommonAttributesInto(const nsMappedAttributes* aAttributes, |
453 | | mozilla::MappedDeclarations&); |
454 | | /** |
455 | | * Same as MapCommonAttributesInto except that it does not handle hidden. |
456 | | * |
457 | | * @param aAttributes the list of attributes to map |
458 | | * @param aData the returned rule data [INOUT] |
459 | | * @see GetAttributeMappingFunction |
460 | | */ |
461 | | static void MapCommonAttributesIntoExceptHidden(const nsMappedAttributes* aAttributes, |
462 | | mozilla::MappedDeclarations&); |
463 | | |
464 | | static const MappedAttributeEntry sCommonAttributeMap[]; |
465 | | static const MappedAttributeEntry sImageMarginSizeAttributeMap[]; |
466 | | static const MappedAttributeEntry sImageBorderAttributeMap[]; |
467 | | static const MappedAttributeEntry sImageAlignAttributeMap[]; |
468 | | static const MappedAttributeEntry sDivAlignAttributeMap[]; |
469 | | static const MappedAttributeEntry sBackgroundAttributeMap[]; |
470 | | static const MappedAttributeEntry sBackgroundColorAttributeMap[]; |
471 | | |
472 | | /** |
473 | | * Helper to map the align attribute into a style struct. |
474 | | * |
475 | | * @param aAttributes the list of attributes to map |
476 | | * @param aData the returned rule data [INOUT] |
477 | | * @see GetAttributeMappingFunction |
478 | | */ |
479 | | static void MapImageAlignAttributeInto(const nsMappedAttributes* aAttributes, |
480 | | mozilla::MappedDeclarations&); |
481 | | |
482 | | /** |
483 | | * Helper to map the align attribute into a style struct for things |
484 | | * like <div>, <h1>, etc. |
485 | | * |
486 | | * @param aAttributes the list of attributes to map |
487 | | * @param aData the returned rule data [INOUT] |
488 | | * @see GetAttributeMappingFunction |
489 | | */ |
490 | | static void MapDivAlignAttributeInto(const nsMappedAttributes* aAttributes, |
491 | | mozilla::MappedDeclarations&); |
492 | | |
493 | | /** |
494 | | * Helper to map the valign attribute into a style struct for things |
495 | | * like <col>, <tr>, <section>, etc. |
496 | | * |
497 | | * @param aAttributes the list of attributes to map |
498 | | * @param aData the returned rule data [INOUT] |
499 | | * @see GetAttributeMappingFunction |
500 | | */ |
501 | | static void MapVAlignAttributeInto(const nsMappedAttributes* aAttributes, |
502 | | mozilla::MappedDeclarations&); |
503 | | |
504 | | /** |
505 | | * Helper to map the image border attribute into a style struct. |
506 | | * |
507 | | * @param aAttributes the list of attributes to map |
508 | | * @param aData the returned rule data [INOUT] |
509 | | * @see GetAttributeMappingFunction |
510 | | */ |
511 | | static void MapImageBorderAttributeInto(const nsMappedAttributes* aAttributes, |
512 | | mozilla::MappedDeclarations&); |
513 | | /** |
514 | | * Helper to map the image margin attribute into a style struct. |
515 | | * |
516 | | * @param aAttributes the list of attributes to map |
517 | | * @param aData the returned rule data [INOUT] |
518 | | * @see GetAttributeMappingFunction |
519 | | */ |
520 | | static void MapImageMarginAttributeInto(const nsMappedAttributes* aAttributes, |
521 | | mozilla::MappedDeclarations&); |
522 | | /** |
523 | | * Helper to map the image position attribute into a style struct. |
524 | | * |
525 | | * @param aAttributes the list of attributes to map |
526 | | * @param aData the returned rule data [INOUT] |
527 | | * @see GetAttributeMappingFunction |
528 | | */ |
529 | | static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes, |
530 | | mozilla::MappedDeclarations&); |
531 | | |
532 | | /** |
533 | | * Helper to map `width` attribute into a style struct. |
534 | | * |
535 | | * @param aAttributes the list of attributes to map |
536 | | * @param aData the returned rule data [INOUT] |
537 | | * @see GetAttributeMappingFunction |
538 | | */ |
539 | | static void MapWidthAttributeInto(const nsMappedAttributes* aAttributes, |
540 | | mozilla::MappedDeclarations&); |
541 | | /** |
542 | | * Helper to map `height` attribute into a style struct. |
543 | | * |
544 | | * @param aAttributes the list of attributes to map |
545 | | * @param aData the returned rule data [INOUT] |
546 | | * @see GetAttributeMappingFunction |
547 | | */ |
548 | | static void MapHeightAttributeInto(const nsMappedAttributes* aAttributes, |
549 | | mozilla::MappedDeclarations&); |
550 | | /** |
551 | | * Helper to map the background attribute |
552 | | * into a style struct. |
553 | | * |
554 | | * @param aAttributes the list of attributes to map |
555 | | * @param aData the returned rule data [INOUT] |
556 | | * @see GetAttributeMappingFunction |
557 | | */ |
558 | | static void MapBackgroundInto(const nsMappedAttributes* aAttributes, |
559 | | mozilla::MappedDeclarations&); |
560 | | /** |
561 | | * Helper to map the bgcolor attribute |
562 | | * into a style struct. |
563 | | * |
564 | | * @param aAttributes the list of attributes to map |
565 | | * @param aData the returned rule data [INOUT] |
566 | | * @see GetAttributeMappingFunction |
567 | | */ |
568 | | static void MapBGColorInto(const nsMappedAttributes* aAttributes, |
569 | | mozilla::MappedDeclarations&); |
570 | | /** |
571 | | * Helper to map the background attributes (currently background and bgcolor) |
572 | | * into a style struct. |
573 | | * |
574 | | * @param aAttributes the list of attributes to map |
575 | | * @param aData the returned rule data [INOUT] |
576 | | * @see GetAttributeMappingFunction |
577 | | */ |
578 | | static void MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes, |
579 | | mozilla::MappedDeclarations&); |
580 | | /** |
581 | | * Helper to map the scrolling attribute on FRAME and IFRAME |
582 | | * into a style struct. |
583 | | * |
584 | | * @param aAttributes the list of attributes to map |
585 | | * @param aData the returned rule data [INOUT] |
586 | | * @see GetAttributeMappingFunction |
587 | | */ |
588 | | static void MapScrollingAttributeInto(const nsMappedAttributes* aAttributes, |
589 | | mozilla::MappedDeclarations&); |
590 | | /** |
591 | | * Get the presentation context for this content node. |
592 | | * @return the presentation context |
593 | | */ |
594 | | enum PresContextFor |
595 | | { |
596 | | eForComposedDoc, |
597 | | eForUncomposedDoc |
598 | | }; |
599 | | nsPresContext* GetPresContext(PresContextFor aFor); |
600 | | |
601 | | // Form Helper Routines |
602 | | /** |
603 | | * Find an ancestor of this content node which is a form (could be null) |
604 | | * @param aCurrentForm the current form for this node. If this is |
605 | | * non-null, and no ancestor form is found, and the current form is in |
606 | | * a connected subtree with the node, the current form will be |
607 | | * returned. This is needed to handle cases when HTML elements have a |
608 | | * current form that they're not descendants of. |
609 | | * @note This method should not be called if the element has a form attribute. |
610 | | */ |
611 | | mozilla::dom::HTMLFormElement* |
612 | | FindAncestorForm(mozilla::dom::HTMLFormElement* aCurrentForm = nullptr); |
613 | | |
614 | | virtual void RecompileScriptEventListeners() override; |
615 | | |
616 | | /** |
617 | | * See if the document being tested has nav-quirks mode enabled. |
618 | | * @param doc the document |
619 | | */ |
620 | | static bool InNavQuirksMode(nsIDocument* aDoc); |
621 | | |
622 | | /** |
623 | | * Gets the absolute URI value of an attribute, by resolving any relative |
624 | | * URIs in the attribute against the baseuri of the element. If the attribute |
625 | | * isn't a relative URI the value of the attribute is returned as is. Only |
626 | | * works for attributes in null namespace. |
627 | | * |
628 | | * @param aAttr name of attribute. |
629 | | * @param aBaseAttr name of base attribute. |
630 | | * @param aResult result value [out] |
631 | | */ |
632 | | void GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr, nsAString& aResult) const; |
633 | | |
634 | | /** |
635 | | * Gets the absolute URI values of an attribute, by resolving any relative |
636 | | * URIs in the attribute against the baseuri of the element. If a substring |
637 | | * isn't a relative URI, the substring is returned as is. Only works for |
638 | | * attributes in null namespace. |
639 | | */ |
640 | | bool GetURIAttr(nsAtom* aAttr, nsAtom* aBaseAttr, nsIURI** aURI) const; |
641 | | |
642 | | /** |
643 | | * Returns the current disabled state of the element. |
644 | | * |
645 | | * TODO(emilio): Consider moving to Element? |
646 | | */ |
647 | | bool IsDisabled() const { |
648 | | return State().HasState(NS_EVENT_STATE_DISABLED); |
649 | | } |
650 | | |
651 | | bool IsHidden() const |
652 | | { |
653 | | return HasAttr(kNameSpaceID_None, nsGkAtoms::hidden); |
654 | | } |
655 | | |
656 | | virtual bool IsLabelable() const override; |
657 | | |
658 | | static bool MatchLabelsElement(Element* aElement, int32_t aNamespaceID, |
659 | | nsAtom* aAtom, void* aData); |
660 | | |
661 | | already_AddRefed<nsINodeList> Labels(); |
662 | | |
663 | | virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override; |
664 | | |
665 | | static bool TouchEventsEnabled(JSContext* /* unused */, JSObject* /* unused */); |
666 | | |
667 | | static inline bool |
668 | | CanHaveName(nsAtom* aTag) |
669 | 0 | { |
670 | 0 | return aTag == nsGkAtoms::img || |
671 | 0 | aTag == nsGkAtoms::form || |
672 | 0 | aTag == nsGkAtoms::embed || |
673 | 0 | aTag == nsGkAtoms::object; |
674 | 0 | } |
675 | | static inline bool |
676 | | ShouldExposeNameAsHTMLDocumentProperty(Element* aElement) |
677 | 0 | { |
678 | 0 | return aElement->IsHTMLElement() && |
679 | 0 | CanHaveName(aElement->NodeInfo()->NameAtom()); |
680 | 0 | } |
681 | | static inline bool |
682 | | ShouldExposeIdAsHTMLDocumentProperty(Element* aElement) |
683 | 0 | { |
684 | 0 | if (aElement->IsHTMLElement(nsGkAtoms::object)) { |
685 | 0 | return true; |
686 | 0 | } |
687 | 0 | |
688 | 0 | // Per spec, <img> is exposed by id only if it also has a nonempty |
689 | 0 | // name (which doesn't have to match the id or anything). |
690 | 0 | // HasName() is true precisely when name is nonempty. |
691 | 0 | return aElement->IsHTMLElement(nsGkAtoms::img) && aElement->HasName(); |
692 | 0 | } |
693 | | |
694 | | protected: |
695 | | /** |
696 | | * Add/remove this element to the documents name cache |
697 | | */ |
698 | | void AddToNameTable(nsAtom* aName); |
699 | | void RemoveFromNameTable(); |
700 | | |
701 | | /** |
702 | | * Register or unregister an access key to this element based on the |
703 | | * accesskey attribute. |
704 | | */ |
705 | | void RegAccessKey() |
706 | 0 | { |
707 | 0 | if (HasFlag(NODE_HAS_ACCESSKEY)) { |
708 | 0 | RegUnRegAccessKey(true); |
709 | 0 | } |
710 | 0 | } |
711 | | |
712 | | void UnregAccessKey() |
713 | 0 | { |
714 | 0 | if (HasFlag(NODE_HAS_ACCESSKEY)) { |
715 | 0 | RegUnRegAccessKey(false); |
716 | 0 | } |
717 | 0 | } |
718 | | |
719 | | private: |
720 | | void RegUnRegAccessKey(bool aDoReg); |
721 | | |
722 | | protected: |
723 | | virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, |
724 | | const nsAttrValueOrString* aValue, |
725 | | bool aNotify) override; |
726 | | virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, |
727 | | const nsAttrValue* aValue, |
728 | | const nsAttrValue* aOldValue, |
729 | | nsIPrincipal* aMaybeScriptedPrincipal, |
730 | | bool aNotify) override; |
731 | | |
732 | | virtual mozilla::EventListenerManager* |
733 | | GetEventListenerManagerForAttr(nsAtom* aAttrName, |
734 | | bool* aDefer) override; |
735 | | |
736 | | /** |
737 | | * Dispatch a simulated mouse click by keyboard to the given element. |
738 | | */ |
739 | | nsresult DispatchSimulatedClick(nsGenericHTMLElement* aElement, |
740 | | bool aIsTrusted, |
741 | | nsPresContext* aPresContext); |
742 | | |
743 | | /** |
744 | | * Create a URI for the given aURISpec string. |
745 | | * Returns INVALID_STATE_ERR and nulls *aURI if aURISpec is empty |
746 | | * and the document's URI matches the element's base URI. |
747 | | */ |
748 | | nsresult NewURIFromString(const nsAString& aURISpec, nsIURI** aURI); |
749 | | |
750 | | void GetHTMLAttr(nsAtom* aName, nsAString& aResult) const |
751 | | { |
752 | | GetAttr(aName, aResult); |
753 | | } |
754 | | void GetHTMLAttr(nsAtom* aName, mozilla::dom::DOMString& aResult) const |
755 | | { |
756 | | GetAttr(kNameSpaceID_None, aName, aResult); |
757 | | } |
758 | | void GetHTMLEnumAttr(nsAtom* aName, nsAString& aResult) const |
759 | 0 | { |
760 | 0 | GetEnumAttr(aName, nullptr, aResult); |
761 | 0 | } |
762 | | void GetHTMLURIAttr(nsAtom* aName, nsAString& aResult) const |
763 | | { |
764 | | GetURIAttr(aName, nullptr, aResult); |
765 | | } |
766 | | |
767 | | void SetHTMLAttr(nsAtom* aName, const nsAString& aValue) |
768 | | { |
769 | | SetAttr(kNameSpaceID_None, aName, aValue, true); |
770 | | } |
771 | | void SetHTMLAttr(nsAtom* aName, const nsAString& aValue, mozilla::ErrorResult& aError) |
772 | | { |
773 | | SetAttr(aName, aValue, aError); |
774 | | } |
775 | | void SetHTMLAttr(nsAtom* aName, const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, mozilla::ErrorResult& aError) |
776 | | { |
777 | | SetAttr(aName, aValue, aTriggeringPrincipal, aError); |
778 | | } |
779 | | void UnsetHTMLAttr(nsAtom* aName, mozilla::ErrorResult& aError) |
780 | | { |
781 | | UnsetAttr(aName, aError); |
782 | | } |
783 | | void SetHTMLBoolAttr(nsAtom* aName, bool aValue, mozilla::ErrorResult& aError) |
784 | | { |
785 | | if (aValue) { |
786 | | SetHTMLAttr(aName, EmptyString(), aError); |
787 | | } else { |
788 | | UnsetHTMLAttr(aName, aError); |
789 | | } |
790 | | } |
791 | | template<typename T> |
792 | | void SetHTMLIntAttr(nsAtom* aName, T aValue, mozilla::ErrorResult& aError) |
793 | | { |
794 | | nsAutoString value; |
795 | | value.AppendInt(aValue); |
796 | | |
797 | | SetHTMLAttr(aName, value, aError); |
798 | | } |
799 | | |
800 | | /** |
801 | | * Gets the integer-value of an attribute, returns specified default value |
802 | | * if the attribute isn't set or isn't set to an integer. Only works for |
803 | | * attributes in null namespace. |
804 | | * |
805 | | * @param aAttr name of attribute. |
806 | | * @param aDefault default-value to return if attribute isn't set. |
807 | | */ |
808 | | int32_t GetIntAttr(nsAtom* aAttr, int32_t aDefault) const; |
809 | | |
810 | | /** |
811 | | * Sets value of attribute to specified integer. Only works for attributes |
812 | | * in null namespace. |
813 | | * |
814 | | * @param aAttr name of attribute. |
815 | | * @param aValue Integer value of attribute. |
816 | | */ |
817 | | nsresult SetIntAttr(nsAtom* aAttr, int32_t aValue); |
818 | | |
819 | | /** |
820 | | * Gets the unsigned integer-value of an attribute, returns specified default |
821 | | * value if the attribute isn't set or isn't set to an integer. Only works for |
822 | | * attributes in null namespace. |
823 | | * |
824 | | * @param aAttr name of attribute. |
825 | | * @param aDefault default-value to return if attribute isn't set. |
826 | | */ |
827 | | uint32_t GetUnsignedIntAttr(nsAtom* aAttr, uint32_t aDefault) const; |
828 | | |
829 | | /** |
830 | | * Sets value of attribute to specified unsigned integer. Only works for |
831 | | * attributes in null namespace. |
832 | | * |
833 | | * @param aAttr name of attribute. |
834 | | * @param aValue Integer value of attribute. |
835 | | * @param aDefault Default value (in case value is out of range). If the spec |
836 | | * doesn't provide one, should be 1 if the value is limited to |
837 | | * nonzero values, and 0 otherwise. |
838 | | */ |
839 | | void SetUnsignedIntAttr(nsAtom* aName, uint32_t aValue, uint32_t aDefault, |
840 | | mozilla::ErrorResult& aError) |
841 | | { |
842 | | nsAutoString value; |
843 | | if (aValue > INT32_MAX) { |
844 | | value.AppendInt(aDefault); |
845 | | } else { |
846 | | value.AppendInt(aValue); |
847 | | } |
848 | | |
849 | | SetHTMLAttr(aName, value, aError); |
850 | | } |
851 | | |
852 | | /** |
853 | | * Sets value of attribute to specified double. Only works for attributes |
854 | | * in null namespace. |
855 | | * |
856 | | * @param aAttr name of attribute. |
857 | | * @param aValue Double value of attribute. |
858 | | */ |
859 | | void SetDoubleAttr(nsAtom* aAttr, double aValue, mozilla::ErrorResult& aRv) |
860 | | { |
861 | | nsAutoString value; |
862 | | value.AppendFloat(aValue); |
863 | | |
864 | | SetHTMLAttr(aAttr, value, aRv); |
865 | | } |
866 | | |
867 | | /** |
868 | | * Locates the TextEditor associated with this node. In general this is |
869 | | * equivalent to GetEditorInternal(), but for designmode or contenteditable, |
870 | | * this may need to get an editor that's not actually on this element's |
871 | | * associated TextControlFrame. This is used by the spellchecking routines |
872 | | * to get the editor affected by changing the spellcheck attribute on this |
873 | | * node. |
874 | | */ |
875 | | virtual already_AddRefed<mozilla::TextEditor> GetAssociatedEditor(); |
876 | | |
877 | | /** |
878 | | * Get the frame's offset information for offsetTop/Left/Width/Height. |
879 | | * Returns the parent the offset is relative to. |
880 | | * @note This method flushes pending notifications (FlushType::Layout). |
881 | | * @param aRect the offset information [OUT] |
882 | | */ |
883 | | mozilla::dom::Element* GetOffsetRect(mozilla::CSSIntRect& aRect); |
884 | | |
885 | | /** |
886 | | * Ensures all editors associated with a subtree are synced, for purposes of |
887 | | * spellchecking. |
888 | | */ |
889 | | static void SyncEditorsOnSubtree(nsIContent* content); |
890 | | |
891 | | enum ContentEditableTristate { |
892 | | eInherit = -1, |
893 | | eFalse = 0, |
894 | | eTrue = 1 |
895 | | }; |
896 | | |
897 | | /** |
898 | | * Returns eTrue if the element has a contentEditable attribute and its value |
899 | | * is "true" or an empty string. Returns eFalse if the element has a |
900 | | * contentEditable attribute and its value is "false". Otherwise returns |
901 | | * eInherit. |
902 | | */ |
903 | | ContentEditableTristate GetContentEditableValue() const |
904 | | { |
905 | | static const Element::AttrValuesArray values[] = |
906 | | { &nsGkAtoms::_false, &nsGkAtoms::_true, &nsGkAtoms::_empty, nullptr }; |
907 | | |
908 | | if (!MayHaveContentEditableAttr()) |
909 | | return eInherit; |
910 | | |
911 | | int32_t value = FindAttrValueIn(kNameSpaceID_None, |
912 | | nsGkAtoms::contenteditable, values, |
913 | | eIgnoreCase); |
914 | | |
915 | | return value > 0 ? eTrue : (value == 0 ? eFalse : eInherit); |
916 | | } |
917 | | |
918 | | // Used by A, AREA, LINK, and STYLE. |
919 | | already_AddRefed<nsIURI> GetHrefURIForAnchors() const; |
920 | | |
921 | | /** |
922 | | * Returns whether this element is an editable root. There are two types of |
923 | | * editable roots: |
924 | | * 1) the documentElement if the whole document is editable (for example for |
925 | | * desginMode=on) |
926 | | * 2) an element that is marked editable with contentEditable=true and that |
927 | | * doesn't have a parent or whose parent is not editable. |
928 | | * Note that this doesn't return input and textarea elements that haven't been |
929 | | * made editable through contentEditable or designMode. |
930 | | */ |
931 | | bool IsEditableRoot() const; |
932 | | |
933 | | private: |
934 | | void ChangeEditableState(int32_t aChange); |
935 | | }; |
936 | | |
937 | | namespace mozilla { |
938 | | namespace dom { |
939 | | class HTMLFieldSetElement; |
940 | | } // namespace dom |
941 | | } // namespace mozilla |
942 | | |
943 | | #define FORM_ELEMENT_FLAG_BIT(n_) NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_)) |
944 | | |
945 | | // Form element specific bits |
946 | | enum { |
947 | | // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement, |
948 | | // that means that we have added ourselves to our mForm. It's possible to |
949 | | // have a non-null mForm, but not have this flag set. That happens when the |
950 | | // form is set via the content sink. |
951 | | ADDED_TO_FORM = FORM_ELEMENT_FLAG_BIT(0), |
952 | | |
953 | | // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement, |
954 | | // that means that its form is in the process of being unbound from the tree, |
955 | | // and this form element hasn't re-found its form in |
956 | | // nsGenericHTMLFormElement::UnbindFromTree yet. |
957 | | MAYBE_ORPHAN_FORM_ELEMENT = FORM_ELEMENT_FLAG_BIT(1), |
958 | | |
959 | | // If this flag is set on an nsGenericHTMLElement or an HTMLImageElement, then |
960 | | // the element might be in the past names map of its form. |
961 | | MAY_BE_IN_PAST_NAMES_MAP = FORM_ELEMENT_FLAG_BIT(2) |
962 | | }; |
963 | | |
964 | | // NOTE: I don't think it's possible to have both ADDED_TO_FORM and |
965 | | // MAYBE_ORPHAN_FORM_ELEMENT set at the same time, so if it becomes an issue we |
966 | | // can probably merge them into the same bit. --bz |
967 | | |
968 | | ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 3); |
969 | | |
970 | | #undef FORM_ELEMENT_FLAG_BIT |
971 | | |
972 | | /** |
973 | | * A helper class for form elements that can contain children |
974 | | */ |
975 | | class nsGenericHTMLFormElement : public nsGenericHTMLElement, |
976 | | public nsIFormControl |
977 | | { |
978 | | public: |
979 | | nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
980 | | uint8_t aType); |
981 | | |
982 | | NS_DECL_ISUPPORTS_INHERITED |
983 | | |
984 | | nsINode* GetScopeChainParent() const override; |
985 | | |
986 | | virtual bool IsNodeOfType(uint32_t aFlags) const override; |
987 | | virtual void SaveSubtreeState() override; |
988 | | |
989 | | // nsIFormControl |
990 | | virtual mozilla::dom::HTMLFieldSetElement* GetFieldSet() override; |
991 | | virtual mozilla::dom::Element* GetFormElement() override; |
992 | | mozilla::dom::HTMLFormElement* GetForm() const |
993 | | { |
994 | | return mForm; |
995 | | } |
996 | | virtual void SetForm(mozilla::dom::HTMLFormElement* aForm) override; |
997 | | virtual void ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete) override; |
998 | | |
999 | | NS_IMETHOD SaveState() override |
1000 | | { |
1001 | | return NS_OK; |
1002 | | } |
1003 | | |
1004 | | virtual bool RestoreState(mozilla::PresState* aState) override |
1005 | | { |
1006 | | return false; |
1007 | | } |
1008 | | virtual bool AllowDrop() override |
1009 | | { |
1010 | | return true; |
1011 | | } |
1012 | | |
1013 | | // nsIContent |
1014 | | virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
1015 | | nsIContent* aBindingParent) override; |
1016 | | virtual void UnbindFromTree(bool aDeep = true, |
1017 | | bool aNullParent = true) override; |
1018 | | virtual IMEState GetDesiredIMEState() override; |
1019 | | virtual mozilla::EventStates IntrinsicState() const override; |
1020 | | |
1021 | | void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; |
1022 | | virtual nsresult PreHandleEvent( |
1023 | | mozilla::EventChainVisitor& aVisitor) override; |
1024 | | |
1025 | | /** |
1026 | | * This callback is called by a fieldest on all its elements whenever its |
1027 | | * disabled attribute is changed so the element knows its disabled state |
1028 | | * might have changed. |
1029 | | * |
1030 | | * @note Classes redefining this method should not do any content |
1031 | | * state updates themselves but should just make sure to call into |
1032 | | * nsGenericHTMLFormElement::FieldSetDisabledChanged. |
1033 | | */ |
1034 | | virtual void FieldSetDisabledChanged(bool aNotify); |
1035 | | |
1036 | | /** |
1037 | | * Check our disabled content attribute and fieldset's (if it exists) disabled |
1038 | | * state to decide whether our disabled flag should be toggled. |
1039 | | */ |
1040 | | void UpdateDisabledState(bool aNotify); |
1041 | | |
1042 | | /** |
1043 | | * Update our required/optional flags to match the given aIsRequired boolean. |
1044 | | */ |
1045 | | void UpdateRequiredState(bool aIsRequired, bool aNotify); |
1046 | | |
1047 | | void FieldSetFirstLegendChanged(bool aNotify) { |
1048 | | UpdateFieldSet(aNotify); |
1049 | | } |
1050 | | |
1051 | | /** |
1052 | | * This callback is called by a fieldset on all it's elements when it's being |
1053 | | * destroyed. When called, the elements should check that aFieldset is there |
1054 | | * first parent fieldset and null mFieldset in that case only. |
1055 | | * |
1056 | | * @param aFieldSet The fieldset being removed. |
1057 | | */ |
1058 | | void ForgetFieldSet(nsIContent* aFieldset); |
1059 | | |
1060 | | /** |
1061 | | * Returns if the control can be disabled. |
1062 | | */ |
1063 | | bool CanBeDisabled() const; |
1064 | | |
1065 | | /** |
1066 | | * Returns if the readonly attribute applies. |
1067 | | */ |
1068 | | bool DoesReadOnlyApply() const; |
1069 | | |
1070 | | virtual bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable, |
1071 | | int32_t* aTabIndex) override; |
1072 | | |
1073 | | virtual bool IsLabelable() const override; |
1074 | | |
1075 | | void GetFormAction(nsString& aValue); |
1076 | | |
1077 | | protected: |
1078 | | virtual ~nsGenericHTMLFormElement(); |
1079 | | |
1080 | | virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName, |
1081 | | const nsAttrValueOrString* aValue, |
1082 | | bool aNotify) override; |
1083 | | |
1084 | | virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, |
1085 | | const nsAttrValue* aValue, |
1086 | | const nsAttrValue* aOldValue, |
1087 | | nsIPrincipal* aMaybeScriptedPrincipal, |
1088 | | bool aNotify) override; |
1089 | | |
1090 | | virtual void BeforeSetForm(bool aBindToTree) {} |
1091 | | |
1092 | | virtual void AfterClearForm(bool aUnbindOrDelete) {} |
1093 | | |
1094 | | void SetForm(mozilla::dom::HTMLFormElement* aForm, bool aBindToTree); |
1095 | | |
1096 | | /** |
1097 | | * This method will update the form owner, using @form or looking to a parent. |
1098 | | * |
1099 | | * @param aBindToTree Whether the element is being attached to the tree. |
1100 | | * @param aFormIdElement The element associated with the id in @form. If |
1101 | | * aBindToTree is false, aFormIdElement *must* contain the element associated |
1102 | | * with the id in @form. Otherwise, it *must* be null. |
1103 | | * |
1104 | | * @note Callers of UpdateFormOwner have to be sure the element is in a |
1105 | | * document (GetUncomposedDoc() != nullptr). |
1106 | | */ |
1107 | | void UpdateFormOwner(bool aBindToTree, Element* aFormIdElement); |
1108 | | |
1109 | | /** |
1110 | | * This method will update mFieldset and set it to the first fieldset parent. |
1111 | | */ |
1112 | | void UpdateFieldSet(bool aNotify); |
1113 | | |
1114 | | /** |
1115 | | * Add a form id observer which will observe when the element with the id in |
1116 | | * @form will change. |
1117 | | * |
1118 | | * @return The element associated with the current id in @form (may be null). |
1119 | | */ |
1120 | | Element* AddFormIdObserver(); |
1121 | | |
1122 | | /** |
1123 | | * Remove the form id observer. |
1124 | | */ |
1125 | | void RemoveFormIdObserver(); |
1126 | | |
1127 | | /** |
1128 | | * This method is a a callback for IDTargetObserver (from nsIDocument). |
1129 | | * It will be called each time the element associated with the id in @form |
1130 | | * changes. |
1131 | | */ |
1132 | | static bool FormIdUpdated(Element* aOldElement, Element* aNewElement, |
1133 | | void* aData); |
1134 | | |
1135 | | // Returns true if the event should not be handled from GetEventTargetParent |
1136 | | bool IsElementDisabledForEvents(mozilla::EventMessage aMessage, |
1137 | | nsIFrame* aFrame); |
1138 | | |
1139 | | // The focusability state of this form control. eUnfocusable means that it |
1140 | | // shouldn't be focused at all, eInactiveWindow means it's in an inactive |
1141 | | // window, eActiveWindow means it's in an active window. |
1142 | | enum FocusTristate { |
1143 | | eUnfocusable, |
1144 | | eInactiveWindow, |
1145 | | eActiveWindow |
1146 | | }; |
1147 | | |
1148 | | // Get our focus state. If this returns eInactiveWindow, it will set this |
1149 | | // element as the focused element for that window. |
1150 | | FocusTristate FocusState(); |
1151 | | |
1152 | | /** The form that contains this control */ |
1153 | | mozilla::dom::HTMLFormElement* mForm; |
1154 | | |
1155 | | /* This is a pointer to our closest fieldset parent if any */ |
1156 | | mozilla::dom::HTMLFieldSetElement* mFieldSet; |
1157 | | }; |
1158 | | |
1159 | | class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement |
1160 | | { |
1161 | | public: |
1162 | | nsGenericHTMLFormElementWithState(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
1163 | | uint8_t aType); |
1164 | | |
1165 | | /** |
1166 | | * Get the presentation state for a piece of content, or create it if it does |
1167 | | * not exist. Generally used by SaveState(). |
1168 | | */ |
1169 | | mozilla::PresState* GetPrimaryPresState(); |
1170 | | |
1171 | | /** |
1172 | | * Get the layout history object for a particular piece of content. |
1173 | | * |
1174 | | * @param aRead if true, won't return a layout history state if the |
1175 | | * layout history state is empty. |
1176 | | * @return the history state object |
1177 | | */ |
1178 | | already_AddRefed<nsILayoutHistoryState> |
1179 | | GetLayoutHistory(bool aRead); |
1180 | | |
1181 | | /** |
1182 | | * Restore the state for a form control. Ends up calling |
1183 | | * nsIFormControl::RestoreState(). |
1184 | | * |
1185 | | * @return false if RestoreState() was not called, the return |
1186 | | * value of RestoreState() otherwise. |
1187 | | */ |
1188 | | bool RestoreFormControlState(); |
1189 | | |
1190 | | /** |
1191 | | * Called when we have been cloned and adopted, and the information of the |
1192 | | * node has been changed. |
1193 | | */ |
1194 | | virtual void NodeInfoChanged(nsIDocument* aOldDoc) override; |
1195 | | |
1196 | | protected: |
1197 | | /* Generates the state key for saving the form state in the session if not |
1198 | | computed already. The result is stored in mStateKey on success */ |
1199 | | nsresult GenerateStateKey(); |
1200 | | |
1201 | | /* Used to store the key to that element in the session. Is void until |
1202 | | GenerateStateKey has been used */ |
1203 | | nsCString mStateKey; |
1204 | | }; |
1205 | | |
1206 | | #define NS_INTERFACE_MAP_ENTRY_IF_TAG(_interface, _tag) \ |
1207 | | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface, \ |
1208 | | mNodeInfo->Equals(nsGkAtoms::_tag)) |
1209 | | |
1210 | | namespace mozilla { |
1211 | | namespace dom { |
1212 | | |
1213 | | typedef nsGenericHTMLElement* (*HTMLContentCreatorFunction)( |
1214 | | already_AddRefed<mozilla::dom::NodeInfo>&&, |
1215 | | mozilla::dom::FromParser aFromParser); |
1216 | | |
1217 | | } // namespace dom |
1218 | | } // namespace mozilla |
1219 | | |
1220 | | /** |
1221 | | * A macro to declare the NS_NewHTMLXXXElement() functions. |
1222 | | */ |
1223 | | #define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName) \ |
1224 | | namespace mozilla { \ |
1225 | | namespace dom { \ |
1226 | | class HTML##_elementName##Element; \ |
1227 | | } \ |
1228 | | } \ |
1229 | | nsGenericHTMLElement* \ |
1230 | | NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \ |
1231 | | mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); |
1232 | | |
1233 | | #define NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(_elementName) \ |
1234 | | inline nsGenericHTMLElement* \ |
1235 | | NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \ |
1236 | | mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER) \ |
1237 | | { \ |
1238 | | return NS_NewHTMLSharedElement(std::move(aNodeInfo), aFromParser); \ |
1239 | | } |
1240 | | |
1241 | | /** |
1242 | | * A macro to implement the NS_NewHTMLXXXElement() functions. |
1243 | | */ |
1244 | | #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName) \ |
1245 | | nsGenericHTMLElement* \ |
1246 | | NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \ |
1247 | | mozilla::dom::FromParser aFromParser) \ |
1248 | | { \ |
1249 | | return new mozilla::dom::HTML##_elementName##Element(std::move(aNodeInfo)); \ |
1250 | | } |
1251 | | |
1252 | | #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName) \ |
1253 | | nsGenericHTMLElement* \ |
1254 | | NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \ |
1255 | | mozilla::dom::FromParser aFromParser) \ |
1256 | | { \ |
1257 | | return new mozilla::dom::HTML##_elementName##Element(std::move(aNodeInfo), \ |
1258 | | aFromParser); \ |
1259 | | } |
1260 | | |
1261 | | // Here, we expand 'NS_DECLARE_NS_NEW_HTML_ELEMENT()' by hand. |
1262 | | // (Calling the macro directly (with no args) produces compiler warnings.) |
1263 | | nsGenericHTMLElement* |
1264 | | NS_NewHTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
1265 | | mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); |
1266 | | |
1267 | | // Distinct from the above in order to have function pointer that compared unequal |
1268 | | // to a function pointer to the above. |
1269 | | nsGenericHTMLElement* |
1270 | | NS_NewCustomElement( |
1271 | | already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
1272 | | mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); |
1273 | | |
1274 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared) |
1275 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList) |
1276 | | |
1277 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor) |
1278 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Area) |
1279 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Audio) |
1280 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(BR) |
1281 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Body) |
1282 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Button) |
1283 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Canvas) |
1284 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Content) |
1285 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod) |
1286 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Data) |
1287 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(DataList) |
1288 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Details) |
1289 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Dialog) |
1290 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Div) |
1291 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Embed) |
1292 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet) |
1293 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Font) |
1294 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Form) |
1295 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Frame) |
1296 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(FrameSet) |
1297 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(HR) |
1298 | | NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Head) |
1299 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Heading) |
1300 | | NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Html) |
1301 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(IFrame) |
1302 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Image) |
1303 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Input) |
1304 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(LI) |
1305 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Label) |
1306 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Legend) |
1307 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Link) |
1308 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Map) |
1309 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Menu) |
1310 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(MenuItem) |
1311 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Meta) |
1312 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Meter) |
1313 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Object) |
1314 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup) |
1315 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Option) |
1316 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Output) |
1317 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph) |
1318 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Picture) |
1319 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre) |
1320 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Progress) |
1321 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Script) |
1322 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Select) |
1323 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Slot) |
1324 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Source) |
1325 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Span) |
1326 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Style) |
1327 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Summary) |
1328 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCaption) |
1329 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCell) |
1330 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCol) |
1331 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Table) |
1332 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TableRow) |
1333 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TableSection) |
1334 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody) |
1335 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Template) |
1336 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea) |
1337 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot) |
1338 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead) |
1339 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Time) |
1340 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Title) |
1341 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Track) |
1342 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown) |
1343 | | NS_DECLARE_NS_NEW_HTML_ELEMENT(Video) |
1344 | | |
1345 | | #endif /* nsGenericHTMLElement_h___ */ |