summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/textfield/native_textfield_win.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 20:06:18 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 20:06:18 +0000
commitfdce4788af32cb9af8d77361cfddb96249263437 (patch)
tree30c6e4b04a7f46658a57a1265729e0b5ebd2de10 /ui/views/controls/textfield/native_textfield_win.cc
parent7d1025eeb76f1fe0e7bfe19f9f23b64974a63820 (diff)
downloadchromium_src-fdce4788af32cb9af8d77361cfddb96249263437.zip
chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.gz
chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.bz2
ake string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the without-'\0' string is non-empty. This replaces the conditional code added recently that makes this case return NULL. It's easier to understand if it's simply an error to call WriteInto() in this case at all.
Add DCHECK()s or conditionals as appropriate to callers in order to ensure this assertion holds. BUG=none TEST=none Review URL: http://codereview.chromium.org/8418034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls/textfield/native_textfield_win.cc')
-rw-r--r--ui/views/controls/textfield/native_textfield_win.cc16
1 files changed, 5 insertions, 11 deletions
diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc
index 20cae12..3b598e1 100644
--- a/ui/views/controls/textfield/native_textfield_win.cc
+++ b/ui/views/controls/textfield/native_textfield_win.cc
@@ -173,18 +173,16 @@ void NativeTextfieldWin::AttachHack() {
string16 NativeTextfieldWin::GetText() const {
int len = GetTextLength() + 1;
- if (len <= 1)
- return string16();
-
string16 str;
- GetWindowText(WriteInto(&str, len), len);
+ if (len > 1)
+ GetWindowText(WriteInto(&str, len), len);
// The text get from GetWindowText() might be wrapped with explicit bidi
// control characters. Refer to UpdateText() for detail. Without such
// wrapping, in RTL chrome, a pure LTR string ending with parenthesis will
// not be displayed correctly in a textfield. For example, "Yahoo!" will be
// displayed as "!Yahoo", and "Google (by default)" will be displayed as
// "(Google (by default".
- return base::i18n::StripWrappingBidiControlCharacters(WideToUTF16(str));
+ return base::i18n::StripWrappingBidiControlCharacters(str);
}
void NativeTextfieldWin::UpdateText() {
@@ -206,15 +204,11 @@ void NativeTextfieldWin::AppendText(const string16& text) {
}
string16 NativeTextfieldWin::GetSelectedText() const {
- // Figure out the length of the selection.
CHARRANGE sel;
GetSel(sel);
- if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input.
- return string16();
-
- // Grab the selected text.
string16 str;
- GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
+ if (sel.cpMin != sel.cpMax)
+ GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1));
return str;
}