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

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

Issue 8748001: Make text input type and password visibility bit independent in Textfield (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Textfield(STYLE_OBSCURED) sets TEXT_INPUT_TYPE_PASSWORD Created 9 years 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
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 "ui/views/controls/textfield/native_textfield_win.h" 5 #include "ui/views/controls/textfield/native_textfield_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 contains_mouse_(false), 93 contains_mouse_(false),
94 ime_discard_composition_(false), 94 ime_discard_composition_(false),
95 ime_composition_start_(0), 95 ime_composition_start_(0),
96 ime_composition_length_(0), 96 ime_composition_length_(0),
97 container_view_(new NativeViewHost), 97 container_view_(new NativeViewHost),
98 bg_color_(0) { 98 bg_color_(0) {
99 if (!did_load_library_) 99 if (!did_load_library_)
100 did_load_library_ = !!LoadLibrary(L"riched20.dll"); 100 did_load_library_ = !!LoadLibrary(L"riched20.dll");
101 101
102 DWORD style = kDefaultEditStyle | ES_AUTOHSCROLL; 102 DWORD style = kDefaultEditStyle | ES_AUTOHSCROLL;
103 if (textfield_->style() & Textfield::STYLE_PASSWORD) 103 if (textfield_->IsObscured())
104 style |= ES_PASSWORD; 104 style |= ES_PASSWORD;
105 105
106 if (textfield_->read_only()) 106 if (textfield_->read_only())
107 style |= ES_READONLY; 107 style |= ES_READONLY;
108 108
109 // Make sure we apply RTL related extended window styles if necessary. 109 // Make sure we apply RTL related extended window styles if necessary.
110 DWORD ex_style = l10n_util::GetExtendedStyles(); 110 DWORD ex_style = l10n_util::GetExtendedStyles();
111 111
112 RECT r = {0, 0, textfield_->width(), textfield_->height()}; 112 RECT r = {0, 0, textfield_->width(), textfield_->height()};
113 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style); 113 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style);
114 114
115 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { 115 if (textfield_->style() & Textfield::STYLE_LOWERCASE) {
116 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); 116 DCHECK(!textfield_->IsObscured());
117 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); 117 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE);
118 } 118 }
119 119
120 // Set up the text_object_model_. 120 // Set up the text_object_model_.
121 base::win::ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface; 121 base::win::ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface;
122 ole_interface.Attach(GetOleInterface()); 122 ole_interface.Attach(GetOleInterface());
123 if (ole_interface) 123 if (ole_interface)
124 text_object_model_.QueryFrom(ole_interface); 124 text_object_model_.QueryFrom(ole_interface);
125 125
126 InitializeAccessibilityInfo(); 126 InitializeAccessibilityInfo();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 254
255 void NativeTextfieldWin::UpdateFont() { 255 void NativeTextfieldWin::UpdateFont() {
256 SendMessage(m_hWnd, WM_SETFONT, 256 SendMessage(m_hWnd, WM_SETFONT,
257 reinterpret_cast<WPARAM>(textfield_->font().GetNativeFont()), 257 reinterpret_cast<WPARAM>(textfield_->font().GetNativeFont()),
258 TRUE); 258 TRUE);
259 // Setting the font blows away any text color we've set, so reset it. 259 // Setting the font blows away any text color we've set, so reset it.
260 UpdateTextColor(); 260 UpdateTextColor();
261 } 261 }
262 262
263 void NativeTextfieldWin::UpdateIsPassword() { 263 void NativeTextfieldWin::UpdateIsObscured() {
264 // TODO: Need to implement for Windows. 264 // TODO: Need to implement for Windows.
265 UpdateAccessibleState(STATE_SYSTEM_PROTECTED, textfield_->IsPassword()); 265 UpdateAccessibleState(STATE_SYSTEM_PROTECTED, textfield_->IsObscured());
266 } 266 }
267 267
268 void NativeTextfieldWin::UpdateEnabled() { 268 void NativeTextfieldWin::UpdateEnabled() {
269 SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0); 269 SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0);
270 UpdateAccessibleState(STATE_SYSTEM_UNAVAILABLE, !textfield_->IsEnabled()); 270 UpdateAccessibleState(STATE_SYSTEM_UNAVAILABLE, !textfield_->IsEnabled());
271 } 271 }
272 272
273 gfx::Insets NativeTextfieldWin::CalculateInsets() { 273 gfx::Insets NativeTextfieldWin::CalculateInsets() {
274 // NOTE: One would think GetThemeMargins would return the insets we should 274 // NOTE: One would think GetThemeMargins would return the insets we should
275 // use, but it doesn't. The margins returned by GetThemeMargins are always 275 // use, but it doesn't. The margins returned by GetThemeMargins are always
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // NativeTextfieldWin, ui::SimpleMenuModel::Delegate implementation: 388 // NativeTextfieldWin, ui::SimpleMenuModel::Delegate implementation:
389 389
390 bool NativeTextfieldWin::IsCommandIdChecked(int command_id) const { 390 bool NativeTextfieldWin::IsCommandIdChecked(int command_id) const {
391 return false; 391 return false;
392 } 392 }
393 393
394 bool NativeTextfieldWin::IsCommandIdEnabled(int command_id) const { 394 bool NativeTextfieldWin::IsCommandIdEnabled(int command_id) const {
395 switch (command_id) { 395 switch (command_id) {
396 case IDS_APP_UNDO: return !textfield_->read_only() && !!CanUndo(); 396 case IDS_APP_UNDO: return !textfield_->read_only() && !!CanUndo();
397 case IDS_APP_CUT: return !textfield_->read_only() && 397 case IDS_APP_CUT: return !textfield_->read_only() &&
398 !textfield_->IsPassword() && !!CanCut(); 398 !textfield_->IsObscured() && !!CanCut();
399 case IDS_APP_COPY: return !!CanCopy() && !textfield_->IsPassword(); 399 case IDS_APP_COPY: return !!CanCopy() && !textfield_->IsObscured();
400 case IDS_APP_PASTE: return !textfield_->read_only() && !!CanPaste(); 400 case IDS_APP_PASTE: return !textfield_->read_only() && !!CanPaste();
401 case IDS_APP_SELECT_ALL: return !!CanSelectAll(); 401 case IDS_APP_SELECT_ALL: return !!CanSelectAll();
402 default: NOTREACHED(); 402 default: NOTREACHED();
403 return false; 403 return false;
404 } 404 }
405 } 405 }
406 406
407 bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id, 407 bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id,
408 ui::Accelerator* accelerator) { 408 ui::Accelerator* accelerator) {
409 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators 409 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 POINT p(point); 515 POINT p(point);
516 if (point.x == -1 || point.y == -1) { 516 if (point.x == -1 || point.y == -1) {
517 GetCaretPos(&p); 517 GetCaretPos(&p);
518 MapWindowPoints(HWND_DESKTOP, &p, 1); 518 MapWindowPoints(HWND_DESKTOP, &p, 1);
519 } 519 }
520 BuildContextMenu(); 520 BuildContextMenu();
521 context_menu_->RunContextMenuAt(gfx::Point(p)); 521 context_menu_->RunContextMenuAt(gfx::Point(p));
522 } 522 }
523 523
524 void NativeTextfieldWin::OnCopy() { 524 void NativeTextfieldWin::OnCopy() {
525 if (textfield_->IsPassword()) 525 if (textfield_->IsObscured())
526 return; 526 return;
527 527
528 const string16 text(GetSelectedText()); 528 const string16 text(GetSelectedText());
529 if (!text.empty() && ViewsDelegate::views_delegate) { 529 if (!text.empty() && ViewsDelegate::views_delegate) {
530 ui::ScopedClipboardWriter scw( 530 ui::ScopedClipboardWriter scw(
531 ViewsDelegate::views_delegate->GetClipboard()); 531 ViewsDelegate::views_delegate->GetClipboard());
532 scw.WriteText(text); 532 scw.WriteText(text);
533 } 533 }
534 } 534 }
535 535
536 void NativeTextfieldWin::OnCut() { 536 void NativeTextfieldWin::OnCut() {
537 if (textfield_->read_only() || textfield_->IsPassword()) 537 if (textfield_->read_only() || textfield_->IsObscured())
538 return; 538 return;
539 539
540 OnCopy(); 540 OnCopy();
541 541
542 // This replace selection will have no effect (even on the undo stack) if the 542 // This replace selection will have no effect (even on the undo stack) if the
543 // current selection is empty. 543 // current selection is empty.
544 ReplaceSel(L"", true); 544 ReplaceSel(L"", true);
545 } 545 }
546 546
547 LRESULT NativeTextfieldWin::OnImeChar(UINT message, 547 LRESULT NativeTextfieldWin::OnImeChar(UINT message,
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1153
1154 // static 1154 // static
1155 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 1155 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
1156 Textfield* field) { 1156 Textfield* field) {
1157 if (views::Widget::IsPureViews()) 1157 if (views::Widget::IsPureViews())
1158 return new NativeTextfieldViews(field); 1158 return new NativeTextfieldViews(field);
1159 return new NativeTextfieldWin(field); 1159 return new NativeTextfieldWin(field);
1160 } 1160 }
1161 1161
1162 } // namespace views 1162 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698