Bug 1560374 - Set testharness and reftest web-platform-tests to Tier-1; r=jmaher...
[gecko.git] / dom / html / HTMLLegendElement.cpp
blob5b7b886f8e2698e90931fa52a324a1211a76d37d
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"
10 #include "nsIFrame.h"
12 NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
14 namespace mozilla {
15 namespace dom {
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)) {
25 return parent;
28 return nullptr;
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},
40 {nullptr, 0}};
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 {
52 nsChangeHint retval =
53 nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
54 if (aAttribute == nsGkAtoms::align) {
55 retval |= NS_STYLE_HINT_REFLOW;
57 return retval;
60 nsresult HTMLLegendElement::BindToTree(BindContext& aContext,
61 nsINode& aParent) {
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();
72 if (!frame) {
73 return;
76 int32_t tabIndex;
77 if (frame->IsFocusable(&tabIndex, false)) {
78 nsGenericHTMLElement::Focus(aOptions, aError);
79 return;
82 // If the legend isn't focusable, focus whatever is focusable following
83 // the legend instead, bug 81481.
84 nsIFocusManager* fm = nsFocusManager::GetFocusManager();
85 if (!fm) {
86 return;
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;
101 ErrorResult rv;
103 Focus(options, rv);
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);
111 return ret.forget();
114 JSObject* HTMLLegendElement::WrapNode(JSContext* aCx,
115 JS::Handle<JSObject*> aGivenProto) {
116 return HTMLLegendElement_Binding::Wrap(aCx, this, aGivenProto);
119 } // namespace dom
120 } // namespace mozilla