WebDefaultUIDelegate.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #import <Cocoa/Cocoa.h>
  29. #import <Foundation/NSURLRequest.h>
  30. #import <WebKit/WebDefaultUIDelegate.h>
  31. #import <WebKit/WebJavaScriptTextInputPanel.h>
  32. #import <WebKit/WebView.h>
  33. #import <WebKit/WebUIDelegatePrivate.h>
  34. #import <WebKit/DOM.h>
  35. #import "WebTypesInternal.h"
  36. @interface NSApplication (DeclarationStolenFromAppKit)
  37. - (void)_cycleWindowsReversed:(BOOL)reversed;
  38. @end
  39. @implementation WebDefaultUIDelegate
  40. static WebDefaultUIDelegate *sharedDelegate = nil;
  41. // Return a object with vanilla implementations of the protocol's methods
  42. // Note this feature relies on our default delegate being stateless. This
  43. // is probably an invalid assumption for the WebUIDelegate.
  44. // If we add any real functionality to this default delegate we probably
  45. // won't be able to use a singleton.
  46. + (WebDefaultUIDelegate *)sharedUIDelegate
  47. {
  48. if (!sharedDelegate) {
  49. sharedDelegate = [[WebDefaultUIDelegate alloc] init];
  50. }
  51. return sharedDelegate;
  52. }
  53. - (WebView *)webView: (WebView *)wv createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features
  54. {
  55. // If the new API method doesn't exist, fallback to the old version of createWebViewWithRequest
  56. // for backwards compatability
  57. if (![[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)] && [[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:)])
  58. return [[wv UIDelegate] webView:wv createWebViewWithRequest:request];
  59. return nil;
  60. }
  61. - (void)webViewShow: (WebView *)wv
  62. {
  63. }
  64. - (void)webViewClose: (WebView *)wv
  65. {
  66. [[wv window] close];
  67. }
  68. - (void)webViewFocus: (WebView *)wv
  69. {
  70. [[wv window] makeKeyAndOrderFront:wv];
  71. }
  72. - (void)webViewUnfocus: (WebView *)wv
  73. {
  74. if ([[wv window] isKeyWindow] || [[[wv window] attachedSheet] isKeyWindow]) {
  75. [NSApp _cycleWindowsReversed:FALSE];
  76. }
  77. }
  78. - (NSResponder *)webViewFirstResponder: (WebView *)wv
  79. {
  80. return [[wv window] firstResponder];
  81. }
  82. - (void)webView: (WebView *)wv makeFirstResponder:(NSResponder *)responder
  83. {
  84. [[wv window] makeFirstResponder:responder];
  85. }
  86. - (void)webView: (WebView *)wv setStatusText:(NSString *)text
  87. {
  88. }
  89. - (NSString *)webViewStatusText: (WebView *)wv
  90. {
  91. return nil;
  92. }
  93. - (void)webView: (WebView *)wv mouseDidMoveOverElement:(NSDictionary *)elementInformation modifierFlags:(NSUInteger)modifierFlags
  94. {
  95. }
  96. - (BOOL)webViewAreToolbarsVisible: (WebView *)wv
  97. {
  98. return NO;
  99. }
  100. - (void)webView: (WebView *)wv setToolbarsVisible:(BOOL)visible
  101. {
  102. }
  103. - (BOOL)webViewIsStatusBarVisible: (WebView *)wv
  104. {
  105. return NO;
  106. }
  107. - (void)webView: (WebView *)wv setStatusBarVisible:(BOOL)visible
  108. {
  109. }
  110. - (BOOL)webViewIsResizable: (WebView *)wv
  111. {
  112. return [[wv window] showsResizeIndicator];
  113. }
  114. - (void)webView: (WebView *)wv setResizable:(BOOL)resizable
  115. {
  116. // FIXME: This doesn't actually change the resizability of the window,
  117. // only visibility of the indicator.
  118. [[wv window] setShowsResizeIndicator:resizable];
  119. }
  120. - (void)webView: (WebView *)wv setFrame:(NSRect)frame
  121. {
  122. [[wv window] setFrame:frame display:YES];
  123. }
  124. - (NSRect)webViewFrame: (WebView *)wv
  125. {
  126. NSWindow *window = [wv window];
  127. return window == nil ? NSZeroRect : [window frame];
  128. }
  129. - (void)webView: (WebView *)wv runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
  130. {
  131. // FIXME: We want a default here, but that would add localized strings.
  132. }
  133. - (BOOL)webView: (WebView *)wv runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
  134. {
  135. // FIXME: We want a default here, but that would add localized strings.
  136. return NO;
  137. }
  138. - (NSString *)webView: (WebView *)wv runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
  139. {
  140. WebJavaScriptTextInputPanel *panel = [[WebJavaScriptTextInputPanel alloc] initWithPrompt:prompt text:defaultText];
  141. [panel showWindow:nil];
  142. NSString *result;
  143. if ([NSApp runModalForWindow:[panel window]]) {
  144. result = [panel text];
  145. } else {
  146. result = nil;
  147. }
  148. [[panel window] close];
  149. [panel release];
  150. return result;
  151. }
  152. - (void)webView: (WebView *)wv runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener
  153. {
  154. // FIXME: We want a default here, but that would add localized strings.
  155. }
  156. - (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView
  157. {
  158. }
  159. - (BOOL)webView:(WebView *)webView shouldBeginDragForElement:(NSDictionary *)element dragImage:(NSImage *)dragImage mouseDownEvent:(NSEvent *)mouseDownEvent mouseDraggedEvent:(NSEvent *)mouseDraggedEvent
  160. {
  161. return YES;
  162. }
  163. - (NSUInteger)webView:(WebView *)webView dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
  164. {
  165. return WebDragDestinationActionAny;
  166. }
  167. - (void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo
  168. {
  169. }
  170. - (NSUInteger)webView:(WebView *)webView dragSourceActionMaskForPoint:(NSPoint)point
  171. {
  172. return WebDragSourceActionAny;
  173. }
  174. - (void)webView:(WebView *)webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:(NSPoint)point withPasteboard:(NSPasteboard *)pasteboard
  175. {
  176. }
  177. - (void)webView:(WebView *)sender didDrawRect:(NSRect)rect
  178. {
  179. }
  180. - (void)webView:(WebView *)sender didScrollDocumentInFrameView:(WebFrameView *)frameView
  181. {
  182. }
  183. - (void)webView:(WebView *)sender willPopupMenu:(NSMenu *)menu
  184. {
  185. }
  186. - (void)webView:(WebView *)sender contextMenuItemSelected:(NSMenuItem *)item forElement:(NSDictionary *)element
  187. {
  188. }
  189. - (void)webView:(WebView *)sender exceededApplicationCacheOriginQuotaForSecurityOrigin:(WebSecurityOrigin *)origin totalSpaceNeeded:(NSUInteger)totalSpaceNeeded
  190. {
  191. }
  192. - (BOOL)webView:(WebView *)sender shouldReplaceUploadFile:(NSString *)path usingGeneratedFilename:(NSString **)filename
  193. {
  194. return NO;
  195. }
  196. - (NSString *)webView:(WebView *)sender generateReplacementFile:(NSString *)path
  197. {
  198. return nil;
  199. }
  200. @end