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 ***** */
|
|
|
|
|
|
|
|
// YY need to pass isMultiple before create called
|
|
|
|
|
|
|
|
//#include "nsFormControlFrame.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsLegendFrame.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMHTMLFieldSetElement.h"
|
|
|
|
#include "nsIDOMHTMLLegendElement.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
//#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsFont.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
class nsLegendFrame;
|
|
|
|
|
|
|
|
class nsFieldSetFrame : public nsHTMLContainerFrame {
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsFieldSetFrame(nsStyleContext* aContext);
|
|
|
|
|
|
|
|
NS_IMETHOD SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_HIDDEN_(nscoord)
|
2008-03-14 13:48:23 -07:00
|
|
|
GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsLayoutUtils::IntrinsicWidthType);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nscoord GetMinWidth(nsIRenderingContext* aRenderingContext);
|
|
|
|
virtual nscoord GetPrefWidth(nsIRenderingContext* aRenderingContext);
|
|
|
|
virtual nsSize ComputeSize(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
|
|
|
PRBool aShrinkWrap);
|
2009-08-03 07:42:59 -07:00
|
|
|
virtual nscoord GetBaseline() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
|
|
|
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists);
|
|
|
|
|
|
|
|
void PaintBorderBackground(nsIRenderingContext& aRenderingContext,
|
2009-09-12 15:44:18 -07:00
|
|
|
nsPoint aPt, const nsRect& aDirtyRect, PRUint32 aBGFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame);
|
|
|
|
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
virtual PRBool IsContainingBlock() const;
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 05:02:03 -07:00
|
|
|
virtual already_AddRefed<nsAccessible> CreateAccessible();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual PRIntn GetSkipSides() const;
|
2010-04-01 23:07:43 -07:00
|
|
|
void ReparentFrameList(const nsFrameList& aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame* mLegendFrame;
|
|
|
|
nsIFrame* mContentFrame;
|
|
|
|
nsRect mLegendRect;
|
|
|
|
nscoord mLegendSpace;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewFieldSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsFieldSetFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsFieldSetFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFieldSetFrame::nsFieldSetFrame(nsStyleContext* aContext)
|
|
|
|
: nsHTMLContainerFrame(aContext)
|
|
|
|
{
|
|
|
|
mContentFrame = nsnull;
|
|
|
|
mLegendFrame = nsnull;
|
|
|
|
mLegendSpace = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsFieldSetFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::fieldSetFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFieldSetFrame::IsContainingBlock() const
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::SetInitialChildList(nsIAtom* aListName,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get the content and legend frames.
|
2009-07-28 05:53:20 -07:00
|
|
|
if (!aChildList.OnlyChild()) {
|
|
|
|
NS_ASSERTION(aChildList.GetLength() == 2, "Unexpected child list");
|
|
|
|
mContentFrame = aChildList.LastChild();
|
|
|
|
mLegendFrame = aChildList.FirstChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-07-28 05:53:20 -07:00
|
|
|
mContentFrame = aChildList.FirstChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
mLegendFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Queue up the frames for the content frame
|
|
|
|
return nsHTMLContainerFrame::SetInitialChildList(nsnull, aChildList);
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayFieldSetBorderBackground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayFieldSetBorderBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsFieldSetFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayFieldSetBorderBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayFieldSetBorderBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayFieldSetBorderBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames);
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("FieldSetBorderBackground", TYPE_FIELDSET_BORDER_BACKGROUND)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void nsDisplayFieldSetBorderBackground::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// aPt is guaranteed to be in this item's bounds. We do the hit test based on the
|
|
|
|
// frame bounds even though our background doesn't cover the whole frame.
|
|
|
|
// It's not clear whether this is correct.
|
2010-04-07 17:31:26 -07:00
|
|
|
aOutFrames->AppendElement(mFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayFieldSetBorderBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-06 17:35:14 -07:00
|
|
|
nsIRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsFieldSetFrame*>(mFrame)->
|
2010-08-13 03:01:58 -07:00
|
|
|
PaintBorderBackground(*aCtx, ToReferenceFrame(),
|
2009-09-06 17:35:14 -07:00
|
|
|
mVisibleRect, aBuilder->GetBackgroundPaintFlags());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
// Paint our background and border in a special way.
|
|
|
|
// REVIEW: We don't really need to check frame emptiness here; if it's empty,
|
|
|
|
// the background/border display item won't do anything, and if it isn't empty,
|
|
|
|
// we need to paint the outline
|
|
|
|
if (IsVisibleForPainting(aBuilder)) {
|
2009-02-10 00:45:13 -08:00
|
|
|
if (GetStyleBorder()->mBoxShadow) {
|
|
|
|
nsresult rv = aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayBoxShadowOuter(aBuilder, this));
|
2009-02-10 00:45:13 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2009-02-05 00:22:02 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// don't bother checking to see if we really have a border or background.
|
|
|
|
// we usually will have a border.
|
2009-02-10 00:45:13 -08:00
|
|
|
nsresult rv = aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayFieldSetBorderBackground(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = DisplayOutlineUnconditional(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayListCollection contentDisplayItems;
|
|
|
|
if (mContentFrame) {
|
|
|
|
// Collect mContentFrame's display items into their own collection. We need
|
|
|
|
// to be calling BuildDisplayList on mContentFrame before mLegendFrame in
|
|
|
|
// case it contains out-of-flow frames whose placeholders are under
|
|
|
|
// mLegendFrame. However, we want mContentFrame's display items to be
|
|
|
|
// after mLegendFrame's display items in z-order, so we need to save them
|
|
|
|
// and append them later.
|
|
|
|
nsresult rv = BuildDisplayListForChild(aBuilder, mContentFrame, aDirtyRect,
|
|
|
|
contentDisplayItems);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
if (mLegendFrame) {
|
2007-12-01 00:32:51 -08:00
|
|
|
// The legend's background goes on our BlockBorderBackgrounds list because
|
|
|
|
// it's a block child.
|
|
|
|
nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = BuildDisplayListForChild(aBuilder, mLegendFrame, aDirtyRect, set);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// Put mContentFrame's display items on the master list. Note that
|
|
|
|
// this moves mContentFrame's border/background display items to our
|
|
|
|
// BorderBackground() list, which isn't really correct, but it's OK because
|
|
|
|
// mContentFrame is anonymous and can't have its own border and background.
|
|
|
|
contentDisplayItems.MoveTo(aLists);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFieldSetFrame::PaintBorderBackground(nsIRenderingContext& aRenderingContext,
|
2009-09-12 15:44:18 -07:00
|
|
|
nsPoint aPt, const nsRect& aDirtyRect, PRUint32 aBGFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRIntn skipSides = GetSkipSides();
|
|
|
|
const nsStyleBorder* borderStyle = GetStyleBorder();
|
|
|
|
|
2008-07-16 23:30:25 -07:00
|
|
|
nscoord topBorder = borderStyle->GetActualBorderWidth(NS_SIDE_TOP);
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord yoff = 0;
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if the border is smaller than the legend. Move the border down
|
|
|
|
// to be centered on the legend.
|
2010-09-07 15:20:35 -07:00
|
|
|
// FIXME: This means border-radius clamping is incorrect; we should
|
|
|
|
// override nsIFrame::GetBorderRadii.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (topBorder < mLegendRect.height)
|
|
|
|
yoff = (mLegendRect.height - topBorder)/2;
|
|
|
|
|
|
|
|
nsRect rect(aPt.x, aPt.y + yoff, mRect.width, mRect.height - yoff);
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBackground(presContext, aRenderingContext, this,
|
2009-09-12 15:44:18 -07:00
|
|
|
aDirtyRect, rect, aBGFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-10 00:45:13 -08:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, aRenderingContext,
|
|
|
|
this, rect, aDirtyRect);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mLegendFrame) {
|
|
|
|
|
|
|
|
// Use the rect of the legend frame, not mLegendRect, so we draw our
|
|
|
|
// border under the legend's left and right margins.
|
|
|
|
nsRect legendRect = mLegendFrame->GetRect() + aPt;
|
|
|
|
|
|
|
|
// we should probably use PaintBorderEdges to do this but for now just use clipping
|
|
|
|
// to achieve the same effect.
|
|
|
|
|
|
|
|
// draw left side
|
|
|
|
nsRect clipRect(rect);
|
|
|
|
clipRect.width = legendRect.x - rect.x;
|
|
|
|
clipRect.height = topBorder;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-02 18:58:26 -07:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
|
|
|
|
|
|
|
|
// draw right side
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.x = legendRect.XMost();
|
|
|
|
clipRect.width = rect.XMost() - legendRect.XMost();
|
|
|
|
clipRect.height = topBorder;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-02 18:58:26 -07:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
|
|
|
|
|
|
|
|
// draw bottom
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.y += topBorder;
|
|
|
|
clipRect.height = mRect.height - (yoff + topBorder);
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-02 18:58:26 -07:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
|
|
|
aDirtyRect,
|
|
|
|
nsRect(aPt, mRect.Size()),
|
2010-04-02 18:58:26 -07:00
|
|
|
mStyleContext, skipSides);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2008-03-14 13:48:23 -07:00
|
|
|
nsFieldSetFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsLayoutUtils::IntrinsicWidthType aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-14 13:48:23 -07:00
|
|
|
nscoord legendWidth = 0;
|
|
|
|
nscoord contentWidth = 0;
|
|
|
|
if (mLegendFrame) {
|
|
|
|
legendWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mLegendFrame,
|
|
|
|
aType);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-14 13:48:23 -07:00
|
|
|
if (mContentFrame) {
|
|
|
|
contentWidth =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mContentFrame,
|
|
|
|
aType);
|
|
|
|
}
|
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
return NS_MAX(legendWidth, contentWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFieldSetFrame::GetMinWidth(nsIRenderingContext* aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
2008-03-14 13:48:23 -07:00
|
|
|
result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH);
|
2007-03-22 10:30:00 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFieldSetFrame::GetPrefWidth(nsIRenderingContext* aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
|
2008-03-14 13:48:23 -07:00
|
|
|
result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH);
|
2007-03-22 10:30:00 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsFieldSetFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
|
|
|
PRBool aShrinkWrap)
|
|
|
|
{
|
|
|
|
nsSize result =
|
|
|
|
nsHTMLContainerFrame::ComputeSize(aRenderingContext, aCBSize,
|
|
|
|
aAvailableWidth,
|
|
|
|
aMargin, aBorder, aPadding, aShrinkWrap);
|
|
|
|
|
|
|
|
// Fieldsets never shrink below their min width.
|
|
|
|
nscoord minWidth = GetMinWidth(aRenderingContext);
|
|
|
|
if (minWidth > result.width)
|
|
|
|
result.width = minWidth;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
|
|
|
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE,
|
|
|
|
"Should have a precomputed width!");
|
|
|
|
|
|
|
|
// Initialize OUT parameter
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
//------------ Handle Incremental Reflow -----------------
|
|
|
|
PRBool reflowContent;
|
|
|
|
PRBool reflowLegend;
|
|
|
|
|
|
|
|
if (aReflowState.ShouldReflowAllKids()) {
|
|
|
|
reflowContent = mContentFrame != nsnull;
|
|
|
|
reflowLegend = mLegendFrame != nsnull;
|
|
|
|
} else {
|
2007-05-06 12:16:51 -07:00
|
|
|
reflowContent = mContentFrame && NS_SUBTREE_DIRTY(mContentFrame);
|
|
|
|
reflowLegend = mLegendFrame && NS_SUBTREE_DIRTY(mLegendFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-07 18:55:22 -07:00
|
|
|
// We don't allow fieldsets to break vertically. If we did, we'd
|
|
|
|
// need logic here to push and pull overflow frames.
|
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(!mContentFrame ||
|
2008-03-14 13:48:23 -07:00
|
|
|
nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
|
|
|
|
mContentFrame,
|
|
|
|
nsLayoutUtils::MIN_WIDTH) <=
|
|
|
|
availSize.width,
|
|
|
|
"Bogus availSize.width; should be bigger");
|
|
|
|
NS_ASSERTION(!mLegendFrame ||
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
|
|
|
|
mLegendFrame,
|
|
|
|
nsLayoutUtils::MIN_WIDTH) <=
|
|
|
|
availSize.width,
|
2007-03-22 10:30:00 -07:00
|
|
|
"Bogus availSize.width; should be bigger");
|
|
|
|
|
|
|
|
// get our border and padding
|
|
|
|
const nsMargin &borderPadding = aReflowState.mComputedBorderPadding;
|
2008-07-09 08:42:44 -07:00
|
|
|
nsMargin border = borderPadding - aReflowState.mComputedPadding;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Figure out how big the legend is if there is one.
|
|
|
|
// get the legend's margin
|
|
|
|
nsMargin legendMargin(0,0,0,0);
|
|
|
|
// reflow the legend only if needed
|
|
|
|
if (reflowLegend) {
|
|
|
|
nsHTMLReflowState legendReflowState(aPresContext, aReflowState,
|
2008-03-14 13:48:23 -07:00
|
|
|
mLegendFrame, availSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHTMLReflowMetrics legendDesiredSize;
|
|
|
|
|
|
|
|
ReflowChild(mLegendFrame, aPresContext, legendDesiredSize, legendReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
printf(" returned (%d, %d)\n", legendDesiredSize.width, legendDesiredSize.height);
|
|
|
|
#endif
|
|
|
|
// figure out the legend's rectangle
|
2008-07-09 08:42:44 -07:00
|
|
|
legendMargin = mLegendFrame->GetUsedMargin();
|
2007-03-22 10:30:00 -07:00
|
|
|
mLegendRect.width = legendDesiredSize.width + legendMargin.left + legendMargin.right;
|
|
|
|
mLegendRect.height = legendDesiredSize.height + legendMargin.top + legendMargin.bottom;
|
|
|
|
mLegendRect.x = borderPadding.left;
|
|
|
|
mLegendRect.y = 0;
|
|
|
|
|
|
|
|
nscoord oldSpace = mLegendSpace;
|
|
|
|
mLegendSpace = 0;
|
|
|
|
if (mLegendRect.height > border.top) {
|
|
|
|
// center the border on the legend
|
|
|
|
mLegendSpace = mLegendRect.height - border.top;
|
|
|
|
} else {
|
|
|
|
mLegendRect.y = (border.top - mLegendRect.height)/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the legend space changes then we need to reflow the
|
|
|
|
// content area as well.
|
|
|
|
if (mLegendSpace != oldSpace && mContentFrame) {
|
|
|
|
reflowContent = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishReflowChild(mLegendFrame, aPresContext, &legendReflowState,
|
|
|
|
legendDesiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME);
|
|
|
|
} else if (!mLegendFrame) {
|
|
|
|
mLegendRect.Empty();
|
|
|
|
mLegendSpace = 0;
|
2008-07-09 08:42:44 -07:00
|
|
|
} else {
|
|
|
|
// mLegendSpace and mLegendRect haven't changed, but we need
|
|
|
|
// the used margin when placing the legend.
|
|
|
|
legendMargin = mLegendFrame->GetUsedMargin();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// reflow the content frame only if needed
|
|
|
|
if (reflowContent) {
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, mContentFrame,
|
|
|
|
availSize);
|
2007-11-07 20:04:32 -08:00
|
|
|
// Our child is "height:100%" but we actually want its height to be reduced
|
|
|
|
// by the amount of content-height the legend is eating up, unless our
|
|
|
|
// height is unconstrained (in which case the child's will be too).
|
|
|
|
if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) {
|
2009-09-16 08:01:36 -07:00
|
|
|
kidReflowState.SetComputedHeight(NS_MAX(0, aReflowState.ComputedHeight() - mLegendSpace));
|
2007-11-07 20:04:32 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-07 22:18:00 -07:00
|
|
|
kidReflowState.mComputedMinHeight =
|
2009-09-16 08:01:36 -07:00
|
|
|
NS_MAX(0, aReflowState.mComputedMinHeight - mLegendSpace);
|
2008-08-07 22:18:00 -07:00
|
|
|
|
|
|
|
if (aReflowState.mComputedMaxHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
kidReflowState.mComputedMaxHeight =
|
2009-09-16 08:01:36 -07:00
|
|
|
NS_MAX(0, aReflowState.mComputedMaxHeight - mLegendSpace);
|
2008-08-07 22:18:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mFlags);
|
|
|
|
// Reflow the frame
|
2007-11-07 20:04:32 -08:00
|
|
|
NS_ASSERTION(kidReflowState.mComputedMargin == nsMargin(0,0,0,0),
|
|
|
|
"Margins on anonymous fieldset child not supported!");
|
|
|
|
nsPoint pt(borderPadding.left, borderPadding.top + mLegendSpace);
|
2007-03-22 10:30:00 -07:00
|
|
|
ReflowChild(mContentFrame, aPresContext, kidDesiredSize, kidReflowState,
|
2007-11-07 20:04:32 -08:00
|
|
|
pt.x, pt.y, 0, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
FinishReflowChild(mContentFrame, aPresContext, &kidReflowState,
|
2007-11-07 20:04:32 -08:00
|
|
|
kidDesiredSize, pt.x, pt.y, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus);
|
2007-11-07 20:04:32 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-11-07 20:04:32 -08:00
|
|
|
nsRect contentRect(0,0,0,0);
|
|
|
|
if (mContentFrame) {
|
2008-07-09 08:42:44 -07:00
|
|
|
// We don't support margins on mContentFrame, so our "content rect" is just
|
2007-11-07 20:04:32 -08:00
|
|
|
// its rect.
|
2007-03-22 10:30:00 -07:00
|
|
|
contentRect = mContentFrame->GetRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// use the computed width if the inner content does not fill it
|
|
|
|
if (aReflowState.ComputedWidth() > contentRect.width) {
|
|
|
|
contentRect.width = aReflowState.ComputedWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLegendFrame) {
|
|
|
|
// if the content rect is larger then the legend we can align the legend
|
|
|
|
if (contentRect.width > mLegendRect.width) {
|
2008-07-09 08:42:44 -07:00
|
|
|
PRInt32 align = static_cast<nsLegendFrame*>(mLegendFrame)->GetAlign();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch(align) {
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
|
|
|
mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ALIGN_CENTER:
|
|
|
|
// Note: rounding removed; there doesn't seem to be any need
|
|
|
|
mLegendRect.x = contentRect.width / 2 - mLegendRect.width / 2 + borderPadding.left;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2008-07-09 08:42:44 -07:00
|
|
|
// otherwise make place for the legend
|
2007-03-22 10:30:00 -07:00
|
|
|
contentRect.width = mLegendRect.width;
|
|
|
|
}
|
|
|
|
// place the legend
|
|
|
|
nsRect actualLegendRect(mLegendRect);
|
|
|
|
actualLegendRect.Deflate(legendMargin);
|
|
|
|
|
|
|
|
nsPoint curOrigin = mLegendFrame->GetPosition();
|
|
|
|
|
|
|
|
// only if the origin changed
|
|
|
|
if ((curOrigin.x != mLegendRect.x) || (curOrigin.y != mLegendRect.y)) {
|
|
|
|
mLegendFrame->SetPosition(nsPoint(actualLegendRect.x , actualLegendRect.y));
|
|
|
|
nsContainerFrame::PositionFrameView(mLegendFrame);
|
|
|
|
|
|
|
|
// We need to recursively process the legend frame's
|
|
|
|
// children since we're moving the frame after Reflow.
|
|
|
|
nsContainerFrame::PositionChildViews(mLegendFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return our size and our result
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredSize.height = mLegendSpace +
|
2007-08-02 11:08:05 -07:00
|
|
|
borderPadding.TopBottom() +
|
|
|
|
contentRect.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2007-08-02 11:08:05 -07:00
|
|
|
nscoord min = borderPadding.TopBottom() + mLegendRect.height;
|
|
|
|
aDesiredSize.height =
|
|
|
|
aReflowState.ComputedHeight() + borderPadding.TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDesiredSize.height < min)
|
|
|
|
aDesiredSize.height = min;
|
|
|
|
}
|
2007-08-02 11:08:05 -07:00
|
|
|
aDesiredSize.width = contentRect.width + borderPadding.LeftRight();
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mLegendFrame)
|
2010-10-06 21:25:46 -07:00
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, mLegendFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContentFrame)
|
2010-10-06 21:25:46 -07:00
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, mContentFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
Invalidate(aDesiredSize.VisualOverflow());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsFieldSetFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-30 10:23:32 -07:00
|
|
|
// aFrameList is not allowed to contain "the legend" for this fieldset
|
2010-04-01 23:07:43 -07:00
|
|
|
ReparentFrameList(aFrameList);
|
2009-07-30 10:23:32 -07:00
|
|
|
return mContentFrame->AppendFrames(aListName, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this ||
|
|
|
|
aPrevFrame->GetParent() == mContentFrame,
|
|
|
|
"inserting after sibling frame with different parent");
|
|
|
|
|
2009-07-30 10:23:32 -07:00
|
|
|
// aFrameList is not allowed to contain "the legend" for this fieldset
|
2010-04-01 23:07:43 -07:00
|
|
|
ReparentFrameList(aFrameList);
|
2009-07-30 10:23:32 -07:00
|
|
|
if (NS_UNLIKELY(aPrevFrame == mLegendFrame)) {
|
|
|
|
aPrevFrame = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-07-30 10:23:32 -07:00
|
|
|
return mContentFrame->InsertFrames(aListName, aPrevFrame, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFieldSetFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
// For reference, see bug 70648, bug 276104 and bug 236071.
|
2009-06-11 19:01:05 -07:00
|
|
|
NS_ASSERTION(aOldFrame != mLegendFrame, "Cannot remove mLegendFrame here");
|
2007-03-22 10:30:00 -07:00
|
|
|
return mContentFrame->RemoveFrame(aListName, aOldFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 05:02:03 -07:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsFieldSetFrame::CreateAccessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2010-06-28 05:02:03 -07:00
|
|
|
return accService->CreateHTMLGroupboxAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 05:02:03 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2010-04-01 23:07:43 -07:00
|
|
|
nsFieldSetFrame::ReparentFrameList(const nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-03-30 14:11:41 -07:00
|
|
|
nsFrameManager* frameManager = PresContext()->FrameManager();
|
2009-07-30 10:23:32 -07:00
|
|
|
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
|
|
|
|
NS_ASSERTION(mLegendFrame || e.get()->GetType() != nsGkAtoms::legendFrame,
|
2009-06-11 19:01:05 -07:00
|
|
|
"The fieldset's legend is not allowed in this list");
|
2009-07-30 10:23:32 -07:00
|
|
|
e.get()->SetParent(mContentFrame);
|
2010-04-01 23:07:43 -07:00
|
|
|
frameManager->ReparentStyleContext(e.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-08-03 07:42:59 -07:00
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFieldSetFrame::GetBaseline() const
|
|
|
|
{
|
|
|
|
// We know mContentFrame is a block, so calling GetBaseline() on it will do
|
|
|
|
// the right thing (that being to return the baseline of the last line).
|
|
|
|
NS_ASSERTION(nsLayoutUtils::GetAsBlock(mContentFrame),
|
|
|
|
"Unexpected mContentFrame");
|
|
|
|
return mContentFrame->GetPosition().y + mContentFrame->GetBaseline();
|
|
|
|
}
|