2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
|
|
|
|
//#define FCF_NOISY
|
|
|
|
|
|
|
|
const PRInt32 kSizeNotSet = -1;
|
|
|
|
|
|
|
|
nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
|
|
|
|
nsLeafFrame(aContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFormControlFrame::~nsFormControlFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormControlFrame::Destroy()
|
|
|
|
{
|
|
|
|
// Unregister the access key registered in reflow
|
2007-07-08 00:08:04 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLeafFrame::Destroy();
|
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsFormControlFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord
|
|
|
|
nsFormControlFrame::GetIntrinsicWidth()
|
|
|
|
{
|
|
|
|
// Provide a reasonable default for sites that use an "auto" height.
|
|
|
|
// Note that if you change this, you should change the values in forms.css
|
|
|
|
// as well. This is the 13px default width minus the 2px default border.
|
|
|
|
return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFormControlFrame::GetIntrinsicHeight()
|
|
|
|
{
|
|
|
|
// Provide a reasonable default for sites that use an "auto" height.
|
|
|
|
// Note that if you change this, you should change the values in forms.css
|
|
|
|
// as well. This is the 13px default width minus the 2px default border.
|
|
|
|
return nsPresContext::CSSPixelsToAppUnits(13 - 2 * 2);
|
|
|
|
}
|
|
|
|
|
2008-03-07 09:57:34 -08:00
|
|
|
nscoord
|
|
|
|
nsFormControlFrame::GetBaseline() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!NS_SUBTREE_DIRTY(this),
|
|
|
|
"frame must not be dirty");
|
|
|
|
// Treat radio buttons and checkboxes as having an intrinsic baseline
|
|
|
|
// at the bottom of the control (use the bottom content edge rather
|
|
|
|
// than the bottom margin edge).
|
|
|
|
return mRect.height - GetUsedBorderAndPadding().bottom;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_METHOD
|
|
|
|
nsFormControlFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsFormControlFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2007-07-08 00:08:04 -07:00
|
|
|
RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsLeafFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(nsIFrame * aFrame, PRBool aDoReg)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFrame);
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(presContext, "aPresContext is NULL in RegUnRegAccessKey!");
|
|
|
|
|
|
|
|
nsAutoString accessKey;
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
|
|
|
if (!accessKey.IsEmpty()) {
|
|
|
|
nsIEventStateManager *stateManager = presContext->EventStateManager();
|
|
|
|
if (aDoReg) {
|
|
|
|
return stateManager->RegisterAccessKey(content, (PRUint32)accessKey.First());
|
|
|
|
} else {
|
|
|
|
return stateManager->UnregisterAccessKey(content, (PRUint32)accessKey.First());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsFormControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
// Check for user-input:none style
|
|
|
|
const nsStyleUserInterface* uiStyle = GetStyleUserInterface();
|
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
|
|
|
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFormControlFrame::GetCurrentCheckState(PRBool *aState)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(mContent);
|
|
|
|
if (inputElement) {
|
|
|
|
inputElement->GetChecked(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFormControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFormControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-17 20:21:07 -07:00
|
|
|
// static
|
|
|
|
nsRect
|
|
|
|
nsFormControlFrame::GetUsableScreenRect(nsPresContext* aPresContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsRect screen;
|
|
|
|
|
|
|
|
nsIDeviceContext *context = aPresContext->DeviceContext();
|
|
|
|
PRBool dropdownCanOverlapOSBar = PR_FALSE;
|
|
|
|
nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel();
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar,
|
|
|
|
dropdownCanOverlapOSBar);
|
|
|
|
if ( dropdownCanOverlapOSBar )
|
2009-08-17 20:21:07 -07:00
|
|
|
context->GetRect(screen);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
context->GetClientRect(screen);
|
|
|
|
|
2009-08-17 20:21:07 -07:00
|
|
|
return screen;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|