2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rendering object that is the root of the frame tree, which contains
|
|
|
|
* the document's scrollbars and contains fixed-positioned elements
|
|
|
|
*/
|
|
|
|
|
2016-11-30 06:14:29 +03:00
|
|
|
#include "mozilla/ViewportFrame.h"
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyleInlines.h"
|
2019-04-06 09:02:28 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
Bug 1691589 - Reduce reliance on GeckoProfiler.h when only labels (and maybe markers) are needed - r=necko-reviewers,geckoview-reviewers,sg,agi,florian
There are no code changes, only #include changes.
It was a fairly mechanical process: Search for all "AUTO_PROFILER_LABEL", and in each file, if only labels are used, convert "GeckoProfiler.h" into "ProfilerLabels.h" (or just add that last one where needed).
In some files, there were also some marker calls but no other profiler-related calls, in these cases "GeckoProfiler.h" was replaced with both "ProfilerLabels.h" and "ProfilerMarkers.h", which still helps in reducing the use of the all-encompassing "GeckoProfiler.h".
Differential Revision: https://phabricator.services.mozilla.com/D104588
2021-02-16 07:44:19 +03:00
|
|
|
#include "mozilla/ProfilerLabels.h"
|
2018-04-05 22:12:37 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-04-17 05:45:38 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2021-01-22 23:57:33 +03:00
|
|
|
#include "nsAbsoluteContainingBlock.h"
|
2021-01-25 03:31:30 +03:00
|
|
|
#include "nsCanvasFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsSubDocumentFrame.h"
|
2015-10-07 06:04:32 +03:00
|
|
|
#include "nsIMozBrowserFrame.h"
|
2016-12-01 01:51:12 +03:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2020-06-19 01:30:00 +03:00
|
|
|
#include "MobileViewportManager.h"
|
2010-08-08 22:49:06 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2015-12-23 01:03:16 +03:00
|
|
|
typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags;
|
1999-01-26 03:05:21 +03:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
ViewportFrame* NS_NewViewportFrame(PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) ViewportFrame(aStyle, aPresShell->GetPresContext());
|
1999-01-26 03:05:21 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(ViewportFrame)
|
2013-04-24 20:17:55 +04:00
|
|
|
NS_QUERYFRAME_HEAD(ViewportFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(ViewportFrame)
|
2013-04-24 20:17:55 +04:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void ViewportFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2016-04-18 09:32:45 +03:00
|
|
|
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2017-03-21 03:22:13 +03:00
|
|
|
// No need to call CreateView() here - the frame ctor will call SetView()
|
|
|
|
// with the ViewManager's root view, so we'll assign it in SetViewInternal().
|
2012-08-29 09:39:01 +04:00
|
|
|
|
2021-08-09 22:12:13 +03:00
|
|
|
nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrameInProcess(this);
|
2012-08-29 09:39:01 +04:00
|
|
|
if (parent) {
|
|
|
|
nsFrameState state = parent->GetStateBits();
|
|
|
|
|
2017-08-24 14:09:42 +03:00
|
|
|
AddStateBits(state & (NS_FRAME_IN_POPUP));
|
2012-08-29 09:39:01 +04:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void ViewportFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
2019-02-16 20:38:23 +03:00
|
|
|
AUTO_PROFILER_LABEL("ViewportFrame::BuildDisplayList",
|
|
|
|
GRAPHICS_DisplayListBuilding);
|
2014-05-24 01:12:29 +04:00
|
|
|
|
2021-01-25 03:31:30 +03:00
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
if (!kid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayListCollection set(aBuilder);
|
|
|
|
BuildDisplayListForChild(aBuilder, kid, set);
|
|
|
|
|
|
|
|
// If we have a scrollframe then it takes care of creating the display list
|
|
|
|
// for the top layer, but otherwise we need to do it here.
|
|
|
|
if (!kid->IsScrollFrame()) {
|
|
|
|
bool isOpaque = false;
|
|
|
|
if (auto* list = BuildDisplayListForTopLayer(aBuilder, &isOpaque)) {
|
|
|
|
if (isOpaque) {
|
|
|
|
set.DeleteAll(aBuilder);
|
|
|
|
}
|
|
|
|
set.PositionedDescendants()->AppendToTop(list);
|
|
|
|
}
|
2015-10-07 06:04:32 +03:00
|
|
|
}
|
2021-01-25 03:31:30 +03:00
|
|
|
|
|
|
|
set.MoveTo(aLists);
|
2015-10-07 06:04:32 +03:00
|
|
|
}
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2015-10-07 06:04:32 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* Returns whether we are going to put an element in the top layer for
|
|
|
|
* fullscreen. This function should matches the CSS rule in ua.css.
|
|
|
|
*/
|
2019-11-29 23:39:36 +03:00
|
|
|
static bool ShouldInTopLayerForFullscreen(dom::Element* aElement) {
|
2015-10-07 06:04:32 +03:00
|
|
|
if (!aElement->GetParent()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(aElement);
|
2016-10-15 04:46:26 +03:00
|
|
|
if (browserFrame && browserFrame->GetReallyIsBrowser()) {
|
2015-10-07 06:04:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2015-10-19 03:56:13 +03:00
|
|
|
static void BuildDisplayListForTopLayerFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList) {
|
2017-10-04 04:28:38 +03:00
|
|
|
nsRect visible;
|
2015-10-19 03:56:13 +03:00
|
|
|
nsRect dirty;
|
2020-04-30 23:39:53 +03:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
2017-02-01 01:07:35 +03:00
|
|
|
nsDisplayListBuilder::AutoCurrentActiveScrolledRootSetter asrSetter(aBuilder);
|
2015-10-19 03:56:13 +03:00
|
|
|
nsDisplayListBuilder::OutOfFlowDisplayData* savedOutOfFlowData =
|
|
|
|
nsDisplayListBuilder::GetOutOfFlowData(aFrame);
|
|
|
|
if (savedOutOfFlowData) {
|
2017-03-01 02:09:43 +03:00
|
|
|
visible =
|
|
|
|
savedOutOfFlowData->GetVisibleRectForFrame(aBuilder, aFrame, &dirty);
|
2017-01-27 19:33:53 +03:00
|
|
|
// This function is called after we've finished building display items for
|
|
|
|
// the root scroll frame. That means that the content clip from the root
|
|
|
|
// scroll frame is no longer on aBuilder. However, we need to make sure
|
|
|
|
// that the display items we build in this function have finite clipped
|
|
|
|
// bounds with respect to the root ASR, so we restore the *combined clip*
|
|
|
|
// that we saved earlier. The combined clip will include the clip from the
|
|
|
|
// root scroll frame.
|
2017-02-01 01:07:35 +03:00
|
|
|
clipState.SetClipChainForContainingBlockDescendants(
|
2017-01-27 19:33:53 +03:00
|
|
|
savedOutOfFlowData->mCombinedClipChain);
|
2017-02-01 01:07:35 +03:00
|
|
|
asrSetter.SetCurrentActiveScrolledRoot(
|
|
|
|
savedOutOfFlowData->mContainingBlockActiveScrolledRoot);
|
2015-10-19 03:56:13 +03:00
|
|
|
}
|
2017-08-07 05:23:35 +03:00
|
|
|
nsDisplayListBuilder::AutoBuildingDisplayList buildingForChild(
|
2019-04-15 18:15:49 +03:00
|
|
|
aBuilder, aFrame, visible, dirty);
|
2017-08-07 05:23:35 +03:00
|
|
|
|
2022-02-23 02:42:18 +03:00
|
|
|
nsDisplayList list(aBuilder);
|
2017-08-07 05:23:35 +03:00
|
|
|
aFrame->BuildDisplayListForStackingContext(aBuilder, &list);
|
2015-10-19 03:56:13 +03:00
|
|
|
aList->AppendToTop(&list);
|
|
|
|
}
|
|
|
|
|
2020-10-16 01:38:49 +03:00
|
|
|
static bool BackdropListIsOpaque(ViewportFrame* aFrame,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList) {
|
|
|
|
// The common case for ::backdrop elements on the top layer is a single
|
|
|
|
// fixed position container, holding an opaque background color covering
|
|
|
|
// the whole viewport.
|
2022-02-23 02:42:18 +03:00
|
|
|
if (aList->Length() != 1 ||
|
2020-10-16 01:38:49 +03:00
|
|
|
aList->GetTop()->GetType() != DisplayItemType::TYPE_FIXED_POSITION) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the fixed position container isn't clipped or scrollable.
|
|
|
|
nsDisplayFixedPosition* fixed =
|
|
|
|
static_cast<nsDisplayFixedPosition*>(aList->GetTop());
|
|
|
|
if (fixed->GetActiveScrolledRoot() || fixed->GetClipChain()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayList* children = fixed->GetChildren();
|
|
|
|
if (!children->GetTop() ||
|
|
|
|
children->GetTop()->GetType() != DisplayItemType::TYPE_BACKGROUND_COLOR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayBackgroundColor* child =
|
|
|
|
static_cast<nsDisplayBackgroundColor*>(children->GetTop());
|
|
|
|
if (child->GetActiveScrolledRoot() || child->GetClipChain()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the background color is both opaque, and covering the
|
|
|
|
// whole viewport.
|
|
|
|
bool dummy;
|
|
|
|
nsRegion opaque = child->GetOpaqueRegion(aBuilder, &dummy);
|
|
|
|
return opaque.Contains(aFrame->GetRect());
|
|
|
|
}
|
|
|
|
|
2021-01-25 03:31:30 +03:00
|
|
|
nsDisplayWrapList* ViewportFrame::BuildDisplayListForTopLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder, bool* aIsOpaque) {
|
2022-02-23 02:42:18 +03:00
|
|
|
nsDisplayList topLayerList(aBuilder);
|
2021-01-25 03:31:30 +03:00
|
|
|
|
2020-04-14 22:51:36 +03:00
|
|
|
nsTArray<dom::Element*> topLayer = PresContext()->Document()->GetTopLayer();
|
|
|
|
for (dom::Element* elem : topLayer) {
|
2021-01-25 03:31:30 +03:00
|
|
|
nsIFrame* frame = elem->GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// There are two cases where an element in fullscreen is not in
|
|
|
|
// the top layer:
|
|
|
|
// 1. When building display list for purpose other than painting,
|
|
|
|
// it is possible that there is inconsistency between the style
|
|
|
|
// info and the content tree.
|
|
|
|
// 2. This is an element which we are not going to put in the top
|
|
|
|
// layer for fullscreen. See ShouldInTopLayerForFullscreen().
|
|
|
|
// In both cases, we want to skip the frame here and paint it in
|
|
|
|
// the normal path.
|
|
|
|
if (frame->StyleDisplay()->mTopLayer == StyleTopLayer::None) {
|
|
|
|
MOZ_ASSERT(!aBuilder->IsForPainting() ||
|
|
|
|
!ShouldInTopLayerForFullscreen(elem));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(ShouldInTopLayerForFullscreen(elem));
|
|
|
|
// Inner SVG, MathML elements, as well as children of some XUL
|
|
|
|
// elements are not allowed to be out-of-flow. They should not
|
|
|
|
// be handled as top layer element here.
|
|
|
|
if (!frame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
MOZ_ASSERT(!elem->GetParent()->IsHTMLElement(),
|
|
|
|
"HTML element should always be out-of-flow if in the top "
|
|
|
|
"layer");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (nsIFrame* backdropPh =
|
|
|
|
frame->GetChildList(kBackdropList).FirstChild()) {
|
|
|
|
MOZ_ASSERT(!backdropPh->GetNextSibling(), "more than one ::backdrop?");
|
|
|
|
MOZ_ASSERT(backdropPh->HasAnyStateBits(NS_FRAME_FIRST_REFLOW),
|
|
|
|
"did you intend to reflow ::backdrop placeholders?");
|
|
|
|
nsIFrame* backdropFrame =
|
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(backdropPh);
|
|
|
|
BuildDisplayListForTopLayerFrame(aBuilder, backdropFrame, &topLayerList);
|
|
|
|
|
|
|
|
if (aIsOpaque) {
|
|
|
|
*aIsOpaque = BackdropListIsOpaque(this, aBuilder, &topLayerList);
|
2021-01-22 23:57:33 +03:00
|
|
|
}
|
2015-10-19 03:56:13 +03:00
|
|
|
}
|
2021-01-25 03:31:30 +03:00
|
|
|
BuildDisplayListForTopLayerFrame(aBuilder, frame, &topLayerList);
|
2015-10-19 03:56:13 +03:00
|
|
|
}
|
2015-10-07 06:04:32 +03:00
|
|
|
|
2019-04-06 09:02:28 +03:00
|
|
|
if (nsCanvasFrame* canvasFrame = PresShell()->GetCanvasFrame()) {
|
2019-11-29 23:39:36 +03:00
|
|
|
if (dom::Element* container = canvasFrame->GetCustomContentContainer()) {
|
2015-10-19 03:56:13 +03:00
|
|
|
if (nsIFrame* frame = container->GetPrimaryFrame()) {
|
2019-12-01 16:05:55 +03:00
|
|
|
MOZ_ASSERT(frame->StyleDisplay()->mTopLayer != StyleTopLayer::None,
|
2018-06-11 05:45:10 +03:00
|
|
|
"ua.css should ensure this");
|
2020-06-27 17:09:45 +03:00
|
|
|
MOZ_ASSERT(frame->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW));
|
2021-01-25 03:31:30 +03:00
|
|
|
BuildDisplayListForTopLayerFrame(aBuilder, frame, &topLayerList);
|
2015-10-07 06:04:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 03:31:30 +03:00
|
|
|
if (topLayerList.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-05-19 04:11:32 +03:00
|
|
|
nsPoint offset = aBuilder->GetCurrentFrame()->GetOffsetTo(this);
|
|
|
|
nsDisplayListBuilder::AutoBuildingDisplayList buildingDisplayList(
|
|
|
|
aBuilder, this, aBuilder->GetVisibleRect() + offset,
|
|
|
|
aBuilder->GetDirtyRect() + offset);
|
2021-01-25 03:31:30 +03:00
|
|
|
// Wrap the whole top layer in a single item with maximum z-index,
|
|
|
|
// and append it at the very end, so that it stays at the topmost.
|
2021-05-19 04:11:32 +03:00
|
|
|
nsDisplayWrapList* wrapList = MakeDisplayItemWithIndex<nsDisplayWrapper>(
|
2021-01-25 03:31:30 +03:00
|
|
|
aBuilder, this, 2, &topLayerList, aBuilder->CurrentActiveScrolledRoot(),
|
|
|
|
false);
|
|
|
|
if (!wrapList) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
wrapList->SetOverrideZIndex(
|
|
|
|
std::numeric_limits<decltype(wrapList->ZIndex())>::max());
|
|
|
|
return wrapList;
|
2000-03-22 05:43:08 +03:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:59 +04:00
|
|
|
#ifdef DEBUG
|
2011-08-25 00:54:30 +04:00
|
|
|
void ViewportFrame::AppendFrames(ChildListID aListID, nsFrameList& aFrameList) {
|
2014-05-28 23:36:59 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
|
|
|
NS_ASSERTION(GetChildList(aListID).IsEmpty(), "Shouldn't have any kids!");
|
2014-05-28 23:36:58 +04:00
|
|
|
nsContainerFrame::AppendFrames(aListID, aFrameList);
|
1999-07-24 07:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void ViewportFrame::InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2019-07-18 02:34:45 +03:00
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
2014-05-28 23:36:59 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
|
|
|
NS_ASSERTION(GetChildList(aListID).IsEmpty(), "Shouldn't have any kids!");
|
2019-07-18 02:34:45 +03:00
|
|
|
nsContainerFrame::InsertFrames(aListID, aPrevFrame, aPrevFrameLine,
|
|
|
|
aFrameList);
|
1999-07-24 07:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void ViewportFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
|
2014-05-28 23:36:59 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
2014-05-28 23:36:58 +04:00
|
|
|
nsContainerFrame::RemoveFrame(aListID, aOldFrame);
|
1999-01-28 20:14:13 +03:00
|
|
|
}
|
2014-05-28 23:36:59 +04:00
|
|
|
#endif
|
1999-01-28 20:14:13 +03:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
nscoord ViewportFrame::GetMinISize(gfxContext* aRenderingContext) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord result;
|
2018-09-12 15:35:47 +03:00
|
|
|
DISPLAY_MIN_INLINE_SIZE(this, result);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (mFrames.IsEmpty())
|
|
|
|
result = 0;
|
|
|
|
else
|
2014-07-24 21:03:25 +04:00
|
|
|
result = mFrames.FirstChild()->GetMinISize(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
nscoord ViewportFrame::GetPrefISize(gfxContext* aRenderingContext) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord result;
|
2018-09-12 15:35:47 +03:00
|
|
|
DISPLAY_PREF_INLINE_SIZE(this, result);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (mFrames.IsEmpty())
|
|
|
|
result = 0;
|
|
|
|
else
|
2014-07-24 21:03:25 +04:00
|
|
|
result = mFrames.FirstChild()->GetPrefISize(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsPoint ViewportFrame::AdjustReflowInputForScrollbars(
|
|
|
|
ReflowInput* aReflowInput) const {
|
1999-02-03 20:01:51 +03:00
|
|
|
// Get our prinicpal child frame and see if we're scrollable
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
2013-04-24 20:17:55 +04:00
|
|
|
nsIScrollableFrame* scrollingFrame = do_QueryFrame(kidFrame);
|
2001-04-17 05:45:38 +04:00
|
|
|
|
|
|
|
if (scrollingFrame) {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput->GetWritingMode();
|
2016-05-18 23:07:54 +03:00
|
|
|
LogicalMargin scrollbars(wm, scrollingFrame->GetActualScrollbarSizes());
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput->SetComputedISize(aReflowInput->ComputedISize() -
|
2016-05-18 23:07:54 +03:00
|
|
|
scrollbars.IStartEnd(wm));
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput->AvailableISize() -= scrollbars.IStartEnd(wm);
|
|
|
|
aReflowInput->SetComputedBSizeWithoutResettingResizeFlags(
|
|
|
|
aReflowInput->ComputedBSize() - scrollbars.BStartEnd(wm));
|
2016-05-18 23:07:54 +03:00
|
|
|
return nsPoint(scrollbars.Left(wm), scrollbars.Top(wm));
|
1999-02-03 20:01:51 +03:00
|
|
|
}
|
2004-01-09 22:21:20 +03:00
|
|
|
return nsPoint(0, 0);
|
1999-02-03 20:01:51 +03:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRect ViewportFrame::AdjustReflowInputAsContainingBlock(
|
|
|
|
ReflowInput* aReflowInput) const {
|
2013-04-24 20:17:55 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsPoint offset =
|
|
|
|
#endif
|
2016-07-21 13:36:39 +03:00
|
|
|
AdjustReflowInputForScrollbars(aReflowInput);
|
2013-04-24 20:17:55 +04:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2018-07-20 21:40:51 +03:00
|
|
|
nsRect rect(0, 0, aReflowInput->ComputedWidth(),
|
|
|
|
aReflowInput->ComputedHeight());
|
2019-09-05 04:15:05 +03:00
|
|
|
|
|
|
|
rect.SizeTo(AdjustViewportSizeForFixedPosition(rect));
|
|
|
|
|
2018-07-20 21:40:51 +03:00
|
|
|
return rect;
|
2013-04-24 20:17:55 +04:00
|
|
|
}
|
|
|
|
|
2008-10-30 03:41:56 +03:00
|
|
|
void ViewportFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
1999-01-26 03:05:21 +03:00
|
|
|
nsReflowStatus& aStatus) {
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("ViewportFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_IN("ViewportFrame::Reflow");
|
|
|
|
|
2015-06-18 09:33:50 +03:00
|
|
|
// Because |Reflow| sets ComputedBSize() on the child to our
|
|
|
|
// ComputedBSize().
|
|
|
|
AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
|
2010-08-06 01:59:36 +04: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.
|
2016-07-21 13:36:39 +03:00
|
|
|
SetSize(nsSize(aReflowInput.ComputedWidth(), aReflowInput.ComputedHeight()));
|
2014-09-23 17:44:00 +04:00
|
|
|
|
2003-02-22 23:13:12 +03: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 12:30:07 +04:00
|
|
|
nscoord kidBSize = 0;
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
1999-07-04 08:09:54 +04:00
|
|
|
|
2002-05-10 22:22:41 +04:00
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
// Deal with a non-incremental reflow or an incremental reflow
|
|
|
|
// targeted at our one-and-only principal child frame.
|
2020-07-31 20:37:20 +03:00
|
|
|
if (aReflowInput.ShouldReflowAllKids() ||
|
2020-07-09 21:29:15 +03:00
|
|
|
mFrames.FirstChild()->IsSubtreeDirty()) {
|
2002-05-10 22:22:41 +04:00
|
|
|
// Reflow our one-and-only principal child frame
|
|
|
|
nsIFrame* kidFrame = mFrames.FirstChild();
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput kidDesiredSize(aReflowInput);
|
2020-10-28 23:42:26 +03:00
|
|
|
const WritingMode kidWM = kidFrame->GetWritingMode();
|
|
|
|
LogicalSize availableSpace = aReflowInput.AvailableSize(kidWM);
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput kidReflowInput(aPresContext, aReflowInput, kidFrame,
|
2002-05-10 22:22:41 +04:00
|
|
|
availableSpace);
|
|
|
|
|
|
|
|
// Reflow the frame
|
2016-07-21 13:36:39 +03:00
|
|
|
kidReflowInput.SetComputedBSize(aReflowInput.ComputedBSize());
|
|
|
|
ReflowChild(kidFrame, aPresContext, kidDesiredSize, kidReflowInput, 0, 0,
|
2019-08-08 22:48:19 +03:00
|
|
|
ReflowChildFlags::Default, aStatus);
|
2014-07-24 12:30:07 +04:00
|
|
|
kidBSize = kidDesiredSize.BSize(wm);
|
2002-05-10 22:22:41 +04:00
|
|
|
|
Bug 1547759 - Pass ReflowInput to FinishReflowChild in almost all cases. r=jfkthame
At first glance, it might look like this would change behavior, since
FinishReflowChild passes aReflowInput to DidReflow, which in turn
notifies aReflowInput's mPercentBSizeObserver. However, if you examine
how the mPercentBSizeObserver is propagated, it can only be set for the
anonymous block wrapping the children of table cells, the children of
table cells, or additionally a child of a table wrapper frame that has
it set (i.e., a table or its caption, when logically a child of a table
cell). Since all of the frames for which this is being changed are
either internal table elements that are inside of the table, or are
things that can never be a descendant of a table at all, there should be
no change in behavior.
Differential Revision: https://phabricator.services.mozilla.com/D40565
--HG--
extra : moz-landing-system : lando
2019-08-05 14:52:19 +03:00
|
|
|
FinishReflowChild(kidFrame, aPresContext, kidDesiredSize, &kidReflowInput,
|
|
|
|
0, 0, ReflowChildFlags::Default);
|
2008-03-13 01:04:45 +03:00
|
|
|
} else {
|
2014-07-24 12:30:07 +04:00
|
|
|
kidBSize = LogicalSize(wm, mFrames.FirstChild()->GetSize()).BSize(wm);
|
2002-05-10 22:22:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_ASSERTION(aReflowInput.AvailableISize() != NS_UNCONSTRAINEDSIZE,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
"shouldn't happen anymore");
|
|
|
|
|
|
|
|
// Return the max size as our desired size
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize maxSize(wm, aReflowInput.AvailableISize(),
|
2014-07-24 12:30:07 +04:00
|
|
|
// Being flowed initially at an unconstrained block size
|
|
|
|
// means we should return our child's intrinsic size.
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.ComputedBSize() != NS_UNCONSTRAINEDSIZE
|
|
|
|
? aReflowInput.ComputedBSize()
|
2014-07-24 12:30:07 +04:00
|
|
|
: kidBSize);
|
|
|
|
aDesiredSize.SetSize(wm, maxSize);
|
2011-12-05 16:39:14 +04:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2015-01-06 12:27:56 +03:00
|
|
|
if (HasAbsolutelyPositionedChildren()) {
|
2019-04-11 23:27:37 +03:00
|
|
|
// Make a copy of the reflow input and change the computed width and height
|
2012-10-23 05:48:12 +04:00
|
|
|
// to reflect the available space for the fixed items
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput reflowInput(aReflowInput);
|
2012-10-23 05:48:12 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
if (reflowInput.AvailableBSize() == NS_UNCONSTRAINEDSIZE) {
|
2012-10-23 05:48:12 +04:00
|
|
|
// We have an intrinsic-height document with abs-pos/fixed-pos children.
|
|
|
|
// Set the available height and mComputedHeight to our chosen height.
|
2016-07-21 13:36:39 +03:00
|
|
|
reflowInput.AvailableBSize() = maxSize.BSize(wm);
|
2012-10-23 05:48:12 +04:00
|
|
|
// Not having border/padding simplifies things
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
reflowInput.ComputedPhysicalBorderPadding() == nsMargin(0, 0, 0, 0),
|
2012-10-23 05:48:12 +04:00
|
|
|
"Viewports can't have border/padding");
|
2016-07-21 13:36:39 +03:00
|
|
|
reflowInput.SetComputedBSize(maxSize.BSize(wm));
|
2012-10-23 05:48:12 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsRect rect = AdjustReflowInputAsContainingBlock(&reflowInput);
|
2015-12-23 01:03:16 +03:00
|
|
|
AbsPosReflowFlags flags =
|
2019-04-26 02:03:04 +03:00
|
|
|
AbsPosReflowFlags::CBWidthAndHeightChanged; // XXX could be optimized
|
2018-11-21 23:06:15 +03:00
|
|
|
GetAbsoluteContainingBlock()->Reflow(this, aPresContext, reflowInput,
|
|
|
|
aStatus, rect, flags,
|
|
|
|
/* aOverflowAreas = */ nullptr);
|
2014-09-23 17:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, mFrames.FirstChild());
|
2011-04-30 03:02:33 +04:00
|
|
|
}
|
2003-02-22 23:13:12 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// If we were dirty then do a repaint
|
2020-06-27 17:09:45 +03:00
|
|
|
if (HasAnyStateBits(NS_FRAME_IS_DIRTY)) {
|
2012-08-29 09:39:31 +04:00
|
|
|
InvalidateFrame();
|
1999-07-24 19:18:24 +04:00
|
|
|
}
|
|
|
|
|
2011-12-05 16:38:46 +04:00
|
|
|
// Clipping is handled by the document container (e.g., nsSubDocumentFrame),
|
|
|
|
// so we don't need to change our overflow areas.
|
2018-11-21 23:06:15 +03:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2007-01-25 05:01:07 +03:00
|
|
|
|
1999-01-26 03:05:21 +03:00
|
|
|
NS_FRAME_TRACE_REFLOW_OUT("ViewportFrame::Reflow", aStatus);
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
1999-01-26 03:05:21 +03:00
|
|
|
}
|
|
|
|
|
2017-06-21 00:21:27 +03:00
|
|
|
void ViewportFrame::UpdateStyle(ServoRestyleState& aRestyleState) {
|
2018-03-25 13:23:00 +03:00
|
|
|
RefPtr<ComputedStyle> newStyle =
|
2019-02-19 16:44:33 +03:00
|
|
|
aRestyleState.StyleSet().ResolveInheritingAnonymousBoxStyle(
|
|
|
|
Style()->GetPseudoType(), nullptr);
|
2017-06-21 18:45:12 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!GetNextContinuation(), "Viewport has continuations?");
|
2018-03-25 13:23:00 +03:00
|
|
|
SetComputedStyle(newStyle);
|
2017-06-21 18:45:12 +03:00
|
|
|
|
2017-06-21 00:21:27 +03:00
|
|
|
UpdateStyleOfOwnedAnonBoxes(aRestyleState);
|
2017-06-21 18:45:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewportFrame::AppendDirectlyOwnedAnonBoxes(
|
|
|
|
nsTArray<OwnedAnonBox>& aResult) {
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
aResult.AppendElement(mFrames.FirstChild());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 04:15:05 +03:00
|
|
|
nsSize ViewportFrame::AdjustViewportSizeForFixedPosition(
|
|
|
|
const nsRect& aViewportRect) const {
|
|
|
|
nsSize result = aViewportRect.Size();
|
|
|
|
|
|
|
|
mozilla::PresShell* presShell = PresShell();
|
|
|
|
// Layout fixed position elements to the visual viewport size if and only if
|
|
|
|
// it has been set and it is larger than the computed size, otherwise use the
|
|
|
|
// computed size.
|
2019-11-22 00:36:59 +03:00
|
|
|
if (presShell->IsVisualViewportSizeSet()) {
|
|
|
|
if (presShell->GetDynamicToolbarState() == DynamicToolbarState::Collapsed &&
|
|
|
|
result < presShell->GetVisualViewportSizeUpdatedByDynamicToolbar()) {
|
|
|
|
// We need to use the viewport size updated by the dynamic toolbar in the
|
|
|
|
// case where the dynamic toolbar is completely hidden.
|
|
|
|
result = presShell->GetVisualViewportSizeUpdatedByDynamicToolbar();
|
|
|
|
} else if (result < presShell->GetVisualViewportSize()) {
|
|
|
|
result = presShell->GetVisualViewportSize();
|
|
|
|
}
|
2019-09-05 04:15:05 +03:00
|
|
|
}
|
|
|
|
// Expand the size to the layout viewport size if necessary.
|
|
|
|
const nsSize layoutViewportSize = presShell->GetLayoutViewportSize();
|
|
|
|
if (result < layoutViewportSize) {
|
|
|
|
result = layoutViewportSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsresult ViewportFrame::GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(u"Viewport"_ns, aResult);
|
1999-01-26 03:05:21 +03:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|