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
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/
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
15 * The Original Code is Mozilla XForms support.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
23 * Brian Ryner <bryner@brianryner.com>
24 * Doron Rosenberg <doronr@us.ibm.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsXFormsUtils.h"
41 #include "nsXFormsControlStub.h"
42 #include "nsXFormsDelegateStub.h"
43 #include "nsXFormsAtoms.h"
45 #include "nsIDOMElement.h"
46 #include "nsIDOMXPathResult.h"
47 #include "nsIDOM3Node.h"
48 #include "nsIDOMDocument.h"
49 #include "nsIDOMText.h"
50 #include "nsStringAPI.h"
51 #include "nsIXFormsUIWidget.h"
52 #include "nsIDocument.h"
53 #include "nsNetUtil.h"
54 #include "nsXFormsModelElement.h"
55 #include "nsXFormsRangeConditionAccessors.h"
56 #include "nsIEventStateManager.h"
58 class nsXFormsSelectElement
: public nsXFormsDelegateStub
61 NS_DECL_ISUPPORTS_INHERITED
63 NS_IMETHOD
OnCreated(nsIXTFElementWrapper
*aWrapper
);
65 // nsIXTFElement overrides
66 NS_IMETHOD
ChildInserted(nsIDOMNode
*aChild
, PRUint32 aIndex
);
67 NS_IMETHOD
ChildAppended(nsIDOMNode
*aChild
);
68 NS_IMETHOD
ChildRemoved(PRUint32 aIndex
);
72 NS_IMETHOD
GetDefaultIntrinsicState(PRInt32
*aState
);
73 NS_IMETHOD
GetDisabledIntrinsicState(PRInt32
*aState
);
75 // nsIXFormsDelegate overrides
76 NS_IMETHOD
GetXFormsAccessors(nsIXFormsAccessors
**aAccessor
);
78 virtual PRBool
IsContentAllowed();
81 virtual const char* Name() { return "select"; }
85 NS_IMPL_ISUPPORTS_INHERITED0(nsXFormsSelectElement
,
89 nsXFormsSelectElement::OnCreated(nsIXTFElementWrapper
*aWrapper
)
91 nsresult rv
= nsXFormsDelegateStub::OnCreated(aWrapper
);
92 NS_ENSURE_SUCCESS(rv
, rv
);
94 aWrapper
->SetNotificationMask(kStandardNotificationMask
|
95 nsIXTFElement::NOTIFY_CHILD_INSERTED
|
96 nsIXTFElement::NOTIFY_CHILD_APPENDED
|
97 nsIXTFElement::NOTIFY_CHILD_REMOVED
|
98 nsIXTFElement::NOTIFY_PERFORM_ACCESSKEY
);
102 // nsIXTFElement overrides
105 nsXFormsSelectElement::ChildInserted(nsIDOMNode
*aChild
, PRUint32 aIndex
)
112 nsXFormsSelectElement::ChildAppended(nsIDOMNode
*aChild
)
119 nsXFormsSelectElement::ChildRemoved(PRUint32 aIndex
)
128 nsXFormsSelectElement::Refresh()
130 PRBool delayRefresh
= nsXFormsModelElement::ContainerNeedsPostRefresh(this);
135 return nsXFormsDelegateStub::Refresh();
139 nsXFormsSelectElement::GetDefaultIntrinsicState(PRInt32
*aState
)
141 NS_ENSURE_ARG_POINTER(aState
);
142 nsXFormsDelegateStub::GetDefaultIntrinsicState(aState
);
143 *aState
|= NS_EVENT_STATE_INRANGE
;
148 nsXFormsSelectElement::GetDisabledIntrinsicState(PRInt32
*aState
)
150 NS_ENSURE_ARG_POINTER(aState
);
151 nsXFormsDelegateStub::GetDisabledIntrinsicState(aState
);
152 *aState
|= NS_EVENT_STATE_INRANGE
;
159 nsXFormsSelectElement::GetXFormsAccessors(nsIXFormsAccessors
**aAccessor
)
162 mAccessor
= new nsXFormsRangeConditionAccessors(this, mElement
);
164 return NS_ERROR_OUT_OF_MEMORY
;
167 NS_ADDREF(*aAccessor
= mAccessor
);
172 nsXFormsSelectElement::IsContentAllowed()
174 PRBool isAllowed
= PR_TRUE
;
176 // For select elements, non-simpleContent is only allowed if the select
177 // element contains an itemset.
178 PRBool isComplex
= IsContentComplex();
179 if (isComplex
&& !nsXFormsUtils::NodeHasItemset(mElement
)) {
180 isAllowed
= PR_FALSE
;
187 NS_NewXFormsSelectElement(nsIXTFElement
**aResult
)
189 *aResult
= new nsXFormsSelectElement();
191 return NS_ERROR_OUT_OF_MEMORY
;