| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 10 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/l10n_util_win.h" | 12 #include "app/l10n_util_win.h" |
| 13 #include "app/win_util.h" | 13 #include "app/win_util.h" |
| 14 #include "base/i18n/rtl.h" |
| 14 #include "base/keyboard_codes.h" | 15 #include "base/keyboard_codes.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/win_util.h" | 17 #include "base/win_util.h" |
| 17 #include "gfx/native_theme_win.h" | 18 #include "gfx/native_theme_win.h" |
| 18 #include "grit/app_strings.h" | 19 #include "grit/app_strings.h" |
| 19 #include "skia/ext/skia_utils_win.h" | 20 #include "skia/ext/skia_utils_win.h" |
| 20 #include "views/controls/menu/menu_win.h" | 21 #include "views/controls/menu/menu_win.h" |
| 21 #include "views/controls/menu/menu_2.h" | 22 #include "views/controls/menu/menu_2.h" |
| 22 #include "views/controls/native/native_view_host.h" | 23 #include "views/controls/native/native_view_host.h" |
| 23 #include "views/controls/textfield/textfield.h" | 24 #include "views/controls/textfield/textfield.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 std::wstring str; | 125 std::wstring str; |
| 125 GetWindowText(WriteInto(&str, len), len); | 126 GetWindowText(WriteInto(&str, len), len); |
| 126 return str; | 127 return str; |
| 127 } | 128 } |
| 128 | 129 |
| 129 void NativeTextfieldWin::UpdateText() { | 130 void NativeTextfieldWin::UpdateText() { |
| 130 std::wstring text = textfield_->text(); | 131 std::wstring text = textfield_->text(); |
| 131 // Adjusting the string direction before setting the text in order to make | 132 // Adjusting the string direction before setting the text in order to make |
| 132 // sure both RTL and LTR strings are displayed properly. | 133 // sure both RTL and LTR strings are displayed properly. |
| 133 std::wstring text_to_set; | 134 std::wstring text_to_set; |
| 134 if (!l10n_util::AdjustStringForLocaleDirection(text, &text_to_set)) | 135 if (!base::i18n::AdjustStringForLocaleDirection(text, &text_to_set)) |
| 135 text_to_set = text; | 136 text_to_set = text; |
| 136 if (textfield_->style() & Textfield::STYLE_LOWERCASE) | 137 if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
| 137 text_to_set = l10n_util::ToLower(text_to_set); | 138 text_to_set = l10n_util::ToLower(text_to_set); |
| 138 SetWindowText(text_to_set.c_str()); | 139 SetWindowText(text_to_set.c_str()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 void NativeTextfieldWin::AppendText(const string16& text) { | 142 void NativeTextfieldWin::AppendText(const string16& text) { |
| 142 int text_length = GetWindowTextLength(); | 143 int text_length = GetWindowTextLength(); |
| 143 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); | 144 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); |
| 144 ::SendMessage(m_hWnd, EM_REPLACESEL, false, | 145 ::SendMessage(m_hWnd, EM_REPLACESEL, false, |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // Clip the X coordinate to the left edge of the text. Careful: | 802 // Clip the X coordinate to the left edge of the text. Careful: |
| 802 // PosFromChar(0) may return a negative X coordinate if the beginning of the | 803 // PosFromChar(0) may return a negative X coordinate if the beginning of the |
| 803 // text has scrolled off the edit, so don't go past the clip rect's edge. | 804 // text has scrolled off the edit, so don't go past the clip rect's edge. |
| 804 PARAFORMAT2 pf2; | 805 PARAFORMAT2 pf2; |
| 805 GetParaFormat(pf2); | 806 GetParaFormat(pf2); |
| 806 // Calculation of the clipped coordinate is more complicated if the paragraph | 807 // Calculation of the clipped coordinate is more complicated if the paragraph |
| 807 // layout is RTL layout, or if there is RTL characters inside the LTR layout | 808 // layout is RTL layout, or if there is RTL characters inside the LTR layout |
| 808 // paragraph. | 809 // paragraph. |
| 809 bool ltr_text_in_ltr_layout = true; | 810 bool ltr_text_in_ltr_layout = true; |
| 810 if ((pf2.wEffects & PFE_RTLPARA) || | 811 if ((pf2.wEffects & PFE_RTLPARA) || |
| 811 l10n_util::StringContainsStrongRTLChars(GetText())) { | 812 base::i18n::StringContainsStrongRTLChars(GetText())) { |
| 812 ltr_text_in_ltr_layout = false; | 813 ltr_text_in_ltr_layout = false; |
| 813 } | 814 } |
| 814 const int length = GetTextLength(); | 815 const int length = GetTextLength(); |
| 815 RECT r; | 816 RECT r; |
| 816 GetRect(&r); | 817 GetRect(&r); |
| 817 // The values returned by PosFromChar() seem to refer always | 818 // The values returned by PosFromChar() seem to refer always |
| 818 // to the left edge of the character's bounding box. | 819 // to the left edge of the character's bounding box. |
| 819 const LONG first_position_x = PosFromChar(0).x; | 820 const LONG first_position_x = PosFromChar(0).x; |
| 820 LONG min_x = first_position_x; | 821 LONG min_x = first_position_x; |
| 821 if (!ltr_text_in_ltr_layout) { | 822 if (!ltr_text_in_ltr_layout) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 //////////////////////////////////////////////////////////////////////////////// | 903 //////////////////////////////////////////////////////////////////////////////// |
| 903 // NativeTextfieldWrapper, public: | 904 // NativeTextfieldWrapper, public: |
| 904 | 905 |
| 905 // static | 906 // static |
| 906 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 907 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 907 Textfield* field) { | 908 Textfield* field) { |
| 908 return new NativeTextfieldWin(field); | 909 return new NativeTextfieldWin(field); |
| 909 } | 910 } |
| 910 | 911 |
| 911 } // namespace views | 912 } // namespace views |
| OLD | NEW |