Index: views/controls/textfield/text_range.h |
diff --git a/views/controls/textfield/text_range.h b/views/controls/textfield/text_range.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0578bffe1963a244836119d8a9543f62178ca33d |
--- /dev/null |
+++ b/views/controls/textfield/text_range.h |
@@ -0,0 +1,61 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ |
+#define VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ |
+#pragma once |
+ |
+#include <stddef.h> |
+ |
+namespace views { |
+ |
+// TextRange specifies the range of text in the Textfield. This is used to |
+// specify selected text and will be used to change the attributes of characters |
+// in the textfield. When this is used for selection, the end is caret position, |
+// and the start is where selection started. The range preserves the direction, |
+// and selecting from the end to the begining is considered "reverse" order. |
+// (that is, start > end is reverse) |
+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
|
+ public: |
+ TextRange(); |
+ TextRange(size_t start, size_t end); |
+ |
+ // Allow copy so that the omnibox can save the view state for each tabs. |
+ explicit TextRange(const TextRange& range); |
+ |
+ // Returns the start position; |
+ size_t start() const { return start_; } |
+ |
+ // Returns the end position. |
+ size_t end() const { return end_; } |
+ |
+ // Returns true if the selected text is empty. |
+ bool is_empty() const { return start_ == end_; } |
+ |
+ // Returns true if the selection is made in reverse order. |
+ bool is_reverse() const { return start_ > end_; } |
+ |
+ // Returns the min of selected range. |
+ size_t GetMin() const; |
+ |
+ // Returns the max of selected range. |
+ size_t GetMax() const; |
+ |
+ // Returns true if the the selection range is same ignoring the direction. |
+ bool EqualsIgnoringDirection(const TextRange& range) const; |
+ |
+ // Set the range with |start| and |end|. |
+ void SetRange(size_t start, size_t end); |
+ |
+ private: |
+ size_t start_; |
+ size_t end_; |
+ |
+ // No assign. |
+ void operator=(const TextRange&); |
+}; |
+ |
+} // namespace views |
+ |
+#endif // VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_ |