| OLD | NEW |
| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // This class implements a View that wraps a native text (edit) field. | 43 // This class implements a View that wraps a native text (edit) field. |
| 44 class Textfield : public View { | 44 class Textfield : public View { |
| 45 public: | 45 public: |
| 46 // The button's class name. | 46 // The button's class name. |
| 47 static const char kViewClassName[]; | 47 static const char kViewClassName[]; |
| 48 | 48 |
| 49 enum StyleFlags { | 49 enum StyleFlags { |
| 50 STYLE_DEFAULT = 0, | 50 STYLE_DEFAULT = 0, |
| 51 STYLE_PASSWORD = 1 << 0, | 51 STYLE_PASSWORD = 1 << 0, |
| 52 STYLE_MULTILINE = 1 << 1, | 52 STYLE_LOWERCASE = 1 << 1 |
| 53 STYLE_LOWERCASE = 1 << 2 | |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 Textfield(); | 55 Textfield(); |
| 57 explicit Textfield(StyleFlags style); | 56 explicit Textfield(StyleFlags style); |
| 58 virtual ~Textfield(); | 57 virtual ~Textfield(); |
| 59 | 58 |
| 60 // TextfieldController accessors | 59 // TextfieldController accessors |
| 61 void SetController(TextfieldController* controller); | 60 void SetController(TextfieldController* controller); |
| 62 TextfieldController* GetController() const; | 61 TextfieldController* GetController() const; |
| 63 | 62 |
| 64 // Gets/Sets whether or not the Textfield is read-only. | 63 // Gets/Sets whether or not the Textfield is read-only. |
| 65 bool read_only() const { return read_only_; } | 64 bool read_only() const { return read_only_; } |
| 66 void SetReadOnly(bool read_only); | 65 void SetReadOnly(bool read_only); |
| 67 | 66 |
| 68 // Gets/Sets whether or not this Textfield is a password field. | 67 // Gets/Sets whether or not this Textfield is a password field. |
| 69 bool IsPassword() const; | 68 bool IsPassword() const; |
| 70 void SetPassword(bool password); | 69 void SetPassword(bool password); |
| 71 | 70 |
| 72 // Whether the text field is multi-line or not, must be set when the text | |
| 73 // field is created, using StyleFlags. | |
| 74 bool IsMultiLine() const; | |
| 75 | |
| 76 // Gets/Sets the text currently displayed in the Textfield. | 71 // Gets/Sets the text currently displayed in the Textfield. |
| 77 const string16& text() const { return text_; } | 72 const string16& text() const { return text_; } |
| 78 void SetText(const string16& text); | 73 void SetText(const string16& text); |
| 79 | 74 |
| 80 // Appends the given string to the previously-existing text in the field. | 75 // Appends the given string to the previously-existing text in the field. |
| 81 void AppendText(const string16& text); | 76 void AppendText(const string16& text); |
| 82 | 77 |
| 83 // Returns the text that is currently selected. | 78 // Returns the text that is currently selected. |
| 84 string16 GetSelectedText() const; | 79 string16 GetSelectedText() const; |
| 85 | 80 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 120 |
| 126 // Sets the left and right margin (in pixels) within the text box. On Windows | 121 // Sets the left and right margin (in pixels) within the text box. On Windows |
| 127 // this is accomplished by packing the left and right margin into a single | 122 // this is accomplished by packing the left and right margin into a single |
| 128 // 32 bit number, so the left and right margins are effectively 16 bits. | 123 // 32 bit number, so the left and right margins are effectively 16 bits. |
| 129 void SetHorizontalMargins(int left, int right); | 124 void SetHorizontalMargins(int left, int right); |
| 130 | 125 |
| 131 // Sets the top and bottom margins (in pixels) within the textfield. | 126 // Sets the top and bottom margins (in pixels) within the textfield. |
| 132 // NOTE: in most cases height could be changed instead. | 127 // NOTE: in most cases height could be changed instead. |
| 133 void SetVerticalMargins(int top, int bottom); | 128 void SetVerticalMargins(int top, int bottom); |
| 134 | 129 |
| 135 // Should only be called on a multi-line text field. Sets how many lines of | |
| 136 // text can be displayed at once by this text field. | |
| 137 void SetHeightInLines(int num_lines); | |
| 138 | |
| 139 // Sets the default width of the text control. See default_width_in_chars_. | 130 // Sets the default width of the text control. See default_width_in_chars_. |
| 140 void set_default_width_in_chars(int default_width) { | 131 void set_default_width_in_chars(int default_width) { |
| 141 default_width_in_chars_ = default_width; | 132 default_width_in_chars_ = default_width; |
| 142 } | 133 } |
| 143 | 134 |
| 144 // Removes the border from the edit box, giving it a 2D look. | 135 // Removes the border from the edit box, giving it a 2D look. |
| 145 bool draw_border() const { return draw_border_; } | 136 bool draw_border() const { return draw_border_; } |
| 146 void RemoveBorder(); | 137 void RemoveBorder(); |
| 147 | 138 |
| 148 // Sets the text to display when empty. | 139 // Sets the text to display when empty. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 250 |
| 260 // The background color to be used when painting the Textfield, provided | 251 // The background color to be used when painting the Textfield, provided |
| 261 // |use_default_background_color_| is set to false. | 252 // |use_default_background_color_| is set to false. |
| 262 SkColor background_color_; | 253 SkColor background_color_; |
| 263 | 254 |
| 264 // When true, the system background color for Textfields is used when painting | 255 // When true, the system background color for Textfields is used when painting |
| 265 // this Textfield. When false, the value of |background_color_| determines the | 256 // this Textfield. When false, the value of |background_color_| determines the |
| 266 // Textfield's background color. | 257 // Textfield's background color. |
| 267 bool use_default_background_color_; | 258 bool use_default_background_color_; |
| 268 | 259 |
| 269 // The number of lines of text this Textfield displays at once. | |
| 270 int num_lines_; | |
| 271 | |
| 272 // TODO(beng): remove this once NativeTextfieldWin subclasses | 260 // TODO(beng): remove this once NativeTextfieldWin subclasses |
| 273 // NativeControlWin. | 261 // NativeControlWin. |
| 274 bool initialized_; | 262 bool initialized_; |
| 275 | 263 |
| 276 // Holds inner textfield margins. | 264 // Holds inner textfield margins. |
| 277 gfx::Insets margins_; | 265 gfx::Insets margins_; |
| 278 | 266 |
| 279 // Holds whether margins were set. | 267 // Holds whether margins were set. |
| 280 bool horizontal_margins_were_set_; | 268 bool horizontal_margins_were_set_; |
| 281 bool vertical_margins_were_set_; | 269 bool vertical_margins_were_set_; |
| 282 | 270 |
| 283 // Text to display when empty. | 271 // Text to display when empty. |
| 284 string16 text_to_display_when_empty_; | 272 string16 text_to_display_when_empty_; |
| 285 | 273 |
| 286 // The accessible name of the text field. | 274 // The accessible name of the text field. |
| 287 string16 accessible_name_; | 275 string16 accessible_name_; |
| 288 | 276 |
| 289 DISALLOW_COPY_AND_ASSIGN(Textfield); | 277 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 290 }; | 278 }; |
| 291 | 279 |
| 292 } // namespace views | 280 } // namespace views |
| 293 | 281 |
| 294 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 282 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |