2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-04-22 02:46:15 +04:00
|
|
|
|
|
|
|
#include "nsHTMLButtonControlFrame.h"
|
|
|
|
|
2011-12-28 00:18:48 +04:00
|
|
|
#include "nsContainerFrame.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-03-06 22:43:13 +03:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
2000-01-08 18:53:48 +03:00
|
|
|
#include "nsFormControlFrame.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2004-01-28 03:18:22 +03:00
|
|
|
#include "nsStyleSet.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
1998-10-14 01:31:26 +04:00
|
|
|
|
2012-09-29 01:53:44 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewHTMLButtonControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsHTMLButtonControlFrame(aContext);
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLButtonControlFrame)
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsHTMLButtonControlFrame::nsHTMLButtonControlFrame(nsStyleContext* aContext)
|
2011-12-28 00:18:48 +04:00
|
|
|
: nsContainerFrame(aContext)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
}
|
|
|
|
|
1999-11-05 02:16:47 +03:00
|
|
|
nsHTMLButtonControlFrame::~nsHTMLButtonControlFrame()
|
|
|
|
{
|
2000-05-16 16:44:32 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsHTMLButtonControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2000-05-16 16:44:32 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2011-12-28 00:18:48 +04:00
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
1999-11-05 02:16:47 +03:00
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2006-03-09 21:55:21 +03:00
|
|
|
nsHTMLButtonControlFrame::Init(
|
1999-03-06 22:43:13 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
mRenderer.SetFrame(this, PresContext());
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsHTMLButtonControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
2011-12-28 00:18:48 +04:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
1998-10-14 01:31:26 +04:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsHTMLButtonControlFrame::AccessibleType()
|
2001-05-18 03:52:32 +04:00
|
|
|
{
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLButtonType;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2006-04-25 23:56:45 +04:00
|
|
|
nsIAtom*
|
|
|
|
nsHTMLButtonControlFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::HTMLButtonControlFrame;
|
2006-04-25 23:56:45 +04:00
|
|
|
}
|
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsHTMLButtonControlFrame::SetFocus(bool aOn, bool aRepaint)
|
1998-10-23 03:00:37 +04:00
|
|
|
{
|
1998-10-17 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLButtonControlFrame::HandleEvent(nsPresContext* aPresContext,
|
1999-03-31 10:02:12 +04:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
// if disabled do nothing
|
|
|
|
if (mRenderer.isDisabled()) {
|
1998-10-17 04:35:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-15 03:01:44 +04:00
|
|
|
|
2000-06-21 04:40:11 +04:00
|
|
|
// mouse clicks are handled by content
|
1999-05-13 05:35:16 +04:00
|
|
|
// we don't want our children to get any events. So just pass it to frame.
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
1998-10-15 03:01:44 +04:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsHTMLButtonControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsDisplayList onTop;
|
|
|
|
if (IsVisibleForPainting(aBuilder)) {
|
2013-02-14 15:08:08 +04:00
|
|
|
mRenderer.DisplayButton(aBuilder, aLists.BorderBackground(), &onTop);
|
1999-04-26 00:07:45 +04:00
|
|
|
}
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListCollection set;
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2013-07-11 19:46:04 +04:00
|
|
|
// Do not allow the child subtree to receive events.
|
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
|
|
|
|
|
|
|
if (IsInput() || StyleDisplay()->mOverflowX != NS_STYLE_OVERFLOW_VISIBLE) {
|
|
|
|
nsMargin border = StyleBorder()->GetComputedBorder();
|
|
|
|
nsRect rect(aBuilder->ToReferenceFrame(this), GetSize());
|
|
|
|
rect.Deflate(border);
|
|
|
|
nscoord radii[8];
|
|
|
|
bool hasRadii = GetPaddingBoxBorderRadii(radii);
|
|
|
|
clipState.ClipContainingBlockDescendants(rect, hasRadii ? radii : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildDisplayListForChild(aBuilder, mFrames.FirstChild(), aDirtyRect, set,
|
|
|
|
DISPLAY_CHILD_FORCE_PSEUDO_STACKING_CONTEXT);
|
|
|
|
// That should put the display items in set.Content()
|
2006-02-19 23:14:11 +03:00
|
|
|
}
|
2013-07-11 19:46:04 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Put the foreground outline and focus rects on top of the children
|
|
|
|
set.Content()->AppendToTop(&onTop);
|
2013-03-04 13:56:02 +04:00
|
|
|
set.MoveTo(aLists);
|
2013-07-11 19:46:04 +04:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplayOutline(aBuilder, aLists);
|
2004-11-11 18:07:22 +03:00
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
// to draw border when selected in editor
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content());
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsHTMLButtonControlFrame::GetMinWidth(nsRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2007-01-30 08:52:27 +03:00
|
|
|
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
result = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
kid,
|
|
|
|
nsLayoutUtils::MIN_WIDTH);
|
|
|
|
|
|
|
|
result += mRenderer.GetAddedButtonBorderAndPadding().LeftRight();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsHTMLButtonControlFrame::GetPrefWidth(nsRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03: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;
|
|
|
|
}
|
1999-08-31 17:05:31 +04:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLButtonControlFrame::Reflow(nsPresContext* aPresContext,
|
1998-10-14 01:31:26 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLButtonControlFrame");
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2000-04-22 01:51:35 +04:00
|
|
|
|
2007-01-26 03:05:12 +03:00
|
|
|
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
"Should have real computed width by now");
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
|
1999-09-14 00:40:59 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 22:48:29 +03:00
|
|
|
// Reflow the child
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame* firstKid = mFrames.FirstChild();
|
1999-02-23 06:48:01 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXbz Eventually we may want to check-and-bail if
|
|
|
|
// !aReflowState.ShouldReflowAllKids() &&
|
2007-05-06 23:16:51 +04:00
|
|
|
// !NS_SUBTREE_DIRTY(firstKid).
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// We'd need to cache our ascent for that, of course.
|
2013-09-27 10:43:16 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Reflow the contents of the button.
|
2013-09-27 10:43:16 +04:00
|
|
|
// (This populates our aDesiredSize, too.)
|
|
|
|
ReflowButtonContents(aPresContext, aDesiredSize,
|
2013-09-27 10:43:16 +04:00
|
|
|
aReflowState, firstKid);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
2010-10-07 08:25:46 +04:00
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, firstKid);
|
2004-11-11 18:07:22 +03:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2013-09-27 10:43:16 +04:00
|
|
|
FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize,
|
|
|
|
aReflowState, aStatus);
|
2000-01-08 18:53:48 +03:00
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
1998-10-14 01:31:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-22 22:48:29 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
2013-09-27 10:43:16 +04:00
|
|
|
nsHTMLReflowMetrics& aButtonDesiredSize,
|
2013-09-27 10:43:15 +04:00
|
|
|
const nsHTMLReflowState& aButtonReflowState,
|
2013-09-27 10:43:16 +04:00
|
|
|
nsIFrame* aFirstKid)
|
2003-02-22 22:48:29 +03:00
|
|
|
{
|
2013-09-27 10:43:16 +04:00
|
|
|
// Buttons have some bonus renderer-determined border/padding,
|
|
|
|
// which occupies part of the button's content-box area:
|
|
|
|
const nsMargin focusPadding = mRenderer.GetAddedButtonBorderAndPadding();
|
|
|
|
|
2013-09-27 10:43:15 +04:00
|
|
|
nsSize availSize(aButtonReflowState.ComputedWidth(), NS_INTRINSICSIZE);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
// Indent the child inside us by the focus border. We must do this separate
|
|
|
|
// from the regular border.
|
2013-09-27 10:43:16 +04:00
|
|
|
availSize.width -= focusPadding.LeftRight();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
// 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.
|
2013-09-27 10:43:16 +04:00
|
|
|
nscoord xoffset = focusPadding.left +
|
2013-09-27 10:43:15 +04:00
|
|
|
aButtonReflowState.mComputedBorderPadding.left;
|
|
|
|
nscoord extrawidth = GetMinWidth(aButtonReflowState.rendContext) -
|
|
|
|
aButtonReflowState.ComputedWidth();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
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-09-27 10:43:15 +04:00
|
|
|
extraleft = std::min(extraleft, aButtonReflowState.mComputedPadding.left);
|
|
|
|
extraright = std::min(extraright, aButtonReflowState.mComputedPadding.right);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
xoffset -= extraleft;
|
|
|
|
availSize.width += extraleft + extraright;
|
|
|
|
}
|
2013-01-15 16:22:03 +04:00
|
|
|
availSize.width = std::max(availSize.width,0);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2013-09-27 10:43:15 +04:00
|
|
|
nsHTMLReflowState contentsReflowState(aPresContext, aButtonReflowState,
|
|
|
|
aFirstKid, availSize);
|
2003-02-22 22:48:29 +03:00
|
|
|
|
2013-09-27 10:43:16 +04:00
|
|
|
nsReflowStatus contentsReflowStatus;
|
2013-09-27 10:43:16 +04:00
|
|
|
nsHTMLReflowMetrics contentsDesiredSize;
|
|
|
|
ReflowChild(aFirstKid, aPresContext,
|
|
|
|
contentsDesiredSize, contentsReflowState,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
xoffset,
|
2013-09-27 10:43:16 +04:00
|
|
|
focusPadding.top + aButtonReflowState.mComputedBorderPadding.top,
|
2013-09-27 10:43:16 +04:00
|
|
|
0, contentsReflowStatus);
|
|
|
|
MOZ_ASSERT(NS_FRAME_IS_COMPLETE(contentsReflowStatus),
|
|
|
|
"We gave button-contents frame unconstrained available height, "
|
|
|
|
"so it should be complete");
|
2003-02-22 22:48:29 +03:00
|
|
|
|
2013-09-27 10:43:16 +04:00
|
|
|
// Compute the button's content-box height:
|
|
|
|
nscoord buttonContentBoxHeight = 0;
|
2013-09-27 10:43:15 +04:00
|
|
|
if (aButtonReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
|
2013-09-27 10:43:16 +04:00
|
|
|
// Button has a fixed height -- that's its content-box height.
|
|
|
|
buttonContentBoxHeight = aButtonReflowState.ComputedHeight();
|
2013-07-10 18:02:47 +04:00
|
|
|
} else {
|
2013-09-27 10:43:16 +04:00
|
|
|
// Button is intrinsically sized -- it should shrinkwrap the
|
|
|
|
// button-contents' height, plus any focus-padding space:
|
|
|
|
buttonContentBoxHeight =
|
2013-09-27 10:43:16 +04:00
|
|
|
contentsDesiredSize.height + focusPadding.TopBottom();
|
2013-07-10 18:02:47 +04: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
|
2013-09-27 10:43:15 +04:00
|
|
|
// aButtonReflowState.ComputedHeight()). Note that we do this before
|
|
|
|
// adjusting for borderpadding, since mComputedMaxHeight and
|
|
|
|
// mComputedMinHeight are content heights.
|
2013-09-27 10:43:16 +04:00
|
|
|
buttonContentBoxHeight =
|
|
|
|
NS_CSS_MINMAX(buttonContentBoxHeight,
|
|
|
|
aButtonReflowState.mComputedMinHeight,
|
|
|
|
aButtonReflowState.mComputedMaxHeight);
|
2013-07-10 18:02:47 +04:00
|
|
|
}
|
|
|
|
|
2013-09-27 10:43:16 +04:00
|
|
|
// Center child vertically in the button
|
|
|
|
// (technically, inside of the button's focus-padding area)
|
|
|
|
nscoord extraSpace =
|
2013-09-27 10:43:16 +04:00
|
|
|
buttonContentBoxHeight - focusPadding.TopBottom() -
|
2013-09-27 10:43:16 +04:00
|
|
|
contentsDesiredSize.height;
|
|
|
|
|
|
|
|
nscoord yoffset = std::max(0, extraSpace / 2);
|
|
|
|
|
|
|
|
// Adjust yoffset to be in terms of the button's frame-rect, instead of
|
|
|
|
// its focus-padding rect:
|
2013-09-27 10:43:16 +04:00
|
|
|
yoffset += focusPadding.top + aButtonReflowState.mComputedBorderPadding.top;
|
2003-02-22 22:48:29 +03:00
|
|
|
|
|
|
|
// Place the child
|
2013-09-27 10:43:16 +04:00
|
|
|
FinishReflowChild(aFirstKid, aPresContext,
|
|
|
|
&contentsReflowState, contentsDesiredSize,
|
|
|
|
xoffset, yoffset, 0);
|
|
|
|
|
|
|
|
// Make sure we have a useful 'ascent' value for the child
|
|
|
|
if (contentsDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
|
|
|
|
contentsDesiredSize.ascent = aFirstKid->GetBaseline();
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK, we're done with the child frame.
|
|
|
|
// Use what we learned to populate the button frame's reflow metrics.
|
|
|
|
// * Button's height & width are content-box size + border-box contribution:
|
|
|
|
aButtonDesiredSize.width = aButtonReflowState.ComputedWidth() +
|
|
|
|
aButtonReflowState.mComputedBorderPadding.LeftRight();
|
|
|
|
|
|
|
|
aButtonDesiredSize.height = buttonContentBoxHeight +
|
|
|
|
aButtonReflowState.mComputedBorderPadding.TopBottom();
|
|
|
|
|
|
|
|
// * Button's ascent is its child's ascent, plus the child's y-offset
|
|
|
|
// within our frame:
|
|
|
|
aButtonDesiredSize.ascent = contentsDesiredSize.ascent + yoffset;
|
|
|
|
|
|
|
|
aButtonDesiredSize.SetOverflowAreasToDesiredBounds();
|
2003-02-22 22:48:29 +03:00
|
|
|
}
|
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::value == aName) {
|
|
|
|
return mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
2011-10-17 18:59:28 +04:00
|
|
|
aValue, true);
|
2001-02-06 04:31:18 +03:00
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHTMLButtonControlFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
1999-09-04 03:36:32 +04:00
|
|
|
{
|
2003-02-22 03:32:13 +03:00
|
|
|
return mRenderer.GetStyleContext(aIndex);
|
1999-09-04 03:36:32 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHTMLButtonControlFrame::SetAdditionalStyleContext(int32_t aIndex,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext)
|
1999-09-04 03:36:32 +04:00
|
|
|
{
|
2003-02-22 03:32:13 +03:00
|
|
|
mRenderer.SetStyleContext(aIndex, aStyleContext);
|
1999-09-04 03:36:32 +04:00
|
|
|
}
|
|
|
|
|
2000-08-03 02:16:12 +04:00
|
|
|
NS_IMETHODIMP
|
2011-08-25 00:54:30 +04:00
|
|
|
nsHTMLButtonControlFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2000-08-03 02:16:12 +04:00
|
|
|
{
|
2006-01-13 10:58:12 +03:00
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-11-18 05:12:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-25 00:54:30 +04:00
|
|
|
nsHTMLButtonControlFrame::InsertFrames(ChildListID aListID,
|
2003-11-18 05:12:24 +03:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2003-11-18 05:12:24 +03:00
|
|
|
{
|
2006-01-13 10:58:12 +03:00
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-11-18 05:12:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-25 00:54:30 +04:00
|
|
|
nsHTMLButtonControlFrame::RemoveFrame(ChildListID aListID,
|
2003-11-18 05:12:24 +03:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2006-01-13 10:58:12 +03:00
|
|
|
NS_NOTREACHED("unsupported operation");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-11-18 05:12:24 +03:00
|
|
|
}
|