⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287866 in webkit


Ignore:
Timestamp:
Jan 10, 2022, 6:17:09 PM (5 years ago)
Author:
Wenson Hsieh
Message:

Followup to r287863 - adjust line wrapping behavior in image overlays
https://bugs.webkit.org/show_bug.cgi?id=235035
rdar://85139146

Reviewed by Tim Horton.

Source/WebCore:

The previous change I landed in r287863 was written under the assumption that -shouldWrap describes whether or
not a recognized line of text should wrap to the next line. However, after trying it out, it seems to indicate
whether or not the previous line of text should wrap to the current line. As a result, the current adoption of
this property is wrong, since the line wrapping is off-by-one.

Fix this by renaming the shouldWrap boolean flag in TextRecognitionLineData to the much less ambiguous name
hasTrailingNewline, and set hasTrailingNewline based on the shouldWrap property of the *next*
VKWKLineInfo.

  • dom/ImageOverlay.cpp:

(WebCore::ImageOverlay::updateSubtree):

Avoid a potentially even-more-confusing != !! here by using static_cast<> to check the nullity of the
RefPtr.

  • platform/TextRecognitionResult.h:

(WebCore::TextRecognitionLineData::TextRecognitionLineData):
(WebCore::TextRecognitionLineData::encode const):
(WebCore::TextRecognitionLineData::decode):

Make sure we also flip the default from false to true, since hasTrailingNewline is intended to have the
opposite effect as the extant shouldWrap.

  • testing/Internals.cpp:

(WebCore::makeDataForLine):

  • testing/Internals.h:
  • testing/Internals.idl:

Source/WebKit:

Use the -shouldWrap property to compute hasTrailingNewline. See WebCore/ChangeLog for more details.

  • Platform/cocoa/TextRecognitionUtilities.mm:

(WebKit::makeTextRecognitionResult):

LayoutTests:

Make a slight adjustment to an existing layout test (i.e. rename shouldWrap to hasTrailingNewline). See
WebCore/ChangeLog for more details.

  • fast/images/text-recognition/image-overlay-line-wrapping.html:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287863 r287866  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Followup to r287863 - adjust line wrapping behavior in image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Make a slight adjustment to an existing layout test (i.e. rename `shouldWrap` to `hasTrailingNewline`). See
     10        WebCore/ChangeLog for more details.
     11
     12        * fast/images/text-recognition/image-overlay-line-wrapping.html:
     13
    1142022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/LayoutTests/fast/images/text-recognition/image-overlay-line-wrapping.html

    r287863 r287866  
    2626            bottomRight : new DOMPointReadOnly(1, 0.3),
    2727            bottomLeft : new DOMPointReadOnly(0, 0.3),
    28             shouldWrap: true,
     28            hasTrailingNewline: false,
    2929            children: [
    3030                {
  • trunk/Source/WebCore/ChangeLog

    r287863 r287866  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Followup to r287863 - adjust line wrapping behavior in image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        The previous change I landed in r287863 was written under the assumption that `-shouldWrap` describes whether or
     10        not a recognized line of text should wrap to the next line. However, after trying it out, it seems to indicate
     11        whether or not the previous line of text should wrap to the current line. As a result, the current adoption of
     12        this property is wrong, since the line wrapping is off-by-one.
     13
     14        Fix this by renaming the `shouldWrap` boolean flag in TextRecognitionLineData to the much less ambiguous name
     15        `hasTrailingNewline`, and set `hasTrailingNewline` based on the `shouldWrap` property of the *next*
     16        VKWKLineInfo.
     17
     18        * dom/ImageOverlay.cpp:
     19        (WebCore::ImageOverlay::updateSubtree):
     20
     21        Avoid a potentially even-more-confusing `!= !!` here by using `static_cast<>` to check the nullity of the
     22        `RefPtr`.
     23
     24        * platform/TextRecognitionResult.h:
     25        (WebCore::TextRecognitionLineData::TextRecognitionLineData):
     26        (WebCore::TextRecognitionLineData::encode const):
     27        (WebCore::TextRecognitionLineData::decode):
     28
     29        Make sure we also flip the default from `false` to `true`, since `hasTrailingNewline` is intended to have the
     30        opposite effect as the extant `shouldWrap`.
     31
     32        * testing/Internals.cpp:
     33        (WebCore::makeDataForLine):
     34        * testing/Internals.h:
     35        * testing/Internals.idl:
     36
    1372022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    238
  • trunk/Source/WebCore/dom/ImageOverlay.cpp

    r287863 r287866  
    277277                auto& lineElements = elements.lines[lineIndex];
    278278                auto& childTextElements = lineElements.children;
    279                 if (lineResult.shouldWrap != !lineElements.lineBreak)
     279                if (lineResult.hasTrailingNewline != static_cast<bool>(lineElements.lineBreak))
    280280                    return false;
    281281
     
    336336            }
    337337
    338             if (!line.shouldWrap) {
     338            if (line.hasTrailingNewline) {
    339339                lineElements.lineBreak = HTMLBRElement::create(document.get());
    340340                lineContainer->appendChild(*lineElements.lineBreak);
  • trunk/Source/WebCore/platform/TextRecognitionResult.h

    r287863 r287866  
    8282
    8383struct TextRecognitionLineData {
    84     TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool wrap)
     84    TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool newline)
    8585        : normalizedQuad(WTFMove(quad))
    8686        , children(WTFMove(theChildren))
    87         , shouldWrap(wrap)
     87        , hasTrailingNewline(newline)
    8888    {
    8989    }
     
    9191    FloatQuad normalizedQuad;
    9292    Vector<TextRecognitionWordData> children;
    93     bool shouldWrap { false };
     93    bool hasTrailingNewline { true };
    9494
    9595    template<class Encoder> void encode(Encoder&) const;
     
    117117    encoder << normalizedQuad;
    118118    encoder << children;
    119     encoder << shouldWrap;
     119    encoder << hasTrailingNewline;
    120120}
    121121
     
    132132        return std::nullopt;
    133133
    134     std::optional<bool> shouldWrap;
    135     decoder >> shouldWrap;
    136     if (!shouldWrap)
    137         return std::nullopt;
    138 
    139     return { { WTFMove(*normalizedQuad), WTFMove(*children), *shouldWrap } };
     134    std::optional<bool> hasTrailingNewline;
     135    decoder >> hasTrailingNewline;
     136    if (!hasTrailingNewline)
     137        return std::nullopt;
     138
     139    return { { WTFMove(*normalizedQuad), WTFMove(*children), *hasTrailingNewline } };
    140140}
    141141
  • trunk/Source/WebCore/testing/Internals.cpp

    r287863 r287866  
    57715771            return { textChild.text, getQuad<Internals::ImageOverlayText>(textChild), textChild.hasLeadingWhitespace };
    57725772        }),
    5773         line.shouldWrap
     5773        line.hasTrailingNewline
    57745774    };
    57755775}
  • trunk/Source/WebCore/testing/Internals.h

    r287863 r287866  
    923923        RefPtr<DOMPointReadOnly> bottomLeft;
    924924        Vector<ImageOverlayText> children;
    925         bool shouldWrap { false };
     925        bool hasTrailingNewline { true };
    926926
    927927        ~ImageOverlayLine();
  • trunk/Source/WebCore/testing/Internals.idl

    r287863 r287866  
    293293    required DOMPointReadOnly bottomLeft;
    294294    sequence<ImageOverlayText> children;
    295     boolean shouldWrap = false;
     295    boolean hasTrailingNewline = true;
    296296};
    297297
  • trunk/Source/WebKit/ChangeLog

    r287863 r287866  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Followup to r287863 - adjust line wrapping behavior in image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Use the `-shouldWrap` property to compute `hasTrailingNewline`. See WebCore/ChangeLog for more details.
     10
     11        * Platform/cocoa/TextRecognitionUtilities.mm:
     12        (WebKit::makeTextRecognitionResult):
     13
    1142022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm

    r287863 r287866  
    7979TextRecognitionResult makeTextRecognitionResult(VKImageAnalysis *analysis)
    8080{
    81     NSArray<VKWKTextInfo *> *allLines = analysis.allLines;
     81    NSArray<VKWKLineInfo *> *allLines = analysis.allLines;
    8282    TextRecognitionResult result;
    8383    result.lines.reserveInitialCapacity(allLines.count);
    8484
    8585    bool isFirstLine = true;
     86    size_t nextLineIndex = 1;
    8687    for (VKWKLineInfo *line in allLines) {
    8788        Vector<TextRecognitionWordData> children;
     
    115116            children.uncheckedAppend({ WTFMove(childText), floatQuad(child.quad), hasLeadingWhitespace });
    116117        }
    117         result.lines.uncheckedAppend({
    118             floatQuad(line.quad),
    119             WTFMove(children),
    120             [line respondsToSelector:@selector(shouldWrap)] && [line shouldWrap]
    121         });
     118        VKWKLineInfo *nextLine = nextLineIndex < allLines.count ? allLines[nextLineIndex] : nil;
     119        // The `shouldWrap` property indicates whether or not a line should wrap, relative to the previous line.
     120        bool hasTrailingNewline = nextLine && (![nextLine respondsToSelector:@selector(shouldWrap)] || ![nextLine shouldWrap]);
     121        result.lines.uncheckedAppend({ floatQuad(line.quad), WTFMove(children), hasTrailingNewline });
    122122        isFirstLine = false;
     123        nextLineIndex++;
    123124    }
    124125
Note: See TracChangeset for help on using the changeset viewer.