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

Side by Side Diff: ui/gfx/range/range.h

Issue 1671403002: Switch gfx::Range to use uint32_t instead of size_t. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 10 months 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/gfx/ipc/gfx_param_traits.cc ('k') | ui/gfx/range/range.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef UI_GFX_RANGE_RANGE_H_ 5 #ifndef UI_GFX_RANGE_RANGE_H_
6 #define UI_GFX_RANGE_RANGE_H_ 6 #define UI_GFX_RANGE_RANGE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h>
9 10
10 #include <ostream> 11 #include <ostream>
11 #include <string> 12 #include <string>
12 13
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "ui/gfx/gfx_export.h" 15 #include "ui/gfx/gfx_export.h"
15 16
16 #if defined(OS_MACOSX) 17 #if defined(OS_MACOSX)
17 #if __OBJC__ 18 #if __OBJC__
18 #import <Foundation/Foundation.h> 19 #import <Foundation/Foundation.h>
(...skipping 13 matching lines...) Expand all
32 // range of characters in a text selection. A range is made of a start and end 33 // range of characters in a text selection. A range is made of a start and end
33 // position; when they are the same, the Range is akin to a caret. Note that 34 // position; when they are the same, the Range is akin to a caret. Note that
34 // |start_| can be greater than |end_| to respect the directionality of the 35 // |start_| can be greater than |end_| to respect the directionality of the
35 // range. 36 // range.
36 class GFX_EXPORT Range { 37 class GFX_EXPORT Range {
37 public: 38 public:
38 // Creates an empty range {0,0}. 39 // Creates an empty range {0,0}.
39 Range(); 40 Range();
40 41
41 // Initializes the range with a start and end. 42 // Initializes the range with a start and end.
42 Range(size_t start, size_t end); 43 Range(uint32_t start, uint32_t end);
43 44
44 // Initializes the range with the same start and end positions. 45 // Initializes the range with the same start and end positions.
45 explicit Range(size_t position); 46 explicit Range(uint32_t position);
46 47
47 // Platform constructors. 48 // Platform constructors.
48 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
49 explicit Range(const NSRange& range); 50 explicit Range(const NSRange& range);
50 #elif defined(OS_WIN) 51 #elif defined(OS_WIN)
51 // The |total_length| paramater should be used if the CHARRANGE is set to 52 // The |total_length| paramater should be used if the CHARRANGE is set to
52 // {0,-1} to indicate the whole range. 53 // {0,-1} to indicate the whole range.
53 Range(const CHARRANGE& range, LONG total_length = -1); 54 Range(const CHARRANGE& range, LONG total_length = -1);
54 #endif 55 #endif
55 56
56 // Returns a range that is invalid, which is {size_t_max,size_t_max}. 57 // Returns a range that is invalid, which is {UINT32_MAX,UINT32_MAX}.
57 static const Range InvalidRange(); 58 static const Range InvalidRange();
58 59
59 // Checks if the range is valid through comparison to InvalidRange(). 60 // Checks if the range is valid through comparison to InvalidRange().
60 bool IsValid() const; 61 bool IsValid() const;
61 62
62 // Getters and setters. 63 // Getters and setters.
63 size_t start() const { return start_; } 64 uint32_t start() const { return start_; }
64 void set_start(size_t start) { start_ = start; } 65 void set_start(uint32_t start) { start_ = start; }
65 66
66 size_t end() const { return end_; } 67 uint32_t end() const { return end_; }
67 void set_end(size_t end) { end_ = end; } 68 void set_end(uint32_t end) { end_ = end; }
68 69
69 // Returns the absolute value of the length. 70 // Returns the absolute value of the length.
70 size_t length() const { 71 uint32_t length() const {
71 ptrdiff_t length = end() - start(); 72 return GetMax() - GetMin();
72 return length >= 0 ? length : -length;
73 } 73 }
74 74
75 bool is_reversed() const { return start() > end(); } 75 bool is_reversed() const { return start() > end(); }
76 bool is_empty() const { return start() == end(); } 76 bool is_empty() const { return start() == end(); }
77 77
78 // Returns the minimum and maximum values. 78 // Returns the minimum and maximum values.
79 size_t GetMin() const; 79 uint32_t GetMin() const;
80 size_t GetMax() const; 80 uint32_t GetMax() const;
81 81
82 bool operator==(const Range& other) const; 82 bool operator==(const Range& other) const;
83 bool operator!=(const Range& other) const; 83 bool operator!=(const Range& other) const;
84 bool EqualsIgnoringDirection(const Range& other) const; 84 bool EqualsIgnoringDirection(const Range& other) const;
85 85
86 // Returns true if this range intersects the specified |range|. 86 // Returns true if this range intersects the specified |range|.
87 bool Intersects(const Range& range) const; 87 bool Intersects(const Range& range) const;
88 88
89 // Returns true if this range contains the specified |range|. 89 // Returns true if this range contains the specified |range|.
90 bool Contains(const Range& range) const; 90 bool Contains(const Range& range) const;
(...skipping 10 matching lines...) Expand all
101 // is_reversed(), the range will get flipped when converted to an NSRange. 101 // is_reversed(), the range will get flipped when converted to an NSRange.
102 NSRange ToNSRange() const; 102 NSRange ToNSRange() const;
103 #elif defined(OS_WIN) 103 #elif defined(OS_WIN)
104 CHARRANGE ToCHARRANGE() const; 104 CHARRANGE ToCHARRANGE() const;
105 #endif 105 #endif
106 // GTK+ has no concept of a range. 106 // GTK+ has no concept of a range.
107 107
108 std::string ToString() const; 108 std::string ToString() const;
109 109
110 private: 110 private:
111 size_t start_; 111 uint32_t start_;
112 size_t end_; 112 uint32_t end_;
113 }; 113 };
114 114
115 GFX_EXPORT std::ostream& operator<<(std::ostream& os, const Range& range); 115 GFX_EXPORT std::ostream& operator<<(std::ostream& os, const Range& range);
116 116
117 } // namespace gfx 117 } // namespace gfx
118 118
119 #endif // UI_GFX_RANGE_RANGE_H_ 119 #endif // UI_GFX_RANGE_RANGE_H_
OLDNEW
« no previous file with comments | « ui/gfx/ipc/gfx_param_traits.cc ('k') | ui/gfx/range/range.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698