Index: ui/base/touch/selection_bound.cc |
diff --git a/ui/base/touch/selection_bound.cc b/ui/base/touch/selection_bound.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3f4cc2db09eb9cc2150c0d4b78929507b971699f |
--- /dev/null |
+++ b/ui/base/touch/selection_bound.cc |
@@ -0,0 +1,94 @@ |
+// 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" |
+ |
+namespace ui { |
+ |
+namespace { |
+ |
+SelectionBound::Type ConvertToSelectionBoundType(cc::SelectionBoundType type) { |
+ switch (type) { |
+ case cc::SELECTION_BOUND_LEFT: |
+ return SelectionBound::LEFT; |
+ case cc::SELECTION_BOUND_RIGHT: |
+ return SelectionBound::RIGHT; |
+ case cc::SELECTION_BOUND_CENTER: |
+ return SelectionBound::CENTER; |
+ case cc::SELECTION_BOUND_EMPTY: |
+ return SelectionBound::EMPTY; |
+ } |
+ NOTREACHED() << "Unknown selection bound type"; |
+ return SelectionBound::EMPTY; |
+} |
+ |
+} // namespace |
+ |
+SelectionBound::SelectionBound() : type_(EMPTY), visible_(false) { |
+} |
+ |
+SelectionBound::SelectionBound(const cc::ViewportSelectionBound& bound) |
+ : type_(ConvertToSelectionBoundType(bound.type)), |
+ visible_(bound.visible) { |
+ SetEdgeTop(bound.edge_top); |
jdduke (slow)
2014/12/01 20:38:04
Let's skip these setters if the bound is empty, as
mohsen
2014/12/02 05:17:02
Done.
|
+ SetEdgeBottom(bound.edge_bottom); |
+} |
+ |
+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); |
+} |
+ |
+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) { |
+ int all_x[] = { |
+ b1.edge_top_rounded().x(), |
jdduke (slow)
2014/12/01 20:38:04
Hmm, it may not be any better, but what about:
gf
mohsen
2014/12/02 05:17:02
Done, although, I wish we could do this:
return gf
|
+ b2.edge_top_rounded().x(), |
+ b1.edge_bottom_rounded().x(), |
+ b2.edge_bottom_rounded().x() |
+ }; |
+ int all_y[] = { |
+ b1.edge_top_rounded().y(), |
+ b2.edge_top_rounded().y(), |
+ b1.edge_bottom_rounded().y(), |
+ b2.edge_bottom_rounded().y() |
+ }; |
+ const int num_elements = arraysize(all_x); |
+ COMPILE_ASSERT(arraysize(all_y) == num_elements, array_size_mismatch); |
+ |
+ int left = *std::min_element(all_x, all_x + num_elements); |
+ int top = *std::min_element(all_y, all_y + num_elements); |
+ int right = *std::max_element(all_x, all_x + num_elements); |
+ int bottom = *std::max_element(all_y, all_y + num_elements); |
+ |
+ return gfx::Rect(left, top, right - left, bottom - top); |
+} |
+ |
+} // namespace ui |