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

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

Issue 2729133005: Fix: Cursor missing in omnibox after entering a alphabet in NTP 'Search box' (Closed)
Patch Set: address comments Created 3 years, 9 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 GetRenderText()->set_selection_background_focused_color( 448 GetRenderText()->set_selection_background_focused_color(
449 GetSelectionBackgroundColor()); 449 GetSelectionBackgroundColor());
450 SchedulePaint(); 450 SchedulePaint();
451 } 451 }
452 452
453 bool Textfield::GetCursorEnabled() const { 453 bool Textfield::GetCursorEnabled() const {
454 return GetRenderText()->cursor_enabled(); 454 return GetRenderText()->cursor_enabled();
455 } 455 }
456 456
457 void Textfield::SetCursorEnabled(bool enabled) { 457 void Textfield::SetCursorEnabled(bool enabled) {
458 if (GetRenderText()->cursor_enabled() == enabled)
459 return;
460
458 GetRenderText()->SetCursorEnabled(enabled); 461 GetRenderText()->SetCursorEnabled(enabled);
462 UpdateCursorViewPosition();
463 UpdateCursorVisibility();
459 } 464 }
460 465
461 const gfx::FontList& Textfield::GetFontList() const { 466 const gfx::FontList& Textfield::GetFontList() const {
462 return GetRenderText()->font_list(); 467 return GetRenderText()->font_list();
463 } 468 }
464 469
465 void Textfield::SetFontList(const gfx::FontList& font_list) { 470 void Textfield::SetFontList(const gfx::FontList& font_list) {
466 GetRenderText()->SetFontList(font_list); 471 GetRenderText()->SetFontList(font_list);
467 OnCaretBoundsChanged(); 472 OnCaretBoundsChanged();
468 PreferredSizeChanged(); 473 PreferredSizeChanged();
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 980
976 void Textfield::OnPaint(gfx::Canvas* canvas) { 981 void Textfield::OnPaint(gfx::Canvas* canvas) {
977 OnPaintBackground(canvas); 982 OnPaintBackground(canvas);
978 PaintTextAndCursor(canvas); 983 PaintTextAndCursor(canvas);
979 OnPaintBorder(canvas); 984 OnPaintBorder(canvas);
980 } 985 }
981 986
982 void Textfield::OnFocus() { 987 void Textfield::OnFocus() {
983 GetRenderText()->set_focused(true); 988 GetRenderText()->set_focused(true);
984 if (ShouldShowCursor()) { 989 if (ShouldShowCursor()) {
985 UpdateCursorView(); 990 UpdateCursorViewPosition();
986 cursor_view_.SetVisible(true); 991 cursor_view_.SetVisible(true);
msw 2017/03/10 21:04:30 optional nit: should this pass ShouldShowCursor(),
yiyix 2017/03/13 04:02:16 Since it is a fix of dev block bug, I hesitate to
987 } 992 }
988 if (GetInputMethod()) 993 if (GetInputMethod())
989 GetInputMethod()->SetFocusedTextInputClient(this); 994 GetInputMethod()->SetFocusedTextInputClient(this);
990 OnCaretBoundsChanged(); 995 OnCaretBoundsChanged();
991 if (ShouldBlinkCursor()) 996 if (ShouldBlinkCursor())
992 StartBlinkingCursor(); 997 StartBlinkingCursor();
993 if (use_focus_ring_) { 998 if (use_focus_ring_) {
994 FocusRing::Install(this, invalid_ 999 FocusRing::Install(this, invalid_
995 ? ui::NativeTheme::kColorId_AlertSeverityHigh 1000 ? ui::NativeTheme::kColorId_AlertSeverityHigh
996 : ui::NativeTheme::kColorId_NumColors); 1001 : ui::NativeTheme::kColorId_NumColors);
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 View::SetBorder(std::move(border)); 1908 View::SetBorder(std::move(border));
1904 } 1909 }
1905 1910
1906 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { 1911 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
1907 if (text_changed) { 1912 if (text_changed) {
1908 if (controller_) 1913 if (controller_)
1909 controller_->ContentsChanged(this, text()); 1914 controller_->ContentsChanged(this, text());
1910 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); 1915 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
1911 } 1916 }
1912 if (cursor_changed) { 1917 if (cursor_changed) {
1913 UpdateCursorView(); 1918 UpdateCursorViewPosition();
1914 cursor_view_.SetVisible(ShouldShowCursor()); 1919 UpdateCursorVisibility();
1915 if (ShouldBlinkCursor())
1916 StartBlinkingCursor();
1917 else
1918 StopBlinkingCursor();
1919 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); 1920 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true);
1920 } 1921 }
1921 if (text_changed || cursor_changed) { 1922 if (text_changed || cursor_changed) {
1922 OnCaretBoundsChanged(); 1923 OnCaretBoundsChanged();
1923 SchedulePaint(); 1924 SchedulePaint();
1924 } 1925 }
1925 } 1926 }
1926 1927
1927 void Textfield::UpdateCursorView() { 1928 void Textfield::UpdateCursorVisibility() {
1929 cursor_view_.SetVisible(ShouldShowCursor());
1930 if (ShouldBlinkCursor())
1931 StartBlinkingCursor();
1932 else
1933 StopBlinkingCursor();
1934 }
1935
1936 void Textfield::UpdateCursorViewPosition() {
1928 gfx::Rect location(GetRenderText()->GetUpdatedCursorBounds()); 1937 gfx::Rect location(GetRenderText()->GetUpdatedCursorBounds());
1929 location.set_x(GetMirroredXForRect(location)); 1938 location.set_x(GetMirroredXForRect(location));
1930 cursor_view_.SetBoundsRect(location); 1939 cursor_view_.SetBoundsRect(location);
1931 } 1940 }
1932 1941
1933 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { 1942 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
1934 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor"); 1943 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor");
1935 canvas->Save(); 1944 canvas->Save();
1936 1945
1937 // Draw placeholder text if needed. 1946 // Draw placeholder text if needed.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 this, &Textfield::OnCursorBlinkTimerFired); 2091 this, &Textfield::OnCursorBlinkTimerFired);
2083 } 2092 }
2084 2093
2085 void Textfield::StopBlinkingCursor() { 2094 void Textfield::StopBlinkingCursor() {
2086 cursor_blink_timer_.Stop(); 2095 cursor_blink_timer_.Stop();
2087 } 2096 }
2088 2097
2089 void Textfield::OnCursorBlinkTimerFired() { 2098 void Textfield::OnCursorBlinkTimerFired() {
2090 DCHECK(ShouldBlinkCursor()); 2099 DCHECK(ShouldBlinkCursor());
2091 cursor_view_.SetVisible(!cursor_view_.visible()); 2100 cursor_view_.SetVisible(!cursor_view_.visible());
2092 UpdateCursorView(); 2101 UpdateCursorViewPosition();
2093 } 2102 }
2094 2103
2095 } // namespace views 2104 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698