2000-02-14 01:42:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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 Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
// YY need to pass isMultiple before create called
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
|
|
|
|
class nsTitledBoxFrame : public nsBoxFrame {
|
|
|
|
public:
|
|
|
|
|
2000-03-02 03:01:30 +00:00
|
|
|
nsTitledBoxFrame(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
|
|
|
|
|
|
|
NS_METHOD Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer);
|
|
|
|
|
|
|
|
#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
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
nsIBox* GetTitleBox(nsIPresContext* aPresContext, nsRect& aRect);
|
2000-02-14 01:42:09 +00:00
|
|
|
};
|
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
/*
|
2000-02-14 01:42:09 +00:00
|
|
|
class nsTitledBoxInnerFrame : public nsBoxFrame {
|
|
|
|
public:
|
|
|
|
|
2000-03-02 03:01:30 +00:00
|
|
|
nsTitledBoxInnerFrame(nsIPresShell* aShell):nsBoxFrame(aShell) {}
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
|
|
|
return MakeFrameName("TitledBoxFrameInner", aResult);
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
NS_NewTitledBoxFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-03-02 03:01:30 +00:00
|
|
|
nsTitledBoxFrame* it = new (aPresShell) nsTitledBoxFrame(aPresShell);
|
2000-02-14 01:42:09 +00:00
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-02 03:01:30 +00:00
|
|
|
nsTitledBoxFrame::nsTitledBoxFrame(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
|
|
|
|
nsTitledBoxFrame::Paint(nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
|
|
|
// Paint our background and border
|
|
|
|
const nsStyleDisplay* disp =
|
|
|
|
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
2000-03-17 10:15:13 +00:00
|
|
|
if (disp->IsVisible() && mRect.width && mRect.height) {
|
2000-02-14 01:42:09 +00:00
|
|
|
PRIntn skipSides = GetSkipSides();
|
|
|
|
const nsStyleColor* color =
|
|
|
|
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
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;
|
|
|
|
|
|
|
|
nsRect titleRect;
|
2000-06-12 23:23:00 +00:00
|
|
|
nsIBox* titleBox = GetTitleBox(aPresContext, titleRect);
|
|
|
|
|
|
|
|
if (titleBox) {
|
|
|
|
nsIFrame* titleFrame;
|
|
|
|
titleBox->GetFrame(&titleFrame);
|
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-02-07 09:57:26 +00:00
|
|
|
const nsStyleMargin* titleMarginData;
|
|
|
|
titleFrame->GetStyleData(eStyleStruct_Margin,
|
|
|
|
(const nsStyleStruct*&) titleMarginData);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
nsMargin titleMargin;
|
2001-02-07 09:57:26 +00:00
|
|
|
titleMarginData->GetMargin(titleMargin);
|
2000-02-14 01:42:09 +00:00
|
|
|
titleRect.Inflate(titleMargin);
|
|
|
|
|
|
|
|
if (border.top < titleRect.height)
|
|
|
|
yoff = (titleRect.height - border.top)/2 + titleRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2000-06-12 23:23:00 +00:00
|
|
|
if (titleBox) {
|
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);
|
|
|
|
clipRect.width = titleRect.x - rect.x;
|
|
|
|
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;
|
|
|
|
clipRect.x = titleRect.x + titleRect.width;
|
|
|
|
clipRect.width -= (titleRect.x + titleRect.width);
|
|
|
|
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*
|
|
|
|
nsTitledBoxFrame::GetTitleBox(nsIPresContext* aPresContext, nsRect& aTitleRect)
|
2000-02-14 01:42:09 +00:00
|
|
|
{
|
2000-06-12 23:23:00 +00:00
|
|
|
// first child is out titled area
|
|
|
|
nsIBox* box;
|
|
|
|
GetChildBox(&box);
|
|
|
|
|
|
|
|
// no area fail.
|
|
|
|
if (!box)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// get the first child in the titled area that is the title
|
|
|
|
box->GetChildBox(&box);
|
|
|
|
|
|
|
|
// nothing in the area? fail
|
|
|
|
if (!box)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// now get the title itself. It is in the title frame.
|
|
|
|
nsIBox* child = nsnull;
|
|
|
|
box->GetChildBox(&child);
|
2000-02-14 01:42:09 +00:00
|
|
|
|
|
|
|
if (child) {
|
|
|
|
// convert to our coordinates.
|
|
|
|
nsRect parentRect;
|
2000-06-12 23:23:00 +00:00
|
|
|
box->GetBounds(parentRect);
|
|
|
|
child->GetBounds(aTitleRect);
|
2000-02-14 01:42:09 +00:00
|
|
|
aTitleRect.x += parentRect.x;
|
|
|
|
aTitleRect.y += parentRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTitledBoxFrame::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
|
|
|
}
|
|
|
|
|