OSDN Git Service

Merge "Removing the list of active loaders"
[android-x86/external-webkit.git] / WebCore / editing / ApplyStyleCommand.h
1 /*
2  * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef ApplyStyleCommand_h
27 #define ApplyStyleCommand_h
28
29 #include "CompositeEditCommand.h"
30
31 namespace WebCore {
32
33 class CSSPrimitiveValue;
34 class HTMLElement;
35 class StyleChange;
36
37 enum ShouldIncludeTypingStyle {
38     IncludeTypingStyle,
39     IgnoreTypingStyle
40 };
41
42 class ApplyStyleCommand : public CompositeEditCommand {
43 public:
44     enum EPropertyLevel { PropertyDefault, ForceBlockProperties };
45
46     static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
47     {
48         return adoptRef(new ApplyStyleCommand(document, style, action, level));
49     }
50     static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
51     {
52         return adoptRef(new ApplyStyleCommand(document, style, start, end, action, level));
53     }
54     static PassRefPtr<ApplyStyleCommand> create(PassRefPtr<Element> element, bool removeOnly = false, EditAction action = EditActionChangeAttributes)
55     {
56         return adoptRef(new ApplyStyleCommand(element, removeOnly, action));
57     }
58     
59     static PassRefPtr<CSSMutableStyleDeclaration> editingStyleAtPosition(Position pos, ShouldIncludeTypingStyle shouldIncludeTypingStyle = IgnoreTypingStyle);
60
61 private:
62     ApplyStyleCommand(Document*, CSSStyleDeclaration*, EditAction, EPropertyLevel);
63     ApplyStyleCommand(Document*, CSSStyleDeclaration*, const Position& start, const Position& end, EditAction, EPropertyLevel);
64     ApplyStyleCommand(PassRefPtr<Element>, bool removeOnly, EditAction);
65
66     virtual void doApply();
67     virtual EditAction editingAction() const;
68
69     CSSMutableStyleDeclaration* style() const { return m_style.get(); }
70
71     // style-removal helpers
72     bool shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const;
73     bool implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(HTMLElement*, CSSMutableStyleDeclaration*);
74     void replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*&);
75     void removeHTMLFontStyle(CSSMutableStyleDeclaration*, HTMLElement*);
76     void removeHTMLBidiEmbeddingStyle(CSSMutableStyleDeclaration*, HTMLElement*);
77     void removeCSSStyle(CSSMutableStyleDeclaration*, HTMLElement*);
78     void removeInlineStyle(PassRefPtr<CSSMutableStyleDeclaration>, const Position& start, const Position& end);
79     bool nodeFullySelected(Node*, const Position& start, const Position& end) const;
80     bool nodeFullyUnselected(Node*, const Position& start, const Position& end) const;
81     PassRefPtr<CSSMutableStyleDeclaration> extractTextDecorationStyle(Node*);
82     PassRefPtr<CSSMutableStyleDeclaration> extractAndNegateTextDecorationStyle(Node*);
83     void applyTextDecorationStyle(Node*, CSSMutableStyleDeclaration *style);
84     void pushDownTextDecorationStyleAroundNode(Node*, bool forceNegate);
85     void pushDownTextDecorationStyleAtBoundaries(const Position& start, const Position& end);
86     
87     // style-application helpers
88     void applyBlockStyle(CSSMutableStyleDeclaration*);
89     void applyRelativeFontStyleChange(CSSMutableStyleDeclaration*);
90     void applyInlineStyle(CSSMutableStyleDeclaration*);
91     void applyInlineStyleToRange(CSSMutableStyleDeclaration*, const Position& start, const Position& end);
92     void addBlockStyle(const StyleChange&, HTMLElement*);
93     void addInlineStyleIfNeeded(CSSMutableStyleDeclaration*, Node* start, Node* end);
94     void splitTextAtStart(const Position& start, const Position& end);
95     void splitTextAtEnd(const Position& start, const Position& end);
96     void splitTextElementAtStart(const Position& start, const Position& end);
97     void splitTextElementAtEnd(const Position& start, const Position& end);
98     bool isValidCaretPositionInTextNode(const Position& position);
99     bool mergeStartWithPreviousIfIdentical(const Position& start, const Position& end);
100     bool mergeEndWithNextIfIdentical(const Position& start, const Position& end);
101     void cleanupUnstyledAppleStyleSpans(Node* dummySpanAncestor);
102
103     void surroundNodeRangeWithElement(Node* start, Node* end, PassRefPtr<Element>);
104     float computedFontSize(const Node*);
105     void joinChildTextNodes(Node*, const Position& start, const Position& end);
106
107     HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, RefPtr<CSSPrimitiveValue> allowedDirection);
108     void removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor);
109
110     void updateStartEnd(const Position& newStart, const Position& newEnd);
111     Position startPosition();
112     Position endPosition();
113
114     RefPtr<CSSMutableStyleDeclaration> m_style;
115     EditAction m_editingAction;
116     EPropertyLevel m_propertyLevel;
117     Position m_start;
118     Position m_end;
119     bool m_useEndingSelection;
120     RefPtr<Element> m_styledInlineElement;
121     bool m_removeOnly;
122 };
123
124 bool isStyleSpan(const Node*);
125 PassRefPtr<HTMLElement> createStyleSpanElement(Document*);
126 RefPtr<CSSMutableStyleDeclaration> getPropertiesNotInComputedStyle(CSSStyleDeclaration* style, CSSComputedStyleDeclaration* computedStyle);
127
128 void prepareEditingStyleToApplyAt(CSSMutableStyleDeclaration*, Position);
129 void removeStylesAddedByNode(CSSMutableStyleDeclaration*, Node*);
130
131 } // namespace WebCore
132
133 #endif