OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #if defined(OS_LINUX) | 11 #if defined(OS_LINUX) |
(...skipping 13 matching lines...) Expand all Loading... | |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #endif | 26 #endif |
27 #ifdef UNIT_TEST | 27 #ifdef UNIT_TEST |
28 #include "gfx/native_widget_types.h" | 28 #include "gfx/native_widget_types.h" |
29 #include "views/controls/textfield/native_textfield_wrapper.h" | 29 #include "views/controls/textfield/native_textfield_wrapper.h" |
30 #endif | 30 #endif |
31 | 31 |
32 namespace views { | 32 namespace views { |
33 | 33 |
34 class KeyEvent; | 34 class KeyEvent; |
35 class NativeTextfieldWrapper; | |
35 | 36 |
36 class NativeTextfieldWrapper; | 37 // TextRange specifies the range of text in the Textfield. This is |
38 // used to specify selected text and will be used to change the | |
39 // attributes of characters in the textfield. The range preserves the | |
40 // direction, and selecting from the end to the begining is considered | |
41 // "reverse" order. | |
42 class TextRange { | |
43 public: | |
44 TextRange() : start_(0), end_(0) {} | |
45 TextRange(size_t start, size_t end); | |
46 | |
47 // Allow copy so that the omnibox can save the view state | |
48 // for each tabs. | |
49 explicit TextRange(const TextRange& range) | |
50 : start_(range.start_), end_(range.end_) {} | |
51 | |
52 // Returns the start position; | |
53 size_t start() const { return start_; } | |
54 | |
55 // Returns the end position. | |
56 size_t end() const { return end_; } | |
57 | |
58 // Returns true if the selected text is empty. | |
59 bool is_empty() const { return start_ == end_; } | |
60 | |
61 // Returns true if the selection is made in reverse order. | |
62 bool is_reverse() const { return start_ > end_; } | |
63 | |
64 // Returns the min of selected range. | |
65 size_t GetMin() const; | |
66 | |
67 // Returns the max of selected range. | |
68 size_t GetMax() const; | |
69 | |
70 // Returns true if |range| has same start, end position. | |
71 bool Equals(const TextRange& range) const { | |
72 return start_ == range.start_ && end_ == range.end_; | |
73 } | |
74 | |
75 // Set the range with |start| and |end|. | |
76 void SetRange(size_t start, size_t end); | |
77 | |
78 private: | |
79 size_t start_; | |
80 size_t end_; | |
81 | |
82 // No assign. | |
83 void operator=(const TextRange&); | |
84 }; | |
37 | 85 |
38 // This class implements a ChromeView that wraps a native text (edit) field. | 86 // This class implements a ChromeView that wraps a native text (edit) field. |
39 class Textfield : public View { | 87 class Textfield : public View { |
40 public: | 88 public: |
41 // The button's class name. | 89 // The button's class name. |
42 static const char kViewClassName[]; | 90 static const char kViewClassName[]; |
43 | 91 |
44 // This defines the callback interface for other code to be notified of | 92 // This defines the callback interface for other code to be notified of |
45 // changes in the state of a text field. | 93 // changes in the state of a text field. |
46 class Controller { | 94 class Controller { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 226 |
179 // Invoked by the edit control when the value changes. This method set | 227 // Invoked by the edit control when the value changes. This method set |
180 // the text_ member variable to the value contained in edit control. | 228 // the text_ member variable to the value contained in edit control. |
181 // This is important because the edit control can be replaced if it has | 229 // This is important because the edit control can be replaced if it has |
182 // been deleted during a window close. | 230 // been deleted during a window close. |
183 void SyncText(); | 231 void SyncText(); |
184 | 232 |
185 // Returns whether or not an IME is composing text. | 233 // Returns whether or not an IME is composing text. |
186 bool IsIMEComposing() const; | 234 bool IsIMEComposing() const; |
187 | 235 |
236 // Gets the selected range. This is views implementation only and | |
Ben Goodger (Google)
2011/01/19 16:40:16
here, and everywhere else: views-implementation
oshima
2011/01/19 18:22:52
Done.
| |
237 // has to be called after the wrapper is created. | |
238 void GetSelectedRange(TextRange* range) const; | |
239 | |
240 // Selects the text given by |range|. This is views implementation only and | |
241 // has to be called after the wrapper is created. | |
242 void SelectRange(const TextRange& range); | |
243 | |
244 // Returns the currnet cursor position. This is views implementation | |
Ben Goodger (Google)
2011/01/19 16:40:16
current
oshima
2011/01/19 18:22:52
Done.
| |
245 // only and has to be called after the wrapper is created. | |
246 size_t GetCursorPosition() const; | |
247 | |
188 #ifdef UNIT_TEST | 248 #ifdef UNIT_TEST |
189 gfx::NativeView GetTestingHandle() const { | 249 gfx::NativeView GetTestingHandle() const { |
190 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; | 250 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; |
191 } | 251 } |
192 NativeTextfieldWrapper* native_wrapper() const { | 252 NativeTextfieldWrapper* native_wrapper() const { |
193 return native_wrapper_; | 253 return native_wrapper_; |
194 } | 254 } |
195 #endif | 255 #endif |
196 | 256 |
197 // Overridden from View: | 257 // Overridden from View: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 | 338 |
279 // Text to display when empty. | 339 // Text to display when empty. |
280 string16 text_to_display_when_empty_; | 340 string16 text_to_display_when_empty_; |
281 | 341 |
282 DISALLOW_COPY_AND_ASSIGN(Textfield); | 342 DISALLOW_COPY_AND_ASSIGN(Textfield); |
283 }; | 343 }; |
284 | 344 |
285 } // namespace views | 345 } // namespace views |
286 | 346 |
287 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 347 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
OLD | NEW |