Changeset 269228 in webkit


Ignore:
Timestamp:
Oct 31, 2020 12:06:24 PM (3 years ago)
Author:
Simon Fraser
Message:

Clean up BoxSide and BorderEdge code
https://bugs.webkit.org/show_bug.cgi?id=218197

Reviewed by Sam Weinig.

Source/WebCore:

Change border-drawing functions in RenderBoxModelObject which took BorderEdge[] to
use RectEdges<BorderEdge>. In addition, make BoxSide an enum class, and remove the redundant
PhysicalBoxSide. Also make BorderEdgeFlags an OptionSet<>.

I renamed PhysicalBoxSide to BoxSide because "physical" is a loaded term (it could mean
either locally top/right/bottom/left, or refer to absolute "physical coordinates").
This allowed BoxSide to be used in RectEdges, therefore making RectEdges<BorderEdge>
the right way to represent the set of edges for a box.

An equivalent set of bit flags, BoxSideFlag, allows use in an OptionSet<>.

Use more enumeration of sides in the border painting code.

  • page/IntersectionObserver.cpp:

(WebCore::IntersectionObserver::rootMargin const):

  • platform/RectEdges.h:

(WebCore::RectEdges::at):
(WebCore::RectEdges::top):
(WebCore::RectEdges::right):
(WebCore::RectEdges::bottom):
(WebCore::RectEdges::left):
(WebCore::RectEdges::at const):
(WebCore::RectEdges::top const):
(WebCore::RectEdges::right const):
(WebCore::RectEdges::bottom const):
(WebCore::RectEdges::left const):
(WebCore::RectEdges::setAt):
(WebCore::RectEdges::setTop):
(WebCore::RectEdges::setRight):
(WebCore::RectEdges::setBottom):
(WebCore::RectEdges::setLeft):

  • platform/text/WritingMode.h:

(WebCore::isHorizontalPhysicalSide):
(WebCore::mirrorPhysicalSide):
(WebCore::rotatePhysicalSide):
(WebCore::mapLogicalSideToPhysicalSide):

  • rendering/BorderEdge.cpp:

(WebCore::borderEdges):
(WebCore::BorderEdge::getBorderEdgeInfo): Deleted.

  • rendering/BorderEdge.h:

(WebCore::edgeFlagForSide):
(WebCore::includesEdge):
(WebCore::includesAdjacentEdges):

  • rendering/RenderBoxModelObject.cpp:

(WebCore::borderWillArcInnerEdge):
(WebCore::borderStyleHasUnmatchedColorsAtCorner):
(WebCore::colorsMatchAtCorner):
(WebCore::colorNeedsAntiAliasAtCorner):
(WebCore::willBeOverdrawn):
(WebCore::joinRequiresMitre):
(WebCore::calculateAdjustedInnerBorder):
(WebCore::RenderBoxModelObject::paintOneBorderSide):
(WebCore::calculateSideRect):
(WebCore::RenderBoxModelObject::paintBorderSides):
(WebCore::RenderBoxModelObject::paintTranslucentBorderSides):
(WebCore::RenderBoxModelObject::paintBorder):
(WebCore::RenderBoxModelObject::drawBoxSideFromPath):
(WebCore::RenderBoxModelObject::clipBorderSidePolygon):
(WebCore::RenderBoxModelObject::borderObscuresBackgroundEdge const):
(WebCore::RenderBoxModelObject::borderObscuresBackground const):

  • rendering/RenderBoxModelObject.h:
  • rendering/RenderElement.cpp:

(WebCore::RenderElement::drawLineForBoxSide const):
(WebCore::RenderElement::paintOutline):

  • rendering/RenderInline.cpp:

(WebCore::RenderInline::paintOutlineForLine):

  • rendering/RenderMultiColumnSet.cpp:

(WebCore::RenderMultiColumnSet::paintColumnRules):

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::calculateBorderStyleColor):

  • rendering/RenderObjectEnums.h:
  • rendering/RenderTableCell.cpp:

(WebCore::RenderTableCell::paintCollapsedBorders):

  • rendering/RenderTableSection.cpp:

(WebCore::RenderTableSection::offsetTopForRowGroupBorder):
(WebCore::RenderTableSection::paintRowGroupBorderIfRequired):
(WebCore::physicalBorderForDirection):

  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::paintMenuListButtonDecorations):

  • rendering/style/NinePieceImage.h:

(WebCore::imagePieceHorizontalSide):
(WebCore::imagePieceVerticalSide):

Source/WebKit:

  • UIProcess/ios/WKKeyboardScrollingAnimator.mm:

(boxSide):

Location:
trunk/Source
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r269227 r269228  
     12020-10-31  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Clean up BoxSide and BorderEdge code
     4        https://bugs.webkit.org/show_bug.cgi?id=218197
     5
     6        Reviewed by Sam Weinig.
     7
     8        Change border-drawing functions in RenderBoxModelObject which took BorderEdge[] to
     9        use RectEdges<BorderEdge>. In addition, make BoxSide an enum class, and remove the redundant
     10        PhysicalBoxSide. Also make BorderEdgeFlags an OptionSet<>.
     11
     12        I renamed PhysicalBoxSide to BoxSide because "physical" is a loaded term (it could mean
     13        either locally top/right/bottom/left, or refer to absolute "physical coordinates").
     14        This allowed BoxSide to be used in RectEdges, therefore making RectEdges<BorderEdge>
     15        the right way to represent the set of edges for a box.
     16       
     17        An equivalent set of bit flags, BoxSideFlag, allows use in an OptionSet<>.
     18       
     19        Use more enumeration of sides in the border painting code.
     20
     21        * page/IntersectionObserver.cpp:
     22        (WebCore::IntersectionObserver::rootMargin const):
     23        * platform/RectEdges.h:
     24        (WebCore::RectEdges::at):
     25        (WebCore::RectEdges::top):
     26        (WebCore::RectEdges::right):
     27        (WebCore::RectEdges::bottom):
     28        (WebCore::RectEdges::left):
     29        (WebCore::RectEdges::at const):
     30        (WebCore::RectEdges::top const):
     31        (WebCore::RectEdges::right const):
     32        (WebCore::RectEdges::bottom const):
     33        (WebCore::RectEdges::left const):
     34        (WebCore::RectEdges::setAt):
     35        (WebCore::RectEdges::setTop):
     36        (WebCore::RectEdges::setRight):
     37        (WebCore::RectEdges::setBottom):
     38        (WebCore::RectEdges::setLeft):
     39        * platform/text/WritingMode.h:
     40        (WebCore::isHorizontalPhysicalSide):
     41        (WebCore::mirrorPhysicalSide):
     42        (WebCore::rotatePhysicalSide):
     43        (WebCore::mapLogicalSideToPhysicalSide):
     44        * rendering/BorderEdge.cpp:
     45        (WebCore::borderEdges):
     46        (WebCore::BorderEdge::getBorderEdgeInfo): Deleted.
     47        * rendering/BorderEdge.h:
     48        (WebCore::edgeFlagForSide):
     49        (WebCore::includesEdge):
     50        (WebCore::includesAdjacentEdges):
     51        * rendering/RenderBoxModelObject.cpp:
     52        (WebCore::borderWillArcInnerEdge):
     53        (WebCore::borderStyleHasUnmatchedColorsAtCorner):
     54        (WebCore::colorsMatchAtCorner):
     55        (WebCore::colorNeedsAntiAliasAtCorner):
     56        (WebCore::willBeOverdrawn):
     57        (WebCore::joinRequiresMitre):
     58        (WebCore::calculateAdjustedInnerBorder):
     59        (WebCore::RenderBoxModelObject::paintOneBorderSide):
     60        (WebCore::calculateSideRect):
     61        (WebCore::RenderBoxModelObject::paintBorderSides):
     62        (WebCore::RenderBoxModelObject::paintTranslucentBorderSides):
     63        (WebCore::RenderBoxModelObject::paintBorder):
     64        (WebCore::RenderBoxModelObject::drawBoxSideFromPath):
     65        (WebCore::RenderBoxModelObject::clipBorderSidePolygon):
     66        (WebCore::RenderBoxModelObject::borderObscuresBackgroundEdge const):
     67        (WebCore::RenderBoxModelObject::borderObscuresBackground const):
     68        * rendering/RenderBoxModelObject.h:
     69        * rendering/RenderElement.cpp:
     70        (WebCore::RenderElement::drawLineForBoxSide const):
     71        (WebCore::RenderElement::paintOutline):
     72        * rendering/RenderInline.cpp:
     73        (WebCore::RenderInline::paintOutlineForLine):
     74        * rendering/RenderMultiColumnSet.cpp:
     75        (WebCore::RenderMultiColumnSet::paintColumnRules):
     76        * rendering/RenderObject.cpp:
     77        (WebCore::RenderObject::calculateBorderStyleColor):
     78        * rendering/RenderObjectEnums.h:
     79        * rendering/RenderTableCell.cpp:
     80        (WebCore::RenderTableCell::paintCollapsedBorders):
     81        * rendering/RenderTableSection.cpp:
     82        (WebCore::RenderTableSection::offsetTopForRowGroupBorder):
     83        (WebCore::RenderTableSection::paintRowGroupBorderIfRequired):
     84        (WebCore::physicalBorderForDirection):
     85        * rendering/RenderThemeIOS.mm:
     86        (WebCore::RenderThemeIOS::paintMenuListButtonDecorations):
     87        * rendering/style/NinePieceImage.h:
     88        (WebCore::imagePieceHorizontalSide):
     89        (WebCore::imagePieceVerticalSide):
     90
    1912020-10-31  Chris Dumez  <cdumez@apple.com>
    292
  • trunk/Source/WebCore/page/IntersectionObserver.cpp

    r265397 r269228  
    151151{
    152152    StringBuilder stringBuilder;
    153     PhysicalBoxSide sides[4] = { PhysicalBoxSide::Top, PhysicalBoxSide::Right, PhysicalBoxSide::Bottom, PhysicalBoxSide::Left };
    154     for (auto side : sides) {
     153    for (auto side : allBoxSides) {
    155154        auto& length = m_rootMargin.at(side);
    156155        stringBuilder.appendNumber(length.intValue());
     
    159158        else
    160159            stringBuilder.appendLiteral("px");
    161         if (side != PhysicalBoxSide::Left)
     160        if (side != BoxSide::Left)
    162161            stringBuilder.append(' ');
    163162    }
  • trunk/Source/WebCore/platform/RectEdges.h

    r234808 r269228  
    2828#include "WritingMode.h"
    2929#include <array>
     30#include <wtf/OptionSet.h>
    3031
    3132namespace WebCore {
    32    
     33
     34enum class BoxSideFlag : uint8_t {
     35    Top     = 1 << static_cast<unsigned>(BoxSide::Top),
     36    Right   = 1 << static_cast<unsigned>(BoxSide::Right),
     37    Bottom  = 1 << static_cast<unsigned>(BoxSide::Bottom),
     38    Left    = 1 << static_cast<unsigned>(BoxSide::Left)
     39};
     40
     41using BoxSideSet = OptionSet<BoxSideFlag>;
     42
    3343template<typename T> class RectEdges {
    3444public:
     
    3949        : m_sides({ { std::forward<T>(top), std::forward<T>(right), std::forward<T>(bottom), std::forward<T>(left) } })
    4050    { }
    41    
    42     T& at(PhysicalBoxSide side) { return m_sides[static_cast<size_t>(side)]; }
    43     T& top() { return at(PhysicalBoxSide::Top); }
    44     T& right() { return at(PhysicalBoxSide::Right); }
    45     T& bottom() { return at(PhysicalBoxSide::Bottom); }
    46     T& left() { return at(PhysicalBoxSide::Left); }
    47    
    48     const T& at(PhysicalBoxSide side) const { return m_sides[static_cast<size_t>(side)]; }
    49     const T& top() const { return at(PhysicalBoxSide::Top); }
    50     const T& right() const { return at(PhysicalBoxSide::Right); }
    51     const T& bottom() const { return at(PhysicalBoxSide::Bottom); }
    52     const T& left() const { return at(PhysicalBoxSide::Left); }
    53    
    54     void setAt(PhysicalBoxSide side, const T& v) { at(side) = v; }
    55     void setTop(const T& top) { setAt(PhysicalBoxSide::Top, top); }
    56     void setRight(const T& right) { setAt(PhysicalBoxSide::Right, right); }
    57     void setBottom(const T& bottom) { setAt(PhysicalBoxSide::Bottom, bottom); }
    58     void setLeft(const T& left) { setAt(PhysicalBoxSide::Left, left); }
    59    
     51
     52    T& at(BoxSide side) { return m_sides[static_cast<size_t>(side)]; }
     53    T& operator[](BoxSide side) { return m_sides[static_cast<size_t>(side)]; }
     54    T& top() { return at(BoxSide::Top); }
     55    T& right() { return at(BoxSide::Right); }
     56    T& bottom() { return at(BoxSide::Bottom); }
     57    T& left() { return at(BoxSide::Left); }
     58
     59    const T& at(BoxSide side) const { return m_sides[static_cast<size_t>(side)]; }
     60    const T& operator[](BoxSide side) const { return m_sides[static_cast<size_t>(side)]; }
     61    const T& top() const { return at(BoxSide::Top); }
     62    const T& right() const { return at(BoxSide::Right); }
     63    const T& bottom() const { return at(BoxSide::Bottom); }
     64    const T& left() const { return at(BoxSide::Left); }
     65
     66    void setAt(BoxSide side, const T& v) { at(side) = v; }
     67    void setTop(const T& top) { setAt(BoxSide::Top, top); }
     68    void setRight(const T& right) { setAt(BoxSide::Right, right); }
     69    void setBottom(const T& bottom) { setAt(BoxSide::Bottom, bottom); }
     70    void setLeft(const T& left) { setAt(BoxSide::Left, left); }
     71
    6072    T& before(WritingMode writingMode) { return at(mapLogicalSideToPhysicalSide(writingMode, LogicalBoxSide::Before)); }
    6173    T& after(WritingMode writingMode) { return at(mapLogicalSideToPhysicalSide(writingMode, LogicalBoxSide::After)); }
    6274    T& start(WritingMode writingMode, TextDirection direction = TextDirection::LTR) { return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), LogicalBoxSide::Start)); }
    6375    T& end(WritingMode writingMode, TextDirection direction = TextDirection::LTR) { return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), LogicalBoxSide::End)); }
    64    
     76
    6577    const T& before(WritingMode writingMode) const { return at(mapLogicalSideToPhysicalSide(writingMode, LogicalBoxSide::Before)); }
    6678    const T& after(WritingMode writingMode) const { return at(mapLogicalSideToPhysicalSide(writingMode, LogicalBoxSide::After)); }
    6779    const T& start(WritingMode writingMode, TextDirection direction = TextDirection::LTR) const { return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), LogicalBoxSide::Start)); }
    6880    const T& end(WritingMode writingMode, TextDirection direction = TextDirection::LTR) const { return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), LogicalBoxSide::End)); }
    69    
     81
    7082    void setBefore(const T& before, WritingMode writingMode) { this->before(writingMode) = before; }
    7183    void setAfter(const T& after, WritingMode writingMode) { this->after(writingMode) = after; }
    7284    void setStart(const T& start, WritingMode writingMode, TextDirection direction = TextDirection::LTR) { this->start(writingMode, direction) = start; }
    7385    void setEnd(const T& end, WritingMode writingMode, TextDirection direction = TextDirection::LTR) { this->end(writingMode, direction) = end; }
    74    
     86
    7587    bool operator==(const RectEdges& other) const { return m_sides == other.m_sides; }
    7688    bool operator!=(const RectEdges& other) const { return m_sides != other.m_sides; }
    7789
    7890private:
    79     std::array<T, 4> m_sides {{0, 0, 0, 0}};
     91    std::array<T, 4> m_sides { };
    8092};
    8193
  • trunk/Source/WebCore/platform/text/WritingMode.h

    r266691 r269228  
    3232#pragma once
    3333
     34#include <array>
    3435#include <wtf/EnumTraits.h>
    3536
     
    122123};
    123124
    124 enum class PhysicalBoxSide : uint8_t {
     125enum class BoxSide : uint8_t {
    125126    Top,
    126127    Right,
     
    129130};
    130131
    131 inline bool isHorizontalPhysicalSide(PhysicalBoxSide physicalSide)
     132constexpr std::array<BoxSide, 4> allBoxSides = { BoxSide::Top, BoxSide::Right, BoxSide::Bottom, BoxSide::Left };
     133
     134inline bool isHorizontalPhysicalSide(BoxSide physicalSide)
    132135{
    133     return physicalSide == PhysicalBoxSide::Left || physicalSide == PhysicalBoxSide::Right;
     136    return physicalSide == BoxSide::Left || physicalSide == BoxSide::Right;
    134137}
    135138
    136 inline PhysicalBoxSide mirrorPhysicalSide(PhysicalBoxSide physicalSide)
     139inline BoxSide mirrorPhysicalSide(BoxSide physicalSide)
    137140{
    138141    // top <-> bottom and left <-> right conversion
    139     return static_cast<PhysicalBoxSide>((static_cast<int>(physicalSide) + 2) % 4);
     142    return static_cast<BoxSide>((static_cast<int>(physicalSide) + 2) % 4);
    140143}
    141144
    142 inline PhysicalBoxSide rotatePhysicalSide(PhysicalBoxSide physicalSide)
     145inline BoxSide rotatePhysicalSide(BoxSide physicalSide)
    143146{
    144147    // top <-> left and right <-> bottom conversion
    145148    bool horizontalSide = isHorizontalPhysicalSide(physicalSide);
    146     return static_cast<PhysicalBoxSide>((static_cast<int>(physicalSide) + (horizontalSide ? 1 : 3)) % 4);
     149    return static_cast<BoxSide>((static_cast<int>(physicalSide) + (horizontalSide ? 1 : 3)) % 4);
    147150}
    148151
    149 inline PhysicalBoxSide mapLogicalSideToPhysicalSide(TextFlow textflow, LogicalBoxSide logicalSide)
     152inline BoxSide mapLogicalSideToPhysicalSide(TextFlow textflow, LogicalBoxSide logicalSide)
    150153{
    151     PhysicalBoxSide physicalSide = static_cast<PhysicalBoxSide>(logicalSide);
     154    BoxSide physicalSide = static_cast<BoxSide>(logicalSide);
    152155    bool horizontalSide = isHorizontalPhysicalSide(physicalSide);
    153156
     
    161164}
    162165
    163 inline PhysicalBoxSide mapLogicalSideToPhysicalSide(WritingMode writingMode, LogicalBoxSide logicalSide)
     166inline BoxSide mapLogicalSideToPhysicalSide(WritingMode writingMode, LogicalBoxSide logicalSide)
    164167{
    165168    // Set the direction such that side is mirrored if isFlippedWritingMode() is true
  • trunk/Source/WebCore/rendering/BorderEdge.cpp

    r245543 r269228  
    4747}
    4848
    49 void BorderEdge::getBorderEdgeInfo(BorderEdge edges[], const RenderStyle& style, float deviceScaleFactor, bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
     49BorderEdges borderEdges(const RenderStyle& style, float deviceScaleFactor, bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
    5050{
    5151    bool horizontal = style.isHorizontalWritingMode();
    5252
    53     edges[BSTop] = BorderEdge(style.borderTopWidth(), style.visitedDependentColorWithColorFilter(CSSPropertyBorderTopColor), style.borderTopStyle(), style.borderTopIsTransparent(),
    54         horizontal || includeLogicalLeftEdge, deviceScaleFactor);
    55     edges[BSRight] = BorderEdge(style.borderRightWidth(), style.visitedDependentColorWithColorFilter(CSSPropertyBorderRightColor), style.borderRightStyle(), style.borderRightIsTransparent(),
    56         !horizontal || includeLogicalRightEdge, deviceScaleFactor);
    57     edges[BSBottom] = BorderEdge(style.borderBottomWidth(), style.visitedDependentColorWithColorFilter(CSSPropertyBorderBottomColor), style.borderBottomStyle(), style.borderBottomIsTransparent(),
    58         horizontal || includeLogicalRightEdge, deviceScaleFactor);
    59     edges[BSLeft] = BorderEdge(style.borderLeftWidth(), style.visitedDependentColorWithColorFilter(CSSPropertyBorderLeftColor), style.borderLeftStyle(), style.borderLeftIsTransparent(),
    60         !horizontal || includeLogicalLeftEdge, deviceScaleFactor);
    61     }
     53    auto constructBorderEdge = [&](float width, CSSPropertyID borderColorProperty, BorderStyle borderStyle, bool isTransparent, bool isPresent) {
     54        return BorderEdge(width, style.visitedDependentColorWithColorFilter(borderColorProperty), borderStyle, isTransparent, isPresent, deviceScaleFactor);
     55    };
     56
     57    return {
     58        constructBorderEdge(style.borderTopWidth(), CSSPropertyBorderTopColor, style.borderTopStyle(), style.borderTopIsTransparent(), horizontal || includeLogicalLeftEdge),
     59        constructBorderEdge(style.borderRightWidth(), CSSPropertyBorderRightColor, style.borderRightStyle(), style.borderRightIsTransparent(), !horizontal || includeLogicalRightEdge),
     60        constructBorderEdge(style.borderBottomWidth(), CSSPropertyBorderBottomColor, style.borderBottomStyle(), style.borderBottomIsTransparent(), horizontal || includeLogicalRightEdge),
     61        constructBorderEdge(style.borderLeftWidth(), CSSPropertyBorderLeftColor, style.borderLeftStyle(), style.borderLeftIsTransparent(), !horizontal || includeLogicalLeftEdge)
     62    };
     63}
    6264
    6365bool BorderEdge::obscuresBackgroundEdge(float scale) const
  • trunk/Source/WebCore/rendering/BorderEdge.h

    r239563 r269228  
    2828#include "Color.h"
    2929#include "LayoutUnit.h"
     30#include "RectEdges.h"
    3031#include "RenderObjectEnums.h"
    3132#include "RenderStyleConstants.h"
     33#include <wtf/OptionSet.h>
    3234
    3335namespace WebCore {
    34 
    35 typedef unsigned BorderEdgeFlags;
    3636
    3737class RenderStyle;
     
    3939class BorderEdge {
    4040public:
    41     enum BorderEdgeFlag {
    42         TopBorderEdge = 1 << BSTop,
    43         RightBorderEdge = 1 << BSRight,
    44         BottomBorderEdge = 1 << BSBottom,
    45         LeftBorderEdge = 1 << BSLeft,
    46         AllBorderEdges = TopBorderEdge | BottomBorderEdge | LeftBorderEdge | RightBorderEdge
    47     };
    48 
    4941    BorderEdge() = default;
    5042    BorderEdge(float edgeWidth, Color edgeColor, BorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent, float devicePixelRatio);
    51 
    52     static void getBorderEdgeInfo(BorderEdge edges[], const RenderStyle&, float deviceScaleFactor, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
    5343
    5444    BorderStyle style() const { return m_style; }
     
    7767};
    7868
     69using BorderEdges = RectEdges<BorderEdge>;
     70BorderEdges borderEdges(const RenderStyle&, float deviceScaleFactor, bool includeLogicalLeftEdge = true, bool includeLogicalRightEdge = true);
     71
    7972inline bool edgesShareColor(const BorderEdge& firstEdge, const BorderEdge& secondEdge) { return firstEdge.color() == secondEdge.color(); }
    80 inline BorderEdge::BorderEdgeFlag edgeFlagForSide(BoxSide side) { return static_cast<BorderEdge::BorderEdgeFlag>(1 << side); }
    81 inline bool includesEdge(BorderEdgeFlags flags, BoxSide side) { return flags & edgeFlagForSide(side); }
    82 inline bool includesAdjacentEdges(BorderEdgeFlags flags)
     73inline BoxSideFlag edgeFlagForSide(BoxSide side) { return static_cast<BoxSideFlag>(1 << static_cast<unsigned>(side)); }
     74inline bool includesEdge(OptionSet<BoxSideFlag> flags, BoxSide side) { return flags.contains(edgeFlagForSide(side)); }
     75
     76inline bool includesAdjacentEdges(OptionSet<BoxSideFlag> flags)
    8377{
    84     return (flags & (BorderEdge::TopBorderEdge | BorderEdge::RightBorderEdge)) == (BorderEdge::TopBorderEdge | BorderEdge::RightBorderEdge)
    85         || (flags & (BorderEdge::RightBorderEdge | BorderEdge::BottomBorderEdge)) == (BorderEdge::RightBorderEdge | BorderEdge::BottomBorderEdge)
    86         || (flags & (BorderEdge::BottomBorderEdge | BorderEdge::LeftBorderEdge)) == (BorderEdge::BottomBorderEdge | BorderEdge::LeftBorderEdge)
    87         || (flags & (BorderEdge::LeftBorderEdge | BorderEdge::TopBorderEdge)) == (BorderEdge::LeftBorderEdge | BorderEdge::TopBorderEdge);
     78    return flags.containsAll({ BoxSideFlag::Top, BoxSideFlag::Right })
     79        || flags.containsAll({ BoxSideFlag::Right, BoxSideFlag::Bottom })
     80        || flags.containsAll({ BoxSideFlag::Bottom, BoxSideFlag::Left })
     81        || flags.containsAll({ BoxSideFlag::Left, BoxSideFlag::Top });
    8882}
    8983
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp

    r268919 r269228  
    14561456}
    14571457
    1458 static bool borderWillArcInnerEdge(const LayoutSize& firstRadius, const FloatSize& secondRadius)
     1458static bool borderWillArcInnerEdge(const LayoutSize& firstRadius, const LayoutSize& secondRadius)
    14591459{
    14601460    return !firstRadius.isZero() || !secondRadius.isZero();
     
    14871487    // These styles match at the top/left and bottom/right.
    14881488    if (style == BorderStyle::Inset || style == BorderStyle::Groove || style == BorderStyle::Ridge || style == BorderStyle::Outset) {
    1489         const BorderEdgeFlags topRightFlags = edgeFlagForSide(BSTop) | edgeFlagForSide(BSRight);
    1490         const BorderEdgeFlags bottomLeftFlags = edgeFlagForSide(BSBottom) | edgeFlagForSide(BSLeft);
    1491 
    1492         BorderEdgeFlags flags = edgeFlagForSide(side) | edgeFlagForSide(adjacentSide);
    1493         return flags == topRightFlags || flags == bottomLeftFlags;
     1489        BoxSideSet topRightSides = { BoxSideFlag::Top, BoxSideFlag::Right };
     1490        BoxSideSet bottomLeftSides = { BoxSideFlag::Bottom, BoxSideFlag::Left };
     1491
     1492        BoxSideSet usedSides { edgeFlagForSide(side), edgeFlagForSide(adjacentSide) };
     1493        return usedSides == topRightSides || usedSides == bottomLeftSides;
    14941494    }
    14951495    return false;
    14961496}
    14971497
    1498 static inline bool colorsMatchAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
    1499 {
    1500     if (edges[side].shouldRender() != edges[adjacentSide].shouldRender())
    1501         return false;
    1502 
    1503     if (!edgesShareColor(edges[side], edges[adjacentSide]))
    1504         return false;
    1505 
    1506     return !borderStyleHasUnmatchedColorsAtCorner(edges[side].style(), side, adjacentSide);
    1507 }
    1508 
    1509 
    1510 static inline bool colorNeedsAntiAliasAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
    1511 {
    1512     if (edges[side].color().isOpaque())
    1513         return false;
    1514 
    1515     if (edges[side].shouldRender() != edges[adjacentSide].shouldRender())
    1516         return false;
    1517 
    1518     if (!edgesShareColor(edges[side], edges[adjacentSide]))
     1498static inline bool colorsMatchAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdges& edges)
     1499{
     1500    auto& edge = edges.at(side);
     1501    auto& adjacentEdge = edges.at(adjacentSide);
     1502
     1503    if (edge.shouldRender() != adjacentEdge.shouldRender())
     1504        return false;
     1505
     1506    if (!edgesShareColor(edge, adjacentEdge))
     1507        return false;
     1508
     1509    return !borderStyleHasUnmatchedColorsAtCorner(edge.style(), side, adjacentSide);
     1510}
     1511
     1512
     1513static inline bool colorNeedsAntiAliasAtCorner(BoxSide side, BoxSide adjacentSide, const BorderEdges& edges)
     1514{
     1515    auto& edge = edges.at(side);
     1516    auto& adjacentEdge = edges.at(adjacentSide);
     1517
     1518    if (edge.color().isOpaque())
     1519        return false;
     1520
     1521    if (edge.shouldRender() != adjacentEdge.shouldRender())
     1522        return false;
     1523
     1524    if (!edgesShareColor(edge, adjacentEdge))
    15191525        return true;
    15201526
    1521     return borderStyleHasUnmatchedColorsAtCorner(edges[side].style(), side, adjacentSide);
     1527    return borderStyleHasUnmatchedColorsAtCorner(edge.style(), side, adjacentSide);
    15221528}
    15231529
    15241530// This assumes that we draw in order: top, bottom, left, right.
    1525 static inline bool willBeOverdrawn(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[])
     1531static inline bool willBeOverdrawn(BoxSide side, BoxSide adjacentSide, const BorderEdges& edges)
    15261532{
    15271533    switch (side) {
    1528     case BSTop:
    1529     case BSBottom:
    1530         if (edges[adjacentSide].presentButInvisible())
     1534    case BoxSide::Top:
     1535    case BoxSide::Bottom: {
     1536        auto& edge = edges.at(side);
     1537        auto& adjacentEdge = edges.at(adjacentSide);
     1538
     1539        if (adjacentEdge.presentButInvisible())
    15311540            return false;
    15321541
    1533         if (!edgesShareColor(edges[side], edges[adjacentSide]) && !edges[adjacentSide].color().isOpaque())
     1542        if (!edgesShareColor(edge, adjacentEdge) && !adjacentEdge.color().isOpaque())
    15341543            return false;
    15351544       
    1536         if (!borderStyleFillsBorderArea(edges[adjacentSide].style()))
     1545        if (!borderStyleFillsBorderArea(adjacentEdge.style()))
    15371546            return false;
    15381547
    15391548        return true;
    1540 
    1541     case BSLeft:
    1542     case BSRight:
     1549    }
     1550    case BoxSide::Left:
     1551    case BoxSide::Right:
    15431552        // These draw last, so are never overdrawn.
    15441553        return false;
     
    15611570}
    15621571
    1563 static bool joinRequiresMitre(BoxSide side, BoxSide adjacentSide, const BorderEdge edges[], bool allowOverdraw)
    1564 {
    1565     if ((edges[side].isTransparent() && edges[adjacentSide].isTransparent()) || !edges[adjacentSide].isPresent())
     1572static bool joinRequiresMitre(BoxSide side, BoxSide adjacentSide, const BorderEdges& edges, bool allowOverdraw)
     1573{
     1574    auto& edge = edges.at(side);
     1575    auto& adjacentEdge = edges.at(adjacentSide);
     1576
     1577    if ((edge.isTransparent() && adjacentEdge.isTransparent()) || !adjacentEdge.isPresent())
    15661578        return false;
    15671579
     
    15691581        return false;
    15701582
    1571     if (!edgesShareColor(edges[side], edges[adjacentSide]))
     1583    if (!edgesShareColor(edge, adjacentEdge))
    15721584        return true;
    15731585
    1574     if (borderStylesRequireMitre(side, adjacentSide, edges[side].style(), edges[adjacentSide].style()))
     1586    if (borderStylesRequireMitre(side, adjacentSide, edge.style(), adjacentEdge.style()))
    15751587        return true;
    15761588   
     
    15901602
    15911603    switch (side) {
    1592     case BSTop:
     1604    case BoxSide::Top:
    15931605        overshoot = newRadii.topLeft().width() + newRadii.topRight().width() - newRect.width();
    15941606        if (overshoot > 0) {
     
    15981610                newRect.move(-overshoot, 0);
    15991611        }
    1600         newRadii.setBottomLeft(IntSize(0, 0));
    1601         newRadii.setBottomRight(IntSize(0, 0));
     1612        newRadii.setBottomLeft({ });
     1613        newRadii.setBottomRight({ });
    16021614        maxRadii = std::max(newRadii.topLeft().height(), newRadii.topRight().height());
    16031615        if (maxRadii > newRect.height())
     
    16051617        break;
    16061618
    1607     case BSBottom:
     1619    case BoxSide::Bottom:
    16081620        overshoot = newRadii.bottomLeft().width() + newRadii.bottomRight().width() - newRect.width();
    16091621        if (overshoot > 0) {
     
    16131625                newRect.move(-overshoot, 0);
    16141626        }
    1615         newRadii.setTopLeft(IntSize(0, 0));
    1616         newRadii.setTopRight(IntSize(0, 0));
     1627        newRadii.setTopLeft({ });
     1628        newRadii.setTopRight({ });
    16171629        maxRadii = std::max(newRadii.bottomLeft().height(), newRadii.bottomRight().height());
    16181630        if (maxRadii > newRect.height()) {
     
    16221634        break;
    16231635
    1624     case BSLeft:
     1636    case BoxSide::Left:
    16251637        overshoot = newRadii.topLeft().height() + newRadii.bottomLeft().height() - newRect.height();
    16261638        if (overshoot > 0) {
     
    16301642                newRect.move(0, -overshoot);
    16311643        }
    1632         newRadii.setTopRight(IntSize(0, 0));
    1633         newRadii.setBottomRight(IntSize(0, 0));
     1644        newRadii.setTopRight({ });
     1645        newRadii.setBottomRight({ });
    16341646        maxRadii = std::max(newRadii.topLeft().width(), newRadii.bottomLeft().width());
    16351647        if (maxRadii > newRect.width())
     
    16371649        break;
    16381650
    1639     case BSRight:
     1651    case BoxSide::Right:
    16401652        overshoot = newRadii.topRight().height() + newRadii.bottomRight().height() - newRect.height();
    16411653        if (overshoot > 0) {
     
    16451657                newRect.move(0, -overshoot);
    16461658        }
    1647         newRadii.setTopLeft(IntSize(0, 0));
    1648         newRadii.setBottomLeft(IntSize(0, 0));
     1659        newRadii.setTopLeft({ });
     1660        newRadii.setBottomLeft({ });
    16491661        maxRadii = std::max(newRadii.topRight().width(), newRadii.bottomRight().width());
    16501662        if (maxRadii > newRect.width()) {
     
    16591671
    16601672void RenderBoxModelObject::paintOneBorderSide(GraphicsContext& graphicsContext, const RenderStyle& style, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    1661     const LayoutRect& sideRect, BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdge edges[], const Path* path,
     1673    const LayoutRect& sideRect, BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdges& edges, const Path* path,
    16621674    BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
    16631675{
    1664     const BorderEdge& edgeToRender = edges[side];
     1676    auto& edgeToRender = edges.at(side);
    16651677    ASSERT(edgeToRender.widthForPainting());
    1666     const BorderEdge& adjacentEdge1 = edges[adjacentSide1];
    1667     const BorderEdge& adjacentEdge2 = edges[adjacentSide2];
     1678    auto& adjacentEdge1 = edges.at(adjacentSide1);
     1679    auto& adjacentEdge2 = edges.at(adjacentSide2);
    16681680
    16691681    bool mitreAdjacentSide1 = joinRequiresMitre(side, adjacentSide1, edges, !antialias);
     
    17051717}
    17061718
    1707 static LayoutRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdge edges[], int side)
     1719static LayoutRect calculateSideRect(const RoundedRect& outerBorder, const BorderEdges& edges, BoxSide side)
    17081720{
    17091721    LayoutRect sideRect = outerBorder.rect();
    1710     float width = edges[side].widthForPainting();
    1711 
    1712     if (side == BSTop)
     1722    float width = edges.at(side).widthForPainting();
     1723
     1724    switch (side) {
     1725    case BoxSide::Top:
    17131726        sideRect.setHeight(width);
    1714     else if (side == BSBottom)
     1727        break;
     1728    case BoxSide::Right:
     1729        sideRect.shiftXEdgeTo(sideRect.maxX() - width);
     1730        break;
     1731    case BoxSide::Bottom:
    17151732        sideRect.shiftYEdgeTo(sideRect.maxY() - width);
    1716     else if (side == BSLeft)
     1733        break;
     1734    case BoxSide::Left:
    17171735        sideRect.setWidth(width);
    1718     else
    1719         sideRect.shiftXEdgeTo(sideRect.maxX() - width);
     1736        break;
     1737    }
    17201738
    17211739    return sideRect;
     
    17231741
    17241742void RenderBoxModelObject::paintBorderSides(GraphicsContext& graphicsContext, const RenderStyle& style, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    1725     const IntPoint& innerBorderAdjustment, const BorderEdge edges[], BorderEdgeFlags edgeSet, BackgroundBleedAvoidance bleedAvoidance,
     1743    const IntPoint& innerBorderAdjustment, const BorderEdges& edges, BoxSideSet edgeSet, BackgroundBleedAvoidance bleedAvoidance,
    17261744    bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor)
    17271745{
     
    17371755    // only depends on sideRect when painting solid borders.
    17381756
    1739     if (edges[BSTop].shouldRender() && includesEdge(edgeSet, BSTop)) {
     1757    auto paintOneSide = [&](BoxSide side, BoxSide adjacentSide1, BoxSide adjacentSide2) {
     1758        auto& edge = edges.at(side);
     1759        if (!edge.shouldRender() || !edgeSet.contains(edgeFlagForSide(side)))
     1760            return;
     1761
    17401762        LayoutRect sideRect = outerBorder.rect();
    1741         sideRect.setHeight(edges[BSTop].widthForPainting() + innerBorderAdjustment.y());
    1742 
    1743         bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSTop].style()) || borderWillArcInnerEdge(innerBorder.radii().topLeft(), innerBorder.radii().topRight()));
    1744         paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSTop, BSLeft, BSRight, edges, usePath ? &roundedPath : nullptr, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
    1745     }
    1746 
    1747     if (edges[BSBottom].shouldRender() && includesEdge(edgeSet, BSBottom)) {
    1748         LayoutRect sideRect = outerBorder.rect();
    1749         sideRect.shiftYEdgeTo(sideRect.maxY() - edges[BSBottom].widthForPainting() - innerBorderAdjustment.y());
    1750 
    1751         bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSBottom].style()) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().bottomRight()));
    1752         paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSBottom, BSLeft, BSRight, edges, usePath ? &roundedPath : nullptr, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
    1753     }
    1754 
    1755     if (edges[BSLeft].shouldRender() && includesEdge(edgeSet, BSLeft)) {
    1756         LayoutRect sideRect = outerBorder.rect();
    1757         sideRect.setWidth(edges[BSLeft].widthForPainting() + innerBorderAdjustment.x());
    1758 
    1759         bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSLeft].style()) || borderWillArcInnerEdge(innerBorder.radii().bottomLeft(), innerBorder.radii().topLeft()));
    1760         paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSLeft, BSTop, BSBottom, edges, usePath ? &roundedPath : nullptr, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
    1761     }
    1762 
    1763     if (edges[BSRight].shouldRender() && includesEdge(edgeSet, BSRight)) {
    1764         LayoutRect sideRect = outerBorder.rect();
    1765         sideRect.shiftXEdgeTo(sideRect.maxX() - edges[BSRight].widthForPainting() - innerBorderAdjustment.x());
    1766 
    1767         bool usePath = renderRadii && (borderStyleHasInnerDetail(edges[BSRight].style()) || borderWillArcInnerEdge(innerBorder.radii().bottomRight(), innerBorder.radii().topRight()));
    1768         paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, BSRight, BSTop, BSBottom, edges, usePath ? &roundedPath : nullptr, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
    1769     }
     1763        LayoutSize firstRadius;
     1764        LayoutSize secondRadius;
     1765
     1766        switch (side) {
     1767        case BoxSide::Top:
     1768            sideRect.setHeight(edge.widthForPainting() + innerBorderAdjustment.y());
     1769            firstRadius = innerBorder.radii().topLeft();
     1770            secondRadius = innerBorder.radii().topRight();
     1771            break;
     1772        case BoxSide::Right:
     1773            sideRect.shiftXEdgeTo(sideRect.maxX() - edge.widthForPainting() - innerBorderAdjustment.x());
     1774            firstRadius = innerBorder.radii().bottomRight();
     1775            secondRadius = innerBorder.radii().topRight();
     1776            break;
     1777        case BoxSide::Bottom:
     1778            sideRect.shiftYEdgeTo(sideRect.maxY() - edge.widthForPainting() - innerBorderAdjustment.y());
     1779            firstRadius = innerBorder.radii().bottomLeft();
     1780            secondRadius = innerBorder.radii().bottomRight();
     1781            break;
     1782        case BoxSide::Left:
     1783            sideRect.setWidth(edge.widthForPainting() + innerBorderAdjustment.x());
     1784            firstRadius = innerBorder.radii().bottomLeft();
     1785            secondRadius = innerBorder.radii().topLeft();
     1786            break;
     1787        }
     1788
     1789        bool usePath = renderRadii && (borderStyleHasInnerDetail(edge.style()) || borderWillArcInnerEdge(firstRadius, secondRadius));
     1790        paintOneBorderSide(graphicsContext, style, outerBorder, innerBorder, sideRect, side, adjacentSide1, adjacentSide2, edges, usePath ? &roundedPath : nullptr, bleedAvoidance, includeLogicalLeftEdge, includeLogicalRightEdge, antialias, overrideColor);
     1791    };
     1792
     1793    paintOneSide(BoxSide::Top, BoxSide::Left, BoxSide::Right);
     1794    paintOneSide(BoxSide::Bottom, BoxSide::Left, BoxSide::Right);
     1795    paintOneSide(BoxSide::Left, BoxSide::Top, BoxSide::Bottom);
     1796    paintOneSide(BoxSide::Right, BoxSide::Top, BoxSide::Bottom);
    17701797}
    17711798
    17721799void RenderBoxModelObject::paintTranslucentBorderSides(GraphicsContext& graphicsContext, const RenderStyle& style, const RoundedRect& outerBorder, const RoundedRect& innerBorder, const IntPoint& innerBorderAdjustment,
    1773     const BorderEdge edges[], BorderEdgeFlags edgesToDraw, BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias)
     1800    const BorderEdges& edges, BoxSideSet edgesToDraw, BackgroundBleedAvoidance bleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias)
    17741801{
    17751802    // willBeOverdrawn assumes that we draw in order: top, bottom, left, right.
    17761803    // This is different from BoxSide enum order.
    1777     static const BoxSide paintOrder[] = { BSTop, BSBottom, BSLeft, BSRight };
     1804    static constexpr std::array<BoxSide, 4> paintOrderSides = { BoxSide::Top, BoxSide::Bottom, BoxSide::Left, BoxSide::Right };
    17781805
    17791806    while (edgesToDraw) {
     
    17811808        Color commonColor;
    17821809       
    1783         BorderEdgeFlags commonColorEdgeSet = 0;
    1784         for (size_t i = 0; i < sizeof(paintOrder) / sizeof(paintOrder[0]); ++i) {
    1785             BoxSide currSide = paintOrder[i];
    1786             if (!includesEdge(edgesToDraw, currSide))
     1810        BoxSideSet commonColorEdgeSet;
     1811        for (auto side : paintOrderSides) {
     1812            if (!edgesToDraw.contains(edgeFlagForSide(side)))
    17871813                continue;
    17881814
     1815            auto& edge = edges.at(side);
    17891816            bool includeEdge;
    1790             if (!commonColorEdgeSet) {
    1791                 commonColor = edges[currSide].color();
     1817            if (commonColorEdgeSet.isEmpty()) {
     1818                commonColor = edge.color();
    17921819                includeEdge = true;
    17931820            } else
    1794                 includeEdge = edges[currSide].color() == commonColor;
     1821                includeEdge = edge.color() == commonColor;
    17951822
    17961823            if (includeEdge)
    1797                 commonColorEdgeSet |= edgeFlagForSide(currSide);
     1824                commonColorEdgeSet.add(edgeFlagForSide(side));
    17981825        }
    17991826
     
    18091836            graphicsContext.endTransparencyLayer();
    18101837       
    1811         edgesToDraw &= ~commonColorEdgeSet;
     1838        edgesToDraw.remove(commonColorEdgeSet);
    18121839    }
    18131840}
     
    18341861        return;
    18351862
    1836     BorderEdge edges[4];
    1837     BorderEdge::getBorderEdgeInfo(edges, style, document().deviceScaleFactor(), includeLogicalLeftEdge, includeLogicalRightEdge);
     1863    auto edges = borderEdges(style, document().deviceScaleFactor(), includeLogicalLeftEdge, includeLogicalRightEdge);
    18381864    RoundedRect outerBorder = style.getRoundedBorderFor(rect, includeLogicalLeftEdge, includeLogicalRightEdge);
    18391865    RoundedRect innerBorder = style.getRoundedInnerBorderFor(borderInnerRectAdjustedForBleedAvoidance(graphicsContext, rect, bleedAvoidance), includeLogicalLeftEdge, includeLogicalRightEdge);
     
    18481874    int numEdgesVisible = 4;
    18491875    bool allEdgesShareColor = true;
    1850     int firstVisibleEdge = -1;
    1851     BorderEdgeFlags edgesToDraw = 0;
    1852 
    1853     for (int i = BSTop; i <= BSLeft; ++i) {
    1854         const BorderEdge& currEdge = edges[i];
    1855 
    1856         if (edges[i].shouldRender())
    1857             edgesToDraw |= edgeFlagForSide(static_cast<BoxSide>(i));
     1876    Optional<BoxSide> firstVisibleSide;
     1877    BoxSideSet edgesToDraw;
     1878
     1879    for (auto side : allBoxSides) {
     1880        auto& currEdge = edges.at(side);
     1881
     1882        if (currEdge.shouldRender())
     1883            edgesToDraw.add(edgeFlagForSide(side));
    18581884
    18591885        if (currEdge.presentButInvisible()) {
     
    18681894        }
    18691895
    1870         if (firstVisibleEdge == -1)
    1871             firstVisibleEdge = i;
    1872         else if (currEdge.color() != edges[firstVisibleEdge].color())
     1896        if (!firstVisibleSide)
     1897            firstVisibleSide = side;
     1898        else if (currEdge.color() != edges.at(*firstVisibleSide).color())
    18731899            allEdgesShareColor = false;
    18741900
     
    19051931                LayoutRect innerThirdRect = outerBorder.rect();
    19061932                LayoutRect outerThirdRect = outerBorder.rect();
    1907                 for (int side = BSTop; side <= BSLeft; ++side) {
     1933                for (auto side : allBoxSides) {
    19081934                    LayoutUnit outerWidth;
    19091935                    LayoutUnit innerWidth;
    1910                     edges[side].getDoubleBorderStripeWidths(outerWidth, innerWidth);
    1911 
    1912                     if (side == BSTop) {
     1936                    edges.at(side).getDoubleBorderStripeWidths(outerWidth, innerWidth);
     1937                    switch (side) {
     1938                    case BoxSide::Top:
    19131939                        innerThirdRect.shiftYEdgeTo(innerThirdRect.y() + innerWidth);
    19141940                        outerThirdRect.shiftYEdgeTo(outerThirdRect.y() + outerWidth);
    1915                     } else if (side == BSBottom) {
     1941                        break;
     1942                    case BoxSide::Right:
     1943                        innerThirdRect.setWidth(innerThirdRect.width() - innerWidth);
     1944                        outerThirdRect.setWidth(outerThirdRect.width() - outerWidth);
     1945                        break;
     1946                    case BoxSide::Bottom:
    19161947                        innerThirdRect.setHeight(innerThirdRect.height() - innerWidth);
    19171948                        outerThirdRect.setHeight(outerThirdRect.height() - outerWidth);
    1918                     } else if (side == BSLeft) {
     1949                        break;
     1950                    case BoxSide::Left:
    19191951                        innerThirdRect.shiftXEdgeTo(innerThirdRect.x() + innerWidth);
    19201952                        outerThirdRect.shiftXEdgeTo(outerThirdRect.x() + outerWidth);
    1921                     } else {
    1922                         innerThirdRect.setWidth(innerThirdRect.width() - innerWidth);
    1923                         outerThirdRect.setWidth(outerThirdRect.width() - outerWidth);
     1953                        break;
    19241954                    }
    19251955                }
     
    19481978           
    19491979            graphicsContext.setFillRule(WindRule::EvenOdd);
    1950             graphicsContext.setFillColor(edges[firstVisibleEdge].color());
     1980            graphicsContext.setFillColor(edges.at(*firstVisibleSide).color());
    19511981            graphicsContext.fillPath(path);
    19521982            return;
     
    19561986            Path path;
    19571987
    1958             for (int i = BSTop; i <= BSLeft; ++i) {
    1959                 const BorderEdge& currEdge = edges[i];
    1960                 if (currEdge.shouldRender()) {
    1961                     LayoutRect sideRect = calculateSideRect(outerBorder, edges, i);
    1962                     path.addRect(sideRect);
     1988            for (auto side : allBoxSides) {
     1989                if (edges.at(side).shouldRender()) {
     1990                    auto sideRect = calculateSideRect(outerBorder, edges, side);
     1991                    path.addRect(sideRect); // FIXME: Need pixel snapping here.
    19631992                }
    19641993            }
    19651994
    19661995            graphicsContext.setFillRule(WindRule::NonZero);
    1967             graphicsContext.setFillColor(edges[firstVisibleEdge].color());
     1996            graphicsContext.setFillColor(edges.at(*firstVisibleSide).color());
    19681997            graphicsContext.fillPath(path);
    19691998            return;
     
    19932022}
    19942023
    1995 void RenderBoxModelObject::drawBoxSideFromPath(GraphicsContext& graphicsContext, const LayoutRect& borderRect, const Path& borderPath, const BorderEdge edges[],
     2024void RenderBoxModelObject::drawBoxSideFromPath(GraphicsContext& graphicsContext, const LayoutRect& borderRect, const Path& borderPath, const BorderEdges& edges,
    19962025    float thickness, float drawThickness, BoxSide side, const RenderStyle& style, Color color, BorderStyle borderStyle, BackgroundBleedAvoidance bleedAvoidance,
    19972026    bool includeLogicalLeftEdge, bool includeLogicalRightEdge)
     
    20522081        LayoutUnit outerBorderTopWidth;
    20532082        LayoutUnit innerBorderTopWidth;
    2054         edges[BSTop].getDoubleBorderStripeWidths(outerBorderTopWidth, innerBorderTopWidth);
     2083        edges.top().getDoubleBorderStripeWidths(outerBorderTopWidth, innerBorderTopWidth);
    20552084
    20562085        LayoutUnit outerBorderRightWidth;
    20572086        LayoutUnit innerBorderRightWidth;
    2058         edges[BSRight].getDoubleBorderStripeWidths(outerBorderRightWidth, innerBorderRightWidth);
     2087        edges.right().getDoubleBorderStripeWidths(outerBorderRightWidth, innerBorderRightWidth);
    20592088
    20602089        LayoutUnit outerBorderBottomWidth;
    20612090        LayoutUnit innerBorderBottomWidth;
    2062         edges[BSBottom].getDoubleBorderStripeWidths(outerBorderBottomWidth, innerBorderBottomWidth);
     2091        edges.bottom().getDoubleBorderStripeWidths(outerBorderBottomWidth, innerBorderBottomWidth);
    20632092
    20642093        LayoutUnit outerBorderLeftWidth;
    20652094        LayoutUnit innerBorderLeftWidth;
    2066         edges[BSLeft].getDoubleBorderStripeWidths(outerBorderLeftWidth, innerBorderLeftWidth);
     2095        edges.left().getDoubleBorderStripeWidths(outerBorderLeftWidth, innerBorderLeftWidth);
    20672096
    20682097        // Draw inner border line
     
    21152144        // Paint inner only
    21162145        GraphicsContextStateSaver stateSaver(graphicsContext);
    2117         LayoutUnit topWidth { edges[BSTop].widthForPainting() / 2 };
    2118         LayoutUnit bottomWidth { edges[BSBottom].widthForPainting() / 2 };
    2119         LayoutUnit leftWidth { edges[BSLeft].widthForPainting() / 2 };
    2120         LayoutUnit rightWidth { edges[BSRight].widthForPainting() / 2 };
     2146        LayoutUnit topWidth { edges.top().widthForPainting() / 2 };
     2147        LayoutUnit bottomWidth { edges.bottom().widthForPainting() / 2 };
     2148        LayoutUnit leftWidth { edges.left().widthForPainting() / 2 };
     2149        LayoutUnit rightWidth { edges.right().widthForPainting() / 2 };
    21212150
    21222151        RoundedRect clipRect = style.getRoundedInnerBorderFor(borderRect,
     
    21652194    quad.reserveInitialCapacity(4);
    21662195    switch (side) {
    2167     case BSTop:
     2196    case BoxSide::Top:
    21682197        quad.uncheckedAppend(outerRect.minXMinYCorner());
    21692198        quad.uncheckedAppend(innerRect.minXMinYCorner());
     
    21782207        break;
    21792208
    2180     case BSLeft:
     2209    case BoxSide::Left:
    21812210        quad.uncheckedAppend(outerRect.minXMinYCorner());
    21822211        quad.uncheckedAppend(innerRect.minXMinYCorner());
     
    21912220        break;
    21922221
    2193     case BSBottom:
     2222    case BoxSide::Bottom:
    21942223        quad.uncheckedAppend(outerRect.minXMaxYCorner());
    21952224        quad.uncheckedAppend(innerRect.minXMaxYCorner());
     
    22042233        break;
    22052234
    2206     case BSRight:
     2235    case BoxSide::Right:
    22072236        quad.uncheckedAppend(outerRect.maxXMinYCorner());
    22082237        quad.uncheckedAppend(innerRect.maxXMinYCorner());
     
    22332262        quad[1],
    22342263        quad[2],
    2235         side == BSTop || side == BSBottom ? FloatPoint(quad[3].x(), quad[2].y()) : FloatPoint(quad[2].x(), quad[3].y()),
     2264        side == BoxSide::Top || side == BoxSide::Bottom ? FloatPoint(quad[3].x(), quad[2].y()) : FloatPoint(quad[2].x(), quad[3].y()),
    22362265        quad[3]
    22372266    };
     
    22422271    Vector<FloatPoint> secondQuad = {
    22432272        quad[0],
    2244         side == BSTop || side == BSBottom ? FloatPoint(quad[0].x(), quad[1].y()) : FloatPoint(quad[1].x(), quad[0].y()),
     2273        side == BoxSide::Top || side == BoxSide::Bottom ? FloatPoint(quad[0].x(), quad[1].y()) : FloatPoint(quad[1].x(), quad[0].y()),
    22452274        quad[1],
    22462275        quad[2],
     
    22562285bool RenderBoxModelObject::borderObscuresBackgroundEdge(const FloatSize& contextScale) const
    22572286{
    2258     BorderEdge edges[4];
    2259     BorderEdge::getBorderEdgeInfo(edges, style(), document().deviceScaleFactor());
    2260 
    2261     for (int i = BSTop; i <= BSLeft; ++i) {
    2262         const BorderEdge& currEdge = edges[i];
     2287    auto edges = borderEdges(style(), document().deviceScaleFactor());
     2288
     2289    for (auto side : allBoxSides) {
     2290        auto& currEdge = edges.at(side);
    22632291        // FIXME: for vertical text
    2264         float axisScale = (i == BSTop || i == BSBottom) ? contextScale.height() : contextScale.width();
     2292        float axisScale = (side == BoxSide::Top || side == BoxSide::Bottom) ? contextScale.height() : contextScale.width();
    22652293        if (!currEdge.obscuresBackgroundEdge(axisScale))
    22662294            return false;
     
    22792307        return false;
    22802308
    2281     BorderEdge edges[4];
    2282     BorderEdge::getBorderEdgeInfo(edges, style(), document().deviceScaleFactor());
    2283 
    2284     for (int i = BSTop; i <= BSLeft; ++i) {
    2285         const BorderEdge& currEdge = edges[i];
    2286         if (!currEdge.obscuresBackground())
     2309    auto edges = borderEdges(style(), document().deviceScaleFactor());
     2310
     2311    for (auto side : allBoxSides) {
     2312        if (!edges.at(side).obscuresBackground())
    22872313            return false;
    22882314    }
  • trunk/Source/WebCore/rendering/RenderBoxModelObject.h

    r268919 r269228  
    2626#include "FontBaseline.h"
    2727#include "LayoutRect.h"
     28#include "RectEdges.h"
    2829#include "RenderLayerModelObject.h"
    2930
     
    3334enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
    3435enum LineDirectionMode { HorizontalLine, VerticalLine };
    35 typedef unsigned BorderEdgeFlags;
    3636
    3737enum BackgroundBleedAvoidance {
     
    6363class RenderTextFragment;
    6464class StickyPositionViewportConstraints;
     65
     66enum class BoxSideFlag : uint8_t;
     67using BoxSideSet = OptionSet<BoxSideFlag>;
     68using BorderEdges = RectEdges<BorderEdge>;
    6569
    6670class BackgroundImageGeometry {
     
    314318
    315319    void paintOneBorderSide(GraphicsContext&, const RenderStyle&, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    316         const LayoutRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdge[],
     320        const LayoutRect& sideRect, BoxSide, BoxSide adjacentSide1, BoxSide adjacentSide2, const BorderEdges&,
    317321        const Path*, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias, const Color* overrideColor = nullptr);
    318322    void paintTranslucentBorderSides(GraphicsContext&, const RenderStyle&, const RoundedRect& outerBorder, const RoundedRect& innerBorder, const IntPoint& innerBorderAdjustment,
    319         const BorderEdge[], BorderEdgeFlags, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false);
     323        const BorderEdges&, BoxSideSet, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false);
    320324    void paintBorderSides(GraphicsContext&, const RenderStyle&, const RoundedRect& outerBorder, const RoundedRect& innerBorder,
    321         const IntPoint& innerBorderAdjustment, const BorderEdge[], BorderEdgeFlags, BackgroundBleedAvoidance,
     325        const IntPoint& innerBorderAdjustment, const BorderEdges&, BoxSideSet, BackgroundBleedAvoidance,
    322326        bool includeLogicalLeftEdge, bool includeLogicalRightEdge, bool antialias = false, const Color* overrideColor = nullptr);
    323     void drawBoxSideFromPath(GraphicsContext&, const LayoutRect&, const Path&, const BorderEdge[],
     327    void drawBoxSideFromPath(GraphicsContext&, const LayoutRect&, const Path&, const BorderEdges&,
    324328        float thickness, float drawThickness, BoxSide, const RenderStyle&,
    325329        Color, BorderStyle, BackgroundBleedAvoidance, bool includeLogicalLeftEdge, bool includeLogicalRightEdge);
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r269144 r269228  
    17031703    float thickness;
    17041704    float length;
    1705     if (side == BSTop || side == BSBottom) {
     1705    if (side == BoxSide::Top || side == BoxSide::Bottom) {
    17061706        thickness = y2 - y1;
    17071707        length = x2 - x1;
     
    17491749
    17501750            switch (side) {
    1751             case BSTop:
    1752             case BSBottom:
     1751            case BoxSide::Top:
     1752            case BoxSide::Bottom:
    17531753                drawBorderRect(snapRectToDevicePixels(LayoutRect(x1, y1, length, thirdOfThickness), deviceScaleFactor));
    17541754                drawBorderRect(snapRectToDevicePixels(LayoutRect(x1, y2 - thirdOfThickness, length, thirdOfThickness), deviceScaleFactor));
    17551755                break;
    1756             case BSLeft:
    1757             case BSRight:
     1756            case BoxSide::Left:
     1757            case BoxSide::Right:
    17581758                drawBorderRect(snapRectToDevicePixels(LayoutRect(x1, y1, thirdOfThickness, length), deviceScaleFactor));
    17591759                drawBorderRect(snapRectToDevicePixels(LayoutRect(x2 - thirdOfThickness, y1, thirdOfThickness, length), deviceScaleFactor));
     
    17771777            FloatRect paintBorderRect;
    17781778            switch (side) {
    1779             case BSTop:
     1779            case BoxSide::Top:
    17801780                paintBorderRect = snapRectToDevicePixels(LayoutRect(x1 + mitreOffset1, y1, (x2 - mitreOffset3) - (x1 + mitreOffset1), thirdOfThickness), deviceScaleFactor);
    17811781                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
     
    17841784                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
    17851785                break;
    1786             case BSLeft:
     1786            case BoxSide::Left:
    17871787                paintBorderRect = snapRectToDevicePixels(LayoutRect(x1, y1 + mitreOffset1, thirdOfThickness, (y2 - mitreOffset3) - (y1 + mitreOffset1)), deviceScaleFactor);
    17881788                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
     
    17911791                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
    17921792                break;
    1793             case BSBottom:
     1793            case BoxSide::Bottom:
    17941794                paintBorderRect = snapRectToDevicePixels(LayoutRect(x1 + mitreOffset2, y1, (x2 - mitreOffset4) - (x1 + mitreOffset2), thirdOfThickness), deviceScaleFactor);
    17951795                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
     
    17981798                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
    17991799                break;
    1800             case BSRight:
     1800            case BoxSide::Right:
    18011801                paintBorderRect = snapRectToDevicePixels(LayoutRect(x1, y1 + mitreOffset2, thirdOfThickness, (y2 - mitreOffset4) - (y1 + mitreOffset2)), deviceScaleFactor);
    18021802                drawLineFor(paintBorderRect, side, BorderStyle::Solid, FloatSize(adjacent1BigThird, adjacent2BigThird));
     
    18341834        float offset4 = 0;
    18351835
    1836         if (((side == BSTop || side == BSLeft) && adjacentWidth1 < 0) || ((side == BSBottom || side == BSRight) && adjacentWidth1 > 0))
     1836        if (((side == BoxSide::Top || side == BoxSide::Left) && adjacentWidth1 < 0) || ((side == BoxSide::Bottom || side == BoxSide::Right) && adjacentWidth1 > 0))
    18371837            offset1 = floorToDevicePixel(adjacentWidth1 / 2, deviceScaleFactor);
    18381838
    1839         if (((side == BSTop || side == BSLeft) && adjacentWidth2 < 0) || ((side == BSBottom || side == BSRight) && adjacentWidth2 > 0))
     1839        if (((side == BoxSide::Top || side == BoxSide::Left) && adjacentWidth2 < 0) || ((side == BoxSide::Bottom || side == BoxSide::Right) && adjacentWidth2 > 0))
    18401840            offset2 = ceilToDevicePixel(adjacentWidth2 / 2, deviceScaleFactor);
    18411841
    1842         if (((side == BSTop || side == BSLeft) && adjacentWidth1 > 0) || ((side == BSBottom || side == BSRight) && adjacentWidth1 < 0))
     1842        if (((side == BoxSide::Top || side == BoxSide::Left) && adjacentWidth1 > 0) || ((side == BoxSide::Bottom || side == BoxSide::Right) && adjacentWidth1 < 0))
    18431843            offset3 = floorToDevicePixel(fabs(adjacentWidth1) / 2, deviceScaleFactor);
    18441844
    1845         if (((side == BSTop || side == BSLeft) && adjacentWidth2 > 0) || ((side == BSBottom || side == BSRight) && adjacentWidth2 < 0))
     1845        if (((side == BoxSide::Top || side == BoxSide::Left) && adjacentWidth2 > 0) || ((side == BoxSide::Bottom || side == BoxSide::Right) && adjacentWidth2 < 0))
    18461846            offset4 = ceilToDevicePixel(adjacentWidth2 / 2, deviceScaleFactor);
    18471847
     
    18551855
    18561856        switch (side) {
    1857         case BSTop:
     1857        case BoxSide::Top:
    18581858            drawLineFor(FloatRect(FloatPoint(x1 + offset1, y1), FloatPoint(x2 - offset2, adjustedY)), side, s1, FloatSize(adjacent1BigHalf, adjacent2BigHalf));
    18591859            drawLineFor(FloatRect(FloatPoint(x1 + offset3, adjustedY), FloatPoint(x2 - offset4, y2)), side, s2, FloatSize(adjacent1SmallHalf, adjacent2SmallHalf));
    18601860            break;
    1861         case BSLeft:
     1861        case BoxSide::Left:
    18621862            drawLineFor(FloatRect(FloatPoint(x1, y1 + offset1), FloatPoint(adjustedX, y2 - offset2)), side, s1, FloatSize(adjacent1BigHalf, adjacent2BigHalf));
    18631863            drawLineFor(FloatRect(FloatPoint(adjustedX, y1 + offset3), FloatPoint(x2, y2 - offset4)), side, s2, FloatSize(adjacent1SmallHalf, adjacent2SmallHalf));
    18641864            break;
    1865         case BSBottom:
     1865        case BoxSide::Bottom:
    18661866            drawLineFor(FloatRect(FloatPoint(x1 + offset1, y1), FloatPoint(x2 - offset2, adjustedY)), side, s2, FloatSize(adjacent1BigHalf, adjacent2BigHalf));
    18671867            drawLineFor(FloatRect(FloatPoint(x1 + offset3, adjustedY), FloatPoint(x2 - offset4, y2)), side, s1, FloatSize(adjacent1SmallHalf, adjacent2SmallHalf));
    18681868            break;
    1869         case BSRight:
     1869        case BoxSide::Right:
    18701870            drawLineFor(FloatRect(FloatPoint(x1, y1 + offset1), FloatPoint(adjustedX, y2 - offset2)), side, s2, FloatSize(adjacent1BigHalf, adjacent2BigHalf));
    18711871            drawLineFor(FloatRect(FloatPoint(adjustedX, y1 + offset3), FloatPoint(x2, y2 - offset4)), side, s1, FloatSize(adjacent1SmallHalf, adjacent2SmallHalf));
     
    19021902        quad.reserveInitialCapacity(4);
    19031903        switch (side) {
    1904         case BSTop:
     1904        case BoxSide::Top:
    19051905            quad.uncheckedAppend({ x1 + std::max<float>(-adjacentWidth1, 0), y1 });
    19061906            quad.uncheckedAppend({ x1 + std::max<float>( adjacentWidth1, 0), y2 });
     
    19081908            quad.uncheckedAppend({ x2 - std::max<float>(-adjacentWidth2, 0), y1 });
    19091909            break;
    1910         case BSBottom:
     1910        case BoxSide::Bottom:
    19111911            quad.uncheckedAppend({ x1 + std::max<float>( adjacentWidth1, 0), y1 });
    19121912            quad.uncheckedAppend({ x1 + std::max<float>(-adjacentWidth1, 0), y2 });
     
    19141914            quad.uncheckedAppend({ x2 - std::max<float>( adjacentWidth2, 0), y1 });
    19151915            break;
    1916         case BSLeft:
     1916        case BoxSide::Left:
    19171917            quad.uncheckedAppend({ x1, y1 + std::max<float>(-adjacentWidth1, 0) });
    19181918            quad.uncheckedAppend({ x1, y2 - std::max<float>(-adjacentWidth2, 0) });
     
    19201920            quad.uncheckedAppend({ x2, y1 + std::max<float>( adjacentWidth1, 0) });
    19211921            break;
    1922         case BSRight:
     1922        case BoxSide::Right:
    19231923            quad.uncheckedAppend({ x1, y1 + std::max<float>( adjacentWidth1, 0) });
    19241924            quad.uncheckedAppend({ x1, y2 - std::max<float>( adjacentWidth2, 0) });
     
    20842084    float bottomInner = std::min(inner.maxY(), bottomOuter);
    20852085
    2086     drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, topOuter), FloatPoint(leftInner, bottomOuter)), BSLeft, outlineColor, outlineStyle, outlineWidth, outlineWidth);
    2087     drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, topOuter), FloatPoint(rightOuter, topInner)), BSTop, outlineColor, outlineStyle, outlineWidth, outlineWidth);
    2088     drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(rightInner, topOuter), FloatPoint(rightOuter, bottomOuter)), BSRight, outlineColor, outlineStyle, outlineWidth, outlineWidth);
    2089     drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, bottomInner), FloatPoint(rightOuter, bottomOuter)), BSBottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
     2086    drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, topOuter), FloatPoint(leftInner, bottomOuter)), BoxSide::Left, outlineColor, outlineStyle, outlineWidth, outlineWidth);
     2087    drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, topOuter), FloatPoint(rightOuter, topInner)), BoxSide::Top, outlineColor, outlineStyle, outlineWidth, outlineWidth);
     2088    drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(rightInner, topOuter), FloatPoint(rightOuter, bottomOuter)), BoxSide::Right, outlineColor, outlineStyle, outlineWidth, outlineWidth);
     2089    drawLineForBoxSide(graphicsContext, FloatRect(FloatPoint(leftOuter, bottomInner), FloatPoint(rightOuter, bottomOuter)), BoxSide::Bottom, outlineColor, outlineStyle, outlineWidth, outlineWidth);
    20902090
    20912091    if (useTransparencyLayer)
  • trunk/Source/WebCore/rendering/RenderInline.cpp

    r261941 r269228  
    12851285        adjacentWidth2 = -outlineWidth;
    12861286    }
    1287     drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSLeft, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1287    drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Left, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    12881288   
    12891289    // right edge
     
    13041304        adjacentWidth2 = -outlineWidth;
    13051305    }
    1306     drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSRight, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1306    drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Right, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13071307
    13081308    // upper edge
     
    13181318        } else
    13191319            adjacentWidth2 = outlineWidth;
    1320         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSTop, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1320        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Top, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13211321    }
    13221322   
     
    13321332        bottomRight.move(outlineWidth, 0);
    13331333        adjacentWidth2 = outlineWidth;
    1334         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSTop, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1334        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Top, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13351335    }
    13361336
     
    13421342        bottomRight.move(outlineWidth, 0);
    13431343        adjacentWidth2 = outlineWidth;
    1344         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSTop, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1344        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Top, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13451345    }
    13461346
     
    13571357        } else
    13581358            adjacentWidth2 = outlineWidth;
    1359         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSBottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1359        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Bottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13601360    }
    13611361   
     
    13711371        bottomRight.move(outlineWidth, outlineWidth);
    13721372        adjacentWidth2 = outlineWidth;
    1373         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSBottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1373        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Bottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13741374    }
    13751375
     
    13811381        bottomRight.move(outlineWidth, outlineWidth);
    13821382        adjacentWidth2 = outlineWidth;
    1383         drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BSBottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
     1383        drawLineForBoxSide(graphicsContext, FloatRect(topLeft, bottomRight), BoxSide::Bottom, outlineColor, outlineStyle, adjacentWidth1, adjacentWidth2, antialias);
    13841384    }
    13851385}
  • trunk/Source/WebCore/rendering/RenderMultiColumnSet.cpp

    r258508 r269228  
    604604        LayoutUnit inlineDirectionSize = computedColumnWidth();
    605605        BoxSide boxSide = isHorizontalWritingMode()
    606             ? leftToRight ? BSLeft : BSRight
    607             : leftToRight ? BSTop : BSBottom;
     606            ? leftToRight ? BoxSide::Left : BoxSide::Right
     607            : leftToRight ? BoxSide::Top : BoxSide::Bottom;
    608608
    609609        for (unsigned i = 0; i < colCount; i++) {
     
    646646        ruleRect.moveBy(paintOffset);
    647647
    648         BoxSide boxSide = isHorizontalWritingMode() ? topToBottom ? BSTop : BSBottom : topToBottom ? BSLeft : BSRight;
     648        BoxSide boxSide = isHorizontalWritingMode() ? topToBottom ? BoxSide::Top : BoxSide::Bottom : topToBottom ? BoxSide::Left : BoxSide::Right;
    649649
    650650        LayoutSize step(0_lu, topToBottom ? computedColumnHeight() + colGap : -(computedColumnHeight() + colGap));
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r267363 r269228  
    18271827    enum Operation { Darken, Lighten };
    18281828
    1829     Operation operation = (side == BSTop || side == BSLeft) == (style == BorderStyle::Inset) ? Darken : Lighten;
     1829    Operation operation = (side == BoxSide::Top || side == BoxSide::Left) == (style == BorderStyle::Inset) ? Darken : Lighten;
    18301830
    18311831    // Here we will darken the border decoration color when needed. This will yield a similar behavior as in FF.
  • trunk/Source/WebCore/rendering/RenderObjectEnums.h

    r202167 r269228  
    4848};
    4949
    50 // Sides used when drawing borders and outlines. The values should run clockwise from top.
    51 enum BoxSide {
    52     BSTop,
    53     BSRight,
    54     BSBottom,
    55     BSLeft
    56 };
    57 
    5850enum MarkingBehavior {
    5951    MarkOnlyThis,
  • trunk/Source/WebCore/rendering/RenderTableCell.cpp

    r268919 r269228  
    12521252    // precedence paint on top of borders with lower precedence. 
    12531253    CollapsedBorders borders;
    1254     borders.addBorder(topVal, BSTop, renderTop, borderRect.x(), borderRect.y(), borderRect.maxX(), borderRect.y() + topWidth, topStyle);
    1255     borders.addBorder(bottomVal, BSBottom, renderBottom, borderRect.x(), borderRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), bottomStyle);
    1256     borders.addBorder(leftVal, BSLeft, renderLeft, borderRect.x(), borderRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), leftStyle);
    1257     borders.addBorder(rightVal, BSRight, renderRight, borderRect.maxX() - rightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), rightStyle);
     1254    borders.addBorder(topVal, BoxSide::Top, renderTop, borderRect.x(), borderRect.y(), borderRect.maxX(), borderRect.y() + topWidth, topStyle);
     1255    borders.addBorder(bottomVal, BoxSide::Bottom, renderBottom, borderRect.x(), borderRect.maxY() - bottomWidth, borderRect.maxX(), borderRect.maxY(), bottomStyle);
     1256    borders.addBorder(leftVal, BoxSide::Left, renderLeft, borderRect.x(), borderRect.y(), borderRect.x() + leftWidth, borderRect.maxY(), leftStyle);
     1257    borders.addBorder(rightVal, BoxSide::Right, renderRight, borderRect.maxX() - rightWidth, borderRect.y(), borderRect.maxX(), borderRect.maxY(), rightStyle);
    12581258
    12591259    bool antialias = shouldAntialiasLines(graphicsContext);
  • trunk/Source/WebCore/rendering/RenderTableSection.cpp

    r268919 r269228  
    10971097    bool isLastRow = row + 1 == m_grid.size();
    10981098    if (style().isHorizontalWritingMode())
    1099         return m_rowPos[row] + (!row && borderSide == BSRight ? -outerBorderTop(&style()) : isLastRow && borderSide == BSLeft ? outerBorderTop(&style()) : 0_lu);
     1099        return m_rowPos[row] + (!row && borderSide == BoxSide::Right ? -outerBorderTop(&style()) : isLastRow && borderSide == BoxSide::Left ? outerBorderTop(&style()) : 0_lu);
    11001100    if (style().isLeftToRightDirection())
    1101         return (cell ? cell->y() + cell->height() : 0_lu) + (borderSide == BSLeft ? outerBorderTop(&style()) : 0_lu);
    1102     return borderSide == BSRight ? -outerBorderTop(&style()) : 0_lu;
     1101        return (cell ? cell->y() + cell->height() : 0_lu) + (borderSide == BoxSide::Left ? outerBorderTop(&style()) : 0_lu);
     1102    return borderSide == BoxSide::Right ? -outerBorderTop(&style()) : 0_lu;
    11031103}
    11041104
     
    11341134    bool antialias = shouldAntialiasLines(paintInfo.context());
    11351135    LayoutRect rowGroupRect = LayoutRect(paintOffset, size());
    1136     rowGroupRect.moveBy(-LayoutPoint(outerBorderLeft(&style), (borderSide == BSRight) ? 0_lu : outerBorderTop(&style)));
     1136    rowGroupRect.moveBy(-LayoutPoint(outerBorderLeft(&style), (borderSide == BoxSide::Right) ? 0_lu : outerBorderTop(&style)));
    11371137
    11381138    switch (borderSide) {
    1139     case BSTop:
     1139    case BoxSide::Top:
    11401140        paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y(),
    1141             horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), LayoutUnit(style.borderTop().width())), BSTop, CSSPropertyBorderTopColor, style.borderTopStyle(), table()->style().borderTopStyle());
     1141            horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), LayoutUnit(style.borderTop().width())), BoxSide::Top, CSSPropertyBorderTopColor, style.borderTopStyle(), table()->style().borderTopStyle());
    11421142        break;
    1143     case BSBottom:
     1143    case BoxSide::Bottom:
    11441144        paintRowGroupBorder(paintInfo, antialias, LayoutRect(paintOffset.x() + offsetLeftForRowGroupBorder(cell, rowGroupRect, row), rowGroupRect.y() + rowGroupRect.height(),
    1145             horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), LayoutUnit(style.borderBottom().width())), BSBottom, CSSPropertyBorderBottomColor, style.borderBottomStyle(), table()->style().borderBottomStyle());
     1145            horizontalRowGroupBorderWidth(cell, rowGroupRect, row, column), LayoutUnit(style.borderBottom().width())), BoxSide::Bottom, CSSPropertyBorderBottomColor, style.borderBottomStyle(), table()->style().borderBottomStyle());
    11461146        break;
    1147     case BSLeft:
     1147    case BoxSide::Left:
    11481148        paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), LayoutUnit(style.borderLeft().width()),
    1149             verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSLeft, CSSPropertyBorderLeftColor, style.borderLeftStyle(), table()->style().borderLeftStyle());
     1149            verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BoxSide::Left, CSSPropertyBorderLeftColor, style.borderLeftStyle(), table()->style().borderLeftStyle());
    11501150        break;
    1151     case BSRight:
     1151    case BoxSide::Right:
    11521152        paintRowGroupBorder(paintInfo, antialias, LayoutRect(rowGroupRect.x() + rowGroupRect.width(), rowGroupRect.y() + offsetTopForRowGroupBorder(cell, borderSide, row), LayoutUnit(style.borderRight().width()),
    1153             verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BSRight, CSSPropertyBorderRightColor, style.borderRightStyle(), table()->style().borderRightStyle());
     1153            verticalRowGroupBorderHeight(cell, rowGroupRect, row)), BoxSide::Right, CSSPropertyBorderRightColor, style.borderRightStyle(), table()->style().borderRightStyle());
    11541154        break;
    11551155    default:
     
    11651165    case CBSStart:
    11661166        if (styleForCellFlow->isHorizontalWritingMode())
    1167             return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight;
    1168         return styleForCellFlow->isLeftToRightDirection() ? BSTop : BSBottom;
     1167            return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Left : BoxSide::Right;
     1168        return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Top : BoxSide::Bottom;
    11691169    case CBSEnd:
    11701170        if (styleForCellFlow->isHorizontalWritingMode())
    1171             return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft;
    1172         return styleForCellFlow->isLeftToRightDirection() ? BSBottom : BSTop;
     1171            return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Right : BoxSide::Left;
     1172        return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Bottom : BoxSide::Top;
    11731173    case CBSBefore:
    11741174        if (styleForCellFlow->isHorizontalWritingMode())
    1175             return BSTop;
    1176         return styleForCellFlow->isLeftToRightDirection() ? BSRight : BSLeft;
     1175            return BoxSide::Top;
     1176        return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Right : BoxSide::Left;
    11771177    case CBSAfter:
    11781178        if (styleForCellFlow->isHorizontalWritingMode())
    1179             return BSBottom;
    1180         return styleForCellFlow->isLeftToRightDirection() ? BSLeft : BSRight;
     1179            return BoxSide::Bottom;
     1180        return styleForCellFlow->isLeftToRightDirection() ? BoxSide::Left : BoxSide::Right;
    11811181    default:
    11821182        ASSERT_NOT_REACHED();
    1183         return BSLeft;
     1183        return BoxSide::Left;
    11841184    }
    11851185}
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r267760 r269228  
    696696    float separatorPosition = isRTL ? (clip.x() + MenuListButtonPaddingAfter) : (clip.maxX() - MenuListButtonPaddingAfter);
    697697
    698     box.drawLineForBoxSide(paintInfo.context(), FloatRect(FloatPoint(separatorPosition - borderTopWidth, clip.y()), FloatPoint(separatorPosition, clip.maxY())), BSRight, style.visitedDependentColor(CSSPropertyBorderTopColor), style.borderTopStyle(), 0, 0);
     698    box.drawLineForBoxSide(paintInfo.context(), FloatRect(FloatPoint(separatorPosition - borderTopWidth, clip.y()), FloatPoint(separatorPosition, clip.maxY())), BoxSide::Right, style.visitedDependentColor(CSSPropertyBorderTopColor), style.borderTopStyle(), 0, 0);
    699699
    700700    FloatRect buttonClip;
  • trunk/Source/WebCore/rendering/style/NinePieceImage.h

    r260311 r269228  
    8383}
    8484
    85 inline Optional<PhysicalBoxSide> imagePieceHorizontalSide(ImagePiece piece)
     85inline Optional<BoxSide> imagePieceHorizontalSide(ImagePiece piece)
    8686{
    8787    if (piece == TopLeftPiece || piece == TopPiece || piece == TopRightPiece)
    88         return PhysicalBoxSide::Top;
     88        return BoxSide::Top;
    8989
    9090    if (piece == BottomLeftPiece || piece == BottomPiece || piece == BottomRightPiece)
    91         return PhysicalBoxSide::Bottom;
     91        return BoxSide::Bottom;
    9292
    9393    return WTF::nullopt;
    9494}
    9595
    96 inline Optional<PhysicalBoxSide> imagePieceVerticalSide(ImagePiece piece)
     96inline Optional<BoxSide> imagePieceVerticalSide(ImagePiece piece)
    9797{
    9898    if (piece == TopLeftPiece || piece == LeftPiece || piece == BottomLeftPiece)
    99         return PhysicalBoxSide::Left;
     99        return BoxSide::Left;
    100100
    101101    if (piece == TopRightPiece || piece == RightPiece || piece == BottomRightPiece)
    102         return PhysicalBoxSide::Right;
     102        return BoxSide::Right;
    103103
    104104    return WTF::nullopt;
  • trunk/Source/WebKit/ChangeLog

    r269210 r269228  
     12020-10-31  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Clean up BoxSide and BorderEdge code
     4        https://bugs.webkit.org/show_bug.cgi?id=218197
     5
     6        Reviewed by Sam Weinig.
     7
     8        * UIProcess/ios/WKKeyboardScrollingAnimator.mm:
     9        (boxSide):
     10
    1112020-10-30  Brian Burg  <bburg@apple.com>
    212
  • trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm

    r261436 r269228  
    164164}
    165165
    166 static WebCore::PhysicalBoxSide boxSide(WebKit::ScrollingDirection direction)
     166static WebCore::BoxSide boxSide(WebKit::ScrollingDirection direction)
    167167{
    168168    switch (direction) {
    169169    case WebKit::ScrollingDirection::Up:
    170         return WebCore::PhysicalBoxSide::Top;
     170        return WebCore::BoxSide::Top;
    171171    case WebKit::ScrollingDirection::Down:
    172         return WebCore::PhysicalBoxSide::Bottom;
     172        return WebCore::BoxSide::Bottom;
    173173    case WebKit::ScrollingDirection::Left:
    174         return WebCore::PhysicalBoxSide::Left;
     174        return WebCore::BoxSide::Left;
    175175    case WebKit::ScrollingDirection::Right:
    176         return WebCore::PhysicalBoxSide::Right;
     176        return WebCore::BoxSide::Right;
    177177    }
    178178}
Note: See TracChangeset for help on using the changeset viewer.