Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: Source/core/editing/EditingStyle.cpp

Issue 423673002: Use tighter typing in editing: EditingStyle (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/EditingStyle.cpp
diff --git a/Source/core/editing/EditingStyle.cpp b/Source/core/editing/EditingStyle.cpp
index 5c45b7a9aebca45930aa9adf4c5f530e4a59c1b9..6f3133144c4265eaacd1e5b45e60957ce316b6f8 100644
--- a/Source/core/editing/EditingStyle.cpp
+++ b/Source/core/editing/EditingStyle.cpp
@@ -163,11 +163,11 @@ public:
return adoptPtrWillBeNoop(new HTMLElementEquivalent(propertyID, primitiveValue, tagName));
}
- virtual bool matches(const Element* element) const { return !m_tagName || element->hasTagName(*m_tagName); }
+ virtual bool matches(const HTMLElement* element) const { return !m_tagName || element->hasTagName(*m_tagName); }
virtual bool hasAttribute() const { return false; }
virtual bool propertyExistsInStyle(const StylePropertySet* style) const { return style->getPropertyCSSValue(m_propertyID); }
- virtual bool valueIsPresentInStyle(Element*, StylePropertySet*) const;
- virtual void addToStyle(Element*, EditingStyle*) const;
+ virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const;
+ virtual void addToStyle(HTMLElement*, EditingStyle*) const;
virtual void trace(Visitor* visitor) { visitor->trace(m_primitiveValue); }
@@ -202,13 +202,13 @@ HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit
ASSERT(primitiveValue != CSSValueInvalid);
}
-bool HTMLElementEquivalent::valueIsPresentInStyle(Element* element, StylePropertySet* style) const
+bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePropertySet* style) const
{
RefPtrWillBeRawPtr<CSSValue> value = style->getPropertyCSSValue(m_propertyID);
return matches(element) && value && value->isPrimitiveValue() && toCSSPrimitiveValue(value.get())->getValueID() == m_primitiveValue->getValueID();
}
-void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
+void HTMLElementEquivalent::addToStyle(HTMLElement*, EditingStyle* style) const
{
style->setProperty(m_propertyID, m_primitiveValue->cssText());
}
@@ -220,7 +220,7 @@ public:
return adoptPtrWillBeNoop(new HTMLTextDecorationEquivalent(primitiveValue, tagName));
}
virtual bool propertyExistsInStyle(const StylePropertySet*) const OVERRIDE;
- virtual bool valueIsPresentInStyle(Element*, StylePropertySet*) const OVERRIDE;
+ virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const OVERRIDE;
virtual void trace(Visitor* visitor) OVERRIDE { HTMLElementEquivalent::trace(visitor); }
@@ -240,7 +240,7 @@ bool HTMLTextDecorationEquivalent::propertyExistsInStyle(const StylePropertySet*
|| style->getPropertyCSSValue(textDecorationPropertyForEditing());
}
-bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, StylePropertySet* style) const
+bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePropertySet* style) const
{
RefPtrWillBeRawPtr<CSSValue> styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
if (!styleValue)
@@ -259,11 +259,11 @@ public:
return adoptPtrWillBeNoop(new HTMLAttributeEquivalent(propertyID, attrName));
}
- virtual bool matches(const Element* elem) const OVERRIDE { return HTMLElementEquivalent::matches(elem) && elem->hasAttribute(m_attrName); }
+ virtual bool matches(const HTMLElement* element) const OVERRIDE { return HTMLElementEquivalent::matches(element) && element->hasAttribute(m_attrName); }
virtual bool hasAttribute() const OVERRIDE { return true; }
- virtual bool valueIsPresentInStyle(Element*, StylePropertySet*) const OVERRIDE;
- virtual void addToStyle(Element*, EditingStyle*) const OVERRIDE;
- virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(Element*) const;
+ virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const OVERRIDE;
+ virtual void addToStyle(HTMLElement*, EditingStyle*) const OVERRIDE;
+ virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(HTMLElement*) const;
inline const QualifiedName& attributeName() const { return m_attrName; }
virtual void trace(Visitor* visitor) OVERRIDE { HTMLElementEquivalent::trace(visitor); }
@@ -286,7 +286,7 @@ HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const Qualifi
{
}
-bool HTMLAttributeEquivalent::valueIsPresentInStyle(Element* element, StylePropertySet* style) const
+bool HTMLAttributeEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePropertySet* style) const
{
RefPtrWillBeRawPtr<CSSValue> value = attributeValueAsCSSValue(element);
RefPtrWillBeRawPtr<CSSValue> styleValue = style->getPropertyCSSValue(m_propertyID);
@@ -294,13 +294,13 @@ bool HTMLAttributeEquivalent::valueIsPresentInStyle(Element* element, StylePrope
return compareCSSValuePtr(value, styleValue);
}
-void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const
+void HTMLAttributeEquivalent::addToStyle(HTMLElement* element, EditingStyle* style) const
{
if (RefPtrWillBeRawPtr<CSSValue> value = attributeValueAsCSSValue(element))
style->setProperty(m_propertyID, value->cssText());
}
-PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) const
+PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(HTMLElement* element) const
{
ASSERT(element);
const AtomicString& value = element->getAttribute(m_attrName);
@@ -319,7 +319,7 @@ public:
{
return adoptPtrWillBeNoop(new HTMLFontSizeEquivalent());
}
- virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(Element*) const OVERRIDE;
+ virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(HTMLElement*) const OVERRIDE;
virtual void trace(Visitor* visitor) OVERRIDE { HTMLAttributeEquivalent::trace(visitor); }
@@ -332,7 +332,7 @@ HTMLFontSizeEquivalent::HTMLFontSizeEquivalent()
{
}
-PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) const
+PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValue(HTMLElement* element) const
{
ASSERT(element);
const AtomicString& value = element->getAttribute(m_attrName);
@@ -352,7 +352,7 @@ EditingStyle::EditingStyle()
{
}
-EditingStyle::EditingStyle(Node* node, PropertiesToInclude propertiesToInclude)
+EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesToInclude)
: m_fixedPitchFontType(NonFixedPitchFont)
, m_fontSizeDelta(NoFontDelta)
{
@@ -627,23 +627,23 @@ void EditingStyle::removeBlockProperties()
m_mutableStyle->removeBlockProperties();
}
-void EditingStyle::removeStyleAddedByNode(Node* node)
+void EditingStyle::removeStyleAddedByElement(Element* element)
{
- if (!node || !node->parentNode())
+ if (!element || !element->parentNode())
return;
- RefPtrWillBeRawPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties);
- RefPtrWillBeRawPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node), AllEditingProperties);
+ RefPtrWillBeRawPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(element->parentNode()), AllEditingProperties);
+ RefPtrWillBeRawPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(element), AllEditingProperties);
nodeStyle->removeEquivalentProperties(parentStyle.get());
m_mutableStyle->removeEquivalentProperties(nodeStyle.get());
}
-void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node)
+void EditingStyle::removeStyleConflictingWithStyleOfElement(Element* element)
{
- if (!node || !node->parentNode() || !m_mutableStyle)
+ if (!element || !element->parentNode() || !m_mutableStyle)
return;
- RefPtrWillBeRawPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties);
- RefPtrWillBeRawPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node), AllEditingProperties);
+ RefPtrWillBeRawPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(element->parentNode()), AllEditingProperties);
+ RefPtrWillBeRawPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(element), AllEditingProperties);
nodeStyle->removeEquivalentProperties(parentStyle.get());
unsigned propertyCount = nodeStyle->propertyCount();
@@ -732,7 +732,7 @@ TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const
return state;
}
-bool EditingStyle::conflictsWithInlineStyleOfElement(Element* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const
+bool EditingStyle::conflictsWithInlineStyleOfElement(HTMLElement* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const
{
ASSERT(element);
ASSERT(!conflictingProperties || conflictingProperties->isEmpty());
@@ -989,7 +989,7 @@ void EditingStyle::mergeTypingStyle(Document* document)
mergeStyle(typingStyle->style(), OverrideValues);
}
-void EditingStyle::mergeInlineStyleOfElement(Element* element, CSSPropertyOverrideMode mode, PropertiesToInclude propertiesToInclude)
+void EditingStyle::mergeInlineStyleOfElement(HTMLElement* element, CSSPropertyOverrideMode mode, PropertiesToInclude propertiesToInclude)
{
ASSERT(element);
if (!element->inlineStyle())
@@ -1008,7 +1008,7 @@ void EditingStyle::mergeInlineStyleOfElement(Element* element, CSSPropertyOverri
}
}
-static inline bool elementMatchesAndPropertyIsNotInInlineStyleDecl(const HTMLElementEquivalent* equivalent, const Element* element,
+static inline bool elementMatchesAndPropertyIsNotInInlineStyleDecl(const HTMLElementEquivalent* equivalent, const HTMLElement* element,
EditingStyle::CSSPropertyOverrideMode mode, StylePropertySet* style)
{
return equivalent->matches(element) && (!element->inlineStyle() || !equivalent->propertyExistsInStyle(element->inlineStyle()))
@@ -1043,22 +1043,26 @@ void EditingStyle::mergeInlineAndImplicitStyleOfElement(Element* element, CSSPro
styleFromRules->m_mutableStyle = extractEditingProperties(styleFromRules->m_mutableStyle.get(), propertiesToInclude);
mergeStyle(styleFromRules->m_mutableStyle.get(), mode);
+ if (!element->isHTMLElement())
pdr. 2014/07/29 22:33:14 Nit: Unlike the other cases, this seems like it co
Inactive 2014/07/29 23:14:59 Ok, I'll drop this part of this change.
Inactive 2014/07/29 23:34:33 Done.
+ return;
+
+ HTMLElement* htmlElement = toHTMLElement(element);
const WillBeHeapVector<OwnPtrWillBeMember<HTMLElementEquivalent> >& elementEquivalents = htmlElementEquivalents();
for (size_t i = 0; i < elementEquivalents.size(); ++i) {
- if (elementMatchesAndPropertyIsNotInInlineStyleDecl(elementEquivalents[i].get(), element, mode, m_mutableStyle.get()))
- elementEquivalents[i]->addToStyle(element, this);
+ if (elementMatchesAndPropertyIsNotInInlineStyleDecl(elementEquivalents[i].get(), htmlElement, mode, m_mutableStyle.get()))
+ elementEquivalents[i]->addToStyle(htmlElement, this);
}
const WillBeHeapVector<OwnPtrWillBeMember<HTMLAttributeEquivalent> >& attributeEquivalents = htmlAttributeEquivalents();
for (size_t i = 0; i < attributeEquivalents.size(); ++i) {
if (attributeEquivalents[i]->attributeName() == HTMLNames::dirAttr)
continue; // We don't want to include directionality
- if (elementMatchesAndPropertyIsNotInInlineStyleDecl(attributeEquivalents[i].get(), element, mode, m_mutableStyle.get()))
- attributeEquivalents[i]->addToStyle(element, this);
+ if (elementMatchesAndPropertyIsNotInInlineStyleDecl(attributeEquivalents[i].get(), htmlElement, mode, m_mutableStyle.get()))
+ attributeEquivalents[i]->addToStyle(htmlElement, this);
}
}
-PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::wrappingStyleForSerialization(Node* context, bool shouldAnnotate)
+PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::wrappingStyleForSerialization(ContainerNode* context, bool shouldAnnotate)
{
RefPtrWillBeRawPtr<EditingStyle> wrappingStyle = nullptr;
if (shouldAnnotate) {
@@ -1067,7 +1071,7 @@ PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::wrappingStyleForSerialization
// Styles that Mail blockquotes contribute should only be placed on the Mail blockquote,
// to help us differentiate those styles from ones that the user has applied.
// This helps us get the color of content pasted into blockquotes right.
- wrappingStyle->removeStyleAddedByNode(enclosingNodeOfType(firstPositionInOrBeforeNode(context), isMailBlockquote, CanCrossEditingBoundary));
+ wrappingStyle->removeStyleAddedByElement(toHTMLElement(enclosingNodeOfType(firstPositionInOrBeforeNode(context), isMailBlockquote, CanCrossEditingBoundary)));
// Call collapseTextDecorationProperties first or otherwise it'll copy the value over from in-effect to text-decorations.
wrappingStyle->collapseTextDecorationProperties();
@@ -1078,7 +1082,7 @@ PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::wrappingStyleForSerialization
wrappingStyle = EditingStyle::create();
// When not annotating for interchange, we only preserve inline style declarations.
- for (Node* node = context; node && !node->isDocumentNode(); node = node->parentNode()) {
+ for (ContainerNode* node = context; node && !node->isDocumentNode(); node = node->parentNode()) {
if (node->isStyledElement() && !isMailBlockquote(node)) {
wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(node), EditingStyle::DoNotOverrideValues,
EditingStyle::EditingPropertiesInEffect);
@@ -1188,7 +1192,7 @@ static void removePropertiesInStyle(MutableStylePropertySet* styleToRemoveProper
styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data(), propertiesToRemove.size());
}
-void EditingStyle::removeStyleFromRulesAndContext(Element* element, Node* context)
+void EditingStyle::removeStyleFromRulesAndContext(Element* element, ContainerNode* context)
{
ASSERT(element);
if (!m_mutableStyle)
@@ -1357,7 +1361,8 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
if (!node->isStyledElement())
continue;
- RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(node);
+ Element* element = toElement(node);
+ RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(element);
RefPtrWillBeRawPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
continue;
@@ -1382,7 +1387,7 @@ WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection&
return NaturalWritingDirection;
// In the range case, make sure that the embedding element persists until the end of the range.
- if (selection.isRange() && !end.deprecatedNode()->isDescendantOf(node))
+ if (selection.isRange() && !end.deprecatedNode()->isDescendantOf(element))
return NaturalWritingDirection;
foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;

Powered by Google App Engine
This is Rietveld 408576698