| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // This class implements a View that wraps a native text (edit) field. | 44 // This class implements a View that wraps a native text (edit) field. |
| 45 class Textfield : public View { | 45 class Textfield : public View { |
| 46 public: | 46 public: |
| 47 // The button's class name. | 47 // The button's class name. |
| 48 static const char kViewClassName[]; | 48 static const char kViewClassName[]; |
| 49 | 49 |
| 50 enum StyleFlags { | 50 enum StyleFlags { |
| 51 STYLE_DEFAULT = 0, | 51 STYLE_DEFAULT = 0, |
| 52 STYLE_PASSWORD = 1 << 0, | 52 STYLE_PASSWORD = 1 << 0, |
| 53 STYLE_MULTILINE = 1 << 1, | 53 STYLE_LOWERCASE = 1 << 1 |
| 54 STYLE_LOWERCASE = 1 << 2 | |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 Textfield(); | 56 Textfield(); |
| 58 explicit Textfield(StyleFlags style); | 57 explicit Textfield(StyleFlags style); |
| 59 virtual ~Textfield(); | 58 virtual ~Textfield(); |
| 60 | 59 |
| 61 // TextfieldController accessors | 60 // TextfieldController accessors |
| 62 void SetController(TextfieldController* controller); | 61 void SetController(TextfieldController* controller); |
| 63 TextfieldController* GetController() const; | 62 TextfieldController* GetController() const; |
| 64 | 63 |
| 65 // Gets/Sets whether or not the Textfield is read-only. | 64 // Gets/Sets whether or not the Textfield is read-only. |
| 66 bool read_only() const { return read_only_; } | 65 bool read_only() const { return read_only_; } |
| 67 void SetReadOnly(bool read_only); | 66 void SetReadOnly(bool read_only); |
| 68 | 67 |
| 69 // Gets/Sets whether or not this Textfield is a password field. | 68 // Gets/Sets whether or not this Textfield is a password field. |
| 70 bool IsPassword() const; | 69 bool IsPassword() const; |
| 71 void SetPassword(bool password); | 70 void SetPassword(bool password); |
| 72 | 71 |
| 73 // Whether the text field is multi-line or not, must be set when the text | 72 // Gets/Sets the text currently displayed in the Textfield. |
| 74 // field is created, using StyleFlags. | |
| 75 bool IsMultiLine() const; | |
| 76 | |
| 77 // Gets the text currently displayed in the Textfield. | |
| 78 const string16& text() const { return text_; } | 73 const string16& text() const { return text_; } |
| 79 | 74 |
| 80 // Sets the text currently displayed in the Textfield. This doesn't | 75 // Sets the text currently displayed in the Textfield. This doesn't |
| 81 // change the cursor position if the current cursor is within the | 76 // change the cursor position if the current cursor is within the |
| 82 // new text's range, or moves the cursor to the end if the cursor is | 77 // new text's range, or moves the cursor to the end if the cursor is |
| 83 // out of the new text's range. | 78 // out of the new text's range. |
| 84 void SetText(const string16& text); | 79 void SetText(const string16& text); |
| 85 | 80 |
| 86 // Appends the given string to the previously-existing text in the field. | 81 // Appends the given string to the previously-existing text in the field. |
| 87 void AppendText(const string16& text); | 82 void AppendText(const string16& text); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 126 |
| 132 // Sets the left and right margin (in pixels) within the text box. On Windows | 127 // Sets the left and right margin (in pixels) within the text box. On Windows |
| 133 // this is accomplished by packing the left and right margin into a single | 128 // this is accomplished by packing the left and right margin into a single |
| 134 // 32 bit number, so the left and right margins are effectively 16 bits. | 129 // 32 bit number, so the left and right margins are effectively 16 bits. |
| 135 void SetHorizontalMargins(int left, int right); | 130 void SetHorizontalMargins(int left, int right); |
| 136 | 131 |
| 137 // Sets the top and bottom margins (in pixels) within the textfield. | 132 // Sets the top and bottom margins (in pixels) within the textfield. |
| 138 // NOTE: in most cases height could be changed instead. | 133 // NOTE: in most cases height could be changed instead. |
| 139 void SetVerticalMargins(int top, int bottom); | 134 void SetVerticalMargins(int top, int bottom); |
| 140 | 135 |
| 141 // Should only be called on a multi-line text field. Sets how many lines of | |
| 142 // text can be displayed at once by this text field. | |
| 143 void SetHeightInLines(int num_lines); | |
| 144 | |
| 145 // Sets the default width of the text control. See default_width_in_chars_. | 136 // Sets the default width of the text control. See default_width_in_chars_. |
| 146 void set_default_width_in_chars(int default_width) { | 137 void set_default_width_in_chars(int default_width) { |
| 147 default_width_in_chars_ = default_width; | 138 default_width_in_chars_ = default_width; |
| 148 } | 139 } |
| 149 | 140 |
| 150 // Removes the border from the edit box, giving it a 2D look. | 141 // Removes the border from the edit box, giving it a 2D look. |
| 151 bool draw_border() const { return draw_border_; } | 142 bool draw_border() const { return draw_border_; } |
| 152 void RemoveBorder(); | 143 void RemoveBorder(); |
| 153 | 144 |
| 154 // Sets the text to display when empty. | 145 // Sets the text to display when empty. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 278 |
| 288 // The background color to be used when painting the Textfield, provided | 279 // The background color to be used when painting the Textfield, provided |
| 289 // |use_default_background_color_| is set to false. | 280 // |use_default_background_color_| is set to false. |
| 290 SkColor background_color_; | 281 SkColor background_color_; |
| 291 | 282 |
| 292 // When true, the system background color for Textfields is used when painting | 283 // When true, the system background color for Textfields is used when painting |
| 293 // this Textfield. When false, the value of |background_color_| determines the | 284 // this Textfield. When false, the value of |background_color_| determines the |
| 294 // Textfield's background color. | 285 // Textfield's background color. |
| 295 bool use_default_background_color_; | 286 bool use_default_background_color_; |
| 296 | 287 |
| 297 // The number of lines of text this Textfield displays at once. | |
| 298 int num_lines_; | |
| 299 | |
| 300 // TODO(beng): remove this once NativeTextfieldWin subclasses | 288 // TODO(beng): remove this once NativeTextfieldWin subclasses |
| 301 // NativeControlWin. | 289 // NativeControlWin. |
| 302 bool initialized_; | 290 bool initialized_; |
| 303 | 291 |
| 304 // Holds inner textfield margins. | 292 // Holds inner textfield margins. |
| 305 gfx::Insets margins_; | 293 gfx::Insets margins_; |
| 306 | 294 |
| 307 // Holds whether margins were set. | 295 // Holds whether margins were set. |
| 308 bool horizontal_margins_were_set_; | 296 bool horizontal_margins_were_set_; |
| 309 bool vertical_margins_were_set_; | 297 bool vertical_margins_were_set_; |
| 310 | 298 |
| 311 // Text to display when empty. | 299 // Text to display when empty. |
| 312 string16 text_to_display_when_empty_; | 300 string16 text_to_display_when_empty_; |
| 313 | 301 |
| 314 // The accessible name of the text field. | 302 // The accessible name of the text field. |
| 315 string16 accessible_name_; | 303 string16 accessible_name_; |
| 316 | 304 |
| 317 DISALLOW_COPY_AND_ASSIGN(Textfield); | 305 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 318 }; | 306 }; |
| 319 | 307 |
| 320 } // namespace views | 308 } // namespace views |
| 321 | 309 |
| 322 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 310 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |