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

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

Issue 993153003: Prevent infinite loop about itemizing text in RenderTextHarfBuzz. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 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
« no previous file with comments | « no previous file | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/i18n/bidi_line_iterator.h" 9 #include "base/i18n/bidi_line_iterator.h"
10 #include "base/i18n/break_iterator.h" 10 #include "base/i18n/break_iterator.h"
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 run_list_out->InitIndexMap(); 1144 run_list_out->InitIndexMap();
1145 return; 1145 return;
1146 } 1146 }
1147 1147
1148 // Temporarily apply composition underlines and selection colors. 1148 // Temporarily apply composition underlines and selection colors.
1149 ApplyCompositionAndSelectionStyles(); 1149 ApplyCompositionAndSelectionStyles();
1150 1150
1151 // Build the run list from the script items and ranged styles and baselines. 1151 // Build the run list from the script items and ranged styles and baselines.
1152 // Use an empty color BreakList to avoid breaking runs at color boundaries. 1152 // Use an empty color BreakList to avoid breaking runs at color boundaries.
1153 BreakList<SkColor> empty_colors; 1153 BreakList<SkColor> empty_colors;
1154 empty_colors.SetMax(text.length()); 1154 // StyleIterator is specified over the text, which can be different from
1155 // |text| variable given in the argument. Therefore its max should be
1156 // the text length, not "text->length()", otherwise it prevents to reach
1157 // to the end of the given text in the loop below.
1158 empty_colors.SetMax(this->text().length());
msw 2015/03/24 01:56:31 Just use colors().max() and remove this comment.
1155 internal::StyleIterator style(empty_colors, baselines(), styles()); 1159 internal::StyleIterator style(empty_colors, baselines(), styles());
1156 1160
1157 for (size_t run_break = 0; run_break < text.length();) { 1161 for (size_t run_break = 0; run_break < text.length();) {
1158 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; 1162 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz;
1159 run->range.set_start(run_break); 1163 run->range.set_start(run_break);
1160 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | 1164 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) |
1161 (style.style(ITALIC) ? Font::ITALIC : 0); 1165 (style.style(ITALIC) ? Font::ITALIC : 0);
1162 run->baseline_type = style.baseline(); 1166 run->baseline_type = style.baseline();
1163 run->strike = style.style(STRIKE); 1167 run->strike = style.style(STRIKE);
1164 run->diagonal_strike = style.style(DIAGONAL_STRIKE); 1168 run->diagonal_strike = style.style(DIAGONAL_STRIKE);
(...skipping 12 matching lines...) Expand all
1177 TextIndexToGivenTextIndex(text, style.GetRange().end())); 1181 TextIndexToGivenTextIndex(text, style.GetRange().end()));
1178 1182
1179 // Break runs at certain characters that need to be rendered separately to 1183 // Break runs at certain characters that need to be rendered separately to
1180 // prevent either an unusual character from forcing a fallback font on the 1184 // prevent either an unusual character from forcing a fallback font on the
1181 // entire run, or brackets from being affected by a fallback font. 1185 // entire run, or brackets from being affected by a fallback font.
1182 // http://crbug.com/278913, http://crbug.com/396776 1186 // http://crbug.com/278913, http://crbug.com/396776
1183 if (run_break > run->range.start()) 1187 if (run_break > run->range.start())
1184 run_break = FindRunBreakingCharacter(text, run->range.start(), run_break); 1188 run_break = FindRunBreakingCharacter(text, run->range.start(), run_break);
1185 1189
1186 DCHECK(IsValidCodePointIndex(text, run_break)); 1190 DCHECK(IsValidCodePointIndex(text, run_break));
1187 style.UpdatePosition(DisplayIndexToTextIndex(run_break)); 1191 style.UpdatePosition(DisplayIndexToTextIndex(run_break));
msw 2015/03/24 01:56:31 ItemizeTextToRuns is called with the layout text a
1188 run->range.set_end(run_break); 1192 run->range.set_end(run_break);
1189 1193
1190 run_list_out->add(run); 1194 run_list_out->add(run);
1191 } 1195 }
1192 1196
1193 // Undo the temporarily applied composition underlines and selection colors. 1197 // Undo the temporarily applied composition underlines and selection colors.
1194 UndoCompositionAndSelectionStyles(); 1198 UndoCompositionAndSelectionStyles();
1195 1199
1196 run_list_out->InitIndexMap(); 1200 run_list_out->InitIndexMap();
1197 } 1201 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 DCHECK(!update_layout_run_list_); 1519 DCHECK(!update_layout_run_list_);
1516 DCHECK(!update_display_run_list_); 1520 DCHECK(!update_display_run_list_);
1517 return text_elided() ? display_run_list_.get() : &layout_run_list_; 1521 return text_elided() ? display_run_list_.get() : &layout_run_list_;
1518 } 1522 }
1519 1523
1520 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { 1524 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const {
1521 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); 1525 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList();
1522 } 1526 }
1523 1527
1524 } // namespace gfx 1528 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698