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
|
|
|
|
|
|
|
/*
|
|
|
|
* rendering object that is the root of the frame tree, which contains
|
|
|
|
* the document's scrollbars and contains fixed-positioned elements
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsViewportFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2011-12-05 04:38:46 -08:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2011-04-29 16:02:33 -07:00
|
|
|
#include "nsAbsoluteContainingBlock.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2010-08-08 11:49:06 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
ViewportFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NewViewportFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) ViewportFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(ViewportFrame)
|
2013-04-24 09:17:55 -07:00
|
|
|
NS_QUERYFRAME_HEAD(ViewportFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(ViewportFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2009-09-12 09:49:24 -07:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
ViewportFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
Super::Init(aContent, aParent, aPrevInFlow);
|
2012-08-28 22:39:01 -07:00
|
|
|
|
|
|
|
nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrame(this);
|
|
|
|
if (parent) {
|
|
|
|
nsFrameState state = parent->GetStateBits();
|
|
|
|
|
|
|
|
mState |= state & (NS_FRAME_IN_POPUP);
|
|
|
|
}
|
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
|
|
|
ViewportFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("ViewportFrame", "BuildDisplayList",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
if (!kid)
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// make the kid's BorderBackground our own. This ensures that the canvas
|
|
|
|
// frame's background becomes our own background and therefore appears
|
|
|
|
// below negative z-index elements.
|
2013-02-14 03:08:08 -08:00
|
|
|
BuildDisplayListForChild(aBuilder, kid, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:59 -07:00
|
|
|
#ifdef DEBUG
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
|
|
|
ViewportFrame::SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
|
|
|
nsFrame::VerifyDirtyBitSet(aChildList);
|
|
|
|
nsContainerFrame::SetInitialChildList(aListID, aChildList);
|
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2011-08-24 13:54:30 -07:00
|
|
|
ViewportFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-28 12:36:59 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
|
|
|
NS_ASSERTION(GetChildList(aListID).IsEmpty(), "Shouldn't have any kids!");
|
2014-05-28 12:36:58 -07:00
|
|
|
nsContainerFrame::AppendFrames(aListID, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2011-08-24 13:54:30 -07:00
|
|
|
ViewportFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-05-28 12:36:59 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
|
|
|
NS_ASSERTION(GetChildList(aListID).IsEmpty(), "Shouldn't have any kids!");
|
2014-05-28 12:36:58 -07:00
|
|
|
nsContainerFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2011-08-24 13:54:30 -07:00
|
|
|
ViewportFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2014-05-28 12:36:59 -07:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
2014-05-28 12:36:58 -07:00
|
|
|
nsContainerFrame::RemoveFrame(aListID, aOldFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-05-28 12:36:59 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
ViewportFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
if (mFrames.IsEmpty())
|
|
|
|
result = 0;
|
|
|
|
else
|
2014-07-24 10:03:25 -07:00
|
|
|
result = mFrames.FirstChild()->GetMinISize(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
ViewportFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
if (mFrames.IsEmpty())
|
|
|
|
result = 0;
|
|
|
|
else
|
2014-07-24 10:03:25 -07:00
|
|
|
result = mFrames.FirstChild()->GetPrefISize(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
2008-10-29 17:41:56 -07:00
|
|
|
ViewportFrame::AdjustReflowStateForScrollbars(nsHTMLReflowState* aReflowState) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get our prinicpal child frame and see if we're scrollable
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
2013-04-24 09:17:55 -07:00
|
|
|
nsIScrollableFrame* scrollingFrame = do_QueryFrame(kidFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (scrollingFrame) {
|
|
|
|
nsMargin scrollbars = scrollingFrame->GetActualScrollbarSizes();
|
|
|
|
aReflowState->SetComputedWidth(aReflowState->ComputedWidth() -
|
2007-08-02 11:08:05 -07:00
|
|
|
scrollbars.LeftRight());
|
2013-12-27 09:59:21 -08:00
|
|
|
aReflowState->AvailableWidth() -= scrollbars.LeftRight();
|
2009-01-29 12:39:22 -08:00
|
|
|
aReflowState->SetComputedHeightWithoutResettingResizeFlags(
|
|
|
|
aReflowState->ComputedHeight() - scrollbars.TopBottom());
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsPoint(scrollbars.left, scrollbars.top);
|
|
|
|
}
|
|
|
|
return nsPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-24 09:17:55 -07:00
|
|
|
nsRect
|
|
|
|
ViewportFrame::AdjustReflowStateAsContainingBlock(nsHTMLReflowState* aReflowState) const
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsPoint offset =
|
|
|
|
#endif
|
|
|
|
AdjustReflowStateForScrollbars(aReflowState);
|
|
|
|
|
|
|
|
NS_ASSERTION(GetAbsoluteContainingBlock()->GetChildList().IsEmpty() ||
|
|
|
|
(offset.x == 0 && offset.y == 0),
|
|
|
|
"We don't handle correct positioning of fixed frames with "
|
|
|
|
"scrollbars in odd positions");
|
|
|
|
|
|
|
|
// If a scroll position clamping scroll-port size has been set, layout
|
|
|
|
// fixed position elements to this size instead of the computed size.
|
|
|
|
nsRect rect(0, 0, aReflowState->ComputedWidth(), aReflowState->ComputedHeight());
|
|
|
|
nsIPresShell* ps = PresContext()->PresShell();
|
|
|
|
if (ps->IsScrollPositionClampingScrollPortSizeSet()) {
|
|
|
|
rect.SizeTo(ps->GetScrollPositionClampingScrollPortSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure content document fixed-position margins are respected.
|
|
|
|
rect.Deflate(ps->GetContentDocumentFixedPositionMargins());
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2008-10-29 17:41:56 -07:00
|
|
|
ViewportFrame::Reflow(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("ViewportFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
NS_FRAME_TRACE_REFLOW_IN("ViewportFrame::Reflow");
|
|
|
|
|
|
|
|
// Initialize OUT parameters
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
// Because |Reflow| sets mComputedHeight on the child to
|
|
|
|
// availableHeight.
|
|
|
|
AddStateBits(NS_FRAME_CONTAINS_RELATIVE_HEIGHT);
|
2010-08-05 14:59:36 -07:00
|
|
|
|
|
|
|
// Set our size up front, since some parts of reflow depend on it
|
|
|
|
// being already set. Note that the computed height may be
|
|
|
|
// unconstrained; that's ok. Consumers should watch out for that.
|
|
|
|
SetSize(nsSize(aReflowState.ComputedWidth(), aReflowState.ComputedHeight()));
|
2014-09-23 06:44:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reflow the main content first so that the placeholders of the
|
|
|
|
// fixed-position frames will be in the right places on an initial
|
|
|
|
// reflow.
|
2014-07-24 01:30:07 -07:00
|
|
|
nscoord kidBSize = 0;
|
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
// Deal with a non-incremental reflow or an incremental reflow
|
|
|
|
// targeted at our one-and-only principal child frame.
|
|
|
|
if (aReflowState.ShouldReflowAllKids() ||
|
|
|
|
aReflowState.mFlags.mVResize ||
|
2007-05-06 12:16:51 -07:00
|
|
|
NS_SUBTREE_DIRTY(mFrames.FirstChild())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reflow our one-and-only principal child frame
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics kidDesiredSize(aReflowState);
|
2014-07-24 01:28:46 -07:00
|
|
|
WritingMode wm = kidFrame->GetWritingMode();
|
|
|
|
LogicalSize availableSpace = aReflowState.AvailableSize(wm);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
|
|
|
|
kidFrame, availableSpace);
|
|
|
|
|
|
|
|
// Reflow the frame
|
2009-01-29 12:39:22 -08:00
|
|
|
kidReflowState.SetComputedHeight(aReflowState.ComputedHeight());
|
2014-05-12 17:47:52 -07:00
|
|
|
ReflowChild(kidFrame, aPresContext, kidDesiredSize, kidReflowState,
|
|
|
|
0, 0, 0, aStatus);
|
2014-07-24 01:30:07 -07:00
|
|
|
kidBSize = kidDesiredSize.BSize(wm);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-16 17:34:44 -08:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, kidDesiredSize, nullptr, 0, 0, 0);
|
2008-03-12 15:04:45 -07:00
|
|
|
} else {
|
2014-07-24 01:30:07 -07:00
|
|
|
kidBSize = LogicalSize(wm, mFrames.FirstChild()->GetSize()).BSize(wm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 09:59:21 -08:00
|
|
|
NS_ASSERTION(aReflowState.AvailableWidth() != NS_UNCONSTRAINEDSIZE,
|
2007-03-22 10:30:00 -07:00
|
|
|
"shouldn't happen anymore");
|
|
|
|
|
|
|
|
// Return the max size as our desired size
|
2014-07-24 01:30:07 -07:00
|
|
|
LogicalSize maxSize(wm, aReflowState.AvailableISize(),
|
|
|
|
// Being flowed initially at an unconstrained block size
|
|
|
|
// means we should return our child's intrinsic size.
|
|
|
|
aReflowState.ComputedBSize() != NS_UNCONSTRAINEDSIZE
|
|
|
|
? aReflowState.ComputedBSize()
|
|
|
|
: kidBSize);
|
|
|
|
aDesiredSize.SetSize(wm, maxSize);
|
2011-12-05 04:39:14 -08:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2012-10-22 18:48:12 -07:00
|
|
|
if (IsAbsoluteContainer()) {
|
|
|
|
// Make a copy of the reflow state and change the computed width and height
|
|
|
|
// to reflect the available space for the fixed items
|
|
|
|
nsHTMLReflowState reflowState(aReflowState);
|
|
|
|
|
2014-07-24 01:30:07 -07:00
|
|
|
if (reflowState.AvailableBSize() == NS_UNCONSTRAINEDSIZE) {
|
2012-10-22 18:48:12 -07:00
|
|
|
// We have an intrinsic-height document with abs-pos/fixed-pos children.
|
|
|
|
// Set the available height and mComputedHeight to our chosen height.
|
2014-07-24 01:30:07 -07:00
|
|
|
reflowState.AvailableBSize() = maxSize.BSize(wm);
|
2012-10-22 18:48:12 -07:00
|
|
|
// Not having border/padding simplifies things
|
2013-12-27 09:59:21 -08:00
|
|
|
NS_ASSERTION(reflowState.ComputedPhysicalBorderPadding() == nsMargin(0,0,0,0),
|
2012-10-22 18:48:12 -07:00
|
|
|
"Viewports can't have border/padding");
|
2014-07-24 01:30:07 -07:00
|
|
|
reflowState.SetComputedBSize(maxSize.BSize(wm));
|
2012-10-22 18:48:12 -07:00
|
|
|
}
|
|
|
|
|
2013-04-24 09:17:55 -07:00
|
|
|
nsRect rect = AdjustReflowStateAsContainingBlock(&reflowState);
|
2013-04-15 01:31:45 -07:00
|
|
|
|
2011-04-29 16:02:33 -07:00
|
|
|
// Just reflow all the fixed-pos frames.
|
2014-05-12 17:47:52 -07:00
|
|
|
GetAbsoluteContainingBlock()->Reflow(this, aPresContext, reflowState, aStatus,
|
|
|
|
rect,
|
|
|
|
false, true, true, // XXX could be optimized
|
|
|
|
&aDesiredSize.mOverflowAreas);
|
2014-09-23 06:44:00 -07:00
|
|
|
|
|
|
|
nsIScrollableFrame* rootScrollFrame =
|
|
|
|
aPresContext->PresShell()->GetRootScrollFrameAsScrollable();
|
|
|
|
if (rootScrollFrame && !rootScrollFrame->IsIgnoringViewportClipping()) {
|
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, mFrames.FirstChild());
|
2011-04-29 16:02:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we were dirty then do a repaint
|
|
|
|
if (GetStateBits() & NS_FRAME_IS_DIRTY) {
|
2012-08-28 22:39:31 -07:00
|
|
|
InvalidateFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-05 04:38:46 -08:00
|
|
|
// Clipping is handled by the document container (e.g., nsSubDocumentFrame),
|
|
|
|
// so we don't need to change our overflow areas.
|
|
|
|
bool overflowChanged = FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
if (overflowChanged) {
|
|
|
|
// We may need to alert our container to get it to pick up the
|
|
|
|
// overflow change.
|
|
|
|
nsSubDocumentFrame* container = static_cast<nsSubDocumentFrame*>
|
|
|
|
(nsLayoutUtils::GetCrossDocParentFrame(this));
|
|
|
|
if (container && !container->ShouldClipSubdocument()) {
|
|
|
|
container->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(container, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus);
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
2014-09-23 06:44:00 -07:00
|
|
|
bool
|
|
|
|
ViewportFrame::UpdateOverflow()
|
|
|
|
{
|
|
|
|
nsIScrollableFrame* rootScrollFrame =
|
|
|
|
PresContext()->PresShell()->GetRootScrollFrameAsScrollable();
|
|
|
|
if (rootScrollFrame && !rootScrollFrame->IsIgnoringViewportClipping()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsFrame::UpdateOverflow();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom*
|
|
|
|
ViewportFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::viewportFrame;
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
ViewportFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Viewport"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|