Title: [272164] trunk/Source
Revision
272164
Author
[email protected]
Date
2021-02-01 12:22:05 -0800 (Mon, 01 Feb 2021)

Log Message

Add some new data structures to represent image extraction results
https://bugs.webkit.org/show_bug.cgi?id=221214

Reviewed by Sam Weinig.

Source/WebCore:

Introduce `ImageExtractionResult`, which will only contain a list of `ImageExtractionTextData` structures for
now; each `ImageExtractionTextData` is composed of a piece of text, as well as a normalized quad representing
the location of the text relative to the extracted image.

* platform/ImageExtractionResult.h: Added.
(WebCore::ImageExtractionTextData::encode const):
(WebCore::ImageExtractionTextData::decode):
(WebCore::ImageExtractionResult::isEmpty const):
(WebCore::ImageExtractionResult::encode const):
(WebCore::ImageExtractionResult::decode):
* platform/graphics/FloatQuad.h:
(WebCore::FloatQuad::encode const):
(WebCore::FloatQuad::decode):

Add generic encoding and decoding support for `WebCore::FloatQuad`, and remove iOS-specific WebKit2 argument
coder logic for serializing `FloatQuad` (see WebKit2 changes).

Source/WebKit:

See WebCore ChangeLog for more details.

* Shared/WebCoreArgumentCoders.cpp:
* Shared/WebCoreArgumentCoders.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272163 => 272164)


--- trunk/Source/WebCore/ChangeLog	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebCore/ChangeLog	2021-02-01 20:22:05 UTC (rev 272164)
@@ -1,3 +1,27 @@
+2021-02-01  Wenson Hsieh  <[email protected]>
+
+        Add some new data structures to represent image extraction results
+        https://bugs.webkit.org/show_bug.cgi?id=221214
+
+        Reviewed by Sam Weinig.
+
+        Introduce `ImageExtractionResult`, which will only contain a list of `ImageExtractionTextData` structures for
+        now; each `ImageExtractionTextData` is composed of a piece of text, as well as a normalized quad representing
+        the location of the text relative to the extracted image.
+
+        * platform/ImageExtractionResult.h: Added.
+        (WebCore::ImageExtractionTextData::encode const):
+        (WebCore::ImageExtractionTextData::decode):
+        (WebCore::ImageExtractionResult::isEmpty const):
+        (WebCore::ImageExtractionResult::encode const):
+        (WebCore::ImageExtractionResult::decode):
+        * platform/graphics/FloatQuad.h:
+        (WebCore::FloatQuad::encode const):
+        (WebCore::FloatQuad::decode):
+
+        Add generic encoding and decoding support for `WebCore::FloatQuad`, and remove iOS-specific WebKit2 argument
+        coder logic for serializing `FloatQuad` (see WebKit2 changes).
+
 2021-02-01  Antti Koivisto  <[email protected]>
 
         [LFC][Integration] Fix editing/execCommand/primitive-value-cleanup-minimal.htm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (272163 => 272164)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-02-01 20:22:05 UTC (rev 272164)
@@ -5270,6 +5270,7 @@
 		F48223101E3869B80066FC79 /* WebItemProviderPasteboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */; };
 		F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		F48B7D5325C341E6009E75DD /* ImageExtractionResult.h in Headers */ = {isa = PBXBuildFile; fileRef = F48B7D5225C341E6009E75DD /* ImageExtractionResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F48D2A6C215623B400C6752B /* FontShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A6A215623B400C6752B /* FontShadow.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F48D2A7E2157182600C6752B /* FontAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A712156DC0A00C6752B /* FontAttributes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F48D2AA52159740D00C6752B /* ColorCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2AA32159740D00C6752B /* ColorCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -16599,6 +16600,7 @@
 		F48223121E386E240066FC79 /* AbstractPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractPasteboard.h; sourceTree = "<group>"; };
 		F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; };
 		F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; };
+		F48B7D5225C341E6009E75DD /* ImageExtractionResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageExtractionResult.h; sourceTree = "<group>"; };
 		F48D2A6A215623B400C6752B /* FontShadow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontShadow.h; sourceTree = "<group>"; };
 		F48D2A712156DC0A00C6752B /* FontAttributes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributes.h; sourceTree = "<group>"; };
 		F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontAttributesCocoa.mm; sourceTree = "<group>"; };
@@ -27565,6 +27567,7 @@
 				CD62FB941AF018E70012ED7D /* GenericTaskQueue.h */,
 				A8748BDF12CBF2DC001FBA41 /* HashTools.h */,
 				BC3BC29B0E91AB0F00835588 /* HostWindow.h */,
+				F48B7D5225C341E6009E75DD /* ImageExtractionResult.h */,
 				1AE00D57182DAC8D00087DD7 /* KeyedCoding.h */,
 				E15FF7D418C9553800FE4C87 /* KeypressCommand.h */,
 				A3D42A841F33BA3600A64B62 /* LayoutUnit.cpp */,
@@ -31573,6 +31576,7 @@
 				77D510171ED6022200DA4C87 /* CredentialsContainer.h in Headers */,
 				51A052331058774F00CC9E95 /* CredentialStorage.h in Headers */,
 				2D481F02146B5C5500AA7834 /* CrossfadeGeneratedImage.h in Headers */,
+				F48B7D5325C341E6009E75DD /* ImageExtractionResult.h in Headers */,
 				E1C416120F6562FD0092D2FB /* CrossOriginAccessControl.h in Headers */,
 				41ABE67B1D0580DB006D862D /* CrossOriginPreflightChecker.h in Headers */,
 				E1C415DA0F655D6F0092D2FB /* CrossOriginPreflightResultCache.h in Headers */,

Added: trunk/Source/WebCore/platform/ImageExtractionResult.h (0 => 272164)


--- trunk/Source/WebCore/platform/ImageExtractionResult.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ImageExtractionResult.h	2021-02-01 20:22:05 UTC (rev 272164)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2021 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(IMAGE_EXTRACTION)
+
+#include "FloatQuad.h"
+#include <wtf/Optional.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct ImageExtractionTextData {
+    String text;
+    FloatQuad normalizedQuad;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<ImageExtractionTextData> decode(Decoder&);
+};
+
+template<class Encoder> void ImageExtractionTextData::encode(Encoder& encoder) const
+{
+    encoder << text;
+    encoder << normalizedQuad;
+}
+
+template<class Decoder> Optional<ImageExtractionTextData> ImageExtractionTextData::decode(Decoder& decoder)
+{
+    Optional<String> text;
+    decoder >> text;
+    if (!text)
+        return WTF::nullopt;
+
+    Optional<FloatQuad> normalizedQuad;
+    decoder >> normalizedQuad;
+    if (!normalizedQuad)
+        return WTF::nullopt;
+
+    return {{ WTFMove(*text), WTFMove(*normalizedQuad) }};
+}
+
+struct ImageExtractionResult {
+    Vector<ImageExtractionTextData> textData;
+
+    bool isEmpty() const { return textData.isEmpty(); }
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<ImageExtractionResult> decode(Decoder&);
+};
+
+template<class Encoder> void ImageExtractionResult::encode(Encoder& encoder) const
+{
+    encoder << textData;
+}
+
+template<class Decoder> Optional<ImageExtractionResult> ImageExtractionResult::decode(Decoder& decoder)
+{
+    Optional<Vector<ImageExtractionTextData>> textData;
+    decoder >> textData;
+    if (!textData)
+        return WTF::nullopt;
+
+    return {{ WTFMove(*textData) }};
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(IMAGE_EXTRACTION)

Modified: trunk/Source/WebCore/platform/graphics/FloatQuad.h (272163 => 272164)


--- trunk/Source/WebCore/platform/graphics/FloatQuad.h	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebCore/platform/graphics/FloatQuad.h	2021-02-01 20:22:05 UTC (rev 272164)
@@ -149,6 +149,9 @@
     // Note that output is undefined when all points are colinear.
     bool isCounterclockwise() const;
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<FloatQuad> decode(Decoder&);
+
 private:
     FloatPoint m_p1;
     FloatPoint m_p2;
@@ -156,6 +159,39 @@
     FloatPoint m_p4;
 };
 
+template<class Encoder> void FloatQuad::encode(Encoder& encoder) const
+{
+    encoder << m_p1;
+    encoder << m_p2;
+    encoder << m_p3;
+    encoder << m_p4;
+}
+
+template<class Decoder> Optional<FloatQuad> FloatQuad::decode(Decoder& decoder)
+{
+    Optional<FloatPoint> p1;
+    decoder >> p1;
+    if (!p1)
+        return WTF::nullopt;
+
+    Optional<FloatPoint> p2;
+    decoder >> p2;
+    if (!p2)
+        return WTF::nullopt;
+
+    Optional<FloatPoint> p3;
+    decoder >> p3;
+    if (!p3)
+        return WTF::nullopt;
+
+    Optional<FloatPoint> p4;
+    decoder >> p4;
+    if (!p4)
+        return WTF::nullopt;
+
+    return {{ *p1, *p2, *p3, *p4 }};
+}
+
 inline FloatQuad& operator+=(FloatQuad& a, const FloatSize& b)
 {
     a.move(b);

Modified: trunk/Source/WebKit/ChangeLog (272163 => 272164)


--- trunk/Source/WebKit/ChangeLog	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebKit/ChangeLog	2021-02-01 20:22:05 UTC (rev 272164)
@@ -1,3 +1,15 @@
+2021-02-01  Wenson Hsieh  <[email protected]>
+
+        Add some new data structures to represent image extraction results
+        https://bugs.webkit.org/show_bug.cgi?id=221214
+
+        Reviewed by Sam Weinig.
+
+        See WebCore ChangeLog for more details.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        * Shared/WebCoreArgumentCoders.h:
+
 2021-02-01  Per Arne  <[email protected]>
 
         [macOS] Observe color preference changes in the UI process

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (272163 => 272164)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-02-01 20:22:05 UTC (rev 272164)
@@ -674,21 +674,6 @@
     return SimpleArgumentCoder<FloatRoundedRect>::decode(decoder, roundedRect);
 }
 
-#if PLATFORM(IOS_FAMILY)
-void ArgumentCoder<FloatQuad>::encode(Encoder& encoder, const FloatQuad& floatQuad)
-{
-    SimpleArgumentCoder<FloatQuad>::encode(encoder, floatQuad);
-}
-
-Optional<FloatQuad> ArgumentCoder<FloatQuad>::decode(Decoder& decoder)
-{
-    FloatQuad floatQuad;
-    if (!SimpleArgumentCoder<FloatQuad>::decode(decoder, floatQuad))
-        return WTF::nullopt;
-    return floatQuad;
-}
-#endif // PLATFORM(IOS_FAMILY)
-
 #if ENABLE(META_VIEWPORT)
 void ArgumentCoder<ViewportArguments>::encode(Encoder& encoder, const ViewportArguments& viewportArguments)
 {

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (272163 => 272164)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-02-01 20:12:03 UTC (rev 272163)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-02-01 20:22:05 UTC (rev 272164)
@@ -325,13 +325,6 @@
     static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::FloatRoundedRect&);
 };
 
-#if PLATFORM(IOS_FAMILY)
-template<> struct ArgumentCoder<WebCore::FloatQuad> {
-    static void encode(Encoder&, const WebCore::FloatQuad&);
-    static Optional<WebCore::FloatQuad> decode(Decoder&);
-};
-#endif // PLATFORM(IOS_FAMILY)
-
 #if ENABLE(META_VIEWPORT)
 template<> struct ArgumentCoder<WebCore::ViewportArguments> {
     static void encode(Encoder&, const WebCore::ViewportArguments&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to