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 "SpellingCorrectionController.h"
     31 #include "EditorInsertAction.h"
     32 #include "FloatRect.h"
     33 #include "PlatformString.h"
     34 #include "TextAffinity.h"
     35 #include <wtf/Forward.h>
     36 #include <wtf/Vector.h>
     37 
     38 #if PLATFORM(MAC)
     39 #ifdef __OBJC__
     40 @class NSArray;
     41 @class NSAttributedString;
     42 @class NSData;
     43 @class NSPasteboard;
     44 @class NSString;
     45 @class NSURL;
     46 #else
     47 class NSArray;
     48 class NSAttributedString;
     49 class NSData;
     50 class NSPasteboard;
     51 class NSString;
     52 class NSURL;
     53 #endif
     54 #endif
     55 
     56 namespace WebCore {
     57 
     58 class ArchiveResource;
     59 class CSSStyleDeclaration;
     60 class DocumentFragment;
     61 class EditCommand;
     62 class Editor;
     63 class Element;
     64 class Frame;
     65 class HTMLElement;
     66 class KeyboardEvent;
     67 class Node;
     68 class Range;
     69 class SpellChecker;
     70 class TextCheckerClient;
     71 class VisibleSelection;
     72 class VisiblePosition;
     73 
     74 struct GrammarDetail;
     75 
     76 class EditorClient {
     77 public:
     78     virtual ~EditorClient() {  }
     79     virtual void pageDestroyed() = 0;
     80 
     81     virtual bool shouldDeleteRange(Range*) = 0;
     82     virtual bool shouldShowDeleteInterface(HTMLElement*) = 0;
     83     virtual bool smartInsertDeleteEnabled() = 0;
     84     virtual bool isSelectTrailingWhitespaceEnabled() = 0;
     85     virtual bool isContinuousSpellCheckingEnabled() = 0;
     86     virtual void toggleContinuousSpellChecking() = 0;
     87     virtual bool isGrammarCheckingEnabled() = 0;
     88     virtual void toggleGrammarChecking() = 0;
     89     virtual int spellCheckerDocumentTag() = 0;
     90 
     91     virtual bool shouldBeginEditing(Range*) = 0;
     92     virtual bool shouldEndEditing(Range*) = 0;
     93     virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) = 0;
     94     virtual bool shouldInsertText(const String&, Range*, EditorInsertAction) = 0;
     95     virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) = 0;
     96 
     97     virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) = 0;
     98     virtual bool shouldMoveRangeAfterDelete(Range*, Range*) = 0;
     99 
    100     virtual void didBeginEditing() = 0;
    101     virtual void respondToChangedContents() = 0;
    102     virtual void respondToChangedSelection() = 0;
    103     virtual void didEndEditing() = 0;
    104     virtual void didWriteSelectionToPasteboard() = 0;
    105     virtual void didSetSelectionTypesForPasteboard() = 0;
    106 
    107     virtual void registerCommandForUndo(PassRefPtr<EditCommand>) = 0;
    108     virtual void registerCommandForRedo(PassRefPtr<EditCommand>) = 0;
    109     virtual void clearUndoRedoOperations() = 0;
    110 
    111     virtual bool canCopyCut(bool defaultValue) const = 0;
    112     virtual bool canPaste(bool defaultValue) const = 0;
    113     virtual bool canUndo() const = 0;
    114     virtual bool canRedo() const = 0;
    115 
    116     virtual void undo() = 0;
    117     virtual void redo() = 0;
    118 
    119     virtual void handleKeyboardEvent(KeyboardEvent*) = 0;
    120     virtual void handleInputMethodKeydown(KeyboardEvent*) = 0;
    121 
    122     virtual void textFieldDidBeginEditing(Element*) = 0;
    123     virtual void textFieldDidEndEditing(Element*) = 0;
    124     virtual void textDidChangeInTextField(Element*) = 0;
    125     virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) = 0;
    126     virtual void textWillBeDeletedInTextField(Element*) = 0;
    127     virtual void textDidChangeInTextArea(Element*) = 0;
    128 
    129 #if PLATFORM(MAC)
    130     virtual NSString* userVisibleString(NSURL*) = 0;
    131     virtual DocumentFragment* documentFragmentFromAttributedString(NSAttributedString*, Vector< RefPtr<ArchiveResource> >&) = 0;
    132     virtual void setInsertionPasteboard(NSPasteboard*) = 0;
    133     virtual NSURL* canonicalizeURL(NSURL*) = 0;
    134     virtual NSURL* canonicalizeURLString(NSString*) = 0;
    135 #ifdef BUILDING_ON_TIGER
    136     virtual NSArray* pasteboardTypesForSelection(Frame*) = 0;
    137 #endif
    138 #endif
    139 
    140 #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    141     virtual void uppercaseWord() = 0;
    142     virtual void lowercaseWord() = 0;
    143     virtual void capitalizeWord() = 0;
    144     virtual void showSubstitutionsPanel(bool show) = 0;
    145     virtual bool substitutionsPanelIsShowing() = 0;
    146     virtual void toggleSmartInsertDelete() = 0;
    147     virtual bool isAutomaticQuoteSubstitutionEnabled() = 0;
    148     virtual void toggleAutomaticQuoteSubstitution() = 0;
    149     virtual bool isAutomaticLinkDetectionEnabled() = 0;
    150     virtual void toggleAutomaticLinkDetection() = 0;
    151     virtual bool isAutomaticDashSubstitutionEnabled() = 0;
    152     virtual void toggleAutomaticDashSubstitution() = 0;
    153     virtual bool isAutomaticTextReplacementEnabled() = 0;
    154     virtual void toggleAutomaticTextReplacement() = 0;
    155     virtual bool isAutomaticSpellingCorrectionEnabled() = 0;
    156     virtual void toggleAutomaticSpellingCorrection() = 0;
    157 #endif
    158 
    159     virtual TextCheckerClient* textChecker() = 0;
    160 
    161     enum AutocorrectionResponseType {
    162         AutocorrectionEdited,
    163         AutocorrectionReverted
    164     };
    165 
    166 #if SUPPORT_AUTOCORRECTION_PANEL
    167     virtual void showCorrectionPanel(CorrectionPanelInfo::PanelType, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacmentString, const Vector<String>& alternativeReplacementStrings) = 0;
    168     virtual void dismissCorrectionPanel(ReasonForDismissingCorrectionPanel) = 0;
    169     virtual String dismissCorrectionPanelSoon(ReasonForDismissingCorrectionPanel) = 0;
    170     virtual void recordAutocorrectionResponse(AutocorrectionResponseType, const String& replacedString, const String& replacementString) = 0;
    171 #endif
    172 
    173     virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail& detail) = 0;
    174     virtual void updateSpellingUIWithMisspelledWord(const String&) = 0;
    175     virtual void showSpellingUI(bool show) = 0;
    176     virtual bool spellingUIIsShowing() = 0;
    177     virtual void willSetInputMethodState() = 0;
    178     virtual void setInputMethodState(bool enabled) = 0;
    179 };
    180 
    181 }
    182 
    183 #endif // EditorClient_h
    184