OLD | NEW |
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 "base/logging.h" |
6 #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" | |
9 | 7 |
10 namespace cc { | 8 namespace cc { |
11 namespace { | |
12 | |
13 proto::LayerSelectionBound::SelectionBoundType | |
14 LayerSelectionBoundTypeToProtobuf(const gfx::SelectionBound::Type& type) { | |
15 switch (type) { | |
16 case gfx::SelectionBound::LEFT: | |
17 return proto::LayerSelectionBound_SelectionBoundType_LEFT; | |
18 case gfx::SelectionBound::RIGHT: | |
19 return proto::LayerSelectionBound_SelectionBoundType_RIGHT; | |
20 case gfx::SelectionBound::CENTER: | |
21 return proto::LayerSelectionBound_SelectionBoundType_CENTER; | |
22 case gfx::SelectionBound::EMPTY: | |
23 return proto::LayerSelectionBound_SelectionBoundType_EMPTY; | |
24 } | |
25 NOTREACHED() << "proto::LayerSelectionBound_SelectionBoundType_UNKNOWN"; | |
26 return proto::LayerSelectionBound_SelectionBoundType_UNKNOWN; | |
27 } | |
28 | |
29 gfx::SelectionBound::Type LayerSelectionBoundTypeFromProtobuf( | |
30 const proto::LayerSelectionBound::SelectionBoundType& type) { | |
31 switch (type) { | |
32 case proto::LayerSelectionBound_SelectionBoundType_LEFT: | |
33 return gfx::SelectionBound::LEFT; | |
34 case proto::LayerSelectionBound_SelectionBoundType_RIGHT: | |
35 return gfx::SelectionBound::RIGHT; | |
36 case proto::LayerSelectionBound_SelectionBoundType_CENTER: | |
37 return gfx::SelectionBound::CENTER; | |
38 case proto::LayerSelectionBound_SelectionBoundType_EMPTY: | |
39 return gfx::SelectionBound::EMPTY; | |
40 case proto::LayerSelectionBound_SelectionBoundType_UNKNOWN: | |
41 NOTREACHED() << "proto::LayerSelectionBound_SelectionBoundType_UNKNOWN"; | |
42 return gfx::SelectionBound::EMPTY; | |
43 } | |
44 return gfx::SelectionBound::EMPTY; | |
45 } | |
46 | |
47 } // namespace | |
48 | 9 |
49 LayerSelectionBound::LayerSelectionBound() | 10 LayerSelectionBound::LayerSelectionBound() |
50 : type(gfx::SelectionBound::EMPTY), layer_id(0) {} | 11 : type(gfx::SelectionBound::EMPTY), layer_id(0) {} |
51 | 12 |
52 LayerSelectionBound::~LayerSelectionBound() { | 13 LayerSelectionBound::~LayerSelectionBound() { |
53 } | 14 } |
54 | 15 |
55 bool LayerSelectionBound::operator==(const LayerSelectionBound& other) const { | 16 bool LayerSelectionBound::operator==(const LayerSelectionBound& other) const { |
56 return type == other.type && layer_id == other.layer_id && | 17 return type == other.type && layer_id == other.layer_id && |
57 edge_top == other.edge_top && edge_bottom == other.edge_bottom; | 18 edge_top == other.edge_top && edge_bottom == other.edge_bottom; |
58 } | 19 } |
59 | 20 |
60 bool LayerSelectionBound::operator!=(const LayerSelectionBound& other) const { | 21 bool LayerSelectionBound::operator!=(const LayerSelectionBound& other) const { |
61 return !(*this == other); | 22 return !(*this == other); |
62 } | 23 } |
63 | 24 |
64 void LayerSelectionBound::ToProtobuf(proto::LayerSelectionBound* proto) const { | |
65 proto->set_type(LayerSelectionBoundTypeToProtobuf(type)); | |
66 PointToProto(edge_top, proto->mutable_edge_top()); | |
67 PointToProto(edge_bottom, proto->mutable_edge_bottom()); | |
68 proto->set_layer_id(layer_id); | |
69 } | |
70 | |
71 void LayerSelectionBound::FromProtobuf( | |
72 const proto::LayerSelectionBound& proto) { | |
73 type = LayerSelectionBoundTypeFromProtobuf(proto.type()); | |
74 edge_top = ProtoToPoint(proto.edge_top()); | |
75 edge_bottom = ProtoToPoint(proto.edge_bottom()); | |
76 layer_id = proto.layer_id(); | |
77 } | |
78 | |
79 void LayerSelectionToProtobuf(const LayerSelection& selection, | |
80 proto::LayerSelection* proto) { | |
81 selection.start.ToProtobuf(proto->mutable_start()); | |
82 selection.end.ToProtobuf(proto->mutable_end()); | |
83 proto->set_is_editable(selection.is_editable); | |
84 proto->set_is_empty_text_form_control(selection.is_empty_text_form_control); | |
85 } | |
86 | |
87 void LayerSelectionFromProtobuf(LayerSelection* selection, | |
88 const proto::LayerSelection& proto) { | |
89 selection->start.FromProtobuf(proto.start()); | |
90 selection->end.FromProtobuf(proto.end()); | |
91 selection->is_editable = proto.is_editable(); | |
92 selection->is_empty_text_form_control = proto.is_empty_text_form_control(); | |
93 } | |
94 | |
95 } // namespace cc | 25 } // namespace cc |
OLD | NEW |