Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / html / HTMLLegendElement.cpp
blob69b0ee49ea8d364e69003b631ce3fc870d52b32a
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"
10 #include "nsIFrame.h"
12 NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
14 namespace mozilla {
15 namespace dom {
18 HTMLLegendElement::~HTMLLegendElement()
22 NS_IMPL_ELEMENT_CLONE(HTMLLegendElement)
24 nsIContent*
25 HTMLLegendElement::GetFieldSet() const
27 nsIContent* parent = GetParent();
29 if (parent && parent->IsHTML(nsGkAtoms::fieldset)) {
30 return parent;
33 return nullptr;
36 bool
37 HTMLLegendElement::ParseAttribute(int32_t aNamespaceID,
38 nsIAtom* aAttribute,
39 const nsAString& aValue,
40 nsAttrValue& aResult)
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 },
49 { 0 }
52 if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
53 return aResult.ParseEnumValue(aValue, kAlignTable, false);
56 return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
57 aResult);
60 nsChangeHint
61 HTMLLegendElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
62 int32_t aModType) const
64 nsChangeHint retval =
65 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
66 if (aAttribute == nsGkAtoms::align) {
67 NS_UpdateHint(retval, NS_STYLE_HINT_REFLOW);
69 return retval;
72 nsresult
73 HTMLLegendElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
74 nsIAtom* aPrefix, const nsAString& aValue,
75 bool aNotify)
77 return nsGenericHTMLElement::SetAttr(aNameSpaceID, aAttribute,
78 aPrefix, aValue, aNotify);
80 nsresult
81 HTMLLegendElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
82 bool aNotify)
84 return nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
87 nsresult
88 HTMLLegendElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
89 nsIContent* aBindingParent,
90 bool aCompileEventHandlers)
92 return nsGenericHTMLElement::BindToTree(aDocument, aParent,
93 aBindingParent,
94 aCompileEventHandlers);
97 void
98 HTMLLegendElement::UnbindFromTree(bool aDeep, bool aNullParent)
100 nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
103 void
104 HTMLLegendElement::Focus(ErrorResult& aError)
106 nsIFrame* frame = GetPrimaryFrame();
107 if (!frame) {
108 return;
111 int32_t tabIndex;
112 if (frame->IsFocusable(&tabIndex, false)) {
113 nsGenericHTMLElement::Focus(aError);
114 return;
117 // If the legend isn't focusable, focus whatever is focusable following
118 // the legend instead, bug 81481.
119 nsIFocusManager* fm = nsFocusManager::GetFocusManager();
120 if (!fm) {
121 return;
124 nsCOMPtr<nsIDOMElement> result;
125 aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD,
126 nsIFocusManager::FLAG_NOPARENTFRAME,
127 getter_AddRefs(result));
130 void
131 HTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation,
132 bool aIsTrustedEvent)
134 // just use the same behaviour as the focus method
135 ErrorResult rv;
136 Focus(rv);
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);
145 return ret.forget();
148 JSObject*
149 HTMLLegendElement::WrapNode(JSContext* aCx)
151 return HTMLLegendElementBinding::Wrap(aCx, this);
154 } // namespace dom
155 } // namespace mozilla