| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/range/range.h" | 5 #include "ui/base/range/range.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 Range Range::Intersect(const Range& range) const { | 68 Range Range::Intersect(const Range& range) const { |
| 69 size_t min = std::max(GetMin(), range.GetMin()); | 69 size_t min = std::max(GetMin(), range.GetMin()); |
| 70 size_t max = std::min(GetMax(), range.GetMax()); | 70 size_t max = std::min(GetMax(), range.GetMax()); |
| 71 | 71 |
| 72 if (min >= max) // No intersection. | 72 if (min >= max) // No intersection. |
| 73 return InvalidRange(); | 73 return InvalidRange(); |
| 74 | 74 |
| 75 return Range(min, max); | 75 return Range(min, max); |
| 76 } | 76 } |
| 77 | 77 |
| 78 #if defined(OS_WIN) | |
| 79 Range::Range(const CHARRANGE& range, LONG total_length) { | |
| 80 // Check if this is an invalid range. | |
| 81 if (range.cpMin == -1 && range.cpMax == -1) { | |
| 82 *this = InvalidRange(); | |
| 83 } else { | |
| 84 DCHECK_GE(range.cpMin, 0); | |
| 85 set_start(range.cpMin); | |
| 86 // {0,-1} is the "whole range" but that doesn't mean much out of context, | |
| 87 // so use the |total_length| parameter. | |
| 88 if (range.cpMax == -1) { | |
| 89 DCHECK_EQ(0, range.cpMin); | |
| 90 DCHECK_NE(-1, total_length); | |
| 91 set_end(total_length); | |
| 92 } else { | |
| 93 set_end(range.cpMax); | |
| 94 } | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 CHARRANGE Range::ToCHARRANGE() const { | |
| 99 CHARRANGE r = { -1, -1 }; | |
| 100 if (!IsValid()) | |
| 101 return r; | |
| 102 | |
| 103 const LONG kLONGMax = std::numeric_limits<LONG>::max(); | |
| 104 DCHECK_LE(static_cast<LONG>(start()), kLONGMax); | |
| 105 DCHECK_LE(static_cast<LONG>(end()), kLONGMax); | |
| 106 r.cpMin = start(); | |
| 107 r.cpMax = end(); | |
| 108 return r; | |
| 109 } | |
| 110 #endif // defined(OS_WIN) | |
| 111 | |
| 112 std::ostream& operator<<(std::ostream& out, const ui::Range& range) { | 78 std::ostream& operator<<(std::ostream& out, const ui::Range& range) { |
| 113 return out << "{" << range.start() << "," << range.end() << "}"; | 79 return out << "{" << range.start() << "," << range.end() << "}"; |
| 114 } | 80 } |
| 115 | 81 |
| 116 } // namespace gfx | 82 } // namespace gfx |
| OLD | NEW |