[iPhone] Hack UIWebView〜コンパイル
SafariのレンダリングエンジンでHTMLを表示できるUIWebViewを試してみた.
Web上にあんまり情報がまとまっておらず,ちょっと苦労した.
・ソースコード
MyWebView.m
#import "MyWebView.h" @interface UIWebView (HackWebView) // for peeking msg to UIWebView - (BOOL) respondsToSelector:(SEL) selector; @end @implementation UIWebView (HackWebView) - (BOOL) respondsToSelector:(SEL) selector { NSLog(@"[UIWebView] respondsToSelector: %s", selector); return [super respondsToSelector:selector]; } @end @implementation MyWebView - (id) initWithFrame:(CGRect) frame { self = [super initWithFrame:frame]; // create WebView webView_ = [[[UIWebView alloc] initWithFrame:frame] autorelease]; [webView_ setDelegate:self]; [webView_ setTilingEnabled: YES]; [webView_ setTileSize: CGSizeMake(320,500)]; [webView_ setAutoresizes: YES]; [self addSubview:webView_]; // load html NSString *html = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"source" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil]; [webView_ loadHTMLString:html baseURL:nil]; return self; } - (void) view:(id)view didDrawInRect:(CGRect)rect duration:(float)duration { } - (void) view:(id)view didSetFrame:(CGRect)currentRect oldFrame:(CGRect)oldRect { [self setContentSize:currentRect.size]; } - (BOOL) respondsToSelector:(SEL) selector { NSLog(@"[MyWebView] respondsToSelector: %s", selector); return [super respondsToSelector:selector]; } @end
MyWebView.h
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import <UIKit/UIApplication.h> #import <UIKit/UIView-Geometry.h> #import <UIKit/UIView-Hierarchy.h> #import <UIKit/UIView-Internal.h> #import <UIKit/UIScroller.h> #import <UIKit/UIWebView.h> //#import <WebKit/WebView.h> //#import <WebKit/WebFrame.h> // if activate these lines, can't compile this..... I disgust a warning msg. #import <WebCore/DOMHTMLDocument.h> #import <WebCore/DOMHTMLElement-DOMHTMLElementExtensions.h> #import "global.h" @interface MyWebView : UIScroller { UIWebView *webView_; } @end
・コンパイルとヘッダファイル修正
実は,Erica氏のヘッダファイル等ではコンパイルできない.
そこで,修正をかける.修正は4つのファイルで,以下です.
> diff ./include/UIKit/UIWebView.h ./include.original/UIKit/UIWebView.h 9c9 < //#import "UIKeyboardInputProtocol.h" --- > #import "UIKeyboardInputProtocol.h" 11c11 < @class DOMHTMLElement, DOMNode, DOMNode/*<UIFormControl>*/, NSTimer, UIAutoscrollTimer, UIInformalDelegate, UITextLoupe, UITextTraits, UITextView, UIView, WebPDFView, WebView; --- > @class DOMHTMLElement, DOMNode, DOMNode<UIFormControl>, NSTimer, UIAutoscrollTimer, UIInformalDelegate, UITextLoupe, UITextTraits, UITextView, UIView, WebPDFView, WebView; 13c13 < @interface UIWebView : UITiledView/* <UIKeyboardInput>*/ --- > @interface UIWebView : UITiledView <UIKeyboardInput> 43c43 < DOMNode/*<UIFormControl>*/ *element; --- > DOMNode<UIFormControl> *element; diff ./include/WebCore/DOMHTMLDocument.h ./include.original/WebCore/DOMHTMLDocument.h 13c13 < //- // Error parsing type: 以下略 --- > - // Error parsing type: 以下略 diff ./include/WebCore/DOMObject.h ./include.original/WebCore/DOMObject.h 9c9 < //#import "NSCopyingProtocol.h" --- > #import "NSCopyingProtocol.h" diff ./include/WebCore/WebScriptObject.h ./include.original/WebCore/WebScriptObject.h 7c7 < //#import "NSObject.h" --- > #import "NSObject.h" </pre>
これで,自前でUIWebViewを作ることができますた.