X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/2de63e6327bc0d8d788881d9bf04132be07b2001..900dc9a5d6341928f9190bb8840fdf61df65b59b:/WBMarkup.mm diff --git a/WBMarkup.mm b/WBMarkup.mm index 9550114..77d7c37 100644 --- a/WBMarkup.mm +++ b/WBMarkup.mm @@ -1,14 +1,15 @@ #include "WBMarkup.h" +#include + @class WKView; -extern "C" { - void WebThreadLock(); - CGContextRef WKGetCurrentGraphicsContext(); - void WKViewLockFocus(WKView *); - void WKViewUnlockFocus(WKView *); - void WKViewDisplayRect(WKView *, CGRect); -} +extern "C" void WebThreadLock(); +extern "C" CGContextRef WKGetCurrentGraphicsContext(); + +static void (*WKViewLockFocus$)(WKView *); +static void (*WKViewUnlockFocus$)(WKView *); +static void (*WKViewDisplayRect$)(WKView *, CGRect); @interface DOMElement : NSObject - (void) setInnerHTML:(NSString *)value; @@ -43,7 +44,11 @@ extern "C" { - (DOMDocument *) DOMDocument; @end -@interface WebView : NSObject +@interface WAKView : NSObject +- (void) _drawRect:(CGRect)rect context:(CGContext *)context lockFocus:(bool)focus; +@end + +@interface WebView : WAKView - (id) initWithFrame:(CGRect)frame; - (WebFrame *) mainFrame; - (void) setDrawsBackground:(BOOL)value; @@ -60,6 +65,13 @@ static WBMarkup *SharedMarkup_; @implementation WBMarkup ++ (void) initialize { + MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore")); + MSHookSymbol(WKViewLockFocus$, "WKViewLockFocus", WebCore); + MSHookSymbol(WKViewUnlockFocus$, "WKViewUnlockFocus", WebCore); + MSHookSymbol(WKViewDisplayRect$, "WKViewDisplayRect", WebCore); +} + + (BOOL) isSharedMarkupCreated { return SharedMarkup_ != nil; } @@ -101,6 +113,25 @@ static WBMarkup *SharedMarkup_; [super dealloc]; } +- (void) drawRect:(CGRect)rect { + [text_ setScrollXOffset:origin_.x scrollYOffset:origin_.y]; + + CGRect draw(CGRectMake(0, 0, rect.size.width - rect.origin.x, rect.size.height - rect.origin.y)); + + CGContextSaveGState(context_); { + CGContextTranslateCTM(context_, rect.origin.x, rect.origin.y); + + if (kCFCoreFoundationVersionNumber > 700) + [view_ _drawRect:draw context:context_ lockFocus:YES]; + else { + WKView *view([view_ _viewRef]); + WKViewLockFocus$(view); { + WKViewDisplayRect$(view, draw); + } WKViewUnlockFocus$(view); + } + } CGContextRestoreGState(context_); +} + - (WebView *) _webView { return view_; } @@ -222,17 +253,7 @@ static WBMarkup *SharedMarkup_; [[view_ mainFrame] forceLayoutAdjustingViewSize:YES]; - [text_ setScrollXOffset:origin_.x scrollYOffset:origin_.y]; - - WKView *view([view_ _viewRef]); - - CGContextSaveGState(context_); { - CGContextTranslateCTM(context_, rect.origin.x, rect.origin.y); - - WKViewLockFocus(view); { - WKViewDisplayRect(view, CGRectMake(0, 0, rect.origin.x, rect.origin.y)); - } WKViewUnlockFocus(view); - } CGContextRestoreGState(context_); + [self drawRect:rect]; } - (void) drawString:(NSString *)string atPoint:(CGPoint)point withStyle:(NSString *)style { @@ -254,17 +275,7 @@ static WBMarkup *SharedMarkup_; [self _setupWithStyle:style width:CGRectGetWidth(rect) height:CGRectGetHeight(rect)]; [frame forceLayoutAdjustingViewSize:YES]; - [text_ setScrollXOffset:origin_.x scrollYOffset:origin_.y]; - - WKView *view([view_ _viewRef]); - - CGContextSaveGState(context_); { - CGContextTranslateCTM(context_, rect.origin.x, rect.origin.y); - - WKViewLockFocus(view); { - WKViewDisplayRect(view, CGRectMake(0, 0, rect.size.width, rect.size.height)); - } WKViewUnlockFocus(view); - } CGContextRestoreGState(context_); + [self drawRect:rect]; } @end