diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/BUILD.gn | 1 | ||||
-rw-r--r-- | cc/cc.gyp | 1 | ||||
-rw-r--r-- | cc/cc_tests.gyp | 1 | ||||
-rw-r--r-- | cc/input/layer_selection_bound.cc | 67 | ||||
-rw-r--r-- | cc/input/layer_selection_bound.h | 13 | ||||
-rw-r--r-- | cc/input/layer_selection_bound_unittest.cc | 38 | ||||
-rw-r--r-- | cc/proto/BUILD.gn | 1 | ||||
-rw-r--r-- | cc/proto/layer_selection_bound.proto | 26 |
8 files changed, 138 insertions, 10 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 0b5a4af..4f1b235 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -778,6 +778,7 @@ test("cc_unittests") { "debug/layer_tree_debug_state_unittest.cc", "debug/micro_benchmark_controller_unittest.cc", "debug/rendering_stats_unittest.cc", + "input/layer_selection_bound_unittest.cc", "input/scroll_state_unittest.cc", "input/top_controls_manager_unittest.cc", "layers/delegated_frame_provider_unittest.cc", @@ -607,6 +607,7 @@ 'proto/layer_position_constraint.proto', 'proto/layer_tree_debug_state.proto', 'proto/layer_tree_settings.proto', + 'proto/layer_selection_bound.proto', 'proto/managed_memory_policy.proto', 'proto/memory_allocation.proto', 'proto/point.proto', diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index ddf3e8d..ecffd21 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -34,6 +34,7 @@ 'debug/layer_tree_debug_state_unittest.cc', 'debug/micro_benchmark_controller_unittest.cc', 'debug/rendering_stats_unittest.cc', + 'input/layer_selection_bound_unittest.cc', 'input/scroll_state_unittest.cc', 'input/top_controls_manager_unittest.cc', 'layers/delegated_frame_provider_unittest.cc', 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 diff --git a/cc/input/layer_selection_bound.h b/cc/input/layer_selection_bound.h index dece32b..fa17399 100644 --- a/cc/input/layer_selection_bound.h +++ b/cc/input/layer_selection_bound.h @@ -12,6 +12,10 @@ namespace cc { +namespace proto { +class LayerSelectionBound; +} // namespace proto + // Marker for a selection end-point attached to a specific layer. struct CC_EXPORT LayerSelectionBound { LayerSelectionBound(); @@ -21,10 +25,13 @@ struct CC_EXPORT LayerSelectionBound { gfx::Point edge_top; gfx::Point edge_bottom; int layer_id; -}; -bool operator==(const LayerSelectionBound& lhs, const LayerSelectionBound& rhs); -bool operator!=(const LayerSelectionBound& lhs, const LayerSelectionBound& rhs); + bool operator==(const LayerSelectionBound& other) const; + bool operator!=(const LayerSelectionBound& other) const; + + void ToProtobuf(proto::LayerSelectionBound* proto) const; + void FromProtobuf(const proto::LayerSelectionBound& proto); +}; typedef Selection<LayerSelectionBound> LayerSelection; diff --git a/cc/input/layer_selection_bound_unittest.cc b/cc/input/layer_selection_bound_unittest.cc new file mode 100644 index 0000000..53f3ac1 --- /dev/null +++ b/cc/input/layer_selection_bound_unittest.cc @@ -0,0 +1,38 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/input/layer_selection_bound.h" + +#include "cc/proto/layer_selection_bound.pb.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/geometry/point.h" + +namespace cc { +namespace { + +void VerifySerializeAndDeserializeProto(const LayerSelectionBound& bound1) { + proto::LayerSelectionBound proto; + bound1.ToProtobuf(&proto); + LayerSelectionBound bound2; + bound2.FromProtobuf(proto); + EXPECT_EQ(bound1, bound2); +} + +TEST(LayerSelectionBoundTest, AllTypePermutations) { + LayerSelectionBound bound; + bound.type = SelectionBoundType::SELECTION_BOUND_LEFT; + bound.edge_top = gfx::Point(3, 14); + bound.edge_bottom = gfx::Point(6, 28); + bound.layer_id = 42; + VerifySerializeAndDeserializeProto(bound); + bound.type = SelectionBoundType::SELECTION_BOUND_RIGHT; + VerifySerializeAndDeserializeProto(bound); + bound.type = SelectionBoundType::SELECTION_BOUND_CENTER; + VerifySerializeAndDeserializeProto(bound); + bound.type = SelectionBoundType::SELECTION_BOUND_EMPTY; + VerifySerializeAndDeserializeProto(bound); +} + +} // namespace +} // namespace cc diff --git a/cc/proto/BUILD.gn b/cc/proto/BUILD.gn index 6ffdc7b..2548e59 100644 --- a/cc/proto/BUILD.gn +++ b/cc/proto/BUILD.gn @@ -34,6 +34,7 @@ proto_library("proto_internal") { "display_list_recording_source.proto", "layer.proto", "layer_position_constraint.proto", + "layer_selection_bound.proto", "layer_tree_debug_state.proto", "layer_tree_settings.proto", "managed_memory_policy.proto", diff --git a/cc/proto/layer_selection_bound.proto b/cc/proto/layer_selection_bound.proto new file mode 100644 index 0000000..397a1f8 --- /dev/null +++ b/cc/proto/layer_selection_bound.proto @@ -0,0 +1,26 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +syntax = "proto2"; + +import "point.proto"; + +option optimize_for = LITE_RUNTIME; + +package cc.proto; + +enum SelectionBoundType { + UNKNOWN = 0; + LEFT = 1; + RIGHT = 2; + CENTER = 3; + EMPTY = 4; +} + +message LayerSelectionBound { + optional SelectionBoundType type = 1; + optional Point edge_top = 2; + optional Point edge_bottom = 3; + optional int32 layer_id = 4; +} |