1 /* -*- Mode: C++; tab-width: 2; 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/. */
6 #include "mozilla/dom/HTMLLegendElement.h"
7 #include "mozilla/dom/HTMLLegendElementBinding.h"
8 #include "nsIDOMHTMLFormElement.h"
9 #include "nsFocusManager.h"
12 NS_IMPL_NS_NEW_HTML_ELEMENT(Legend
)
18 HTMLLegendElement::~HTMLLegendElement()
22 NS_IMPL_ELEMENT_CLONE(HTMLLegendElement
)
25 HTMLLegendElement::GetFieldSet() const
27 nsIContent
* parent
= GetParent();
29 if (parent
&& parent
->IsHTML(nsGkAtoms::fieldset
)) {
37 HTMLLegendElement::ParseAttribute(int32_t aNamespaceID
,
39 const nsAString
& aValue
,
42 // this contains center, because IE4 does
43 static const nsAttrValue::EnumTable kAlignTable
[] = {
44 { "left", NS_STYLE_TEXT_ALIGN_LEFT
},
45 { "right", NS_STYLE_TEXT_ALIGN_RIGHT
},
46 { "center", NS_STYLE_TEXT_ALIGN_CENTER
},
47 { "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM
},
48 { "top", NS_STYLE_VERTICAL_ALIGN_TOP
},
52 if (aAttribute
== nsGkAtoms::align
&& aNamespaceID
== kNameSpaceID_None
) {
53 return aResult
.ParseEnumValue(aValue
, kAlignTable
, false);
56 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
61 HTMLLegendElement::GetAttributeChangeHint(const nsIAtom
* aAttribute
,
62 int32_t aModType
) const
65 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute
, aModType
);
66 if (aAttribute
== nsGkAtoms::align
) {
67 NS_UpdateHint(retval
, NS_STYLE_HINT_REFLOW
);
73 HTMLLegendElement::SetAttr(int32_t aNameSpaceID
, nsIAtom
* aAttribute
,
74 nsIAtom
* aPrefix
, const nsAString
& aValue
,
77 return nsGenericHTMLElement::SetAttr(aNameSpaceID
, aAttribute
,
78 aPrefix
, aValue
, aNotify
);
81 HTMLLegendElement::UnsetAttr(int32_t aNameSpaceID
, nsIAtom
* aAttribute
,
84 return nsGenericHTMLElement::UnsetAttr(aNameSpaceID
, aAttribute
, aNotify
);
88 HTMLLegendElement::BindToTree(nsIDocument
* aDocument
, nsIContent
* aParent
,
89 nsIContent
* aBindingParent
,
90 bool aCompileEventHandlers
)
92 return nsGenericHTMLElement::BindToTree(aDocument
, aParent
,
94 aCompileEventHandlers
);
98 HTMLLegendElement::UnbindFromTree(bool aDeep
, bool aNullParent
)
100 nsGenericHTMLElement::UnbindFromTree(aDeep
, aNullParent
);
104 HTMLLegendElement::Focus(ErrorResult
& aError
)
106 nsIFrame
* frame
= GetPrimaryFrame();
112 if (frame
->IsFocusable(&tabIndex
, false)) {
113 nsGenericHTMLElement::Focus(aError
);
117 // If the legend isn't focusable, focus whatever is focusable following
118 // the legend instead, bug 81481.
119 nsIFocusManager
* fm
= nsFocusManager::GetFocusManager();
124 nsCOMPtr
<nsIDOMElement
> result
;
125 aError
= fm
->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD
,
126 nsIFocusManager::FLAG_NOPARENTFRAME
,
127 getter_AddRefs(result
));
131 HTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation
,
132 bool aIsTrustedEvent
)
134 // just use the same behaviour as the focus method
139 already_AddRefed
<HTMLFormElement
>
140 HTMLLegendElement::GetForm()
142 Element
* form
= GetFormElement();
143 MOZ_ASSERT_IF(form
, form
->IsHTML(nsGkAtoms::form
));
144 nsRefPtr
<HTMLFormElement
> ret
= static_cast<HTMLFormElement
*>(form
);
149 HTMLLegendElement::WrapNode(JSContext
* aCx
)
151 return HTMLLegendElementBinding::Wrap(aCx
, this);
155 } // namespace mozilla