Commit dcb94b97 authored by codeimpl's avatar codeimpl Committed by Commit Bot

[ShapeDetection] Change DetectedText.boundingBox to DOMRectReadOnly

The spec[1] says that the boundingBox attribute should be
DOMRectReadOnly instead of DOMRect.

[1] https://github.com/WICG/shape-detection-api/pull/41

Bug: 852838
Change-Id: I8666d56fcaf4ac77c29b497827b410ec0aeaa916
Reviewed-on: https://chromium-review.googlesource.com/1102838Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Byoungkwon Ko <codeimpl@gmail.com>
Cr-Commit-Position: refs/heads/master@{#570763}
parent 3b181ae2
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/services/shape_detection/public/mojom/barcodedetection_provider.mojom.js"></script> <script src="file:///gen/services/shape_detection/public/mojom/barcodedetection_provider.mojom.js"></script>
<script src="file:///gen/services/shape_detection/public/mojom/facedetection_provider.mojom.js"></script> <script src="file:///gen/services/shape_detection/public/mojom/facedetection_provider.mojom.js"></script>
<script src="file:///gen/services/shape_detection/public/mojom/textdetection.mojom.js"></script>
<script src="resources/big-buffer-helpers.js"></script> <script src="resources/big-buffer-helpers.js"></script>
<script src="resources/mock-barcodedetection.js"></script> <script src="resources/mock-barcodedetection.js"></script>
<script src="resources/mock-facedetection.js"></script> <script src="resources/mock-facedetection.js"></script>
<script src="resources/mock-textdetection.js"></script>
<script> <script>
const createTestForImageData = (createDetector, mock, detectionResultTest) => { const createTestForImageData = (createDetector, mock, detectionResultTest) => {
...@@ -33,18 +35,17 @@ const createTestForImageData = (createDetector, mock, detectionResultTest) => { ...@@ -33,18 +35,17 @@ const createTestForImageData = (createDetector, mock, detectionResultTest) => {
}); });
}; };
function CheckDetectedReadOnlyBoundingBoxes(detectedObject) { function CheckDetectedReadOnlyBoundingBoxes(detectedObjects) {
assert_readonly(detectedObject[0].boundingBox, 'x'); var properties = ['x', 'y', 'width', 'height', 'top', 'right', 'bottom', 'left'];
assert_readonly(detectedObject[0].boundingBox, 'y');
assert_readonly(detectedObject[0].boundingBox, 'width'); detectedObjects.forEach(detectedObject => {
assert_readonly(detectedObject[0].boundingBox, 'height'); properties.forEach(property => {
assert_readonly(detectedObject[0].boundingBox, 'top'); assert_readonly(detectedObject.boundingBox, property);
assert_readonly(detectedObject[0].boundingBox, 'right'); });
assert_readonly(detectedObject[0].boundingBox, 'bottom'); });
assert_readonly(detectedObject[0].boundingBox, 'left');
} }
// These tests verify that detectedFace's boundingBox should be DOMRectReadOnly. // These tests verify that detected{Face, Barcode, Text}'s boundingBox should be DOMRectReadOnly.
generate_tests(createTestForImageData, [ generate_tests(createTestForImageData, [
[ [
"Face - detectedFace.boundingBox should be DOMRectReadOnly", "Face - detectedFace.boundingBox should be DOMRectReadOnly",
...@@ -57,6 +58,12 @@ generate_tests(createTestForImageData, [ ...@@ -57,6 +58,12 @@ generate_tests(createTestForImageData, [
() => { return new BarcodeDetector(); }, () => { return new BarcodeDetector(); },
mockBarcodeDetectionProvider, mockBarcodeDetectionProvider,
CheckDetectedReadOnlyBoundingBoxes CheckDetectedReadOnlyBoundingBoxes
],
[
"Text - detectedText.boundingBox should be DOMRectReadOnly",
() => { return new TextDetector(); },
mockTextDetection,
CheckDetectedReadOnlyBoundingBoxes
] ]
]); ]);
......
...@@ -10,11 +10,12 @@ namespace blink { ...@@ -10,11 +10,12 @@ namespace blink {
DetectedText* DetectedText::Create() { DetectedText* DetectedText::Create() {
HeapVector<Point2D> empty_list; HeapVector<Point2D> empty_list;
return new DetectedText(g_empty_string, DOMRect::Create(), empty_list); return new DetectedText(g_empty_string, DOMRectReadOnly::Create(0, 0, 0, 0),
empty_list);
} }
DetectedText* DetectedText::Create(String raw_value, DetectedText* DetectedText::Create(String raw_value,
DOMRect* bounding_box, DOMRectReadOnly* bounding_box,
HeapVector<Point2D> corner_points) { HeapVector<Point2D> corner_points) {
return new DetectedText(raw_value, bounding_box, corner_points); return new DetectedText(raw_value, bounding_box, corner_points);
} }
...@@ -23,7 +24,7 @@ const String& DetectedText::rawValue() const { ...@@ -23,7 +24,7 @@ const String& DetectedText::rawValue() const {
return raw_value_; return raw_value_;
} }
DOMRect* DetectedText::boundingBox() const { DOMRectReadOnly* DetectedText::boundingBox() const {
return bounding_box_.Get(); return bounding_box_.Get();
} }
...@@ -32,7 +33,7 @@ const HeapVector<Point2D>& DetectedText::cornerPoints() const { ...@@ -32,7 +33,7 @@ const HeapVector<Point2D>& DetectedText::cornerPoints() const {
} }
DetectedText::DetectedText(String raw_value, DetectedText::DetectedText(String raw_value,
DOMRect* bounding_box, DOMRectReadOnly* bounding_box,
HeapVector<Point2D> corner_points) HeapVector<Point2D> corner_points)
: raw_value_(raw_value), : raw_value_(raw_value),
bounding_box_(bounding_box), bounding_box_(bounding_box),
......
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
namespace blink { namespace blink {
class DOMRect; class DOMRectReadOnly;
class MODULES_EXPORT DetectedText final : public ScriptWrappable { class MODULES_EXPORT DetectedText final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static DetectedText* Create(); static DetectedText* Create();
static DetectedText* Create(String, DOMRect*, HeapVector<Point2D>); static DetectedText* Create(String, DOMRectReadOnly*, HeapVector<Point2D>);
const String& rawValue() const; const String& rawValue() const;
DOMRect* boundingBox() const; DOMRectReadOnly* boundingBox() const;
const HeapVector<Point2D>& cornerPoints() const; const HeapVector<Point2D>& cornerPoints() const;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
private: private:
DetectedText(String, DOMRect*, HeapVector<Point2D>); DetectedText(String, DOMRectReadOnly*, HeapVector<Point2D>);
const String raw_value_; const String raw_value_;
const Member<DOMRect> bounding_box_; const Member<DOMRectReadOnly> bounding_box_;
const HeapVector<Point2D> corner_points_; const HeapVector<Point2D> corner_points_;
}; };
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
RuntimeEnabled=ShapeDetection RuntimeEnabled=ShapeDetection
] interface DetectedText { ] interface DetectedText {
[SameObject] readonly attribute DOMString rawValue; [SameObject] readonly attribute DOMString rawValue;
[SameObject] readonly attribute DOMRect boundingBox; [SameObject] readonly attribute DOMRectReadOnly boundingBox;
// 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;
......
...@@ -64,8 +64,9 @@ void TextDetector::OnDetectText( ...@@ -64,8 +64,9 @@ void TextDetector::OnDetectText(
} }
detected_text.push_back(DetectedText::Create( detected_text.push_back(DetectedText::Create(
text->raw_value, text->raw_value,
DOMRect::Create(text->bounding_box.x, text->bounding_box.y, DOMRectReadOnly::Create(text->bounding_box.x, text->bounding_box.y,
text->bounding_box.width, text->bounding_box.height), text->bounding_box.width,
text->bounding_box.height),
corner_points)); corner_points));
} }
......
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