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 <algorithm> | |
6 | |
7 #include "base/macros.h" | |
8 #include "ui/base/touch/selection_bound.h" | |
9 #include "ui/gfx/geometry/point_conversions.h" | |
10 | |
11 namespace ui { | |
12 | |
13 namespace { | |
14 | |
15 SelectionBound::Type ConvertToSelectionBoundType(cc::SelectionBoundType type) { | |
16 switch (type) { | |
17 case cc::SELECTION_BOUND_LEFT: | |
18 return SelectionBound::LEFT; | |
19 case cc::SELECTION_BOUND_RIGHT: | |
20 return SelectionBound::RIGHT; | |
21 case cc::SELECTION_BOUND_CENTER: | |
22 return SelectionBound::CENTER; | |
23 case cc::SELECTION_BOUND_EMPTY: | |
24 return SelectionBound::EMPTY; | |
25 } | |
26 NOTREACHED() << "Unknown selection bound type"; | |
27 return SelectionBound::EMPTY; | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) { | |
33 } | |
34 | |
35 SelectionBound::SelectionBound(const cc::ViewportSelectionBound& bound) | |
36 : type_(ConvertToSelectionBoundType(bound.type)), | |
37 visible_(bound.visible) { | |
38 SetEdgeTop(bound.edge_top); | |
jdduke (slow)
2014/12/01 20:38:04
Let's skip these setters if the bound is empty, as
mohsen
2014/12/02 05:17:02
Done.
| |
39 SetEdgeBottom(bound.edge_bottom); | |
40 } | |
41 | |
42 SelectionBound::~SelectionBound() { | |
43 } | |
44 | |
45 void SelectionBound::SetEdgeTop(const gfx::PointF& value) { | |
46 edge_top_ = value; | |
47 edge_top_rounded_ = gfx::ToRoundedPoint(value); | |
48 } | |
49 | |
50 void SelectionBound::SetEdgeBottom(const gfx::PointF& value) { | |
51 edge_bottom_ = value; | |
52 edge_bottom_rounded_ = gfx::ToRoundedPoint(value); | |
53 } | |
54 | |
55 int SelectionBound::GetHeight() const { | |
56 return edge_bottom_rounded_.y() - edge_top_rounded_.y(); | |
57 } | |
58 | |
59 bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) { | |
60 return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() && | |
61 lhs.edge_top() == rhs.edge_top() && | |
62 lhs.edge_bottom() == rhs.edge_bottom(); | |
63 } | |
64 | |
65 bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) { | |
66 return !(lhs == rhs); | |
67 } | |
68 | |
69 gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1, | |
70 const SelectionBound& b2) { | |
71 int all_x[] = { | |
72 b1.edge_top_rounded().x(), | |
jdduke (slow)
2014/12/01 20:38:04
Hmm, it may not be any better, but what about:
gf
mohsen
2014/12/02 05:17:02
Done, although, I wish we could do this:
return gf
| |
73 b2.edge_top_rounded().x(), | |
74 b1.edge_bottom_rounded().x(), | |
75 b2.edge_bottom_rounded().x() | |
76 }; | |
77 int all_y[] = { | |
78 b1.edge_top_rounded().y(), | |
79 b2.edge_top_rounded().y(), | |
80 b1.edge_bottom_rounded().y(), | |
81 b2.edge_bottom_rounded().y() | |
82 }; | |
83 const int num_elements = arraysize(all_x); | |
84 COMPILE_ASSERT(arraysize(all_y) == num_elements, array_size_mismatch); | |
85 | |
86 int left = *std::min_element(all_x, all_x + num_elements); | |
87 int top = *std::min_element(all_y, all_y + num_elements); | |
88 int right = *std::max_element(all_x, all_x + num_elements); | |
89 int bottom = *std::max_element(all_y, all_y + num_elements); | |
90 | |
91 return gfx::Rect(left, top, right - left, bottom - top); | |
92 } | |
93 | |
94 } // namespace ui | |
OLD | NEW |