2 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #import <Cocoa/Cocoa.h>
30 #import <Foundation/NSURLRequest.h>
32 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
33 #define WebNSUInteger unsigned int
35 #define WebNSUInteger NSUInteger
40 @discussion Each menu item in the default menu items array passed in
41 contextMenuItemsForElement:defaultMenuItems: has its tag set to one of the WebMenuItemTags.
42 When iterating through the default menu items array, use the tag to differentiate between them.
46 WebMenuItemTagOpenLinkInNewWindow=1,
47 WebMenuItemTagDownloadLinkToDisk,
48 WebMenuItemTagCopyLinkToClipboard,
49 WebMenuItemTagOpenImageInNewWindow,
50 WebMenuItemTagDownloadImageToDisk,
51 WebMenuItemTagCopyImageToClipboard,
52 WebMenuItemTagOpenFrameInNewWindow,
55 WebMenuItemTagGoForward,
60 WebMenuItemTagSpellingGuess,
61 WebMenuItemTagNoGuessesFound,
62 WebMenuItemTagIgnoreSpelling,
63 WebMenuItemTagLearnSpelling,
65 WebMenuItemTagSearchInSpotlight,
66 WebMenuItemTagSearchWeb,
67 WebMenuItemTagLookUpInDictionary,
68 WebMenuItemTagOpenWithDefaultApplication,
69 WebMenuItemPDFActualSize,
71 WebMenuItemPDFZoomOut,
72 WebMenuItemPDFAutoSize,
73 WebMenuItemPDFSinglePage,
74 WebMenuItemPDFFacingPages,
75 WebMenuItemPDFContinuous,
76 WebMenuItemPDFNextPage,
77 WebMenuItemPDFPreviousPage,
81 @enum WebDragDestinationAction
82 @abstract Actions that the destination of a drag can perform.
83 @constant WebDragDestinationActionNone No action
84 @constant WebDragDestinationActionDHTML Allows DHTML (such as JavaScript) to handle the drag
85 @constant WebDragDestinationActionEdit Allows editable documents to be edited from the drag
86 @constant WebDragDestinationActionLoad Allows a location change from the drag
87 @constant WebDragDestinationActionAny Allows any of the above to occur
90 WebDragDestinationActionNone = 0,
91 WebDragDestinationActionDHTML = 1,
92 WebDragDestinationActionEdit = 2,
93 WebDragDestinationActionLoad = 4,
94 WebDragDestinationActionAny = UINT_MAX
95 } WebDragDestinationAction;
98 @enum WebDragSourceAction
99 @abstract Actions that the source of a drag can perform.
100 @constant WebDragSourceActionNone No action
101 @constant WebDragSourceActionDHTML Allows DHTML (such as JavaScript) to start a drag
102 @constant WebDragSourceActionImage Allows an image drag to occur
103 @constant WebDragSourceActionLink Allows a link drag to occur
104 @constant WebDragSourceActionSelection Allows a selection drag to occur
105 @constant WebDragSourceActionAny Allows any of the above to occur
108 WebDragSourceActionNone = 0,
109 WebDragSourceActionDHTML = 1,
110 WebDragSourceActionImage = 2,
111 WebDragSourceActionLink = 4,
112 WebDragSourceActionSelection = 8,
113 WebDragSourceActionAny = UINT_MAX
114 } WebDragSourceAction;
117 @protocol WebOpenPanelResultListener
118 @discussion This protocol is used to call back with the results of
119 the file open panel requested by runOpenPanelForFileButtonWithResultListener:
121 @protocol WebOpenPanelResultListener <NSObject>
124 @method chooseFilename:
125 @abstract Call this method to return a filename from the file open panel.
128 - (void)chooseFilename:(NSString *)fileName;
132 @abstract Call this method to indicate that the file open panel was cancelled.
141 @category WebUIDelegate
142 @discussion A class that implements WebUIDelegate provides
143 window-related methods that may be used by Javascript, plugins and
144 other aspects of web pages. These methods are used to open new
145 windows and control aspects of existing windows.
147 @interface NSObject (WebUIDelegate)
150 @method webView:createWebViewWithRequest:
151 @abstract Create a new window and begin to load the specified request.
152 @discussion The newly created window is hidden, and the window operations delegate on the
153 new WebViews will get a webViewShow: call.
154 @param sender The WebView sending the delegate method.
155 @param request The request to load.
156 @result The WebView for the new window.
158 - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request;
162 @param sender The WebView sending the delegate method.
163 @abstract Show the window that contains the top level view of the WebView,
164 ordering it frontmost.
165 @discussion This will only be called just after createWindowWithRequest:
166 is used to create a new window.
168 - (void)webViewShow:(WebView *)sender;
171 @method webView:createWebViewModalDialogWithRequest:
172 @abstract Create a new window and begin to load the specified request.
173 @discussion The newly created window is hidden, and the window operations delegate on the
174 new WebViews will get a webViewShow: call.
175 @param sender The WebView sending the delegate method.
176 @param request The request to load.
177 @result The WebView for the new window.
179 - (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request;
182 @method webViewRunModal:
183 @param sender The WebView sending the delegate method.
184 @abstract Show the window that contains the top level view of the WebView,
185 ordering it frontmost. The window should be run modal in the application.
186 @discussion This will only be called just after createWebViewModalDialogWithRequest:
187 is used to create a new window.
189 - (void)webViewRunModal:(WebView *)sender;
192 @method webViewClose:
193 @abstract Close the current window.
194 @param sender The WebView sending the delegate method.
195 @discussion Clients showing multiple views in one window may
196 choose to close only the one corresponding to this
197 WebView. Other clients may choose to ignore this method
200 - (void)webViewClose:(WebView *)sender;
203 @method webViewFocus:
204 @abstract Focus the current window (i.e. makeKeyAndOrderFront:).
205 @param The WebView sending the delegate method.
206 @discussion Clients showing multiple views in one window may want to
207 also do something to focus the one corresponding to this WebView.
209 - (void)webViewFocus:(WebView *)sender;
212 @method webViewUnfocus:
213 @abstract Unfocus the current window.
214 @param sender The WebView sending the delegate method.
215 @discussion Clients showing multiple views in one window may want to
216 also do something to unfocus the one corresponding to this WebView.
218 - (void)webViewUnfocus:(WebView *)sender;
221 @method webViewFirstResponder:
222 @abstract Get the first responder for this window.
223 @param sender The WebView sending the delegate method.
224 @discussion This method should return the focused control in the
225 WebView's view, if any. If the view is out of the window
226 hierarchy, this might return something than calling firstResponder
227 on the real NSWindow would. It's OK to return either nil or the
228 real first responder if some control not in the window has focus.
230 - (NSResponder *)webViewFirstResponder:(WebView *)sender;
233 @method webView:makeFirstResponder:
234 @abstract Set the first responder for this window.
235 @param sender The WebView sending the delegate method.
236 @param responder The responder to make first (will always be a view)
237 @discussion responder will always be a view that is in the view
238 subhierarchy of the top-level web view for this WebView. If the
239 WebView's top level view is currently out of the view
240 hierarchy, it may be desirable to save the first responder
241 elsewhere, or possibly ignore this call.
243 - (void)webView:(WebView *)sender makeFirstResponder:(NSResponder *)responder;
246 @method webView:setStatusText:
247 @abstract Set the window's status display, if any, to the specified string.
248 @param sender The WebView sending the delegate method.
249 @param text The status text to set
251 - (void)webView:(WebView *)sender setStatusText:(NSString *)text;
254 @method webViewStatusText:
255 @abstract Get the currently displayed status text.
256 @param sender The WebView sending the delegate method.
257 @result The status text
259 - (NSString *)webViewStatusText:(WebView *)sender;
262 @method webViewAreToolbarsVisible:
263 @abstract Determine whether the window's toolbars are currently visible
264 @param sender The WebView sending the delegate method.
265 @discussion This method should return YES if the window has any
266 toolbars that are currently on, besides the status bar. If the app
267 has more than one toolbar per window, for example a regular
268 command toolbar and a favorites bar, it should return YES from
269 this method if at least one is on.
270 @result YES if at least one toolbar is visible, otherwise NO.
272 - (BOOL)webViewAreToolbarsVisible:(WebView *)sender;
275 @method webView:setToolbarsVisible:
276 @param sender The WebView sending the delegate method.
277 @abstract Set whether the window's toolbars are currently visible.
278 @param visible New value for toolbar visibility
279 @discussion Setting this to YES should turn on all toolbars
280 (except for a possible status bar). Setting it to NO should turn
281 off all toolbars (with the same exception).
283 - (void)webView:(WebView *)sender setToolbarsVisible:(BOOL)visible;
286 @method webViewIsStatusBarVisible:
287 @abstract Determine whether the status bar is visible.
288 @param sender The WebView sending the delegate method.
289 @result YES if the status bar is visible, otherwise NO.
291 - (BOOL)webViewIsStatusBarVisible:(WebView *)sender;
294 @method webView:setStatusBarVisible:
295 @abstract Set whether the status bar is currently visible.
296 @param visible The new visibility value
297 @discussion Setting this to YES should show the status bar,
298 setting it to NO should hide it.
300 - (void)webView:(WebView *)sender setStatusBarVisible:(BOOL)visible;
303 @method webViewIsResizable:
304 @abstract Determine whether the window is resizable or not.
305 @param sender The WebView sending the delegate method.
306 @result YES if resizable, NO if not.
307 @discussion If there are multiple views in the same window, they
308 have have their own separate resize controls and this may need to
309 be handled specially.
311 - (BOOL)webViewIsResizable:(WebView *)sender;
314 @method webView:setResizable:
315 @abstract Set the window to resizable or not
316 @param sender The WebView sending the delegate method.
317 @param resizable YES if the window should be made resizable, NO if not.
318 @discussion If there are multiple views in the same window, they
319 have have their own separate resize controls and this may need to
320 be handled specially.
322 - (void)webView:(WebView *)sender setResizable:(BOOL)resizable;
325 @method webView:setFrame:
326 @abstract Set the window's frame rect
327 @param sender The WebView sending the delegate method.
328 @param frame The new window frame size
329 @discussion Even though a caller could set the frame directly using the NSWindow,
330 this method is provided so implementors of this protocol can do special
331 things on programmatic move/resize, like avoiding autosaving of the size.
333 - (void)webView:(WebView *)sender setFrame:(NSRect)frame;
336 @method webViewFrame:
337 @param sender The WebView sending the delegate method.
338 @abstract REturn the window's frame rect
341 - (NSRect)webViewFrame:(WebView *)sender;
344 @method webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:
345 @abstract Display a JavaScript alert panel.
346 @param sender The WebView sending the delegate method.
347 @param message The message to display.
348 @param frame The WebFrame whose JavaScript initiated this call.
349 @discussion Clients should visually indicate that this panel comes
350 from JavaScript initiated by the specified frame. The panel should have
353 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
356 @method webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:
357 @abstract Display a JavaScript confirm panel.
358 @param sender The WebView sending the delegate method.
359 @param message The message to display.
360 @param frame The WebFrame whose JavaScript initiated this call.
361 @result YES if the user hit OK, NO if the user chose Cancel.
362 @discussion Clients should visually indicate that this panel comes
363 from JavaScript initiated by the specified frame. The panel should have
364 two buttons, e.g. "OK" and "Cancel".
366 - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
369 @method webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:
370 @abstract Display a JavaScript text input panel.
371 @param sender The WebView sending the delegate method.
372 @param message The message to display.
373 @param defaultText The initial text for the text entry area.
374 @param frame The WebFrame whose JavaScript initiated this call.
375 @result The typed text if the user hit OK, otherwise nil.
376 @discussion Clients should visually indicate that this panel comes
377 from JavaScript initiated by the specified frame. The panel should have
378 two buttons, e.g. "OK" and "Cancel", and an area to type text.
380 - (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame;
383 @method webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:
384 @abstract Display a confirm panel by an "before unload" event handler.
385 @param sender The WebView sending the delegate method.
386 @param message The message to display.
387 @param frame The WebFrame whose JavaScript initiated this call.
388 @result YES if the user hit OK, NO if the user chose Cancel.
389 @discussion Clients should include a message in addition to the one
390 supplied by the web page that indicates. The panel should have
391 two buttons, e.g. "OK" and "Cancel".
393 - (BOOL)webView:(WebView *)sender runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame;
396 @method webView:runOpenPanelForFileButtonWithResultListener:
397 @abstract Display a file open panel for a file input control.
398 @param sender The WebView sending the delegate method.
399 @param resultListener The object to call back with the results.
400 @discussion This method is passed a callback object instead of giving a return
401 value so that it can be handled with a sheet.
403 - (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener;
406 @method webView:mouseDidMoveOverElement:modifierFlags:
407 @abstract Update the window's feedback for mousing over links to reflect a new item the mouse is over
408 or new modifier flags.
409 @param sender The WebView sending the delegate method.
410 @param elementInformation Dictionary that describes the element that the mouse is over, or nil.
411 @param modifierFlags The modifier flags as in NSEvent.
413 - (void)webView:(WebView *)sender mouseDidMoveOverElement:(NSDictionary *)elementInformation modifierFlags:(WebNSUInteger)modifierFlags;
416 @method webView:contextMenuItemsForElement:defaultMenuItems:
417 @abstract Returns the menu items to display in an element's contextual menu.
418 @param sender The WebView sending the delegate method.
419 @param element A dictionary representation of the clicked element.
420 @param defaultMenuItems An array of default NSMenuItems to include in all contextual menus.
421 @result An array of NSMenuItems to include in the contextual menu.
423 - (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems;
426 @method webView:validateUserInterfaceItem:defaultValidation:
427 @abstract Controls UI validation
428 @param webView The WebView sending the delegate method
429 @param item The user interface item being validated
430 @pararm defaultValidation Whether or not the WebView thinks the item is valid
431 @discussion This method allows the UI delegate to control WebView's validation of user interface items.
432 See WebView.h to see the methods to that WebView can currently validate. See NSUserInterfaceValidations and
433 NSValidatedUserInterfaceItem for information about UI validation.
435 - (BOOL)webView:(WebView *)webView validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item defaultValidation:(BOOL)defaultValidation;
438 @method webView:shouldPerformAction:fromSender:
439 @abstract Controls actions
440 @param webView The WebView sending the delegate method
441 @param action The action being sent
442 @param sender The sender of the action
443 @discussion This method allows the UI delegate to control WebView's behavior when an action is being sent.
444 For example, if the action is copy:, the delegate can return YES to allow WebView to perform its default
445 copy behavior or return NO and perform copy: in some other way. See WebView.h to see the actions that
448 - (BOOL)webView:(WebView *)webView shouldPerformAction:(SEL)action fromSender:(id)sender;
451 @method webView:dragDestinationActionMaskForDraggingInfo:
452 @abstract Controls behavior when dragging to a WebView
453 @param webView The WebView sending the delegate method
454 @param draggingInfo The dragging info of the drag
455 @discussion This method is called periodically as something is dragged over a WebView. The UI delegate can return a mask
456 indicating which drag destination actions can occur, WebDragDestinationActionAny to allow any kind of action or
457 WebDragDestinationActionNone to not accept the drag.
459 - (unsigned)webView:(WebView *)webView dragDestinationActionMaskForDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
462 @method webView:willPerformDragDestinationAction:forDraggingInfo:
463 @abstract Informs that WebView will perform a drag destination action
464 @param webView The WebView sending the delegate method
465 @param action The drag destination action
466 @param draggingInfo The dragging info of the drag
467 @discussion This method is called after the last call to webView:dragDestinationActionMaskForDraggingInfo: after something is dropped on a WebView.
468 This method informs the UI delegate of the drag destination action that WebView will perform.
470 - (void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
473 @method webView:dragSourceActionMaskForPoint:
474 @abstract Controls behavior when dragging from a WebView
475 @param webView The WebView sending the delegate method
476 @param point The point where the drag started in the coordinates of the WebView
477 @discussion This method is called after the user has begun a drag from a WebView. The UI delegate can return a mask indicating
478 which drag source actions can occur, WebDragSourceActionAny to allow any kind of action or WebDragSourceActionNone to not begin a drag.
480 - (unsigned)webView:(WebView *)webView dragSourceActionMaskForPoint:(NSPoint)point;
483 @method webView:willPerformDragSourceAction:fromPoint:withPasteboard:
484 @abstract Informs that a drag a has begun from a WebView
485 @param webView The WebView sending the delegate method
486 @param action The drag source action
487 @param point The point where the drag started in the coordinates of the WebView
488 @param pasteboard The drag pasteboard
489 @discussion This method is called after webView:dragSourceActionMaskForPoint: is called after the user has begun a drag from a WebView.
490 This method informs the UI delegate of the drag source action that will be performed and gives the delegate an opportunity to modify
491 the contents of the dragging pasteboard.
493 - (void)webView:(WebView *)webView willPerformDragSourceAction:(WebDragSourceAction)action fromPoint:(NSPoint)point withPasteboard:(NSPasteboard *)pasteboard;
496 @method webView:printFrameView:
497 @abstract Informs that a WebFrameView needs to be printed
498 @param webView The WebView sending the delegate method
499 @param frameView The WebFrameView needing to be printed
500 @discussion This method is called when a script or user requests the page to be printed.
501 In this method the delegate can prepare the WebFrameView to be printed. Some content that WebKit
502 displays can be printed directly by the WebFrameView, other content will need to be handled by
503 the delegate. To determine if the WebFrameView can handle printing the delegate should check
504 WebFrameView's documentViewShouldHandlePrint, if YES then the delegate can call printDocumentView
505 on the WebFrameView. Otherwise the delegate will need to request a NSPrintOperation from
506 the WebFrameView's printOperationWithPrintInfo to handle the printing.
508 - (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView;
511 @method webViewHeaderHeight:
512 @param webView The WebView sending the delegate method
513 @abstract Reserve a height for the printed page header.
514 @result The height to reserve for the printed page header, return 0.0 to not reserve any space for a header.
515 @discussion The height returned will be used to calculate the rect passed to webView:drawHeaderInRect:.
517 - (float)webViewHeaderHeight:(WebView *)sender;
520 @method webViewFooterHeight:
521 @param webView The WebView sending the delegate method
522 @abstract Reserve a height for the printed page footer.
523 @result The height to reserve for the printed page footer, return 0.0 to not reserve any space for a footer.
524 @discussion The height returned will be used to calculate the rect passed to webView:drawFooterInRect:.
526 - (float)webViewFooterHeight:(WebView *)sender;
529 @method webView:drawHeaderInRect:
530 @param webView The WebView sending the delegate method
531 @param rect The NSRect reserved for the header of the page
532 @abstract The delegate should draw a header for the sender in the supplied rect.
534 - (void)webView:(WebView *)sender drawHeaderInRect:(NSRect)rect;
537 @method webView:drawFooterInRect:
538 @param webView The WebView sending the delegate method
539 @param rect The NSRect reserved for the footer of the page
540 @abstract The delegate should draw a footer for the sender in the supplied rect.
542 - (void)webView:(WebView *)sender drawFooterInRect:(NSRect)rect;
544 // The following delegate methods are deprecated in favor of the ones above that specify
545 // the WebFrame whose JavaScript initiated this call.
546 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message;
547 - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message;
548 - (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText;
550 // The following delegate methods are deprecated. Content rect calculations are now done automatically.
551 - (void)webView:(WebView *)sender setContentRect:(NSRect)frame;
552 - (NSRect)webViewContentRect:(WebView *)sender;