2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// YY need to pass isMultiple before create called
|
|
|
|
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
class nsGroupBoxFrame : public nsBoxFrame {
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsGroupBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext) {}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetBorderAndPadding(nsMargin& aBorderAndPadding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const {
|
2007-03-22 10:30:00 -07:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("GroupBoxFrame"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool HonorPrintBackgroundSettings() { return false; }
|
2009-05-27 22:01:42 -07:00
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
void PaintBorderBackground(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint aPt, const nsRect& aDirtyRect);
|
|
|
|
|
|
|
|
// make sure we our kids get our orient and align instead of us.
|
|
|
|
// our child box has no content node so it will search for a parent with one.
|
|
|
|
// that will be us.
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual void GetInitialOrientation(bool& aHorizontal) { aHorizontal = false; }
|
|
|
|
virtual bool GetInitialHAlignment(Halignment& aHalign) { aHalign = hAlign_Left; return true; }
|
|
|
|
virtual bool GetInitialVAlignment(Valignment& aValign) { aValign = vAlign_Top; return true; }
|
|
|
|
virtual bool GetInitialAutoStretch(bool& aStretch) { aStretch = true; return true; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* GetCaptionBox(nsPresContext* aPresContext, nsRect& aCaptionRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
class nsGroupBoxInnerFrame : public nsBoxFrame {
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsGroupBoxInnerFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext) {}
|
|
|
|
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
|
|
|
return MakeFrameName("GroupBoxFrameInner", aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// we are always flexible
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool GetDefaultFlex(int32_t& aFlex) { aFlex = 1; return true; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewGroupBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsGroupBoxFrame(aPresShell, aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsGroupBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsDisplayXULGroupBackground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayXULGroupBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsGroupBoxFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayXULGroupBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayXULGroupBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayXULGroupBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("XULGroupBackground", TYPE_XUL_GROUP_BACKGROUND)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayXULGroupBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsGroupBoxFrame*>(mFrame)->
|
2010-08-13 03:01:58 -07:00
|
|
|
PaintBorderBackground(*aCtx, ToReferenceFrame(), mVisibleRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGroupBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// Paint our background and border
|
|
|
|
if (IsVisibleForPainting(aBuilder)) {
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayXULGroupBackground(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayOutline(aBuilder, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsGroupBoxFrame::PaintBorderBackground(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint aPt, const nsRect& aDirtyRect) {
|
2012-08-09 00:09:40 -07:00
|
|
|
int skipSides = 0;
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleBorder* borderStyleData = StyleBorder();
|
2012-05-30 22:19:49 -07:00
|
|
|
const nsMargin& border = borderStyleData->GetComputedBorder();
|
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
|
|
|
|
|
|
|
nsRect groupRect;
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* groupBox = GetCaptionBox(presContext, groupRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (groupBox) {
|
|
|
|
// if the border is smaller than the legend. Move the border down
|
|
|
|
// to be centered on the legend.
|
|
|
|
nsMargin groupMargin;
|
2013-02-16 13:51:02 -08:00
|
|
|
groupBox->StyleMargin()->GetMargin(groupMargin);
|
2007-03-22 10:30:00 -07:00
|
|
|
groupRect.Inflate(groupMargin);
|
|
|
|
|
|
|
|
if (border.top < groupRect.height)
|
|
|
|
yoff = (groupRect.height - border.top)/2 + groupRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(aPt.x, aPt.y + yoff, mRect.width, mRect.height - yoff);
|
|
|
|
|
|
|
|
groupRect += aPt;
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBackground(presContext, aRenderingContext, this,
|
2009-09-12 15:44:18 -07:00
|
|
|
aDirtyRect, rect,
|
|
|
|
nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (groupBox) {
|
|
|
|
|
|
|
|
// 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 = groupRect.x - rect.x;
|
|
|
|
clipRect.height = border.top;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
2011-04-07 18:04:40 -07:00
|
|
|
aRenderingContext.IntersectClip(clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
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 = groupRect.XMost();
|
|
|
|
clipRect.width = rect.XMost() - groupRect.XMost();
|
|
|
|
clipRect.height = border.top;
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
2011-04-07 18:04:40 -07:00
|
|
|
aRenderingContext.IntersectClip(clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
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 += border.top;
|
|
|
|
clipRect.height = mRect.height - (yoff + border.top);
|
|
|
|
|
|
|
|
aRenderingContext.PushState();
|
2011-04-07 18:04:40 -07:00
|
|
|
aRenderingContext.IntersectClip(clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
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, GetSize()),
|
2010-04-02 18:58:26 -07:00
|
|
|
mStyleContext, skipSides);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGroupBoxFrame::GetCaptionBox(nsPresContext* aPresContext, nsRect& aCaptionRect)
|
|
|
|
{
|
|
|
|
// first child is our grouped area
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* box = GetChildBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// no area fail.
|
|
|
|
if (!box)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the first child in the grouped area, that is the caption
|
|
|
|
box = box->GetChildBox();
|
|
|
|
|
|
|
|
// nothing in the area? fail
|
|
|
|
if (!box)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// now get the caption itself. It is in the caption frame.
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame* child = box->GetChildBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (child) {
|
|
|
|
// convert to our coordinates.
|
|
|
|
nsRect parentRect(box->GetRect());
|
|
|
|
aCaptionRect = child->GetRect();
|
|
|
|
aCaptionRect.x += parentRect.x;
|
|
|
|
aCaptionRect.y += parentRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGroupBoxFrame::GetBorderAndPadding(nsMargin& aBorderAndPadding)
|
|
|
|
{
|
|
|
|
aBorderAndPadding.SizeTo(0,0,0,0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|