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 
7 #ifndef mozilla_dom_HTMLBRElement_h
8 #define mozilla_dom_HTMLBRElement_h
9 
10 #include "mozilla/Attributes.h"
11 #include "nsGenericHTMLElement.h"
12 #include "nsGkAtoms.h"
13 
14 namespace mozilla {
15 namespace dom {
16 
17 #define BR_ELEMENT_FLAG_BIT(n_) \
18   NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
19 
20 // BR element specific bits
21 enum {
22   // NS_PADDING_FOR_EMPTY_EDITOR is set if the <br> element is created by
23   // editor for placing caret at proper position in empty editor.
24   NS_PADDING_FOR_EMPTY_EDITOR = BR_ELEMENT_FLAG_BIT(0),
25 
26   // NS_PADDING_FOR_EMPTY_LAST_LINE is set if the <br> element is created by
27   // editor for placing caret at proper position for making empty last line
28   // in a block or <textarea> element visible.
29   NS_PADDING_FOR_EMPTY_LAST_LINE = BR_ELEMENT_FLAG_BIT(1),
30 };
31 
32 ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 2);
33 
34 class HTMLBRElement final : public nsGenericHTMLElement {
35  public:
36   explicit HTMLBRElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
37 
38   NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLBRElement, br)
39 
40   virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
41                               const nsAString& aValue,
42                               nsIPrincipal* aMaybeScriptedPrincipal,
43                               nsAttrValue& aResult) override;
44   NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
45   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction()
46       const override;
47   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
48 
Clear()49   bool Clear() { return GetBoolAttr(nsGkAtoms::clear); }
SetClear(const nsAString & aClear,ErrorResult & aError)50   void SetClear(const nsAString& aClear, ErrorResult& aError) {
51     return SetHTMLAttr(nsGkAtoms::clear, aClear, aError);
52   }
GetClear(DOMString & aClear)53   void GetClear(DOMString& aClear) const {
54     return GetHTMLAttr(nsGkAtoms::clear, aClear);
55   }
56 
57   virtual JSObject* WrapNode(JSContext* aCx,
58                              JS::Handle<JSObject*> aGivenProto) override;
59 
IsPaddingForEmptyEditor()60   bool IsPaddingForEmptyEditor() const {
61     return HasFlag(NS_PADDING_FOR_EMPTY_EDITOR);
62   }
IsPaddingForEmptyLastLine()63   bool IsPaddingForEmptyLastLine() const {
64     return HasFlag(NS_PADDING_FOR_EMPTY_LAST_LINE);
65   }
66 
67  private:
68   virtual ~HTMLBRElement();
69 
70   static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
71                                     MappedDeclarations&);
72 };
73 
74 }  // namespace dom
75 }  // namespace mozilla
76 
77 #endif
78