2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2012-01-30 09:48:46 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2011-09-08 19:27:13 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-23 04:55:35 -07:00
|
|
|
#include "nsDeviceContext.h"
|
2011-09-08 19:27:13 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//#define FCF_NOISY
|
|
|
|
|
|
|
|
nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
|
|
|
|
nsLeafFrame(aContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFormControlFrame::~nsFormControlFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-04 16:26:30 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsFormControlFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::formControlFrame;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsFormControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Unregister the access key registered in reflow
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsLeafFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-30 09:48:46 -08:00
|
|
|
nsresult rv = nsLeafFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
|
|
|
aStatus);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
|
2012-05-20 22:18:28 -07:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2012-01-30 09:48:46 -08:00
|
|
|
aDesiredSize.width *= inflation;
|
|
|
|
aDesiredSize.height *= inflation;
|
|
|
|
aDesiredSize.UnionOverflowAreasWithDesiredBounds();
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(nsIFrame * aFrame, bool aDoReg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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()) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager *stateManager = presContext->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDoReg) {
|
2012-08-22 08:56:38 -07:00
|
|
|
stateManager->RegisterAccessKey(content, (uint32_t)accessKey.First());
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
stateManager->UnregisterAccessKey(content, (uint32_t)accessKey.First());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-21 10:35:52 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsFormControlFrame::SetFocus(bool aOn, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsFormControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
// Check for user-input:none style
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsFormControlFrame::GetCurrentCheckState(bool *aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(mContent);
|
|
|
|
if (inputElement) {
|
|
|
|
inputElement->GetChecked(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFormControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *context = aPresContext->DeviceContext();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t dropdownCanOverlapOSBar =
|
2011-09-08 19:27:13 -07:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_MenusCanOverlapOSBar, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
}
|