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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 offset.set_y((display_rect_.height() - text_height) / 2); | 1086 offset.set_y((display_rect_.height() - text_height) / 2); |
1087 } else { | 1087 } else { |
1088 offset.set_y(GetBaseline() - GetLayoutTextBaseline()); | 1088 offset.set_y(GetBaseline() - GetLayoutTextBaseline()); |
1089 } | 1089 } |
1090 | 1090 |
1091 return offset; | 1091 return offset; |
1092 } | 1092 } |
1093 | 1093 |
1094 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { | 1094 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { |
1095 const int width = display_rect().width(); | 1095 const int width = display_rect().width(); |
1096 if (multiline() || elide_behavior_ != FADE_TAIL || GetContentWidth() <= width) | 1096 if (multiline() || elide_behavior_ != FADE_TAIL || |
| 1097 static_cast<int>(GetContentWidth()) <= width) |
1097 return; | 1098 return; |
1098 | 1099 |
1099 const int gradient_width = CalculateFadeGradientWidth(font_list(), width); | 1100 const int gradient_width = CalculateFadeGradientWidth(font_list(), width); |
1100 if (gradient_width == 0) | 1101 if (gradient_width == 0) |
1101 return; | 1102 return; |
1102 | 1103 |
1103 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); | 1104 HorizontalAlignment horizontal_alignment = GetCurrentHorizontalAlignment(); |
1104 Rect solid_part = display_rect(); | 1105 Rect solid_part = display_rect(); |
1105 Rect left_part; | 1106 Rect left_part; |
1106 Rect right_part; | 1107 Rect right_part; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 const size_t ellipsis_end = iter.getIndex(); | 1192 const size_t ellipsis_end = iter.getIndex(); |
1192 DCHECK_LE(ellipsis_start, ellipsis_end); | 1193 DCHECK_LE(ellipsis_start, ellipsis_end); |
1193 layout_text_.assign(text.substr(0, ellipsis_start) + kEllipsisUTF16 + | 1194 layout_text_.assign(text.substr(0, ellipsis_start) + kEllipsisUTF16 + |
1194 text.substr(ellipsis_end)); | 1195 text.substr(ellipsis_end)); |
1195 } else { | 1196 } else { |
1196 iter.setIndex32(truncate_length_ - 1); | 1197 iter.setIndex32(truncate_length_ - 1); |
1197 layout_text_.assign(text.substr(0, iter.getIndex()) + kEllipsisUTF16); | 1198 layout_text_.assign(text.substr(0, iter.getIndex()) + kEllipsisUTF16); |
1198 } | 1199 } |
1199 } | 1200 } |
1200 | 1201 |
1201 if (elide_behavior_ != NO_ELIDE && elide_behavior_ != FADE_TAIL && | 1202 if (elide_behavior_ != NO_ELIDE && |
1202 !layout_text_.empty() && GetContentWidth() > display_rect_.width()) { | 1203 elide_behavior_ != FADE_TAIL && |
| 1204 !layout_text_.empty() && |
| 1205 static_cast<int>(GetContentWidth()) > display_rect_.width()) { |
1203 // This doesn't trim styles so ellipsis may get rendered as a different | 1206 // This doesn't trim styles so ellipsis may get rendered as a different |
1204 // style than the preceding text. See crbug.com/327850. | 1207 // style than the preceding text. See crbug.com/327850. |
1205 layout_text_.assign( | 1208 layout_text_.assign( |
1206 Elide(layout_text_, display_rect_.width(), elide_behavior_)); | 1209 Elide(layout_text_, display_rect_.width(), elide_behavior_)); |
1207 } | 1210 } |
1208 | 1211 |
1209 // Replace the newline character with a newline symbol in single line mode. | 1212 // Replace the newline character with a newline symbol in single line mode. |
1210 static const base::char16 kNewline[] = { '\n', 0 }; | 1213 static const base::char16 kNewline[] = { '\n', 0 }; |
1211 static const base::char16 kNewlineSymbol[] = { 0x2424, 0 }; | 1214 static const base::char16 kNewlineSymbol[] = { 0x2424, 0 }; |
1212 if (!multiline_ && replace_newline_chars_with_symbols_) | 1215 if (!multiline_ && replace_newline_chars_with_symbols_) |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 SetDisplayOffset(display_offset_.x() + delta_x); | 1381 SetDisplayOffset(display_offset_.x() + delta_x); |
1379 } | 1382 } |
1380 | 1383 |
1381 void RenderText::DrawSelection(Canvas* canvas) { | 1384 void RenderText::DrawSelection(Canvas* canvas) { |
1382 const std::vector<Rect> sel = GetSubstringBounds(selection()); | 1385 const std::vector<Rect> sel = GetSubstringBounds(selection()); |
1383 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) | 1386 for (std::vector<Rect>::const_iterator i = sel.begin(); i < sel.end(); ++i) |
1384 canvas->FillRect(*i, selection_background_focused_color_); | 1387 canvas->FillRect(*i, selection_background_focused_color_); |
1385 } | 1388 } |
1386 | 1389 |
1387 } // namespace gfx | 1390 } // namespace gfx |
OLD | NEW |