File indexing completed on 2024-05-12 11:51:55

0001 /*
0002  * Copyright (C) 2006 Eric Seidel (eric@webkit.org)
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  * 1. Redistributions of source code must retain the above copyright
0008  *    notice, this list of conditions and the following disclaimer.
0009  * 2. Redistributions in binary form must reproduce the above copyright
0010  *    notice, this list of conditions and the following disclaimer in the
0011  *    documentation and/or other materials provided with the distribution.
0012  *
0013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
0014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
0017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
0021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 
0026 #ifndef SVGImageEmptyClients_h
0027 #define SVGImageEmptyClients_h
0028 
0029 #if ENABLE(SVG)
0030 
0031 #include "ChromeClient.h"
0032 #include "ContextMenuClient.h"
0033 #include "DragClient.h"
0034 #include "EditorClient.h"
0035 #include "FocusDirection.h"
0036 #include "FrameLoaderClient.h"
0037 #include "InspectorClient.h"
0038 #include "SharedBuffer.h"
0039 
0040 /*
0041  This file holds empty Client stubs for use by SVGImage.
0042  SVGImage needs to create a dummy Page->Frame->FrameView tree for use in parsing an SVGDocument.
0043  This tree depends heavily on Clients (usually provided by WebKit classes).
0044 
0045  SVGImage has no way to access the current Page (nor should it, since Images are not tied to a page).
0046  See https://bugs.webkit.org/show_bug.cgi?id=5971 for more discussion on this issue.
0047 
0048  Ideally, whenever you change a Client class, you should add a stub here.
0049  Brittle, yes.  Unfortunate, yes.  Hopefully temporary.
0050 */
0051 
0052 namespace WebCore
0053 {
0054 
0055 class SVGEmptyChromeClient : public ChromeClient
0056 {
0057 public:
0058     virtual ~SVGEmptyChromeClient() { }
0059     virtual void chromeDestroyed() { }
0060 
0061     virtual void setWindowRect(const FloatRect &) { }
0062     virtual FloatRect windowRect()
0063     {
0064         return FloatRect();
0065     }
0066 
0067     virtual FloatRect pageRect()
0068     {
0069         return FloatRect();
0070     }
0071 
0072     virtual float scaleFactor()
0073     {
0074         return 1.f;
0075     }
0076 
0077     virtual void focus() { }
0078     virtual void unfocus() { }
0079 
0080     virtual bool canTakeFocus(FocusDirection)
0081     {
0082         return false;
0083     }
0084     virtual void takeFocus(FocusDirection) { }
0085 
0086     virtual Page *createWindow(Frame *, const FrameLoadRequest &, const WindowFeatures &)
0087     {
0088         return 0;
0089     }
0090     virtual void show() { }
0091 
0092     virtual bool canRunModal()
0093     {
0094         return false;
0095     }
0096     virtual void runModal() { }
0097 
0098     virtual void setToolbarsVisible(bool) { }
0099     virtual bool toolbarsVisible()
0100     {
0101         return false;
0102     }
0103 
0104     virtual void setStatusbarVisible(bool) { }
0105     virtual bool statusbarVisible()
0106     {
0107         return false;
0108     }
0109 
0110     virtual void setScrollbarsVisible(bool) { }
0111     virtual bool scrollbarsVisible()
0112     {
0113         return false;
0114     }
0115 
0116     virtual void setMenubarVisible(bool) { }
0117     virtual bool menubarVisible()
0118     {
0119         return false;
0120     }
0121 
0122     virtual void setResizable(bool) { }
0123 
0124     virtual void addMessageToConsole(const String &message, unsigned int lineNumber, const String &sourceID) { }
0125 
0126     virtual bool canRunBeforeUnloadConfirmPanel()
0127     {
0128         return false;
0129     }
0130     virtual bool runBeforeUnloadConfirmPanel(const String &message, Frame *frame)
0131     {
0132         return true;
0133     }
0134 
0135     virtual void closeWindowSoon() { }
0136 
0137     virtual void runJavaScriptAlert(Frame *, const String &) { }
0138     virtual bool runJavaScriptConfirm(Frame *, const String &)
0139     {
0140         return false;
0141     }
0142     virtual bool runJavaScriptPrompt(Frame *, const String &message, const String &defaultValue, String &result)
0143     {
0144         return false;
0145     }
0146     virtual bool shouldInterruptJavaScript()
0147     {
0148         return false;
0149     }
0150 
0151     virtual void setStatusbarText(const String &) { }
0152 
0153     virtual bool tabsToLinks() const
0154     {
0155         return false;
0156     }
0157 
0158     virtual IntRect windowResizerRect() const
0159     {
0160         return IntRect();
0161     }
0162     virtual void addToDirtyRegion(const IntRect &) { }
0163     virtual void scrollBackingStore(int dx, int dy, const IntRect &scrollViewRect, const IntRect &clipRect) { }
0164     virtual void updateBackingStore() { }
0165 
0166     virtual void mouseDidMoveOverElement(const HitTestResult &, unsigned modifierFlags) { }
0167 
0168     virtual void setToolTip(const String &) { }
0169 
0170     virtual void print(Frame *) { }
0171 
0172     virtual void exceededDatabaseQuota(Frame *, const String &) { }
0173 };
0174 
0175 class SVGEmptyFrameLoaderClient : public FrameLoaderClient
0176 {
0177 public:
0178     virtual ~SVGEmptyFrameLoaderClient() {  }
0179     virtual void frameLoaderDestroyed() { }
0180 
0181     virtual bool hasWebView() const
0182     {
0183         return true;    // mainly for assertions
0184     }
0185     virtual bool hasFrameView() const
0186     {
0187         return true;    // ditto
0188     }
0189 
0190     virtual void makeRepresentation(DocumentLoader *) { }
0191     virtual void forceLayout() { }
0192     virtual void forceLayoutForNonHTML() { }
0193 
0194     virtual void updateHistoryForCommit() { }
0195 
0196     virtual void updateHistoryForBackForwardNavigation() { }
0197     virtual void updateHistoryForReload() { }
0198     virtual void updateHistoryForStandardLoad() { }
0199     virtual void updateHistoryForInternalLoad() { }
0200 
0201     virtual void updateHistoryAfterClientRedirect() { }
0202 
0203     virtual void setCopiesOnScroll() { }
0204 
0205     virtual void detachedFromParent2() { }
0206     virtual void detachedFromParent3() { }
0207     virtual void detachedFromParent4() { }
0208 
0209     virtual void download(ResourceHandle *, const ResourceRequest &, const ResourceRequest &, const ResourceResponse &) { }
0210 
0211     virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader *, const ResourceRequest &) { }
0212     virtual void dispatchWillSendRequest(DocumentLoader *, unsigned long identifier, ResourceRequest &, const ResourceResponse &redirectResponse) { }
0213     virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader *, unsigned long identifier, const AuthenticationChallenge &) { }
0214     virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader *, unsigned long identifier, const AuthenticationChallenge &) { }
0215     virtual void dispatchDidReceiveResponse(DocumentLoader *, unsigned long identifier, const ResourceResponse &) { }
0216     virtual void dispatchDidReceiveContentLength(DocumentLoader *, unsigned long identifier, int lengthReceived) { }
0217     virtual void dispatchDidFinishLoading(DocumentLoader *, unsigned long identifier) { }
0218     virtual void dispatchDidFailLoading(DocumentLoader *, unsigned long identifier, const ResourceError &) { }
0219     virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader *, const ResourceRequest &, const ResourceResponse &, int length)
0220     {
0221         return false;
0222     }
0223 
0224     virtual void dispatchDidHandleOnloadEvents() { }
0225     virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() { }
0226     virtual void dispatchDidCancelClientRedirect() { }
0227     virtual void dispatchWillPerformClientRedirect(const KURL &, double interval, double fireDate) { }
0228     virtual void dispatchDidChangeLocationWithinPage() { }
0229     virtual void dispatchWillClose() { }
0230     virtual void dispatchDidReceiveIcon() { }
0231     virtual void dispatchDidStartProvisionalLoad() { }
0232     virtual void dispatchDidReceiveTitle(const String &title) { }
0233     virtual void dispatchDidCommitLoad() { }
0234     virtual void dispatchDidFailProvisionalLoad(const ResourceError &) { }
0235     virtual void dispatchDidFailLoad(const ResourceError &) { }
0236     virtual void dispatchDidFinishDocumentLoad() { }
0237     virtual void dispatchDidFinishLoad() { }
0238     virtual void dispatchDidFirstLayout() { }
0239 
0240     virtual Frame *dispatchCreatePage()
0241     {
0242         return 0;
0243     }
0244     virtual void dispatchShow() { }
0245 
0246     virtual void dispatchDecidePolicyForMIMEType(FramePolicyFunction, const String &MIMEType, const ResourceRequest &) { }
0247     virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction &, const ResourceRequest &, const String &frameName) { }
0248     virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction &, const ResourceRequest &) { }
0249     virtual void cancelPolicyCheck() { }
0250 
0251     virtual void dispatchUnableToImplementPolicy(const ResourceError &) { }
0252 
0253     virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>) { }
0254 
0255     virtual void dispatchDidLoadMainResource(DocumentLoader *) { }
0256     virtual void revertToProvisionalState(DocumentLoader *) { }
0257     virtual void setMainDocumentError(DocumentLoader *, const ResourceError &) { }
0258 
0259     virtual void willChangeEstimatedProgress() { }
0260     virtual void didChangeEstimatedProgress() { }
0261     virtual void postProgressStartedNotification() { }
0262     virtual void postProgressEstimateChangedNotification() { }
0263     virtual void postProgressFinishedNotification() { }
0264 
0265     virtual void setMainFrameDocumentReady(bool) { }
0266 
0267     virtual void startDownload(const ResourceRequest &) { }
0268 
0269     virtual void willChangeTitle(DocumentLoader *) { }
0270     virtual void didChangeTitle(DocumentLoader *) { }
0271 
0272     virtual void committedLoad(DocumentLoader *, const char *, int) { }
0273     virtual void finishedLoading(DocumentLoader *) { }
0274 
0275     virtual ResourceError cancelledError(const ResourceRequest &)
0276     {
0277         return ResourceError();
0278     }
0279     virtual ResourceError blockedError(const ResourceRequest &)
0280     {
0281         return ResourceError();
0282     }
0283     virtual ResourceError cannotShowURLError(const ResourceRequest &)
0284     {
0285         return ResourceError();
0286     }
0287     virtual ResourceError interruptForPolicyChangeError(const ResourceRequest &)
0288     {
0289         return ResourceError();
0290     }
0291 
0292     virtual ResourceError cannotShowMIMETypeError(const ResourceResponse &)
0293     {
0294         return ResourceError();
0295     }
0296     virtual ResourceError fileDoesNotExistError(const ResourceResponse &)
0297     {
0298         return ResourceError();
0299     }
0300 
0301     virtual bool shouldFallBack(const ResourceError &)
0302     {
0303         return false;
0304     }
0305 
0306     virtual bool canHandleRequest(const ResourceRequest &) const
0307     {
0308         return false;
0309     }
0310     virtual bool canShowMIMEType(const String &MIMEType) const
0311     {
0312         return false;
0313     }
0314     virtual bool representationExistsForURLScheme(const String &URLScheme) const
0315     {
0316         return false;
0317     }
0318     virtual String generatedMIMETypeForURLScheme(const String &URLScheme) const
0319     {
0320         return "";
0321     }
0322 
0323     virtual void frameLoadCompleted() { }
0324     virtual void restoreViewState() { }
0325     virtual void provisionalLoadStarted() { }
0326     virtual bool shouldTreatURLAsSameAsCurrent(const KURL &) const
0327     {
0328         return false;
0329     }
0330     virtual void addHistoryItemForFragmentScroll() { }
0331     virtual void didFinishLoad() { }
0332     virtual void prepareForDataSourceReplacement() { }
0333 
0334     virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest &request, const SubstituteData &substituteData)
0335     {
0336         return new DocumentLoader(request, substituteData);
0337     }
0338     virtual void setTitle(const String &title, const KURL &) { }
0339 
0340     virtual String userAgent(const KURL &)
0341     {
0342         return "";
0343     }
0344 
0345     virtual void savePlatformDataToCachedPage(CachedPage *) { }
0346     virtual void transitionToCommittedFromCachedPage(CachedPage *) { }
0347     virtual void transitionToCommittedForNewPage() { }
0348 
0349     virtual void updateGlobalHistory(const KURL &) { }
0350     virtual bool shouldGoToHistoryItem(HistoryItem *) const
0351     {
0352         return false;
0353     }
0354     virtual void saveViewStateToItem(HistoryItem *) { }
0355     virtual bool canCachePage() const
0356     {
0357         return false;
0358     }
0359 
0360     virtual PassRefPtr<Frame> createFrame(const KURL &url, const String &name, HTMLFrameOwnerElement *ownerElement,
0361                                           const String &referrer, bool allowsScrolling, int marginWidth, int marginHeight)
0362     {
0363         return 0;
0364     }
0365     virtual Widget *createPlugin(const IntSize &, Element *, const KURL &, const Vector<String> &, const Vector<String> &, const String &, bool)
0366     {
0367         return 0;
0368     }
0369     virtual Widget *createJavaAppletWidget(const IntSize &, Element *, const KURL &, const Vector<String> &, const Vector<String> &)
0370     {
0371         return 0;
0372     }
0373 
0374     virtual ObjectContentType objectContentType(const KURL &url, const String &mimeType)
0375     {
0376         return ObjectContentType();
0377     }
0378     virtual String overrideMediaType() const
0379     {
0380         return String();
0381     }
0382 
0383     virtual void redirectDataToPlugin(Widget *) {}
0384     virtual void windowObjectCleared() {}
0385     virtual void didPerformFirstNavigation() const {}
0386 
0387     virtual void registerForIconNotification(bool listen) {}
0388 
0389 #if PLATFORM(MAC)
0390     virtual NSCachedURLResponse *willCacheResponse(DocumentLoader *, unsigned long identifier, NSCachedURLResponse *response) const
0391     {
0392         return response;
0393     }
0394 #endif
0395 
0396 };
0397 
0398 class SVGEmptyEditorClient : public EditorClient
0399 {
0400 public:
0401     virtual ~SVGEmptyEditorClient() { }
0402     virtual void pageDestroyed() { }
0403 
0404     virtual bool shouldDeleteRange(Range *)
0405     {
0406         return false;
0407     }
0408     virtual bool shouldShowDeleteInterface(HTMLElement *)
0409     {
0410         return false;
0411     }
0412     virtual bool smartInsertDeleteEnabled()
0413     {
0414         return false;
0415     }
0416     virtual bool isContinuousSpellCheckingEnabled()
0417     {
0418         return false;
0419     }
0420     virtual void toggleContinuousSpellChecking() { }
0421     virtual bool isGrammarCheckingEnabled()
0422     {
0423         return false;
0424     }
0425     virtual void toggleGrammarChecking() { }
0426     virtual int spellCheckerDocumentTag()
0427     {
0428         return -1;
0429     }
0430 
0431     virtual bool selectWordBeforeMenuEvent()
0432     {
0433         return false;
0434     }
0435     virtual bool isEditable()
0436     {
0437         return false;
0438     }
0439 
0440     virtual bool shouldBeginEditing(Range *)
0441     {
0442         return false;
0443     }
0444     virtual bool shouldEndEditing(Range *)
0445     {
0446         return false;
0447     }
0448     virtual bool shouldInsertNode(Node *, Range *, EditorInsertAction)
0449     {
0450         return false;
0451     }
0452     //  virtual bool shouldInsertNode(Node*, Range* replacingRange, WebViewInsertAction) { return false; }
0453     virtual bool shouldInsertText(const String &, Range *, EditorInsertAction)
0454     {
0455         return false;
0456     }
0457     virtual bool shouldChangeSelectedRange(Range *fromRange, Range *toRange, EAffinity, bool stillSelecting)
0458     {
0459         return false;
0460     }
0461 
0462     virtual bool shouldApplyStyle(CSSStyleDeclaration *, Range *)
0463     {
0464         return false;
0465     }
0466     virtual bool shouldMoveRangeAfterDelete(Range *, Range *)
0467     {
0468         return false;
0469     }
0470     //  virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle) { return false; }
0471     //  virtual bool doCommandBySelector(SEL selector) { return false; }
0472     //
0473     virtual void didBeginEditing() { }
0474     virtual void respondToChangedContents() { }
0475     virtual void respondToChangedSelection() { }
0476     virtual void didEndEditing() { }
0477     virtual void didWriteSelectionToPasteboard() { }
0478     virtual void didSetSelectionTypesForPasteboard() { }
0479     //  virtual void webViewDidChangeTypingStyle:(NSNotification *)notification { }
0480     //  virtual void webViewDidChangeSelection:(NSNotification *)notification { }
0481     //  virtual NSUndoManager* undoManagerForWebView:(WebView *)webView { return 0; }
0482 
0483     virtual void registerCommandForUndo(PassRefPtr<EditCommand>) { }
0484     virtual void registerCommandForRedo(PassRefPtr<EditCommand>) { }
0485     virtual void clearUndoRedoOperations() { }
0486 
0487     virtual bool canUndo() const
0488     {
0489         return false;
0490     }
0491     virtual bool canRedo() const
0492     {
0493         return false;
0494     }
0495 
0496     virtual void undo() { }
0497     virtual void redo() { }
0498 
0499     virtual void handleKeyboardEvent(KeyboardEvent *) { }
0500     virtual void handleInputMethodKeydown(KeyboardEvent *) { }
0501 
0502     virtual void textFieldDidBeginEditing(Element *) { }
0503     virtual void textFieldDidEndEditing(Element *) { }
0504     virtual void textDidChangeInTextField(Element *) { }
0505     virtual bool doTextFieldCommandFromEvent(Element *, KeyboardEvent *)
0506     {
0507         return false;
0508     }
0509     virtual void textWillBeDeletedInTextField(Element *) { }
0510     virtual void textDidChangeInTextArea(Element *) { }
0511 
0512 #if PLATFORM(MAC)
0513     virtual void markedTextAbandoned(Frame *) { }
0514 
0515     virtual NSString *userVisibleString(NSURL *)
0516     {
0517         return 0;
0518     }
0519 #ifdef BUILDING_ON_TIGER
0520     virtual NSArray *pasteboardTypesForSelection(Frame *)
0521     {
0522         return 0;
0523     }
0524 #endif
0525 #endif
0526     virtual void ignoreWordInSpellDocument(const String &) { }
0527     virtual void learnWord(const String &) { }
0528     virtual void checkSpellingOfString(const UChar *, int length, int *misspellingLocation, int *misspellingLength) { }
0529     virtual void checkGrammarOfString(const UChar *, int length, Vector<GrammarDetail> &, int *badGrammarLocation, int *badGrammarLength) { }
0530     virtual void updateSpellingUIWithGrammarString(const String &, const GrammarDetail &) { }
0531     virtual void updateSpellingUIWithMisspelledWord(const String &) { }
0532     virtual void showSpellingUI(bool show) { }
0533     virtual bool spellingUIIsShowing()
0534     {
0535         return false;
0536     }
0537     virtual void getGuessesForWord(const String &, Vector<String> &guesses) { }
0538     virtual void setInputMethodState(bool enabled) { }
0539 
0540 };
0541 
0542 class SVGEmptyContextMenuClient : public ContextMenuClient
0543 {
0544 public:
0545     virtual ~SVGEmptyContextMenuClient() {  }
0546     virtual void contextMenuDestroyed() { }
0547 
0548     virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu *)
0549     {
0550         return 0;
0551     }
0552     virtual void contextMenuItemSelected(ContextMenuItem *, const ContextMenu *) { }
0553 
0554     virtual void downloadURL(const KURL &url) { }
0555     virtual void copyImageToClipboard(const HitTestResult &) { }
0556     virtual void searchWithGoogle(const Frame *) { }
0557     virtual void lookUpInDictionary(Frame *) { }
0558     virtual void speak(const String &) { }
0559     virtual void stopSpeaking() { }
0560 
0561 #if PLATFORM(MAC)
0562     virtual void searchWithSpotlight() { }
0563 #endif
0564 };
0565 
0566 class SVGEmptyDragClient : public DragClient
0567 {
0568 public:
0569     virtual ~SVGEmptyDragClient() {}
0570     virtual void willPerformDragDestinationAction(DragDestinationAction, DragData *) { }
0571     virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint &, Clipboard *) { }
0572     virtual DragDestinationAction actionMaskForDrag(DragData *)
0573     {
0574         return DragDestinationActionNone;
0575     }
0576     virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint &)
0577     {
0578         return DragSourceActionNone;
0579     }
0580     virtual void startDrag(DragImageRef, const IntPoint &, const IntPoint &, Clipboard *, Frame *, bool) { }
0581     virtual DragImageRef createDragImageForLink(KURL &, const String &label, Frame *)
0582     {
0583         return 0;
0584     }
0585     virtual void dragControllerDestroyed() { }
0586 };
0587 
0588 class SVGEmptyInspectorClient : public InspectorClient
0589 {
0590 public:
0591     virtual ~SVGEmptyInspectorClient() {}
0592 
0593     virtual void inspectorDestroyed() {};
0594 
0595     virtual Page *createPage()
0596     {
0597         return 0;
0598     };
0599 
0600     virtual String localizedStringsURL()
0601     {
0602         return String();
0603     };
0604 
0605     virtual void showWindow() {};
0606     virtual void closeWindow() {};
0607 
0608     virtual void attachWindow() {};
0609     virtual void detachWindow() {};
0610 
0611     virtual void highlight(Node *) {};
0612     virtual void hideHighlight() {};
0613     virtual void inspectedURLChanged(const String &newURL) {};
0614 };
0615 
0616 }
0617 
0618 #endif // ENABLE(SVG)
0619 
0620 #endif // SVGImageEmptyClients_h
0621