Home | History | Annotate | Download | only in WebCoreSupport
      1 /*
      2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2006 Zack Rusin <zack (at) kde.org>
      4  * Copyright (C) 2006 Apple Computer, Inc.
      5  * Copyright (C) 2010 Martin Robinson <mrobinson (at) webkit.org>
      6  *
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef EditorClientGtk_h
     32 #define EditorClientGtk_h
     33 
     34 #include "EditorClient.h"
     35 #include "TextCheckerClient.h"
     36 
     37 #include <wtf/Deque.h>
     38 #include <wtf/Forward.h>
     39 #include <wtf/gobject/GOwnPtr.h>
     40 #include <wtf/gobject/GRefPtr.h>
     41 
     42 #if ENABLE(SPELLCHECK)
     43 #include "TextCheckerClientEnchant.h"
     44 #else
     45 #include "EmptyClients.h"
     46 #endif
     47 
     48 typedef struct _WebKitWebView WebKitWebView;
     49 
     50 namespace WebCore {
     51 class Frame;
     52 class KeyboardEvent;
     53 }
     54 
     55 namespace WebKit {
     56 
     57 class EditorClient : public WebCore::EditorClient {
     58     protected:
     59         bool m_isInRedo;
     60 
     61         WTF::Deque<WTF::RefPtr<WebCore::EditCommand> > undoStack;
     62         WTF::Deque<WTF::RefPtr<WebCore::EditCommand> > redoStack;
     63 
     64     public:
     65         EditorClient(WebKitWebView*);
     66         ~EditorClient();
     67         WebKitWebView* webView() { return m_webView; }
     68         bool treatContextCommitAsKeyEvent() { return m_treatContextCommitAsKeyEvent; }
     69         bool preventNextCompositionCommit() { return m_preventNextCompositionCommit; }
     70         void clearPendingComposition() { m_pendingComposition.set(0); }
     71         bool hasPendingComposition() { return m_pendingComposition; }
     72         void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(command); }
     73         void updatePendingComposition(const char*);
     74         void generateEditorCommands(const WebCore::KeyboardEvent*);
     75         bool executePendingEditorCommands(WebCore::Frame*, bool);
     76 
     77         // from EditorClient
     78         virtual void pageDestroyed();
     79 
     80         virtual bool shouldDeleteRange(WebCore::Range*);
     81         virtual bool shouldShowDeleteInterface(WebCore::HTMLElement*);
     82         virtual bool smartInsertDeleteEnabled();
     83         virtual bool isSelectTrailingWhitespaceEnabled();
     84         virtual bool isContinuousSpellCheckingEnabled();
     85         virtual void toggleContinuousSpellChecking();
     86         virtual bool isGrammarCheckingEnabled();
     87         virtual void toggleGrammarChecking();
     88         virtual int spellCheckerDocumentTag();
     89 
     90         virtual bool shouldBeginEditing(WebCore::Range*);
     91         virtual bool shouldEndEditing(WebCore::Range*);
     92         virtual bool shouldInsertNode(WebCore::Node*, WebCore::Range*, WebCore::EditorInsertAction);
     93         virtual bool shouldInsertText(const WTF::String&, WebCore::Range*, WebCore::EditorInsertAction);
     94         virtual bool shouldChangeSelectedRange(WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity, bool stillSelecting);
     95 
     96         virtual bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
     97 
     98         virtual bool shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*);
     99 
    100         virtual void didBeginEditing();
    101         virtual void respondToChangedContents();
    102         virtual void respondToChangedSelection();
    103         virtual void didEndEditing();
    104         virtual void didWriteSelectionToPasteboard();
    105         virtual void didSetSelectionTypesForPasteboard();
    106 
    107         virtual void registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand>);
    108         virtual void registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>);
    109         virtual void clearUndoRedoOperations();
    110 
    111         virtual bool canCopyCut(bool defaultValue) const;
    112         virtual bool canPaste(bool defaultValue) const;
    113         virtual bool canUndo() const;
    114         virtual bool canRedo() const;
    115 
    116         virtual void undo();
    117         virtual void redo();
    118 
    119         virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
    120         virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
    121         virtual void handleInputMethodMousePress();
    122 
    123         virtual void textFieldDidBeginEditing(WebCore::Element*);
    124         virtual void textFieldDidEndEditing(WebCore::Element*);
    125         virtual void textDidChangeInTextField(WebCore::Element*);
    126         virtual bool doTextFieldCommandFromEvent(WebCore::Element*, WebCore::KeyboardEvent*);
    127         virtual void textWillBeDeletedInTextField(WebCore::Element*);
    128         virtual void textDidChangeInTextArea(WebCore::Element*);
    129 
    130         virtual WebCore::TextCheckerClient* textChecker() { return &m_textCheckerClient; }
    131 
    132         virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&);
    133         virtual void updateSpellingUIWithMisspelledWord(const WTF::String&);
    134         virtual void showSpellingUI(bool show);
    135         virtual bool spellingUIIsShowing();
    136         virtual void willSetInputMethodState();
    137         virtual void setInputMethodState(bool enabled);
    138 
    139     private:
    140 #if ENABLE(SPELLCHECK)
    141         TextCheckerClientEnchant m_textCheckerClient;
    142 #else
    143         WebCore::EmptyTextCheckerClient m_textCheckerClient;
    144 #endif
    145         WebKitWebView* m_webView;
    146         bool m_preventNextCompositionCommit;
    147         bool m_treatContextCommitAsKeyEvent;
    148         GOwnPtr<gchar> m_pendingComposition;
    149         Vector<const char*> m_pendingEditorCommands;
    150         GRefPtr<GtkWidget> m_nativeWidget;
    151     };
    152 }
    153 
    154 #endif
    155 
    156 // vim: ts=4 sw=4 et
    157