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. |