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 "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 |
OLD | NEW |