Changeset 287863 in webkit
- Timestamp:
- Jan 10, 2022, 3:48:40 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/images/text-recognition/image-overlay-line-wrapping-expected.txt (added)
-
LayoutTests/fast/images/text-recognition/image-overlay-line-wrapping.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/PAL/ChangeLog (modified) (1 diff)
-
Source/WebCore/PAL/pal/spi/cocoa/VisionKitCoreSPI.h (modified) (1 diff)
-
Source/WebCore/dom/ImageOverlay.cpp (modified) (5 diffs)
-
Source/WebCore/platform/TextRecognitionResult.h (modified) (4 diffs)
-
Source/WebCore/testing/Internals.cpp (modified) (1 diff)
-
Source/WebCore/testing/Internals.h (modified) (1 diff)
-
Source/WebCore/testing/Internals.idl (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r287854 r287863 1 2022-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 1 14 2022-01-10 Chris Dumez <cdumez@apple.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r287862 r287863 1 2022-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 1 36 2022-01-10 Eric Carlson <eric.carlson@apple.com> 2 37 -
trunk/Source/WebCore/PAL/ChangeLog
r287848 r287863 1 2022-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 1 13 2022-01-10 Alex Christensen <achristensen@webkit.org> 2 14 -
trunk/Source/WebCore/PAL/pal/spi/cocoa/VisionKitCoreSPI.h
r285973 r287863 147 147 #endif 148 148 149 @interface VKWKLineInfo (Staging_85139101) 150 @property (nonatomic, readonly) BOOL shouldWrap; 151 @end 152 149 153 #if USE(APPLE_INTERNAL_SDK) 150 154 #include <WebKitAdditions/VisionKitCoreSPIAdditions.h> -
trunk/Source/WebCore/dom/ImageOverlay.cpp
r286366 r287863 193 193 Ref<HTMLDivElement> line; 194 194 Vector<Ref<HTMLElement>> children; 195 RefPtr<HTMLBRElement> lineBreak; 195 196 }; 196 197 … … 254 255 255 256 ASSERT(classes.contains(imageOverlayLineClass())); 256 LineElements lineElements { childElement, { } };257 Vector<Ref<HTMLElement>> lineChildren; 257 258 for (auto& text : childrenOfType<HTMLDivElement>(childElement)) 258 line Elements.children.append(text);259 elements.lines.append( WTFMove(lineElements));259 lineChildren.append(text); 260 elements.lines.append({ childElement, WTFMove(lineChildren), childrenOfType<HTMLBRElement>(childElement).first() }); 260 261 } 261 262 … … 271 272 272 273 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 275 282 if (childResults.size() != childTextElements.size()) 276 283 return false; … … 318 325 lineContainer->classList().add(imageOverlayLineClass()); 319 326 rootContainer->appendChild(lineContainer); 320 LineElements lineElements { lineContainer, { } };327 LineElements lineElements { lineContainer, { }, { } }; 321 328 lineElements.children.reserveInitialCapacity(line.children.size()); 322 329 for (size_t childIndex = 0; childIndex < line.children.size(); ++childIndex) { … … 329 336 } 330 337 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 332 343 elements.lines.uncheckedAppend(WTFMove(lineElements)); 333 344 } -
trunk/Source/WebCore/platform/TextRecognitionResult.h
r285670 r287863 82 82 83 83 struct TextRecognitionLineData { 84 TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren )84 TextRecognitionLineData(FloatQuad&& quad, Vector<TextRecognitionWordData>&& theChildren, bool wrap) 85 85 : normalizedQuad(WTFMove(quad)) 86 86 , children(WTFMove(theChildren)) 87 , shouldWrap(wrap) 87 88 { 88 89 } … … 90 91 FloatQuad normalizedQuad; 91 92 Vector<TextRecognitionWordData> children; 93 bool shouldWrap { false }; 92 94 93 95 template<class Encoder> void encode(Encoder&) const; … … 115 117 encoder << normalizedQuad; 116 118 encoder << children; 119 encoder << shouldWrap; 117 120 } 118 121 … … 129 132 return std::nullopt; 130 133 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 } }; 132 140 } 133 141 -
trunk/Source/WebCore/testing/Internals.cpp
r287810 r287863 5770 5770 line.children.map([](auto& textChild) -> TextRecognitionWordData { 5771 5771 return { textChild.text, getQuad<Internals::ImageOverlayText>(textChild), textChild.hasLeadingWhitespace }; 5772 }) 5772 }), 5773 line.shouldWrap 5773 5774 }; 5774 5775 } -
trunk/Source/WebCore/testing/Internals.h
r287810 r287863 923 923 RefPtr<DOMPointReadOnly> bottomLeft; 924 924 Vector<ImageOverlayText> children; 925 bool shouldWrap { false }; 925 926 926 927 ~ImageOverlayLine(); -
trunk/Source/WebCore/testing/Internals.idl
r287810 r287863 293 293 required DOMPointReadOnly bottomLeft; 294 294 sequence<ImageOverlayText> children; 295 boolean shouldWrap = false; 295 296 }; 296 297 -
trunk/Source/WebKit/ChangeLog
r287848 r287863 1 2022-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 1 15 2022-01-10 Alex Christensen <achristensen@webkit.org> 2 16 -
trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm
r285973 r287863 115 115 children.uncheckedAppend({ WTFMove(childText), floatQuad(child.quad), hasLeadingWhitespace }); 116 116 } 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 }); 118 122 isFirstLine = false; 119 123 }
Note:
See TracChangeset
for help on using the changeset viewer.