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.org 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 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsFormControlFrame.h"
39 : #include "nsGkAtoms.h"
40 : #include "nsLayoutUtils.h"
41 : #include "nsIDOMHTMLInputElement.h"
42 : #include "nsEventStateManager.h"
43 : #include "mozilla/LookAndFeel.h"
44 :
45 : using namespace mozilla;
46 :
47 : //#define FCF_NOISY
48 :
49 : const PRInt32 kSizeNotSet = -1;
50 :
51 0 : nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
52 0 : nsLeafFrame(aContext)
53 : {
54 0 : }
55 :
56 0 : nsFormControlFrame::~nsFormControlFrame()
57 : {
58 0 : }
59 :
60 : void
61 0 : nsFormControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
62 : {
63 : // Unregister the access key registered in reflow
64 0 : nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
65 0 : nsLeafFrame::DestroyFrom(aDestructRoot);
66 0 : }
67 :
68 0 : NS_QUERYFRAME_HEAD(nsFormControlFrame)
69 0 : NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
70 0 : NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
71 :
72 0 : NS_IMPL_FRAMEARENA_HELPERS(nsFormControlFrame)
73 :
74 : nscoord
75 0 : nsFormControlFrame::GetIntrinsicWidth()
76 : {
77 : // Provide a reasonable default for sites that use an "auto" height.
78 : // Note that if you change this, you should change the values in forms.css
79 : // as well. This is the 13px default width minus the 2px default border.
80 0 : return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
81 : }
82 :
83 : nscoord
84 0 : nsFormControlFrame::GetIntrinsicHeight()
85 : {
86 : // Provide a reasonable default for sites that use an "auto" height.
87 : // Note that if you change this, you should change the values in forms.css
88 : // as well. This is the 13px default width minus the 2px default border.
89 0 : return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
90 : }
91 :
92 : nscoord
93 0 : nsFormControlFrame::GetBaseline() const
94 : {
95 0 : NS_ASSERTION(!NS_SUBTREE_DIRTY(this),
96 : "frame must not be dirty");
97 : // Treat radio buttons and checkboxes as having an intrinsic baseline
98 : // at the bottom of the control (use the bottom content edge rather
99 : // than the bottom margin edge).
100 0 : return mRect.height - GetUsedBorderAndPadding().bottom;
101 : }
102 :
103 : NS_METHOD
104 0 : nsFormControlFrame::Reflow(nsPresContext* aPresContext,
105 : nsHTMLReflowMetrics& aDesiredSize,
106 : const nsHTMLReflowState& aReflowState,
107 : nsReflowStatus& aStatus)
108 : {
109 0 : DO_GLOBAL_REFLOW_COUNT("nsFormControlFrame");
110 0 : DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
111 :
112 0 : if (mState & NS_FRAME_FIRST_REFLOW) {
113 0 : RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
114 : }
115 :
116 : nsresult rv = nsLeafFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
117 0 : aStatus);
118 0 : if (NS_FAILED(rv)) {
119 0 : return rv;
120 : }
121 :
122 0 : if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
123 : float inflation =
124 0 : nsLayoutUtils::FontSizeInflationFor(this, nsLayoutUtils::eInReflow);
125 0 : aDesiredSize.width *= inflation;
126 0 : aDesiredSize.height *= inflation;
127 0 : aDesiredSize.UnionOverflowAreasWithDesiredBounds();
128 0 : FinishAndStoreOverflow(&aDesiredSize);
129 : }
130 0 : return NS_OK;
131 : }
132 :
133 : nsresult
134 0 : nsFormControlFrame::RegUnRegAccessKey(nsIFrame * aFrame, bool aDoReg)
135 : {
136 0 : NS_ENSURE_ARG_POINTER(aFrame);
137 :
138 0 : nsPresContext* presContext = aFrame->PresContext();
139 :
140 0 : NS_ASSERTION(presContext, "aPresContext is NULL in RegUnRegAccessKey!");
141 :
142 0 : nsAutoString accessKey;
143 :
144 0 : nsIContent* content = aFrame->GetContent();
145 0 : content->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
146 0 : if (!accessKey.IsEmpty()) {
147 0 : nsEventStateManager *stateManager = presContext->EventStateManager();
148 0 : if (aDoReg) {
149 0 : stateManager->RegisterAccessKey(content, (PRUint32)accessKey.First());
150 : } else {
151 0 : stateManager->UnregisterAccessKey(content, (PRUint32)accessKey.First());
152 : }
153 0 : return NS_OK;
154 : }
155 0 : return NS_ERROR_FAILURE;
156 : }
157 :
158 : void
159 0 : nsFormControlFrame::SetFocus(bool aOn, bool aRepaint)
160 : {
161 0 : }
162 :
163 : NS_METHOD
164 0 : nsFormControlFrame::HandleEvent(nsPresContext* aPresContext,
165 : nsGUIEvent* aEvent,
166 : nsEventStatus* aEventStatus)
167 : {
168 : // Check for user-input:none style
169 0 : const nsStyleUserInterface* uiStyle = GetStyleUserInterface();
170 0 : if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
171 : uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
172 0 : return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
173 :
174 0 : return NS_OK;
175 : }
176 :
177 : void
178 0 : nsFormControlFrame::GetCurrentCheckState(bool *aState)
179 : {
180 0 : nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(mContent);
181 0 : if (inputElement) {
182 0 : inputElement->GetChecked(aState);
183 : }
184 0 : }
185 :
186 : nsresult
187 0 : nsFormControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
188 : {
189 0 : return NS_OK;
190 : }
191 :
192 : nsresult
193 0 : nsFormControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
194 : {
195 0 : aValue.Truncate();
196 0 : return NS_OK;
197 : }
198 :
199 : // static
200 : nsRect
201 0 : nsFormControlFrame::GetUsableScreenRect(nsPresContext* aPresContext)
202 : {
203 0 : nsRect screen;
204 :
205 0 : nsDeviceContext *context = aPresContext->DeviceContext();
206 : PRInt32 dropdownCanOverlapOSBar =
207 0 : LookAndFeel::GetInt(LookAndFeel::eIntID_MenusCanOverlapOSBar, 0);
208 0 : if ( dropdownCanOverlapOSBar )
209 0 : context->GetRect(screen);
210 : else
211 0 : context->GetClientRect(screen);
212 :
213 : return screen;
214 : }
|