2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef __apply_style_command_h__
27 #define __apply_style_command_h__
29 #include "composite_edit_command.h"
32 class HTMLElementImpl;
37 class ApplyStyleCommand : public CompositeEditCommand
40 enum EPropertyLevel { PropertyDefault, ForceBlockProperties };
42 ApplyStyleCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *style, EditAction editingAction=EditActionChangeAttributes, EPropertyLevel=PropertyDefault);
43 virtual ~ApplyStyleCommand();
45 virtual void doApply();
46 virtual EditAction editingAction() const;
48 DOM::CSSMutableStyleDeclarationImpl *style() const { return m_style; }
51 // style-removal helpers
52 bool isHTMLStyleNode(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
53 void removeHTMLStyleNode(DOM::HTMLElementImpl *);
54 void removeHTMLFontStyle(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
55 void removeCSSStyle(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
56 void removeBlockStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end);
57 void removeInlineStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end);
58 bool nodeFullySelected(DOM::NodeImpl *, const DOM::Position &start, const DOM::Position &end) const;
59 bool nodeFullyUnselected(DOM::NodeImpl *node, const DOM::Position &start, const DOM::Position &end) const;
60 DOM::CSSMutableStyleDeclarationImpl *extractTextDecorationStyle(DOM::NodeImpl *node);
61 DOM::CSSMutableStyleDeclarationImpl *extractAndNegateTextDecorationStyle(DOM::NodeImpl *node);
62 void applyTextDecorationStyle(DOM::NodeImpl *node, DOM::CSSMutableStyleDeclarationImpl *style);
63 void pushDownTextDecorationStyleAroundNode(DOM::NodeImpl *node, const DOM::Position &start, const DOM::Position &end, bool force);
64 void pushDownTextDecorationStyleAtBoundaries(const DOM::Position &start, const DOM::Position &end);
66 // style-application helpers
67 void applyBlockStyle(DOM::CSSMutableStyleDeclarationImpl *);
68 void applyRelativeFontStyleChange(DOM::CSSMutableStyleDeclarationImpl *);
69 void applyInlineStyle(DOM::CSSMutableStyleDeclarationImpl *);
70 void addBlockStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::NodeImpl *);
71 void addInlineStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::NodeImpl *start, DOM::NodeImpl *end);
72 bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
73 bool splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
74 bool splitTextElementAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
75 bool splitTextElementAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
76 bool mergeStartWithPreviousIfIdentical(const DOM::Position &start, const DOM::Position &end);
77 bool mergeEndWithNextIfIdentical(const DOM::Position &start, const DOM::Position &end);
78 void cleanUpEmptyStyleSpans(const DOM::Position &start, const DOM::Position &end);
80 void surroundNodeRangeWithElement(DOM::NodeImpl *start, DOM::NodeImpl *end, DOM::ElementImpl *element);
81 float computedFontSize(const DOM::NodeImpl *);
82 void joinChildTextNodes(DOM::NodeImpl *, const DOM::Position &start, const DOM::Position &end);
84 DOM::CSSMutableStyleDeclarationImpl *m_style;
85 EditAction m_editingAction;
86 EPropertyLevel m_propertyLevel;
89 bool isStyleSpan(const DOM::NodeImpl *node);
90 DOM::ElementImpl *createStyleSpanElement(DOM::DocumentImpl *document);
94 #endif // __apply_style_command_h__