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/. */
7 #include "mozilla/dom/HTMLLegendElement.h"
8 #include "mozilla/dom/HTMLLegendElementBinding.h"
9 #include "nsFocusManager.h"
12 NS_IMPL_NS_NEW_HTML_ELEMENT(Legend
)
17 HTMLLegendElement::~HTMLLegendElement() {}
19 NS_IMPL_ELEMENT_CLONE(HTMLLegendElement
)
21 nsIContent
* HTMLLegendElement::GetFieldSet() const {
22 nsIContent
* parent
= GetParent();
24 if (parent
&& parent
->IsHTMLElement(nsGkAtoms::fieldset
)) {
31 bool HTMLLegendElement::ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
32 const nsAString
& aValue
,
33 nsIPrincipal
* aMaybeScriptedPrincipal
,
34 nsAttrValue
& aResult
) {
35 // this contains center, because IE4 does
36 static const nsAttrValue::EnumTable kAlignTable
[] = {
37 {"left", NS_STYLE_TEXT_ALIGN_LEFT
},
38 {"right", NS_STYLE_TEXT_ALIGN_RIGHT
},
39 {"center", NS_STYLE_TEXT_ALIGN_CENTER
},
42 if (aAttribute
== nsGkAtoms::align
&& aNamespaceID
== kNameSpaceID_None
) {
43 return aResult
.ParseEnumValue(aValue
, kAlignTable
, false);
46 return nsGenericHTMLElement::ParseAttribute(aNamespaceID
, aAttribute
, aValue
,
47 aMaybeScriptedPrincipal
, aResult
);
50 nsChangeHint
HTMLLegendElement::GetAttributeChangeHint(const nsAtom
* aAttribute
,
51 int32_t aModType
) const {
53 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute
, aModType
);
54 if (aAttribute
== nsGkAtoms::align
) {
55 retval
|= NS_STYLE_HINT_REFLOW
;
60 nsresult
HTMLLegendElement::BindToTree(BindContext
& aContext
,
62 return nsGenericHTMLElement::BindToTree(aContext
, aParent
);
65 void HTMLLegendElement::UnbindFromTree(bool aNullParent
) {
66 nsGenericHTMLElement::UnbindFromTree(aNullParent
);
69 void HTMLLegendElement::Focus(const FocusOptions
& aOptions
,
70 ErrorResult
& aError
) {
71 nsIFrame
* frame
= GetPrimaryFrame();
77 if (frame
->IsFocusable(&tabIndex
, false)) {
78 nsGenericHTMLElement::Focus(aOptions
, aError
);
82 // If the legend isn't focusable, focus whatever is focusable following
83 // the legend instead, bug 81481.
84 nsIFocusManager
* fm
= nsFocusManager::GetFocusManager();
89 RefPtr
<Element
> result
;
90 aError
= fm
->MoveFocus(
91 nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD
,
92 nsIFocusManager::FLAG_NOPARENTFRAME
|
93 nsIFocusManager::FLAG_BYELEMENTFOCUS
|
94 nsFocusManager::FocusOptionsToFocusManagerFlags(aOptions
),
95 getter_AddRefs(result
));
98 bool HTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation
,
99 bool aIsTrustedEvent
) {
100 FocusOptions options
;
104 return NS_SUCCEEDED(rv
.StealNSResult());
107 already_AddRefed
<HTMLFormElement
> HTMLLegendElement::GetForm() {
108 Element
* form
= GetFormElement();
109 MOZ_ASSERT_IF(form
, form
->IsHTMLElement(nsGkAtoms::form
));
110 RefPtr
<HTMLFormElement
> ret
= static_cast<HTMLFormElement
*>(form
);
114 JSObject
* HTMLLegendElement::WrapNode(JSContext
* aCx
,
115 JS::Handle
<JSObject
*> aGivenProto
) {
116 return HTMLLegendElement_Binding::Wrap(aCx
, this, aGivenProto
);
120 } // namespace mozilla