Chromium Code Reviews| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "ui/base/accessibility/accessible_view_state.h" | 15 #include "ui/base/accessibility/accessible_view_state.h" |
| 16 #include "ui/base/ime/text_input_type.h" | |
| 16 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
| 17 #include "ui/base/range/range.h" | 18 #include "ui/base/range/range.h" |
| 18 #include "ui/gfx/insets.h" | 19 #include "ui/gfx/insets.h" |
| 19 #include "views/controls/native/native_view_host.h" | 20 #include "views/controls/native/native_view_host.h" |
| 20 #include "views/controls/textfield/native_textfield_wrapper.h" | 21 #include "views/controls/textfield/native_textfield_wrapper.h" |
| 21 #include "views/controls/textfield/textfield_controller.h" | 22 #include "views/controls/textfield/textfield_controller.h" |
| 22 #include "views/widget/widget.h" | 23 #include "views/widget/widget.h" |
| 23 | 24 |
| 24 #if defined(OS_LINUX) | 25 #if defined(OS_LINUX) |
| 25 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 26 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 46 style_(STYLE_DEFAULT), | 47 style_(STYLE_DEFAULT), |
| 47 read_only_(false), | 48 read_only_(false), |
| 48 default_width_in_chars_(0), | 49 default_width_in_chars_(0), |
| 49 draw_border_(true), | 50 draw_border_(true), |
| 50 text_color_(SK_ColorBLACK), | 51 text_color_(SK_ColorBLACK), |
| 51 use_default_text_color_(true), | 52 use_default_text_color_(true), |
| 52 background_color_(SK_ColorWHITE), | 53 background_color_(SK_ColorWHITE), |
| 53 use_default_background_color_(true), | 54 use_default_background_color_(true), |
| 54 initialized_(false), | 55 initialized_(false), |
| 55 horizontal_margins_were_set_(false), | 56 horizontal_margins_were_set_(false), |
| 56 vertical_margins_were_set_(false) { | 57 vertical_margins_were_set_(false), |
| 58 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) { | |
| 57 set_focusable(true); | 59 set_focusable(true); |
| 58 } | 60 } |
| 59 | 61 |
| 60 Textfield::Textfield(StyleFlags style) | 62 Textfield::Textfield(StyleFlags style) |
| 61 : native_wrapper_(NULL), | 63 : native_wrapper_(NULL), |
| 62 controller_(NULL), | 64 controller_(NULL), |
| 63 style_(style), | 65 style_(style), |
| 64 read_only_(false), | 66 read_only_(false), |
| 65 default_width_in_chars_(0), | 67 default_width_in_chars_(0), |
| 66 draw_border_(true), | 68 draw_border_(true), |
| 67 text_color_(SK_ColorBLACK), | 69 text_color_(SK_ColorBLACK), |
| 68 use_default_text_color_(true), | 70 use_default_text_color_(true), |
| 69 background_color_(SK_ColorWHITE), | 71 background_color_(SK_ColorWHITE), |
| 70 use_default_background_color_(true), | 72 use_default_background_color_(true), |
| 71 initialized_(false), | 73 initialized_(false), |
| 72 horizontal_margins_were_set_(false), | 74 horizontal_margins_were_set_(false), |
| 73 vertical_margins_were_set_(false) { | 75 vertical_margins_were_set_(false), |
| 76 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT) { | |
| 74 set_focusable(true); | 77 set_focusable(true); |
| 78 if (IsPassword()) | |
| 79 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
| 75 } | 80 } |
| 76 | 81 |
| 77 Textfield::~Textfield() { | 82 Textfield::~Textfield() { |
| 78 } | 83 } |
| 79 | 84 |
| 80 void Textfield::SetController(TextfieldController* controller) { | 85 void Textfield::SetController(TextfieldController* controller) { |
| 81 controller_ = controller; | 86 controller_ = controller; |
| 82 } | 87 } |
| 83 | 88 |
| 84 TextfieldController* Textfield::GetController() const { | 89 TextfieldController* Textfield::GetController() const { |
| 85 return controller_; | 90 return controller_; |
| 86 } | 91 } |
| 87 | 92 |
| 88 void Textfield::SetReadOnly(bool read_only) { | 93 void Textfield::SetReadOnly(bool read_only) { |
| 89 read_only_ = read_only; | 94 read_only_ = read_only; |
| 90 if (native_wrapper_) { | 95 if (native_wrapper_) { |
| 91 native_wrapper_->UpdateReadOnly(); | 96 native_wrapper_->UpdateReadOnly(); |
| 92 native_wrapper_->UpdateTextColor(); | 97 native_wrapper_->UpdateTextColor(); |
| 93 native_wrapper_->UpdateBackgroundColor(); | 98 native_wrapper_->UpdateBackgroundColor(); |
| 94 } | 99 } |
| 95 } | 100 } |
| 96 | 101 |
| 97 bool Textfield::IsPassword() const { | 102 bool Textfield::IsPassword() const { |
| 98 return style_ & STYLE_PASSWORD; | 103 return style_ & STYLE_PASSWORD; |
| 99 } | 104 } |
| 100 | 105 |
| 101 void Textfield::SetPassword(bool password) { | 106 void Textfield::SetPassword(bool password) { |
| 102 if (password) | 107 if (password) { |
| 103 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); | 108 style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD); |
| 104 else | 109 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 110 } else { | |
| 105 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); | 111 style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD); |
| 112 SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); | |
| 113 } | |
| 106 if (native_wrapper_) | 114 if (native_wrapper_) |
| 107 native_wrapper_->UpdateIsPassword(); | 115 native_wrapper_->UpdateIsPassword(); |
| 108 } | 116 } |
| 109 | 117 |
| 118 | |
| 119 ui::TextInputType Textfield::GetTextInputType() const { | |
|
sadrul
2011/09/02 23:47:37
This could be Textfield::text_input_type() const {
oshima
2011/09/03 00:26:32
Textfield and NativeTextfieldViews will be merged,
| |
| 120 return text_input_type_; | |
| 121 } | |
| 122 | |
| 123 void Textfield::SetTextInputType(ui::TextInputType type) { | |
| 124 text_input_type_ = type; | |
| 125 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD; | |
| 126 if (IsPassword() != should_be_password) | |
| 127 SetPassword(should_be_password); | |
| 128 } | |
| 129 | |
| 110 void Textfield::SetText(const string16& text) { | 130 void Textfield::SetText(const string16& text) { |
| 111 text_ = text; | 131 text_ = text; |
| 112 if (native_wrapper_) | 132 if (native_wrapper_) |
| 113 native_wrapper_->UpdateText(); | 133 native_wrapper_->UpdateText(); |
| 114 } | 134 } |
| 115 | 135 |
| 116 void Textfield::AppendText(const string16& text) { | 136 void Textfield::AppendText(const string16& text) { |
| 117 text_ += text; | 137 text_ += text; |
| 118 if (native_wrapper_) | 138 if (native_wrapper_) |
| 119 native_wrapper_->AppendText(text); | 139 native_wrapper_->AppendText(text); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 } | 431 } |
| 412 #endif | 432 #endif |
| 413 } | 433 } |
| 414 } | 434 } |
| 415 | 435 |
| 416 std::string Textfield::GetClassName() const { | 436 std::string Textfield::GetClassName() const { |
| 417 return kViewClassName; | 437 return kViewClassName; |
| 418 } | 438 } |
| 419 | 439 |
| 420 } // namespace views | 440 } // namespace views |
| OLD | NEW |