WebEditorClient.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #import <WebCore/EditorClient.h>
  30. #import <WebCore/TextCheckerClient.h>
  31. #import <wtf/Forward.h>
  32. #import <wtf/RetainPtr.h>
  33. #import <wtf/Vector.h>
  34. @class WebView;
  35. @class WebEditorUndoTarget;
  36. class WebEditorClient : public WebCore::EditorClient, public WebCore::TextCheckerClient {
  37. public:
  38. WebEditorClient(WebView *);
  39. virtual ~WebEditorClient();
  40. virtual void pageDestroyed() OVERRIDE;
  41. virtual void frameWillDetachPage(WebCore::Frame*) OVERRIDE { }
  42. virtual bool isGrammarCheckingEnabled() OVERRIDE;
  43. virtual void toggleGrammarChecking() OVERRIDE;
  44. virtual bool isContinuousSpellCheckingEnabled() OVERRIDE;
  45. virtual void toggleContinuousSpellChecking() OVERRIDE;
  46. virtual int spellCheckerDocumentTag() OVERRIDE;
  47. virtual bool smartInsertDeleteEnabled() OVERRIDE;
  48. virtual bool isSelectTrailingWhitespaceEnabled() OVERRIDE;
  49. virtual bool shouldDeleteRange(WebCore::Range*) OVERRIDE;
  50. virtual bool shouldBeginEditing(WebCore::Range*) OVERRIDE;
  51. virtual bool shouldEndEditing(WebCore::Range*) OVERRIDE;
  52. virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction) OVERRIDE;
  53. virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction) OVERRIDE;
  54. virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting) OVERRIDE;
  55. virtual bool shouldApplyStyle(WebCore::StylePropertySet*, WebCore::Range*) OVERRIDE;
  56. virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range* rangeToBeReplaced) OVERRIDE;
  57. virtual void didBeginEditing() OVERRIDE;
  58. virtual void didEndEditing() OVERRIDE;
  59. virtual void willWriteSelectionToPasteboard(WebCore::Range*) OVERRIDE;
  60. virtual void didWriteSelectionToPasteboard() OVERRIDE;
  61. virtual void getClientPasteboardDataForRange(WebCore::Range*, Vector<String>& pasteboardTypes, Vector<RefPtr<WebCore::SharedBuffer> >& pasteboardData) OVERRIDE;
  62. virtual void didSetSelectionTypesForPasteboard() OVERRIDE;
  63. virtual NSString* userVisibleString(NSURL *) OVERRIDE;
  64. virtual WebCore::DocumentFragment* documentFragmentFromAttributedString(NSAttributedString *, Vector< RefPtr<WebCore::ArchiveResource> >&) OVERRIDE;
  65. virtual void setInsertionPasteboard(const String&) OVERRIDE;
  66. virtual NSURL* canonicalizeURL(NSURL*) OVERRIDE;
  67. virtual NSURL* canonicalizeURLString(NSString*) OVERRIDE;
  68. #if USE(APPKIT)
  69. virtual void uppercaseWord() OVERRIDE;
  70. virtual void lowercaseWord() OVERRIDE;
  71. virtual void capitalizeWord() OVERRIDE;
  72. #endif
  73. #if USE(AUTOMATIC_TEXT_REPLACEMENT)
  74. virtual void showSubstitutionsPanel(bool show) OVERRIDE;
  75. virtual bool substitutionsPanelIsShowing() OVERRIDE;
  76. virtual void toggleSmartInsertDelete() OVERRIDE;
  77. virtual bool isAutomaticQuoteSubstitutionEnabled() OVERRIDE;
  78. virtual void toggleAutomaticQuoteSubstitution() OVERRIDE;
  79. virtual bool isAutomaticLinkDetectionEnabled() OVERRIDE;
  80. virtual void toggleAutomaticLinkDetection() OVERRIDE;
  81. virtual bool isAutomaticDashSubstitutionEnabled() OVERRIDE;
  82. virtual void toggleAutomaticDashSubstitution() OVERRIDE;
  83. virtual bool isAutomaticTextReplacementEnabled() OVERRIDE;
  84. virtual void toggleAutomaticTextReplacement() OVERRIDE;
  85. virtual bool isAutomaticSpellingCorrectionEnabled() OVERRIDE;
  86. virtual void toggleAutomaticSpellingCorrection() OVERRIDE;
  87. #endif
  88. #if ENABLE(DELETION_UI)
  89. virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*) OVERRIDE;
  90. #endif
  91. TextCheckerClient* textChecker() OVERRIDE { return this; }
  92. virtual void respondToChangedContents() OVERRIDE;
  93. virtual void respondToChangedSelection(WebCore::Frame*) OVERRIDE;
  94. virtual void registerUndoStep(PassRefPtr<WebCore::UndoStep>) OVERRIDE;
  95. virtual void registerRedoStep(PassRefPtr<WebCore::UndoStep>) OVERRIDE;
  96. virtual void clearUndoRedoOperations() OVERRIDE;
  97. virtual bool canCopyCut(WebCore::Frame*, bool defaultValue) const OVERRIDE;
  98. virtual bool canPaste(WebCore::Frame*, bool defaultValue) const OVERRIDE;
  99. virtual bool canUndo() const OVERRIDE;
  100. virtual bool canRedo() const OVERRIDE;
  101. virtual void undo() OVERRIDE;
  102. virtual void redo() OVERRIDE;
  103. virtual void handleKeyboardEvent(WebCore::KeyboardEvent*) OVERRIDE;
  104. virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*) OVERRIDE;
  105. virtual void textFieldDidBeginEditing(WebCore::Element*) OVERRIDE;
  106. virtual void textFieldDidEndEditing(WebCore::Element*) OVERRIDE;
  107. virtual void textDidChangeInTextField(WebCore::Element*) OVERRIDE;
  108. virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*) OVERRIDE;
  109. virtual void textWillBeDeletedInTextField(WebCore::Element*) OVERRIDE;
  110. virtual void textDidChangeInTextArea(WebCore::Element*) OVERRIDE;
  111. virtual bool shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType) const OVERRIDE;
  112. virtual void ignoreWordInSpellDocument(const WTF::String&) OVERRIDE;
  113. virtual void learnWord(const WTF::String&) OVERRIDE;
  114. virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) OVERRIDE;
  115. virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE;
  116. virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE;
  117. virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
  118. virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE;
  119. virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE;
  120. virtual void showSpellingUI(bool show) OVERRIDE;
  121. virtual bool spellingUIIsShowing() OVERRIDE;
  122. virtual void getGuessesForWord(const WTF::String& word, const WTF::String& context, WTF::Vector<WTF::String>& guesses) OVERRIDE;
  123. virtual void willSetInputMethodState() OVERRIDE;
  124. virtual void setInputMethodState(bool enabled) OVERRIDE;
  125. virtual void requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest>) OVERRIDE;
  126. void didCheckSucceed(int sequence, NSArray* results);
  127. private:
  128. void registerUndoOrRedoStep(PassRefPtr<WebCore::UndoStep>, bool isRedo);
  129. WebEditorClient();
  130. WebView *m_webView;
  131. RetainPtr<WebEditorUndoTarget> m_undoTarget;
  132. bool m_haveUndoRedoOperations;
  133. RefPtr<WebCore::TextCheckingRequest> m_textCheckingRequest;
  134. };