Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1521)

Unified Diff: cc/input/layer_selection_bound.cc

Issue 1532973002: Add support for (de)serializing LayerSelectionBound. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made operator members Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/input/layer_selection_bound.h ('k') | cc/input/layer_selection_bound_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/input/layer_selection_bound.cc
diff --git a/cc/input/layer_selection_bound.cc b/cc/input/layer_selection_bound.cc
index 2761e9e2b43aa1bceed58da58b1f53c7c0e01fcf..7abd9e000030aaf403063634d1ae0ef4985a8c89 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
« no previous file with comments | « cc/input/layer_selection_bound.h ('k') | cc/input/layer_selection_bound_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698