Skip to content

Commit

Permalink
Move enums under WebCore/rendering/ to use the serializer
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264623

Reviewed by Chris Dumez.

This patch covers the enums in Pagination.h (WebCore::PaginationMode) and
in RenderObject.h (WebCore::RepaintRectCalculation).

The patch mostly just adds the necessary scopes given that the enums now
are enum classes. The only exception is the EnumeratedArray in the
rendering/svg/legacy/ headers, which needed an extra argument, the last
value in the enum; without it EnumeratedArray tries to call
EnumTraits<Key>::values::max> and fails

* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::paginationModeForRenderStyle):
* Source/WebCore/page/Page.cpp:
(WebCore::Page::pageCount const):
(WebCore::Page::pageCountAssumingLayoutIsUpToDate const):
* Source/WebCore/rendering/Pagination.h:
* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::checkForPaginationLogicalHeightChange):
* Source/WebCore/rendering/RenderObject.h:
* Source/WebCore/rendering/RenderView.cpp:
(WebCore::RenderView::styleDidChange):
(WebCore::RenderView::requiresColumns const):
(WebCore::RenderView::paint):
(WebCore::RenderView::pageNumberForBlockProgressionOffset const):
(WebCore::RenderView::pageCount const):
* Source/WebCore/rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::setColumnStylesFromPaginationMode):
* Source/WebCore/rendering/style/RenderStyle.h:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGForeignObject.cpp:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResource.h:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResourceClipper.h:
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGResourceMasker.h:
* Source/WebCore/style/StyleResolveForDocument.cpp:
(WebCore::Style::resolveForDocument):
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::setPagination):
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/C/WKPage.cpp:
(WKPageSetPaginationMode):
(WKPageGetPaginationMode):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setPaginationMode):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:

Canonical link: https://commits.webkit.org/270613@main
  • Loading branch information
mikhailramalho committed Nov 12, 2023
1 parent 723ded3 commit d53d6d2
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 106 deletions.
10 changes: 5 additions & 5 deletions Source/WebCore/page/LocalFrameView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Pagination::Mode paginationModeForRenderStyle(const RenderStyle& style)
{
auto overflow = style.overflowY();
if (overflow != Overflow::PagedX && overflow != Overflow::PagedY)
return Unpaginated;
return Pagination::Mode::Unpaginated;

bool isHorizontalWritingMode = style.isHorizontalWritingMode();
auto textDirection = style.direction();
Expand All @@ -179,16 +179,16 @@ Pagination::Mode paginationModeForRenderStyle(const RenderStyle& style)
// is vertical, then the block flow direction dictates the choice.
if (overflow == Overflow::PagedX) {
if ((isHorizontalWritingMode && textDirection == TextDirection::LTR) || blockFlowDirection == BlockFlowDirection::LeftToRight)
return LeftToRightPaginated;
return RightToLeftPaginated;
return Pagination::Mode::LeftToRightPaginated;
return Pagination::Mode::RightToLeftPaginated;
}

// paged-y always corresponds to TopToBottomPaginated or BottomToTopPaginated. If the WritingMode
// is horizontal, then the block flow direction dictates the choice. If the WritingMode
// is vertical, then we use TextDirection to choose between those options.
if (blockFlowDirection == BlockFlowDirection::TopToBottom || (!isHorizontalWritingMode && textDirection == TextDirection::RTL))
return TopToBottomPaginated;
return BottomToTopPaginated;
return Pagination::Mode::TopToBottomPaginated;
return Pagination::Mode::BottomToTopPaginated;
}

LocalFrameView::LocalFrameView(LocalFrame& frame)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ void Page::setPagination(const Pagination& pagination)

unsigned Page::pageCount() const
{
if (m_pagination.mode == Unpaginated)
if (m_pagination.mode == Pagination::Mode::Unpaginated)
return 0;

auto* localMainFrame = dynamicDowncast<LocalFrame>(mainFrame());
Expand All @@ -1655,7 +1655,7 @@ unsigned Page::pageCount() const

unsigned Page::pageCountAssumingLayoutIsUpToDate() const
{
if (m_pagination.mode == Unpaginated)
if (m_pagination.mode == Pagination::Mode::Unpaginated)
return 0;

auto* localMainFrame = dynamicDowncast<LocalFrame>(mainFrame());
Expand Down
21 changes: 2 additions & 19 deletions Source/WebCore/rendering/Pagination.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,19 @@

#pragma once

#include <wtf/EnumTraits.h>

namespace WebCore {

enum PaginationMode : uint8_t { Unpaginated, LeftToRightPaginated, RightToLeftPaginated, TopToBottomPaginated, BottomToTopPaginated };
enum class PaginationMode : uint8_t { Unpaginated, LeftToRightPaginated, RightToLeftPaginated, TopToBottomPaginated, BottomToTopPaginated };

struct Pagination {
using Mode = PaginationMode;

friend bool operator==(const Pagination&, const Pagination&) = default;

Mode mode { Unpaginated };
Mode mode { Pagination::Mode::Unpaginated };
bool behavesLikeColumns { false };
unsigned pageLength { 0 };
unsigned gap { 0 };
};

} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::Pagination::Mode> {
using values = EnumValues<
WebCore::Pagination::Mode,
WebCore::Pagination::Mode::Unpaginated,
WebCore::Pagination::Mode::LeftToRightPaginated,
WebCore::Pagination::Mode::RightToLeftPaginated,
WebCore::Pagination::Mode::TopToBottomPaginated,
WebCore::Pagination::Mode::BottomToTopPaginated
>;
};

} // namespace WTF
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderBlockFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4258,7 +4258,7 @@ void RenderBlockFlow::checkForPaginationLogicalHeightChange(bool& relayoutChildr
// We don't actually update any of the variables. We just subclassed to adjust our column height.
if (RenderMultiColumnFlow* fragmentedFlow = multiColumnFlow()) {
LayoutUnit newColumnHeight;
if (hasDefiniteLogicalHeight() || view().frameView().pagination().mode != Unpaginated) {
if (hasDefiniteLogicalHeight() || view().frameView().pagination().mode != Pagination::Mode::Unpaginated) {
auto computedValues = computeLogicalHeight(0_lu, logicalTop());
newColumnHeight = std::max<LayoutUnit>(computedValues.m_extent - borderAndPaddingLogicalHeight() - scrollbarLogicalHeight(), 0);
if (fragmentedFlow->columnHeightAvailable() != newColumnHeight)
Expand Down
14 changes: 1 addition & 13 deletions Source/WebCore/rendering/RenderObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace Style {
class PseudoElementRequest;
}

enum class RepaintRectCalculation { Fast, Accurate };
enum class RepaintRectCalculation : bool { Fast, Accurate };

// Base class for all rendering tree objects.
class RenderObject : public CachedImageClient, public CanMakeCheckedPtr {
Expand Down Expand Up @@ -1446,15 +1446,3 @@ void showNodeTree(const WebCore::RenderObject*);
void showLineTree(const WebCore::RenderObject*);
void showRenderTree(const WebCore::RenderObject*);
#endif

namespace WTF {

template<> struct EnumTraits<WebCore::RepaintRectCalculation> {
using values = EnumValues<
WebCore::RepaintRectCalculation,
WebCore::RepaintRectCalculation::Fast,
WebCore::RepaintRectCalculation::Accurate
>;
};

} // namespace WTF
10 changes: 5 additions & 5 deletions Source/WebCore/rendering/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void RenderView::styleDidChange(StyleDifference diff, const RenderStyle* oldStyl
bool directionChanged = oldStyle && style().direction() != oldStyle->direction();

if ((writingModeChanged || directionChanged) && multiColumnFlow()) {
if (frameView().pagination().mode != Unpaginated)
if (frameView().pagination().mode != Pagination::Mode::Unpaginated)
updateColumnProgressionFromStyle(style());
updateStylesForColumnChildren(oldStyle);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ void RenderView::mapAbsoluteToLocalPoint(OptionSet<MapCoordinatesMode> mode, Tra

bool RenderView::requiresColumns(int) const
{
return frameView().pagination().mode != Unpaginated;
return frameView().pagination().mode != Pagination::Mode::Unpaginated;
}

void RenderView::computeColumnCountAndWidth()
Expand All @@ -362,7 +362,7 @@ void RenderView::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
ASSERT(LayoutPoint(IntPoint(paintOffset.x(), paintOffset.y())) == paintOffset);

// This avoids painting garbage between columns if there is a column gap.
if (frameView().pagination().mode != Unpaginated && paintInfo.shouldPaintWithinRoot(*this))
if (frameView().pagination().mode != Pagination::Mode::Unpaginated && paintInfo.shouldPaintWithinRoot(*this))
paintInfo.context().fillRect(paintInfo.rect, frameView().baseBackgroundColor());

paintObject(paintInfo, paintOffset);
Expand Down Expand Up @@ -1056,7 +1056,7 @@ unsigned RenderView::pageNumberForBlockProgressionOffset(int offset) const
{
int columnNumber = 0;
const Pagination& pagination = page().pagination();
if (pagination.mode == Unpaginated)
if (pagination.mode == Pagination::Mode::Unpaginated)
return columnNumber;

bool progressionIsInline = false;
Expand All @@ -1081,7 +1081,7 @@ unsigned RenderView::pageNumberForBlockProgressionOffset(int offset) const
unsigned RenderView::pageCount() const
{
const Pagination& pagination = page().pagination();
if (pagination.mode == Unpaginated)
if (pagination.mode == Pagination::Mode::Unpaginated)
return 0;

if (multiColumnFlow() && multiColumnFlow()->firstMultiColumnSet())
Expand Down
12 changes: 6 additions & 6 deletions Source/WebCore/rendering/style/RenderStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3464,41 +3464,41 @@ void RenderStyle::setBorderImageVerticalRule(NinePieceImageRule rule)

void RenderStyle::setColumnStylesFromPaginationMode(PaginationMode paginationMode)
{
if (paginationMode == Unpaginated)
if (paginationMode == Pagination::Mode::Unpaginated)
return;

setColumnFill(ColumnFill::Auto);

switch (paginationMode) {
case LeftToRightPaginated:
case Pagination::Mode::LeftToRightPaginated:
setColumnAxis(ColumnAxis::Horizontal);
if (isHorizontalWritingMode())
setColumnProgression(isLeftToRightDirection() ? ColumnProgression::Normal : ColumnProgression::Reverse);
else
setColumnProgression(isFlippedBlocksWritingMode() ? ColumnProgression::Reverse : ColumnProgression::Normal);
break;
case RightToLeftPaginated:
case Pagination::Mode::RightToLeftPaginated:
setColumnAxis(ColumnAxis::Horizontal);
if (isHorizontalWritingMode())
setColumnProgression(isLeftToRightDirection() ? ColumnProgression::Reverse : ColumnProgression::Normal);
else
setColumnProgression(isFlippedBlocksWritingMode() ? ColumnProgression::Normal : ColumnProgression::Reverse);
break;
case TopToBottomPaginated:
case Pagination::Mode::TopToBottomPaginated:
setColumnAxis(ColumnAxis::Vertical);
if (isHorizontalWritingMode())
setColumnProgression(isFlippedBlocksWritingMode() ? ColumnProgression::Reverse : ColumnProgression::Normal);
else
setColumnProgression(isLeftToRightDirection() ? ColumnProgression::Normal : ColumnProgression::Reverse);
break;
case BottomToTopPaginated:
case Pagination::Mode::BottomToTopPaginated:
setColumnAxis(ColumnAxis::Vertical);
if (isHorizontalWritingMode())
setColumnProgression(isFlippedBlocksWritingMode() ? ColumnProgression::Normal : ColumnProgression::Reverse);
else
setColumnProgression(isLeftToRightDirection() ? ColumnProgression::Reverse : ColumnProgression::Normal);
break;
case Unpaginated:
case Pagination::Mode::Unpaginated:
ASSERT_NOT_REACHED();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/style/RenderStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WillChangeData;
enum CSSPropertyID : uint16_t;
enum GridAutoFlow : uint8_t;
enum PageSizeType : uint8_t;
enum PaginationMode : uint8_t;
enum class PaginationMode : uint8_t;

enum class ApplePayButtonStyle : uint8_t;
enum class ApplePayButtonType : uint8_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "LayoutRepainter.h"
#include "LegacyRenderSVGResource.h"
#include "RenderBoxModelObjectInlines.h"
#include "RenderObject.h"
#include "RenderSVGBlockInlines.h"
#include "RenderView.h"
#include "SVGElementTypeHelpers.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum class RenderSVGResourceMode {
ApplyToText = 1 << 2 // used in combination with ApplyTo{Fill|Stroke}Mode
};

enum class RepaintRectCalculation;
enum class RepaintRectCalculation : bool;

class Color;
class FloatRect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LegacyRenderSVGResourceClipper final : public LegacyRenderSVGResourceConta
bool drawContentIntoMaskImage(ImageBuffer&, const FloatRect& objectBoundingBox, float effectiveZoom);
void calculateClipContentRepaintRect(RepaintRectCalculation);

EnumeratedArray<RepaintRectCalculation, FloatRect> m_clipBoundaries;
EnumeratedArray<RepaintRectCalculation, FloatRect, RepaintRectCalculation::Accurate> m_clipBoundaries;
HashMap<const RenderObject*, std::unique_ptr<ClipperData>> m_clipperMap;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LegacyRenderSVGResourceMasker final : public LegacyRenderSVGResourceContai
bool drawContentIntoMaskImage(MaskerData*, const DestinationColorSpace&, RenderObject*);
void calculateMaskContentRepaintRect(RepaintRectCalculation);

EnumeratedArray<RepaintRectCalculation, FloatRect> m_maskContentBoundaries;
EnumeratedArray<RepaintRectCalculation, FloatRect, RepaintRectCalculation::Accurate> m_maskContentBoundaries;
HashMap<RenderObject*, std::unique_ptr<MaskerData>> m_masker;
};

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/style/StyleResolveForDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ RenderStyle resolveForDocument(const Document& document)
Adjuster::adjustEventListenerRegionTypesForRootStyle(documentStyle, document);

const Pagination& pagination = renderView.frameView().pagination();
if (pagination.mode != Unpaginated) {
if (pagination.mode != Pagination::Mode::Unpaginated) {
documentStyle.setColumnStylesFromPaginationMode(pagination.mode);
documentStyle.setColumnGap(GapLength(Length((int) pagination.gap, LengthType::Fixed)));
if (renderView.multiColumnFlow())
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/testing/Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,15 +2162,15 @@ ExceptionOr<void> Internals::setPagination(const String& mode, int gap, int page

Pagination pagination;
if (mode == "Unpaginated"_s)
pagination.mode = Unpaginated;
pagination.mode = Pagination::Mode::Unpaginated;
else if (mode == "LeftToRightPaginated"_s)
pagination.mode = LeftToRightPaginated;
pagination.mode = Pagination::Mode::LeftToRightPaginated;
else if (mode == "RightToLeftPaginated"_s)
pagination.mode = RightToLeftPaginated;
pagination.mode = Pagination::Mode::RightToLeftPaginated;
else if (mode == "TopToBottomPaginated"_s)
pagination.mode = TopToBottomPaginated;
pagination.mode = Pagination::Mode::TopToBottomPaginated;
else if (mode == "BottomToTopPaginated"_s)
pagination.mode = BottomToTopPaginated;
pagination.mode = Pagination::Mode::BottomToTopPaginated;
else
return Exception { ExceptionCode::SyntaxError };

Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Original file line number Diff line number Diff line change
Expand Up @@ -6696,3 +6696,14 @@ enum class WebCore::CredentialPersistence : uint8_t {
ForSession,
Permanent,
}
header: <WebCore/Pagination.h>
enum class WebCore::PaginationMode : uint8_t {
Unpaginated,
LeftToRightPaginated,
RightToLeftPaginated,
TopToBottomPaginated,
BottomToTopPaginated
};

header: <WebCore/RenderObject.h>
enum class WebCore::RepaintRectCalculation : bool;
20 changes: 10 additions & 10 deletions Source/WebKit/UIProcess/API/C/WKPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,19 +815,19 @@ void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
WebCore::Pagination::Mode mode;
switch (paginationMode) {
case kWKPaginationModeUnpaginated:
mode = WebCore::Unpaginated;
mode = WebCore::Pagination::Mode::Unpaginated;
break;
case kWKPaginationModeLeftToRight:
mode = WebCore::LeftToRightPaginated;
mode = WebCore::Pagination::Mode::LeftToRightPaginated;
break;
case kWKPaginationModeRightToLeft:
mode = WebCore::RightToLeftPaginated;
mode = WebCore::Pagination::Mode::RightToLeftPaginated;
break;
case kWKPaginationModeTopToBottom:
mode = WebCore::TopToBottomPaginated;
mode = WebCore::Pagination::Mode::TopToBottomPaginated;
break;
case kWKPaginationModeBottomToTop:
mode = WebCore::BottomToTopPaginated;
mode = WebCore::Pagination::Mode::BottomToTopPaginated;
break;
default:
return;
Expand All @@ -838,15 +838,15 @@ void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode)
WKPaginationMode WKPageGetPaginationMode(WKPageRef pageRef)
{
switch (toImpl(pageRef)->paginationMode()) {
case WebCore::Unpaginated:
case WebCore::Pagination::Mode::Unpaginated:
return kWKPaginationModeUnpaginated;
case WebCore::LeftToRightPaginated:
case WebCore::Pagination::Mode::LeftToRightPaginated:
return kWKPaginationModeLeftToRight;
case WebCore::RightToLeftPaginated:
case WebCore::Pagination::Mode::RightToLeftPaginated:
return kWKPaginationModeRightToLeft;
case WebCore::TopToBottomPaginated:
case WebCore::Pagination::Mode::TopToBottomPaginated:
return kWKPaginationModeTopToBottom;
case WebCore::BottomToTopPaginated:
case WebCore::Pagination::Mode::BottomToTopPaginated:
return kWKPaginationModeBottomToTop;
}

Expand Down
20 changes: 10 additions & 10 deletions Source/WebKit/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,19 @@ - (void)setPaginationMode:(WKBrowsingContextPaginationMode)paginationMode
WebCore::Pagination::Mode mode;
switch (paginationMode) {
case WKPaginationModeUnpaginated:
mode = WebCore::Unpaginated;
mode = WebCore::PaginationMode::Unpaginated;
break;
case WKPaginationModeLeftToRight:
mode = WebCore::LeftToRightPaginated;
mode = WebCore::PaginationMode::LeftToRightPaginated;
break;
case WKPaginationModeRightToLeft:
mode = WebCore::RightToLeftPaginated;
mode = WebCore::PaginationMode::RightToLeftPaginated;
break;
case WKPaginationModeTopToBottom:
mode = WebCore::TopToBottomPaginated;
mode = WebCore::PaginationMode::TopToBottomPaginated;
break;
case WKPaginationModeBottomToTop:
mode = WebCore::BottomToTopPaginated;
mode = WebCore::PaginationMode::BottomToTopPaginated;
break;
default:
return;
Expand All @@ -678,15 +678,15 @@ - (void)setPaginationMode:(WKBrowsingContextPaginationMode)paginationMode
- (WKBrowsingContextPaginationMode)paginationMode
{
switch (_page->paginationMode()) {
case WebCore::Unpaginated:
case WebCore::PaginationMode::Unpaginated:
return WKPaginationModeUnpaginated;
case WebCore::LeftToRightPaginated:
case WebCore::PaginationMode::LeftToRightPaginated:
return WKPaginationModeLeftToRight;
case WebCore::RightToLeftPaginated:
case WebCore::PaginationMode::RightToLeftPaginated:
return WKPaginationModeRightToLeft;
case WebCore::TopToBottomPaginated:
case WebCore::PaginationMode::TopToBottomPaginated:
return WKPaginationModeTopToBottom;
case WebCore::BottomToTopPaginated:
case WebCore::PaginationMode::BottomToTopPaginated:
return WKPaginationModeBottomToTop;
}

Expand Down
Loading

0 comments on commit d53d6d2

Please sign in to comment.