OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/i18n/rtl.h" |
15 #include "base/keyboard_codes.h" | 15 #include "base/keyboard_codes.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/win_util.h" | 18 #include "base/win_util.h" |
19 #include "gfx/native_theme_win.h" | 19 #include "gfx/native_theme_win.h" |
20 #include "grit/app_strings.h" | 20 #include "grit/app_strings.h" |
21 #include "skia/ext/skia_utils_win.h" | 21 #include "skia/ext/skia_utils_win.h" |
22 #include "views/controls/label.h" | |
22 #include "views/controls/menu/menu_win.h" | 23 #include "views/controls/menu/menu_win.h" |
23 #include "views/controls/menu/menu_2.h" | 24 #include "views/controls/menu/menu_2.h" |
24 #include "views/controls/native/native_view_host.h" | 25 #include "views/controls/native/native_view_host.h" |
25 #include "views/controls/textfield/textfield.h" | 26 #include "views/controls/textfield/textfield.h" |
26 #include "views/focus/focus_manager.h" | 27 #include "views/focus/focus_manager.h" |
27 #include "views/focus/focus_util_win.h" | 28 #include "views/focus/focus_util_win.h" |
28 #include "views/views_delegate.h" | 29 #include "views/views_delegate.h" |
29 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
30 | 31 |
31 namespace views { | 32 namespace views { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { | 99 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { |
99 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); | 100 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); |
100 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); | 101 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); |
101 } | 102 } |
102 | 103 |
103 // Set up the text_object_model_. | 104 // Set up the text_object_model_. |
104 ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface; | 105 ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface; |
105 ole_interface.Attach(GetOleInterface()); | 106 ole_interface.Attach(GetOleInterface()); |
106 if (ole_interface) | 107 if (ole_interface) |
107 text_object_model_.QueryFrom(ole_interface); | 108 text_object_model_.QueryFrom(ole_interface); |
109 | |
110 InitializeAccessibilityInfo(); | |
108 } | 111 } |
109 | 112 |
110 NativeTextfieldWin::~NativeTextfieldWin() { | 113 NativeTextfieldWin::~NativeTextfieldWin() { |
111 if (IsWindow()) | 114 if (IsWindow()) |
112 DestroyWindow(); | 115 DestroyWindow(); |
113 } | 116 } |
114 | 117 |
115 void NativeTextfieldWin::AttachHack() { | 118 void NativeTextfieldWin::AttachHack() { |
116 // See the code in textfield.cc that calls this for why this is here. | 119 // See the code in textfield.cc that calls this for why this is here. |
117 container_view_->set_focus_view(textfield_); | 120 container_view_->set_focus_view(textfield_); |
(...skipping 19 matching lines...) Expand all Loading... | |
137 void NativeTextfieldWin::UpdateText() { | 140 void NativeTextfieldWin::UpdateText() { |
138 std::wstring text = textfield_->text(); | 141 std::wstring text = textfield_->text(); |
139 // Adjusting the string direction before setting the text in order to make | 142 // Adjusting the string direction before setting the text in order to make |
140 // sure both RTL and LTR strings are displayed properly. | 143 // sure both RTL and LTR strings are displayed properly. |
141 std::wstring text_to_set; | 144 std::wstring text_to_set; |
142 if (!base::i18n::AdjustStringForLocaleDirection(text, &text_to_set)) | 145 if (!base::i18n::AdjustStringForLocaleDirection(text, &text_to_set)) |
143 text_to_set = text; | 146 text_to_set = text; |
144 if (textfield_->style() & Textfield::STYLE_LOWERCASE) | 147 if (textfield_->style() & Textfield::STYLE_LOWERCASE) |
145 text_to_set = l10n_util::ToLower(text_to_set); | 148 text_to_set = l10n_util::ToLower(text_to_set); |
146 SetWindowText(text_to_set.c_str()); | 149 SetWindowText(text_to_set.c_str()); |
150 UpdateAccessibleValue(text_to_set); | |
147 } | 151 } |
148 | 152 |
149 void NativeTextfieldWin::AppendText(const string16& text) { | 153 void NativeTextfieldWin::AppendText(const string16& text) { |
150 int text_length = GetWindowTextLength(); | 154 int text_length = GetWindowTextLength(); |
151 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); | 155 ::SendMessage(m_hWnd, TBM_SETSEL, true, MAKELPARAM(text_length, text_length)); |
152 ::SendMessage(m_hWnd, EM_REPLACESEL, false, | 156 ::SendMessage(m_hWnd, EM_REPLACESEL, false, |
153 reinterpret_cast<LPARAM>(text.c_str())); | 157 reinterpret_cast<LPARAM>(text.c_str())); |
154 } | 158 } |
155 | 159 |
156 string16 NativeTextfieldWin::GetSelectedText() const { | 160 string16 NativeTextfieldWin::GetSelectedText() const { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 bg_color_ = skia::SkColorToCOLORREF(textfield_->background_color()); | 200 bg_color_ = skia::SkColorToCOLORREF(textfield_->background_color()); |
197 } else { | 201 } else { |
198 bg_color_ = GetSysColor(textfield_->read_only() ? COLOR_3DFACE | 202 bg_color_ = GetSysColor(textfield_->read_only() ? COLOR_3DFACE |
199 : COLOR_WINDOW); | 203 : COLOR_WINDOW); |
200 } | 204 } |
201 CRichEditCtrl::SetBackgroundColor(bg_color_); | 205 CRichEditCtrl::SetBackgroundColor(bg_color_); |
202 } | 206 } |
203 | 207 |
204 void NativeTextfieldWin::UpdateReadOnly() { | 208 void NativeTextfieldWin::UpdateReadOnly() { |
205 SendMessage(m_hWnd, EM_SETREADONLY, textfield_->read_only(), 0); | 209 SendMessage(m_hWnd, EM_SETREADONLY, textfield_->read_only(), 0); |
210 UpdateAccessibleState(STATE_SYSTEM_READONLY, textfield_->read_only()); | |
206 } | 211 } |
207 | 212 |
208 void NativeTextfieldWin::UpdateFont() { | 213 void NativeTextfieldWin::UpdateFont() { |
209 SendMessage(m_hWnd, WM_SETFONT, | 214 SendMessage(m_hWnd, WM_SETFONT, |
210 reinterpret_cast<WPARAM>(textfield_->font().hfont()), TRUE); | 215 reinterpret_cast<WPARAM>(textfield_->font().hfont()), TRUE); |
211 // Setting the font blows away any text color we've set, so reset it. | 216 // Setting the font blows away any text color we've set, so reset it. |
212 UpdateTextColor(); | 217 UpdateTextColor(); |
213 } | 218 } |
214 | 219 |
215 void NativeTextfieldWin::UpdateIsPassword() { | 220 void NativeTextfieldWin::UpdateIsPassword() { |
216 // TODO: Need to implement for Windows. | 221 // TODO: Need to implement for Windows. |
222 UpdateAccessibleState(STATE_SYSTEM_PROTECTED, textfield_->IsPassword()); | |
217 } | 223 } |
218 | 224 |
219 void NativeTextfieldWin::UpdateEnabled() { | 225 void NativeTextfieldWin::UpdateEnabled() { |
220 SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0); | 226 SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0); |
227 UpdateAccessibleState(STATE_SYSTEM_UNAVAILABLE, !textfield_->IsEnabled()); | |
221 } | 228 } |
222 | 229 |
223 gfx::Insets NativeTextfieldWin::CalculateInsets() { | 230 gfx::Insets NativeTextfieldWin::CalculateInsets() { |
224 // NOTE: One would think GetThemeMargins would return the insets we should | 231 // NOTE: One would think GetThemeMargins would return the insets we should |
225 // use, but it doesn't. The margins returned by GetThemeMargins are always | 232 // use, but it doesn't. The margins returned by GetThemeMargins are always |
226 // 0. | 233 // 0. |
227 | 234 |
228 // This appears to be the insets used by Windows. | 235 // This appears to be the insets used by Windows. |
229 return gfx::Insets(3, 3, 3, 3); | 236 return gfx::Insets(3, 3, 3, 3); |
230 } | 237 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 case IDS_APP_UNDO: Undo(); break; | 317 case IDS_APP_UNDO: Undo(); break; |
311 case IDS_APP_CUT: Cut(); break; | 318 case IDS_APP_CUT: Cut(); break; |
312 case IDS_APP_COPY: Copy(); break; | 319 case IDS_APP_COPY: Copy(); break; |
313 case IDS_APP_PASTE: Paste(); break; | 320 case IDS_APP_PASTE: Paste(); break; |
314 case IDS_APP_SELECT_ALL: SelectAll(); break; | 321 case IDS_APP_SELECT_ALL: SelectAll(); break; |
315 default: NOTREACHED(); break; | 322 default: NOTREACHED(); break; |
316 } | 323 } |
317 OnAfterPossibleChange(); | 324 OnAfterPossibleChange(); |
318 } | 325 } |
319 | 326 |
327 void NativeTextfieldWin::InitializeAccessibilityInfo() { | |
328 // Set the accessible state. | |
329 accessibility_state_ = 0; | |
330 | |
331 ScopedComPtr<IAccPropServices> pAccPropServices; | |
332 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | |
333 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | |
334 if (!SUCCEEDED(hr)) | |
335 return; | |
336 | |
337 VARIANT var; | |
338 | |
339 // Set the accessible role. | |
340 var.vt = VT_I4; | |
341 var.lVal = ROLE_SYSTEM_TEXT; | |
342 hr = pAccPropServices->SetHwndProp(m_hWnd, OBJID_CLIENT, | |
343 CHILDID_SELF, PROPID_ACC_ROLE, var); | |
344 | |
345 // Set the accessible name by getting the label text. | |
346 View* parent = textfield_->GetParent(); | |
347 int label_index = parent->GetChildIndex(textfield_) - 1; | |
348 if (label_index >= 0) { | |
349 std::wstring name; | |
350 View* label_view = parent->GetChildViewAt(label_index ); | |
351 if (label_view ->GetClassName() == Label::kViewClassName && | |
Chris Guillory
2010/06/15 17:30:16
Can we DCHECK label_view ->GetClassName() == Label
| |
352 label_view ->GetAccessibleName(&name)) { | |
353 | |
354 hr = pAccPropServices->SetHwndPropStr(m_hWnd, OBJID_CLIENT, | |
355 CHILDID_SELF, PROPID_ACC_NAME, name.c_str()); | |
356 } | |
357 } | |
358 } | |
359 | |
360 void NativeTextfieldWin::UpdateAccessibleState(uint32 state_flag, | |
361 bool set_value) { | |
362 ScopedComPtr<IAccPropServices> pAccPropServices; | |
363 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | |
364 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | |
365 if (!SUCCEEDED(hr)) | |
366 return; | |
367 | |
368 VARIANT var; | |
369 var.vt = VT_I4; | |
370 var.lVal = set_value ? accessibility_state_ | state_flag | |
371 : accessibility_state_ & ~state_flag; | |
372 hr = pAccPropServices->SetHwndProp(m_hWnd, OBJID_CLIENT, | |
373 CHILDID_SELF, PROPID_ACC_STATE, var); | |
374 | |
375 ::NotifyWinEvent(EVENT_OBJECT_STATECHANGE, m_hWnd, OBJID_CLIENT, | |
376 CHILDID_SELF); | |
377 } | |
378 | |
379 void NativeTextfieldWin::UpdateAccessibleValue(const std::wstring& value) { | |
380 ScopedComPtr<IAccPropServices> pAccPropServices; | |
381 HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, | |
382 IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices)); | |
383 if (!SUCCEEDED(hr)) | |
384 return; | |
385 | |
386 hr = pAccPropServices->SetHwndPropStr(m_hWnd, OBJID_CLIENT, | |
387 CHILDID_SELF, PROPID_ACC_VALUE, value.c_str()); | |
388 | |
389 ::NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, m_hWnd, OBJID_CLIENT, | |
390 CHILDID_SELF); | |
391 } | |
392 | |
320 //////////////////////////////////////////////////////////////////////////////// | 393 //////////////////////////////////////////////////////////////////////////////// |
321 // NativeTextfieldWin, private: | 394 // NativeTextfieldWin, private: |
322 | 395 |
323 void NativeTextfieldWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { | 396 void NativeTextfieldWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { |
324 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); | 397 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); |
325 } | 398 } |
326 | 399 |
327 void NativeTextfieldWin::OnContextMenu(HWND window, const POINT& point) { | 400 void NativeTextfieldWin::OnContextMenu(HWND window, const POINT& point) { |
328 POINT p(point); | 401 POINT p(point); |
329 if (point.x == -1 || point.y == -1) { | 402 if (point.x == -1 || point.y == -1) { |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 // A string retrieved with a GetText() call contains a string being | 899 // A string retrieved with a GetText() call contains a string being |
827 // composed by an IME. We remove the composition string from this search | 900 // composed by an IME. We remove the composition string from this search |
828 // string. | 901 // string. |
829 new_text.erase(ime_composition_start_, ime_composition_length_); | 902 new_text.erase(ime_composition_start_, ime_composition_length_); |
830 ime_composition_start_ = 0; | 903 ime_composition_start_ = 0; |
831 ime_composition_length_ = 0; | 904 ime_composition_length_ = 0; |
832 if (new_text.empty()) | 905 if (new_text.empty()) |
833 return; | 906 return; |
834 } | 907 } |
835 textfield_->SyncText(); | 908 textfield_->SyncText(); |
909 UpdateAccessibleValue(textfield_->text()); | |
836 if (textfield_->GetController()) | 910 if (textfield_->GetController()) |
837 textfield_->GetController()->ContentsChanged(textfield_, new_text); | 911 textfield_->GetController()->ContentsChanged(textfield_, new_text); |
838 } | 912 } |
839 } | 913 } |
840 | 914 |
841 LONG NativeTextfieldWin::ClipXCoordToVisibleText(LONG x, | 915 LONG NativeTextfieldWin::ClipXCoordToVisibleText(LONG x, |
842 bool is_triple_click) const { | 916 bool is_triple_click) const { |
843 // Clip the X coordinate to the left edge of the text. Careful: | 917 // Clip the X coordinate to the left edge of the text. Careful: |
844 // PosFromChar(0) may return a negative X coordinate if the beginning of the | 918 // PosFromChar(0) may return a negative X coordinate if the beginning of the |
845 // text has scrolled off the edit, so don't go past the clip rect's edge. | 919 // text has scrolled off the edit, so don't go past the clip rect's edge. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 //////////////////////////////////////////////////////////////////////////////// | 1018 //////////////////////////////////////////////////////////////////////////////// |
945 // NativeTextfieldWrapper, public: | 1019 // NativeTextfieldWrapper, public: |
946 | 1020 |
947 // static | 1021 // static |
948 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1022 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
949 Textfield* field) { | 1023 Textfield* field) { |
950 return new NativeTextfieldWin(field); | 1024 return new NativeTextfieldWin(field); |
951 } | 1025 } |
952 | 1026 |
953 } // namespace views | 1027 } // namespace views |
OLD | NEW |