| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #ifndef EditingStyleUtilities_h | 32 #ifndef EditingStyleUtilities_h |
| 33 #define EditingStyleUtilities_h | 33 #define EditingStyleUtilities_h |
| 34 | 34 |
| 35 #include "core/CSSPropertyNames.h" | 35 #include "core/CSSPropertyNames.h" |
| 36 #include "core/CSSValueKeywords.h" | 36 #include "core/CSSValueKeywords.h" |
| 37 #include "core/CoreExport.h" | |
| 38 #include "core/editing/Position.h" | |
| 39 #include "core/editing/VisibleSelection.h" | 37 #include "core/editing/VisibleSelection.h" |
| 40 #include "core/editing/WritingDirection.h" | 38 #include "core/editing/WritingDirection.h" |
| 41 #include "platform/heap/Handle.h" | |
| 42 #include "wtf/Forward.h" | |
| 43 #include "wtf/TriState.h" | |
| 44 #include "wtf/Vector.h" | |
| 45 #include "wtf/text/WTFString.h" | |
| 46 | 39 |
| 47 namespace blink { | 40 namespace blink { |
| 48 | 41 |
| 49 class CSSStyleDeclaration; | 42 class CSSStyleDeclaration; |
| 50 class CSSComputedStyleDeclaration; | 43 class EditingStyle; |
| 51 class ContainerNode; | |
| 52 class Document; | |
| 53 class Element; | |
| 54 class HTMLElement; | |
| 55 class MutableStylePropertySet; | 44 class MutableStylePropertySet; |
| 56 class Node; | 45 class Node; |
| 57 class QualifiedName; | |
| 58 class ComputedStyle; | |
| 59 class StylePropertySet; | 46 class StylePropertySet; |
| 60 | 47 |
| 61 class CORE_EXPORT EditingStyle final : public GarbageCollected<EditingStyle> { | 48 class EditingStyleUtilities { |
| 49 STATIC_ONLY(EditingStyleUtilities); |
| 50 |
| 62 public: | 51 public: |
| 63 enum PropertiesToInclude { | |
| 64 AllProperties, | |
| 65 OnlyEditingInheritableProperties, | |
| 66 EditingPropertiesInEffect | |
| 67 }; | |
| 68 enum ShouldPreserveWritingDirection { | |
| 69 PreserveWritingDirection, | |
| 70 DoNotPreserveWritingDirection | |
| 71 }; | |
| 72 enum ShouldExtractMatchingStyle { | |
| 73 ExtractMatchingStyle, | |
| 74 DoNotExtractMatchingStyle | |
| 75 }; | |
| 76 static float NoFontDelta; | |
| 77 | |
| 78 static EditingStyle* create() { return new EditingStyle(); } | |
| 79 | |
| 80 static EditingStyle* create(ContainerNode* node, | |
| 81 PropertiesToInclude propertiesToInclude = | |
| 82 OnlyEditingInheritableProperties) { | |
| 83 return new EditingStyle(node, propertiesToInclude); | |
| 84 } | |
| 85 | |
| 86 static EditingStyle* create(const Position& position, | |
| 87 PropertiesToInclude propertiesToInclude = | |
| 88 OnlyEditingInheritableProperties) { | |
| 89 return new EditingStyle(position, propertiesToInclude); | |
| 90 } | |
| 91 | |
| 92 static EditingStyle* create(const StylePropertySet* style) { | |
| 93 return new EditingStyle(style); | |
| 94 } | |
| 95 | |
| 96 static EditingStyle* create(CSSPropertyID propertyID, const String& value) { | |
| 97 return new EditingStyle(propertyID, value); | |
| 98 } | |
| 99 | |
| 100 MutableStylePropertySet* style() { return m_mutableStyle.get(); } | |
| 101 bool textDirection(WritingDirection&) const; | |
| 102 bool isEmpty() const; | |
| 103 void overrideWithStyle(const StylePropertySet*); | |
| 104 void clear(); | |
| 105 EditingStyle* copy() const; | |
| 106 EditingStyle* extractAndRemoveBlockProperties(); | |
| 107 EditingStyle* extractAndRemoveTextDirection(); | |
| 108 void removeBlockProperties(); | |
| 109 void removeStyleAddedByElement(Element*); | |
| 110 void removeStyleConflictingWithStyleOfElement(Element*); | |
| 111 void collapseTextDecorationProperties(); | |
| 112 enum ShouldIgnoreTextOnlyProperties { | |
| 113 IgnoreTextOnlyProperties, | |
| 114 DoNotIgnoreTextOnlyProperties | |
| 115 }; | |
| 116 TriState triStateOfStyle(EditingStyle*) const; | |
| 117 TriState triStateOfStyle(const VisibleSelection&) const; | |
| 118 bool conflictsWithInlineStyleOfElement(HTMLElement* element) const { | |
| 119 return conflictsWithInlineStyleOfElement(element, 0, 0); | |
| 120 } | |
| 121 bool conflictsWithInlineStyleOfElement( | |
| 122 HTMLElement* element, | |
| 123 EditingStyle* extractedStyle, | |
| 124 Vector<CSSPropertyID>& conflictingProperties) const { | |
| 125 return conflictsWithInlineStyleOfElement(element, extractedStyle, | |
| 126 &conflictingProperties); | |
| 127 } | |
| 128 bool conflictsWithImplicitStyleOfElement( | |
| 129 HTMLElement*, | |
| 130 EditingStyle* extractedStyle = nullptr, | |
| 131 ShouldExtractMatchingStyle = DoNotExtractMatchingStyle) const; | |
| 132 bool conflictsWithImplicitStyleOfAttributes(HTMLElement*) const; | |
| 133 bool extractConflictingImplicitStyleOfAttributes( | |
| 134 HTMLElement*, | |
| 135 ShouldPreserveWritingDirection, | |
| 136 EditingStyle* extractedStyle, | |
| 137 Vector<QualifiedName>& conflictingAttributes, | |
| 138 ShouldExtractMatchingStyle) const; | |
| 139 bool styleIsPresentInComputedStyleOfNode(Node*) const; | |
| 140 | |
| 141 static bool elementIsStyledSpanOrHTMLEquivalent(const HTMLElement*); | |
| 142 | |
| 143 void prepareToApplyAt( | |
| 144 const Position&, | |
| 145 ShouldPreserveWritingDirection = DoNotPreserveWritingDirection); | |
| 146 void mergeTypingStyle(Document*); | |
| 147 enum CSSPropertyOverrideMode { OverrideValues, DoNotOverrideValues }; | |
| 148 void mergeInlineStyleOfElement(HTMLElement*, | |
| 149 CSSPropertyOverrideMode, | |
| 150 PropertiesToInclude = AllProperties); | |
| 151 static EditingStyle* wrappingStyleForAnnotatedSerialization( | 52 static EditingStyle* wrappingStyleForAnnotatedSerialization( |
| 152 ContainerNode* context); | 53 ContainerNode* context); |
| 153 static EditingStyle* wrappingStyleForSerialization(ContainerNode* context); | 54 static EditingStyle* wrappingStyleForSerialization(ContainerNode* context); |
| 154 void mergeStyleFromRules(Element*); | |
| 155 void mergeStyleFromRulesForSerialization(Element*); | |
| 156 void removeStyleFromRulesAndContext(Element*, ContainerNode* context); | |
| 157 void removePropertiesInElementDefaultStyle(Element*); | |
| 158 void addAbsolutePositioningFromElement(const Element&); | |
| 159 void forceInline(); | |
| 160 int legacyFontSize(Document*) const; | |
| 161 | |
| 162 float fontSizeDelta() const { return m_fontSizeDelta; } | |
| 163 bool hasFontSizeDelta() const { return m_fontSizeDelta != NoFontDelta; } | |
| 164 | |
| 165 static EditingStyle* styleAtSelectionStart( | 55 static EditingStyle* styleAtSelectionStart( |
| 166 const VisibleSelection&, | 56 const VisibleSelection&, |
| 167 bool shouldUseBackgroundColorInEffect = false, | 57 bool shouldUseBackgroundColorInEffect = false, |
| 168 MutableStylePropertySet* styleToCheck = nullptr); | 58 MutableStylePropertySet* styleToCheck = nullptr); |
| 169 static WritingDirection textDirectionForSelection( | 59 static WritingDirection textDirectionForSelection( |
| 170 const VisibleSelection&, | 60 const VisibleSelection&, |
| 171 EditingStyle* typingStyle, | 61 EditingStyle* typingStyle, |
| 172 bool& hasNestedOrMultipleEmbeddings); | 62 bool& hasNestedOrMultipleEmbeddings); |
| 173 static bool isEmbedOrIsolate(CSSValueID unicodeBidi) { | 63 static bool isEmbedOrIsolate(CSSValueID unicodeBidi) { |
| 174 return unicodeBidi == CSSValueIsolate || | 64 return unicodeBidi == CSSValueIsolate || |
| 175 unicodeBidi == CSSValueWebkitIsolate || unicodeBidi == CSSValueEmbed; | 65 unicodeBidi == CSSValueWebkitIsolate || unicodeBidi == CSSValueEmbed; |
| 176 } | 66 } |
| 177 | 67 |
| 178 DECLARE_TRACE(); | 68 static bool isTransparentColorValue(const CSSValue*); |
| 179 | 69 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); |
| 180 private: | 70 static bool hasTransparentBackgroundColor(StylePropertySet*); |
| 181 EditingStyle() = default; | 71 static const CSSValue* backgroundColorValueInEffect(Node*); |
| 182 EditingStyle(ContainerNode*, PropertiesToInclude); | 72 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID); |
| 183 EditingStyle(const Position&, PropertiesToInclude); | |
| 184 explicit EditingStyle(const StylePropertySet*); | |
| 185 EditingStyle(CSSPropertyID, const String& value); | |
| 186 void init(Node*, PropertiesToInclude); | |
| 187 void removeInheritedColorsIfNeeded(const ComputedStyle*); | |
| 188 void setProperty(CSSPropertyID, const String& value, bool important = false); | |
| 189 void replaceFontSizeByKeywordIfPossible(const ComputedStyle*, | |
| 190 CSSComputedStyleDeclaration*); | |
| 191 void extractFontSizeDelta(); | |
| 192 TriState triStateOfStyle(CSSStyleDeclaration* styleToCompare, | |
| 193 ShouldIgnoreTextOnlyProperties) const; | |
| 194 bool conflictsWithInlineStyleOfElement( | |
| 195 HTMLElement*, | |
| 196 EditingStyle* extractedStyle, | |
| 197 Vector<CSSPropertyID>* conflictingProperties) const; | |
| 198 void mergeInlineAndImplicitStyleOfElement(Element*, | |
| 199 CSSPropertyOverrideMode, | |
| 200 PropertiesToInclude); | |
| 201 void mergeStyle(const StylePropertySet*, CSSPropertyOverrideMode); | |
| 202 | |
| 203 Member<MutableStylePropertySet> m_mutableStyle; | |
| 204 bool m_isMonospaceFont = false; | |
| 205 float m_fontSizeDelta = NoFontDelta; | |
| 206 bool m_isVerticalAlign = false; | |
| 207 | |
| 208 friend class HTMLElementEquivalent; | |
| 209 friend class HTMLAttributeEquivalent; | |
| 210 }; | 73 }; |
| 211 | 74 |
| 212 class StyleChange { | |
| 213 DISALLOW_NEW(); | |
| 214 | |
| 215 public: | |
| 216 StyleChange() | |
| 217 : m_applyBold(false), | |
| 218 m_applyItalic(false), | |
| 219 m_applyUnderline(false), | |
| 220 m_applyLineThrough(false), | |
| 221 m_applySubscript(false), | |
| 222 m_applySuperscript(false) {} | |
| 223 | |
| 224 StyleChange(EditingStyle*, const Position&); | |
| 225 | |
| 226 String cssStyle() const { return m_cssStyle; } | |
| 227 bool applyBold() const { return m_applyBold; } | |
| 228 bool applyItalic() const { return m_applyItalic; } | |
| 229 bool applyUnderline() const { return m_applyUnderline; } | |
| 230 bool applyLineThrough() const { return m_applyLineThrough; } | |
| 231 bool applySubscript() const { return m_applySubscript; } | |
| 232 bool applySuperscript() const { return m_applySuperscript; } | |
| 233 bool applyFontColor() const { return m_applyFontColor.length() > 0; } | |
| 234 bool applyFontFace() const { return m_applyFontFace.length() > 0; } | |
| 235 bool applyFontSize() const { return m_applyFontSize.length() > 0; } | |
| 236 | |
| 237 String fontColor() { return m_applyFontColor; } | |
| 238 String fontFace() { return m_applyFontFace; } | |
| 239 String fontSize() { return m_applyFontSize; } | |
| 240 | |
| 241 bool operator==(const StyleChange& other) { | |
| 242 return m_cssStyle == other.m_cssStyle && m_applyBold == other.m_applyBold && | |
| 243 m_applyItalic == other.m_applyItalic && | |
| 244 m_applyUnderline == other.m_applyUnderline && | |
| 245 m_applyLineThrough == other.m_applyLineThrough && | |
| 246 m_applySubscript == other.m_applySubscript && | |
| 247 m_applySuperscript == other.m_applySuperscript && | |
| 248 m_applyFontColor == other.m_applyFontColor && | |
| 249 m_applyFontFace == other.m_applyFontFace && | |
| 250 m_applyFontSize == other.m_applyFontSize; | |
| 251 } | |
| 252 bool operator!=(const StyleChange& other) { return !(*this == other); } | |
| 253 | |
| 254 private: | |
| 255 void extractTextStyles(Document*, | |
| 256 MutableStylePropertySet*, | |
| 257 bool isMonospaceFont); | |
| 258 | |
| 259 String m_cssStyle; | |
| 260 bool m_applyBold; | |
| 261 bool m_applyItalic; | |
| 262 bool m_applyUnderline; | |
| 263 bool m_applyLineThrough; | |
| 264 bool m_applySubscript; | |
| 265 bool m_applySuperscript; | |
| 266 String m_applyFontColor; | |
| 267 String m_applyFontFace; | |
| 268 String m_applyFontSize; | |
| 269 }; | |
| 270 | |
| 271 // FIXME: Remove these functions or make them non-global to discourage using | |
| 272 // CSSStyleDeclaration directly. | |
| 273 CSSValueID getIdentifierValue(CSSStyleDeclaration*, CSSPropertyID); | |
| 274 CSSValueID getIdentifierValue(StylePropertySet*, CSSPropertyID); | |
| 275 | |
| 276 } // namespace blink | 75 } // namespace blink |
| 277 | 76 |
| 278 #endif // EditingStyleUtilities_h | 77 #endif // EditingStyleUtilities_h |
| OLD | NEW |