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

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

Issue 115825: Move text_field.cc and rename the class to Textfield in preparation for porti... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // These classes define a text field widget that can be used in the views UI 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
6 // toolkit. 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
7
8 #ifndef VIEWS_CONTROLS_TEXT_FIELD_H_
9 #define VIEWS_CONTROLS_TEXT_FIELD_H_
10 7
11 #include <string> 8 #include <string>
12 9
13 #include "app/gfx/font.h" 10 #include "app/gfx/font.h"
14 #include "base/basictypes.h" 11 #include "base/basictypes.h"
15 #include "views/view.h" 12 #include "views/view.h"
16 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
17 14
18 namespace views { 15 namespace views {
19 16
20 class HWNDView; 17 class HWNDView;
21 18
22 // This class implements a ChromeView that wraps a native text (edit) field. 19 // This class implements a ChromeView that wraps a native text (edit) field.
23 class TextField : public View { 20 class Textfield : public View {
24 public: 21 public:
25 // Keystroke provides a platform-dependent way to send keystroke events. 22 // Keystroke provides a platform-dependent way to send keystroke events.
26 // Cross-platform code can use IsKeystrokeEnter/Escape to check for these 23 // Cross-platform code can use IsKeystrokeEnter/Escape to check for these
27 // two common key events. 24 // two common key events.
28 // TODO(brettw) this should be cleaned up to be more cross-platform. 25 // TODO(brettw) this should be cleaned up to be more cross-platform.
29 #if defined(OS_WIN) 26 #if defined(OS_WIN)
30 struct Keystroke { 27 struct Keystroke {
31 Keystroke(unsigned int m, 28 Keystroke(unsigned int m,
32 wchar_t k, 29 wchar_t k,
33 int r, 30 int r,
(...skipping 13 matching lines...) Expand all
47 struct Keystroke { 44 struct Keystroke {
48 // TODO(brettw) figure out what this should be on GTK. 45 // TODO(brettw) figure out what this should be on GTK.
49 }; 46 };
50 #endif 47 #endif
51 48
52 // This defines the callback interface for other code to be notified of 49 // This defines the callback interface for other code to be notified of
53 // changes in the state of a text field. 50 // changes in the state of a text field.
54 class Controller { 51 class Controller {
55 public: 52 public:
56 // This method is called whenever the text in the field changes. 53 // This method is called whenever the text in the field changes.
57 virtual void ContentsChanged(TextField* sender, 54 virtual void ContentsChanged(Textfield* sender,
58 const std::wstring& new_contents) = 0; 55 const std::wstring& new_contents) = 0;
59 56
60 // This method is called to get notified about keystrokes in the edit. 57 // This method is called to get notified about keystrokes in the edit.
61 // This method returns true if the message was handled and should not be 58 // This method returns true if the message was handled and should not be
62 // processed further. If it returns false the processing continues. 59 // processed further. If it returns false the processing continues.
63 virtual bool HandleKeystroke(TextField* sender, 60 virtual bool HandleKeystroke(Textfield* sender,
64 const TextField::Keystroke& keystroke) = 0; 61 const Textfield::Keystroke& keystroke) = 0;
65 }; 62 };
66 63
67 enum StyleFlags { 64 enum StyleFlags {
68 STYLE_DEFAULT = 0, 65 STYLE_DEFAULT = 0,
69 STYLE_PASSWORD = 1<<0, 66 STYLE_PASSWORD = 1<<0,
70 STYLE_MULTILINE = 1<<1, 67 STYLE_MULTILINE = 1<<1,
71 STYLE_LOWERCASE = 1<<2 68 STYLE_LOWERCASE = 1<<2
72 }; 69 };
73 70
74 TextField() 71 Textfield()
75 : 72 :
76 #if defined(OS_WIN) 73 #if defined(OS_WIN)
77 native_view_(NULL), 74 native_view_(NULL),
78 #endif 75 #endif
79 edit_(NULL), 76 edit_(NULL),
80 controller_(NULL), 77 controller_(NULL),
81 style_(STYLE_DEFAULT), 78 style_(STYLE_DEFAULT),
82 read_only_(false), 79 read_only_(false),
83 default_width_in_chars_(0), 80 default_width_in_chars_(0),
84 draw_border_(true), 81 draw_border_(true),
85 use_default_background_color_(true), 82 use_default_background_color_(true),
86 num_lines_(1) { 83 num_lines_(1) {
87 SetFocusable(true); 84 SetFocusable(true);
88 } 85 }
89 explicit TextField(StyleFlags style) 86 explicit Textfield(StyleFlags style)
90 : 87 :
91 #if defined(OS_WIN) 88 #if defined(OS_WIN)
92 native_view_(NULL), 89 native_view_(NULL),
93 #endif 90 #endif
94 edit_(NULL), 91 edit_(NULL),
95 controller_(NULL), 92 controller_(NULL),
96 style_(style), 93 style_(style),
97 read_only_(false), 94 read_only_(false),
98 default_width_in_chars_(0), 95 default_width_in_chars_(0),
99 draw_border_(true), 96 draw_border_(true),
100 use_default_background_color_(true), 97 use_default_background_color_(true),
101 num_lines_(1) { 98 num_lines_(1) {
102 SetFocusable(true); 99 SetFocusable(true);
103 } 100 }
104 virtual ~TextField(); 101 virtual ~Textfield();
105 102
106 void ViewHierarchyChanged(bool is_add, View* parent, View* child); 103 void ViewHierarchyChanged(bool is_add, View* parent, View* child);
107 104
108 // Overridden for layout purposes 105 // Overridden for layout purposes
109 virtual void Layout(); 106 virtual void Layout();
110 virtual gfx::Size GetPreferredSize(); 107 virtual gfx::Size GetPreferredSize();
111 108
112 // Controller accessors 109 // Controller accessors
113 void SetController(Controller* controller); 110 void SetController(Controller* controller);
114 Controller* GetController() const; 111 Controller* GetController() const;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void ClearSelection() const; 147 void ClearSelection() const;
151 148
152 StyleFlags GetStyle() const { return style_; } 149 StyleFlags GetStyle() const { return style_; }
153 150
154 void SetBackgroundColor(SkColor color); 151 void SetBackgroundColor(SkColor color);
155 void SetDefaultBackgroundColor(); 152 void SetDefaultBackgroundColor();
156 153
157 // Set the font. 154 // Set the font.
158 void SetFont(const gfx::Font& font); 155 void SetFont(const gfx::Font& font);
159 156
160 // Return the font used by this TextField. 157 // Return the font used by this Textfield.
161 gfx::Font GetFont() const; 158 gfx::Font GetFont() const;
162 159
163 // Sets the left and right margin (in pixels) within the text box. On Windows 160 // Sets the left and right margin (in pixels) within the text box. On Windows
164 // this is accomplished by packing the left and right margin into a single 161 // this is accomplished by packing the left and right margin into a single
165 // 32 bit number, so the left and right margins are effectively 16 bits. 162 // 32 bit number, so the left and right margins are effectively 16 bits.
166 bool SetHorizontalMargins(int left, int right); 163 bool SetHorizontalMargins(int left, int right);
167 164
168 // Should only be called on a multi-line text field. Sets how many lines of 165 // Should only be called on a multi-line text field. Sets how many lines of
169 // text can be displayed at once by this text field. 166 // text can be displayed at once by this text field.
170 void SetHeightInLines(int num_lines); 167 void SetHeightInLines(int num_lines);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // This inherits from the native text field. 210 // This inherits from the native text field.
214 Edit* edit_; 211 Edit* edit_;
215 212
216 // This is the current listener for events from this control. 213 // This is the current listener for events from this control.
217 Controller* controller_; 214 Controller* controller_;
218 215
219 StyleFlags style_; 216 StyleFlags style_;
220 217
221 gfx::Font font_; 218 gfx::Font font_;
222 219
223 // NOTE: this is temporary until we rewrite TextField to always work whether 220 // NOTE: this is temporary until we rewrite Textfield to always work whether
224 // there is an HWND or not. 221 // there is an HWND or not.
225 // Used if the HWND hasn't been created yet. 222 // Used if the HWND hasn't been created yet.
226 std::wstring text_; 223 std::wstring text_;
227 224
228 bool read_only_; 225 bool read_only_;
229 226
230 // The default number of average characters for the width of this text field. 227 // The default number of average characters for the width of this text field.
231 // This will be reported as the "desired size". Defaults to 0. 228 // This will be reported as the "desired size". Defaults to 0.
232 int default_width_in_chars_; 229 int default_width_in_chars_;
233 230
234 // Whether the border is drawn. 231 // Whether the border is drawn.
235 bool draw_border_; 232 bool draw_border_;
236 233
237 SkColor background_color_; 234 SkColor background_color_;
238 235
239 bool use_default_background_color_; 236 bool use_default_background_color_;
240 237
241 // The number of lines of text this textfield displays at once. 238 // The number of lines of text this Textfield displays at once.
242 int num_lines_; 239 int num_lines_;
243 240
244 protected: 241 protected:
245 // Calculates the insets for the text field. 242 // Calculates the insets for the text field.
246 void CalculateInsets(gfx::Insets* insets); 243 void CalculateInsets(gfx::Insets* insets);
247 244
248 DISALLOW_COPY_AND_ASSIGN(TextField); 245 DISALLOW_COPY_AND_ASSIGN(Textfield);
249 }; 246 };
250 247
251 } // namespace views 248 } // namespace views
252 249
253 #endif // VIEWS_CONTROLS_TEXT_FIELD_H_ 250 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_wrapper.h ('k') | views/controls/textfield/textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698