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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 1015533016: Move allow_character_break property to RenderText. (Closed) 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_harfbuzz.cc
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc
index c931f22216e57951854e33322a597d7271c4ea37..4fc836d377bc934c1ca63d034858a364659a119a 100644
--- a/ui/gfx/render_text_harfbuzz.cc
+++ b/ui/gfx/render_text_harfbuzz.cc
@@ -224,6 +224,7 @@ class HarfBuzzLineBreaker {
int min_baseline,
float min_height,
bool multiline,
+ WordWrapBehavior word_wrap_behavior,
const base::string16& text,
const BreakList<size_t>* words,
const internal::TextRunList& run_list)
@@ -231,6 +232,7 @@ class HarfBuzzLineBreaker {
min_baseline_(min_baseline),
min_height_(min_height),
multiline_(multiline),
+ word_wrap_behavior_(word_wrap_behavior),
text_(text),
words_(words),
run_list_(run_list),
@@ -285,9 +287,10 @@ class HarfBuzzLineBreaker {
// Break the run until it fits the current line.
while (next_char < run.range.end()) {
const size_t current_char = next_char;
+ size_t end_char = next_char;
const bool skip_line =
- BreakRunAtWidth(run, current_char, &width, &next_char);
- AddSegment(run_index, Range(current_char, next_char),
+ BreakRunAtWidth(run, current_char, &width, &end_char, &next_char);
+ AddSegment(run_index, Range(current_char, end_char),
SkScalarToFloat(width));
if (skip_line)
AdvanceLine();
@@ -298,7 +301,8 @@ class HarfBuzzLineBreaker {
// before available width using word break. If the current position is at the
// beginning of a line, this function will not roll back to |start_char| and
// |*next_char| will be greater than |start_char| (to avoid constructing empty
- // lines).
+ // lines). It stores the end of the segment range to |end_char|, which can be
+ // smaller than |*next_char| for certain word wrapping behavior.
// Returns whether to skip the line before |*next_char|.
// TODO(ckocagil): We might have to reshape after breaking at ligatures.
// See whether resolving the TODO above resolves this too.
@@ -306,6 +310,7 @@ class HarfBuzzLineBreaker {
bool BreakRunAtWidth(const internal::TextRunHarfBuzz& run,
size_t start_char,
SkScalar* width,
+ size_t* end_char,
size_t* next_char) {
DCHECK(words_);
DCHECK(run.range.Contains(Range(start_char, start_char + 1)));
@@ -322,6 +327,13 @@ class HarfBuzzLineBreaker {
// the word boundary right after |i|. Advance both |word| and |next_word|
// when |i| reaches |next_word|.
if (next_word != words_->breaks().end() && i >= next_word->first) {
+ if (*width > available_width) {
+ DCHECK_NE(WRAP_LONG_WORDS, word_wrap_behavior_);
+ *next_char = i;
+ if (word_wrap_behavior_ != TRUNCATE_LONG_WORDS)
+ *end_char = *next_char;
+ return true;
+ }
word = next_word++;
word_width = 0;
}
@@ -338,24 +350,33 @@ class HarfBuzzLineBreaker {
*width += char_width;
word_width += char_width;
+ // TODO(mukai): implement ELIDE_LONG_WORDS.
if (*width > available_width) {
if (line_x_ != 0 || word_width < *width) {
// Roll back one word.
*width -= word_width;
*next_char = std::max(word->first, start_char);
- } else if (char_width < *width) {
- // Roll back one character.
- *width -= char_width;
- *next_char = i;
- } else {
- // Continue from the next character.
- *next_char = i + char_range.length();
+ *end_char = *next_char;
+ return true;
+ } else if (word_wrap_behavior_ == WRAP_LONG_WORDS) {
+ if (char_width < *width) {
+ // Roll back one character.
+ *width -= char_width;
+ *next_char = i;
+ } else {
+ // Continue from the next character.
+ *next_char = i + char_range.length();
+ }
+ *end_char = *next_char;
+ return true;
}
- return true;
+ } else {
+ *end_char = char_range.end();
}
}
*next_char = run.range.end();
+ *end_char = *next_char;
msw 2015/03/27 01:45:27 optional nit: "*end_char = *next_char = run.range.
Jun Mukai 2015/03/27 16:36:12 Done.
return false;
}
@@ -448,6 +469,7 @@ class HarfBuzzLineBreaker {
const int min_baseline_;
const float min_height_;
const bool multiline_;
+ const WordWrapBehavior word_wrap_behavior_;
const base::string16& text_;
const BreakList<size_t>* const words_;
const internal::TextRunList& run_list_;
@@ -997,7 +1019,8 @@ void RenderTextHarfBuzz::EnsureLayout() {
HarfBuzzLineBreaker line_breaker(
display_rect().width(), font_list().GetBaseline(),
std::max(font_list().GetHeight(), min_line_height()), multiline(),
- GetDisplayText(), multiline() ? &GetLineBreaks() : nullptr, *run_list);
+ word_wrap_behavior(), GetDisplayText(),
+ multiline() ? &GetLineBreaks() : nullptr, *run_list);
// TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
tracked_objects::ScopedTracker tracking_profile3(
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698