2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; 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
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsLeafBoxFrame.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2013-01-04 19:12:24 -08:00
|
|
|
#include "nsViewManager.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewLeafBoxFrame
|
|
|
|
//
|
|
|
|
// Creates a new Toolbar frame and returns it
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewLeafBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsLeafBoxFrame(aPresShell, aContext);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsLeafBoxFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsLeafBoxFrame::nsLeafBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext)
|
2010-11-30 06:59:46 -08:00
|
|
|
: nsLeafFrame(aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
void
|
|
|
|
nsLeafBoxFrame::GetBoxName(nsAutoString& aName)
|
|
|
|
{
|
|
|
|
GetFrameName(aName);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize us. This is a good time to get the alignment of the box
|
|
|
|
*/
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLeafBoxFrame::Init(
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsLeafFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-16 15:32:12 -07:00
|
|
|
if (GetStateBits() & NS_FRAME_FONT_INFLATION_CONTAINER) {
|
|
|
|
AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
|
|
|
|
}
|
|
|
|
|
2007-06-18 16:22:46 -07:00
|
|
|
UpdateMouseThrough();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-06-18 16:22:46 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsLeafBoxFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-06-18 16:22:46 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-06-18 16:22:46 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsLeafFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::mousethrough)
|
|
|
|
UpdateMouseThrough();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsLeafBoxFrame::UpdateMouseThrough()
|
|
|
|
{
|
|
|
|
if (mContent) {
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::never, &nsGkAtoms::always, nullptr};
|
2007-06-18 16:22:46 -07:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::mousethrough,
|
|
|
|
strings, eCaseMatters)) {
|
2010-11-30 06:59:46 -08:00
|
|
|
case 0: AddStateBits(NS_FRAME_MOUSE_THROUGH_NEVER); break;
|
|
|
|
case 1: AddStateBits(NS_FRAME_MOUSE_THROUGH_ALWAYS); break;
|
|
|
|
case 2: {
|
|
|
|
RemoveStateBits(NS_FRAME_MOUSE_THROUGH_ALWAYS);
|
|
|
|
RemoveStateBits(NS_FRAME_MOUSE_THROUGH_NEVER);
|
|
|
|
break;
|
|
|
|
}
|
2007-06-18 16:22:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLeafBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// REVIEW: GetFrameForPoint used to not report events for the background
|
|
|
|
// layer, whereas this code will put an event receiver for this frame in the
|
|
|
|
// BlockBorderBackground() list. But I don't see any need to preserve
|
|
|
|
// that anomalous behaviour. The important thing I'm preserving is that
|
|
|
|
// leaf boxes continue to receive events in the foreground layer.
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!aBuilder->IsForEventDelivery() || !IsVisibleForPainting(aBuilder))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayEventReceiver(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafBoxFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext(), aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize minSize = GetMinSize(state);
|
|
|
|
|
|
|
|
// GetMinSize returns border-box width, and we want to return content
|
|
|
|
// width. Since Reflow uses the reflow state's border and padding, we
|
|
|
|
// actually just want to subtract what GetMinSize added, which is the
|
|
|
|
// result of GetBorderAndPadding.
|
|
|
|
nsMargin bp;
|
|
|
|
GetBorderAndPadding(bp);
|
|
|
|
|
|
|
|
result = minSize.width - bp.LeftRight();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafBoxFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
2007-03-30 14:11:41 -07:00
|
|
|
nsBoxLayoutState state(PresContext(), aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize prefSize = GetPrefSize(state);
|
|
|
|
|
|
|
|
// GetPrefSize returns border-box width, and we want to return content
|
|
|
|
// width. Since Reflow uses the reflow state's border and padding, we
|
|
|
|
// actually just want to subtract what GetPrefSize added, which is the
|
|
|
|
// result of GetBorderAndPadding.
|
|
|
|
nsMargin bp;
|
|
|
|
GetBorderAndPadding(bp);
|
|
|
|
|
|
|
|
result = prefSize.width - bp.LeftRight();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLeafBoxFrame::GetIntrinsicWidth()
|
|
|
|
{
|
|
|
|
// No intrinsic width
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-27 12:24:06 -08:00
|
|
|
nsSize
|
2011-04-07 18:04:40 -07:00
|
|
|
nsLeafBoxFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
2008-01-27 12:24:06 -08:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSize aPadding, bool aShrinkWrap)
|
2008-01-27 12:24:06 -08:00
|
|
|
{
|
|
|
|
// Important: NOT calling our direct superclass here!
|
|
|
|
return nsFrame::ComputeAutoSize(aRenderingContext, aCBSize, aAvailableWidth,
|
|
|
|
aMargin, aBorder, aPadding, aShrinkWrap);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLeafBoxFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// This is mostly a copy of nsBoxFrame::Reflow().
|
|
|
|
// We aren't able to share an implementation because of the frame
|
|
|
|
// class hierarchy. If you make changes here, please keep
|
|
|
|
// nsBoxFrame::Reflow in sync.
|
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
NS_ASSERTION(aReflowState.ComputedWidth() >=0 &&
|
|
|
|
aReflowState.ComputedHeight() >= 0, "Computed Size < 0");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DO_NOISY_REFLOW
|
|
|
|
printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n");
|
|
|
|
printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++);
|
|
|
|
switch (aReflowState.reason) {
|
|
|
|
case eReflowReason_Initial:
|
|
|
|
printf("Ini");break;
|
|
|
|
case eReflowReason_Incremental:
|
|
|
|
printf("Inc");break;
|
|
|
|
case eReflowReason_Resize:
|
|
|
|
printf("Rsz");break;
|
|
|
|
case eReflowReason_StyleChange:
|
|
|
|
printf("Sty");break;
|
|
|
|
case eReflowReason_Dirty:
|
|
|
|
printf("Drt ");
|
|
|
|
break;
|
|
|
|
default:printf("<unknown>%d", aReflowState.reason);break;
|
|
|
|
}
|
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
printSize("AW", aReflowState.AvailableWidth());
|
|
|
|
printSize("AH", aReflowState.AvailableHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
printSize("CW", aReflowState.ComputedWidth());
|
2007-08-02 11:08:05 -07:00
|
|
|
printSize("CH", aReflowState.ComputedHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
printf(" *\n");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
// create the layout state
|
|
|
|
nsBoxLayoutState state(aPresContext, aReflowState.rendContext);
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
nsSize computedSize(aReflowState.ComputedWidth(),aReflowState.ComputedHeight());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMargin m;
|
2013-12-27 09:59:21 -08:00
|
|
|
m = aReflowState.ComputedPhysicalBorderPadding();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//GetBorderAndPadding(m);
|
|
|
|
|
|
|
|
// this happens sometimes. So lets handle it gracefully.
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize minSize = GetMinSize(state);
|
|
|
|
computedSize.height = minSize.height - m.top - m.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize prefSize(0,0);
|
|
|
|
|
|
|
|
// if we are told to layout intrinic then get our preferred size.
|
|
|
|
if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) {
|
|
|
|
prefSize = GetPrefSize(state);
|
|
|
|
nsSize minSize = GetMinSize(state);
|
|
|
|
nsSize maxSize = GetMaxSize(state);
|
2008-01-04 21:49:44 -08:00
|
|
|
prefSize = BoundsCheck(minSize, prefSize, maxSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// get our desiredSize
|
|
|
|
if (aReflowState.ComputedWidth() == NS_INTRINSICSIZE) {
|
|
|
|
computedSize.width = prefSize.width;
|
|
|
|
} else {
|
|
|
|
computedSize.width += m.left + m.right;
|
|
|
|
}
|
|
|
|
|
2007-08-02 11:08:05 -07:00
|
|
|
if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
computedSize.height = prefSize.height;
|
|
|
|
} else {
|
|
|
|
computedSize.height += m.top + m.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle reflow state min and max sizes
|
2012-08-27 12:46:23 -07:00
|
|
|
// XXXbz the width handling here seems to be wrong, since
|
|
|
|
// mComputedMin/MaxWidth is a content-box size, whole
|
|
|
|
// computedSize.width is a border-box size...
|
2013-12-27 09:59:21 -08:00
|
|
|
if (computedSize.width > aReflowState.ComputedMaxWidth())
|
|
|
|
computedSize.width = aReflowState.ComputedMaxWidth();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
if (computedSize.width < aReflowState.ComputedMinWidth())
|
|
|
|
computedSize.width = aReflowState.ComputedMinWidth();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-27 12:46:23 -07:00
|
|
|
// Now adjust computedSize.height for our min and max computed
|
|
|
|
// height. The only problem is that those are content-box sizes,
|
|
|
|
// while computedSize.height is a border-box size. So subtract off
|
|
|
|
// m.TopBottom() before adjusting, then readd it.
|
2013-01-15 04:22:03 -08:00
|
|
|
computedSize.height = std::max(0, computedSize.height - m.TopBottom());
|
2012-08-27 12:46:23 -07:00
|
|
|
computedSize.height = NS_CSS_MINMAX(computedSize.height,
|
2013-12-27 09:59:21 -08:00
|
|
|
aReflowState.ComputedMinHeight(),
|
|
|
|
aReflowState.ComputedMaxHeight());
|
2012-08-27 12:46:23 -07:00
|
|
|
computedSize.height += m.TopBottom();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height);
|
|
|
|
|
|
|
|
SetBounds(state, r);
|
|
|
|
|
|
|
|
// layout our children
|
|
|
|
Layout(state);
|
|
|
|
|
|
|
|
// ok our child could have gotten bigger. So lets get its bounds
|
|
|
|
aDesiredSize.width = mRect.width;
|
|
|
|
aDesiredSize.height = mRect.height;
|
|
|
|
aDesiredSize.ascent = GetBoxAscent(state);
|
|
|
|
|
2009-04-05 17:31:50 -07:00
|
|
|
// the overflow rect is set in SetBounds() above
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.mOverflowAreas = GetOverflowAreas();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DO_NOISY_REFLOW
|
|
|
|
{
|
|
|
|
printf("%p ** nsLBF(done) W:%d H:%d ", this, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
|
|
|
|
if (maxElementWidth) {
|
|
|
|
printf("MW:%d\n", *maxElementWidth);
|
|
|
|
} else {
|
|
|
|
printf("MW:?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLeafBoxFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("LeafBox"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-03 15:11:28 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsLeafBoxFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::leafBoxFrame;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2009-08-04 18:38:10 -07:00
|
|
|
nsLeafBoxFrame::CharacterDataChanged(CharacterDataChangeInfo* aInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MarkIntrinsicWidthsDirty();
|
2009-08-04 18:38:10 -07:00
|
|
|
return nsLeafFrame::CharacterDataChanged(aInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsLeafBoxFrame::GetPrefSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::GetPrefSize(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsLeafBoxFrame::GetMinSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::GetMinSize(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSize
|
|
|
|
nsLeafBoxFrame::GetMaxSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::GetMaxSize(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsLeafBoxFrame::GetFlex(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::GetFlex(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsLeafBoxFrame::GetBoxAscent(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::GetBoxAscent(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsLeafBoxFrame::MarkIntrinsicWidthsDirty()
|
|
|
|
{
|
|
|
|
// Don't call base class method, since everything it does is within an
|
|
|
|
// IsBoxWrapped check.
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLeafBoxFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
return nsBox::DoLayout(aState);
|
|
|
|
}
|