Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: ui/base/touch/selection_bound.cc

Issue 2034863002: Move SelectionBound from ui/base/touch to ui/gfx to be used by cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated views_unittests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/touch/selection_bound.h ('k') | ui/base/touch/selection_bound_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/geometry/rect_f.h"
12
13 namespace ui {
14
15 SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) {
16 }
17
18 SelectionBound::SelectionBound(const SelectionBound& other) = default;
19
20 SelectionBound::~SelectionBound() {
21 }
22
23 void SelectionBound::SetEdgeTop(const gfx::PointF& value) {
24 edge_top_ = value;
25 edge_top_rounded_ = gfx::ToRoundedPoint(value);
26 }
27
28 void SelectionBound::SetEdgeBottom(const gfx::PointF& value) {
29 edge_bottom_ = value;
30 edge_bottom_rounded_ = gfx::ToRoundedPoint(value);
31 }
32
33 void SelectionBound::SetEdge(const gfx::PointF& top,
34 const gfx::PointF& bottom) {
35 SetEdgeTop(top);
36 SetEdgeBottom(bottom);
37 }
38
39 int SelectionBound::GetHeight() const {
40 return edge_bottom_rounded_.y() - edge_top_rounded_.y();
41 }
42
43 bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) {
44 return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() &&
45 lhs.edge_top() == rhs.edge_top() &&
46 lhs.edge_bottom() == rhs.edge_bottom();
47 }
48
49 bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) {
50 return !(lhs == rhs);
51 }
52
53 gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1,
54 const SelectionBound& b2) {
55 gfx::Point top_left(b1.edge_top_rounded());
56 top_left.SetToMin(b1.edge_bottom_rounded());
57 top_left.SetToMin(b2.edge_top_rounded());
58 top_left.SetToMin(b2.edge_bottom_rounded());
59
60 gfx::Point bottom_right(b1.edge_top_rounded());
61 bottom_right.SetToMax(b1.edge_bottom_rounded());
62 bottom_right.SetToMax(b2.edge_top_rounded());
63 bottom_right.SetToMax(b2.edge_bottom_rounded());
64
65 gfx::Vector2d diff = bottom_right - top_left;
66 return gfx::Rect(top_left, gfx::Size(diff.x(), diff.y()));
67 }
68
69 gfx::RectF RectFBetweenSelectionBounds(const SelectionBound& b1,
70 const SelectionBound& b2) {
71 gfx::PointF top_left(b1.edge_top());
72 top_left.SetToMin(b1.edge_bottom());
73 top_left.SetToMin(b2.edge_top());
74 top_left.SetToMin(b2.edge_bottom());
75
76 gfx::PointF bottom_right(b1.edge_top());
77 bottom_right.SetToMax(b1.edge_bottom());
78 bottom_right.SetToMax(b2.edge_top());
79 bottom_right.SetToMax(b2.edge_bottom());
80
81 gfx::Vector2dF diff = bottom_right - top_left;
82 return gfx::RectF(top_left, gfx::SizeF(diff.x(), diff.y()));
83 }
84
85 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/selection_bound.h ('k') | ui/base/touch/selection_bound_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698