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/gfx/range/range.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace ui { | 11 namespace gfx { |
12 | 12 |
13 Range::Range(const NSRange& range) { | 13 Range::Range(const NSRange& range) { |
14 *this = range; | 14 *this = range; |
15 } | 15 } |
16 | 16 |
17 Range& Range::operator=(const NSRange& range) { | 17 Range& Range::operator=(const NSRange& range) { |
18 if (range.location == NSNotFound) { | 18 if (range.location == NSNotFound) { |
19 DCHECK_EQ(0U, range.length); | 19 DCHECK_EQ(0U, range.length); |
20 *this = InvalidRange(); | 20 *this = InvalidRange(); |
21 } else { | 21 } else { |
22 set_start(range.location); | 22 set_start(range.location); |
23 // Don't overflow |end_|. | 23 // Don't overflow |end_|. |
24 DCHECK_LE(range.length, std::numeric_limits<size_t>::max() - start()); | 24 DCHECK_LE(range.length, std::numeric_limits<size_t>::max() - start()); |
25 set_end(start() + range.length); | 25 set_end(start() + range.length); |
26 } | 26 } |
27 return *this; | 27 return *this; |
28 } | 28 } |
29 | 29 |
30 NSRange Range::ToNSRange() const { | 30 NSRange Range::ToNSRange() const { |
31 if (!IsValid()) | 31 if (!IsValid()) |
32 return NSMakeRange(NSNotFound, 0); | 32 return NSMakeRange(NSNotFound, 0); |
33 return NSMakeRange(GetMin(), length()); | 33 return NSMakeRange(GetMin(), length()); |
34 } | 34 } |
35 | 35 |
36 } // namespace gfx | 36 } // namespace gfx |
OLD | NEW |