OLD | NEW |
---|---|
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 <algorithm> | 7 #include <algorithm> |
8 #include <climits> | 8 #include <climits> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 633 matching lines...) Loading... | |
644 } | 644 } |
645 | 645 |
646 void RenderText::SetStyle(TextStyle style, bool value) { | 646 void RenderText::SetStyle(TextStyle style, bool value) { |
647 styles_[style].SetValue(value); | 647 styles_[style].SetValue(value); |
648 | 648 |
649 cached_bounds_and_offset_valid_ = false; | 649 cached_bounds_and_offset_valid_ = false; |
650 ResetLayout(); | 650 ResetLayout(); |
651 } | 651 } |
652 | 652 |
653 void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) { | 653 void RenderText::ApplyStyle(TextStyle style, bool value, const Range& range) { |
654 styles_[style].ApplyValue(value, range); | 654 // Don't change style in the middle of grapheme to avoid breaking of ligature. |
msw
2014/09/03 19:17:32
nit: "Do not change styles mid-grapheme to avoid b
| |
655 const size_t corrected_end = | |
msw
2014/09/03 19:17:32
We should only correct the range bounds as needed:
| |
656 IndexOfAdjacentGrapheme(range.end() - 1, CURSOR_FORWARD); | |
657 styles_[style].ApplyValue(value, Range(range.start(), corrected_end)); | |
msw
2014/09/03 19:17:32
We should also correct the range start (using CURS
| |
655 | 658 |
656 cached_bounds_and_offset_valid_ = false; | 659 cached_bounds_and_offset_valid_ = false; |
657 ResetLayout(); | 660 ResetLayout(); |
658 } | 661 } |
659 | 662 |
660 bool RenderText::GetStyle(TextStyle style) const { | 663 bool RenderText::GetStyle(TextStyle style) const { |
661 return (styles_[style].breaks().size() == 1) && | 664 return (styles_[style].breaks().size() == 1) && |
662 styles_[style].breaks().front().second; | 665 styles_[style].breaks().front().second; |
663 } | 666 } |
664 | 667 |
(...skipping 703 matching lines...) Loading... | |
1368 SetDisplayOffset(display_offset_.x() + delta_x); | 1371 SetDisplayOffset(display_offset_.x() + delta_x); |
1369 } | 1372 } |
1370 | 1373 |
1371 void RenderText::DrawSelection(Canvas* canvas) { | 1374 void RenderText::DrawSelection(Canvas* canvas) { |
1372 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1375 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1373 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1376 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1374 canvas->FillRect(*i, selection_background_focused_color_); | 1377 canvas->FillRect(*i, selection_background_focused_color_); |
1375 } | 1378 } |
1376 | 1379 |
1377 } // namespace gfx | 1380 } // namespace gfx |
OLD | NEW |