From da244100d3ac663a1f827fc712dc508c7761d207 Mon Sep 17 00:00:00 2001 From: "xji@chromium.org" Date: Fri, 7 May 2010 23:13:11 +0000 Subject: This CL fixes issue 42867 - "OK" button disabled on "Edit Exception" dialog box when URL is modified in non-empty input field - RTL In RTL chrome in windows, the text get from "Pattern" text field is wrapped with LRE/POP, which makes the pattern invalid. Trim explicit bidi control characters off in NativeTextfieldWin::GetText(). BUG=http://crbug.com/42867 TEST= 1. Launch Chrome with RTL language UI 2. click Wrench => Options => Under the Hood => Content settings => Exceptions => Edit... 3. modify an existing url on the Pattern field. The "OK" button should not be grayed out. Review URL: http://codereview.chromium.org/1703026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46751 0039d316-1c4b-4281-b951-d872f2087c98 --- base/i18n/rtl.cc | 17 ++++++++++++++++- base/i18n/rtl.h | 12 ++++++++++-- views/controls/textfield/native_textfield_win.cc | 9 ++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/base/i18n/rtl.cc b/base/i18n/rtl.cc index 4755a94..9fbf35e 100644 --- a/base/i18n/rtl.cc +++ b/base/i18n/rtl.cc @@ -225,6 +225,21 @@ std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text) { return *text; } +const string16 StripWrappingBidiControlCharacters(const string16& text) { + if (text.empty()) + return text; + size_t begin_index = 0; + char16 begin = text[begin_index]; + if (begin == kLeftToRightEmbeddingMark || + begin == kRightToLeftEmbeddingMark || + begin == kLeftToRightOverride || + begin == kRightToLeftOverride) + ++begin_index; + size_t end_index = text.length() - 1; + if (text[end_index] == kPopDirectionalFormatting) + --end_index; + return text.substr(begin_index, end_index - begin_index + 1); +} + } // namespace i18n } // namespace base - diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h index 70cd9d3..f708206 100644 --- a/base/i18n/rtl.h +++ b/base/i18n/rtl.h @@ -12,11 +12,13 @@ class FilePath; namespace base { namespace i18n { -const char16 kRightToLeftMark = 0x200f; -const char16 kLeftToRightMark = 0x200e; +const char16 kRightToLeftMark = 0x200F; +const char16 kLeftToRightMark = 0x200E; const char16 kLeftToRightEmbeddingMark = 0x202A; const char16 kRightToLeftEmbeddingMark = 0x202B; const char16 kPopDirectionalFormatting = 0x202C; +const char16 kLeftToRightOverride = 0x202D; +const char16 kRightToLeftOverride = 0x202E; enum TextDirection { UNKNOWN_DIRECTION, @@ -108,6 +110,12 @@ void WrapPathWithLTRFormatting(const FilePath& path, // is returned. std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text); +// Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C) +// explicit bidi control characters from |text|, if there are any. Otherwise, +// return the text itself. Explicit bidi control characters display and have +// semantic effect. They can be deleted so they might not always appear in a +// pair. +const string16 StripWrappingBidiControlCharacters(const string16& text); } // namespace i18n } // namespace base diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 13cf93b..a981b79 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -14,6 +14,7 @@ #include "base/i18n/rtl.h" #include "base/keyboard_codes.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "base/win_util.h" #include "gfx/native_theme_win.h" #include "grit/app_strings.h" @@ -124,7 +125,13 @@ string16 NativeTextfieldWin::GetText() const { int len = GetTextLength() + 1; std::wstring str; GetWindowText(WriteInto(&str, len), len); - return str; + // 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)); } void NativeTextfieldWin::UpdateText() { -- cgit v1.1