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

Side by Side Diff: views/controls/textfield/text_range.h

Issue 6628037: views: Moves TextfieldController/TextRange into their own headers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/native_textfield_win.cc ('k') | views/controls/textfield/textfield.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_),
29 end_(range.end_) {}
30
31 // Returns the start position;
32 size_t start() const { return start_; }
33
34 // Returns the end position.
35 size_t end() const { return end_; }
36
37 // Returns true if the selected text is empty.
38 bool is_empty() const { return start_ == end_; }
39
40 // Returns true if the selection is made in reverse order.
41 bool is_reverse() const { return start_ > end_; }
42
43 // Returns the min of selected range.
44 size_t GetMin() const { return std::min(start_, end_); }
45
46 // Returns the max of selected range.
47 size_t GetMax() const { return std::max(start_, end_); }
48
49 // Returns true if the the selection range is same ignoring the direction.
50 bool EqualsIgnoringDirection(const TextRange& range) const {
51 return GetMin() == range.GetMin() && GetMax() == range.GetMax();
52 }
53
54 // Set the range with |start| and |end|.
55 void SetRange(size_t start, size_t end) {
56 start_ = start;
57 end_ = end;
58 }
59
60 private:
61 size_t start_;
62 size_t end_;
63 };
64
65 } // namespace views
66
67 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXT_RANGE_H_
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_win.cc ('k') | views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698