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