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 "nsHTMLButtonControlFrame.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsButtonFrameRenderer.h"
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMHTMLButtonElement.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsDisplayList.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-28 14:53:44 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewHTMLButtonControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsHTMLButtonControlFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLButtonControlFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLButtonControlFrame::nsHTMLButtonControlFrame(nsStyleContext* aContext)
|
2011-12-27 12:18:48 -08:00
|
|
|
: nsContainerFrame(aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLButtonControlFrame::~nsHTMLButtonControlFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsHTMLButtonControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2011-12-27 12:18:48 -08:00
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLButtonControlFrame::Init(
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
mRenderer.SetFrame(this, PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
2011-12-27 12:18:48 -08:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
a11y::AccType
|
|
|
|
nsHTMLButtonControlFrame::AccessibleType()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-17 17:25:52 -08:00
|
|
|
return a11y::eHTMLButtonType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLButtonControlFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::HTMLButtonControlFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLButtonControlFrame::SetFocus(bool aOn, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
// if disabled do nothing
|
|
|
|
if (mRenderer.isDisabled()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mouse clicks are handled by content
|
|
|
|
// we don't want our children to get any events. So just pass it to frame.
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLButtonControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsDisplayList onTop;
|
|
|
|
if (IsVisibleForPainting(aBuilder)) {
|
2013-02-14 03:08:08 -08:00
|
|
|
mRenderer.DisplayButton(aBuilder, aLists.BorderBackground(), &onTop);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-04 01:56:02 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayListCollection set;
|
2013-03-04 01:56:02 -08:00
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
// Do not allow the child subtree to receive events.
|
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
2013-03-04 01:56:02 -08:00
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
if (IsInput() || StyleDisplay()->mOverflowX != NS_STYLE_OVERFLOW_VISIBLE) {
|
2013-03-04 01:56:02 -08:00
|
|
|
nsMargin border = StyleBorder()->GetComputedBorder();
|
2013-04-04 04:36:45 -07:00
|
|
|
nsRect rect(aBuilder->ToReferenceFrame(this), GetSize());
|
2013-03-04 01:56:02 -08:00
|
|
|
rect.Deflate(border);
|
2013-04-04 04:36:45 -07:00
|
|
|
nscoord radii[8];
|
2013-03-04 01:56:02 -08:00
|
|
|
bool hasRadii = GetPaddingBoxBorderRadii(radii);
|
2013-04-04 04:36:45 -07:00
|
|
|
clipState.ClipContainingBlockDescendants(rect, hasRadii ? radii : nullptr);
|
2013-03-04 01:56:02 -08:00
|
|
|
}
|
|
|
|
|
2013-04-04 04:36:45 -07:00
|
|
|
BuildDisplayListForChild(aBuilder, mFrames.FirstChild(), aDirtyRect, set,
|
|
|
|
DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT);
|
|
|
|
// That should put the display items in set.Content()
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put the foreground outline and focus rects on top of the children
|
|
|
|
set.Content()->AppendToTop(&onTop);
|
2013-03-04 01:56:02 -08:00
|
|
|
set.MoveTo(aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayOutline(aBuilder, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// to draw border when selected in editor
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsHTMLButtonControlFrame::GetMinWidth(nsRenderingContext* aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
result = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
kid,
|
|
|
|
nsLayoutUtils::MIN_WIDTH);
|
|
|
|
|
|
|
|
result += mRenderer.GetAddedButtonBorderAndPadding().LeftRight();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsHTMLButtonControlFrame::GetPrefWidth(nsRenderingContext* aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
result = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
kid,
|
|
|
|
nsLayoutUtils::PREF_WIDTH);
|
|
|
|
result += mRenderer.GetAddedButtonBorderAndPadding().LeftRight();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLButtonControlFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE,
|
|
|
|
"Should have real computed width by now");
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reflow the child
|
|
|
|
nsIFrame* firstKid = mFrames.FirstChild();
|
|
|
|
|
|
|
|
// XXXbz Eventually we may want to check-and-bail if
|
|
|
|
// !aReflowState.ShouldReflowAllKids() &&
|
2007-05-06 12:16:51 -07:00
|
|
|
// !NS_SUBTREE_DIRTY(firstKid).
|
2007-03-22 10:30:00 -07:00
|
|
|
// We'd need to cache our ascent for that, of course.
|
|
|
|
|
|
|
|
nsMargin focusPadding = mRenderer.GetAddedButtonBorderAndPadding();
|
|
|
|
|
|
|
|
// Reflow the contents of the button.
|
|
|
|
ReflowButtonContents(aPresContext, aDesiredSize, aReflowState, firstKid,
|
|
|
|
focusPadding, aStatus);
|
|
|
|
|
|
|
|
aDesiredSize.width = aReflowState.ComputedWidth();
|
|
|
|
|
|
|
|
// If computed use the computed value.
|
2012-08-27 12:46:23 -07:00
|
|
|
if (aReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
|
2007-08-02 11:08:05 -07:00
|
|
|
aDesiredSize.height = aReflowState.ComputedHeight();
|
2012-08-27 12:46:23 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredSize.height += focusPadding.TopBottom();
|
|
|
|
|
2012-08-27 12:46:23 -07:00
|
|
|
// Make sure we obey min/max-height in the case when we're doing intrinsic
|
|
|
|
// sizing (we get it for free when we have a non-intrinsic
|
|
|
|
// aReflowState.ComputedHeight()). Note that we do this before adjusting
|
|
|
|
// for borderpadding, since mComputedMaxHeight and mComputedMinHeight are
|
|
|
|
// content heights.
|
|
|
|
aDesiredSize.height = NS_CSS_MINMAX(aDesiredSize.height,
|
|
|
|
aReflowState.mComputedMinHeight,
|
|
|
|
aReflowState.mComputedMaxHeight);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-27 12:46:23 -07:00
|
|
|
aDesiredSize.width += aReflowState.mComputedBorderPadding.LeftRight();
|
|
|
|
aDesiredSize.height += aReflowState.mComputedBorderPadding.TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aDesiredSize.ascent +=
|
|
|
|
aReflowState.mComputedBorderPadding.top + focusPadding.top;
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, firstKid);
|
2011-05-11 16:53:34 -07:00
|
|
|
FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aFirstKid,
|
|
|
|
nsMargin aFocusPadding,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_INTRINSICSIZE);
|
|
|
|
|
|
|
|
// Indent the child inside us by the focus border. We must do this separate
|
|
|
|
// from the regular border.
|
|
|
|
availSize.width -= aFocusPadding.LeftRight();
|
|
|
|
|
|
|
|
// See whether out availSize's width is big enough. If it's smaller than our
|
|
|
|
// intrinsic min width, that means that the kid wouldn't really fit; for a
|
|
|
|
// better look in such cases we adjust the available width and our left
|
|
|
|
// offset to allow the kid to spill left into our padding.
|
|
|
|
nscoord xoffset = aFocusPadding.left + aReflowState.mComputedBorderPadding.left;
|
|
|
|
nscoord extrawidth = GetMinWidth(aReflowState.rendContext) -
|
|
|
|
aReflowState.ComputedWidth();
|
|
|
|
if (extrawidth > 0) {
|
|
|
|
nscoord extraleft = extrawidth / 2;
|
|
|
|
nscoord extraright = extrawidth - extraleft;
|
|
|
|
NS_ASSERTION(extraright >=0, "How'd that happen?");
|
|
|
|
|
|
|
|
// Do not allow the extras to be bigger than the relevant padding
|
2013-01-15 04:22:03 -08:00
|
|
|
extraleft = std::min(extraleft, aReflowState.mComputedPadding.left);
|
|
|
|
extraright = std::min(extraright, aReflowState.mComputedPadding.right);
|
2007-03-22 10:30:00 -07:00
|
|
|
xoffset -= extraleft;
|
|
|
|
availSize.width += extraleft + extraright;
|
|
|
|
}
|
2013-01-15 04:22:03 -08:00
|
|
|
availSize.width = std::max(availSize.width,0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLReflowState reflowState(aPresContext, aReflowState, aFirstKid,
|
|
|
|
availSize);
|
|
|
|
|
|
|
|
ReflowChild(aFirstKid, aPresContext, aDesiredSize, reflowState,
|
|
|
|
xoffset,
|
|
|
|
aFocusPadding.top + aReflowState.mComputedBorderPadding.top,
|
|
|
|
0, aStatus);
|
|
|
|
|
|
|
|
// calculate the min internal height so the contents gets centered correctly.
|
|
|
|
// XXXbz this assumes border-box sizing.
|
|
|
|
nscoord minInternalHeight = aReflowState.mComputedMinHeight -
|
|
|
|
aReflowState.mComputedBorderPadding.TopBottom();
|
2013-01-15 04:22:03 -08:00
|
|
|
minInternalHeight = std::max(minInternalHeight, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// center child vertically
|
|
|
|
nscoord yoff = 0;
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
|
|
|
|
yoff = (aReflowState.ComputedHeight() - aDesiredSize.height)/2;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (yoff < 0) {
|
|
|
|
yoff = 0;
|
|
|
|
}
|
|
|
|
} else if (aDesiredSize.height < minInternalHeight) {
|
|
|
|
yoff = (minInternalHeight - aDesiredSize.height) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place the child
|
|
|
|
FinishReflowChild(aFirstKid, aPresContext, &reflowState, aDesiredSize,
|
|
|
|
xoffset,
|
|
|
|
yoff + aFocusPadding.top + aReflowState.mComputedBorderPadding.top, 0);
|
|
|
|
|
|
|
|
if (aDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE)
|
|
|
|
aDesiredSize.ascent = aFirstKid->GetBaseline();
|
|
|
|
|
|
|
|
// Adjust the baseline by our offset (since we moved the child's
|
|
|
|
// baseline by that much).
|
|
|
|
aDesiredSize.ascent += yoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
if (nsGkAtoms::value == aName) {
|
|
|
|
return mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
2011-10-17 07:59:28 -07:00
|
|
|
aValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleContext*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLButtonControlFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mRenderer.GetStyleContext(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLButtonControlFrame::SetAdditionalStyleContext(int32_t aIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
mRenderer.SetStyleContext(aIndex, aStyleContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLButtonControlFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLButtonControlFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsHTMLButtonControlFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|