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

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

Issue 759433002: Reland: Move TouchSelectionController from content to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Excluded ui/touch_selection from Windows GN build Created 6 years 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 "cc/output/viewport_selection_bound.h"
9 #include "ui/base/touch/selection_bound.h"
10 #include "ui/gfx/geometry/point_conversions.h"
11 #include "ui/gfx/rect.h"
12
13 namespace ui {
14
15 namespace {
16
17 SelectionBound::Type ConvertToSelectionBoundType(cc::SelectionBoundType type) {
18 switch (type) {
19 case cc::SELECTION_BOUND_LEFT:
20 return SelectionBound::LEFT;
21 case cc::SELECTION_BOUND_RIGHT:
22 return SelectionBound::RIGHT;
23 case cc::SELECTION_BOUND_CENTER:
24 return SelectionBound::CENTER;
25 case cc::SELECTION_BOUND_EMPTY:
26 return SelectionBound::EMPTY;
27 }
28 NOTREACHED() << "Unknown selection bound type";
29 return SelectionBound::EMPTY;
30 }
31
32 } // namespace
33
34 SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) {
35 }
36
37 SelectionBound::SelectionBound(const cc::ViewportSelectionBound& bound)
38 : type_(ConvertToSelectionBoundType(bound.type)),
39 visible_(bound.visible) {
40 if (type_ != EMPTY)
41 SetEdge(bound.edge_top, bound.edge_bottom);
42 }
43
44 SelectionBound::~SelectionBound() {
45 }
46
47 void SelectionBound::SetEdgeTop(const gfx::PointF& value) {
48 edge_top_ = value;
49 edge_top_rounded_ = gfx::ToRoundedPoint(value);
50 }
51
52 void SelectionBound::SetEdgeBottom(const gfx::PointF& value) {
53 edge_bottom_ = value;
54 edge_bottom_rounded_ = gfx::ToRoundedPoint(value);
55 }
56
57 void SelectionBound::SetEdge(const gfx::PointF& top,
58 const gfx::PointF& bottom) {
59 SetEdgeTop(top);
60 SetEdgeBottom(bottom);
61 }
62
63 int SelectionBound::GetHeight() const {
64 return edge_bottom_rounded_.y() - edge_top_rounded_.y();
65 }
66
67 bool operator==(const SelectionBound& lhs, const SelectionBound& rhs) {
68 return lhs.type() == rhs.type() && lhs.visible() == rhs.visible() &&
69 lhs.edge_top() == rhs.edge_top() &&
70 lhs.edge_bottom() == rhs.edge_bottom();
71 }
72
73 bool operator!=(const SelectionBound& lhs, const SelectionBound& rhs) {
74 return !(lhs == rhs);
75 }
76
77 gfx::Rect RectBetweenSelectionBounds(const SelectionBound& b1,
78 const SelectionBound& b2) {
79 gfx::Point top_left(b1.edge_top_rounded());
80 top_left.SetToMin(b1.edge_bottom_rounded());
81 top_left.SetToMin(b2.edge_top_rounded());
82 top_left.SetToMin(b2.edge_bottom_rounded());
83
84 gfx::Point bottom_right(b1.edge_top_rounded());
85 bottom_right.SetToMax(b1.edge_bottom_rounded());
86 bottom_right.SetToMax(b2.edge_top_rounded());
87 bottom_right.SetToMax(b2.edge_bottom_rounded());
88
89 gfx::Vector2d diff = bottom_right - top_left;
90 return gfx::Rect(top_left, gfx::Size(diff.x(), diff.y()));
91 }
92
93 } // 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