Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2982453002: New AppListView Scroll Behavior. (Closed)
Patch Set: Addressed comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 391
392 void Textfield::UseDefaultTextColor() { 392 void Textfield::UseDefaultTextColor() {
393 use_default_text_color_ = true; 393 use_default_text_color_ = true;
394 SetColor(GetTextColor()); 394 SetColor(GetTextColor());
395 } 395 }
396 396
397 SkColor Textfield::GetBackgroundColor() const { 397 SkColor Textfield::GetBackgroundColor() const {
398 if (!use_default_background_color_) 398 if (!use_default_background_color_)
399 return background_color_; 399 return background_color_;
400 400
401 return GetNativeTheme()->GetSystemColor(read_only() || !enabled() ? 401 return GetNativeTheme()->GetSystemColor(
402 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground : 402 read_only() || !enabled()
403 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 403 ? ui::NativeTheme::kColorId_TextfieldReadOnlyBackground
404 : ui::NativeTheme::kColorId_TextfieldDefaultBackground);
404 } 405 }
405 406
406 void Textfield::SetBackgroundColor(SkColor color) { 407 void Textfield::SetBackgroundColor(SkColor color) {
407 background_color_ = color; 408 background_color_ = color;
408 use_default_background_color_ = false; 409 use_default_background_color_ = false;
409 UpdateBackgroundColor(); 410 UpdateBackgroundColor();
410 } 411 }
411 412
412 void Textfield::UseDefaultBackgroundColor() { 413 void Textfield::UseDefaultBackgroundColor() {
413 use_default_background_color_ = true; 414 use_default_background_color_ = true;
414 UpdateBackgroundColor(); 415 UpdateBackgroundColor();
415 } 416 }
416 417
417 SkColor Textfield::GetSelectionTextColor() const { 418 SkColor Textfield::GetSelectionTextColor() const {
418 return use_default_selection_text_color_ ? 419 return use_default_selection_text_color_
419 GetNativeTheme()->GetSystemColor( 420 ? GetNativeTheme()->GetSystemColor(
420 ui::NativeTheme::kColorId_TextfieldSelectionColor) : 421 ui::NativeTheme::kColorId_TextfieldSelectionColor)
421 selection_text_color_; 422 : selection_text_color_;
422 } 423 }
423 424
424 void Textfield::SetSelectionTextColor(SkColor color) { 425 void Textfield::SetSelectionTextColor(SkColor color) {
425 selection_text_color_ = color; 426 selection_text_color_ = color;
426 use_default_selection_text_color_ = false; 427 use_default_selection_text_color_ = false;
427 GetRenderText()->set_selection_color(GetSelectionTextColor()); 428 GetRenderText()->set_selection_color(GetSelectionTextColor());
428 SchedulePaint(); 429 SchedulePaint();
429 } 430 }
430 431
431 void Textfield::UseDefaultSelectionTextColor() { 432 void Textfield::UseDefaultSelectionTextColor() {
432 use_default_selection_text_color_ = true; 433 use_default_selection_text_color_ = true;
433 GetRenderText()->set_selection_color(GetSelectionTextColor()); 434 GetRenderText()->set_selection_color(GetSelectionTextColor());
434 SchedulePaint(); 435 SchedulePaint();
435 } 436 }
436 437
437 SkColor Textfield::GetSelectionBackgroundColor() const { 438 SkColor Textfield::GetSelectionBackgroundColor() const {
438 return use_default_selection_background_color_ ? 439 return use_default_selection_background_color_
439 GetNativeTheme()->GetSystemColor( 440 ? GetNativeTheme()->GetSystemColor(
440 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : 441 ui::NativeTheme::
441 selection_background_color_; 442 kColorId_TextfieldSelectionBackgroundFocused)
443 : selection_background_color_;
442 } 444 }
443 445
444 void Textfield::SetSelectionBackgroundColor(SkColor color) { 446 void Textfield::SetSelectionBackgroundColor(SkColor color) {
445 selection_background_color_ = color; 447 selection_background_color_ = color;
446 use_default_selection_background_color_ = false; 448 use_default_selection_background_color_ = false;
447 GetRenderText()->set_selection_background_focused_color( 449 GetRenderText()->set_selection_background_focused_color(
448 GetSelectionBackgroundColor()); 450 GetSelectionBackgroundColor());
449 SchedulePaint(); 451 SchedulePaint();
450 } 452 }
451 453
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 return insets; 577 return insets;
576 } 578 }
577 579
578 int Textfield::GetBaseline() const { 580 int Textfield::GetBaseline() const {
579 return GetInsets().top() + GetRenderText()->GetBaseline(); 581 return GetInsets().top() + GetRenderText()->GetBaseline();
580 } 582 }
581 583
582 gfx::Size Textfield::CalculatePreferredSize() const { 584 gfx::Size Textfield::CalculatePreferredSize() const {
583 const gfx::Insets& insets = GetInsets(); 585 const gfx::Insets& insets = GetInsets();
584 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + 586 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
585 insets.width(), GetFontList().GetHeight() + insets.height()); 587 insets.width(),
588 GetFontList().GetHeight() + insets.height());
586 } 589 }
587 590
588 const char* Textfield::GetClassName() const { 591 const char* Textfield::GetClassName() const {
589 return kViewClassName; 592 return kViewClassName;
590 } 593 }
591 594
592 void Textfield::SetBorder(std::unique_ptr<Border> b) { 595 void Textfield::SetBorder(std::unique_ptr<Border> b) {
593 if (use_focus_ring_ && HasFocus()) 596 if (use_focus_ring_ && HasFocus())
594 FocusRing::Uninstall(this); 597 FocusRing::Uninstall(this);
595 use_focus_ring_ = false; 598 use_focus_ring_ = false;
(...skipping 16 matching lines...) Expand all
612 RequestFocus(); 615 RequestFocus();
613 ShowImeIfNeeded(); 616 ShowImeIfNeeded();
614 } 617 }
615 618
616 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 619 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
617 if (!handled && !had_focus && event.IsOnlyMiddleMouseButton()) 620 if (!handled && !had_focus && event.IsOnlyMiddleMouseButton())
618 RequestFocus(); 621 RequestFocus();
619 #endif 622 #endif
620 623
621 return selection_controller_.OnMousePressed( 624 return selection_controller_.OnMousePressed(
622 event, handled, had_focus ? SelectionController::FOCUSED 625 event, handled,
623 : SelectionController::UNFOCUSED); 626 had_focus ? SelectionController::FOCUSED
627 : SelectionController::UNFOCUSED);
624 } 628 }
625 629
626 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { 630 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) {
627 return selection_controller_.OnMouseDragged(event); 631 return selection_controller_.OnMouseDragged(event);
628 } 632 }
629 633
630 void Textfield::OnMouseReleased(const ui::MouseEvent& event) { 634 void Textfield::OnMouseReleased(const ui::MouseEvent& event) {
631 selection_controller_.OnMouseReleased(event); 635 selection_controller_.OnMouseReleased(event);
632 } 636 }
633 637
634 void Textfield::OnMouseCaptureLost() { 638 void Textfield::OnMouseCaptureLost() {
635 selection_controller_.OnMouseCaptureLost(); 639 selection_controller_.OnMouseCaptureLost();
636 } 640 }
637 641
642 bool Textfield::OnMouseWheel(const ui::MouseWheelEvent& event) {
643 return controller_ && controller_->HandleMouseEvent(this, event);
644 }
645
638 WordLookupClient* Textfield::GetWordLookupClient() { 646 WordLookupClient* Textfield::GetWordLookupClient() {
639 return this; 647 return this;
640 } 648 }
641 649
642 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { 650 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
643 ui::TextEditCommand edit_command = scheduled_text_edit_command_; 651 ui::TextEditCommand edit_command = scheduled_text_edit_command_;
644 scheduled_text_edit_command_ = ui::TextEditCommand::INVALID_COMMAND; 652 scheduled_text_edit_command_ = ui::TextEditCommand::INVALID_COMMAND;
645 653
646 // Since HandleKeyEvent() might destroy |this|, get a weak pointer and verify 654 // Since HandleKeyEvent() might destroy |this|, get a weak pointer and verify
647 // it isn't null before proceeding. 655 // it isn't null before proceeding.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 case ui::ET_GESTURE_SCROLL_BEGIN: 757 case ui::ET_GESTURE_SCROLL_BEGIN:
750 touch_handles_hidden_due_to_scroll_ = touch_selection_controller_ != NULL; 758 touch_handles_hidden_due_to_scroll_ = touch_selection_controller_ != NULL;
751 DestroyTouchSelection(); 759 DestroyTouchSelection();
752 drag_start_location_ = event->location(); 760 drag_start_location_ = event->location();
753 drag_start_display_offset_ = 761 drag_start_display_offset_ =
754 GetRenderText()->GetUpdatedDisplayOffset().x(); 762 GetRenderText()->GetUpdatedDisplayOffset().x();
755 event->SetHandled(); 763 event->SetHandled();
756 break; 764 break;
757 case ui::ET_GESTURE_SCROLL_UPDATE: { 765 case ui::ET_GESTURE_SCROLL_UPDATE: {
758 int new_offset = drag_start_display_offset_ + event->location().x() - 766 int new_offset = drag_start_display_offset_ + event->location().x() -
759 drag_start_location_.x(); 767 drag_start_location_.x();
760 GetRenderText()->SetDisplayOffset(new_offset); 768 GetRenderText()->SetDisplayOffset(new_offset);
761 SchedulePaint(); 769 SchedulePaint();
762 event->SetHandled(); 770 event->SetHandled();
763 break; 771 break;
764 } 772 }
765 case ui::ET_GESTURE_SCROLL_END: 773 case ui::ET_GESTURE_SCROLL_END:
766 case ui::ET_SCROLL_FLING_START: 774 case ui::ET_SCROLL_FLING_START:
767 if (touch_handles_hidden_due_to_scroll_) { 775 if (touch_handles_hidden_due_to_scroll_) {
768 CreateTouchSelectionControllerAndNotifyIt(); 776 CreateTouchSelectionControllerAndNotifyIt();
769 touch_handles_hidden_due_to_scroll_ = false; 777 touch_handles_hidden_due_to_scroll_ = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 std::set<ui::Clipboard::FormatType> format_types; 838 std::set<ui::Clipboard::FormatType> format_types;
831 GetDropFormats(&formats, &format_types); 839 GetDropFormats(&formats, &format_types);
832 return enabled() && !read_only() && data.HasAnyFormat(formats, format_types); 840 return enabled() && !read_only() && data.HasAnyFormat(formats, format_types);
833 } 841 }
834 842
835 int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) { 843 int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) {
836 DCHECK(CanDrop(event.data())); 844 DCHECK(CanDrop(event.data()));
837 gfx::RenderText* render_text = GetRenderText(); 845 gfx::RenderText* render_text = GetRenderText();
838 const gfx::Range& selection = render_text->selection(); 846 const gfx::Range& selection = render_text->selection();
839 drop_cursor_position_ = render_text->FindCursorPosition(event.location()); 847 drop_cursor_position_ = render_text->FindCursorPosition(event.location());
840 bool in_selection = !selection.is_empty() && 848 bool in_selection =
849 !selection.is_empty() &&
841 selection.Contains(gfx::Range(drop_cursor_position_.caret_pos())); 850 selection.Contains(gfx::Range(drop_cursor_position_.caret_pos()));
842 drop_cursor_visible_ = !in_selection; 851 drop_cursor_visible_ = !in_selection;
843 // TODO(msw): Pan over text when the user drags to the visible text edge. 852 // TODO(msw): Pan over text when the user drags to the visible text edge.
844 OnCaretBoundsChanged(); 853 OnCaretBoundsChanged();
845 SchedulePaint(); 854 SchedulePaint();
846 855
847 StopBlinkingCursor(); 856 StopBlinkingCursor();
848 857
849 if (initiating_drag_) { 858 if (initiating_drag_) {
850 if (in_selection) 859 if (in_selection)
851 return ui::DragDropTypes::DRAG_NONE; 860 return ui::DragDropTypes::DRAG_NONE;
852 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : 861 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY
853 ui::DragDropTypes::DRAG_MOVE; 862 : ui::DragDropTypes::DRAG_MOVE;
854 } 863 }
855 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; 864 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE;
856 } 865 }
857 866
858 void Textfield::OnDragExited() { 867 void Textfield::OnDragExited() {
859 drop_cursor_visible_ = false; 868 drop_cursor_visible_ = false;
860 if (ShouldBlinkCursor()) 869 if (ShouldBlinkCursor())
861 StartBlinkingCursor(); 870 StartBlinkingCursor();
862 SchedulePaint(); 871 SchedulePaint();
863 } 872 }
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 return false; 1395 return false;
1387 gfx::Range composition_range; 1396 gfx::Range composition_range;
1388 model_->GetCompositionTextRange(&composition_range); 1397 model_->GetCompositionTextRange(&composition_range);
1389 DCHECK(!composition_range.is_empty()); 1398 DCHECK(!composition_range.is_empty());
1390 1399
1391 size_t text_index = composition_range.start() + index; 1400 size_t text_index = composition_range.start() + index;
1392 if (composition_range.end() <= text_index) 1401 if (composition_range.end() <= text_index)
1393 return false; 1402 return false;
1394 gfx::RenderText* render_text = GetRenderText(); 1403 gfx::RenderText* render_text = GetRenderText();
1395 if (!render_text->IsValidCursorIndex(text_index)) { 1404 if (!render_text->IsValidCursorIndex(text_index)) {
1396 text_index = render_text->IndexOfAdjacentGrapheme( 1405 text_index =
1397 text_index, gfx::CURSOR_BACKWARD); 1406 render_text->IndexOfAdjacentGrapheme(text_index, gfx::CURSOR_BACKWARD);
1398 } 1407 }
1399 if (text_index < composition_range.start()) 1408 if (text_index < composition_range.start())
1400 return false; 1409 return false;
1401 const gfx::SelectionModel caret(text_index, gfx::CURSOR_BACKWARD); 1410 const gfx::SelectionModel caret(text_index, gfx::CURSOR_BACKWARD);
1402 *rect = render_text->GetCursorBounds(caret, false); 1411 *rect = render_text->GetCursorBounds(caret, false);
1403 ConvertRectToScreen(this, rect); 1412 ConvertRectToScreen(this, rect);
1404 return true; 1413 return true;
1405 } 1414 }
1406 1415
1407 bool Textfield::HasCompositionText() const { 1416 bool Textfield::HasCompositionText() const {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 return true; 1476 return true;
1468 } 1477 }
1469 1478
1470 void Textfield::OnInputMethodChanged() {} 1479 void Textfield::OnInputMethodChanged() {}
1471 1480
1472 bool Textfield::ChangeTextDirectionAndLayoutAlignment( 1481 bool Textfield::ChangeTextDirectionAndLayoutAlignment(
1473 base::i18n::TextDirection direction) { 1482 base::i18n::TextDirection direction) {
1474 // Restore text directionality mode when the indicated direction matches the 1483 // Restore text directionality mode when the indicated direction matches the
1475 // current forced mode; otherwise, force the mode indicated. This helps users 1484 // current forced mode; otherwise, force the mode indicated. This helps users
1476 // manage BiDi text layout without getting stuck in forced LTR or RTL modes. 1485 // manage BiDi text layout without getting stuck in forced LTR or RTL modes.
1477 const gfx::DirectionalityMode mode = direction == base::i18n::RIGHT_TO_LEFT ? 1486 const gfx::DirectionalityMode mode = direction == base::i18n::RIGHT_TO_LEFT
1478 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR; 1487 ? gfx::DIRECTIONALITY_FORCE_RTL
1488 : gfx::DIRECTIONALITY_FORCE_LTR;
1479 if (mode == GetRenderText()->directionality_mode()) 1489 if (mode == GetRenderText()->directionality_mode())
1480 GetRenderText()->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT); 1490 GetRenderText()->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT);
1481 else 1491 else
1482 GetRenderText()->SetDirectionalityMode(mode); 1492 GetRenderText()->SetDirectionalityMode(mode);
1483 SchedulePaint(); 1493 SchedulePaint();
1484 return true; 1494 return true;
1485 } 1495 }
1486 1496
1487 void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) { 1497 void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) {
1488 gfx::Range range = GetRenderText()->selection(); 1498 gfx::Range range = GetRenderText()->selection();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 gfx::RenderText* Textfield::GetRenderText() const { 1624 gfx::RenderText* Textfield::GetRenderText() const {
1615 return model_->render_text(); 1625 return model_->render_text();
1616 } 1626 }
1617 1627
1618 gfx::Point Textfield::GetLastClickLocation() const { 1628 gfx::Point Textfield::GetLastClickLocation() const {
1619 return selection_controller_.last_click_location(); 1629 return selection_controller_.last_click_location();
1620 } 1630 }
1621 1631
1622 base::string16 Textfield::GetSelectionClipboardText() const { 1632 base::string16 Textfield::GetSelectionClipboardText() const {
1623 base::string16 selection_clipboard_text; 1633 base::string16 selection_clipboard_text;
1624 ui::Clipboard::GetForCurrentThread()->ReadText( 1634 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_SELECTION,
1625 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text); 1635 &selection_clipboard_text);
1626 return selection_clipboard_text; 1636 return selection_clipboard_text;
1627 } 1637 }
1628 1638
1629 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { 1639 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
1630 DestroyTouchSelection(); 1640 DestroyTouchSelection();
1631 1641
1632 bool add_to_kill_buffer = false; 1642 bool add_to_kill_buffer = false;
1633 1643
1634 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent 1644 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
1635 // modifications of the command should happen here. 1645 // modifications of the command should happen here.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1918 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1909 SetBackground( 1919 SetBackground(
1910 CreateBackgroundFromPainter(Painter::CreateSolidRoundRectPainter( 1920 CreateBackgroundFromPainter(Painter::CreateSolidRoundRectPainter(
1911 color, FocusableBorder::kCornerRadiusDp))); 1921 color, FocusableBorder::kCornerRadiusDp)));
1912 } else { 1922 } else {
1913 SetBackground(CreateSolidBackground(color)); 1923 SetBackground(CreateSolidBackground(color));
1914 } 1924 }
1915 // Disable subpixel rendering when the background color is transparent 1925 // Disable subpixel rendering when the background color is transparent
1916 // because it draws incorrect colors around the glyphs in that case. 1926 // because it draws incorrect colors around the glyphs in that case.
1917 // See crbug.com/115198 1927 // See crbug.com/115198
1918 GetRenderText()->set_subpixel_rendering_suppressed( 1928 GetRenderText()->set_subpixel_rendering_suppressed(SkColorGetA(color) !=
1919 SkColorGetA(color) != SK_AlphaOPAQUE); 1929 SK_AlphaOPAQUE);
1920 SchedulePaint(); 1930 SchedulePaint();
1921 } 1931 }
1922 1932
1923 void Textfield::UpdateBorder() { 1933 void Textfield::UpdateBorder() {
1924 auto border = base::MakeUnique<views::FocusableBorder>(); 1934 auto border = base::MakeUnique<views::FocusableBorder>();
1925 if (invalid_) 1935 if (invalid_)
1926 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); 1936 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh);
1927 View::SetBorder(std::move(border)); 1937 View::SetBorder(std::move(border));
1928 } 1938 }
1929 1939
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 // Disallow input method editing of password fields. 2075 // Disallow input method editing of password fields.
2066 ui::TextInputType t = GetTextInputType(); 2076 ui::TextInputType t = GetTextInputType();
2067 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); 2077 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD);
2068 } 2078 }
2069 2079
2070 void Textfield::RevealPasswordChar(int index) { 2080 void Textfield::RevealPasswordChar(int index) {
2071 GetRenderText()->SetObscuredRevealIndex(index); 2081 GetRenderText()->SetObscuredRevealIndex(index);
2072 SchedulePaint(); 2082 SchedulePaint();
2073 2083
2074 if (index != -1) { 2084 if (index != -1) {
2075 password_reveal_timer_.Start(FROM_HERE, GetPasswordRevealDuration(), 2085 password_reveal_timer_.Start(
2086 FROM_HERE, GetPasswordRevealDuration(),
2076 base::Bind(&Textfield::RevealPasswordChar, 2087 base::Bind(&Textfield::RevealPasswordChar,
2077 weak_ptr_factory_.GetWeakPtr(), -1)); 2088 weak_ptr_factory_.GetWeakPtr(), -1));
2078 } 2089 }
2079 } 2090 }
2080 2091
2081 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { 2092 void Textfield::CreateTouchSelectionControllerAndNotifyIt() {
2082 if (!HasFocus()) 2093 if (!HasFocus())
2083 return; 2094 return;
2084 2095
2085 if (!touch_selection_controller_) { 2096 if (!touch_selection_controller_) {
(...skipping 12 matching lines...) Expand all
2098 return HasFocus() && !HasSelection() && enabled() && !read_only() && 2109 return HasFocus() && !HasSelection() && enabled() && !read_only() &&
2099 !drop_cursor_visible_ && GetRenderText()->cursor_enabled(); 2110 !drop_cursor_visible_ && GetRenderText()->cursor_enabled();
2100 } 2111 }
2101 2112
2102 bool Textfield::ShouldBlinkCursor() const { 2113 bool Textfield::ShouldBlinkCursor() const {
2103 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0; 2114 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0;
2104 } 2115 }
2105 2116
2106 void Textfield::StartBlinkingCursor() { 2117 void Textfield::StartBlinkingCursor() {
2107 DCHECK(ShouldBlinkCursor()); 2118 DCHECK(ShouldBlinkCursor());
2108 cursor_blink_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( 2119 cursor_blink_timer_.Start(
2109 Textfield::GetCaretBlinkMs()), 2120 FROM_HERE,
2110 this, &Textfield::OnCursorBlinkTimerFired); 2121 base::TimeDelta::FromMilliseconds(Textfield::GetCaretBlinkMs()), this,
2122 &Textfield::OnCursorBlinkTimerFired);
2111 } 2123 }
2112 2124
2113 void Textfield::StopBlinkingCursor() { 2125 void Textfield::StopBlinkingCursor() {
2114 cursor_blink_timer_.Stop(); 2126 cursor_blink_timer_.Stop();
2115 } 2127 }
2116 2128
2117 void Textfield::OnCursorBlinkTimerFired() { 2129 void Textfield::OnCursorBlinkTimerFired() {
2118 DCHECK(ShouldBlinkCursor()); 2130 DCHECK(ShouldBlinkCursor());
2119 UpdateCursorViewPosition(); 2131 UpdateCursorViewPosition();
2120 cursor_view_.SetVisible(!cursor_view_.visible()); 2132 cursor_view_.SetVisible(!cursor_view_.visible());
2121 } 2133 }
2122 2134
2123 } // namespace views 2135 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698