OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/native_textfield_win.h" | 5 #include "ui/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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/win/metro.h" | 13 #include "base/win/metro.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "grit/ui_strings.h" | 15 #include "grit/ui_strings.h" |
16 #include "skia/ext/skia_utils_win.h" | 16 #include "skia/ext/skia_utils_win.h" |
17 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
18 #include "ui/base/clipboard/clipboard.h" | 18 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 19 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
20 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | |
21 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
22 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/l10n/l10n_util_win.h" | 22 #include "ui/base/l10n/l10n_util_win.h" |
24 #include "ui/base/native_theme/native_theme_win.h" | 23 #include "ui/base/native_theme/native_theme_win.h" |
25 #include "ui/base/range/range.h" | 24 #include "ui/base/range/range.h" |
26 #include "ui/base/win/mouse_wheel_util.h" | 25 #include "ui/base/win/mouse_wheel_util.h" |
27 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
28 #include "ui/views/controls/menu/menu_item_view.h" | 27 #include "ui/views/controls/menu/menu_item_view.h" |
29 #include "ui/views/controls/menu/menu_model_adapter.h" | 28 #include "ui/views/controls/menu/menu_model_adapter.h" |
30 #include "ui/views/controls/menu/menu_runner.h" | 29 #include "ui/views/controls/menu/menu_runner.h" |
31 #include "ui/views/controls/native/native_view_host.h" | 30 #include "ui/views/controls/native/native_view_host.h" |
32 #include "ui/views/controls/textfield/native_textfield_views.h" | |
33 #include "ui/views/controls/textfield/textfield.h" | 31 #include "ui/views/controls/textfield/textfield.h" |
34 #include "ui/views/controls/textfield/textfield_controller.h" | 32 #include "ui/views/controls/textfield/textfield_controller.h" |
35 #include "ui/views/focus/focus_manager.h" | 33 #include "ui/views/focus/focus_manager.h" |
36 #include "ui/views/metrics.h" | 34 #include "ui/views/metrics.h" |
37 #include "ui/views/views_delegate.h" | 35 #include "ui/views/views_delegate.h" |
38 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
39 | 37 |
40 namespace views { | 38 namespace views { |
41 | 39 |
42 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const POINT& current, | 143 const POINT& current, |
146 DWORD elapsed_time) { | 144 DWORD elapsed_time) { |
147 // The CXDOUBLECLK and CYDOUBLECLK system metrics describe the width and | 145 // The CXDOUBLECLK and CYDOUBLECLK system metrics describe the width and |
148 // height of a rectangle around the origin position, inside of which clicks | 146 // height of a rectangle around the origin position, inside of which clicks |
149 // within the double click time are considered double clicks. | 147 // within the double click time are considered double clicks. |
150 return (elapsed_time <= GetDoubleClickTime()) && | 148 return (elapsed_time <= GetDoubleClickTime()) && |
151 (abs(current.x - origin.x) <= (GetSystemMetrics(SM_CXDOUBLECLK) / 2)) && | 149 (abs(current.x - origin.x) <= (GetSystemMetrics(SM_CXDOUBLECLK) / 2)) && |
152 (abs(current.y - origin.y) <= (GetSystemMetrics(SM_CYDOUBLECLK) / 2)); | 150 (abs(current.y - origin.y) <= (GetSystemMetrics(SM_CYDOUBLECLK) / 2)); |
153 } | 151 } |
154 | 152 |
155 // static | |
156 bool NativeTextfieldWin::IsNumPadDigit(int key_code, bool extended_key) { | |
157 if (key_code >= VK_NUMPAD0 && key_code <= VK_NUMPAD9) | |
158 return true; | |
159 | |
160 // Check for num pad keys without NumLock. | |
161 // Note: there is no easy way to know if a the key that was pressed comes from | |
162 // the num pad or the rest of the keyboard. Investigating how | |
163 // TranslateMessage() generates the WM_KEYCHAR from an | |
164 // ALT + <NumPad sequences> it appears it looks at the extended key flag | |
165 // (which is on if the key pressed comes from one of the 3 clusters to | |
166 // the left of the numeric keypad). So we use it as well. | |
167 return !extended_key && | |
168 ((key_code >= VK_PRIOR && key_code <= VK_DOWN) || // All keys but 5 | |
169 // and 0. | |
170 (key_code == VK_CLEAR) || // Key 5. | |
171 (key_code == VK_INSERT)); // Key 0. | |
172 } | |
173 | |
174 void NativeTextfieldWin::AttachHack() { | 153 void NativeTextfieldWin::AttachHack() { |
175 // See the code in textfield.cc that calls this for why this is here. | 154 // See the code in textfield.cc that calls this for why this is here. |
176 container_view_->set_focus_view(textfield_); | 155 container_view_->set_focus_view(textfield_); |
177 container_view_->Attach(m_hWnd); | 156 container_view_->Attach(m_hWnd); |
178 } | 157 } |
179 | 158 |
180 //////////////////////////////////////////////////////////////////////////////// | 159 //////////////////////////////////////////////////////////////////////////////// |
181 // NativeTextfieldWin, NativeTextfieldWrapper implementation: | 160 // NativeTextfieldWin, NativeTextfieldWrapper implementation: |
182 | 161 |
183 string16 NativeTextfieldWin::GetText() const { | 162 string16 NativeTextfieldWin::GetText() const { |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); | 1178 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); |
1200 context_menu_contents_->AddSeparator(); | 1179 context_menu_contents_->AddSeparator(); |
1201 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); | 1180 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
1202 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1181 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
1203 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 1182 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
1204 context_menu_contents_->AddSeparator(); | 1183 context_menu_contents_->AddSeparator(); |
1205 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, | 1184 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
1206 IDS_APP_SELECT_ALL); | 1185 IDS_APP_SELECT_ALL); |
1207 } | 1186 } |
1208 | 1187 |
1209 //////////////////////////////////////////////////////////////////////////////// | |
1210 // NativeTextfieldWrapper, public: | |
1211 | |
1212 // static | |
1213 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | |
1214 Textfield* field) { | |
1215 #if defined(USE_AURA) | |
1216 return new NativeTextfieldViews(field); | |
1217 #else | |
1218 return new NativeTextfieldWin(field); | |
1219 #endif | |
1220 } | |
1221 | |
1222 } // namespace views | 1188 } // namespace views |
OLD | NEW |