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/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "ui/base/accessibility/accessible_view_state.h" | 12 #include "ui/base/accessibility/accessible_view_state.h" |
12 #include "ui/base/ime/text_input_type.h" | 13 #include "ui/base/ime/text_input_type.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
14 #include "ui/base/range/range.h" | 15 #include "ui/base/range/range.h" |
16 #include "ui/base/ui_base_switches.h" | |
15 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" |
16 #include "ui/gfx/selection_model.h" | 18 #include "ui/gfx/selection_model.h" |
17 #include "ui/views/controls/native/native_view_host.h" | 19 #include "ui/views/controls/native/native_view_host.h" |
20 #include "ui/views/controls/textfield/native_textfield_views.h" | |
18 #include "ui/views/controls/textfield/native_textfield_wrapper.h" | 21 #include "ui/views/controls/textfield/native_textfield_wrapper.h" |
19 #include "ui/views/controls/textfield/textfield_controller.h" | 22 #include "ui/views/controls/textfield/textfield_controller.h" |
20 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
21 | 24 |
22 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
23 #include "base/win/win_util.h" | 26 #include "base/win/win_util.h" |
24 // TODO(beng): this should be removed when the OS_WIN hack from | 27 // TODO(beng): this should be removed when the OS_WIN hack from |
25 // ViewHierarchyChanged is removed. | 28 // ViewHierarchyChanged is removed. |
26 #include "ui/views/controls/textfield/native_textfield_views.h" | |
27 #include "ui/views/controls/textfield/native_textfield_win.h" | 29 #include "ui/views/controls/textfield/native_textfield_win.h" |
28 #endif | 30 #endif |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 // Default placeholder text color. | 34 // Default placeholder text color. |
33 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; | 35 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; |
34 | 36 |
37 #if defined(OS_WIN) && !defined(USE_AURA) | |
38 bool UseNativeTextfieldViews() { | |
39 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
40 return command_line->HasSwitch(switches::kEnableViewsTextfield); | |
41 } | |
42 #endif | |
43 | |
35 } // namespace | 44 } // namespace |
36 | 45 |
37 namespace views { | 46 namespace views { |
38 | 47 |
39 // static | 48 // static |
40 const char Textfield::kViewClassName[] = "views/Textfield"; | 49 const char Textfield::kViewClassName[] = "views/Textfield"; |
41 | 50 |
42 ///////////////////////////////////////////////////////////////////////////// | 51 ///////////////////////////////////////////////////////////////////////////// |
43 // Textfield | 52 // Textfield |
44 | 53 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 insets.width(), font_height + insets.height()); | 369 insets.width(), font_height + insets.height()); |
361 } | 370 } |
362 | 371 |
363 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { | 372 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { |
364 SelectAll(); | 373 SelectAll(); |
365 } | 374 } |
366 | 375 |
367 bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { | 376 bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { |
368 // TODO(hamaji): Figure out which keyboard combinations we need to add here, | 377 // TODO(hamaji): Figure out which keyboard combinations we need to add here, |
369 // similar to LocationBarView::SkipDefaultKeyEventProcessing. | 378 // similar to LocationBarView::SkipDefaultKeyEventProcessing. |
370 ui::KeyboardCode key = e.key_code(); | 379 if (e.key_code() == ui::VKEY_BACK) |
371 if (key == ui::VKEY_BACK) | |
372 return true; // We'll handle BackSpace ourselves. | 380 return true; // We'll handle BackSpace ourselves. |
373 | 381 |
374 #if defined(USE_AURA) | 382 #if defined(USE_AURA) |
375 NOTIMPLEMENTED(); | 383 NOTIMPLEMENTED(); |
376 #elif defined(OS_WIN) | 384 #elif defined(OS_WIN) |
377 // We don't translate accelerators for ALT + NumPad digit on Windows, they are | 385 // We don't translate accelerators for ALT + NumPad digit on Windows, they are |
378 // used for entering special characters. We do translate alt-home. | 386 // used for entering special characters. We do translate alt-home. |
379 if (e.IsAltDown() && (key != ui::VKEY_HOME) && | 387 if (e.IsAltDown() && (e.key_code() != ui::VKEY_HOME) && e.IsNumPadDigit()) |
380 NativeTextfieldWin::IsNumPadDigit(key, | |
381 (e.flags() & ui::EF_EXTENDED) != 0)) | |
382 return true; | 388 return true; |
383 #endif | 389 #endif |
384 return false; | 390 return false; |
385 } | 391 } |
386 | 392 |
387 void Textfield::OnPaintFocusBorder(gfx::Canvas* canvas) { | 393 void Textfield::OnPaintFocusBorder(gfx::Canvas* canvas) { |
388 if (NativeViewHost::kRenderNativeControlFocus) | 394 if (NativeViewHost::kRenderNativeControlFocus) |
389 View::OnPaintFocusBorder(canvas); | 395 View::OnPaintFocusBorder(canvas); |
390 } | 396 } |
391 | 397 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 | 453 |
448 // The native wrapper's lifetime will be managed by the view hierarchy after | 454 // The native wrapper's lifetime will be managed by the view hierarchy after |
449 // we call AddChildView. | 455 // we call AddChildView. |
450 native_wrapper_ = NativeTextfieldWrapper::CreateWrapper(this); | 456 native_wrapper_ = NativeTextfieldWrapper::CreateWrapper(this); |
451 AddChildView(native_wrapper_->GetView()); | 457 AddChildView(native_wrapper_->GetView()); |
452 // TODO(beng): Move this initialization to NativeTextfieldWin once it | 458 // TODO(beng): Move this initialization to NativeTextfieldWin once it |
453 // subclasses NativeControlWin. | 459 // subclasses NativeControlWin. |
454 UpdateAllProperties(); | 460 UpdateAllProperties(); |
455 | 461 |
456 #if defined(OS_WIN) && !defined(USE_AURA) | 462 #if defined(OS_WIN) && !defined(USE_AURA) |
457 // TODO(beng): remove this once NativeTextfieldWin subclasses | 463 // TODO(beng): Remove this once NativeTextfieldWin subclasses |
458 // NativeControlWin. This is currently called to perform post-AddChildView | 464 // NativeControlWin. This is currently called to perform post-AddChildView |
459 // initialization for the wrapper. | 465 // initialization for the wrapper. |
460 // | 466 // |
461 // Remove the include for native_textfield_win.h above when you fix this. | 467 // Remove the include for native_textfield_win.h above when you fix this. |
462 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); | 468 if (!UseNativeTextfieldViews()) |
469 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); | |
463 #endif | 470 #endif |
464 } | 471 } |
465 } | 472 } |
466 | 473 |
467 std::string Textfield::GetClassName() const { | 474 std::string Textfield::GetClassName() const { |
468 return kViewClassName; | 475 return kViewClassName; |
469 } | 476 } |
470 | 477 |
478 //////////////////////////////////////////////////////////////////////////////// | |
479 // NativeTextfieldWrapper, public: | |
480 | |
481 // static | |
482 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | |
483 Textfield* field) { | |
484 #if defined(OS_WIN) && !defined(USE_AURA) | |
485 if (!UseNativeTextfieldViews()) | |
tfarina
2012/06/08 00:15:00
nit: what happens if this is true? Is that even po
msw
2012/06/08 00:23:49
I'm not sure I understand what you're asking. Both
| |
486 return new NativeTextfieldWin(field); | |
487 #endif | |
488 return new NativeTextfieldViews(field); | |
489 } | |
490 | |
471 } // namespace views | 491 } // namespace views |
OLD | NEW |