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

Changeset 287863 in webkit


Ignore:
Timestamp:
Jan 10, 2022, 3:48:40 PM (5 years ago)
Author:
Wenson Hsieh
Message:

Add support for a -shouldWrap property when injecting Live Text
https://bugs.webkit.org/show_bug.cgi?id=235035
rdar://85139146

Reviewed by Tim Horton.

Source/WebCore:

Add support for a new property on VKWKLineInfo to indicate whether or not the line should wrap. If set to true,
we will avoid adding a br element at the end of the div.image-overlay-line that corresponds to the line of
recognized text in the image overlay; currently, we always add this trailing br.

Test: fast/images/text-recognition/image-overlay-line-wrapping.html

  • dom/ImageOverlay.cpp:

(WebCore::ImageOverlay::updateSubtree):

Consult the flag when converting each TextRecognitionLineData into shadow DOM elements.

  • platform/TextRecognitionResult.h:

Add the new boolean flag to TextRecognitionLineData, and add encoding/decoding support.

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

  • testing/Internals.cpp:

(WebCore::makeDataForLine):

Add a way to specify a value for shouldWrap, when using internals to inject image overlay content in layout
and API tests.

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

Source/WebCore/PAL:

Add a forward staging declaration for the new SPI property.

  • pal/spi/cocoa/VisionKitCoreSPI.h:

Source/WebKit:

Consult the new SPI property (behind a runtime selector check), and pass the boolean flag through the
TextRecognitionResult.

  • Platform/cocoa/TextRecognitionUtilities.mm:

(WebKit::makeTextRecognitionResult):

LayoutTests:

Add a layout test to exercise the changes. See WebCore/ChangeLog for more details.

  • fast/images/text-recognition/image-overlay-line-wrapping-expected.txt: Added.
  • fast/images/text-recognition/image-overlay-line-wrapping.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287854 r287863  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for a -shouldWrap property when injecting Live Text
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a layout test to exercise the changes. See WebCore/ChangeLog for more details.
     10
     11        * fast/images/text-recognition/image-overlay-line-wrapping-expected.txt: Added.
     12        * fast/images/text-recognition/image-overlay-line-wrapping.html: Added.
     13
    1142022-01-10  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r287862 r287863  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for a -shouldWrap property when injecting Live Text
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Add support for a new property on VKWKLineInfo to indicate whether or not the line should wrap. If set to true,
     10        we will avoid adding a `br` element at the end of the `div.image-overlay-line` that corresponds to the line of
     11        recognized text in the image overlay; currently, we always add this trailing `br`.
     12
     13        Test: fast/images/text-recognition/image-overlay-line-wrapping.html
     14
     15        * dom/ImageOverlay.cpp:
     16        (WebCore::ImageOverlay::updateSubtree):
     17
     18        Consult the flag when converting each TextRecognitionLineData into shadow DOM elements.
     19
     20        * platform/TextRecognitionResult.h:
     21
     22        Add the new boolean flag to TextRecognitionLineData, and add encoding/decoding support.
     23
     24        (WebCore::TextRecognitionLineData::TextRecognitionLineData):
     25        (WebCore::TextRecognitionLineData::encode const):
     26        (WebCore::TextRecognitionLineData::decode):
     27        * testing/Internals.cpp:
     28        (WebCore::makeDataForLine):
     29
     30        Add a way to specify a value for `shouldWrap`, when using `internals` to inject image overlay content in layout
     31        and API tests.
     32
     33        * testing/Internals.h:
     34        * testing/Internals.idl:
     35
    1362022-01-10  Eric Carlson  <eric.carlson@apple.com>
    237
  • trunk/Source/WebCore/PAL/ChangeLog

    r287848 r287863  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for a -shouldWrap property when injecting Live Text
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a forward staging declaration for the new SPI property.
     10
     11        * pal/spi/cocoa/VisionKitCoreSPI.h:
     12
    1132022-01-10  Alex Christensen  <achristensen@webkit.org>
    214
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/VisionKitCoreSPI.h

    r285973 r287863  
    147147#endif
    148148
     149@interface VKWKLineInfo (Staging_85139101)
     150@property (nonatomic, readonly) BOOL shouldWrap;
     151@end
     152
    149153#if USE(APPLE_INTERNAL_SDK)
    150154#include <WebKitAdditions/VisionKitCoreSPIAdditions.h>
  • trunk/Source/WebCore/dom/ImageOverlay.cpp

    r286366 r287863  
    193193    Ref<HTMLDivElement> line;
    194194    Vector<Ref<HTMLElement>> children;
     195    RefPtr<HTMLBRElement> lineBreak;
    195196};
    196197
     
    254255
    255256            ASSERT(classes.contains(imageOverlayLineClass()));
    256             LineElements lineElements { childElement, { } };
     257            Vector<Ref<HTMLElement>> lineChildren;
    257258            for (auto& text : childrenOfType<HTMLDivElement>(childElement))
    258                 lineElements.children.append(text);
    259             elements.lines.append(WTFMove(lineElements));
     259                lineChildren.append(text);
     260            elements.lines.append({ childElement, WTFMove(lineChildren), childrenOfType<HTMLBRElement>(childElement).first() });
    260261        }
    261262
     
    271272
    272273            for (size_t lineIndex = 0; lineIndex < result.lines.size(); ++lineIndex) {
    273                 auto& childResults = result.lines[lineIndex].children;
    274                 auto& childTextElements = elements.lines[lineIndex].children;
     274                auto& lineResult = result.lines[lineIndex];
     275                auto& childResults = lineResult.children;
     276
     277                auto& lineElements = elements.lines[lineIndex];
     278                auto& childTextElements = lineElements.children;
     279                if (lineResult.shouldWrap != !lineElements.lineBreak)
     280                    return false;
     281
    275282                if (childResults.size() != childTextElements.size())
    276283                    return false;
     
    318325            lineContainer->classList().add(imageOverlayLineClass());
    319326            rootContainer->appendChild(lineContainer);
    320             LineElements lineElements { lineContainer, { } };
     327            LineElements lineElements { lineContainer, { }, { } };
    321328            lineElements.children.reserveInitialCapacity(line.children.size());
    322329            for (size_t childIndex = 0; childIndex < line.children.size(); ++childIndex) {
     
    329336            }
    330337
    331             lineContainer->appendChild(HTMLBRElement::create(document.get()));
     338            if (!line.shouldWrap) {
     339                lineElements.lineBreak = HTMLBRElement::create(document.get());
     340                lineContainer->appendChild(*lineElements.lineBreak);
     341            }
     342
    332343            elements.lines.uncheckedAppend(WTFMove(lineElements));
    333344        }
  • trunk/Source/WebCore/platform/TextRecognitionResult.h

    r285670 r287863  
    8282
    8383struct TextRecognitionLineData {
    84     TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren)
     84    TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool wrap)
    8585        : normalizedQuad(WTFMove(quad))
    8686        , children(WTFMove(theChildren))
     87        , shouldWrap(wrap)
    8788    {
    8889    }
     
    9091    FloatQuad normalizedQuad;
    9192    Vector<TextRecognitionWordData> children;
     93    bool shouldWrap { false };
    9294
    9395    template<class Encoder> void encode(Encoder&) const;
     
    115117    encoder << normalizedQuad;
    116118    encoder << children;
     119    encoder << shouldWrap;
    117120}
    118121
     
    129132        return std::nullopt;
    130133
    131     return {{ WTFMove(*normalizedQuad), WTFMove(*children) }};
     134    std::optional<bool> shouldWrap;
     135    decoder >> shouldWrap;
     136    if (!shouldWrap)
     137        return std::nullopt;
     138
     139    return { { WTFMove(*normalizedQuad), WTFMove(*children), *shouldWrap } };
    132140}
    133141
  • trunk/Source/WebCore/testing/Internals.cpp

    r287810 r287863  
    57705770        line.children.map([](auto& textChild) -> TextRecognitionWordData {
    57715771            return { textChild.text, getQuad<Internals::ImageOverlayText>(textChild), textChild.hasLeadingWhitespace };
    5772         })
     5772        }),
     5773        line.shouldWrap
    57735774    };
    57745775}
  • trunk/Source/WebCore/testing/Internals.h

    r287810 r287863  
    923923        RefPtr<DOMPointReadOnly> bottomLeft;
    924924        Vector<ImageOverlayText> children;
     925        bool shouldWrap { false };
    925926
    926927        ~ImageOverlayLine();
  • trunk/Source/WebCore/testing/Internals.idl

    r287810 r287863  
    293293    required DOMPointReadOnly bottomLeft;
    294294    sequence<ImageOverlayText> children;
     295    boolean shouldWrap = false;
    295296};
    296297
  • trunk/Source/WebKit/ChangeLog

    r287848 r287863  
     12022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add support for a -shouldWrap property when injecting Live Text
     4        https://bugs.webkit.org/show_bug.cgi?id=235035
     5        rdar://85139146
     6
     7        Reviewed by Tim Horton.
     8
     9        Consult the new SPI property (behind a runtime selector check), and pass the boolean flag through the
     10        TextRecognitionResult.
     11
     12        * Platform/cocoa/TextRecognitionUtilities.mm:
     13        (WebKit::makeTextRecognitionResult):
     14
    1152022-01-10  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm

    r285973 r287863  
    115115            children.uncheckedAppend({ WTFMove(childText), floatQuad(child.quad), hasLeadingWhitespace });
    116116        }
    117         result.lines.uncheckedAppend({ floatQuad(line.quad), WTFMove(children) });
     117        result.lines.uncheckedAppend({
     118            floatQuad(line.quad),
     119            WTFMove(children),
     120            [line respondsToSelector:@selector(shouldWrap)] && [line shouldWrap]
     121        });
    118122        isFirstLine = false;
    119123    }
Note: See TracChangeset for help on using the changeset viewer.