summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2015-12-18 15:18:25 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-18 23:19:05 +0000
commitbe6c29c514beca0a3d18158d4fbef28b26d6fa53 (patch)
tree966ce47b80d25402516269bbcfaf1b62db05c56d /cc
parent4da4f9927a55fe884e362cccff1dab01475f11c1 (diff)
downloadchromium_src-be6c29c514beca0a3d18158d4fbef28b26d6fa53.zip
chromium_src-be6c29c514beca0a3d18158d4fbef28b26d6fa53.tar.gz
chromium_src-be6c29c514beca0a3d18158d4fbef28b26d6fa53.tar.bz2
Add support for (de)serializing LayerSelection.
As part of serializing cc::LayerTreeHost, we also need to serialize the Selection<LayerSelectionBound>, which is typedef'ed to LayerSelection. We only support this type of the templated Selection for now, so the code lives together with the LayerSelectionBound. BUG=561210 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1531413002 Cr-Commit-Position: refs/heads/master@{#366202}
Diffstat (limited to 'cc')
-rw-r--r--cc/input/layer_selection_bound.cc16
-rw-r--r--cc/input/layer_selection_bound.h6
-rw-r--r--cc/input/layer_selection_bound_unittest.cc38
-rw-r--r--cc/proto/layer_selection_bound.proto7
4 files changed, 67 insertions, 0 deletions
diff --git a/cc/input/layer_selection_bound.cc b/cc/input/layer_selection_bound.cc
index 7abd9e0..a5146dc 100644
--- a/cc/input/layer_selection_bound.cc
+++ b/cc/input/layer_selection_bound.cc
@@ -77,4 +77,20 @@ void LayerSelectionBound::FromProtobuf(
layer_id = proto.layer_id();
}
+void LayerSelectionToProtobuf(const LayerSelection& selection,
+ proto::LayerSelection* proto) {
+ selection.start.ToProtobuf(proto->mutable_start());
+ selection.end.ToProtobuf(proto->mutable_end());
+ proto->set_is_editable(selection.is_editable);
+ proto->set_is_empty_text_form_control(selection.is_empty_text_form_control);
+}
+
+void LayerSelectionFromProtobuf(LayerSelection* selection,
+ const proto::LayerSelection& proto) {
+ selection->start.FromProtobuf(proto.start());
+ selection->end.FromProtobuf(proto.end());
+ selection->is_editable = proto.is_editable();
+ selection->is_empty_text_form_control = proto.is_empty_text_form_control();
+}
+
} // namespace cc
diff --git a/cc/input/layer_selection_bound.h b/cc/input/layer_selection_bound.h
index fa17399..333d1ef 100644
--- a/cc/input/layer_selection_bound.h
+++ b/cc/input/layer_selection_bound.h
@@ -13,6 +13,7 @@
namespace cc {
namespace proto {
+class LayerSelection;
class LayerSelectionBound;
} // namespace proto
@@ -35,6 +36,11 @@ struct CC_EXPORT LayerSelectionBound {
typedef Selection<LayerSelectionBound> LayerSelection;
+CC_EXPORT void LayerSelectionToProtobuf(const LayerSelection& selection,
+ proto::LayerSelection* proto);
+CC_EXPORT void LayerSelectionFromProtobuf(LayerSelection* selection,
+ const proto::LayerSelection& proto);
+
} // namespace cc
#endif // CC_INPUT_LAYER_SELECTION_BOUND_H_
diff --git a/cc/input/layer_selection_bound_unittest.cc b/cc/input/layer_selection_bound_unittest.cc
index 53f3ac1..e1ad56b 100644
--- a/cc/input/layer_selection_bound_unittest.cc
+++ b/cc/input/layer_selection_bound_unittest.cc
@@ -19,12 +19,22 @@ void VerifySerializeAndDeserializeProto(const LayerSelectionBound& bound1) {
EXPECT_EQ(bound1, bound2);
}
+void VerifySerializeAndDeserializeLayerSelectionProto(
+ const LayerSelection& selection1) {
+ proto::LayerSelection proto;
+ LayerSelectionToProtobuf(selection1, &proto);
+ LayerSelection selection2;
+ LayerSelectionFromProtobuf(&selection2, proto);
+ EXPECT_EQ(selection1, selection2);
+}
+
TEST(LayerSelectionBoundTest, AllTypePermutations) {
LayerSelectionBound bound;
bound.type = SelectionBoundType::SELECTION_BOUND_LEFT;
bound.edge_top = gfx::Point(3, 14);
bound.edge_bottom = gfx::Point(6, 28);
bound.layer_id = 42;
+
VerifySerializeAndDeserializeProto(bound);
bound.type = SelectionBoundType::SELECTION_BOUND_RIGHT;
VerifySerializeAndDeserializeProto(bound);
@@ -34,5 +44,33 @@ TEST(LayerSelectionBoundTest, AllTypePermutations) {
VerifySerializeAndDeserializeProto(bound);
}
+TEST(LayerSelectionTest, AllSelectionPermutations) {
+ LayerSelectionBound start;
+ start.type = SelectionBoundType::SELECTION_BOUND_LEFT;
+ start.edge_top = gfx::Point(3, 14);
+ start.edge_bottom = gfx::Point(6, 28);
+ start.layer_id = 42;
+
+ LayerSelectionBound end;
+ end.type = SelectionBoundType::SELECTION_BOUND_RIGHT;
+ end.edge_top = gfx::Point(14, 3);
+ end.edge_bottom = gfx::Point(28, 6);
+ end.layer_id = 24;
+
+ LayerSelection selection;
+ selection.start = start;
+ selection.end = end;
+ selection.is_editable = true;
+ selection.is_empty_text_form_control = true;
+
+ VerifySerializeAndDeserializeLayerSelectionProto(selection);
+ selection.is_empty_text_form_control = false;
+ VerifySerializeAndDeserializeLayerSelectionProto(selection);
+ selection.is_editable = false;
+ VerifySerializeAndDeserializeLayerSelectionProto(selection);
+ selection.is_empty_text_form_control = true;
+ VerifySerializeAndDeserializeLayerSelectionProto(selection);
+}
+
} // namespace
} // namespace cc
diff --git a/cc/proto/layer_selection_bound.proto b/cc/proto/layer_selection_bound.proto
index 397a1f8..84dd559 100644
--- a/cc/proto/layer_selection_bound.proto
+++ b/cc/proto/layer_selection_bound.proto
@@ -24,3 +24,10 @@ message LayerSelectionBound {
optional Point edge_bottom = 3;
optional int32 layer_id = 4;
}
+
+message LayerSelection {
+ optional LayerSelectionBound start = 1;
+ optional LayerSelectionBound end = 2;
+ optional bool is_editable = 3;
+ optional bool is_empty_text_form_control = 4;
+}