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

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

Issue 2399863002: views: call UpdateAfterChange() in Textfield::InsertOrReplaceText(). (Closed)
Patch Set: Created 4 years, 2 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/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 break; 1764 break;
1765 } 1765 }
1766 1766
1767 cursor_changed |= GetSelectionModel() != selection_model; 1767 cursor_changed |= GetSelectionModel() != selection_model;
1768 if (cursor_changed) 1768 if (cursor_changed)
1769 UpdateSelectionClipboard(); 1769 UpdateSelectionClipboard();
1770 UpdateAfterChange(text_changed, cursor_changed); 1770 UpdateAfterChange(text_changed, cursor_changed);
1771 OnAfterUserAction(); 1771 OnAfterUserAction();
1772 } 1772 }
1773 1773
1774 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
1775 if (text_changed) {
1776 if (controller_)
1777 controller_->ContentsChanged(this, text());
1778 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
1779 }
1780 if (cursor_changed) {
1781 GetRenderText()->set_cursor_visible(ShouldShowCursor());
1782 RepaintCursor();
1783 if (ShouldBlinkCursor())
1784 StartBlinkingCursor();
1785 else
1786 StopBlinkingCursor();
1787 if (!text_changed) {
1788 // TEXT_CHANGED implies TEXT_SELECTION_CHANGED, so we only need to fire
1789 // this if only the selection changed.
1790 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true);
1791 }
1792 }
1793 if (text_changed || cursor_changed) {
1794 OnCaretBoundsChanged();
1795 SchedulePaint();
1796 }
1797 }
1798
1774 //////////////////////////////////////////////////////////////////////////////// 1799 ////////////////////////////////////////////////////////////////////////////////
1775 // Textfield, private: 1800 // Textfield, private:
1776 1801
1777 void Textfield::AccessibilitySetValue(const base::string16& new_value) { 1802 void Textfield::AccessibilitySetValue(const base::string16& new_value) {
1778 if (!read_only()) { 1803 if (!read_only()) {
1779 SetText(new_value); 1804 SetText(new_value);
1780 ClearSelection(); 1805 ClearSelection();
1781 } 1806 }
1782 } 1807 }
1783 1808
1784 void Textfield::UpdateBackgroundColor() { 1809 void Textfield::UpdateBackgroundColor() {
1785 const SkColor color = GetBackgroundColor(); 1810 const SkColor color = GetBackgroundColor();
1786 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 1811 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
1787 set_background(Background::CreateBackgroundPainter( 1812 set_background(Background::CreateBackgroundPainter(
1788 true, Painter::CreateSolidRoundRectPainter( 1813 true, Painter::CreateSolidRoundRectPainter(
1789 color, FocusableBorder::kCornerRadiusDp))); 1814 color, FocusableBorder::kCornerRadiusDp)));
1790 } else { 1815 } else {
1791 set_background(Background::CreateSolidBackground(color)); 1816 set_background(Background::CreateSolidBackground(color));
1792 } 1817 }
1793 // Disable subpixel rendering when the background color is transparent 1818 // Disable subpixel rendering when the background color is transparent
1794 // because it draws incorrect colors around the glyphs in that case. 1819 // because it draws incorrect colors around the glyphs in that case.
1795 // See crbug.com/115198 1820 // See crbug.com/115198
1796 GetRenderText()->set_subpixel_rendering_suppressed( 1821 GetRenderText()->set_subpixel_rendering_suppressed(
1797 SkColorGetA(color) != SK_AlphaOPAQUE); 1822 SkColorGetA(color) != SK_AlphaOPAQUE);
1798 SchedulePaint(); 1823 SchedulePaint();
1799 } 1824 }
1800 1825
1801 void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
1802 if (text_changed) {
1803 if (controller_)
1804 controller_->ContentsChanged(this, text());
1805 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
1806 }
1807 if (cursor_changed) {
1808 GetRenderText()->set_cursor_visible(ShouldShowCursor());
1809 RepaintCursor();
1810 if (ShouldBlinkCursor())
1811 StartBlinkingCursor();
1812 else
1813 StopBlinkingCursor();
1814 if (!text_changed) {
1815 // TEXT_CHANGED implies TEXT_SELECTION_CHANGED, so we only need to fire
1816 // this if only the selection changed.
1817 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true);
1818 }
1819 }
1820 if (text_changed || cursor_changed) {
1821 OnCaretBoundsChanged();
1822 SchedulePaint();
1823 }
1824 }
1825
1826 void Textfield::RepaintCursor() { 1826 void Textfield::RepaintCursor() {
1827 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds()); 1827 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds());
1828 r.Inset(-1, -1, -1, -1); 1828 r.Inset(-1, -1, -1, -1);
1829 SchedulePaintInRect(r); 1829 SchedulePaintInRect(r);
1830 } 1830 }
1831 1831
1832 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { 1832 void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
1833 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor"); 1833 TRACE_EVENT0("views", "Textfield::PaintTextAndCursor");
1834 canvas->Save(); 1834 canvas->Save();
1835 1835
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 } 2064 }
2065 2065
2066 void Textfield::OnCursorBlinkTimerFired() { 2066 void Textfield::OnCursorBlinkTimerFired() {
2067 DCHECK(ShouldBlinkCursor()); 2067 DCHECK(ShouldBlinkCursor());
2068 gfx::RenderText* render_text = GetRenderText(); 2068 gfx::RenderText* render_text = GetRenderText();
2069 render_text->set_cursor_visible(!render_text->cursor_visible()); 2069 render_text->set_cursor_visible(!render_text->cursor_visible());
2070 RepaintCursor(); 2070 RepaintCursor();
2071 } 2071 }
2072 2072
2073 } // namespace views 2073 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698