Skip to content

Commit

Permalink
Merge branch 'release-1.6.22'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Jun 27, 2019
2 parents 878fa93 + b572f62 commit 9b7e346
Show file tree
Hide file tree
Showing 31 changed files with 276 additions and 1,187 deletions.
22 changes: 12 additions & 10 deletions Core/Source/DTAttributedTextContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#import "DTAccessibilityViewProxy.h"
#import "DTAccessibilityElement.h"
#import "DTCoreTextLayoutFrameAccessibilityElementGenerator.h"
#import "DTBlockFunctions.h"

#import <DTFoundation/DTBlockFunctions.h>

#if !__has_feature(objc_arc)
#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
Expand Down Expand Up @@ -503,18 +504,19 @@ - (void)drawRect:(CGRect)rect

- (void)relayoutText
{
__weak typeof(self) weakSelf = self;
DTBlockPerformSyncIfOnMainThreadElseAsync(^{

DTAttributedTextContentView *strongSelf = weakSelf;
// Make sure we actually have a superview and a previous layout before attempting to relayout the text.
if (_layoutFrame && self.superview)
if (strongSelf->_layoutFrame && strongSelf.superview)
{
// need new layout frame, layouter can remain because the attributed string is probably the same
self.layoutFrame = nil;
strongSelf.layoutFrame = nil;

// remove all links because they might have merged or split
[self removeAllCustomViewsForLinks];
[strongSelf removeAllCustomViewsForLinks];

if (_attributedString)
if (strongSelf->_attributedString)
{
// triggers new layout
CGSize neededSize = [self intrinsicContentSize];
Expand All @@ -525,12 +527,12 @@ - (void)relayoutText
[[NSNotificationCenter defaultCenter] postNotificationName:DTAttributedTextContentViewDidFinishLayoutNotification object:self userInfo:userInfo];
}

[self setNeedsLayout];
[self setNeedsDisplayInRect:self.bounds];
[strongSelf setNeedsLayout];
[strongSelf setNeedsDisplayInRect:self.bounds];

if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)])
if ([strongSelf respondsToSelector:@selector(invalidateIntrinsicContentSize)])
{
[self invalidateIntrinsicContentSize];
[strongSelf invalidateIntrinsicContentSize];
}
}
});
Expand Down
16 changes: 10 additions & 6 deletions Core/Source/DTAttributedTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#import "DTAttributedTextView.h"
#import "DTCoreText.h"
#import "DTBlockFunctions.h"

#import <DTFoundation/DTTiledLayerWithoutFade.h>
#import <DTFoundation/DTBlockFunctions.h>


@interface DTAttributedTextView ()
Expand Down Expand Up @@ -130,16 +130,18 @@ - (void)scrollRangeToVisible:(NSRange)range animated:(BOOL)animated

- (void)relayoutText
{
__weak typeof(self) weakSelf = self;
DTBlockPerformSyncIfOnMainThreadElseAsync(^{
DTAttributedTextView *strongSelf = weakSelf;

// need to reset the layouter because otherwise we get the old framesetter or cached layout frames
_attributedTextContentView.layouter=nil;
strongSelf->_attributedTextContentView.layouter=nil;

// here we're layouting the entire string, might be more efficient to only relayout the paragraphs that contain these attachments
[_attributedTextContentView relayoutText];
[strongSelf->_attributedTextContentView relayoutText];

// layout custom subviews for visible area
[self setNeedsLayout];
[strongSelf setNeedsLayout];
});
}

Expand All @@ -166,7 +168,9 @@ - (CGRect)cursorRectAtIndex:(NSInteger)index
#pragma mark Notifications
- (void)contentViewDidLayout:(NSNotification *)notification
{
__weak typeof(self) weakSelf = self;
DTBlockPerformSyncIfOnMainThreadElseAsync(^{
DTAttributedTextView *strongSelf = weakSelf;

NSDictionary *userInfo = [notification userInfo];
CGRect optimalFrame = [[userInfo objectForKey:@"OptimalFrame"] CGRectValue];
Expand All @@ -176,8 +180,8 @@ - (void)contentViewDidLayout:(NSNotification *)notification
// ignore possibly delayed layout notification for a different width
if (optimalFrame.size.width == frame.size.width)
{
_attributedTextContentView.frame = optimalFrame;
self.contentSize = [_attributedTextContentView intrinsicContentSize];
strongSelf->_attributedTextContentView.frame = optimalFrame;
strongSelf.contentSize = [strongSelf->_attributedTextContentView intrinsicContentSize];
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/DTCSSStylesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
Creates the default stylesheet.
This stylesheet is based on the standard styles that Webkit provides for these tags. This stylesheet is loaded from an embedded copy of default.css.
This stylesheet is based on the standard styles that Webkit provides for these tags. This stylesheet is loaded from default.css.
*/
+ (DTCSSStylesheet *)defaultStyleSheet;

Expand Down
26 changes: 15 additions & 11 deletions Core/Source/DTCSSStylesheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#import "NSString+HTML.h"


// external symbols generated via custom build rule and xxd
extern unsigned char default_css[];
extern unsigned int default_css_len;


@implementation DTCSSStylesheet
Expand All @@ -41,9 +38,16 @@ + (DTCSSStylesheet *)defaultStyleSheet
{
if (!defaultDTCSSStylesheet)
{
// get the data from the external symbol
NSData *data = [NSData dataWithBytes:default_css length:default_css_len];
NSString *cssString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSBundle *bundle = [NSBundle bundleForClass:self];
NSString *path = [bundle pathForResource:@"default" ofType:@"css"];
// Cocoapods uses a separate Resources bundle to include default.css
if (!path)
{
NSString *resourcesBundlePath = [bundle pathForResource:@"Resources" ofType:@"bundle"];
NSBundle *resourcesBundle = [NSBundle bundleWithPath:resourcesBundlePath];
path = [resourcesBundle pathForResource:@"default" ofType:@"css"];
}
NSString *cssString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

defaultDTCSSStylesheet = [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
}
Expand Down Expand Up @@ -709,18 +713,18 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element match
// Get based on class(es)
NSString *classString = [element.attributes objectForKey:@"class"];
NSArray *classes = [classString componentsSeparatedByString:@" "];

// Cascaded selectors with more than one part are sorted by specificity
NSMutableArray *matchingCascadingSelectors = [self matchingComplexCascadingSelectorsForElement:element];
[matchingCascadingSelectors sortUsingComparator:^NSComparisonResult(NSString *selector1, NSString *selector2)
{
NSInteger weightForSelector1 = [[_orderedSelectorWeights objectForKey:selector1] integerValue];
NSInteger weightForSelector2 = [[_orderedSelectorWeights objectForKey:selector2] integerValue];
NSInteger weightForSelector1 = [[self->_orderedSelectorWeights objectForKey:selector1] integerValue];
NSInteger weightForSelector2 = [[self->_orderedSelectorWeights objectForKey:selector2] integerValue];

if (weightForSelector1 == weightForSelector2)
{
weightForSelector1 += [_orderedSelectors indexOfObject:selector1];
weightForSelector2 += [_orderedSelectors indexOfObject:selector2];
weightForSelector1 += [self->_orderedSelectors indexOfObject:selector1];
weightForSelector2 += [self->_orderedSelectors indexOfObject:selector2];
}

if (weightForSelector1 > weightForSelector2)
Expand Down
3 changes: 2 additions & 1 deletion Core/Source/DTCoreTextFunctions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

#import "DTCoreTextFunctions.h"
#import "DTLog.h"

#import <DTFoundation/DTLog.h>

#if TARGET_OS_IPHONE
CTFontRef DTCTFontCreateWithUIFont(UIFont *font)
Expand Down
3 changes: 2 additions & 1 deletion Core/Source/DTCoreTextGlyphRun.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#import "DTCoreTextFunctions.h"
#import "NSDictionary+DTCoreText.h"
#import "DTWeakSupport.h"
#import "DTLog.h"

#import <DTFoundation/DTLog.h>

@implementation DTCoreTextGlyphRun
{
Expand Down
3 changes: 2 additions & 1 deletion Core/Source/DTDictationPlaceholderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
{
[super willMoveToSuperview:newSuperview];

[_phaseTimer invalidate], _phaseTimer = nil;
[_phaseTimer invalidate];
_phaseTimer = nil;

if (newSuperview)
{
Expand Down
Loading

0 comments on commit 9b7e346

Please sign in to comment.