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

Unified Diff: ui/gfx/render_text_mac.cc

Issue 916203002: Reduce the number of text reshaping in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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_mac.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_mac.cc
diff --git a/ui/gfx/render_text_mac.cc b/ui/gfx/render_text_mac.cc
index aa33fc019d26e165ed49205b0ab383540d0b4add..32731d4259872aed3bfde4a56012c519c11e4e0b 100644
--- a/ui/gfx/render_text_mac.cc
+++ b/ui/gfx/render_text_mac.cc
@@ -17,7 +17,8 @@
namespace gfx {
-RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) {
+RenderTextMac::RenderTextMac()
+ : common_baseline_(0), runs_valid_(false) {
}
RenderTextMac::~RenderTextMac() {
@@ -27,6 +28,10 @@ scoped_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const {
return scoped_ptr<RenderTextMac>(new RenderTextMac);
}
+const base::string16& RenderTextMac::GetDisplayText() {
+ return text_elided() ? display_text() : layout_text();
+}
+
Size RenderTextMac::GetStringSize() {
EnsureLayout();
return Size(std::ceil(string_size_.width()), string_size_.height());
@@ -58,7 +63,7 @@ std::vector<RenderText::FontSpan> RenderTextMac::GetFontSpansForTesting() {
return spans;
}
-int RenderTextMac::GetLayoutTextBaseline() {
+int RenderTextMac::GetDisplayTextBaseline() {
EnsureLayout();
return common_baseline_;
}
@@ -87,12 +92,12 @@ std::vector<Rect> RenderTextMac::GetSubstringBounds(const Range& range) {
return std::vector<Rect>();
}
-size_t RenderTextMac::TextIndexToLayoutIndex(size_t index) const {
+size_t RenderTextMac::TextIndexToDisplayIndex(size_t index) {
// TODO(asvitkine): Implement this. http://crbug.com/131618
return index;
}
-size_t RenderTextMac::LayoutIndexToTextIndex(size_t index) const {
+size_t RenderTextMac::DisplayIndexToTextIndex(size_t index) {
// TODO(asvitkine): Implement this. http://crbug.com/131618
return index;
}
@@ -102,13 +107,26 @@ bool RenderTextMac::IsValidCursorIndex(size_t index) {
return IsValidLogicalIndex(index);
}
-void RenderTextMac::ResetLayout() {
+void RenderTextMac::OnLayoutTextAttributeChanged(bool text_changed) {
+ if (text_changed) {
+ if (elide_behavior() != NO_ELIDE &&
+ elide_behavior() != FADE_TAIL &&
+ !layout_text().empty()) {
+ UpdateDisplayText(GetContentWidth());
+ } else {
+ UpdateDisplayText(0);
+ }
+ }
line_.reset();
attributes_.reset();
runs_.clear();
runs_valid_ = false;
}
+void RenderTextMac::OnDisplayTextAttributeChanged() {
+ OnLayoutTextAttributeChanged(true);
+}
+
void RenderTextMac::EnsureLayout() {
if (line_.get())
return;
@@ -212,9 +230,9 @@ void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string,
// https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_StringAttributes_Ref/Reference/reference.html
internal::StyleIterator style(colors(), styles());
- const size_t layout_text_length = GetLayoutText().length();
+ const size_t layout_text_length = GetDisplayText().length();
for (size_t i = 0, end = 0; i < layout_text_length; i = end) {
- end = TextIndexToLayoutIndex(style.GetRange().end());
+ end = TextIndexToDisplayIndex(style.GetRange().end());
const CFRange range = CFRangeMake(i, end - i);
base::ScopedCFTypeRef<CGColorRef> foreground(
CGColorCreateFromSkColor(style.color()));
@@ -245,7 +263,7 @@ void RenderTextMac::ApplyStyles(CFMutableAttributedStringRef attr_string,
}
}
- style.UpdatePosition(LayoutIndexToTextIndex(end));
+ style.UpdatePosition(DisplayIndexToTextIndex(end));
}
// Undo the temporarily applied composition underlines and selection colors.
« no previous file with comments | « ui/gfx/render_text_mac.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698