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

Side by Side Diff: views/controls/textfield/textfield.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/text_range.h ('k') | views/controls/textfield/textfield.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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)
12 #include <gdk/gdk.h> 12 #include <gdk/gdk.h>
13 #endif 13 #endif
14 14
15 #include <string> 15 #include <string>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/compiler_specific.h"
18 #include "base/string16.h" 19 #include "base/string16.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/keycodes/keyboard_codes.h" 21 #include "ui/base/keycodes/keyboard_codes.h"
21 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
22 #include "views/view.h" 23 #include "views/view.h"
23 24
24 #if !defined(OS_LINUX) 25 #if !defined(OS_LINUX)
25 #include "base/logging.h" 26 #include "base/logging.h"
26 #endif 27 #endif
27 #ifdef UNIT_TEST 28 #ifdef UNIT_TEST
28 #include "ui/gfx/native_widget_types.h" 29 #include "ui/gfx/native_widget_types.h"
29 #include "views/controls/textfield/native_textfield_wrapper.h" 30 #include "views/controls/textfield/native_textfield_wrapper.h"
30 #endif 31 #endif
31 32
32 namespace views { 33 namespace views {
33 34
34 class KeyEvent; 35 class KeyEvent;
35 class NativeTextfieldWrapper; 36 class NativeTextfieldWrapper;
37 class TextfieldController;
38 class TextRange;
36 39
37 // TextRange specifies the range of text in the Textfield. This is 40 // This class implements a View that wraps a native text (edit) field.
38 // used to specify selected text and will be used to change the
39 // attributes of characters in the textfield. When this is used for
40 // selection, the end is caret position, and the start is where
41 // selection started. The range preserves the direction, and
42 // selecting from the end to the begining is considered "reverse"
43 // order. (that is, start > end is reverse)
44 class TextRange {
45 public:
46 TextRange() : start_(0), end_(0) {}
47 TextRange(size_t start, size_t end);
48
49 // Allow copy so that the omnibox can save the view state
50 // for each tabs.
51 explicit TextRange(const TextRange& range)
52 : start_(range.start_), end_(range.end_) {}
53
54 // Returns the start position;
55 size_t start() const { return start_; }
56
57 // Returns the end position.
58 size_t end() const { return end_; }
59
60 // Returns true if the selected text is empty.
61 bool is_empty() const { return start_ == end_; }
62
63 // Returns true if the selection is made in reverse order.
64 bool is_reverse() const { return start_ > end_; }
65
66 // Returns the min of selected range.
67 size_t GetMin() const;
68
69 // Returns the max of selected range.
70 size_t GetMax() const;
71
72 // Returns true if the the selection range is same ignoring the direction.
73 bool EqualsIgnoringDirection(const TextRange& range) const {
74 return GetMin() == range.GetMin() && GetMax() == range.GetMax();
75 }
76
77 // Set the range with |start| and |end|.
78 void SetRange(size_t start, size_t end);
79
80 private:
81 size_t start_;
82 size_t end_;
83
84 // No assign.
85 void operator=(const TextRange&);
86 };
87
88 // This class implements a ChromeView that wraps a native text (edit) field.
89 class Textfield : public View { 41 class Textfield : public View {
90 public: 42 public:
91 // The button's class name. 43 // The button's class name.
92 static const char kViewClassName[]; 44 static const char kViewClassName[];
93 45
94 // This defines the callback interface for other code to be notified of
95 // changes in the state of a text field.
96 class Controller {
97 public:
98 // This method is called whenever the text in the field changes.
99 virtual void ContentsChanged(Textfield* sender,
100 const string16& new_contents) = 0;
101
102 // This method is called to get notified about keystrokes in the edit.
103 // This method returns true if the message was handled and should not be
104 // processed further. If it returns false the processing continues.
105 virtual bool HandleKeyEvent(Textfield* sender,
106 const KeyEvent& key_event) = 0;
107 };
108
109 enum StyleFlags { 46 enum StyleFlags {
110 STYLE_DEFAULT = 0, 47 STYLE_DEFAULT = 0,
111 STYLE_PASSWORD = 1<<0, 48 STYLE_PASSWORD = 1 << 0,
112 STYLE_MULTILINE = 1<<1, 49 STYLE_MULTILINE = 1 << 1,
113 STYLE_LOWERCASE = 1<<2 50 STYLE_LOWERCASE = 1 << 2
114 }; 51 };
115 52
116 Textfield(); 53 Textfield();
117 explicit Textfield(StyleFlags style); 54 explicit Textfield(StyleFlags style);
118 virtual ~Textfield(); 55 virtual ~Textfield();
119 56
120 57 // TextfieldController accessors
121 // Controller accessors 58 void SetController(TextfieldController* controller);
122 void SetController(Controller* controller); 59 TextfieldController* GetController() const;
123 Controller* GetController() const;
124 60
125 // Gets/Sets whether or not the Textfield is read-only. 61 // Gets/Sets whether or not the Textfield is read-only.
126 bool read_only() const { return read_only_; } 62 bool read_only() const { return read_only_; }
127 void SetReadOnly(bool read_only); 63 void SetReadOnly(bool read_only);
128 64
129 // Gets/Sets whether or not this Textfield is a password field. 65 // Gets/Sets whether or not this Textfield is a password field.
130 bool IsPassword() const; 66 bool IsPassword() const;
131 void SetPassword(bool password); 67 void SetPassword(bool password);
132 68
133 // Whether the text field is multi-line or not, must be set when the text 69 // Whether the text field is multi-line or not, must be set when the text
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 protected: 216 protected:
281 virtual void ViewHierarchyChanged(bool is_add, View* parent, 217 virtual void ViewHierarchyChanged(bool is_add, View* parent,
282 View* child) OVERRIDE; 218 View* child) OVERRIDE;
283 virtual std::string GetClassName() const OVERRIDE; 219 virtual std::string GetClassName() const OVERRIDE;
284 220
285 // The object that actually implements the native text field. 221 // The object that actually implements the native text field.
286 NativeTextfieldWrapper* native_wrapper_; 222 NativeTextfieldWrapper* native_wrapper_;
287 223
288 private: 224 private:
289 // This is the current listener for events from this Textfield. 225 // This is the current listener for events from this Textfield.
290 Controller* controller_; 226 TextfieldController* controller_;
291 227
292 // The mask of style options for this Textfield. 228 // The mask of style options for this Textfield.
293 StyleFlags style_; 229 StyleFlags style_;
294 230
295 // The font used to render the text in the Textfield. 231 // The font used to render the text in the Textfield.
296 gfx::Font font_; 232 gfx::Font font_;
297 233
298 // The text displayed in the Textfield. 234 // The text displayed in the Textfield.
299 string16 text_; 235 string16 text_;
300 236
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 278
343 // Text to display when empty. 279 // Text to display when empty.
344 string16 text_to_display_when_empty_; 280 string16 text_to_display_when_empty_;
345 281
346 DISALLOW_COPY_AND_ASSIGN(Textfield); 282 DISALLOW_COPY_AND_ASSIGN(Textfield);
347 }; 283 };
348 284
349 } // namespace views 285 } // namespace views
350 286
351 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 287 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW
« no previous file with comments | « views/controls/textfield/text_range.h ('k') | views/controls/textfield/textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698