| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // See the code in textfield.cc that calls this for why this is here. | 166 // See the code in textfield.cc that calls this for why this is here. |
| 167 container_view_->set_focus_view(textfield_); | 167 container_view_->set_focus_view(textfield_); |
| 168 container_view_->Attach(m_hWnd); | 168 container_view_->Attach(m_hWnd); |
| 169 } | 169 } |
| 170 | 170 |
| 171 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
| 172 // NativeTextfieldWin, NativeTextfieldWrapper implementation: | 172 // NativeTextfieldWin, NativeTextfieldWrapper implementation: |
| 173 | 173 |
| 174 string16 NativeTextfieldWin::GetText() const { | 174 string16 NativeTextfieldWin::GetText() const { |
| 175 int len = GetTextLength() + 1; | 175 int len = GetTextLength() + 1; |
| 176 if (len <= 1) | |
| 177 return string16(); | |
| 178 | |
| 179 string16 str; | 176 string16 str; |
| 180 GetWindowText(WriteInto(&str, len), len); | 177 if (len > 1) |
| 178 GetWindowText(WriteInto(&str, len), len); |
| 181 // The text get from GetWindowText() might be wrapped with explicit bidi | 179 // The text get from GetWindowText() might be wrapped with explicit bidi |
| 182 // control characters. Refer to UpdateText() for detail. Without such | 180 // control characters. Refer to UpdateText() for detail. Without such |
| 183 // wrapping, in RTL chrome, a pure LTR string ending with parenthesis will | 181 // wrapping, in RTL chrome, a pure LTR string ending with parenthesis will |
| 184 // not be displayed correctly in a textfield. For example, "Yahoo!" will be | 182 // not be displayed correctly in a textfield. For example, "Yahoo!" will be |
| 185 // displayed as "!Yahoo", and "Google (by default)" will be displayed as | 183 // displayed as "!Yahoo", and "Google (by default)" will be displayed as |
| 186 // "(Google (by default". | 184 // "(Google (by default". |
| 187 return base::i18n::StripWrappingBidiControlCharacters(WideToUTF16(str)); | 185 return base::i18n::StripWrappingBidiControlCharacters(str); |
| 188 } | 186 } |
| 189 | 187 |
| 190 void NativeTextfieldWin::UpdateText() { | 188 void NativeTextfieldWin::UpdateText() { |
| 191 string16 text = textfield_->text(); | 189 string16 text = textfield_->text(); |
| 192 // Adjusting the string direction before setting the text in order to make | 190 // Adjusting the string direction before setting the text in order to make |
| 193 // sure both RTL and LTR strings are displayed properly. | 191 // sure both RTL and LTR strings are displayed properly. |
| 194 base::i18n::AdjustStringForLocaleDirection(&text); | 192 base::i18n::AdjustStringForLocaleDirection(&text); |
| 195 if (textfield_->style() & Textfield::STYLE_LOWERCASE) | 193 if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| 196 text = base::i18n::ToLower(text); | 194 text = base::i18n::ToLower(text); |
| 197 SetWindowText(text.c_str()); | 195 SetWindowText(text.c_str()); |
| 198 UpdateAccessibleValue(text); | 196 UpdateAccessibleValue(text); |
| 199 } | 197 } |
| 200 | 198 |
| 201 void NativeTextfieldWin::AppendText(const string16& text) { | 199 void NativeTextfieldWin::AppendText(const string16& text) { |
| 202 int text_length = GetWindowTextLength(); | 200 int text_length = GetWindowTextLength(); |
| 203 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); | 201 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); |
| 204 ::SendMessage(m_hWnd, EM_REPLACESEL, false, | 202 ::SendMessage(m_hWnd, EM_REPLACESEL, false, |
| 205 reinterpret_cast<LPARAM>(text.c_str())); | 203 reinterpret_cast<LPARAM>(text.c_str())); |
| 206 } | 204 } |
| 207 | 205 |
| 208 string16 NativeTextfieldWin::GetSelectedText() const { | 206 string16 NativeTextfieldWin::GetSelectedText() const { |
| 209 // Figure out the length of the selection. | |
| 210 CHARRANGE sel; | 207 CHARRANGE sel; |
| 211 GetSel(sel); | 208 GetSel(sel); |
| 212 if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input. | |
| 213 return string16(); | |
| 214 | |
| 215 // Grab the selected text. | |
| 216 string16 str; | 209 string16 str; |
| 217 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); | 210 if (sel.cpMin != sel.cpMax) |
| 211 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); |
| 218 return str; | 212 return str; |
| 219 } | 213 } |
| 220 | 214 |
| 221 void NativeTextfieldWin::SelectAll() { | 215 void NativeTextfieldWin::SelectAll() { |
| 222 // Select from the end to the front so that the first part of the text is | 216 // Select from the end to the front so that the first part of the text is |
| 223 // always visible. | 217 // always visible. |
| 224 SetSel(GetTextLength(), 0); | 218 SetSel(GetTextLength(), 0); |
| 225 } | 219 } |
| 226 | 220 |
| 227 void NativeTextfieldWin::ClearSelection() { | 221 void NativeTextfieldWin::ClearSelection() { |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 | 1153 |
| 1160 // static | 1154 // static |
| 1161 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1155 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 1162 Textfield* field) { | 1156 Textfield* field) { |
| 1163 if (views::Widget::IsPureViews()) | 1157 if (views::Widget::IsPureViews()) |
| 1164 return new NativeTextfieldViews(field); | 1158 return new NativeTextfieldViews(field); |
| 1165 return new NativeTextfieldWin(field); | 1159 return new NativeTextfieldWin(field); |
| 1166 } | 1160 } |
| 1167 | 1161 |
| 1168 } // namespace views | 1162 } // namespace views |
| OLD | NEW |