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

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: new approach 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) {
msw 2017/03/09 21:05:45 nit: curlies not needed
yiyix 2017/03/10 20:19:29 Done.
459 return;
460 }
458 GetRenderText()->SetCursorEnabled(enabled); 461 GetRenderText()->SetCursorEnabled(enabled);
462 UpdateCursorView();
463 ShowCursor();
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 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UpdateCursorView();
1914 cursor_view_.SetVisible(ShouldShowCursor()); 1919 ShowCursor();
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
1928 void Textfield::ShowCursor() {
msw 2017/03/09 21:05:45 Can we inline this into UpdateCursorView()? Otherw
yiyix 2017/03/10 20:19:29 I don't think inline this into UpdateCursorView is
msw 2017/03/10 21:04:29 Acknowledged.
1929 cursor_view_.SetVisible(ShouldShowCursor());
1930 if (ShouldBlinkCursor())
1931 StartBlinkingCursor();
1932 else
1933 StopBlinkingCursor();
1934 }
1935
1927 void Textfield::UpdateCursorView() { 1936 void Textfield::UpdateCursorView() {
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
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UpdateCursorView();
2093 } 2102 }
2094 2103
2095 } // namespace views 2104 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698