/src/mozilla-central/dom/html/HTMLLegendElement.cpp
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 | | |
7 | | #include "mozilla/dom/HTMLLegendElement.h" |
8 | | #include "mozilla/dom/HTMLLegendElementBinding.h" |
9 | | #include "nsFocusManager.h" |
10 | | #include "nsIFrame.h" |
11 | | |
12 | | NS_IMPL_NS_NEW_HTML_ELEMENT(Legend) |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | |
18 | | HTMLLegendElement::~HTMLLegendElement() |
19 | 0 | { |
20 | 0 | } |
21 | | |
22 | | NS_IMPL_ELEMENT_CLONE(HTMLLegendElement) |
23 | | |
24 | | nsIContent* |
25 | | HTMLLegendElement::GetFieldSet() const |
26 | 0 | { |
27 | 0 | nsIContent* parent = GetParent(); |
28 | 0 |
|
29 | 0 | if (parent && parent->IsHTMLElement(nsGkAtoms::fieldset)) { |
30 | 0 | return parent; |
31 | 0 | } |
32 | 0 | |
33 | 0 | return nullptr; |
34 | 0 | } |
35 | | |
36 | | bool |
37 | | HTMLLegendElement::ParseAttribute(int32_t aNamespaceID, |
38 | | nsAtom* aAttribute, |
39 | | const nsAString& aValue, |
40 | | nsIPrincipal* aMaybeScriptedPrincipal, |
41 | | nsAttrValue& aResult) |
42 | 0 | { |
43 | 0 | // this contains center, because IE4 does |
44 | 0 | static const nsAttrValue::EnumTable kAlignTable[] = { |
45 | 0 | { "left", NS_STYLE_TEXT_ALIGN_LEFT }, |
46 | 0 | { "right", NS_STYLE_TEXT_ALIGN_RIGHT }, |
47 | 0 | { "center", NS_STYLE_TEXT_ALIGN_CENTER }, |
48 | 0 | { "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM }, |
49 | 0 | { "top", NS_STYLE_VERTICAL_ALIGN_TOP }, |
50 | 0 | { nullptr, 0 } |
51 | 0 | }; |
52 | 0 |
|
53 | 0 | if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) { |
54 | 0 | return aResult.ParseEnumValue(aValue, kAlignTable, false); |
55 | 0 | } |
56 | 0 | |
57 | 0 | return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, |
58 | 0 | aMaybeScriptedPrincipal, aResult); |
59 | 0 | } |
60 | | |
61 | | nsChangeHint |
62 | | HTMLLegendElement::GetAttributeChangeHint(const nsAtom* aAttribute, |
63 | | int32_t aModType) const |
64 | 0 | { |
65 | 0 | nsChangeHint retval = |
66 | 0 | nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType); |
67 | 0 | if (aAttribute == nsGkAtoms::align) { |
68 | 0 | retval |= NS_STYLE_HINT_REFLOW; |
69 | 0 | } |
70 | 0 | return retval; |
71 | 0 | } |
72 | | |
73 | | nsresult |
74 | | HTMLLegendElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, |
75 | | nsIContent* aBindingParent) |
76 | 0 | { |
77 | 0 | return nsGenericHTMLElement::BindToTree(aDocument, aParent, |
78 | 0 | aBindingParent); |
79 | 0 | } |
80 | | |
81 | | void |
82 | | HTMLLegendElement::UnbindFromTree(bool aDeep, bool aNullParent) |
83 | 0 | { |
84 | 0 | nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); |
85 | 0 | } |
86 | | |
87 | | void |
88 | | HTMLLegendElement::Focus(ErrorResult& aError) |
89 | 0 | { |
90 | 0 | nsIFrame* frame = GetPrimaryFrame(); |
91 | 0 | if (!frame) { |
92 | 0 | return; |
93 | 0 | } |
94 | 0 | |
95 | 0 | int32_t tabIndex; |
96 | 0 | if (frame->IsFocusable(&tabIndex, false)) { |
97 | 0 | nsGenericHTMLElement::Focus(aError); |
98 | 0 | return; |
99 | 0 | } |
100 | 0 | |
101 | 0 | // If the legend isn't focusable, focus whatever is focusable following |
102 | 0 | // the legend instead, bug 81481. |
103 | 0 | nsIFocusManager* fm = nsFocusManager::GetFocusManager(); |
104 | 0 | if (!fm) { |
105 | 0 | return; |
106 | 0 | } |
107 | 0 | |
108 | 0 | RefPtr<Element> result; |
109 | 0 | aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD, |
110 | 0 | nsIFocusManager::FLAG_NOPARENTFRAME, |
111 | 0 | getter_AddRefs(result)); |
112 | 0 | } |
113 | | |
114 | | bool |
115 | | HTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation, |
116 | | bool aIsTrustedEvent) |
117 | 0 | { |
118 | 0 | // just use the same behaviour as the focus method |
119 | 0 | ErrorResult rv; |
120 | 0 | Focus(rv); |
121 | 0 | return NS_SUCCEEDED(rv.StealNSResult()); |
122 | 0 | } |
123 | | |
124 | | already_AddRefed<HTMLFormElement> |
125 | | HTMLLegendElement::GetForm() |
126 | 0 | { |
127 | 0 | Element* form = GetFormElement(); |
128 | 0 | MOZ_ASSERT_IF(form, form->IsHTMLElement(nsGkAtoms::form)); |
129 | 0 | RefPtr<HTMLFormElement> ret = static_cast<HTMLFormElement*>(form); |
130 | 0 | return ret.forget(); |
131 | 0 | } |
132 | | |
133 | | JSObject* |
134 | | HTMLLegendElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
135 | 0 | { |
136 | 0 | return HTMLLegendElement_Binding::Wrap(aCx, this, aGivenProto); |
137 | 0 | } |
138 | | |
139 | | } // namespace dom |
140 | | } // namespace mozilla |