2 * Copyright (C) 2004 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #import <Foundation/Foundation.h>
27 #import <AppKit/NSDragging.h> // for NSDragOperation typedef
29 #import <WebCore/WebCoreKeyboardAccess.h>
31 #import <JavaScriptCore/npruntime.h>
32 #import <JavaVM/jni.h>
45 typedef khtml::RenderPart KHTMLRenderPart;
51 @class KHTMLRenderPart;
56 @class DOMCSSStyleDeclaration;
58 @class DOMDocumentFragment;
60 @class DOMHTMLElement;
63 @class WebCoreSettings;
64 @class WebScriptObject;
66 @protocol WebCoreDOMTreeCopier;
67 @protocol WebCoreRenderTreeCopier;
68 @protocol WebCoreResourceHandle;
69 @protocol WebCoreResourceLoader;
70 @protocol WebCoreFileButton;
71 @protocol WebCoreFileButtonDelegate;
73 extern NSString *WebCoreElementDOMNodeKey;
74 extern NSString *WebCoreElementFrameKey;
75 extern NSString *WebCoreElementImageAltStringKey;
76 extern NSString *WebCoreElementImageKey;
77 extern NSString *WebCoreElementImageRectKey;
78 extern NSString *WebCoreElementImageURLKey;
79 extern NSString *WebCoreElementIsSelectedKey;
80 extern NSString *WebCoreElementLinkURLKey;
81 extern NSString *WebCoreElementLinkTargetFrameKey;
82 extern NSString *WebCoreElementLinkLabelKey;
83 extern NSString *WebCoreElementLinkTitleKey;
84 extern NSString *WebCoreElementTitleKey;
86 extern NSString *WebCorePageCacheStateKey;
94 WebSelectionStateNone,
95 WebSelectionStateCaret,
96 WebSelectionStateRange,
102 } WebSelectionAlteration;
109 } WebSelectionDirection;
112 WebSelectByCharacter,
115 WebSelectByParagraph,
117 WebSelectToLineBoundary
118 } WebSelectionGranularity;
121 // WebCoreBridge objects are used by WebCore to abstract away operations that need
122 // to be implemented by library clients, for example WebKit. The objects are also
123 // used in the opposite direction, for simple access to WebCore functions without dealing
124 // directly with the KHTML C++ classes.
126 // A WebCoreBridge creates and holds a reference to a KHTMLPart.
128 // The WebCoreBridge interface contains methods for use by the non-WebCore side of the bridge.
130 @interface WebCoreBridge : NSObject
133 KHTMLRenderPart *_renderPart;
134 RenderArena *_renderPartArena;
135 BOOL _shouldCreateRenderers;
138 + (WebCoreBridge *)bridgeForDOMDocument:(DOMDocument *)document;
140 - (void)initializeSettings:(WebCoreSettings *)settings;
142 - (void)setRenderPart:(KHTMLRenderPart *)renderPart;
143 - (KHTMLRenderPart *)renderPart;
145 - (void)setName:(NSString *)name;
148 - (KWQKHTMLPart *)part;
150 - (void)setParent:(WebCoreBridge *)parent;
152 - (void)provisionalLoadStarted;
154 - (void)openURL:(NSURL *)URL reload:(BOOL)reload
155 contentType:(NSString *)contentType refresh:(NSString *)refresh lastModified:(NSDate *)lastModified
156 pageCache:(NSDictionary *)pageCache;
157 - (void)setEncoding:(NSString *)encoding userChosen:(BOOL)userChosen;
158 - (void)addData:(NSData *)data;
161 - (void)didNotOpenURL:(NSURL *)URL pageCache:(NSDictionary *)pageCache;
163 - (void)saveDocumentState;
164 - (void)restoreDocumentState;
166 - (BOOL)canCachePage;
167 - (BOOL)saveDocumentToPageCache;
172 - (NSString *)referrer;
173 - (NSString *)domain;
175 - (void)installInFrame:(NSView *)view;
176 - (void)removeFromFrame;
178 - (void)scrollToAnchor:(NSString *)anchor;
179 - (void)scrollToAnchorWithURL:(NSURL *)URL;
181 - (void)createKHTMLViewWithNSView:(NSView *)view marginWidth:(int)mw marginHeight:(int)mh;
185 - (void)reapplyStylesForDeviceType:(WebCoreDeviceType)deviceType;
186 - (void)forceLayoutAdjustingViewSize:(BOOL)adjustSizeFlag;
187 - (void)forceLayoutWithMinimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)adjustSizeFlag;
188 - (void)sendResizeEvent;
189 - (void)sendScrollEvent;
191 - (void)setNeedsLayout;
192 - (void)drawRect:(NSRect)rect;
193 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit;
194 - (NSArray*)computePageRectsWithPrintWidthScaleFactor:(float)printWidthScaleFactor printHeight:(float)printHeight;
196 - (void)setActivationEventNumber:(int)num;
197 - (void)mouseDown:(NSEvent *)event;
198 - (void)mouseUp:(NSEvent *)event;
199 - (void)mouseMoved:(NSEvent *)event;
200 - (void)mouseDragged:(NSEvent *)event;
202 - (BOOL)sendContextMenuEvent:(NSEvent *)event; // return YES if event is eaten by WebCore
204 - (NSView *)nextKeyView;
205 - (NSView *)previousKeyView;
207 - (NSView *)nextKeyViewInsideWebFrameViews;
208 - (NSView *)previousKeyViewInsideWebFrameViews;
210 - (NSObject *)copyDOMTree:(id <WebCoreDOMTreeCopier>)copier;
211 - (NSObject *)copyRenderTree:(id <WebCoreRenderTreeCopier>)copier;
212 - (NSString *)renderTreeAsExternalRepresentation;
214 - (NSDictionary *)elementAtPoint:(NSPoint)point;
215 - (NSURL *)URLWithRelativeString:(NSString *)string;
217 - (DOMElement *)elementWithName:(NSString *)name inForm:(DOMElement *)form;
218 - (DOMElement *)elementForView:(NSView *)view;
219 - (BOOL)elementDoesAutoComplete:(DOMElement *)element;
220 - (BOOL)elementIsPassword:(DOMElement *)element;
221 - (DOMElement *)formForElement:(DOMElement *)element;
222 - (DOMElement *)currentForm;
223 - (NSArray *)controlsInForm:(DOMElement *)form;
224 - (NSString *)searchForLabels:(NSArray *)labels beforeElement:(DOMElement *)element;
225 - (NSString *)matchLabels:(NSArray *)labels againstElement:(DOMElement *)element;
227 - (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;
228 - (void)jumpToSelection;
229 - (NSString *)advanceToNextMisspelling;
231 - (void)setTextSizeMultiplier:(float)multiplier;
233 - (CFStringEncoding)textEncoding;
235 - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)string;
237 - (DOMDocument *)DOMDocument;
238 - (DOMHTMLElement *)frameElement;
240 - (void)setSelectionFrom:(DOMNode *)start startOffset:(int)startOffset to:(DOMNode *)end endOffset:(int) endOffset;
242 - (BOOL)isSelectionEditable;
243 - (WebSelectionState)selectionState;
245 - (NSAttributedString *)selectedAttributedString;
246 - (NSString *)selectedString;
248 - (void)setDisplaysWithFocusAttributes:(BOOL)flag;
250 - (NSString *)stringForRange:(DOMRange *)range;
252 - (NSString *)markupStringFromNode:(DOMNode *)node nodes:(NSArray **)nodes;
253 - (NSString *)markupStringFromRange:(DOMRange *)range nodes:(NSArray **)nodes;
257 - (void)deselectText;
259 - (NSRect)selectionRect;
260 - (NSRect)visibleSelectionRect;
261 - (NSImage *)selectionImage;
262 - (NSRect)caretRectAtNode:(DOMNode *)node offset:(int)offset;
264 - (DOMNode *)selectionStart;
265 - (int)selectionStartOffset;
266 - (DOMNode *)selectionEnd;
267 - (int)selectionEndOffset;
268 - (void)setSelectedDOMRange:(DOMRange *)range affinity:(NSSelectionAffinity)selectionAffinity;
269 - (DOMRange *)selectedDOMRange;
270 - (NSSelectionAffinity)selectionAffinity;
272 - (void)setMarkedDOMRange:(DOMRange *)range;
273 - (DOMRange *)markedDOMRange;
274 - (void)clearMarkedDOMRange;
276 - (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset;
277 - (NSFont *)renderedFontForNode:(DOMNode *)node;
279 + (NSString *)stringWithData:(NSData *)data textEncoding:(CFStringEncoding)textEncoding;
280 + (NSString *)stringWithData:(NSData *)data textEncodingName:(NSString *)textEncodingName;
282 - (BOOL)interceptKeyEvent:(NSEvent *)event toView:(NSView *)view;
284 - (void)setShouldCreateRenderers:(BOOL)f;
285 - (BOOL)shouldCreateRenderers;
287 - (int)numPendingOrLoadingRequests;
289 - (void)setDrawsBackground:(BOOL)drawsBackround;
291 - (NSColor *)bodyBackgroundColor;
292 - (NSColor *)selectionColor;
294 - (void)adjustViewSize;
296 + (void)updateAllViews;
298 - (id)accessibilityTree;
300 - (void)undoEditing:(id)arg;
301 - (void)redoEditing:(id)arg;
303 - (DOMRange *)rangeByExpandingSelectionWithGranularity:(WebSelectionGranularity)granularity;
304 - (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
305 - (void)alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
307 - (DOMDocumentFragment *)documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
308 - (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text;
310 - (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement;
311 - (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement;
312 - (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement;
313 - (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement;
315 - (void)insertText:(NSString *)text;
316 - (void)insertNewline;
318 - (void)setSelectionToDragCaret;
319 - (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment;
320 - (void)moveDragCaretToPoint:(NSPoint)point;
321 - (void)removeDragCaret;
322 - (DOMRange *)dragCaretDOMRange;
323 - (DOMRange *)editableDOMRangeForPoint:(NSPoint)point;
325 - (void)deleteSelection;
326 - (void)deleteKeyPressed;
327 - (void)applyStyle:(DOMCSSStyleDeclaration *)style;
328 - (NSFont *)fontForCurrentPosition;
329 - (void)ensureCaretVisible;
331 - (WebScriptObject *)windowScriptObject;
332 - (NPObject *)windowScriptNPObject;
334 - (BOOL)eventMayStartDrag:(NSEvent *)event;
335 - (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)info;
336 - (void)dragExitedWithDraggingInfo:(id <NSDraggingInfo>)info;
337 - (BOOL)concludeDragForDraggingInfo:(id <NSDraggingInfo>)info;
338 - (void)dragSourceMovedTo:(NSPoint)windowLoc;
339 - (void)dragSourceEndedAt:(NSPoint)windowLoc operation:(NSDragOperation)operation;
342 - (BOOL)mayDHTMLCopy;
343 - (BOOL)mayDHTMLPaste;
345 - (BOOL)tryDHTMLCopy;
346 - (BOOL)tryDHTMLPaste;
350 // The WebCoreBridge protocol contains methods for use by the WebCore side of the bridge.
352 @protocol WebCoreBridge
354 - (NSArray *)childFrames; // WebCoreBridge objects
355 - (WebCoreBridge *)mainFrame;
356 - (WebCoreBridge *)findFrameNamed:(NSString *)name;
357 /* Creates a name for an frame unnamed in the HTML. It should produce repeatable results for loads of the same frameset. */
358 - (NSString *)generateFrameName;
359 - (void)frameDetached;
360 - (NSView *)documentView;
362 - (void)loadURL:(NSURL *)URL referrer:(NSString *)referrer reload:(BOOL)reload userGesture:(BOOL)forUser target:(NSString *)target triggeringEvent:(NSEvent *)event form:(DOMElement *)form formValues:(NSDictionary *)values;
363 - (void)postWithURL:(NSURL *)URL referrer:(NSString *)referrer target:(NSString *)target data:(NSData *)data contentType:(NSString *)contentType triggeringEvent:(NSEvent *)event form:(DOMElement *)form formValues:(NSDictionary *)values;
365 - (WebCoreBridge *)createWindowWithURL:(NSURL *)URL frameName:(NSString *)name;
368 - (NSString *)userAgentForURL:(NSURL *)URL;
370 - (void)setTitle:(NSString *)title;
371 - (void)setStatusText:(NSString *)status;
373 - (void)setIconURL:(NSURL *)URL;
374 - (void)setIconURL:(NSURL *)URL withType:(NSString *)string;
376 - (WebCoreBridge *)createChildFrameNamed:(NSString *)frameName withURL:(NSURL *)URL
377 renderPart:(KHTMLRenderPart *)renderPart
378 allowsScrolling:(BOOL)allowsScrolling marginWidth:(int)width marginHeight:(int)height;
380 - (BOOL)areToolbarsVisible;
381 - (void)setToolbarsVisible:(BOOL)visible;
382 - (BOOL)isStatusBarVisible;
383 - (void)setStatusBarVisible:(BOOL)visible;
384 - (BOOL)areScrollbarsVisible;
385 - (void)setScrollbarsVisible:(BOOL)visible;
386 - (NSWindow *)window;
387 - (void)setWindowFrame:(NSRect)frame;
388 - (NSRect)windowFrame;
389 - (void)setWindowContentRect:(NSRect)frame;
390 - (NSRect)windowContentRect;
392 - (void)setWindowIsResizable:(BOOL)resizable;
393 - (BOOL)windowIsResizable;
395 - (NSResponder *)firstResponder;
396 - (void)makeFirstResponder:(NSResponder *)view;
398 - (void)closeWindowSoon;
400 - (void)runJavaScriptAlertPanelWithMessage:(NSString *)message;
401 - (BOOL)runJavaScriptConfirmPanelWithMessage:(NSString *)message;
402 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result;
403 - (void)addMessageToConsole:(NSDictionary *)message;
405 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withURL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders;
406 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)loader withURL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSData *)data;
407 - (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(id)response size:(unsigned)bytes;
409 - (NSData *)syncLoadResourceWithURL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSData *)postData finalURL:(NSURL **)finalNSURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode;
412 - (time_t)expiresTimeForResponse:(NSURLResponse *)response;
414 - (void)reportClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date lockHistory:(BOOL)lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction;
415 - (void)reportClientRedirectCancelled:(BOOL)cancelWithLoadInProgress;
418 - (void)unfocusWindow;
420 - (NSView *)nextKeyViewOutsideWebFrameViews;
421 - (NSView *)previousKeyViewOutsideWebFrameViews;
423 - (BOOL)defersLoading;
424 - (void)setDefersLoading:(BOOL)loading;
425 - (void)saveDocumentState:(NSArray *)documentState;
426 - (NSArray *)documentState;
428 - (void)setNeedsReapplyStyles;
430 // OK to be an NSString rather than an NSURL.
431 // This URL is only used for coloring visited links.
432 - (NSString *)requestedURLString;
433 - (NSString *)incomingReferrer;
435 - (NSView *)viewForPluginWithURL:(NSURL *)URL
436 attributes:(NSArray *)attributesArray
437 baseURL:(NSURL *)baseURL
438 MIMEType:(NSString *)MIMEType;
439 - (NSView *)viewForJavaAppletWithFrame:(NSRect)frame
440 attributes:(NSDictionary *)attributes
441 baseURL:(NSURL *)baseURL;
443 - (BOOL)saveDocumentToPageCache:(id)documentInfo;
445 - (int)getObjectCacheSize;
447 - (BOOL)frameRequiredForMIMEType:(NSString*)MIMEType URL:(NSURL *)URL;
449 - (void)loadEmptyDocumentSynchronously;
451 - (NSString *)MIMETypeForPath:(NSString *)path;
453 - (void)allowDHTMLDrag:(BOOL *)flagDHTML UADrag:(BOOL *)flagUA;
454 - (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData;
455 - (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
456 - (BOOL)mayStartDragAtEventLocation:(NSPoint)location;
458 - (int)historyLength;
459 - (void)goBackOrForward:(int)distance;
460 - (BOOL)canGoBackOrForward:(int)distance;
462 - (void)controlTextDidBeginEditing:(NSNotification *)obj;
463 - (void)controlTextDidEndEditing:(NSNotification *)obj;
464 - (void)controlTextDidChange:(NSNotification *)obj;
466 - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;
467 - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor;
468 - (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error;
469 - (void)control:(NSControl *)control didFailToValidatePartialString:(NSString *)string errorDescription:(NSString *)error;
470 - (BOOL)control:(NSControl *)control isValidObject:(id)obj;
471 - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
473 - (NSView <WebCoreFileButton> *)fileButtonWithDelegate:(id <WebCoreFileButtonDelegate>)delegate;
475 - (void)setHasBorder:(BOOL)hasBorder;
477 - (WebCoreKeyboardUIMode)keyboardUIMode;
479 - (void)didSetName:(NSString *)name;
481 - (NSFileWrapper *)fileWrapperForURL:(NSURL *)URL;
485 - (jobject)getAppletInView:(NSView *)view;
487 // Deprecated, use getAppletInView: instead.
488 - (jobject)pollForAppletInView:(NSView *)view;
490 - (NSUndoManager *)undoManager;
491 - (void)issueCutCommand;
492 - (void)issueCopyCommand;
493 - (void)issuePasteCommand;
494 - (void)respondToChangedSelection;
495 - (void)respondToChangedContents;
496 - (void)setIsSelected:(BOOL)isSelected forView:(NSView *)view;
498 - (BOOL)shouldBeginEditing:(DOMRange *)range;
499 - (BOOL)shouldEndEditing:(DOMRange *)range;
501 - (NSString *)overrideMediaType;
503 - (void)windowObjectCleared;
505 - (int)spellCheckerDocumentTag;
506 - (BOOL)isContinuousSpellCheckingEnabled;
510 // This interface definition allows those who hold a WebCoreBridge * to call all the methods
511 // in the WebCoreBridge protocol without requiring the base implementation to supply the methods.
512 // This idiom is appropriate because WebCoreBridge is an abstract class.
514 @interface WebCoreBridge (SubclassResponsibility) <WebCoreBridge>
517 @protocol WebCoreDOMTreeCopier <NSObject>
518 - (NSObject *)nodeWithName:(NSString *)name value:(NSString *)value source:(NSString *)source children:(NSArray *)children;
521 @protocol WebCoreRenderTreeCopier <NSObject>
522 - (NSObject *)nodeWithName:(NSString *)name position:(NSPoint)p rect:(NSRect)rect view:(NSView *)view children:(NSArray *)children;
525 @protocol WebCoreFileButton <NSObject>
526 - (void)setFilename:(NSString *)filename;
527 - (void)performClick;
528 - (NSString *)filename;
530 - (void)setVisualFrame:(NSRect)rect;
531 - (NSRect)visualFrame;
532 - (NSSize)bestVisualFrameSizeForCharacterCount:(int)count;
535 @protocol WebCoreFileButtonDelegate <NSObject>
536 - (void)filenameChanged:(NSString *)filename;
537 - (void)focusChanged:(BOOL)nowHasFocus;