зеркало из https://github.com/github/Rebel.git
added RBLHTMLView
This commit is contained in:
Родитель
e4a5fd8e80
Коммит
c49de21bc1
|
@ -16,6 +16,9 @@
|
|||
306A81E81601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 306A81E61601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
306A81E91601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 306A81E71601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.m */; };
|
||||
306A81EB1601EAE700BF45F3 /* CAAnimation+RBLBlockAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 306A81EA1601EAE700BF45F3 /* CAAnimation+RBLBlockAdditionsSpec.m */; };
|
||||
88347E6A16F213C500872A0A /* RBLHTMLView.h in Headers */ = {isa = PBXBuildFile; fileRef = 88347E6816F213C500872A0A /* RBLHTMLView.h */; };
|
||||
88347E6B16F213C500872A0A /* RBLHTMLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88347E6916F213C500872A0A /* RBLHTMLView.m */; };
|
||||
88347E7316F2145900872A0A /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88347E7216F2145900872A0A /* WebKit.framework */; };
|
||||
AB10DB4D166EA9CA00AB7AB1 /* RBLScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = AB10DB4B166EA9CA00AB7AB1 /* RBLScrollView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
AB10DB4E166EA9CA00AB7AB1 /* RBLScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = AB10DB4C166EA9CA00AB7AB1 /* RBLScrollView.m */; };
|
||||
AB10DB53166EADD000AB7AB1 /* RBLScrollViewSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = AB10DB52166EADD000AB7AB1 /* RBLScrollViewSpec.m */; };
|
||||
|
@ -154,6 +157,9 @@
|
|||
306A81E71601E92000BF45F3 /* CAAnimation+RBLBlockAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CAAnimation+RBLBlockAdditions.m"; sourceTree = "<group>"; };
|
||||
306A81EA1601EAE700BF45F3 /* CAAnimation+RBLBlockAdditionsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CAAnimation+RBLBlockAdditionsSpec.m"; sourceTree = "<group>"; };
|
||||
306A81EC1601F44200BF45F3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
||||
88347E6816F213C500872A0A /* RBLHTMLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBLHTMLView.h; sourceTree = "<group>"; };
|
||||
88347E6916F213C500872A0A /* RBLHTMLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBLHTMLView.m; sourceTree = "<group>"; };
|
||||
88347E7216F2145900872A0A /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
|
||||
AB10DB4B166EA9CA00AB7AB1 /* RBLScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBLScrollView.h; sourceTree = "<group>"; };
|
||||
AB10DB4C166EA9CA00AB7AB1 /* RBLScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBLScrollView.m; sourceTree = "<group>"; };
|
||||
AB10DB52166EADD000AB7AB1 /* RBLScrollViewSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBLScrollViewSpec.m; sourceTree = "<group>"; };
|
||||
|
@ -232,6 +238,7 @@
|
|||
files = (
|
||||
D0E91C5B1603CDC300D23E93 /* QuartzCore.framework in Frameworks */,
|
||||
D09AE4E315C5F45200ECAD10 /* Cocoa.framework in Frameworks */,
|
||||
88347E7316F2145900872A0A /* WebKit.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -301,6 +308,8 @@
|
|||
AB10DB4C166EA9CA00AB7AB1 /* RBLScrollView.m */,
|
||||
303DEF4216D2B88700BD65C4 /* RBLShadowedTextFieldCell.h */,
|
||||
303DEF4316D2B88700BD65C4 /* RBLShadowedTextFieldCell.m */,
|
||||
88347E6816F213C500872A0A /* RBLHTMLView.h */,
|
||||
88347E6916F213C500872A0A /* RBLHTMLView.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
|
@ -439,6 +448,7 @@
|
|||
D09AE4E215C5F45200ECAD10 /* Cocoa.framework */,
|
||||
D09AE4F815C5F45300ECAD10 /* SenTestingKit.framework */,
|
||||
D0E91C5A1603CDC300D23E93 /* QuartzCore.framework */,
|
||||
88347E7216F2145900872A0A /* WebKit.framework */,
|
||||
D09AE4E415C5F45200ECAD10 /* Other Frameworks */,
|
||||
);
|
||||
name = Frameworks;
|
||||
|
@ -521,6 +531,7 @@
|
|||
303DEF4416D2B88700BD65C4 /* RBLShadowedTextFieldCell.h in Headers */,
|
||||
D088BEF916747D8F004B2665 /* NSFont+RBLFallbackAdditions.h in Headers */,
|
||||
D03D67181677E13F0041DDF2 /* NSAttributedString+RBLHTMLAdditions.h in Headers */,
|
||||
88347E6A16F213C500872A0A /* RBLHTMLView.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -721,6 +732,7 @@
|
|||
D088BEFA16747D8F004B2665 /* NSFont+RBLFallbackAdditions.m in Sources */,
|
||||
D03D67191677E13F0041DDF2 /* NSAttributedString+RBLHTMLAdditions.m in Sources */,
|
||||
303DEF4516D2B88700BD65C4 /* RBLShadowedTextFieldCell.m in Sources */,
|
||||
88347E6B16F213C500872A0A /* RBLHTMLView.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// RBLHTMLView.h
|
||||
// Rebel
|
||||
//
|
||||
// Created by Josh Abernathy on 3/13/13.
|
||||
// Copyright (c) 2013 GitHub. All rights reserved.
|
||||
//
|
||||
|
||||
#import <WebKit/WebKit.h>
|
||||
|
||||
// A view for displaying HTML-styled text.
|
||||
@interface RBLHTMLView : WebView
|
||||
|
||||
// The CSS to use to style the HTML.
|
||||
//
|
||||
// Reasonable defaults are used when this is not set.
|
||||
@property (nonatomic, copy) NSString *CSS;
|
||||
|
||||
// The HTML to display.
|
||||
@property (nonatomic, copy) NSString *HTML;
|
||||
|
||||
@end
|
|
@ -0,0 +1,105 @@
|
|||
//
|
||||
// RBLHTMLView.m
|
||||
// Rebel
|
||||
//
|
||||
// Created by Josh Abernathy on 3/13/13.
|
||||
// Copyright (c) 2013 GitHub. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RBLHTMLView.h"
|
||||
|
||||
@implementation RBLHTMLView
|
||||
|
||||
#pragma mark Lifecycle
|
||||
|
||||
static void CommonInit(RBLHTMLView *self) {
|
||||
self.drawsBackground = NO;
|
||||
self.maintainsBackForwardList = NO;
|
||||
self.mainFrame.frameView.allowsScrolling = NO;
|
||||
self.policyDelegate = self;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect {
|
||||
self = [super initWithFrame:frameRect];
|
||||
if (self == nil) return nil;
|
||||
|
||||
CommonInit(self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)decoder {
|
||||
self = [super initWithCoder:decoder];
|
||||
if (self == nil) return nil;
|
||||
|
||||
CommonInit(self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark WebPolicyDelegate
|
||||
|
||||
- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
|
||||
// WebNavigationTypeOther is when we do our HTML string load. Otherwise, we
|
||||
// shunt it off to a Real Browser®.
|
||||
if ([actionInformation[WebActionNavigationTypeKey] integerValue] == WebNavigationTypeOther) {
|
||||
[listener use];
|
||||
} else {
|
||||
[listener ignore];
|
||||
[NSWorkspace.sharedWorkspace openURL:request.URL];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark HTML
|
||||
|
||||
- (void)setHTML:(NSString *)HTML {
|
||||
if (_HTML == HTML) return;
|
||||
|
||||
_HTML = [HTML copy];
|
||||
|
||||
[self reloadConstructedContent];
|
||||
}
|
||||
|
||||
- (void)setCSS:(NSString *)CSS {
|
||||
if (_CSS == CSS) return;
|
||||
|
||||
_CSS = [CSS copy];
|
||||
|
||||
[self reloadConstructedContent];
|
||||
}
|
||||
|
||||
- (void)reloadConstructedContent {
|
||||
if (self.HTML == nil) return;
|
||||
|
||||
static NSString * const template = @""
|
||||
"<style type='text/css'> "
|
||||
" body { "
|
||||
" font: 11px Lucida Grande, sans-serif; "
|
||||
" color: #262626; "
|
||||
" line-height: 16px; "
|
||||
" vertical-align: baseline; "
|
||||
" margin: 0px 0px 0px 0px; "
|
||||
" } "
|
||||
" a { "
|
||||
" text-decoration: none; "
|
||||
" color: #06C; "
|
||||
" } "
|
||||
" a:visited { "
|
||||
" text-decoration: none; "
|
||||
" color: #06C; "
|
||||
" } "
|
||||
" .error { "
|
||||
" color: #911; "
|
||||
" } "
|
||||
"%@"
|
||||
"</style> "
|
||||
"<body>%@</body> ";
|
||||
|
||||
NSString *constructedHTML = [NSString stringWithFormat:template, self.CSS, self.HTML];
|
||||
[self.mainFrame loadHTMLString:constructedHTML baseURL:nil];
|
||||
while (self.isLoading) {
|
||||
[NSRunLoop.currentRunLoop runUntilDate:[NSDate date]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Загрузка…
Ссылка в новой задаче