1/* 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#import "CorrectionPanel.h" 31#import <WebCore/EditorClient.h> 32#import <WebCore/TextCheckerClient.h> 33#import <wtf/Forward.h> 34#import <wtf/RetainPtr.h> 35#import <wtf/Vector.h> 36 37@class WebView; 38@class WebEditorUndoTarget; 39 40class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient { 41public: 42 WebEditorClient(WebView *); 43 virtual ~WebEditorClient(); 44 virtual void pageDestroyed(); 45 46 virtual bool isGrammarCheckingEnabled(); 47 virtual void toggleGrammarChecking(); 48 virtual bool isContinuousSpellCheckingEnabled(); 49 virtual void toggleContinuousSpellChecking(); 50 virtual int spellCheckerDocumentTag(); 51 52 virtual bool smartInsertDeleteEnabled(); 53 virtual bool isSelectTrailingWhitespaceEnabled(); 54 55 virtual bool shouldDeleteRange(WebCore::Range*); 56 virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*); 57 58 virtual bool shouldBeginEditing(WebCore::Range*); 59 virtual bool shouldEndEditing(WebCore::Range*); 60 virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction); 61 virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction); 62 virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting); 63 64 virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*); 65 66 virtual bool shouldMoveRangeAfterDelete(WebCore::Range* range, WebCore::Range* rangeToBeReplaced); 67 68 virtual void didBeginEditing(); 69 virtual void didEndEditing(); 70 virtual void didWriteSelectionToPasteboard(); 71 virtual void didSetSelectionTypesForPasteboard(); 72 73 virtual NSString* userVisibleString(NSURL *); 74 virtual WebCore::DocumentFragment* documentFragmentFromAttributedString(NSAttributedString *, Vector< RefPtr<WebCore::ArchiveResource> >&); 75 virtual void setInsertionPasteboard(NSPasteboard *); 76 virtual NSURL* canonicalizeURL(NSURL*); 77 virtual NSURL* canonicalizeURLString(NSString*); 78#ifdef BUILDING_ON_TIGER 79 virtual NSArray *pasteboardTypesForSelection(WebCore::Frame*); 80#endif 81 82#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) 83 virtual void uppercaseWord(); 84 virtual void lowercaseWord(); 85 virtual void capitalizeWord(); 86 virtual void showSubstitutionsPanel(bool show); 87 virtual bool substitutionsPanelIsShowing(); 88 virtual void toggleSmartInsertDelete(); 89 virtual bool isAutomaticQuoteSubstitutionEnabled(); 90 virtual void toggleAutomaticQuoteSubstitution(); 91 virtual bool isAutomaticLinkDetectionEnabled(); 92 virtual void toggleAutomaticLinkDetection(); 93 virtual bool isAutomaticDashSubstitutionEnabled(); 94 virtual void toggleAutomaticDashSubstitution(); 95 virtual bool isAutomaticTextReplacementEnabled(); 96 virtual void toggleAutomaticTextReplacement(); 97 virtual bool isAutomaticSpellingCorrectionEnabled(); 98 virtual void toggleAutomaticSpellingCorrection(); 99#endif 100 101 TextCheckerClient* textChecker() { return this; } 102 103 virtual void respondToChangedContents(); 104 virtual void respondToChangedSelection(); 105 106 virtual void registerCommandForUndo(PassRefPtr<WebCore::EditCommand>); 107 virtual void registerCommandForRedo(PassRefPtr<WebCore::EditCommand>); 108 virtual void clearUndoRedoOperations(); 109 110 virtual bool canCopyCut(bool defaultValue) const; 111 virtual bool canPaste(bool defaultValue) const; 112 virtual bool canUndo() const; 113 virtual bool canRedo() const; 114 115 virtual void undo(); 116 virtual void redo(); 117 118 virtual void handleKeyboardEvent(WebCore::KeyboardEvent*); 119 virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*); 120 121 virtual void textFieldDidBeginEditing(WebCore::Element*); 122 virtual void textFieldDidEndEditing(WebCore::Element*); 123 virtual void textDidChangeInTextField(WebCore::Element*); 124 virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*); 125 virtual void textWillBeDeletedInTextField(WebCore::Element*); 126 virtual void textDidChangeInTextArea(WebCore::Element*); 127 128 virtual void ignoreWordInSpellDocument(const WTF::String&); 129 virtual void learnWord(const WTF::String&); 130 virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength); 131 virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&); 132 virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength); 133 virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results); 134 virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&); 135 virtual void updateSpellingUIWithMisspelledWord(const WTF::String&); 136 virtual void showSpellingUI(bool show); 137 virtual bool spellingUIIsShowing(); 138 virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses); 139 virtual void willSetInputMethodState(); 140 virtual void setInputMethodState(bool enabled); 141 virtual void requestCheckingOfString(WebCore::SpellChecker*, int, WebCore::TextCheckingTypeMask, const WTF::String&); 142#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 143 virtual void showCorrectionPanel(WebCore::CorrectionPanelInfo::PanelType, const WebCore::FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings); 144 virtual void dismissCorrectionPanel(WebCore::ReasonForDismissingCorrectionPanel); 145 virtual String dismissCorrectionPanelSoon(WebCore::ReasonForDismissingCorrectionPanel); 146 virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString); 147#endif 148private: 149 void registerCommandForUndoOrRedo(PassRefPtr<WebCore::EditCommand>, bool isRedo); 150 WebEditorClient(); 151 152 WebView *m_webView; 153 RetainPtr<WebEditorUndoTarget> m_undoTarget; 154 bool m_haveUndoRedoOperations; 155 156#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) 157 CorrectionPanel m_correctionPanel; 158#endif 159}; 160