| 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 #include "views/controls/textfield/textfield.h" | 5 #include "views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 : native_wrapper_(NULL), | 44 : native_wrapper_(NULL), |
| 45 controller_(NULL), | 45 controller_(NULL), |
| 46 style_(STYLE_DEFAULT), | 46 style_(STYLE_DEFAULT), |
| 47 read_only_(false), | 47 read_only_(false), |
| 48 default_width_in_chars_(0), | 48 default_width_in_chars_(0), |
| 49 draw_border_(true), | 49 draw_border_(true), |
| 50 text_color_(SK_ColorBLACK), | 50 text_color_(SK_ColorBLACK), |
| 51 use_default_text_color_(true), | 51 use_default_text_color_(true), |
| 52 background_color_(SK_ColorWHITE), | 52 background_color_(SK_ColorWHITE), |
| 53 use_default_background_color_(true), | 53 use_default_background_color_(true), |
| 54 num_lines_(1), | |
| 55 initialized_(false), | 54 initialized_(false), |
| 56 horizontal_margins_were_set_(false), | 55 horizontal_margins_were_set_(false), |
| 57 vertical_margins_were_set_(false) { | 56 vertical_margins_were_set_(false) { |
| 58 set_focusable(true); | 57 set_focusable(true); |
| 59 } | 58 } |
| 60 | 59 |
| 61 Textfield::Textfield(StyleFlags style) | 60 Textfield::Textfield(StyleFlags style) |
| 62 : native_wrapper_(NULL), | 61 : native_wrapper_(NULL), |
| 63 controller_(NULL), | 62 controller_(NULL), |
| 64 style_(style), | 63 style_(style), |
| 65 read_only_(false), | 64 read_only_(false), |
| 66 default_width_in_chars_(0), | 65 default_width_in_chars_(0), |
| 67 draw_border_(true), | 66 draw_border_(true), |
| 68 text_color_(SK_ColorBLACK), | 67 text_color_(SK_ColorBLACK), |
| 69 use_default_text_color_(true), | 68 use_default_text_color_(true), |
| 70 background_color_(SK_ColorWHITE), | 69 background_color_(SK_ColorWHITE), |
| 71 use_default_background_color_(true), | 70 use_default_background_color_(true), |
| 72 num_lines_(1), | |
| 73 initialized_(false), | 71 initialized_(false), |
| 74 horizontal_margins_were_set_(false), | 72 horizontal_margins_were_set_(false), |
| 75 vertical_margins_were_set_(false) { | 73 vertical_margins_were_set_(false) { |
| 76 set_focusable(true); | 74 set_focusable(true); |
| 77 } | 75 } |
| 78 | 76 |
| 79 Textfield::~Textfield() { | 77 Textfield::~Textfield() { |
| 80 } | 78 } |
| 81 | 79 |
| 82 void Textfield::SetController(TextfieldController* controller) { | 80 void Textfield::SetController(TextfieldController* controller) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 102 | 100 |
| 103 void Textfield::SetPassword(bool password) { | 101 void Textfield::SetPassword(bool password) { |
| 104 if (password) | 102 if (password) |
| 105 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); | 103 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); |
| 106 else | 104 else |
| 107 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); | 105 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); |
| 108 if (native_wrapper_) | 106 if (native_wrapper_) |
| 109 native_wrapper_->UpdateIsPassword(); | 107 native_wrapper_->UpdateIsPassword(); |
| 110 } | 108 } |
| 111 | 109 |
| 112 bool Textfield::IsMultiLine() const { | |
| 113 return !!(style_ & STYLE_MULTILINE); | |
| 114 } | |
| 115 | |
| 116 void Textfield::SetText(const string16& text) { | 110 void Textfield::SetText(const string16& text) { |
| 117 text_ = text; | 111 text_ = text; |
| 118 if (native_wrapper_) | 112 if (native_wrapper_) |
| 119 native_wrapper_->UpdateText(); | 113 native_wrapper_->UpdateText(); |
| 120 } | 114 } |
| 121 | 115 |
| 122 void Textfield::AppendText(const string16& text) { | 116 void Textfield::AppendText(const string16& text) { |
| 123 text_ += text; | 117 text_ += text; |
| 124 if (native_wrapper_) | 118 if (native_wrapper_) |
| 125 native_wrapper_->AppendText(text); | 119 native_wrapper_->AppendText(text); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 184 } |
| 191 | 185 |
| 192 void Textfield::SetVerticalMargins(int top, int bottom) { | 186 void Textfield::SetVerticalMargins(int top, int bottom) { |
| 193 margins_.Set(top, margins_.left(), bottom, margins_.right()); | 187 margins_.Set(top, margins_.left(), bottom, margins_.right()); |
| 194 vertical_margins_were_set_ = true; | 188 vertical_margins_were_set_ = true; |
| 195 if (native_wrapper_) | 189 if (native_wrapper_) |
| 196 native_wrapper_->UpdateVerticalMargins(); | 190 native_wrapper_->UpdateVerticalMargins(); |
| 197 PreferredSizeChanged(); | 191 PreferredSizeChanged(); |
| 198 } | 192 } |
| 199 | 193 |
| 200 void Textfield::SetHeightInLines(int num_lines) { | |
| 201 DCHECK(IsMultiLine()); | |
| 202 num_lines_ = num_lines; | |
| 203 PreferredSizeChanged(); | |
| 204 } | |
| 205 | |
| 206 void Textfield::RemoveBorder() { | 194 void Textfield::RemoveBorder() { |
| 207 if (!draw_border_) | 195 if (!draw_border_) |
| 208 return; | 196 return; |
| 209 | 197 |
| 210 draw_border_ = false; | 198 draw_border_ = false; |
| 211 if (native_wrapper_) | 199 if (native_wrapper_) |
| 212 native_wrapper_->UpdateBorder(); | 200 native_wrapper_->UpdateBorder(); |
| 213 } | 201 } |
| 214 | 202 |
| 215 bool Textfield::GetHorizontalMargins(int* left, int* right) { | 203 bool Textfield::GetHorizontalMargins(int* left, int* right) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 native_wrapper_->GetView()->SetBoundsRect(GetLocalBounds()); | 294 native_wrapper_->GetView()->SetBoundsRect(GetLocalBounds()); |
| 307 native_wrapper_->GetView()->Layout(); | 295 native_wrapper_->GetView()->Layout(); |
| 308 } | 296 } |
| 309 } | 297 } |
| 310 | 298 |
| 311 gfx::Size Textfield::GetPreferredSize() { | 299 gfx::Size Textfield::GetPreferredSize() { |
| 312 gfx::Insets insets; | 300 gfx::Insets insets; |
| 313 if (draw_border_ && native_wrapper_) | 301 if (draw_border_ && native_wrapper_) |
| 314 insets = native_wrapper_->CalculateInsets(); | 302 insets = native_wrapper_->CalculateInsets(); |
| 315 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + | 303 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + |
| 316 insets.width(), | 304 insets.width(), font_.GetHeight() + insets.height()); |
| 317 num_lines_ * font_.GetHeight() + insets.height()); | |
| 318 } | 305 } |
| 319 | 306 |
| 320 bool Textfield::IsFocusable() const { | 307 bool Textfield::IsFocusable() const { |
| 321 return View::IsFocusable() && !read_only_; | 308 return View::IsFocusable() && !read_only_; |
| 322 } | 309 } |
| 323 | 310 |
| 324 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { | 311 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 325 SelectAll(); | 312 SelectAll(); |
| 326 } | 313 } |
| 327 | 314 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 415 } |
| 429 #endif | 416 #endif |
| 430 } | 417 } |
| 431 } | 418 } |
| 432 | 419 |
| 433 std::string Textfield::GetClassName() const { | 420 std::string Textfield::GetClassName() const { |
| 434 return kViewClassName; | 421 return kViewClassName; |
| 435 } | 422 } |
| 436 | 423 |
| 437 } // namespace views | 424 } // namespace views |
| OLD | NEW |