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_views.h" | 5 #include "ui/views/controls/textfield/native_textfield_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 : textfield_(parent), | 63 : textfield_(parent), |
64 ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TextfieldViewsModel(this))), | 64 ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TextfieldViewsModel(this))), |
65 text_border_(new FocusableBorder()), | 65 text_border_(new FocusableBorder()), |
66 is_cursor_visible_(false), | 66 is_cursor_visible_(false), |
67 is_drop_cursor_visible_(false), | 67 is_drop_cursor_visible_(false), |
68 skip_input_method_cancel_composition_(false), | 68 skip_input_method_cancel_composition_(false), |
69 initiating_drag_(false), | 69 initiating_drag_(false), |
70 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)), | 70 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)), |
71 aggregated_clicks_(0), | 71 aggregated_clicks_(0), |
72 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_( | 72 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_( |
73 TouchSelectionController::create(this))) { | 73 ui::TouchSelectionController::create(this))) { |
74 set_border(text_border_); | 74 set_border(text_border_); |
75 | 75 |
76 #if defined(OS_CHROMEOS) | 76 #if defined(OS_CHROMEOS) |
77 GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8( | 77 GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8( |
78 IDS_UI_FONT_FAMILY_CROS))); | 78 IDS_UI_FONT_FAMILY_CROS))); |
79 #else | 79 #else |
80 GetRenderText()->SetFont(textfield_->font()); | 80 GetRenderText()->SetFont(textfield_->font()); |
81 #endif | 81 #endif |
82 | 82 |
83 UpdateColorsFromTheme(GetNativeTheme()); | 83 UpdateColorsFromTheme(GetNativeTheme()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 case ui::ET_GESTURE_SCROLL_UPDATE: | 165 case ui::ET_GESTURE_SCROLL_UPDATE: |
166 OnBeforeUserAction(); | 166 OnBeforeUserAction(); |
167 if (MoveCursorTo(event->location(), true)) | 167 if (MoveCursorTo(event->location(), true)) |
168 SchedulePaint(); | 168 SchedulePaint(); |
169 OnAfterUserAction(); | 169 OnAfterUserAction(); |
170 event->SetHandled(); | 170 event->SetHandled(); |
171 return; | 171 return; |
172 default: | 172 default: |
173 break; | 173 break; |
174 } | 174 } |
175 TouchSelectionClientView::OnGestureEvent(event); | 175 View::OnGestureEvent(event); |
176 } | 176 } |
177 | 177 |
178 bool NativeTextfieldViews::OnKeyPressed(const ui::KeyEvent& event) { | 178 bool NativeTextfieldViews::OnKeyPressed(const ui::KeyEvent& event) { |
179 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on | 179 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on |
180 // NativeTextfieldViews as it will never gain focus. | 180 // NativeTextfieldViews as it will never gain focus. |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 return false; | 182 return false; |
183 } | 183 } |
184 | 184 |
185 bool NativeTextfieldViews::OnKeyReleased(const ui::KeyEvent& event) { | 185 bool NativeTextfieldViews::OnKeyReleased(const ui::KeyEvent& event) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 ui::Range(start_caret.caret_pos(), end_caret.caret_pos()), | 304 ui::Range(start_caret.caret_pos(), end_caret.caret_pos()), |
305 end_caret.caret_affinity()); | 305 end_caret.caret_affinity()); |
306 | 306 |
307 OnBeforeUserAction(); | 307 OnBeforeUserAction(); |
308 model_->SelectSelectionModel(selection); | 308 model_->SelectSelectionModel(selection); |
309 OnCaretBoundsChanged(); | 309 OnCaretBoundsChanged(); |
310 SchedulePaint(); | 310 SchedulePaint(); |
311 OnAfterUserAction(); | 311 OnAfterUserAction(); |
312 } | 312 } |
313 | 313 |
314 const gfx::Rect& NativeTextfieldViews::GetBounds() { | |
315 return bounds(); | |
316 } | |
317 | |
318 gfx::NativeView NativeTextfieldViews::GetNativeView() { | |
319 return GetWidget()->GetNativeView(); | |
320 } | |
321 | |
322 void NativeTextfieldViews::ConvertPointToScreen(gfx::Point* point) { | |
323 View::ConvertPointToScreen(this, point); | |
324 } | |
325 | |
326 void NativeTextfieldViews::ConvertPointFromScreen(gfx::Point* point) { | |
327 if (!GetWidget()) | |
328 return; | |
329 gfx::Rect r = GetWidget()->GetClientAreaBoundsInScreen(); | |
330 point->SetPoint(point->x() - r.x(), point->y() - r.y()); | |
331 View::ConvertPointFromWidget(this, point); | |
sadrul
2013/02/13 00:49:17
There is View::ConvertPointFromScreen
varunjain
2013/02/13 00:52:12
Done.
| |
332 } | |
333 | |
314 gfx::NativeCursor NativeTextfieldViews::GetCursor(const ui::MouseEvent& event) { | 334 gfx::NativeCursor NativeTextfieldViews::GetCursor(const ui::MouseEvent& event) { |
315 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 335 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
316 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; | 336 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; |
317 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); | 337 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); |
318 #if defined(USE_AURA) | 338 #if defined(USE_AURA) |
319 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; | 339 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; |
320 #elif defined(OS_WIN) | 340 #elif defined(OS_WIN) |
321 static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM); | 341 static HCURSOR ibeam = LoadCursor(NULL, IDC_IBEAM); |
322 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); | 342 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); |
323 return text_cursor ? ibeam : arrow; | 343 return text_cursor ? ibeam : arrow; |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1295 // Filter out all control characters, including tab and new line characters, | 1315 // Filter out all control characters, including tab and new line characters, |
1296 // and all characters with Alt modifier. But we need to allow characters with | 1316 // and all characters with Alt modifier. But we need to allow characters with |
1297 // AltGr modifier. | 1317 // AltGr modifier. |
1298 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1318 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
1299 // flag that we don't care about. | 1319 // flag that we don't care about. |
1300 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1320 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
1301 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1321 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
1302 } | 1322 } |
1303 | 1323 |
1304 } // namespace views | 1324 } // namespace views |
OLD | NEW |