| 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_mac.h" | 5 #include "ui/gfx/render_text_mac.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/mac/foundation_util.h" | 13 #include "base/mac/foundation_util.h" |
| 14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "skia/ext/skia_utils_mac.h" | 16 #include "skia/ext/skia_utils_mac.h" |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 | 19 |
| 20 RenderTextMac::RenderTextMac() : common_baseline_(0), runs_valid_(false) { | 20 RenderTextMac::RenderTextMac() |
| 21 : common_baseline_(0), runs_valid_(false) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 RenderTextMac::~RenderTextMac() { | 24 RenderTextMac::~RenderTextMac() { |
| 24 } | 25 } |
| 25 | 26 |
| 26 scoped_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const { | 27 scoped_ptr<RenderText> RenderTextMac::CreateInstanceOfSameType() const { |
| 27 return scoped_ptr<RenderTextMac>(new RenderTextMac); | 28 return scoped_ptr<RenderTextMac>(new RenderTextMac); |
| 28 } | 29 } |
| 29 | 30 |
| 31 const base::string16& RenderTextMac::GetLayoutText() { |
| 32 if (elide_behavior() == NO_ELIDE || |
| 33 elide_behavior() == FADE_TAIL) { |
| 34 return layout_text(); |
| 35 } |
| 36 return text_elided() ? elided_text() : layout_text(); |
| 37 } |
| 38 |
| 30 Size RenderTextMac::GetStringSize() { | 39 Size RenderTextMac::GetStringSize() { |
| 31 EnsureLayout(); | 40 EnsureLayout(); |
| 32 return Size(std::ceil(string_size_.width()), string_size_.height()); | 41 return Size(std::ceil(string_size_.width()), string_size_.height()); |
| 33 } | 42 } |
| 34 | 43 |
| 35 SizeF RenderTextMac::GetStringSizeF() { | 44 SizeF RenderTextMac::GetStringSizeF() { |
| 36 EnsureLayout(); | 45 EnsureLayout(); |
| 37 return string_size_; | 46 return string_size_; |
| 38 } | 47 } |
| 39 | 48 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 Range RenderTextMac::GetGlyphBounds(size_t index) { | 89 Range RenderTextMac::GetGlyphBounds(size_t index) { |
| 81 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 90 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
| 82 return Range(); | 91 return Range(); |
| 83 } | 92 } |
| 84 | 93 |
| 85 std::vector<Rect> RenderTextMac::GetSubstringBounds(const Range& range) { | 94 std::vector<Rect> RenderTextMac::GetSubstringBounds(const Range& range) { |
| 86 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 95 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
| 87 return std::vector<Rect>(); | 96 return std::vector<Rect>(); |
| 88 } | 97 } |
| 89 | 98 |
| 90 size_t RenderTextMac::TextIndexToLayoutIndex(size_t index) const { | 99 size_t RenderTextMac::TextIndexToLayoutIndex(size_t index) { |
| 91 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 100 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
| 92 return index; | 101 return index; |
| 93 } | 102 } |
| 94 | 103 |
| 95 size_t RenderTextMac::LayoutIndexToTextIndex(size_t index) const { | 104 size_t RenderTextMac::LayoutIndexToTextIndex(size_t index) { |
| 96 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 105 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
| 97 return index; | 106 return index; |
| 98 } | 107 } |
| 99 | 108 |
| 100 bool RenderTextMac::IsValidCursorIndex(size_t index) { | 109 bool RenderTextMac::IsValidCursorIndex(size_t index) { |
| 101 // TODO(asvitkine): Implement this. http://crbug.com/131618 | 110 // TODO(asvitkine): Implement this. http://crbug.com/131618 |
| 102 return IsValidLogicalIndex(index); | 111 return IsValidLogicalIndex(index); |
| 103 } | 112 } |
| 104 | 113 |
| 105 void RenderTextMac::ResetLayout() { | 114 void RenderTextMac::OnLayoutTextShapeChanged(bool text_changed) { |
| 115 if (text_changed && |
| 116 elide_behavior() != NO_ELIDE && |
| 117 elide_behavior() != FADE_TAIL && |
| 118 !layout_text().empty()) { |
| 119 UpdateElidedText(GetContentWidth()); |
| 120 } |
| 106 line_.reset(); | 121 line_.reset(); |
| 107 attributes_.reset(); | 122 attributes_.reset(); |
| 108 runs_.clear(); | 123 runs_.clear(); |
| 109 runs_valid_ = false; | 124 runs_valid_ = false; |
| 110 } | 125 } |
| 111 | 126 |
| 127 void RenderTextMac::OnElidedTextShapeChanged() { |
| 128 OnLayoutTextShapeChanged(true); |
| 129 } |
| 130 |
| 112 void RenderTextMac::EnsureLayout() { | 131 void RenderTextMac::EnsureLayout() { |
| 113 if (line_.get()) | 132 if (line_.get()) |
| 114 return; | 133 return; |
| 115 runs_.clear(); | 134 runs_.clear(); |
| 116 runs_valid_ = false; | 135 runs_valid_ = false; |
| 117 | 136 |
| 118 CTFontRef ct_font = base::mac::NSToCFCast( | 137 CTFontRef ct_font = base::mac::NSToCFCast( |
| 119 font_list().GetPrimaryFont().GetNativeFont()); | 138 font_list().GetPrimaryFont().GetNativeFont()); |
| 120 | 139 |
| 121 const void* keys[] = { kCTFontAttributeName }; | 140 const void* keys[] = { kCTFontAttributeName }; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 CTUnderlineStyle value = kCTUnderlineStyleNone; | 358 CTUnderlineStyle value = kCTUnderlineStyleNone; |
| 340 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) | 359 if (underline && CFNumberGetValue(underline, kCFNumberSInt32Type, &value)) |
| 341 run->underline = (value == kCTUnderlineStyleSingle); | 360 run->underline = (value == kCTUnderlineStyleSingle); |
| 342 | 361 |
| 343 run_origin.offset(run_width, 0); | 362 run_origin.offset(run_width, 0); |
| 344 } | 363 } |
| 345 runs_valid_ = true; | 364 runs_valid_ = true; |
| 346 } | 365 } |
| 347 | 366 |
| 348 } // namespace gfx | 367 } // namespace gfx |
| OLD | NEW |