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

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: 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
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..9fcee2b4f01dc611035936a47996dc9a6118a29a 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,6 +53,21 @@ LayerSelectionBound::LayerSelectionBound()
LayerSelectionBound::~LayerSelectionBound() {
}
+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);
+}
+
+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();
+}
+
bool operator==(const LayerSelectionBound& lhs,
const LayerSelectionBound& rhs) {
return lhs.type == rhs.type && lhs.layer_id == rhs.layer_id &&

Powered by Google App Engine
This is Rietveld 408576698