Home | History | Annotate | Download | only in page
      1 /*
      2  * Copyright (C) 2006, 2007 Apple 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  * 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  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #ifndef EditorClient_h
     28 #define EditorClient_h
     29 
     30 #include "EditorInsertAction.h"
     31 #include "PlatformString.h"
     32 #include "TextAffinity.h"
     33 #include <wtf/Forward.h>
     34 #include <wtf/Vector.h>
     35 
     36 #if PLATFORM(MAC)
     37 class NSArray;
     38 class NSData;
     39 class NSString;
     40 class NSURL;
     41 #endif
     42 
     43 namespace WebCore {
     44 
     45 class CSSStyleDeclaration;
     46 class EditCommand;
     47 class Element;
     48 class Frame;
     49 class HTMLElement;
     50 class KeyboardEvent;
     51 class Node;
     52 class Range;
     53 class VisibleSelection;
     54 class String;
     55 class VisiblePosition;
     56 
     57 struct GrammarDetail {
     58     int location;
     59     int length;
     60     Vector<String> guesses;
     61     String userDescription;
     62 };
     63 
     64 enum TextCheckingType {
     65     TextCheckingTypeSpelling    = 1 << 1,
     66     TextCheckingTypeGrammar     = 1 << 2,
     67     TextCheckingTypeLink        = 1 << 5,
     68     TextCheckingTypeQuote       = 1 << 6,
     69     TextCheckingTypeDash        = 1 << 7,
     70     TextCheckingTypeReplacement = 1 << 8,
     71     TextCheckingTypeCorrection  = 1 << 9
     72 };
     73 
     74 struct TextCheckingResult {
     75     TextCheckingType type;
     76     int location;
     77     int length;
     78     Vector<GrammarDetail> details;
     79     String replacement;
     80 };
     81 
     82 class EditorClient {
     83 public:
     84     virtual ~EditorClient() {  }
     85     virtual void pageDestroyed() = 0;
     86 
     87     virtual bool shouldDeleteRange(Range*) = 0;
     88     virtual bool shouldShowDeleteInterface(HTMLElement*) = 0;
     89     virtual bool smartInsertDeleteEnabled() = 0;
     90     virtual bool isSelectTrailingWhitespaceEnabled() = 0;
     91     virtual bool isContinuousSpellCheckingEnabled() = 0;
     92     virtual void toggleContinuousSpellChecking() = 0;
     93     virtual bool isGrammarCheckingEnabled() = 0;
     94     virtual void toggleGrammarChecking() = 0;
     95     virtual int spellCheckerDocumentTag() = 0;
     96 
     97     virtual bool isEditable() = 0;
     98 
     99     virtual bool shouldBeginEditing(Range*) = 0;
    100     virtual bool shouldEndEditing(Range*) = 0;
    101     virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) = 0;
    102     virtual bool shouldInsertText(const String&, Range*, EditorInsertAction) = 0;
    103     virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) = 0;
    104 
    105     virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) = 0;
    106 //  virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle) = 0;
    107 //  virtual bool doCommandBySelector(SEL selector) = 0;
    108     virtual bool shouldMoveRangeAfterDelete(Range*, Range*) = 0;
    109 
    110     virtual void didBeginEditing() = 0;
    111     virtual void respondToChangedContents() = 0;
    112     virtual void respondToChangedSelection() = 0;
    113     virtual void didEndEditing() = 0;
    114     virtual void didWriteSelectionToPasteboard() = 0;
    115     virtual void didSetSelectionTypesForPasteboard() = 0;
    116 //  virtual void didChangeTypingStyle:(NSNotification *)notification = 0;
    117 //  virtual void didChangeSelection:(NSNotification *)notification = 0;
    118 //  virtual NSUndoManager* undoManager:(WebView *)webView = 0;
    119 
    120     virtual void registerCommandForUndo(PassRefPtr<EditCommand>) = 0;
    121     virtual void registerCommandForRedo(PassRefPtr<EditCommand>) = 0;
    122     virtual void clearUndoRedoOperations() = 0;
    123 
    124     virtual bool canUndo() const = 0;
    125     virtual bool canRedo() const = 0;
    126 
    127     virtual void undo() = 0;
    128     virtual void redo() = 0;
    129 
    130     virtual void handleKeyboardEvent(KeyboardEvent*) = 0;
    131     virtual void handleInputMethodKeydown(KeyboardEvent*) = 0;
    132 
    133     virtual void textFieldDidBeginEditing(Element*) = 0;
    134     virtual void textFieldDidEndEditing(Element*) = 0;
    135     virtual void textDidChangeInTextField(Element*) = 0;
    136     virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) = 0;
    137     virtual void textWillBeDeletedInTextField(Element*) = 0;
    138     virtual void textDidChangeInTextArea(Element*) = 0;
    139 
    140 #if PLATFORM(MAC)
    141     virtual NSString* userVisibleString(NSURL*) = 0;
    142 #ifdef BUILDING_ON_TIGER
    143     virtual NSArray* pasteboardTypesForSelection(Frame*) = 0;
    144 #endif
    145 #endif
    146 
    147 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    148     virtual void uppercaseWord() = 0;
    149     virtual void lowercaseWord() = 0;
    150     virtual void capitalizeWord() = 0;
    151     virtual void showSubstitutionsPanel(bool show) = 0;
    152     virtual bool substitutionsPanelIsShowing() = 0;
    153     virtual void toggleSmartInsertDelete() = 0;
    154     virtual bool isAutomaticQuoteSubstitutionEnabled() = 0;
    155     virtual void toggleAutomaticQuoteSubstitution() = 0;
    156     virtual bool isAutomaticLinkDetectionEnabled() = 0;
    157     virtual void toggleAutomaticLinkDetection() = 0;
    158     virtual bool isAutomaticDashSubstitutionEnabled() = 0;
    159     virtual void toggleAutomaticDashSubstitution() = 0;
    160     virtual bool isAutomaticTextReplacementEnabled() = 0;
    161     virtual void toggleAutomaticTextReplacement() = 0;
    162     virtual bool isAutomaticSpellingCorrectionEnabled() = 0;
    163     virtual void toggleAutomaticSpellingCorrection() = 0;
    164 #endif
    165 
    166     virtual void ignoreWordInSpellDocument(const String&) = 0;
    167     virtual void learnWord(const String&) = 0;
    168     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) = 0;
    169     virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) = 0;
    170     virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
    171 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    172     virtual void checkTextOfParagraph(const UChar* text, int length, uint64_t checkingTypes, Vector<TextCheckingResult>& results) = 0;
    173 #endif
    174     virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail) = 0;
    175     virtual void updateSpellingUIWithMisspelledWord(const String&) = 0;
    176     virtual void showSpellingUI(bool show) = 0;
    177     virtual bool spellingUIIsShowing() = 0;
    178     virtual void getGuessesForWord(const String&, Vector<String>& guesses) = 0;
    179     virtual void setInputMethodState(bool enabled) = 0;
    180 };
    181 
    182 }
    183 
    184 #endif // EditorClient_h
    185 
    186