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

Side by Side Diff: ui/gfx/render_text.cc

Issue 2660593002: Paint text cursor in LAYER_SOLID_COLOR (Closed)
Patch Set: address comments Created 3 years, 10 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/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <climits> 10 #include <climits>
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 Rect clip_rect(display_rect()); 857 Rect clip_rect(display_rect());
858 clip_rect.Inset(ShadowValue::GetMargin(shadows_)); 858 clip_rect.Inset(ShadowValue::GetMargin(shadows_));
859 859
860 canvas->Save(); 860 canvas->Save();
861 canvas->ClipRect(clip_rect); 861 canvas->ClipRect(clip_rect);
862 } 862 }
863 863
864 if (!text().empty() && focused()) 864 if (!text().empty() && focused())
865 DrawSelection(canvas); 865 DrawSelection(canvas);
866 866
867 if (cursor_enabled() && cursor_visible() && focused())
868 DrawCursor(canvas, selection_model_);
869
870 if (!text().empty()) { 867 if (!text().empty()) {
871 internal::SkiaTextRenderer renderer(canvas); 868 internal::SkiaTextRenderer renderer(canvas);
872 if (halo_effect()) 869 if (halo_effect())
873 renderer.SetHaloEffect(); 870 renderer.SetHaloEffect();
874 DrawVisualText(&renderer); 871 DrawVisualText(&renderer);
875 } 872 }
876 873
877 if (clip_to_display_rect()) 874 if (clip_to_display_rect())
878 canvas->Restore(); 875 canvas->Restore();
879 } 876 }
880 877
881 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) { 878 void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) {
msw 2017/02/13 21:27:12 Can you remove this function and inline similar fu
yiyix 2017/02/15 16:56:32 Inline it it's a good idea. I will remove the todo
882 // Paint cursor. Replace cursor is drawn as rectangle for now. 879 // Paint cursor. Replace cursor is drawn as rectangle for now.
883 // TODO(msw): Draw a better cursor with a better indication of association. 880 // TODO(msw): Draw a better cursor with a better indication of association.
884 canvas->FillRect(GetCursorBounds(position, true), cursor_color_); 881 canvas->FillRect(GetCursorBounds(position, true), cursor_color_);
885 } 882 }
886 883
887 bool RenderText::IsValidLogicalIndex(size_t index) const { 884 bool RenderText::IsValidLogicalIndex(size_t index) const {
888 // Check that the index is at a valid code point (not mid-surrgate-pair) and 885 // Check that the index is at a valid code point (not mid-surrgate-pair) and
889 // that it's not truncated from the display text (its glyph may be shown). 886 // that it's not truncated from the display text (its glyph may be shown).
890 // 887 //
891 // Indices within truncated text are disallowed so users can easily interact 888 // Indices within truncated text are disallowed so users can easily interact
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 if (range.IsValid() && range.GetMin() < text().length()) 1069 if (range.IsValid() && range.GetMin() < text().length())
1073 return text().substr(range.GetMin(), range.length()); 1070 return text().substr(range.GetMin(), range.length());
1074 return base::string16(); 1071 return base::string16();
1075 } 1072 }
1076 1073
1077 RenderText::RenderText() 1074 RenderText::RenderText()
1078 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), 1075 : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
1079 directionality_mode_(DIRECTIONALITY_FROM_TEXT), 1076 directionality_mode_(DIRECTIONALITY_FROM_TEXT),
1080 text_direction_(base::i18n::UNKNOWN_DIRECTION), 1077 text_direction_(base::i18n::UNKNOWN_DIRECTION),
1081 cursor_enabled_(true), 1078 cursor_enabled_(true),
1082 cursor_visible_(false),
1083 cursor_color_(kDefaultColor), 1079 cursor_color_(kDefaultColor),
1084 selection_color_(kDefaultColor), 1080 selection_color_(kDefaultColor),
1085 selection_background_focused_color_(kDefaultSelectionBackgroundColor), 1081 selection_background_focused_color_(kDefaultSelectionBackgroundColor),
1086 focused_(false), 1082 focused_(false),
1087 composition_range_(Range::InvalidRange()), 1083 composition_range_(Range::InvalidRange()),
1088 colors_(kDefaultColor), 1084 colors_(kDefaultColor),
1089 baselines_(NORMAL_BASELINE), 1085 baselines_(NORMAL_BASELINE),
1090 weights_(Font::Weight::NORMAL), 1086 weights_(Font::Weight::NORMAL),
1091 styles_(NUM_TEXT_STYLES), 1087 styles_(NUM_TEXT_STYLES),
1092 composition_and_selection_styles_applied_(false), 1088 composition_and_selection_styles_applied_(false),
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 1710
1715 for (; range_max < length; ++range_max) 1711 for (; range_max < length; ++range_max)
1716 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1712 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1717 break; 1713 break;
1718 1714
1719 return range.is_reversed() ? Range(range_max, range_min) 1715 return range.is_reversed() ? Range(range_max, range_min)
1720 : Range(range_min, range_max); 1716 : Range(range_min, range_max);
1721 } 1717 }
1722 1718
1723 } // namespace gfx 1719 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698