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