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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h"
5 #include "cc/input/layer_selection_bound.h" 6 #include "cc/input/layer_selection_bound.h"
7 #include "cc/proto/gfx_conversions.h"
8 #include "cc/proto/layer_selection_bound.pb.h"
6 9
7 namespace cc { 10 namespace cc {
11 namespace {
12
13 proto::SelectionBoundType SelectionBoundTypeToProtobuf(
14 const SelectionBoundType& type) {
15 switch (type) {
16 case SELECTION_BOUND_LEFT:
17 return proto::SelectionBoundType::LEFT;
18 case SELECTION_BOUND_RIGHT:
19 return proto::SelectionBoundType::RIGHT;
20 case SELECTION_BOUND_CENTER:
21 return proto::SelectionBoundType::CENTER;
22 case SELECTION_BOUND_EMPTY:
23 return proto::SelectionBoundType::EMPTY;
24 }
25 NOTREACHED() << "proto::SelectionBoundType::UNKNOWN";
26 return proto::SelectionBoundType::UNKNOWN;
27 }
28
29 SelectionBoundType SelectionBoundTypeFromProtobuf(
30 const proto::SelectionBoundType& type) {
31 switch (type) {
32 case proto::SelectionBoundType::LEFT:
33 return SELECTION_BOUND_LEFT;
34 case proto::SelectionBoundType::RIGHT:
35 return SELECTION_BOUND_RIGHT;
36 case proto::SelectionBoundType::CENTER:
37 return SELECTION_BOUND_CENTER;
38 case proto::SelectionBoundType::EMPTY:
39 return SELECTION_BOUND_EMPTY;
40 case proto::SelectionBoundType::UNKNOWN:
41 NOTREACHED() << "proto::SelectionBoundType::UNKNOWN";
42 return SELECTION_BOUND_EMPTY;
43 }
44 return SELECTION_BOUND_EMPTY;
45 }
46
47 } // namespace
8 48
9 LayerSelectionBound::LayerSelectionBound() 49 LayerSelectionBound::LayerSelectionBound()
10 : type(SELECTION_BOUND_EMPTY), layer_id(0) { 50 : type(SELECTION_BOUND_EMPTY), layer_id(0) {
11 } 51 }
12 52
13 LayerSelectionBound::~LayerSelectionBound() { 53 LayerSelectionBound::~LayerSelectionBound() {
14 } 54 }
15 55
56 void LayerSelectionBound::ToProtobuf(proto::LayerSelectionBound* proto) const {
57 proto->set_type(SelectionBoundTypeToProtobuf(type));
58 PointToProto(edge_top, proto->mutable_edge_top());
59 PointToProto(edge_bottom, proto->mutable_edge_bottom());
60 proto->set_layer_id(layer_id);
61 }
62
63 void LayerSelectionBound::FromProtobuf(
64 const proto::LayerSelectionBound& proto) {
65 type = SelectionBoundTypeFromProtobuf(proto.type());
66 edge_top = ProtoToPoint(proto.edge_top());
67 edge_bottom = ProtoToPoint(proto.edge_bottom());
68 layer_id = proto.layer_id();
69 }
70
16 bool operator==(const LayerSelectionBound& lhs, 71 bool operator==(const LayerSelectionBound& lhs,
17 const LayerSelectionBound& rhs) { 72 const LayerSelectionBound& rhs) {
18 return lhs.type == rhs.type && lhs.layer_id == rhs.layer_id && 73 return lhs.type == rhs.type && lhs.layer_id == rhs.layer_id &&
19 lhs.edge_top == rhs.edge_top && lhs.edge_bottom == rhs.edge_bottom; 74 lhs.edge_top == rhs.edge_top && lhs.edge_bottom == rhs.edge_bottom;
20 } 75 }
21 76
22 bool operator!=(const LayerSelectionBound& lhs, 77 bool operator!=(const LayerSelectionBound& lhs,
23 const LayerSelectionBound& rhs) { 78 const LayerSelectionBound& rhs) {
24 return !(lhs == rhs); 79 return !(lhs == rhs);
25 } 80 }
26 81
27 } // namespace cc 82 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698