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

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

Issue 7826039: Identify the omnibox as a URL field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 9 years, 3 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
« no previous file with comments | « views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {
120 if (read_only() || !IsEnabled())
121 return ui::TEXT_INPUT_TYPE_NONE;
122 return text_input_type_;
123 }
124
125 void Textfield::SetTextInputType(ui::TextInputType type) {
126 text_input_type_ = type;
127 bool should_be_password = type == ui::TEXT_INPUT_TYPE_PASSWORD;
128 if (IsPassword() != should_be_password)
129 SetPassword(should_be_password);
130 }
131
110 void Textfield::SetText(const string16& text) { 132 void Textfield::SetText(const string16& text) {
111 text_ = text; 133 text_ = text;
112 if (native_wrapper_) 134 if (native_wrapper_)
113 native_wrapper_->UpdateText(); 135 native_wrapper_->UpdateText();
114 } 136 }
115 137
116 void Textfield::AppendText(const string16& text) { 138 void Textfield::AppendText(const string16& text) {
117 text_ += text; 139 text_ += text;
118 if (native_wrapper_) 140 if (native_wrapper_)
119 native_wrapper_->AppendText(text); 141 native_wrapper_->AppendText(text);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 433 }
412 #endif 434 #endif
413 } 435 }
414 } 436 }
415 437
416 std::string Textfield::GetClassName() const { 438 std::string Textfield::GetClassName() const {
417 return kViewClassName; 439 return kViewClassName;
418 } 440 }
419 441
420 } // namespace views 442 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698