1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Mats Palmgren <mats.palmgren@bredband.net>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 : #include "nsHTMLLegendElement.h"
39 : #include "nsIDOMHTMLFormElement.h"
40 : #include "nsIDOMEventTarget.h"
41 : #include "nsGkAtoms.h"
42 : #include "nsStyleConsts.h"
43 : #include "nsIForm.h"
44 : #include "nsIFormControl.h"
45 : #include "nsIDocument.h"
46 : #include "nsPIDOMWindow.h"
47 : #include "nsFocusManager.h"
48 : #include "nsIFrame.h"
49 :
50 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
51 :
52 :
53 0 : nsHTMLLegendElement::nsHTMLLegendElement(already_AddRefed<nsINodeInfo> aNodeInfo)
54 0 : : nsGenericHTMLElement(aNodeInfo)
55 : {
56 0 : }
57 :
58 0 : nsHTMLLegendElement::~nsHTMLLegendElement()
59 : {
60 0 : }
61 :
62 :
63 0 : NS_IMPL_ADDREF_INHERITED(nsHTMLLegendElement, nsGenericElement)
64 0 : NS_IMPL_RELEASE_INHERITED(nsHTMLLegendElement, nsGenericElement)
65 :
66 :
67 0 : DOMCI_NODE_DATA(HTMLLegendElement, nsHTMLLegendElement)
68 :
69 : // QueryInterface implementation for nsHTMLLegendElement
70 0 : NS_INTERFACE_TABLE_HEAD(nsHTMLLegendElement)
71 0 : NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLLegendElement, nsIDOMHTMLLegendElement)
72 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLLegendElement,
73 : nsGenericHTMLElement)
74 0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLLegendElement)
75 :
76 :
77 : // nsIDOMHTMLLegendElement
78 :
79 :
80 0 : NS_IMPL_ELEMENT_CLONE(nsHTMLLegendElement)
81 :
82 :
83 : NS_IMETHODIMP
84 0 : nsHTMLLegendElement::GetForm(nsIDOMHTMLFormElement** aForm)
85 : {
86 0 : Element* form = GetFormElement();
87 :
88 0 : return form ? CallQueryInterface(form, aForm) : NS_OK;
89 : }
90 :
91 :
92 0 : NS_IMPL_STRING_ATTR(nsHTMLLegendElement, Align, align)
93 :
94 : // this contains center, because IE4 does
95 : static const nsAttrValue::EnumTable kAlignTable[] = {
96 : { "left", NS_STYLE_TEXT_ALIGN_LEFT },
97 : { "right", NS_STYLE_TEXT_ALIGN_RIGHT },
98 : { "center", NS_STYLE_TEXT_ALIGN_CENTER },
99 : { "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM },
100 : { "top", NS_STYLE_VERTICAL_ALIGN_TOP },
101 : { 0 }
102 : };
103 :
104 : nsIContent*
105 0 : nsHTMLLegendElement::GetFieldSet()
106 : {
107 0 : nsIContent* parent = GetParent();
108 :
109 0 : if (parent && parent->IsHTML(nsGkAtoms::fieldset)) {
110 0 : return parent;
111 : }
112 :
113 0 : return nsnull;
114 : }
115 :
116 : bool
117 0 : nsHTMLLegendElement::ParseAttribute(PRInt32 aNamespaceID,
118 : nsIAtom* aAttribute,
119 : const nsAString& aValue,
120 : nsAttrValue& aResult)
121 : {
122 0 : if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
123 0 : return aResult.ParseEnumValue(aValue, kAlignTable, false);
124 : }
125 :
126 : return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
127 0 : aResult);
128 : }
129 :
130 : nsChangeHint
131 0 : nsHTMLLegendElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
132 : PRInt32 aModType) const
133 : {
134 : nsChangeHint retval =
135 0 : nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
136 0 : if (aAttribute == nsGkAtoms::align) {
137 0 : NS_UpdateHint(retval, NS_STYLE_HINT_REFLOW);
138 : }
139 0 : return retval;
140 : }
141 :
142 : nsresult
143 0 : nsHTMLLegendElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
144 : nsIAtom* aPrefix, const nsAString& aValue,
145 : bool aNotify)
146 : {
147 : return nsGenericHTMLElement::SetAttr(aNameSpaceID, aAttribute,
148 0 : aPrefix, aValue, aNotify);
149 : }
150 : nsresult
151 0 : nsHTMLLegendElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
152 : bool aNotify)
153 : {
154 0 : return nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
155 : }
156 :
157 : nsresult
158 0 : nsHTMLLegendElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
159 : nsIContent* aBindingParent,
160 : bool aCompileEventHandlers)
161 : {
162 : return nsGenericHTMLElement::BindToTree(aDocument, aParent,
163 : aBindingParent,
164 0 : aCompileEventHandlers);
165 : }
166 :
167 : void
168 0 : nsHTMLLegendElement::UnbindFromTree(bool aDeep, bool aNullParent)
169 : {
170 0 : nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
171 0 : }
172 :
173 : NS_IMETHODIMP
174 0 : nsHTMLLegendElement::Focus()
175 : {
176 0 : nsIFrame* frame = GetPrimaryFrame();
177 0 : if (!frame)
178 0 : return NS_OK;
179 :
180 : PRInt32 tabIndex;
181 0 : if (frame->IsFocusable(&tabIndex, false))
182 0 : return nsGenericHTMLElement::Focus();
183 :
184 : // If the legend isn't focusable, focus whatever is focusable following
185 : // the legend instead, bug 81481.
186 0 : nsIFocusManager* fm = nsFocusManager::GetFocusManager();
187 0 : if (!fm)
188 0 : return NS_OK;
189 :
190 0 : nsCOMPtr<nsIDOMElement> result;
191 : return fm->MoveFocus(nsnull, this, nsIFocusManager::MOVEFOCUS_FORWARD,
192 : nsIFocusManager::FLAG_NOPARENTFRAME,
193 0 : getter_AddRefs(result));
194 : }
195 :
196 : void
197 0 : nsHTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation,
198 : bool aIsTrustedEvent)
199 : {
200 : // just use the same behaviour as the focus method
201 0 : Focus();
202 0 : }
203 :
|