2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-02-14 01:42:09 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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/
|
2000-02-14 01:42:09 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
2000-02-14 01:42:09 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-02-14 01:42:09 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
// YY need to pass isMultiple before create called
|
|
|
|
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsBoxFrame.h"
|
2000-02-14 01:42:09 +00:00
|
|
|
#include "nsCSSRendering.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
class nsGroupBoxFrame : public nsBoxFrame {
|
2000-02-14 01:42:09 +00:00
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsGroupBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext) {}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHOD GetBorderAndPadding(nsMargin& aBorderAndPadding);
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-11-14 01:33:42 +00:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("GroupBoxFrame"), aResult);
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-05-28 05:01:42 +00:00
|
|
|
virtual PRBool HonorPrintBackgroundSettings() { return PR_FALSE; }
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void PaintBorderBackground(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsPoint aPt, const nsRect& aDirtyRect);
|
|
|
|
|
107642 - XUL syntax/cleanup landing. Fixes 94470, 96008, 96019, 76800, 102637, 80399, 108303, and removes over a thousand unnecessary or nonsensical attributes. Also fixes 108302, 102366, 102367, 105815. r=sspitzer,cmanske on appropriate parts sr=ben
2001-11-03 04:17:02 +00:00
|
|
|
// make sure we our kids get our orient and align instead of us.
|
2000-04-26 04:00:29 +00:00
|
|
|
// our child box has no content node so it will search for a parent with one.
|
|
|
|
// that will be us.
|
2001-03-06 02:27:50 +00:00
|
|
|
virtual void GetInitialOrientation(PRBool& aHorizontal) { aHorizontal = PR_FALSE; }
|
2000-04-26 04:00:29 +00:00
|
|
|
virtual PRBool GetInitialHAlignment(Halignment& aHalign) { aHalign = hAlign_Left; return PR_TRUE; }
|
|
|
|
virtual PRBool GetInitialVAlignment(Valignment& aValign) { aValign = vAlign_Top; return PR_TRUE; }
|
|
|
|
virtual PRBool GetInitialAutoStretch(PRBool& aStretch) { aStretch = PR_TRUE; return PR_TRUE; }
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsIBox* GetCaptionBox(nsPresContext* aPresContext, nsRect& aCaptionRect);
|
2000-02-14 01:42:09 +00:00
|
|
|
};
|
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
/*
|
2001-10-21 07:03:02 +00:00
|
|
|
class nsGroupBoxInnerFrame : public nsBoxFrame {
|
2000-02-14 01:42:09 +00:00
|
|
|
public:
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsGroupBoxInnerFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext) {}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
2001-10-21 07:03:02 +00:00
|
|
|
return MakeFrameName("GroupBoxFrameInner", aResult);
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// we are always flexible
|
|
|
|
virtual PRBool GetDefaultFlex(PRInt32& aFlex) { aFlex = 1; return PR_TRUE; }
|
|
|
|
|
|
|
|
};
|
2000-06-12 23:23:00 +00:00
|
|
|
*/
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewGroupBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsGroupBoxFrame(aPresShell, aContext);
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGroupBoxFrame)
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
class nsDisplayXULGroupBackground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayXULGroupBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsGroupBoxFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2006-01-29 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULGroupBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULGroupBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULGroupBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-08 00:31:26 +00:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2009-09-07 00:35:14 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2010-07-15 21:07:49 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("XULGroupBackground", TYPE_XUL_GROUP_BACKGROUND)
|
2006-01-26 02:29:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayXULGroupBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsGroupBoxFrame*>(mFrame)->
|
2010-08-13 10:01:58 +00:00
|
|
|
PaintBorderBackground(*aCtx, ToReferenceFrame(), mVisibleRect);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-01-26 02:29:17 +00:00
|
|
|
nsGroupBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
2006-01-26 02:29:17 +00:00
|
|
|
// Paint our background and border
|
|
|
|
if (IsVisibleForPainting(aBuilder)) {
|
|
|
|
nsresult rv = aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayXULGroupBackground(aBuilder, this));
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = DisplayOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
return BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
|
|
|
// REVIEW: Debug borders now painted by nsFrame::BuildDisplayListForChild
|
|
|
|
}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void
|
|
|
|
nsGroupBoxFrame::PaintBorderBackground(nsIRenderingContext& aRenderingContext,
|
|
|
|
nsPoint aPt, const nsRect& aDirtyRect) {
|
|
|
|
PRIntn skipSides = 0;
|
|
|
|
const nsStyleBorder* borderStyleData = GetStyleBorder();
|
2008-07-17 06:30:25 +00:00
|
|
|
const nsMargin& border = borderStyleData->GetActualBorder();
|
2006-01-26 02:29:17 +00:00
|
|
|
nscoord yoff = 0;
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2006-01-26 02:29:17 +00:00
|
|
|
|
|
|
|
nsRect groupRect;
|
|
|
|
nsIBox* groupBox = GetCaptionBox(presContext, groupRect);
|
|
|
|
|
|
|
|
if (groupBox) {
|
|
|
|
// if the border is smaller than the legend. Move the border down
|
|
|
|
// to be centered on the legend.
|
|
|
|
nsMargin groupMargin;
|
|
|
|
groupBox->GetStyleMargin()->GetMargin(groupMargin);
|
|
|
|
groupRect.Inflate(groupMargin);
|
|
|
|
|
|
|
|
if (border.top < groupRect.height)
|
|
|
|
yoff = (groupRect.height - border.top)/2 + groupRect.y;
|
|
|
|
}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRect rect(aPt.x, aPt.y + yoff, mRect.width, mRect.height - yoff);
|
2000-06-12 23:23:00 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
groupRect += aPt;
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsCSSRendering::PaintBackground(presContext, aRenderingContext, this,
|
2009-09-12 22:44:18 +00:00
|
|
|
aDirtyRect, rect,
|
|
|
|
nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
if (groupBox) {
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// we should probably use PaintBorderEdges to do this but for now just use clipping
|
|
|
|
// to achieve the same effect.
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// draw left side
|
|
|
|
nsRect clipRect(rect);
|
|
|
|
clipRect.width = groupRect.x - rect.x;
|
|
|
|
clipRect.height = border.top;
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-03 01:58:26 +00:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
aRenderingContext.PopState();
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// draw right side
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.x = groupRect.XMost();
|
|
|
|
clipRect.width = rect.XMost() - groupRect.XMost();
|
|
|
|
clipRect.height = border.top;
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-03 01:58:26 +00:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
aRenderingContext.PopState();
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
// draw bottom
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
clipRect = rect;
|
|
|
|
clipRect.y += border.top;
|
|
|
|
clipRect.height = mRect.height - (yoff + border.top);
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
2010-04-03 01:58:26 +00:00
|
|
|
aDirtyRect, rect, mStyleContext, skipSides);
|
2006-01-26 02:29:17 +00:00
|
|
|
|
|
|
|
aRenderingContext.PopState();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, nsRect(aPt, GetSize()),
|
2010-04-03 01:58:26 +00:00
|
|
|
mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
nsIBox*
|
2004-07-31 23:15:21 +00:00
|
|
|
nsGroupBoxFrame::GetCaptionBox(nsPresContext* aPresContext, nsRect& aCaptionRect)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
2001-10-21 09:30:22 +00:00
|
|
|
// first child is our grouped area
|
2007-02-22 18:05:14 +00:00
|
|
|
nsIBox* box = GetChildBox();
|
2000-06-12 23:23:00 +00:00
|
|
|
|
|
|
|
// no area fail.
|
|
|
|
if (!box)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
// get the first child in the grouped area, that is the caption
|
2007-02-22 18:05:14 +00:00
|
|
|
box = box->GetChildBox();
|
2000-06-12 23:23:00 +00:00
|
|
|
|
|
|
|
// nothing in the area? fail
|
2001-10-21 07:03:02 +00:00
|
|
|
if (!box)
|
2000-06-12 23:23:00 +00:00
|
|
|
return nsnull;
|
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
// now get the caption itself. It is in the caption frame.
|
2007-02-22 18:05:14 +00:00
|
|
|
nsIBox* child = box->GetChildBox();
|
2001-10-21 07:03:02 +00:00
|
|
|
|
|
|
|
if (child) {
|
|
|
|
// convert to our coordinates.
|
2004-09-28 18:37:50 +00:00
|
|
|
nsRect parentRect(box->GetRect());
|
|
|
|
aCaptionRect = child->GetRect();
|
2001-10-21 09:30:22 +00:00
|
|
|
aCaptionRect.x += parentRect.x;
|
|
|
|
aCaptionRect.y += parentRect.y;
|
2001-10-21 07:03:02 +00:00
|
|
|
}
|
|
|
|
|
2000-02-14 01:42:09 +00:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
aBorderAndPadding.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
2000-02-15 00:56:15 +00:00
|
|
|
}
|
|
|
|
|