summaryrefslogtreecommitdiffstats
path: root/cc/input
diff options
context:
space:
mode:
authornyquist <nyquist@chromium.org>2015-12-18 12:09:06 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-18 20:10:14 +0000
commit9de8ad81c88e8f82afb072204852d4cd61fa4814 (patch)
tree7c25d17d02a5ae6ef8491ae22a4153d49ee966f3 /cc/input
parent6dd347458f4bdcc934ac91092eacce2dfa3ee097 (diff)
downloadchromium_src-9de8ad81c88e8f82afb072204852d4cd61fa4814.zip
chromium_src-9de8ad81c88e8f82afb072204852d4cd61fa4814.tar.gz
chromium_src-9de8ad81c88e8f82afb072204852d4cd61fa4814.tar.bz2
Add support for (de)serializing LayerSelectionBound.
As part of serializing cc::LayerTreeHost, we also need to serialize the cc::LayerTreeBounds. BUG=561210 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1532973002 Cr-Commit-Position: refs/heads/master@{#366155}
Diffstat (limited to 'cc/input')
-rw-r--r--cc/input/layer_selection_bound.cc67
-rw-r--r--cc/input/layer_selection_bound.h13
-rw-r--r--cc/input/layer_selection_bound_unittest.cc38
3 files changed, 108 insertions, 10 deletions
diff --git a/cc/input/layer_selection_bound.cc b/cc/input/layer_selection_bound.cc
index 2761e9e2..7abd9e0 100644
--- a/cc/input/layer_selection_bound.cc
+++ b/cc/input/layer_selection_bound.cc
@@ -2,9 +2,49 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/logging.h"
#include "cc/input/layer_selection_bound.h"
+#include "cc/proto/gfx_conversions.h"
+#include "cc/proto/layer_selection_bound.pb.h"
namespace cc {
+namespace {
+
+proto::SelectionBoundType SelectionBoundTypeToProtobuf(
+ const SelectionBoundType& type) {
+ switch (type) {
+ case SELECTION_BOUND_LEFT:
+ return proto::SelectionBoundType::LEFT;
+ case SELECTION_BOUND_RIGHT:
+ return proto::SelectionBoundType::RIGHT;
+ case SELECTION_BOUND_CENTER:
+ return proto::SelectionBoundType::CENTER;
+ case SELECTION_BOUND_EMPTY:
+ return proto::SelectionBoundType::EMPTY;
+ }
+ NOTREACHED() << "proto::SelectionBoundType::UNKNOWN";
+ return proto::SelectionBoundType::UNKNOWN;
+}
+
+SelectionBoundType SelectionBoundTypeFromProtobuf(
+ const proto::SelectionBoundType& type) {
+ switch (type) {
+ case proto::SelectionBoundType::LEFT:
+ return SELECTION_BOUND_LEFT;
+ case proto::SelectionBoundType::RIGHT:
+ return SELECTION_BOUND_RIGHT;
+ case proto::SelectionBoundType::CENTER:
+ return SELECTION_BOUND_CENTER;
+ case proto::SelectionBoundType::EMPTY:
+ return SELECTION_BOUND_EMPTY;
+ case proto::SelectionBoundType::UNKNOWN:
+ NOTREACHED() << "proto::SelectionBoundType::UNKNOWN";
+ return SELECTION_BOUND_EMPTY;
+ }
+ return SELECTION_BOUND_EMPTY;
+}
+
+} // namespace
LayerSelectionBound::LayerSelectionBound()
: type(SELECTION_BOUND_EMPTY), layer_id(0) {
@@ -13,15 +53,28 @@ LayerSelectionBound::LayerSelectionBound()
LayerSelectionBound::~LayerSelectionBound() {
}
-bool operator==(const LayerSelectionBound& lhs,
- const LayerSelectionBound& rhs) {
- return lhs.type == rhs.type && lhs.layer_id == rhs.layer_id &&
- lhs.edge_top == rhs.edge_top && lhs.edge_bottom == rhs.edge_bottom;
+bool LayerSelectionBound::operator==(const LayerSelectionBound& other) const {
+ return type == other.type && layer_id == other.layer_id &&
+ edge_top == other.edge_top && edge_bottom == other.edge_bottom;
+}
+
+bool LayerSelectionBound::operator!=(const LayerSelectionBound& other) const {
+ return !(*this == other);
+}
+
+void LayerSelectionBound::ToProtobuf(proto::LayerSelectionBound* proto) const {
+ proto->set_type(SelectionBoundTypeToProtobuf(type));
+ PointToProto(edge_top, proto->mutable_edge_top());
+ PointToProto(edge_bottom, proto->mutable_edge_bottom());
+ proto->set_layer_id(layer_id);
}
-bool operator!=(const LayerSelectionBound& lhs,
- const LayerSelectionBound& rhs) {
- return !(lhs == rhs);
+void LayerSelectionBound::FromProtobuf(
+ const proto::LayerSelectionBound& proto) {
+ type = SelectionBoundTypeFromProtobuf(proto.type());
+ edge_top = ProtoToPoint(proto.edge_top());
+ edge_bottom = ProtoToPoint(proto.edge_bottom());
+ layer_id = proto.layer_id();
}
} // namespace cc
diff --git a/cc/input/layer_selection_bound.h b/cc/input/layer_selection_bound.h
index dece32b..fa17399 100644
--- a/cc/input/layer_selection_bound.h
+++ b/cc/input/layer_selection_bound.h
@@ -12,6 +12,10 @@
namespace cc {
+namespace proto {
+class LayerSelectionBound;
+} // namespace proto
+
// Marker for a selection end-point attached to a specific layer.
struct CC_EXPORT LayerSelectionBound {
LayerSelectionBound();
@@ -21,10 +25,13 @@ struct CC_EXPORT LayerSelectionBound {
gfx::Point edge_top;
gfx::Point edge_bottom;
int layer_id;
-};
-bool operator==(const LayerSelectionBound& lhs, const LayerSelectionBound& rhs);
-bool operator!=(const LayerSelectionBound& lhs, const LayerSelectionBound& rhs);
+ bool operator==(const LayerSelectionBound& other) const;
+ bool operator!=(const LayerSelectionBound& other) const;
+
+ void ToProtobuf(proto::LayerSelectionBound* proto) const;
+ void FromProtobuf(const proto::LayerSelectionBound& proto);
+};
typedef Selection<LayerSelectionBound> LayerSelection;
diff --git a/cc/input/layer_selection_bound_unittest.cc b/cc/input/layer_selection_bound_unittest.cc
new file mode 100644
index 0000000..53f3ac1
--- /dev/null
+++ b/cc/input/layer_selection_bound_unittest.cc
@@ -0,0 +1,38 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/input/layer_selection_bound.h"
+
+#include "cc/proto/layer_selection_bound.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/point.h"
+
+namespace cc {
+namespace {
+
+void VerifySerializeAndDeserializeProto(const LayerSelectionBound& bound1) {
+ proto::LayerSelectionBound proto;
+ bound1.ToProtobuf(&proto);
+ LayerSelectionBound bound2;
+ bound2.FromProtobuf(proto);
+ EXPECT_EQ(bound1, bound2);
+}
+
+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);
+ bound.type = SelectionBoundType::SELECTION_BOUND_CENTER;
+ VerifySerializeAndDeserializeProto(bound);
+ bound.type = SelectionBoundType::SELECTION_BOUND_EMPTY;
+ VerifySerializeAndDeserializeProto(bound);
+}
+
+} // namespace
+} // namespace cc