2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
2000-02-14 01:42:09 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
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
|
|
|
|
* either 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
// YY need to pass isMultiple before create called
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
class nsGroupBoxFrame : public nsBoxFrame {
|
2000-02-14 01:42:09 +00:00
|
|
|
public:
|
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxFrame(nsIPresShell* aShell);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHOD GetBorderAndPadding(nsMargin& aBorderAndPadding);
|
|
|
|
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
NS_METHOD Paint(nsIPresContext* aPresContext,
|
2000-02-14 01:42:09 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-10-21 07:03:02 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
|
|
|
return MakeFrameName("GroupBoxFrame", aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-26 04:00:29 +00:00
|
|
|
// make sure we our kids get our orient, align, and autostretch instead of us.
|
|
|
|
// 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
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
nsIBox* GetCaptionBox(nsIPresContext* 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:
|
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxInnerFrame(nsIPresShell* aShell):nsBoxFrame(aShell) {}
|
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
|
|
|
|
|
|
|
nsresult
|
2001-10-21 07:03:02 +00:00
|
|
|
NS_NewGroupBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxFrame* it = new (aPresShell) nsGroupBoxFrame(aPresShell);
|
2000-02-14 01:42:09 +00:00
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxFrame::nsGroupBoxFrame(nsIPresShell* aShell):nsBoxFrame(aShell)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this is identical to nsHTMLContainerFrame::Paint except for the background and border.
|
|
|
|
NS_IMETHODIMP
|
2001-10-21 07:03:02 +00:00
|
|
|
nsGroupBoxFrame::Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
|
|
|
// Paint our background and border
|
2001-05-31 22:19:43 +00:00
|
|
|
const nsStyleVisibility* vis =
|
|
|
|
(const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
if (vis->IsVisible() && mRect.width && mRect.height) {
|
2000-02-14 01:42:09 +00:00
|
|
|
PRIntn skipSides = GetSkipSides();
|
2001-05-31 22:19:43 +00:00
|
|
|
const nsStyleBackground* color =
|
|
|
|
(const nsStyleBackground*)mStyleContext->GetStyleData(eStyleStruct_Background);
|
2001-02-07 09:57:26 +00:00
|
|
|
const nsStyleBorder* borderStyleData =
|
|
|
|
(const nsStyleBorder*)mStyleContext->GetStyleData(eStyleStruct_Border);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
nsMargin border;
|
2001-02-07 09:57:26 +00:00
|
|
|
if (!borderStyleData->GetBorder(border)) {
|
2000-02-14 01:42:09 +00:00
|
|
|
NS_NOTYETIMPLEMENTED("percentage border");
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord yoff = 0;
|
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
nsRect groupRect;
|
|
|
|
nsIBox* groupBox = GetCaptionBox(aPresContext, groupRect);
|
2000-06-12 23:23:00 +00:00
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
if (groupBox) {
|
|
|
|
nsIFrame* groupFrame;
|
|
|
|
groupBox->GetFrame(&groupFrame);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
// if the border is smaller than the legend. Move the border down
|
|
|
|
// to be centered on the legend.
|
2001-10-21 09:30:22 +00:00
|
|
|
const nsStyleMargin* groupMarginData;
|
|
|
|
groupFrame->GetStyleData(eStyleStruct_Margin,
|
|
|
|
(const nsStyleStruct*&) groupMarginData);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
nsMargin groupMargin;
|
|
|
|
groupMarginData->GetMargin(groupMargin);
|
|
|
|
groupRect.Inflate(groupMargin);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
if (border.top < groupRect.height)
|
|
|
|
yoff = (groupRect.height - border.top)/2 + groupRect.y;
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(0, yoff, mRect.width, mRect.height - yoff);
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *color, *borderStyleData, 0, 0);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
|
2001-10-21 09:30:22 +00:00
|
|
|
if (groupBox) {
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
// we should probably use PaintBorderEdges to do this but for now just use clipping
|
|
|
|
// to achieve the same effect.
|
|
|
|
PRBool clipState;
|
|
|
|
|
|
|
|
// draw left side
|
|
|
|
nsRect clipRect(rect);
|
2001-10-21 09:30:22 +00:00
|
|
|
clipRect.width = groupRect.x - rect.x;
|
2000-02-14 01:42:09 +00:00
|
|
|
clipRect.height = border.top;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
|
|
|
|
|
|
|
|
// draw right side
|
|
|
|
clipRect = rect;
|
2001-10-21 09:30:22 +00:00
|
|
|
clipRect.x = groupRect.x + groupRect.width;
|
|
|
|
clipRect.width -= (groupRect.x + groupRect.width);
|
2000-02-14 01:42:09 +00:00
|
|
|
clipRect.height = border.top;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// draw bottom
|
|
|
|
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.y += border.top;
|
|
|
|
clipRect.height = mRect.height - (yoff + border.top);
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
2001-02-07 09:57:26 +00:00
|
|
|
aDirtyRect, nsRect(0,0,mRect.width, mRect.height), *borderStyleData, mStyleContext, skipSides);
|
2000-02-14 01:42:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
|
|
|
nsIView* view;
|
|
|
|
GetView(aPresContext, &view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
}
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
nsIBox*
|
2001-10-21 09:30:22 +00:00
|
|
|
nsGroupBoxFrame::GetCaptionBox(nsIPresContext* 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
|
2000-06-12 23:23:00 +00:00
|
|
|
nsIBox* box;
|
|
|
|
GetChildBox(&box);
|
|
|
|
|
|
|
|
// 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
|
2001-10-21 07:03:02 +00:00
|
|
|
box->GetChildBox(&box);
|
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.
|
2001-10-21 07:03:02 +00:00
|
|
|
nsIBox* child = nsnull;
|
|
|
|
box->GetChildBox(&child);
|
|
|
|
|
|
|
|
if (child) {
|
|
|
|
// convert to our coordinates.
|
|
|
|
nsRect parentRect;
|
|
|
|
box->GetBounds(parentRect);
|
2001-10-21 09:30:22 +00:00
|
|
|
child->GetBounds(aCaptionRect);
|
|
|
|
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
|
|
|
}
|
|
|
|
|