OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ | |
6 #define VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ | |
7 #pragma once | |
8 | |
9 #include <stddef.h> | |
10 | |
11 #include <algorithm> | |
12 | |
13 namespace views { | |
14 | |
15 // TextRange specifies the range of text in the Textfield. This is used to | |
16 // specify selected text and will be used to change the attributes of characters | |
17 // in the textfield. When this is used for selection, the end is caret position, | |
18 // and the start is where selection started. The range preserves the direction, | |
19 // and selecting from the end to the begining is considered "reverse" order. | |
20 // (that is, start > end is reverse) | |
21 class TextRange { | |
22 public: | |
23 TextRange() : start_(0), end_(0) {} | |
24 TextRange(size_t start, size_t end) : start_(start), end_(end) {} | |
25 | |
26 // Allow copy so that the omnibox can save the view state for each tabs. | |
27 explicit TextRange(const TextRange& range) | |
28 : start_(range.start_), end_(range.end_) {} | |
sky
2011/03/09 17:02:33
Once you wrap, each variable should be on its own
tfarina
2011/03/09 17:31:06
Done.
| |
29 | |
30 // Returns the start position; | |
31 size_t start() const { return start_; } | |
32 | |
33 // Returns the end position. | |
34 size_t end() const { return end_; } | |
35 | |
36 // Returns true if the selected text is empty. | |
37 bool is_empty() const { return start_ == end_; } | |
38 | |
39 // Returns true if the selection is made in reverse order. | |
40 bool is_reverse() const { return start_ > end_; } | |
41 | |
42 // Returns the min of selected range. | |
43 size_t GetMin() const { return std::min(start_, end_); } | |
44 | |
45 // Returns the max of selected range. | |
46 size_t GetMax() const { return std::max(start_, end_); } | |
47 | |
48 // Returns true if the the selection range is same ignoring the direction. | |
49 bool EqualsIgnoringDirection(const TextRange& range) const { | |
50 return GetMin() == range.GetMin() && GetMax() == range.GetMax(); | |
51 } | |
52 | |
53 // Set the range with |start| and |end|. | |
54 void SetRange(size_t start, size_t end) { | |
55 start_ = start; | |
56 end_ = end; | |
57 } | |
58 | |
59 private: | |
60 size_t start_; | |
61 size_t end_; | |
62 | |
63 // No assign. | |
64 void operator=(const TextRange&); | |
sky
2011/03/09 17:02:33
I can't think of a good reason why we should disal
tfarina
2011/03/09 17:31:06
Removed.
| |
65 }; | |
66 | |
67 } // namespace views | |
68 | |
69 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ | |
OLD | NEW |