1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 sw=2 et tw=78: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Pierre Phaneuf <pp@ludusdesign.com>
25 : * Mats Palmgren <mats.palmgren@bredband.net>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either of the GNU General Public License Version 2 or later (the "GPL"),
29 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #ifndef nsHTMLOptionElement_h__
42 : #define nsHTMLOptionElement_h__
43 :
44 : #include "nsGenericHTMLElement.h"
45 : #include "nsIDOMHTMLOptionElement.h"
46 : #include "nsIJSNativeInitializer.h"
47 :
48 : class nsHTMLSelectElement;
49 :
50 : class nsHTMLOptionElement : public nsGenericHTMLElement,
51 : public nsIDOMHTMLOptionElement,
52 : public nsIJSNativeInitializer
53 : {
54 : public:
55 : nsHTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
56 : virtual ~nsHTMLOptionElement();
57 :
58 : /** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
59 0 : static nsHTMLOptionElement* FromContent(nsIContent *aContent)
60 : {
61 0 : if (aContent && aContent->IsHTML(nsGkAtoms::option))
62 0 : return static_cast<nsHTMLOptionElement*>(aContent);
63 0 : return nsnull;
64 : }
65 :
66 : // nsISupports
67 : NS_DECL_ISUPPORTS_INHERITED
68 :
69 : // nsIDOMNode
70 0 : NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
71 :
72 : // nsIDOMElement
73 0 : NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
74 :
75 : // nsIDOMHTMLElement
76 0 : NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
77 :
78 : // nsIDOMHTMLOptionElement
79 : using nsGenericElement::SetText;
80 : using nsGenericElement::GetText;
81 : NS_DECL_NSIDOMHTMLOPTIONELEMENT
82 :
83 : bool Selected() const;
84 : bool DefaultSelected() const;
85 :
86 : // nsIJSNativeInitializer
87 : NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
88 : JSObject *aObj, PRUint32 argc, jsval *argv);
89 :
90 : virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
91 : PRInt32 aModType) const;
92 :
93 : virtual nsresult BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
94 : const nsAttrValueOrString* aValue,
95 : bool aNotify);
96 :
97 : void SetSelectedInternal(bool aValue, bool aNotify);
98 :
99 : // nsIContent
100 : virtual nsEventStates IntrinsicState() const;
101 :
102 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
103 :
104 : nsresult CopyInnerTo(nsGenericElement* aDest) const;
105 :
106 : virtual nsXPCClassInfo* GetClassInfo();
107 :
108 0 : virtual bool IsDisabled() const {
109 0 : return HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
110 : }
111 : protected:
112 : /**
113 : * Get the select content element that contains this option, this
114 : * intentionally does not return nsresult, all we care about is if
115 : * there's a select associated with this option or not.
116 : */
117 : nsHTMLSelectElement* GetSelect();
118 :
119 : bool mSelectedChanged;
120 : bool mIsSelected;
121 :
122 : // True only while we're under the SetOptionsSelectedByIndex call when our
123 : // "selected" attribute is changing and mSelectedChanged is false.
124 : bool mIsInSetDefaultSelected;
125 : };
126 :
127 : #endif
|