Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / touch / selection_bound.cc
blob6aa472c6043ae38c2fda712dcab6197449542fdf
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.
5 #include <algorithm>
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"
12 namespace ui {
14 SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) {
17 SelectionBound::SelectionBound(const SelectionBound& other) = default;
19 SelectionBound::~SelectionBound() {
22 void SelectionBound::SetEdgeTop(const gfx::PointF& value) {
23 edge_top_ = value;
24 edge_top_rounded_ = gfx::ToRoundedPoint(value);
27 void SelectionBound::SetEdgeBottom(const gfx::PointF& value) {
28 edge_bottom_ = value;
29 edge_bottom_rounded_ = gfx::ToRoundedPoint(value);
32 void SelectionBound::SetEdge(const gfx::PointF& top,
33 const gfx::PointF& bottom) {
34 SetEdgeTop(top);
35 SetEdgeBottom(bottom);
38 int SelectionBound::GetHeight() const {
39 return edge_bottom_rounded_.y() - edge_top_rounded_.y();
42 bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) {
43 return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() &&
44 lhs.edge_top() == rhs.edge_top() &&
45 lhs.edge_bottom() == rhs.edge_bottom();
48 bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) {
49 return !(lhs == rhs);
52 gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1,
53 const SelectionBound& b2) {
54 gfx::Point top_left(b1.edge_top_rounded());
55 top_left.SetToMin(b1.edge_bottom_rounded());
56 top_left.SetToMin(b2.edge_top_rounded());
57 top_left.SetToMin(b2.edge_bottom_rounded());
59 gfx::Point bottom_right(b1.edge_top_rounded());
60 bottom_right.SetToMax(b1.edge_bottom_rounded());
61 bottom_right.SetToMax(b2.edge_top_rounded());
62 bottom_right.SetToMax(b2.edge_bottom_rounded());
64 gfx::Vector2d diff = bottom_right - top_left;
65 return gfx::Rect(top_left, gfx::Size(diff.x(), diff.y()));
68 gfx::RectF RectFBetweenSelectionBounds(const SelectionBound& b1,
69 const SelectionBound& b2) {
70 gfx::PointF top_left(b1.edge_top());
71 top_left.SetToMin(b1.edge_bottom());
72 top_left.SetToMin(b2.edge_top());
73 top_left.SetToMin(b2.edge_bottom());
75 gfx::PointF bottom_right(b1.edge_top());
76 bottom_right.SetToMax(b1.edge_bottom());
77 bottom_right.SetToMax(b2.edge_top());
78 bottom_right.SetToMax(b2.edge_bottom());
80 gfx::Vector2dF diff = bottom_right - top_left;
81 return gfx::RectF(top_left, gfx::SizeF(diff.x(), diff.y()));
84 } // namespace ui