⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlediting.h

📁 手机浏览器源码程序,功能强大
💻 H
📖 第 1 页 / 共 3 页
字号:

//------------------------------------------------------------------------------------------
// RemoveNodePreservingChildrenCommand

class RemoveNodePreservingChildrenCommand : public CompositeEditCommand
{
public:
    RemoveNodePreservingChildrenCommand(DOM::DocumentImpl *, DOM::NodeImpl *);
    virtual ~RemoveNodePreservingChildrenCommand();
	
    virtual void doApply();

    DOM::NodeImpl *node() const { return m_node; }

private:
    DOM::NodeImpl *m_node;
};

//------------------------------------------------------------------------------------------
// ReplaceSelectionCommand

// --- NodeDesiredStyle helper class

class NodeDesiredStyle
OOM_MODIFIED
{
public:
    NodeDesiredStyle(DOM::NodeImpl *, DOM::CSSMutableStyleDeclarationImpl *);
    NodeDesiredStyle(const NodeDesiredStyle &);
    ~NodeDesiredStyle();
    
    DOM::NodeImpl *node() const { return m_node; }
    DOM::CSSMutableStyleDeclarationImpl *style() const { return m_style; }

    NodeDesiredStyle &operator=(const NodeDesiredStyle &);

private:
    DOM::NodeImpl *m_node;
    DOM::CSSMutableStyleDeclarationImpl *m_style;
};

// --- ReplacementFragment helper class

class ReplacementFragment
OOM_MODIFIED
{
public:
    ReplacementFragment(DOM::DocumentImpl *, DOM::DocumentFragmentImpl *, bool matchStyle);
    ~ReplacementFragment();

    enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };

    DOM::DocumentFragmentImpl *root() const { return m_fragment; }
    DOM::NodeImpl *firstChild() const;
    DOM::NodeImpl *lastChild() const;

    DOM::NodeImpl *mergeStartNode() const;

    const QValueList<NodeDesiredStyle> &desiredStyles() { return m_styles; }
        
    void pruneEmptyNodes();

    EFragmentType type() const { return m_type; }
    bool isEmpty() const { return m_type == EmptyFragment; }
    bool isSingleTextNode() const { return m_type == SingleTextNodeFragment; }
    bool isTreeFragment() const { return m_type == TreeFragment; }

    bool hasMoreThanOneBlock() const { return m_hasMoreThanOneBlock; }
    bool hasInterchangeNewlineAtStart() const { return m_hasInterchangeNewlineAtStart; }
    bool hasInterchangeNewlineAtEnd() const { return m_hasInterchangeNewlineAtEnd; }

private:
    // no copy construction or assignment
    ReplacementFragment(const ReplacementFragment &);
    ReplacementFragment &operator=(const ReplacementFragment &);
    
    static bool isInterchangeNewlineNode(const DOM::NodeImpl *);
    static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);

    DOM::NodeImpl *insertFragmentForTestRendering();
    void restoreTestRenderingNodesToFragment(DOM::NodeImpl *);
    void computeStylesUsingTestRendering(DOM::NodeImpl *);
    void removeUnrenderedNodesUsingTestRendering(DOM::NodeImpl *);
    int countRenderedBlocks(DOM::NodeImpl *holder);
    void removeStyleNodes();

    // A couple simple DOM helpers
    DOM::NodeImpl *enclosingBlock(DOM::NodeImpl *) const;
    void removeNode(DOM::NodeImpl *);
    void removeNodePreservingChildren(DOM::NodeImpl *);
    void insertNodeBefore(DOM::NodeImpl *node, DOM::NodeImpl *refNode);

    EFragmentType m_type;
    DOM::DocumentImpl *m_document;
    DOM::DocumentFragmentImpl *m_fragment;
    QValueList<NodeDesiredStyle> m_styles;
    bool m_matchStyle;
    bool m_hasInterchangeNewlineAtStart;
    bool m_hasInterchangeNewlineAtEnd;
    bool m_hasMoreThanOneBlock;
};

class ReplaceSelectionCommand : public CompositeEditCommand
{
public:
    ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false, bool matchStyle=false);
    virtual ~ReplaceSelectionCommand();
    
    virtual void doApply();
    virtual EditAction editingAction() const;

private:
    void completeHTMLReplacement(const DOM::Position &lastPositionToSelect);

    void insertNodeAfterAndUpdateNodesInserted(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
    void insertNodeAtAndUpdateNodesInserted(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild, long offset);
    void insertNodeBeforeAndUpdateNodesInserted(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);

    void updateNodesInserted(DOM::NodeImpl *);
    void fixupNodeStyles(const QValueList<NodeDesiredStyle> &);
    void removeLinePlaceholderIfNeeded(DOM::NodeImpl *);

    ReplacementFragment m_fragment;
    DOM::NodeImpl *m_firstNodeInserted;
    DOM::NodeImpl *m_lastNodeInserted;
    DOM::NodeImpl *m_lastTopNodeInserted;
    DOM::CSSMutableStyleDeclarationImpl *m_insertionStyle;
    bool m_selectReplacement;
    bool m_smartReplace;
    bool m_matchStyle;
};

void computeAndStoreNodeDesiredStyle(DOM::NodeImpl *, QValueList<NodeDesiredStyle> &);

//------------------------------------------------------------------------------------------
// SetNodeAttributeCommand

class SetNodeAttributeCommand : public EditCommand
{
public:
    SetNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, DOM::NodeImpl::Id attribute, const DOM::DOMString &value);
    virtual ~SetNodeAttributeCommand();

    virtual void doApply();
    virtual void doUnapply();

    DOM::ElementImpl *element() const { return m_element; }
    DOM::NodeImpl::Id attribute() const { return m_attribute; }
    DOM::DOMString value() const { return m_value; }
    
private:
    DOM::ElementImpl *m_element;
    DOM::NodeImpl::Id m_attribute;
    DOM::DOMString m_value;
    DOM::DOMString m_oldValue;
};

//------------------------------------------------------------------------------------------
// SplitTextNodeCommand

class SplitTextNodeCommand : public EditCommand
{
public:
    SplitTextNodeCommand(DOM::DocumentImpl *, DOM::TextImpl *, long);
    virtual ~SplitTextNodeCommand();
	
    virtual void doApply();
    virtual void doUnapply();

    DOM::TextImpl *node() const { return m_text2; }
    long offset() const { return m_offset; }

private:
    DOM::TextImpl *m_text1;
    DOM::TextImpl *m_text2;
    unsigned long m_offset;
};

//------------------------------------------------------------------------------------------
// WrapContentsInDummySpanCommand

class WrapContentsInDummySpanCommand : public EditCommand
{
public:
    WrapContentsInDummySpanCommand(DOM::DocumentImpl *, DOM::ElementImpl *);
    virtual ~WrapContentsInDummySpanCommand();
	
    virtual void doApply();
    virtual void doUnapply();

private:
    DOM::ElementImpl *m_element;
    DOM::ElementImpl *m_dummySpan;
};

//------------------------------------------------------------------------------------------
// SplitElementCommand

class SplitElementCommand : public EditCommand
{
public:
    SplitElementCommand(DOM::DocumentImpl *, DOM::ElementImpl *element, DOM::NodeImpl *atChild);
    virtual ~SplitElementCommand();
	
    virtual void doApply();
    virtual void doUnapply();

private:
    DOM::ElementImpl *m_element1;
    DOM::ElementImpl *m_element2;
    DOM::NodeImpl *m_atChild;
};

//------------------------------------------------------------------------------------------
// MergeIdenticalElementsCommand

class MergeIdenticalElementsCommand : public EditCommand
{
public:
    MergeIdenticalElementsCommand(DOM::DocumentImpl *, DOM::ElementImpl *first, DOM::ElementImpl *second);
    virtual ~MergeIdenticalElementsCommand();
	
    virtual void doApply();
    virtual void doUnapply();

private:
    DOM::ElementImpl *m_element1;
    DOM::ElementImpl *m_element2;
    DOM::NodeImpl *m_atChild;
};

//------------------------------------------------------------------------------------------
// SplitTextNodeContainingElementCommand

class SplitTextNodeContainingElementCommand : public CompositeEditCommand
{
public:
    SplitTextNodeContainingElementCommand(DOM::DocumentImpl *, DOM::TextImpl *, long);
    virtual ~SplitTextNodeContainingElementCommand();
	
    virtual void doApply();

private:
    DOM::TextImpl *m_text;
    long m_offset;
};


//------------------------------------------------------------------------------------------
// TypingCommand

class TypingCommand : public CompositeEditCommand
{
public:
    enum ETypingCommand { 
        DeleteKey, 
        ForwardDeleteKey, 
        InsertText, 
        InsertLineBreak, 
        InsertParagraphSeparator,
        InsertParagraphSeparatorInQuotedContent,
    };

    TypingCommand(DOM::DocumentImpl *document, ETypingCommand, const DOM::DOMString &text = "", bool selectInsertedText = false);

    static void deleteKeyPressed(DOM::DocumentImpl *, bool smartDelete = false);
    static void forwardDeleteKeyPressed(DOM::DocumentImpl *, bool smartDelete = false);
    static void insertText(DOM::DocumentImpl *, const DOM::DOMString &, bool selectInsertedText = false);
    static void insertLineBreak(DOM::DocumentImpl *);
    static void insertParagraphSeparator(DOM::DocumentImpl *);
    static void insertParagraphSeparatorInQuotedContent(DOM::DocumentImpl *);
    static bool isOpenForMoreTypingCommand(const EditCommandPtr &);
    static void closeTyping(const EditCommandPtr &);
    
    virtual void doApply();
    virtual EditAction editingAction() const;

    bool openForMoreTyping() const { return m_openForMoreTyping; }
    void closeTyping() { m_openForMoreTyping = false; }

    void insertText(const DOM::DOMString &text, bool selectInsertedText);
    void insertTextRunWithoutNewlines(const DOM::DOMString &text, bool selectInsertedText);
    void insertLineBreak();
    void insertParagraphSeparatorInQuotedContent();
    void insertParagraphSeparator();
    void deleteKeyPressed();
    void forwardDeleteKeyPressed();

    bool smartDelete() { return m_smartDelete; }
    void setSmartDelete(bool smartDelete) { m_smartDelete = smartDelete; }

private:
    virtual bool isTypingCommand() const;
    virtual bool preservesTypingStyle() const;

    void markMisspellingsAfterTyping();
    void typingAddedToOpenCommand();
    
    ETypingCommand m_commandType;
    DOM::DOMString m_textToInsert;
    bool m_openForMoreTyping;
    bool m_applyEditing;
    bool m_selectInsertedText;
    bool m_smartDelete;
};

//------------------------------------------------------------------------------------------

DOM::ElementImpl *floatRefdElement(DOM::ElementImpl *element);
DOM::ElementImpl *createDefaultParagraphElement(DOM::DocumentImpl *document);
DOM::ElementImpl *createBlockPlaceholderElement(DOM::DocumentImpl *document);
DOM::ElementImpl *createBreakElement(DOM::DocumentImpl *document);
DOM::ElementImpl *createFontElement(DOM::DocumentImpl *document);
DOM::ElementImpl *createStyleSpanElement(DOM::DocumentImpl *document);

bool isNodeRendered(const DOM::NodeImpl *);
bool isProbablyBlock(const DOM::NodeImpl *);
bool isProbablyTableStructureNode(const DOM::NodeImpl *);
bool isMailBlockquote(const DOM::NodeImpl *);
DOM::NodeImpl *nearestMailBlockquote(const DOM::NodeImpl *);
bool isMailPasteAsQuotationNode(const DOM::NodeImpl *node);

//------------------------------------------------------------------------------------------

} // end namespace khtml

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -