Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/chrome/browser/ui/util/core_text_util.h" | 5 #import "ios/chrome/browser/ui/util/core_text_util.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" | |
| 12 #import "ios/chrome/browser/ui/util/manual_text_framer.h" | 11 #import "ios/chrome/browser/ui/util/manual_text_framer.h" |
| 13 #import "ios/chrome/browser/ui/util/text_frame.h" | 12 #import "ios/chrome/browser/ui/util/text_frame.h" |
| 14 #import "ios/chrome/browser/ui/util/unicode_util.h" | 13 #import "ios/chrome/browser/ui/util/unicode_util.h" |
| 15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 16 #error "This file requires ARC support." | |
| 17 #endif | |
| 18 | |
| 16 namespace core_text_util { | 19 namespace core_text_util { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 // Returns the range within |string| for which |text_frame|'s glyph information | 22 // Returns the range within |string| for which |text_frame|'s glyph information |
| 20 // is non-repeating. | 23 // is non-repeating. |
| 21 CFRange GetValidRangeForTextFrame(CTFrameRef text_frame, | 24 CFRange GetValidRangeForTextFrame(CTFrameRef text_frame, |
| 22 NSAttributedString* string) { | 25 NSAttributedString* string) { |
| 23 DCHECK(text_frame); | 26 DCHECK(text_frame); |
| 24 DCHECK(string.length); | 27 DCHECK(string.length); |
| 25 CFRange range = CFRangeMake(0, 0); | 28 CFRange range = CFRangeMake(0, 0); |
| 26 bool is_rtl = | 29 bool is_rtl = |
| 27 GetEffectiveWritingDirection(string) == NSWritingDirectionRightToLeft; | 30 GetEffectiveWritingDirection(string) == NSWritingDirectionRightToLeft; |
| 28 for (id line_id in base::mac::CFToNSCast(CTFrameGetLines(text_frame))) { | 31 for (id line_id in base::mac::CFToNSCast(CTFrameGetLines(text_frame))) { |
| 29 CTLineRef line = static_cast<CTLineRef>(line_id); | 32 CTLineRef line = (__bridge CTLineRef)(line_id); |
|
marq (ping after 24h)
2017/04/21 16:25:04
We should still use static_cast<>() even if we're
sdefresne
2017/04/24 11:30:02
Sadly "bridge" and "static_cast" don't mix. This i
| |
| 30 NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(line)); | 33 NSArray* runs = base::mac::CFToNSCast(CTLineGetGlyphRuns(line)); |
| 31 NSInteger run_idx = is_rtl ? runs.count - 1 : 0; | 34 NSInteger run_idx = is_rtl ? runs.count - 1 : 0; |
| 32 while (run_idx >= 0 && run_idx < static_cast<NSInteger>(runs.count)) { | 35 while (run_idx >= 0 && run_idx < static_cast<NSInteger>(runs.count)) { |
| 33 CTRunRef run = static_cast<CTRunRef>(runs[run_idx]); | 36 CTRunRef run = (__bridge CTRunRef)(runs[run_idx]); |
| 34 CFRange run_range = CTRunGetStringRange(run); | 37 CFRange run_range = CTRunGetStringRange(run); |
| 35 if (run_range.location == range.location + range.length) | 38 if (run_range.location == range.location + range.length) |
| 36 range.length += run_range.length; | 39 range.length += run_range.length; |
| 37 else | 40 else |
| 38 break; | 41 break; |
| 39 run_idx += is_rtl ? -1 : 1; | 42 run_idx += is_rtl ? -1 : 1; |
| 40 } | 43 } |
| 41 } | 44 } |
| 42 return range; | 45 return range; |
| 43 } | 46 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 atIndex:0 | 220 atIndex:0 |
| 218 effectiveRange:nullptr]; | 221 effectiveRange:nullptr]; |
| 219 if (style && style.baseWritingDirection != NSWritingDirectionNatural) { | 222 if (style && style.baseWritingDirection != NSWritingDirectionNatural) { |
| 220 // Use the NSParagraphStyle's writing direction if specified. | 223 // Use the NSParagraphStyle's writing direction if specified. |
| 221 direction = style.baseWritingDirection; | 224 direction = style.baseWritingDirection; |
| 222 } | 225 } |
| 223 return direction; | 226 return direction; |
| 224 } | 227 } |
| 225 | 228 |
| 226 } // namespace core_text_util | 229 } // namespace core_text_util |
| OLD | NEW |