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