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/native_textfield_win.h" | 5 #include "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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 can_discard_mousemove_(false), | 92 can_discard_mousemove_(false), |
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; | 102 DWORD style = kDefaultEditStyle | ES_AUTOHSCROLL; |
103 if (textfield_->style() & Textfield::STYLE_PASSWORD) | 103 if (textfield_->style() & Textfield::STYLE_PASSWORD) |
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 if (textfield_->style() & Textfield::STYLE_MULTILINE) | |
110 style |= ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL; | |
111 else | |
112 style |= ES_AUTOHSCROLL; | |
113 // Make sure we apply RTL related extended window styles if necessary. | 109 // Make sure we apply RTL related extended window styles if necessary. |
114 DWORD ex_style = l10n_util::GetExtendedStyles(); | 110 DWORD ex_style = l10n_util::GetExtendedStyles(); |
115 | 111 |
116 RECT r = {0, 0, textfield_->width(), textfield_->height()}; | 112 RECT r = {0, 0, textfield_->width(), textfield_->height()}; |
117 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style); | 113 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style); |
118 | 114 |
119 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { | 115 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { |
120 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); | 116 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); |
121 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); | 117 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); |
122 } | 118 } |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 textfield_->SyncText(); | 623 textfield_->SyncText(); |
628 return DefWindowProc(message, wparam, lparam); | 624 return DefWindowProc(message, wparam, lparam); |
629 } | 625 } |
630 | 626 |
631 void NativeTextfieldWin::OnKeyDown(TCHAR key, UINT repeat_count, UINT flags) { | 627 void NativeTextfieldWin::OnKeyDown(TCHAR key, UINT repeat_count, UINT flags) { |
632 // NOTE: Annoyingly, ctrl-alt-<key> generates WM_KEYDOWN rather than | 628 // NOTE: Annoyingly, ctrl-alt-<key> generates WM_KEYDOWN rather than |
633 // WM_SYSKEYDOWN, so we need to check (flags & KF_ALTDOWN) in various places | 629 // WM_SYSKEYDOWN, so we need to check (flags & KF_ALTDOWN) in various places |
634 // in this function even with a WM_SYSKEYDOWN handler. | 630 // in this function even with a WM_SYSKEYDOWN handler. |
635 | 631 |
636 switch (key) { | 632 switch (key) { |
| 633 |
| 634 // Ignore Return |
637 case VK_RETURN: | 635 case VK_RETURN: |
638 // If we are multi-line, we want to let returns through so they start a | 636 return; |
639 // new line. | 637 |
640 if (textfield_->IsMultiLine()) | |
641 break; | |
642 else | |
643 return; | |
644 // Hijacking Editing Commands | 638 // Hijacking Editing Commands |
645 // | 639 // |
646 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that | 640 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that |
647 // they go through our clipboard routines. This allows us to be smarter | 641 // they go through our clipboard routines. This allows us to be smarter |
648 // about how we interact with the clipboard and avoid bugs in the | 642 // about how we interact with the clipboard and avoid bugs in the |
649 // CRichEditCtrl. If we didn't hijack here, the edit control would handle | 643 // CRichEditCtrl. If we didn't hijack here, the edit control would handle |
650 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. | 644 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. |
651 // | 645 // |
652 // Cut: Shift-Delete and Ctrl-x are treated as cut. Ctrl-Shift-Delete and | 646 // Cut: Shift-Delete and Ctrl-x are treated as cut. Ctrl-Shift-Delete and |
653 // Ctrl-Shift-x are not treated as cut even though the underlying | 647 // Ctrl-Shift-x are not treated as cut even though the underlying |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1157 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
1164 Textfield* field) { | 1158 Textfield* field) { |
1165 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { | 1159 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { |
1166 return new NativeTextfieldViews(field); | 1160 return new NativeTextfieldViews(field); |
1167 } else { | 1161 } else { |
1168 return new NativeTextfieldWin(field); | 1162 return new NativeTextfieldWin(field); |
1169 } | 1163 } |
1170 } | 1164 } |
1171 | 1165 |
1172 } // namespace views | 1166 } // namespace views |
OLD | NEW |