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

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

Issue 2982453002: New AppListView Scroll Behavior. (Closed)
Patch Set: Removed unintended edit. 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 case ui::ET_GESTURE_SCROLL_BEGIN: 761 case ui::ET_GESTURE_SCROLL_BEGIN:
754 touch_handles_hidden_due_to_scroll_ = touch_selection_controller_ != NULL; 762 touch_handles_hidden_due_to_scroll_ = touch_selection_controller_ != NULL;
755 DestroyTouchSelection(); 763 DestroyTouchSelection();
756 drag_start_location_ = event->location(); 764 drag_start_location_ = event->location();
757 drag_start_display_offset_ = 765 drag_start_display_offset_ =
758 GetRenderText()->GetUpdatedDisplayOffset().x(); 766 GetRenderText()->GetUpdatedDisplayOffset().x();
759 event->SetHandled(); 767 event->SetHandled();
760 break; 768 break;
761 case ui::ET_GESTURE_SCROLL_UPDATE: { 769 case ui::ET_GESTURE_SCROLL_UPDATE: {
762 int new_offset = drag_start_display_offset_ + event->location().x() - 770 int new_offset = drag_start_display_offset_ + event->location().x() -
763 drag_start_location_.x(); 771 drag_start_location_.x();
764 GetRenderText()->SetDisplayOffset(new_offset); 772 GetRenderText()->SetDisplayOffset(new_offset);
765 SchedulePaint(); 773 SchedulePaint();
766 event->SetHandled(); 774 event->SetHandled();
767 break; 775 break;
768 } 776 }
769 case ui::ET_GESTURE_SCROLL_END: 777 case ui::ET_GESTURE_SCROLL_END:
770 case ui::ET_SCROLL_FLING_START: 778 case ui::ET_SCROLL_FLING_START:
771 if (touch_handles_hidden_due_to_scroll_) { 779 if (touch_handles_hidden_due_to_scroll_) {
772 CreateTouchSelectionControllerAndNotifyIt(); 780 CreateTouchSelectionControllerAndNotifyIt();
773 touch_handles_hidden_due_to_scroll_ = false; 781 touch_handles_hidden_due_to_scroll_ = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 std::set<ui::Clipboard::FormatType> format_types; 842 std::set<ui::Clipboard::FormatType> format_types;
835 GetDropFormats(&formats, &format_types); 843 GetDropFormats(&formats, &format_types);
836 return enabled() && !read_only() && data.HasAnyFormat(formats, format_types); 844 return enabled() && !read_only() && data.HasAnyFormat(formats, format_types);
837 } 845 }
838 846
839 int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) { 847 int Textfield::OnDragUpdated(const ui::DropTargetEvent& event) {
840 DCHECK(CanDrop(event.data())); 848 DCHECK(CanDrop(event.data()));
841 gfx::RenderText* render_text = GetRenderText(); 849 gfx::RenderText* render_text = GetRenderText();
842 const gfx::Range& selection = render_text->selection(); 850 const gfx::Range& selection = render_text->selection();
843 drop_cursor_position_ = render_text->FindCursorPosition(event.location()); 851 drop_cursor_position_ = render_text->FindCursorPosition(event.location());
844 bool in_selection = !selection.is_empty() && 852 bool in_selection =
853 !selection.is_empty() &&
845 selection.Contains(gfx::Range(drop_cursor_position_.caret_pos())); 854 selection.Contains(gfx::Range(drop_cursor_position_.caret_pos()));
846 drop_cursor_visible_ = !in_selection; 855 drop_cursor_visible_ = !in_selection;
847 // TODO(msw): Pan over text when the user drags to the visible text edge. 856 // TODO(msw): Pan over text when the user drags to the visible text edge.
848 OnCaretBoundsChanged(); 857 OnCaretBoundsChanged();
849 SchedulePaint(); 858 SchedulePaint();
850 859
851 StopBlinkingCursor(); 860 StopBlinkingCursor();
852 861
853 if (initiating_drag_) { 862 if (initiating_drag_) {
854 if (in_selection) 863 if (in_selection)
855 return ui::DragDropTypes::DRAG_NONE; 864 return ui::DragDropTypes::DRAG_NONE;
856 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : 865 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY
857 ui::DragDropTypes::DRAG_MOVE; 866 : ui::DragDropTypes::DRAG_MOVE;
858 } 867 }
859 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; 868 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE;
860 } 869 }
861 870
862 void Textfield::OnDragExited() { 871 void Textfield::OnDragExited() {
863 drop_cursor_visible_ = false; 872 drop_cursor_visible_ = false;
864 if (ShouldBlinkCursor()) 873 if (ShouldBlinkCursor())
865 StartBlinkingCursor(); 874 StartBlinkingCursor();
866 SchedulePaint(); 875 SchedulePaint();
867 } 876 }
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 return false; 1400 return false;
1392 gfx::Range composition_range; 1401 gfx::Range composition_range;
1393 model_->GetCompositionTextRange(&composition_range); 1402 model_->GetCompositionTextRange(&composition_range);
1394 DCHECK(!composition_range.is_empty()); 1403 DCHECK(!composition_range.is_empty());
1395 1404
1396 size_t text_index = composition_range.start() + index; 1405 size_t text_index = composition_range.start() + index;
1397 if (composition_range.end() <= text_index) 1406 if (composition_range.end() <= text_index)
1398 return false; 1407 return false;
1399 gfx::RenderText* render_text = GetRenderText(); 1408 gfx::RenderText* render_text = GetRenderText();
1400 if (!render_text->IsValidCursorIndex(text_index)) { 1409 if (!render_text->IsValidCursorIndex(text_index)) {
1401 text_index = render_text->IndexOfAdjacentGrapheme( 1410 text_index =
1402 text_index, gfx::CURSOR_BACKWARD); 1411 render_text->IndexOfAdjacentGrapheme(text_index, gfx::CURSOR_BACKWARD);
1403 } 1412 }
1404 if (text_index < composition_range.start()) 1413 if (text_index < composition_range.start())
1405 return false; 1414 return false;
1406 const gfx::SelectionModel caret(text_index, gfx::CURSOR_BACKWARD); 1415 const gfx::SelectionModel caret(text_index, gfx::CURSOR_BACKWARD);
1407 *rect = render_text->GetCursorBounds(caret, false); 1416 *rect = render_text->GetCursorBounds(caret, false);
1408 ConvertRectToScreen(this, rect); 1417 ConvertRectToScreen(this, rect);
1409 return true; 1418 return true;
1410 } 1419 }
1411 1420
1412 bool Textfield::HasCompositionText() const { 1421 bool Textfield::HasCompositionText() const {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 return true; 1481 return true;
1473 } 1482 }
1474 1483
1475 void Textfield::OnInputMethodChanged() {} 1484 void Textfield::OnInputMethodChanged() {}
1476 1485
1477 bool Textfield::ChangeTextDirectionAndLayoutAlignment( 1486 bool Textfield::ChangeTextDirectionAndLayoutAlignment(
1478 base::i18n::TextDirection direction) { 1487 base::i18n::TextDirection direction) {
1479 // Restore text directionality mode when the indicated direction matches the 1488 // Restore text directionality mode when the indicated direction matches the
1480 // current forced mode; otherwise, force the mode indicated. This helps users 1489 // current forced mode; otherwise, force the mode indicated. This helps users
1481 // manage BiDi text layout without getting stuck in forced LTR or RTL modes. 1490 // manage BiDi text layout without getting stuck in forced LTR or RTL modes.
1482 const gfx::DirectionalityMode mode = direction == base::i18n::RIGHT_TO_LEFT ? 1491 const gfx::DirectionalityMode mode = direction == base::i18n::RIGHT_TO_LEFT
1483 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR; 1492 ? gfx::DIRECTIONALITY_FORCE_RTL
1493 : gfx::DIRECTIONALITY_FORCE_LTR;
1484 if (mode == GetRenderText()->directionality_mode()) 1494 if (mode == GetRenderText()->directionality_mode())
1485 GetRenderText()->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT); 1495 GetRenderText()->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT);
1486 else 1496 else
1487 GetRenderText()->SetDirectionalityMode(mode); 1497 GetRenderText()->SetDirectionalityMode(mode);
1488 SchedulePaint(); 1498 SchedulePaint();
1489 return true; 1499 return true;
1490 } 1500 }
1491 1501
1492 void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) { 1502 void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) {
1493 gfx::Range range = GetRenderText()->selection(); 1503 gfx::Range range = GetRenderText()->selection();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 gfx::RenderText* Textfield::GetRenderText() const { 1629 gfx::RenderText* Textfield::GetRenderText() const {
1620 return model_->render_text(); 1630 return model_->render_text();
1621 } 1631 }
1622 1632
1623 gfx::Point Textfield::GetLastClickLocation() const { 1633 gfx::Point Textfield::GetLastClickLocation() const {
1624 return selection_controller_.last_click_location(); 1634 return selection_controller_.last_click_location();
1625 } 1635 }
1626 1636
1627 base::string16 Textfield::GetSelectionClipboardText() const { 1637 base::string16 Textfield::GetSelectionClipboardText() const {
1628 base::string16 selection_clipboard_text; 1638 base::string16 selection_clipboard_text;
1629 ui::Clipboard::GetForCurrentThread()->ReadText( 1639 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_SELECTION,
1630 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text); 1640 &selection_clipboard_text);
1631 return selection_clipboard_text; 1641 return selection_clipboard_text;
1632 } 1642 }
1633 1643
1634 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { 1644 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
1635 DestroyTouchSelection(); 1645 DestroyTouchSelection();
1636 1646
1637 bool add_to_kill_buffer = false; 1647 bool add_to_kill_buffer = false;
1638 1648
1639 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent 1649 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
1640 // modifications of the command should happen here. 1650 // modifications of the command should happen here.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1923 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1914 SetBackground( 1924 SetBackground(
1915 CreateBackgroundFromPainter(Painter::CreateSolidRoundRectPainter( 1925 CreateBackgroundFromPainter(Painter::CreateSolidRoundRectPainter(
1916 color, FocusableBorder::kCornerRadiusDp))); 1926 color, FocusableBorder::kCornerRadiusDp)));
1917 } else { 1927 } else {
1918 SetBackground(CreateSolidBackground(color)); 1928 SetBackground(CreateSolidBackground(color));
1919 } 1929 }
1920 // Disable subpixel rendering when the background color is transparent 1930 // Disable subpixel rendering when the background color is transparent
1921 // because it draws incorrect colors around the glyphs in that case. 1931 // because it draws incorrect colors around the glyphs in that case.
1922 // See crbug.com/115198 1932 // See crbug.com/115198
1923 GetRenderText()->set_subpixel_rendering_suppressed( 1933 GetRenderText()->set_subpixel_rendering_suppressed(SkColorGetA(color) !=
1924 SkColorGetA(color) != SK_AlphaOPAQUE); 1934 SK_AlphaOPAQUE);
1925 SchedulePaint(); 1935 SchedulePaint();
1926 } 1936 }
1927 1937
1928 void Textfield::UpdateBorder() { 1938 void Textfield::UpdateBorder() {
1929 auto border = base::MakeUnique<views::FocusableBorder>(); 1939 auto border = base::MakeUnique<views::FocusableBorder>();
1930 if (invalid_) 1940 if (invalid_)
1931 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); 1941 border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh);
1932 View::SetBorder(std::move(border)); 1942 View::SetBorder(std::move(border));
1933 } 1943 }
1934 1944
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 // Disallow input method editing of password fields. 2080 // Disallow input method editing of password fields.
2071 ui::TextInputType t = GetTextInputType(); 2081 ui::TextInputType t = GetTextInputType();
2072 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); 2082 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD);
2073 } 2083 }
2074 2084
2075 void Textfield::RevealPasswordChar(int index) { 2085 void Textfield::RevealPasswordChar(int index) {
2076 GetRenderText()->SetObscuredRevealIndex(index); 2086 GetRenderText()->SetObscuredRevealIndex(index);
2077 SchedulePaint(); 2087 SchedulePaint();
2078 2088
2079 if (index != -1) { 2089 if (index != -1) {
2080 password_reveal_timer_.Start(FROM_HERE, GetPasswordRevealDuration(), 2090 password_reveal_timer_.Start(
2091 FROM_HERE, GetPasswordRevealDuration(),
2081 base::Bind(&Textfield::RevealPasswordChar, 2092 base::Bind(&Textfield::RevealPasswordChar,
2082 weak_ptr_factory_.GetWeakPtr(), -1)); 2093 weak_ptr_factory_.GetWeakPtr(), -1));
2083 } 2094 }
2084 } 2095 }
2085 2096
2086 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { 2097 void Textfield::CreateTouchSelectionControllerAndNotifyIt() {
2087 if (!HasFocus()) 2098 if (!HasFocus())
2088 return; 2099 return;
2089 2100
2090 if (!touch_selection_controller_) { 2101 if (!touch_selection_controller_) {
(...skipping 12 matching lines...) Expand all
2103 return HasFocus() && !HasSelection() && enabled() && !read_only() && 2114 return HasFocus() && !HasSelection() && enabled() && !read_only() &&
2104 !drop_cursor_visible_ && GetRenderText()->cursor_enabled(); 2115 !drop_cursor_visible_ && GetRenderText()->cursor_enabled();
2105 } 2116 }
2106 2117
2107 bool Textfield::ShouldBlinkCursor() const { 2118 bool Textfield::ShouldBlinkCursor() const {
2108 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0; 2119 return ShouldShowCursor() && Textfield::GetCaretBlinkMs() != 0;
2109 } 2120 }
2110 2121
2111 void Textfield::StartBlinkingCursor() { 2122 void Textfield::StartBlinkingCursor() {
2112 DCHECK(ShouldBlinkCursor()); 2123 DCHECK(ShouldBlinkCursor());
2113 cursor_blink_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( 2124 cursor_blink_timer_.Start(
2114 Textfield::GetCaretBlinkMs()), 2125 FROM_HERE,
2115 this, &Textfield::OnCursorBlinkTimerFired); 2126 base::TimeDelta::FromMilliseconds(Textfield::GetCaretBlinkMs()), this,
2127 &Textfield::OnCursorBlinkTimerFired);
2116 } 2128 }
2117 2129
2118 void Textfield::StopBlinkingCursor() { 2130 void Textfield::StopBlinkingCursor() {
2119 cursor_blink_timer_.Stop(); 2131 cursor_blink_timer_.Stop();
2120 } 2132 }
2121 2133
2122 void Textfield::OnCursorBlinkTimerFired() { 2134 void Textfield::OnCursorBlinkTimerFired() {
2123 DCHECK(ShouldBlinkCursor()); 2135 DCHECK(ShouldBlinkCursor());
2124 UpdateCursorViewPosition(); 2136 UpdateCursorViewPosition();
2125 cursor_view_.SetVisible(!cursor_view_.visible()); 2137 cursor_view_.SetVisible(!cursor_view_.visible());
2126 } 2138 }
2127 2139
2128 } // namespace views 2140 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698