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"
|
2014-10-20 02:55:48 -07:00
|
|
|
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSRendering.h"
|
2014-10-20 02:55:48 -07:00
|
|
|
#include "nsLayoutUtils.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"
|
|
|
|
|
2014-10-20 02:55:48 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
2015-01-06 01:27:56 -08:00
|
|
|
explicit nsGroupBoxFrame(nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aContext) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult GetBorderAndPadding(nsMargin& aBorderAndPadding) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2007-03-22 10:30:00 -07:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("GroupBoxFrame"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool HonorPrintBackgroundSettings() override { 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.
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void GetInitialOrientation(bool& aHorizontal) override { aHorizontal = false; }
|
|
|
|
virtual bool GetInitialHAlignment(Halignment& aHalign) override { aHalign = hAlign_Left; return true; }
|
|
|
|
virtual bool GetInitialVAlignment(Valignment& aValign) override { aValign = vAlign_Top; return true; }
|
|
|
|
virtual bool GetInitialAutoStretch(bool& aStretch) override { 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)
|
|
|
|
{
|
2015-01-06 01:27:56 -08:00
|
|
|
return new (aPresShell) nsGroupBoxFrame(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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,
|
2015-03-21 09:28:04 -07:00
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) override {
|
2010-04-07 17:31:26 -07:00
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsRenderingContext* aCtx) override;
|
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) {
|
2014-10-20 02:55:48 -07:00
|
|
|
|
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
gfxContext* gfx = aRenderingContext.ThebesContext();
|
|
|
|
|
2014-06-28 03:13:13 -07:00
|
|
|
Sides skipSides;
|
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) {
|
2014-10-20 02:55:48 -07:00
|
|
|
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Save();
|
2014-10-22 04:29:06 -07:00
|
|
|
gfx->Clip(NSRectToSnappedRect(clipRect, appUnitsPerDevPixel, *drawTarget));
|
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);
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// draw right side
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.x = groupRect.XMost();
|
|
|
|
clipRect.width = rect.XMost() - groupRect.XMost();
|
|
|
|
clipRect.height = border.top;
|
|
|
|
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Save();
|
2014-10-22 04:29:06 -07:00
|
|
|
gfx->Clip(NSRectToSnappedRect(clipRect, appUnitsPerDevPixel, *drawTarget));
|
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);
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// draw bottom
|
|
|
|
|
|
|
|
clipRect = rect;
|
|
|
|
clipRect.y += border.top;
|
|
|
|
clipRect.height = mRect.height - (yoff + border.top);
|
|
|
|
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Save();
|
2014-10-22 04:29:06 -07:00
|
|
|
gfx->Clip(NSRectToSnappedRect(clipRect, appUnitsPerDevPixel, *drawTarget));
|
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);
|
2014-10-20 02:55:48 -07:00
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
} 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
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* box = nsBox::GetChildBox(this);
|
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
|
2014-05-24 15:20:41 -07:00
|
|
|
box = nsBox::GetChildBox(box);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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.
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIFrame* child = nsBox::GetChildBox(box);
|
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;
|
|
|
|
}
|
|
|
|
|