Home | History | Annotate | Download | only in DefaultDelegates
      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 
     29 #import <Cocoa/Cocoa.h>
     30 
     31 #import <Foundation/NSURLRequest.h>
     32 
     33 #import <WebKit/WebDefaultUIDelegate.h>
     34 #import <WebKit/WebJavaScriptTextInputPanel.h>
     35 #import <WebKit/WebView.h>
     36 #import <WebKit/WebUIDelegatePrivate.h>
     37 #import <WebKit/DOM.h>
     38 #import "WebTypesInternal.h"
     39 
     40 @interface NSApplication (DeclarationStolenFromAppKit)
     41 - (void)_cycleWindowsReversed:(BOOL)reversed;
     42 @end
     43 
     44 @implementation WebDefaultUIDelegate
     45 
     46 static WebDefaultUIDelegate *sharedDelegate = nil;
     47 
     48 // Return a object with vanilla implementations of the protocol's methods
     49 // Note this feature relies on our default delegate being stateless.  This
     50 // is probably an invalid assumption for the WebUIDelegate.
     51 // If we add any real functionality to this default delegate we probably
     52 // won't be able to use a singleton.
     53 + (WebDefaultUIDelegate *)sharedUIDelegate
     54 {
     55     if (!sharedDelegate) {
     56         sharedDelegate = [[WebDefaultUIDelegate alloc] init];
     57     }
     58     return sharedDelegate;
     59 }
     60 
     61 - (WebView *)webView: (WebView *)wv createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features
     62 {
     63     // If the new API method doesn't exist, fallback to the old version of createWebViewWithRequest
     64     // for backwards compatability
     65     if (![[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)] && [[wv UIDelegate] respondsToSelector:@selector(webView:createWebViewWithRequest:)])
     66         return [[wv UIDelegate] webView:wv createWebViewWithRequest:request];
     67     return nil;
     68 }
     69 
     70 - (void)webViewShow: (WebView *)wv
     71 {
     72 }
     73 
     74 - (void)webViewClose: (WebView *)wv
     75 {
     76     [[wv window] close];
     77 }
     78 
     79 - (void)webViewFocus: (WebView *)wv
     80 {
     81     [[wv window] makeKeyAndOrderFront:wv];
     82 }
     83 
     84 - (void)webViewUnfocus: (WebView *)wv
     85 {
     86     if ([[wv window] isKeyWindow] || [[[wv window] attachedSheet] isKeyWindow]) {
     87         [NSApp _cycleWindowsReversed:FALSE];
     88     }
     89 }
     90 
     91 - (NSResponder *)webViewFirstResponder: (WebView *)wv
     92 {
     93     return [[wv window] firstResponder];
     94 }
     95 
     96 - (void)webView: (WebView *)wv makeFirstResponder:(NSResponder *)responder
     97 {
     98     [[wv window] makeFirstResponder:responder];
     99 }
    100 
    101 - (void)webView: (WebView *)wv setStatusText:(NSString *)text
    102 {
    103 }
    104 
    105 - (NSString *)webViewStatusText: (WebView *)wv
    106 {
    107     return nil;
    108 }
    109 
    110 - (void)webView: (WebView *)wv mouseDidMoveOverElement:(NSDictionary *)elementInformation modifierFlags:(NSUInteger)modifierFlags
    111 {
    112 }
    113 
    114 - (BOOL)webViewAreToolbarsVisible: (WebView *)wv
    115 {
    116     return NO;
    117 }
    118 
    119 - (void)webView: (WebView *)wv setToolbarsVisible:(BOOL)visible
    120 {
    121 }
    122 
    123 - (BOOL)webViewIsStatusBarVisible: (WebView *)wv
    124 {
    125     return NO;
    126 }
    127 
    128 - (void)webView: (WebView *)wv setStatusBarVisible:(BOOL)visible
    129 {
    130 }
    131 
    132 - (BOOL)webViewIsResizable: (WebView *)wv
    133 {
    134     return [[wv window] showsResizeIndicator];
    135 }
    136 
    137 - (void)webView: (WebView *)wv setResizable:(BOOL)resizable
    138 {
    139     // FIXME: This doesn't actually change the resizability of the window,
    140     // only visibility of the indicator.
    141     [[wv window] setShowsResizeIndicator:resizable];
    142 }
    143 
    144 - (void)webView: (WebView *)wv setFrame:(NSRect)frame
    145 {
    146     [[wv window] setFrame:frame display:YES];
    147 }
    148 
    149 - (NSRect)webViewFrame: (WebView *)wv
    150 {
    151     NSWindow *window = [wv window];
    152     return window == nil ? NSZeroRect : [window frame];
    153 }
    154 
    155 - (void)webView: (WebView *)wv runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
    156 {
    157     // FIXME: We want a default here, but that would add localized strings.
    158 }
    159 
    160 - (BOOL)webView: (WebView *)wv runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
    161 {
    162     // FIXME: We want a default here, but that would add localized strings.
    163     return NO;
    164 }
    165 
    166 - (NSString *)webView: (WebView *)wv runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
    167 {
    168     WebJavaScriptTextInputPanel *panel = [[WebJavaScriptTextInputPanel alloc] initWithPrompt:prompt text:defaultText];
    169     [panel showWindow:nil];
    170     NSString *result;
    171     if ([NSApp runModalForWindow:[panel window]]) {
    172         result = [panel text];
    173     } else {
    174         result = nil;
    175     }
    176     [[panel window] close];
    177     [panel release];
    178     return result;
    179 }
    180 
    181 - (void)webView: (WebView *)wv runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener
    182 {
    183     // FIXME: We want a default here, but that would add localized strings.
    184 }
    185 
    186 - (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView
    187 {
    188 }
    189 
    190 
    191 - (BOOL)webView:(WebView *)webView shouldBeginDragForElement:(NSDictionary *)element dragImage:(NSImage *)dragImage mouseDownEvent:(NSEvent *)mouseDownEvent mouseDraggedEvent:(NSEvent *)mouseDraggedEvent
    192 {
    193     return YES;
    194 }
    195 
    196 - (NSUInteger)webView:(WebView *)webView dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
    197 {
    198     return WebDragDestinationActionAny;
    199 }
    200 
    201 - (void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo
    202 {
    203 }
    204 
    205 - (NSUInteger)webView:(WebView *)webView dragSourceActionMaskForPoint:(NSPoint)point
    206 {
    207     return WebDragSourceActionAny;
    208 }
    209 
    210 - (void)webView:(WebView *)webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:(NSPoint)point withPasteboard:(NSPasteboard *)pasteboard
    211 {
    212 }
    213 
    214 - (void)webView:(WebView *)sender didDrawRect:(NSRect)rect
    215 {
    216 }
    217 
    218 - (void)webView:(WebView *)sender didScrollDocumentInFrameView:(WebFrameView *)frameView
    219 {
    220 }
    221 
    222 - (void)webView:(WebView *)sender willPopupMenu:(NSMenu *)menu
    223 {
    224 }
    225 
    226 - (void)webView:(WebView *)sender contextMenuItemSelected:(NSMenuItem *)item forElement:(NSDictionary *)element
    227 {
    228 }
    229 
    230 - (void)webView:(WebView *)sender exceededApplicationCacheOriginQuotaForSecurityOrigin:(WebSecurityOrigin *)origin
    231 {
    232 }
    233 
    234 - (BOOL)webView:(WebView *)sender shouldReplaceUploadFile:(NSString *)path usingGeneratedFilename:(NSString **)filename
    235 {
    236     return NO;
    237 }
    238 
    239 - (NSString *)webView:(WebView *)sender generateReplacementFile:(NSString *)path
    240 {
    241     return nil;
    242 }
    243 
    244 @end
    245