Commit 537a208c authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

[Shape Detection] Make DetectedText interface serializable.

This CL makes sure DetectedText interface is serializable so that
DetectedText can easily be transfered from workers.

Change-Id: Ic5ac034ae4f472c34ae75ec001cfda5af97cf6a9
Reviewed-on: https://chromium-review.googlesource.com/1243023
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594452}
parent 070ab0de
...@@ -1438,6 +1438,7 @@ interface DetectedText ...@@ -1438,6 +1438,7 @@ interface DetectedText
getter cornerPoints getter cornerPoints
getter rawValue getter rawValue
method constructor method constructor
method toJSON
interface DeviceMotionEvent : Event interface DeviceMotionEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter acceleration getter acceleration
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/shapedetection/detected_text.h" #include "third_party/blink/renderer/modules/shapedetection/detected_text.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
#include "third_party/blink/renderer/core/geometry/dom_rect.h" #include "third_party/blink/renderer/core/geometry/dom_rect.h"
namespace blink { namespace blink {
...@@ -39,6 +40,21 @@ DetectedText::DetectedText(String raw_value, ...@@ -39,6 +40,21 @@ DetectedText::DetectedText(String raw_value,
bounding_box_(bounding_box), bounding_box_(bounding_box),
corner_points_(corner_points) {} corner_points_(corner_points) {}
ScriptValue DetectedText::toJSONForBinding(ScriptState* script_state) const {
V8ObjectBuilder result(script_state);
result.AddString("rawValue", rawValue());
result.Add("boundingBox", boundingBox()->toJSONForBinding(script_state));
Vector<ScriptValue> corner_points;
for (const auto& corner_point : corner_points_) {
V8ObjectBuilder builder(script_state);
builder.AddNumber("x", corner_point.x());
builder.AddNumber("y", corner_point.y());
corner_points.push_back(builder.GetScriptValue());
}
result.Add("cornerPoints", corner_points);
return result.GetScriptValue();
}
void DetectedText::Trace(blink::Visitor* visitor) { void DetectedText::Trace(blink::Visitor* visitor) {
visitor->Trace(bounding_box_); visitor->Trace(bounding_box_);
visitor->Trace(corner_points_); visitor->Trace(corner_points_);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_DETECTED_TEXT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_DETECTED_TEXT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_DETECTED_TEXT_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_SHAPEDETECTION_DETECTED_TEXT_H_
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/modules/imagecapture/point_2d.h" #include "third_party/blink/renderer/modules/imagecapture/point_2d.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -24,6 +25,8 @@ class MODULES_EXPORT DetectedText final : public ScriptWrappable { ...@@ -24,6 +25,8 @@ class MODULES_EXPORT DetectedText final : public ScriptWrappable {
const String& rawValue() const; const String& rawValue() const;
DOMRectReadOnly* boundingBox() const; DOMRectReadOnly* boundingBox() const;
const HeapVector<Point2D>& cornerPoints() const; const HeapVector<Point2D>& cornerPoints() const;
ScriptValue toJSONForBinding(ScriptState*) const;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
private: private:
......
...@@ -13,4 +13,6 @@ ...@@ -13,4 +13,6 @@
// 4 corner points in clockwise direction starting with top-left. Due to // 4 corner points in clockwise direction starting with top-left. Due to
// possible perspective distortions, this is not necessarily a rectangle. // possible perspective distortions, this is not necessarily a rectangle.
[SameObject] readonly attribute FrozenArray<Point2D> cornerPoints; [SameObject] readonly attribute FrozenArray<Point2D> cornerPoints;
serializer = { attribute };
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment