| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/base/touch/selection_bound.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #include "ui/gfx/geometry/rect.h" | |
| 9 | |
| 10 namespace ui { | |
| 11 | |
| 12 TEST(SelectionBoundTest, RectBetweenSelectionBounds) { | |
| 13 SelectionBound b1, b2; | |
| 14 // Simple case of aligned vertical bounds of equal height | |
| 15 b1.SetEdge(gfx::PointF(0.f, 20.f), gfx::PointF(0.f, 25.f)); | |
| 16 b2.SetEdge(gfx::PointF(110.f, 20.f), gfx::PointF(110.f, 25.f)); | |
| 17 gfx::Rect expected_rect( | |
| 18 b1.edge_top_rounded().x(), | |
| 19 b1.edge_top_rounded().y(), | |
| 20 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
| 21 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
| 22 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 23 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 24 | |
| 25 // Parallel vertical bounds of different heights | |
| 26 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f)); | |
| 27 b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f)); | |
| 28 expected_rect = gfx::Rect( | |
| 29 b1.edge_top_rounded().x(), | |
| 30 b2.edge_top_rounded().y(), | |
| 31 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
| 32 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
| 33 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 34 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 35 | |
| 36 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); | |
| 37 b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f)); | |
| 38 expected_rect = gfx::Rect( | |
| 39 b1.edge_top_rounded().x(), | |
| 40 b1.edge_top_rounded().y(), | |
| 41 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
| 42 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
| 43 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 44 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 45 | |
| 46 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); | |
| 47 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f)); | |
| 48 expected_rect = gfx::Rect( | |
| 49 b1.edge_top_rounded().x(), | |
| 50 b1.edge_top_rounded().y(), | |
| 51 b2.edge_top_rounded().x() - b1.edge_top_rounded().x(), | |
| 52 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
| 53 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 54 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 55 | |
| 56 // Overlapping vertical bounds | |
| 57 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); | |
| 58 b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f)); | |
| 59 expected_rect = gfx::Rect( | |
| 60 b1.edge_top_rounded().x(), | |
| 61 b1.edge_top_rounded().y(), | |
| 62 0, | |
| 63 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
| 64 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 65 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 66 | |
| 67 // Non-vertical bounds: "\ \" | |
| 68 b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f)); | |
| 69 b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f)); | |
| 70 expected_rect = gfx::Rect( | |
| 71 b1.edge_top_rounded().x(), | |
| 72 b1.edge_top_rounded().y(), | |
| 73 b2.edge_bottom_rounded().x() - b1.edge_top_rounded().x(), | |
| 74 b2.edge_bottom_rounded().y() - b1.edge_top_rounded().y()); | |
| 75 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 76 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 77 | |
| 78 // Non-vertical bounds: "/ \" | |
| 79 b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f)); | |
| 80 b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f)); | |
| 81 expected_rect = gfx::Rect( | |
| 82 b1.edge_bottom_rounded().x(), | |
| 83 b1.edge_top_rounded().y(), | |
| 84 b2.edge_bottom_rounded().x() - b1.edge_bottom_rounded().x(), | |
| 85 b2.edge_bottom_rounded().y() - b2.edge_top_rounded().y()); | |
| 86 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); | |
| 87 EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); | |
| 88 } | |
| 89 | |
| 90 } // namespace ui | |
| OLD | NEW |