blob: 036bc6f9051aa8937c923e4cbf01aa97877634a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2014 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 <algorithm>
#include "base/macros.h"
#include "ui/base/touch/selection_bound.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
namespace ui {
SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) {
}
SelectionBound::SelectionBound(const SelectionBound& other) = default;
SelectionBound::~SelectionBound() {
}
void SelectionBound::SetEdgeTop(const gfx::PointF& value) {
edge_top_ = value;
edge_top_rounded_ = gfx::ToRoundedPoint(value);
}
void SelectionBound::SetEdgeBottom(const gfx::PointF& value) {
edge_bottom_ = value;
edge_bottom_rounded_ = gfx::ToRoundedPoint(value);
}
void SelectionBound::SetEdge(const gfx::PointF& top,
const gfx::PointF& bottom) {
SetEdgeTop(top);
SetEdgeBottom(bottom);
}
int SelectionBound::GetHeight() const {
return edge_bottom_rounded_.y() - edge_top_rounded_.y();
}
bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) {
return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() &&
lhs.edge_top() == rhs.edge_top() &&
lhs.edge_bottom() == rhs.edge_bottom();
}
bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) {
return !(lhs == rhs);
}
gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1,
const SelectionBound& b2) {
gfx::Point top_left(b1.edge_top_rounded());
top_left.SetToMin(b1.edge_bottom_rounded());
top_left.SetToMin(b2.edge_top_rounded());
top_left.SetToMin(b2.edge_bottom_rounded());
gfx::Point bottom_right(b1.edge_top_rounded());
bottom_right.SetToMax(b1.edge_bottom_rounded());
bottom_right.SetToMax(b2.edge_top_rounded());
bottom_right.SetToMax(b2.edge_bottom_rounded());
gfx::Vector2d diff = bottom_right - top_left;
return gfx::Rect(top_left, gfx::Size(diff.x(), diff.y()));
}
gfx::RectF RectFBetweenSelectionBounds(const SelectionBound& b1,
const SelectionBound& b2) {
gfx::PointF top_left(b1.edge_top());
top_left.SetToMin(b1.edge_bottom());
top_left.SetToMin(b2.edge_top());
top_left.SetToMin(b2.edge_bottom());
gfx::PointF bottom_right(b1.edge_top());
bottom_right.SetToMax(b1.edge_bottom());
bottom_right.SetToMax(b2.edge_top());
bottom_right.SetToMax(b2.edge_bottom());
gfx::Vector2dF diff = bottom_right - top_left;
return gfx::RectF(top_left, gfx::SizeF(diff.x(), diff.y()));
}
} // namespace ui
|