Chromium Code Reviews| 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 namespace views { | |
| 12 | |
| 13 // TextRange specifies the range of text in the Textfield. This is used to | |
| 14 // specify selected text and will be used to change the attributes of characters | |
| 15 // in the textfield. When this is used for selection, the end is caret position, | |
| 16 // and the start is where selection started. The range preserves the direction, | |
| 17 // and selecting from the end to the begining is considered "reverse" order. | |
| 18 // (that is, start > end is reverse) | |
| 19 class TextRange { | |
|
sky
2011/03/07 23:40:11
All methods of this class are cheap. Inline it all
tfarina
2011/03/08 00:02:46
Ctors should not be in lined. I'd like to keep the
sky
2011/03/08 00:11:27
See http://dev.chromium.org/developers/coding-styl
| |
| 20 public: | |
| 21 TextRange(); | |
| 22 TextRange(size_t start, size_t end); | |
| 23 | |
| 24 // Allow copy so that the omnibox can save the view state for each tabs. | |
| 25 explicit TextRange(const TextRange& range); | |
| 26 | |
| 27 // Returns the start position; | |
| 28 size_t start() const { return start_; } | |
| 29 | |
| 30 // Returns the end position. | |
| 31 size_t end() const { return end_; } | |
| 32 | |
| 33 // Returns true if the selected text is empty. | |
| 34 bool is_empty() const { return start_ == end_; } | |
| 35 | |
| 36 // Returns true if the selection is made in reverse order. | |
| 37 bool is_reverse() const { return start_ > end_; } | |
| 38 | |
| 39 // Returns the min of selected range. | |
| 40 size_t GetMin() const; | |
| 41 | |
| 42 // Returns the max of selected range. | |
| 43 size_t GetMax() const; | |
| 44 | |
| 45 // Returns true if the the selection range is same ignoring the direction. | |
| 46 bool EqualsIgnoringDirection(const TextRange& range) const; | |
| 47 | |
| 48 // Set the range with |start| and |end|. | |
| 49 void SetRange(size_t start, size_t end); | |
| 50 | |
| 51 private: | |
| 52 size_t start_; | |
| 53 size_t end_; | |
| 54 | |
| 55 // No assign. | |
| 56 void operator=(const TextRange&); | |
| 57 }; | |
| 58 | |
| 59 } // namespace views | |
| 60 | |
| 61 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ | |
| OLD | NEW |