Skip to content

Commit

Permalink
[LFC][IFC] Introduce BlockLayoutState
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=247780

Reviewed by Antti Koivisto.

In many cases child IFCs need to know about parent block level layout state. E.g how many lines the block still needs across sibling IFCs
when line-clamp is present, or where the intrusive, BFC level floats are.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/layout/formattingContexts/block/BlockLayoutState.h: Added.
(WebCore::Layout::BlockLayoutState::lineClamp const):
(WebCore::Layout::BlockLayoutState::setLineClamp):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.h:
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::layout):

Canonical link: https://commits.webkit.org/256570@main
  • Loading branch information
alanbaradlay committed Nov 11, 2022
1 parent 917d04b commit 1017863
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -4892,6 +4892,7 @@
DD17C084286EC57A00D60B58 /* web in Copy PDF.js */ = {isa = PBXBuildFile; fileRef = DD17C07E286EC51A00D60B58 /* web */; };
DD763BB20992C2C900740B8E /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DD763BB10992C2C900740B8E /* libxml2.dylib */; };
DD7CDF250A23CF9800069928 /* CSSUnknownRule.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E6CCE0A1989CA007FB8C5 /* CSSUnknownRule.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD8A30B4291DFC8F00AD537C /* BlockLayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = DD8A30B3291DFC8F00AD537C /* BlockLayoutState.h */; settings = {ATTRIBUTES = (Private, ); }; };
DDB04F3A278E5539008D3678 /* libWTF.a in Product Dependencies */ = {isa = PBXBuildFile; fileRef = DDB04F39278E5531008D3678 /* libWTF.a */; };
DDDFE83E2846ECE2006F1EE5 /* cocoa in Copy PDF.js Extras */ = {isa = PBXBuildFile; fileRef = DDDFE83B2846ECD3006F1EE5 /* cocoa */; };
DDDFE83F2846ECE5006F1EE5 /* content-script.js in Copy PDF.js Extras */ = {isa = PBXBuildFile; fileRef = DDDFE83C2846ECD4006F1EE5 /* content-script.js */; };
Expand Down Expand Up @@ -17117,6 +17118,7 @@
DD17C07E286EC51A00D60B58 /* web */ = {isa = PBXFileReference; lastKnownFileType = folder; name = web; path = ../../ThirdParty/pdfjs/web; sourceTree = "<group>"; };
DD17C080286EC51B00D60B58 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; name = LICENSE; path = ../../ThirdParty/pdfjs/LICENSE; sourceTree = "<group>"; };
DD763BB10992C2C900740B8E /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = /usr/lib/libxml2.dylib; sourceTree = "<absolute>"; };
DD8A30B3291DFC8F00AD537C /* BlockLayoutState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockLayoutState.h; sourceTree = "<group>"; };
DDB04F37278E5527008D3678 /* libWTF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
DDB04F39278E5531008D3678 /* libWTF.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
DDDFE83A2846ECD3006F1EE5 /* adwaita */ = {isa = PBXFileReference; lastKnownFileType = folder; path = adwaita; sourceTree = "<group>"; };
Expand Down Expand Up @@ -20002,6 +20004,7 @@
115CFA78208B8D9D001E6991 /* BlockFormattingState.h */,
115CFA89208B921A001E6991 /* BlockMarginCollapse.cpp */,
6F6DF36E264722EA0093E834 /* BlockMarginCollapse.h */,
DD8A30B3291DFC8F00AD537C /* BlockLayoutState.h */,
6FAE16BA2406DE7E00A48414 /* PrecomputedBlockMarginCollapse.cpp */,
);
path = block;
Expand Down Expand Up @@ -37317,6 +37320,7 @@
9493B6C11D74B4120088E780 /* LegacyMediaQueryParser.h in Headers */,
F44A5F591FED38F2007F5944 /* LegacyNSPasteboardTypes.h in Headers */,
A185B42A1E8211A100DC9118 /* LegacyPreviewLoader.h in Headers */,
DD8A30B4291DFC8F00AD537C /* BlockLayoutState.h in Headers */,
A10DBF4718F92317000D70C6 /* LegacyPreviewLoaderClient.h in Headers */,
436708C312D9CA4B00044234 /* LegacyRenderSVGContainer.h in Headers */,
2B365C841525119E0091D27B /* LegacyRenderSVGEllipse.h in Headers */,
Expand Down
52 changes: 52 additions & 0 deletions Source/WebCore/layout/formattingContexts/block/BlockLayoutState.h
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

namespace WebCore {
namespace Layout {

class BlockFormattingContext;

// This class holds block level information shared across child inline formatting contexts.
class BlockLayoutState {
public:
struct LineClamp {
size_t m_maximumNumberOfLines { 0 };
size_t m_numberOfVisibleLines { 0 };
};
std::optional<LineClamp> lineClamp() const { return m_lineClamp; }

// FIXME: Move FloatingState here.
private:
friend BlockFormattingContext;

void setLineClamp(LineClamp lineClamp) { m_lineClamp = lineClamp; }

std::optional<LineClamp> m_lineClamp;
};

}
}
Expand Up @@ -26,6 +26,7 @@
#include "config.h"
#include "InlineFormattingContext.h"

#include "BlockLayoutState.h"
#include "FloatingContext.h"
#include "FontCascade.h"
#include "InlineDamage.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ void InlineFormattingContext::layoutInFlowContent(const ConstraintsForInFlowCont
LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
}

void InlineFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
void InlineFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints, const BlockLayoutState&)
{
invalidateFormattingState();
collectContentIfNeeded();
Expand Down
Expand Up @@ -36,6 +36,7 @@
namespace WebCore {
namespace Layout {

class BlockLayoutState;
class InlineDamage;
class InlineFormattingState;
class LineBox;
Expand All @@ -56,7 +57,7 @@ class InlineFormattingContext final : public FormattingContext {
const InlineFormattingGeometry& formattingGeometry() const final { return m_inlineFormattingGeometry; }
const InlineFormattingQuirks& formattingQuirks() const final { return m_inlineFormattingQuirks; }

void layoutInFlowContentForIntegration(const ConstraintsForInFlowContent&);
void layoutInFlowContentForIntegration(const ConstraintsForInFlowContent&, const BlockLayoutState&);
IntrinsicWidthConstraints computedIntrinsicWidthConstraintsForIntegration();

private:
Expand Down
Expand Up @@ -26,6 +26,7 @@
#include "config.h"
#include "LayoutIntegrationLineLayout.h"

#include "BlockLayoutState.h"
#include "DeprecatedGlobalSettings.h"
#include "EventRegion.h"
#include "FloatingState.h"
Expand Down Expand Up @@ -439,7 +440,7 @@ void LineLayout::layout()
// FIXME: Do not clear the lines and boxes here unconditionally, but consult with the damage object instead.
clearInlineContent();
ASSERT(m_inlineContentConstraints);
Layout::InlineFormattingContext { rootLayoutBox, m_inlineFormattingState, m_lineDamage.get() }.layoutInFlowContentForIntegration(*m_inlineContentConstraints);
Layout::InlineFormattingContext { rootLayoutBox, m_inlineFormattingState, m_lineDamage.get() }.layoutInFlowContentForIntegration(*m_inlineContentConstraints, { });

constructContent();

Expand Down

0 comments on commit 1017863

Please sign in to comment.