Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 read_only_(false), | 244 read_only_(false), |
| 245 default_width_in_chars_(0), | 245 default_width_in_chars_(0), |
| 246 use_default_text_color_(true), | 246 use_default_text_color_(true), |
| 247 use_default_background_color_(true), | 247 use_default_background_color_(true), |
| 248 use_default_selection_text_color_(true), | 248 use_default_selection_text_color_(true), |
| 249 use_default_selection_background_color_(true), | 249 use_default_selection_background_color_(true), |
| 250 text_color_(SK_ColorBLACK), | 250 text_color_(SK_ColorBLACK), |
| 251 background_color_(SK_ColorWHITE), | 251 background_color_(SK_ColorWHITE), |
| 252 selection_text_color_(SK_ColorWHITE), | 252 selection_text_color_(SK_ColorWHITE), |
| 253 selection_background_color_(SK_ColorBLUE), | 253 selection_background_color_(SK_ColorBLUE), |
| 254 change_selection_background_color_on_next_blur_(false), | |
| 254 placeholder_text_color_(kDefaultPlaceholderTextColor), | 255 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 256 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 256 text_input_flags_(0), | 257 text_input_flags_(0), |
| 257 performing_user_action_(false), | 258 performing_user_action_(false), |
| 258 skip_input_method_cancel_composition_(false), | 259 skip_input_method_cancel_composition_(false), |
| 259 drop_cursor_visible_(false), | 260 drop_cursor_visible_(false), |
| 260 initiating_drag_(false), | 261 initiating_drag_(false), |
| 261 aggregated_clicks_(0), | 262 aggregated_clicks_(0), |
| 262 drag_start_display_offset_(0), | 263 drag_start_display_offset_(0), |
| 263 touch_handles_hidden_due_to_scroll_(false), | 264 touch_handles_hidden_due_to_scroll_(false), |
| 264 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()), | 265 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()), |
| 265 weak_ptr_factory_(this) { | 266 weak_ptr_factory_(this) { |
| 266 set_context_menu_controller(this); | 267 set_context_menu_controller(this); |
| 267 set_drag_controller(this); | 268 set_drag_controller(this); |
| 268 GetRenderText()->SetFontList(GetDefaultFontList()); | 269 GetRenderText()->SetFontList(GetDefaultFontList()); |
| 269 View::SetBorder(std::unique_ptr<Border>(new FocusableBorder())); | 270 View::SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
| 270 SetFocusBehavior(FocusBehavior::ALWAYS); | 271 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 271 | 272 |
| 272 // These allow BrowserView to pass edit commands from the Chrome menu to us | 273 // These allow BrowserView to pass edit commands from the Chrome menu to us |
| 273 // when we're focused by simply asking the FocusManager to | 274 // when we're focused by simply asking the FocusManager to |
| 274 // ProcessAccelerator() with the relevant accelerators. | 275 // ProcessAccelerator() with the relevant accelerators. |
| 275 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); | 276 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); |
| 276 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); | 277 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); |
| 277 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 278 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
| 278 } | 279 } |
| 279 | 280 |
| 280 Textfield::~Textfield() { | 281 Textfield::~Textfield() { |
| 282 FocusManager* focus_manager = GetFocusManager(); | |
|
tapted
2016/10/13 06:21:35
comment why this might be null?
Patti Lor
2016/10/24 02:43:17
Done.
| |
| 283 if (focus_manager) | |
| 284 focus_manager->RemoveFocusChangeListener(this); | |
| 285 | |
| 281 if (GetInputMethod()) { | 286 if (GetInputMethod()) { |
| 282 // The textfield should have been blurred before destroy. | 287 // The textfield should have been blurred before destroy. |
| 283 DCHECK(this != GetInputMethod()->GetTextInputClient()); | 288 DCHECK(this != GetInputMethod()->GetTextInputClient()); |
| 284 } | 289 } |
| 285 } | 290 } |
| 286 | 291 |
| 287 void Textfield::SetReadOnly(bool read_only) { | 292 void Textfield::SetReadOnly(bool read_only) { |
| 288 // Update read-only without changing the focusable state (or active, etc.). | 293 // Update read-only without changing the focusable state (or active, etc.). |
| 289 read_only_ = read_only; | 294 read_only_ = read_only; |
| 290 if (GetInputMethod()) | 295 if (GetInputMethod()) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 SkColor Textfield::GetSelectionBackgroundColor() const { | 426 SkColor Textfield::GetSelectionBackgroundColor() const { |
| 422 return use_default_selection_background_color_ ? | 427 return use_default_selection_background_color_ ? |
| 423 GetNativeTheme()->GetSystemColor( | 428 GetNativeTheme()->GetSystemColor( |
| 424 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : | 429 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : |
| 425 selection_background_color_; | 430 selection_background_color_; |
| 426 } | 431 } |
| 427 | 432 |
| 428 void Textfield::SetSelectionBackgroundColor(SkColor color) { | 433 void Textfield::SetSelectionBackgroundColor(SkColor color) { |
| 429 selection_background_color_ = color; | 434 selection_background_color_ = color; |
| 430 use_default_selection_background_color_ = false; | 435 use_default_selection_background_color_ = false; |
| 431 GetRenderText()->set_selection_background_focused_color( | 436 GetRenderText()->set_selection_background_color( |
| 432 GetSelectionBackgroundColor()); | 437 GetSelectionBackgroundColor()); |
| 433 SchedulePaint(); | 438 SchedulePaint(); |
| 434 } | 439 } |
| 435 | 440 |
| 436 void Textfield::UseDefaultSelectionBackgroundColor() { | 441 void Textfield::UseDefaultSelectionBackgroundColor() { |
| 437 use_default_selection_background_color_ = true; | 442 use_default_selection_background_color_ = true; |
| 438 GetRenderText()->set_selection_background_focused_color( | 443 GetRenderText()->set_selection_background_color( |
| 439 GetSelectionBackgroundColor()); | 444 GetSelectionBackgroundColor()); |
| 440 SchedulePaint(); | 445 SchedulePaint(); |
| 441 } | 446 } |
| 442 | 447 |
| 448 SkColor Textfield::GetUnfocusedSelectionBackgroundColor() const { | |
| 449 return GetNativeTheme()->GetSystemColor( | |
| 450 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused); | |
| 451 } | |
| 452 | |
| 443 bool Textfield::GetCursorEnabled() const { | 453 bool Textfield::GetCursorEnabled() const { |
| 444 return GetRenderText()->cursor_enabled(); | 454 return GetRenderText()->cursor_enabled(); |
| 445 } | 455 } |
| 446 | 456 |
| 447 void Textfield::SetCursorEnabled(bool enabled) { | 457 void Textfield::SetCursorEnabled(bool enabled) { |
| 448 GetRenderText()->SetCursorEnabled(enabled); | 458 GetRenderText()->SetCursorEnabled(enabled); |
| 449 } | 459 } |
| 450 | 460 |
| 451 const gfx::FontList& Textfield::GetFontList() const { | 461 const gfx::FontList& Textfield::GetFontList() const { |
| 452 return GetRenderText()->font_list(); | 462 return GetRenderText()->font_list(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 539 |
| 530 void Textfield::SetAccessibleName(const base::string16& name) { | 540 void Textfield::SetAccessibleName(const base::string16& name) { |
| 531 accessible_name_ = name; | 541 accessible_name_ = name; |
| 532 } | 542 } |
| 533 | 543 |
| 534 bool Textfield::HasTextBeingDragged() { | 544 bool Textfield::HasTextBeingDragged() { |
| 535 return initiating_drag_; | 545 return initiating_drag_; |
| 536 } | 546 } |
| 537 | 547 |
| 538 //////////////////////////////////////////////////////////////////////////////// | 548 //////////////////////////////////////////////////////////////////////////////// |
| 539 // Textfield, View overrides: | 549 // Textfield, View: |
| 540 | 550 |
| 541 gfx::Insets Textfield::GetInsets() const { | 551 gfx::Insets Textfield::GetInsets() const { |
| 542 gfx::Insets insets = View::GetInsets(); | 552 gfx::Insets insets = View::GetInsets(); |
| 543 insets += gfx::Insets(kTextPadding, kTextPadding, kTextPadding, kTextPadding); | 553 insets += gfx::Insets(kTextPadding, kTextPadding, kTextPadding, kTextPadding); |
| 544 return insets; | 554 return insets; |
| 545 } | 555 } |
| 546 | 556 |
| 547 int Textfield::GetBaseline() const { | 557 int Textfield::GetBaseline() const { |
| 548 return GetInsets().top() + GetRenderText()->GetBaseline(); | 558 return GetInsets().top() + GetRenderText()->GetBaseline(); |
| 549 } | 559 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 579 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { | 589 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { |
| 580 RequestFocus(); | 590 RequestFocus(); |
| 581 ShowImeIfNeeded(); | 591 ShowImeIfNeeded(); |
| 582 } | 592 } |
| 583 | 593 |
| 584 if (event.IsOnlyLeftMouseButton()) { | 594 if (event.IsOnlyLeftMouseButton()) { |
| 585 OnBeforeUserAction(); | 595 OnBeforeUserAction(); |
| 586 initiating_drag_ = false; | 596 initiating_drag_ = false; |
| 587 switch (aggregated_clicks_) { | 597 switch (aggregated_clicks_) { |
| 588 case 0: | 598 case 0: |
| 589 if (GetRenderText()->IsPointInSelection(event.location())) | 599 if (GetRenderText()->IsPointInSelection(event.location())) { |
| 590 initiating_drag_ = true; | 600 initiating_drag_ = true; |
| 591 else | 601 // If this isn't actually a mouse drag (determined later in |
| 602 // OnMouseReleased()), the selection should be cleared before being | |
| 603 // drawn. But if it does turn out to be a mouse drag (determined | |
| 604 // later in OnMouseDragged()), the selection needs to be kept for | |
| 605 // dragging. Don't draw the text selection til it's known for sure. | |
| 606 if (!GetSelectedRange().is_empty()) | |
| 607 GetRenderText()->set_draw_text_selection(false); | |
| 608 } else { | |
| 592 MoveCursorTo(event.location(), event.IsShiftDown()); | 609 MoveCursorTo(event.location(), event.IsShiftDown()); |
| 610 } | |
| 593 break; | 611 break; |
| 594 case 1: | 612 case 1: |
| 595 SelectWordAt(event.location()); | 613 SelectWordAt(event.location()); |
| 596 double_click_word_ = GetRenderText()->selection(); | 614 double_click_word_ = GetRenderText()->selection(); |
| 597 break; | 615 break; |
| 598 case 2: | 616 case 2: |
| 599 SelectAll(false); | 617 SelectAll(false); |
| 600 break; | 618 break; |
| 601 default: | 619 default: |
| 602 NOTREACHED(); | 620 NOTREACHED(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 617 } | 635 } |
| 618 } | 636 } |
| 619 #endif | 637 #endif |
| 620 } | 638 } |
| 621 | 639 |
| 622 return true; | 640 return true; |
| 623 } | 641 } |
| 624 | 642 |
| 625 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { | 643 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { |
| 626 last_drag_location_ = event.location(); | 644 last_drag_location_ = event.location(); |
| 645 // Follow up from setting this to false in OnMousePressed() - it's safe to | |
| 646 // draw the selection now that it's determined this is a drag. | |
| 647 GetRenderText()->set_draw_text_selection(true); | |
| 627 | 648 |
| 628 // Don't adjust the cursor on a potential drag and drop. | 649 // Don't adjust the cursor on a potential drag and drop. |
| 629 if (initiating_drag_ || !event.IsOnlyLeftMouseButton()) | 650 if (initiating_drag_ || !event.IsOnlyLeftMouseButton()) |
| 630 return true; | 651 return true; |
| 631 | 652 |
| 632 // A timer is used to continuously scroll while selecting beyond side edges. | 653 // A timer is used to continuously scroll while selecting beyond side edges. |
| 633 const int x = event.location().x(); | 654 const int x = event.location().x(); |
| 634 if ((x >= 0 && x <= width()) || GetDragSelectionDelay() == 0) { | 655 if ((x >= 0 && x <= width()) || GetDragSelectionDelay() == 0) { |
| 635 drag_selection_timer_.Stop(); | 656 drag_selection_timer_.Stop(); |
| 636 SelectThroughLastDragLocation(); | 657 SelectThroughLastDragLocation(); |
| 637 } else if (!drag_selection_timer_.IsRunning()) { | 658 } else if (!drag_selection_timer_.IsRunning()) { |
| 638 // Select through the edge of the visible text, then start the scroll timer. | 659 // Select through the edge of the visible text, then start the scroll timer. |
| 639 last_drag_location_.set_x(std::min(std::max(0, x), width())); | 660 last_drag_location_.set_x(std::min(std::max(0, x), width())); |
| 640 SelectThroughLastDragLocation(); | 661 SelectThroughLastDragLocation(); |
| 641 drag_selection_timer_.Start( | 662 drag_selection_timer_.Start( |
| 642 FROM_HERE, base::TimeDelta::FromMilliseconds(GetDragSelectionDelay()), | 663 FROM_HERE, base::TimeDelta::FromMilliseconds(GetDragSelectionDelay()), |
| 643 this, &Textfield::SelectThroughLastDragLocation); | 664 this, &Textfield::SelectThroughLastDragLocation); |
| 644 } | 665 } |
| 645 | 666 |
| 646 return true; | 667 return true; |
| 647 } | 668 } |
| 648 | 669 |
| 649 void Textfield::OnMouseReleased(const ui::MouseEvent& event) { | 670 void Textfield::OnMouseReleased(const ui::MouseEvent& event) { |
| 650 OnBeforeUserAction(); | 671 OnBeforeUserAction(); |
| 651 drag_selection_timer_.Stop(); | 672 drag_selection_timer_.Stop(); |
| 652 // Cancel suspected drag initiations, the user was clicking in the selection. | 673 // Cancel suspected drag initiations, the user was clicking in the selection. |
| 653 if (initiating_drag_) | 674 if (initiating_drag_) { |
| 654 MoveCursorTo(event.location(), false); | 675 MoveCursorTo(event.location(), false); |
| 676 // Follow up from setting this to false in OnMousePressed() - it's safe to | |
| 677 // draw the selection now that it's determined this is just a click. | |
| 678 GetRenderText()->set_draw_text_selection(true); | |
| 679 } | |
| 655 initiating_drag_ = false; | 680 initiating_drag_ = false; |
| 656 UpdateSelectionClipboard(); | 681 UpdateSelectionClipboard(); |
| 657 OnAfterUserAction(); | 682 OnAfterUserAction(); |
| 658 } | 683 } |
| 659 | 684 |
| 660 WordLookupClient* Textfield::GetWordLookupClient() { | 685 WordLookupClient* Textfield::GetWordLookupClient() { |
| 661 return this; | 686 return this; |
| 662 } | 687 } |
| 663 | 688 |
| 664 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 689 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 touch_selection_controller_->SelectionChanged(); | 999 touch_selection_controller_->SelectionChanged(); |
| 975 } | 1000 } |
| 976 | 1001 |
| 977 void Textfield::OnEnabledChanged() { | 1002 void Textfield::OnEnabledChanged() { |
| 978 View::OnEnabledChanged(); | 1003 View::OnEnabledChanged(); |
| 979 if (GetInputMethod()) | 1004 if (GetInputMethod()) |
| 980 GetInputMethod()->OnTextInputTypeChanged(this); | 1005 GetInputMethod()->OnTextInputTypeChanged(this); |
| 981 SchedulePaint(); | 1006 SchedulePaint(); |
| 982 } | 1007 } |
| 983 | 1008 |
| 1009 void Textfield::ViewHierarchyChanged( | |
| 1010 const ViewHierarchyChangedDetails& details) { | |
| 1011 FocusManager* focus_manager = GetFocusManager(); | |
| 1012 if (details.parent->Contains(this) && details.move_view == nullptr && | |
| 1013 focus_manager) { | |
| 1014 if (details.is_add) | |
| 1015 focus_manager->AddFocusChangeListener(this); | |
| 1016 else | |
| 1017 focus_manager->RemoveFocusChangeListener(this); | |
| 1018 } | |
| 1019 } | |
| 1020 | |
| 984 void Textfield::OnPaint(gfx::Canvas* canvas) { | 1021 void Textfield::OnPaint(gfx::Canvas* canvas) { |
| 985 OnPaintBackground(canvas); | 1022 OnPaintBackground(canvas); |
| 986 PaintTextAndCursor(canvas); | 1023 PaintTextAndCursor(canvas); |
| 987 OnPaintBorder(canvas); | 1024 OnPaintBorder(canvas); |
| 988 } | 1025 } |
| 989 | 1026 |
| 990 void Textfield::OnFocus() { | 1027 void Textfield::OnFocus() { |
| 991 GetRenderText()->set_focused(true); | 1028 GetRenderText()->set_focused(true); |
| 1029 GetRenderText()->set_selection_background_color( | |
| 1030 GetSelectionBackgroundColor()); | |
| 992 if (ShouldShowCursor()) | 1031 if (ShouldShowCursor()) |
| 993 GetRenderText()->set_cursor_visible(true); | 1032 GetRenderText()->set_cursor_visible(true); |
| 994 if (GetInputMethod()) | 1033 if (GetInputMethod()) |
| 995 GetInputMethod()->SetFocusedTextInputClient(this); | 1034 GetInputMethod()->SetFocusedTextInputClient(this); |
| 996 OnCaretBoundsChanged(); | 1035 OnCaretBoundsChanged(); |
| 997 if (ShouldBlinkCursor()) | 1036 if (ShouldBlinkCursor()) |
| 998 StartBlinkingCursor(); | 1037 StartBlinkingCursor(); |
| 999 if (use_focus_ring_) | 1038 if (use_focus_ring_) |
| 1000 FocusRing::Install(this); | 1039 FocusRing::Install(this); |
| 1001 SchedulePaint(); | 1040 SchedulePaint(); |
| 1002 View::OnFocus(); | 1041 View::OnFocus(); |
| 1003 } | 1042 } |
| 1004 | 1043 |
| 1005 void Textfield::OnBlur() { | 1044 void Textfield::OnBlur() { |
| 1006 gfx::RenderText* render_text = GetRenderText(); | 1045 gfx::RenderText* render_text = GetRenderText(); |
| 1007 render_text->set_focused(false); | 1046 render_text->set_focused(false); |
| 1008 if (GetInputMethod()) | 1047 if (GetInputMethod()) |
| 1009 GetInputMethod()->DetachTextInputClient(this); | 1048 GetInputMethod()->DetachTextInputClient(this); |
| 1010 StopBlinkingCursor(); | 1049 StopBlinkingCursor(); |
| 1011 if (render_text->cursor_visible()) { | 1050 if (render_text->cursor_visible()) { |
| 1012 render_text->set_cursor_visible(false); | 1051 render_text->set_cursor_visible(false); |
| 1013 RepaintCursor(); | 1052 RepaintCursor(); |
| 1014 } | 1053 } |
| 1015 | 1054 |
| 1055 if (change_selection_background_color_on_next_blur_) { | |
| 1056 // This being set means the entire Widget has now lost focus. Check that. | |
| 1057 DCHECK(GetFocusManager()->GetFocusedView() == nullptr); | |
| 1058 change_selection_background_color_on_next_blur_ = false; | |
| 1059 GetRenderText()->set_selection_background_color( | |
| 1060 GetUnfocusedSelectionBackgroundColor()); | |
| 1061 GetRenderText()->set_draw_text_selection(true); | |
| 1062 } | |
| 1063 | |
| 1016 DestroyTouchSelection(); | 1064 DestroyTouchSelection(); |
| 1017 | 1065 |
| 1018 if (use_focus_ring_) | 1066 if (use_focus_ring_) |
| 1019 FocusRing::Uninstall(this); | 1067 FocusRing::Uninstall(this); |
| 1020 SchedulePaint(); | 1068 SchedulePaint(); |
| 1021 View::OnBlur(); | 1069 View::OnBlur(); |
| 1022 } | 1070 } |
| 1023 | 1071 |
| 1024 gfx::Point Textfield::GetKeyboardContextMenuLocation() { | 1072 gfx::Point Textfield::GetKeyboardContextMenuLocation() { |
| 1025 return GetCaretBounds().bottom_right(); | 1073 return GetCaretBounds().bottom_right(); |
| 1026 } | 1074 } |
| 1027 | 1075 |
| 1028 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 1076 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 1029 gfx::RenderText* render_text = GetRenderText(); | 1077 gfx::RenderText* render_text = GetRenderText(); |
| 1030 render_text->SetColor(GetTextColor()); | 1078 render_text->SetColor(GetTextColor()); |
| 1031 UpdateBackgroundColor(); | 1079 UpdateBackgroundColor(); |
| 1032 render_text->set_cursor_color(GetTextColor()); | 1080 render_text->set_cursor_color(GetTextColor()); |
| 1033 render_text->set_selection_color(GetSelectionTextColor()); | 1081 render_text->set_selection_color(GetSelectionTextColor()); |
| 1034 render_text->set_selection_background_focused_color( | 1082 if (HasFocus()) |
| 1035 GetSelectionBackgroundColor()); | 1083 render_text->set_selection_background_color(GetSelectionBackgroundColor()); |
| 1084 else | |
|
tapted
2016/10/13 06:21:35
needs curlies (both parts)
Patti Lor
2016/10/24 02:43:17
Done.
| |
| 1085 render_text->set_selection_background_color( | |
| 1086 GetUnfocusedSelectionBackgroundColor()); | |
| 1036 } | 1087 } |
| 1037 | 1088 |
| 1038 //////////////////////////////////////////////////////////////////////////////// | 1089 //////////////////////////////////////////////////////////////////////////////// |
| 1039 // Textfield, TextfieldModel::Delegate overrides: | 1090 // Textfield, TextfieldModel::Delegate: |
| 1040 | 1091 |
| 1041 void Textfield::OnCompositionTextConfirmedOrCleared() { | 1092 void Textfield::OnCompositionTextConfirmedOrCleared() { |
| 1042 if (!skip_input_method_cancel_composition_) | 1093 if (!skip_input_method_cancel_composition_) |
| 1043 GetInputMethod()->CancelComposition(this); | 1094 GetInputMethod()->CancelComposition(this); |
| 1044 } | 1095 } |
| 1045 | 1096 |
| 1046 //////////////////////////////////////////////////////////////////////////////// | 1097 //////////////////////////////////////////////////////////////////////////////// |
| 1047 // Textfield, ContextMenuController overrides: | 1098 // Textfield, ContextMenuController: |
| 1048 | 1099 |
| 1049 void Textfield::ShowContextMenuForView(View* source, | 1100 void Textfield::ShowContextMenuForView(View* source, |
| 1050 const gfx::Point& point, | 1101 const gfx::Point& point, |
| 1051 ui::MenuSourceType source_type) { | 1102 ui::MenuSourceType source_type) { |
| 1052 UpdateContextMenu(); | 1103 UpdateContextMenu(); |
| 1053 ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), | 1104 ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), |
| 1054 NULL, | 1105 NULL, |
| 1055 gfx::Rect(point, gfx::Size()), | 1106 gfx::Rect(point, gfx::Size()), |
| 1056 MENU_ANCHOR_TOPLEFT, | 1107 MENU_ANCHOR_TOPLEFT, |
| 1057 source_type)); | 1108 source_type)); |
| 1058 } | 1109 } |
| 1059 | 1110 |
| 1060 //////////////////////////////////////////////////////////////////////////////// | 1111 //////////////////////////////////////////////////////////////////////////////// |
| 1061 // Textfield, DragController overrides: | 1112 // Textfield, DragController: |
| 1062 | 1113 |
| 1063 void Textfield::WriteDragDataForView(View* sender, | 1114 void Textfield::WriteDragDataForView(View* sender, |
| 1064 const gfx::Point& press_pt, | 1115 const gfx::Point& press_pt, |
| 1065 OSExchangeData* data) { | 1116 OSExchangeData* data) { |
| 1066 const base::string16& selected_text(GetSelectedText()); | 1117 const base::string16& selected_text(GetSelectedText()); |
| 1067 data->SetString(selected_text); | 1118 data->SetString(selected_text); |
| 1068 Label label(selected_text, GetFontList()); | 1119 Label label(selected_text, GetFontList()); |
| 1069 label.SetBackgroundColor(GetBackgroundColor()); | 1120 label.SetBackgroundColor(GetBackgroundColor()); |
| 1070 label.SetSubpixelRenderingEnabled(false); | 1121 label.SetSubpixelRenderingEnabled(false); |
| 1071 gfx::Size size(label.GetPreferredSize()); | 1122 gfx::Size size(label.GetPreferredSize()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1102 return drag_operations; | 1153 return drag_operations; |
| 1103 } | 1154 } |
| 1104 | 1155 |
| 1105 bool Textfield::CanStartDragForView(View* sender, | 1156 bool Textfield::CanStartDragForView(View* sender, |
| 1106 const gfx::Point& press_pt, | 1157 const gfx::Point& press_pt, |
| 1107 const gfx::Point& p) { | 1158 const gfx::Point& p) { |
| 1108 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt); | 1159 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt); |
| 1109 } | 1160 } |
| 1110 | 1161 |
| 1111 //////////////////////////////////////////////////////////////////////////////// | 1162 //////////////////////////////////////////////////////////////////////////////// |
| 1163 // Textfield, FocusChangeListener: | |
| 1164 | |
| 1165 void Textfield::OnWillChangeFocus(View* focus_before, View* focus_after) { | |
| 1166 // If this was the last focused View before switching Widgets, draw the text | |
| 1167 // selection grayed out. | |
| 1168 if (focus_before == this && focus_after == nullptr) | |
| 1169 change_selection_background_color_on_next_blur_ = true; | |
|
tapted
2016/10/13 06:21:35
what happens if we try to gray it out immediately?
Patti Lor
2016/10/24 02:43:17
Ah, I think that variable was there from your sugg
| |
| 1170 // If another View in the same widget is focused, don't draw the selection. | |
| 1171 else if (focus_before == this && focus_after != nullptr) | |
|
tapted
2016/10/13 06:21:35
needs curlies due to comments
Patti Lor
2016/10/24 02:43:17
Done.
| |
| 1172 GetRenderText()->set_draw_text_selection(false); | |
| 1173 // This is focused now, draw the text selection. | |
| 1174 else if (focus_after == this) | |
| 1175 GetRenderText()->set_draw_text_selection(true); | |
| 1176 } | |
| 1177 | |
| 1178 void Textfield::OnDidChangeFocus(View* focused_before, View* focused_now) {} | |
| 1179 | |
| 1180 //////////////////////////////////////////////////////////////////////////////// | |
| 1112 // Textfield, WordLookupClient overrides: | 1181 // Textfield, WordLookupClient overrides: |
| 1113 | 1182 |
| 1114 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, | 1183 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, |
| 1115 gfx::DecoratedText* decorated_word, | 1184 gfx::DecoratedText* decorated_word, |
| 1116 gfx::Point* baseline_point) { | 1185 gfx::Point* baseline_point) { |
| 1117 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, | 1186 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, |
| 1118 baseline_point); | 1187 baseline_point); |
| 1119 } | 1188 } |
| 1120 | 1189 |
| 1121 //////////////////////////////////////////////////////////////////////////////// | 1190 //////////////////////////////////////////////////////////////////////////////// |
| 1122 // Textfield, ui::TouchEditable overrides: | 1191 // Textfield, ui::TouchEditable: |
| 1123 | 1192 |
| 1124 void Textfield::SelectRect(const gfx::Point& start, const gfx::Point& end) { | 1193 void Textfield::SelectRect(const gfx::Point& start, const gfx::Point& end) { |
| 1125 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 1194 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 1126 return; | 1195 return; |
| 1127 | 1196 |
| 1128 gfx::SelectionModel start_caret = GetRenderText()->FindCursorPosition(start); | 1197 gfx::SelectionModel start_caret = GetRenderText()->FindCursorPosition(start); |
| 1129 gfx::SelectionModel end_caret = GetRenderText()->FindCursorPosition(end); | 1198 gfx::SelectionModel end_caret = GetRenderText()->FindCursorPosition(end); |
| 1130 gfx::SelectionModel selection( | 1199 gfx::SelectionModel selection( |
| 1131 gfx::Range(start_caret.caret_pos(), end_caret.caret_pos()), | 1200 gfx::Range(start_caret.caret_pos(), end_caret.caret_pos()), |
| 1132 end_caret.caret_affinity()); | 1201 end_caret.caret_affinity()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 void Textfield::OpenContextMenu(const gfx::Point& anchor) { | 1264 void Textfield::OpenContextMenu(const gfx::Point& anchor) { |
| 1196 DestroyTouchSelection(); | 1265 DestroyTouchSelection(); |
| 1197 ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU); | 1266 ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU); |
| 1198 } | 1267 } |
| 1199 | 1268 |
| 1200 void Textfield::DestroyTouchSelection() { | 1269 void Textfield::DestroyTouchSelection() { |
| 1201 touch_selection_controller_.reset(); | 1270 touch_selection_controller_.reset(); |
| 1202 } | 1271 } |
| 1203 | 1272 |
| 1204 //////////////////////////////////////////////////////////////////////////////// | 1273 //////////////////////////////////////////////////////////////////////////////// |
| 1205 // Textfield, ui::SimpleMenuModel::Delegate overrides: | 1274 // Textfield, ui::SimpleMenuModel::Delegate: |
| 1206 | 1275 |
| 1207 bool Textfield::IsCommandIdChecked(int command_id) const { | 1276 bool Textfield::IsCommandIdChecked(int command_id) const { |
| 1208 return true; | 1277 return true; |
| 1209 } | 1278 } |
| 1210 | 1279 |
| 1211 bool Textfield::IsCommandIdEnabled(int command_id) const { | 1280 bool Textfield::IsCommandIdEnabled(int command_id) const { |
| 1212 return Textfield::IsTextEditCommandEnabled( | 1281 return Textfield::IsTextEditCommandEnabled( |
| 1213 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1282 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| 1214 } | 1283 } |
| 1215 | 1284 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1240 return false; | 1309 return false; |
| 1241 } | 1310 } |
| 1242 } | 1311 } |
| 1243 | 1312 |
| 1244 void Textfield::ExecuteCommand(int command_id, int event_flags) { | 1313 void Textfield::ExecuteCommand(int command_id, int event_flags) { |
| 1245 Textfield::ExecuteTextEditCommand( | 1314 Textfield::ExecuteTextEditCommand( |
| 1246 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1315 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| 1247 } | 1316 } |
| 1248 | 1317 |
| 1249 //////////////////////////////////////////////////////////////////////////////// | 1318 //////////////////////////////////////////////////////////////////////////////// |
| 1250 // Textfield, ui::TextInputClient overrides: | 1319 // Textfield, ui::TextInputClient: |
| 1251 | 1320 |
| 1252 void Textfield::SetCompositionText(const ui::CompositionText& composition) { | 1321 void Textfield::SetCompositionText(const ui::CompositionText& composition) { |
| 1253 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 1322 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 1254 return; | 1323 return; |
| 1255 | 1324 |
| 1256 OnBeforeUserAction(); | 1325 OnBeforeUserAction(); |
| 1257 skip_input_method_cancel_composition_ = true; | 1326 skip_input_method_cancel_composition_ = true; |
| 1258 model_->SetCompositionText(composition); | 1327 model_->SetCompositionText(composition); |
| 1259 skip_input_method_cancel_composition_ = false; | 1328 skip_input_method_cancel_composition_ = false; |
| 1260 UpdateAfterChange(true, true); | 1329 UpdateAfterChange(true, true); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2081 } | 2150 } |
| 2082 | 2151 |
| 2083 void Textfield::OnCursorBlinkTimerFired() { | 2152 void Textfield::OnCursorBlinkTimerFired() { |
| 2084 DCHECK(ShouldBlinkCursor()); | 2153 DCHECK(ShouldBlinkCursor()); |
| 2085 gfx::RenderText* render_text = GetRenderText(); | 2154 gfx::RenderText* render_text = GetRenderText(); |
| 2086 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2155 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2087 RepaintCursor(); | 2156 RepaintCursor(); |
| 2088 } | 2157 } |
| 2089 | 2158 |
| 2090 } // namespace views | 2159 } // namespace views |
| OLD | NEW |