OLD | NEW |
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 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 update_grapheme_iterator_ = false; | 1446 update_grapheme_iterator_ = false; |
1447 grapheme_iterator_.reset(new base::i18n::BreakIterator( | 1447 grapheme_iterator_.reset(new base::i18n::BreakIterator( |
1448 GetDisplayText(), | 1448 GetDisplayText(), |
1449 base::i18n::BreakIterator::BREAK_CHARACTER)); | 1449 base::i18n::BreakIterator::BREAK_CHARACTER)); |
1450 if (!grapheme_iterator_->Init()) | 1450 if (!grapheme_iterator_->Init()) |
1451 grapheme_iterator_.reset(); | 1451 grapheme_iterator_.reset(); |
1452 } | 1452 } |
1453 return grapheme_iterator_.get(); | 1453 return grapheme_iterator_.get(); |
1454 } | 1454 } |
1455 | 1455 |
1456 size_t RenderTextHarfBuzz::TextIndexToGivenTextIndex( | |
1457 const base::string16& given_text, | |
1458 size_t index) { | |
1459 DCHECK(given_text == layout_text() || given_text == display_text()); | |
1460 DCHECK_LE(index, text().length()); | |
1461 ptrdiff_t i = obscured() ? UTF16IndexToOffset(text(), 0, index) : index; | |
1462 CHECK_GE(i, 0); | |
1463 // Clamp indices to the length of the given layout or display text. | |
1464 return std::min<size_t>(given_text.length(), i); | |
1465 } | |
1466 | |
1467 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { | 1456 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { |
1468 DCHECK(!update_layout_run_list_); | 1457 DCHECK(!update_layout_run_list_); |
1469 DCHECK(!update_display_run_list_); | 1458 DCHECK(!update_display_run_list_); |
1470 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1459 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1471 } | 1460 } |
1472 | 1461 |
1473 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1462 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1474 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1463 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1475 } | 1464 } |
1476 | 1465 |
1477 } // namespace gfx | 1466 } // namespace gfx |
OLD | NEW |