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

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

Issue 2754633002: Fix: Cursor missing in omnibox after entering a alphabet in NTP 'Search box' (Closed)
Patch Set: 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 979
975 void Textfield::OnPaint(gfx::Canvas* canvas) { 980 void Textfield::OnPaint(gfx::Canvas* canvas) {
976 OnPaintBackground(canvas); 981 OnPaintBackground(canvas);
977 PaintTextAndCursor(canvas); 982 PaintTextAndCursor(canvas);
978 OnPaintBorder(canvas); 983 OnPaintBorder(canvas);
979 } 984 }
980 985
981 void Textfield::OnFocus() { 986 void Textfield::OnFocus() {
982 GetRenderText()->set_focused(true); 987 GetRenderText()->set_focused(true);
983 if (ShouldShowCursor()) { 988 if (ShouldShowCursor()) {
984 UpdateCursorView(); 989 UpdateCursorViewPosition();
985 cursor_view_.SetVisible(true); 990 cursor_view_.SetVisible(true);
986 } 991 }
987 if (GetInputMethod()) 992 if (GetInputMethod())
988 GetInputMethod()->SetFocusedTextInputClient(this); 993 GetInputMethod()->SetFocusedTextInputClient(this);
989 OnCaretBoundsChanged(); 994 OnCaretBoundsChanged();
990 if (ShouldBlinkCursor()) 995 if (ShouldBlinkCursor())
991 StartBlinkingCursor(); 996 StartBlinkingCursor();
992 if (use_focus_ring_) { 997 if (use_focus_ring_) {
993 FocusRing::Install(this, invalid_ 998 FocusRing::Install(this, invalid_
994 ? ui::NativeTheme::kColorId_AlertSeverityHigh 999 ? ui::NativeTheme::kColorId_AlertSeverityHigh
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 View::SetBorder(std::move(border)); 1907 View::SetBorder(std::move(border));
1903 } 1908 }
1904 1909
1905 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) { 1910 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
1906 if (text_changed) { 1911 if (text_changed) {
1907 if (controller_) 1912 if (controller_)
1908 controller_->ContentsChanged(this, text()); 1913 controller_->ContentsChanged(this, text());
1909 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true); 1914 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
1910 } 1915 }
1911 if (cursor_changed) { 1916 if (cursor_changed) {
1912 UpdateCursorView(); 1917 UpdateCursorViewPosition();
1913 cursor_view_.SetVisible(ShouldShowCursor()); 1918 UpdateCursorVisibility();
1914 if (ShouldBlinkCursor())
1915 StartBlinkingCursor();
1916 else
1917 StopBlinkingCursor();
1918 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); 1919 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true);
1919 } 1920 }
1920 if (text_changed || cursor_changed) { 1921 if (text_changed || cursor_changed) {
1921 OnCaretBoundsChanged(); 1922 OnCaretBoundsChanged();
1922 SchedulePaint(); 1923 SchedulePaint();
1923 } 1924 }
1924 } 1925 }
1925 1926
1926 void Textfield::UpdateCursorView() { 1927 void Textfield::UpdateCursorVisibility() {
1928 cursor_view_.SetVisible(ShouldShowCursor());
1929 if (ShouldBlinkCursor())
1930 StartBlinkingCursor();
1931 else
1932 StopBlinkingCursor();
1933 }
1934
1935 void Textfield::UpdateCursorViewPosition() {
1927 gfx::Rect location(GetRenderText()->GetUpdatedCursorBounds()); 1936 gfx::Rect location(GetRenderText()->GetUpdatedCursorBounds());
1928 location.set_x(GetMirroredXForRect(location)); 1937 location.set_x(GetMirroredXForRect(location));
1929 cursor_view_.SetBoundsRect(location); 1938 cursor_view_.SetBoundsRect(location);
1930 } 1939 }
1931 1940
1932 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { 1941 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
1933 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor"); 1942 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor");
1934 canvas->Save(); 1943 canvas->Save();
1935 1944
1936 // Draw placeholder text if needed. 1945 // Draw placeholder text if needed.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 this, &Textfield::OnCursorBlinkTimerFired); 2090 this, &Textfield::OnCursorBlinkTimerFired);
2082 } 2091 }
2083 2092
2084 void Textfield::StopBlinkingCursor() { 2093 void Textfield::StopBlinkingCursor() {
2085 cursor_blink_timer_.Stop(); 2094 cursor_blink_timer_.Stop();
2086 } 2095 }
2087 2096
2088 void Textfield::OnCursorBlinkTimerFired() { 2097 void Textfield::OnCursorBlinkTimerFired() {
2089 DCHECK(ShouldBlinkCursor()); 2098 DCHECK(ShouldBlinkCursor());
2090 cursor_view_.SetVisible(!cursor_view_.visible()); 2099 cursor_view_.SetVisible(!cursor_view_.visible());
2091 UpdateCursorView(); 2100 UpdateCursorViewPosition();
2092 } 2101 }
2093 2102
2094 } // namespace views 2103 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698