diff options
Diffstat (limited to 'cc/input/layer_selection_bound.cc')
-rw-r--r-- | cc/input/layer_selection_bound.cc | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/cc/input/layer_selection_bound.cc b/cc/input/layer_selection_bound.cc index 2761e9e2..7abd9e0 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 |