summaryrefslogtreecommitdiff
path: root/Source/WebCore/editing/EditingStyle.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-06-20 13:01:08 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-06-20 13:01:08 +0200
commit49233e234e5c787396cadb2cea33b31ae0cd65c1 (patch)
tree5410cb9a8fd53168bb60d62c54b654d86f03c38d /Source/WebCore/editing/EditingStyle.cpp
parentb211c645d8ab690f713515dfdc84d80b11c27d2c (diff)
downloadqtwebkit-49233e234e5c787396cadb2cea33b31ae0cd65c1.tar.gz
Imported WebKit commit 3a8c29f35d00659d2ce7a0ccdfa8304f14e82327 (http://svn.webkit.org/repository/webkit/trunk@120813)
New snapshot with Windows build fixes
Diffstat (limited to 'Source/WebCore/editing/EditingStyle.cpp')
-rw-r--r--Source/WebCore/editing/EditingStyle.cpp77
1 files changed, 41 insertions, 36 deletions
diff --git a/Source/WebCore/editing/EditingStyle.cpp b/Source/WebCore/editing/EditingStyle.cpp
index d14a903fe..0ea0a254f 100644
--- a/Source/WebCore/editing/EditingStyle.cpp
+++ b/Source/WebCore/editing/EditingStyle.cpp
@@ -373,6 +373,34 @@ static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
return cssValueToRGBA(backgroundColorInEffect(node).get());
}
+static int textAlignResolvingStartAndEnd(int textAlign, int direction)
+{
+ switch (textAlign) {
+ case CSSValueCenter:
+ case CSSValueWebkitCenter:
+ return CSSValueCenter;
+ case CSSValueJustify:
+ return CSSValueJustify;
+ case CSSValueLeft:
+ case CSSValueWebkitLeft:
+ return CSSValueLeft;
+ case CSSValueRight:
+ case CSSValueWebkitRight:
+ return CSSValueRight;
+ case CSSValueStart:
+ return direction != CSSValueRtl ? CSSValueLeft : CSSValueRight;
+ case CSSValueEnd:
+ return direction == CSSValueRtl ? CSSValueRight : CSSValueLeft;
+ }
+ return CSSValueInvalid;
+}
+
+template<typename T>
+static int textAlignResolvingStartAndEnd(T* style)
+{
+ return textAlignResolvingStartAndEnd(getIdentifierValue(style, CSSPropertyTextAlign), getIdentifierValue(style, CSSPropertyDirection));
+}
+
void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude)
{
if (isTabSpanTextNode(node))
@@ -501,7 +529,7 @@ void EditingStyle::overrideWithStyle(const StylePropertySet* style)
return;
if (!m_mutableStyle)
m_mutableStyle = StylePropertySet::create();
- m_mutableStyle->merge(style);
+ m_mutableStyle->mergeAndOverrideOnConflict(style);
extractFontSizeDelta();
}
@@ -874,7 +902,8 @@ void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit
// ReplaceSelectionCommand::handleStyleSpans() requires that this function only removes the editing style.
// If this function was modified in the future to delete all redundant properties, then add a boolean value to indicate
// which one of editingStyleAtPosition or computedStyle is called.
- RefPtr<EditingStyle> style = EditingStyle::create(position, EditingPropertiesInEffect);
+ RefPtr<EditingStyle> editingStyleAtPosition = EditingStyle::create(position, EditingPropertiesInEffect);
+ StylePropertySet* styleAtPosition = editingStyleAtPosition->m_mutableStyle.get();
RefPtr<CSSValue> unicodeBidi;
RefPtr<CSSValue> direction;
@@ -883,9 +912,12 @@ void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit
direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
}
- m_mutableStyle->removeEquivalentProperties(style->m_mutableStyle.get());
+ m_mutableStyle->removeEquivalentProperties(styleAtPosition);
- if (getRGBAFontColor(m_mutableStyle.get()) == getRGBAFontColor(style->m_mutableStyle.get()))
+ if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvingStartAndEnd(styleAtPosition))
+ m_mutableStyle->removeProperty(CSSPropertyTextAlign);
+
+ if (getRGBAFontColor(m_mutableStyle.get()) == getRGBAFontColor(styleAtPosition))
m_mutableStyle->removeProperty(CSSPropertyColor);
if (hasTransparentBackgroundColor(m_mutableStyle.get())
@@ -1034,7 +1066,7 @@ static PassRefPtr<StylePropertySet> styleFromMatchedRulesForElement(Element* ele
if (matchedRules) {
for (unsigned i = 0; i < matchedRules->length(); i++) {
if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE)
- style->merge(static_cast<CSSStyleRule*>(matchedRules->item(i))->styleRule()->properties(), true);
+ style->mergeAndOverrideOnConflict(static_cast<CSSStyleRule*>(matchedRules->item(i))->styleRule()->properties());
}
}
@@ -1048,7 +1080,7 @@ void EditingStyle::mergeStyleFromRules(StyledElement* element)
// Styles from the inline style declaration, held in the variable "style", take precedence
// over those from matched rules.
if (m_mutableStyle)
- styleFromMatchedRules->merge(m_mutableStyle.get());
+ styleFromMatchedRules->mergeAndOverrideOnConflict(m_mutableStyle.get());
clear();
m_mutableStyle = styleFromMatchedRules;
@@ -1076,7 +1108,7 @@ void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement* element)
}
}
}
- m_mutableStyle->merge(fromComputedStyle.get());
+ m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle.get());
}
static void removePropertiesInStyle(StylePropertySet* styleToRemovePropertiesFrom, StylePropertySet* style)
@@ -1451,34 +1483,6 @@ static bool fontWeightIsBold(StylePropertySet* style)
return fontWeightIsBold(fontWeight.get());
}
-static int getTextAlignment(int textAlignIdentifierValue)
-{
- switch (textAlignIdentifierValue) {
- case CSSValueCenter:
- case CSSValueWebkitCenter:
- return CSSValueCenter;
- case CSSValueJustify:
- return CSSValueJustify;
- case CSSValueLeft:
- case CSSValueWebkitLeft:
- return CSSValueLeft;
- case CSSValueRight:
- case CSSValueWebkitRight:
- return CSSValueRight;
- }
- return CSSValueInvalid;
-}
-
-static int getTextAlignment(CSSStyleDeclaration* style)
-{
- return getTextAlignment(getIdentifierValue(style, CSSPropertyTextAlign));
-}
-
-static int getTextAlignment(StylePropertySet* style)
-{
- return getTextAlignment(getIdentifierValue(style, CSSPropertyTextAlign));
-}
-
PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle)
{
ASSERT(styleWithRedundantProperties);
@@ -1497,7 +1501,8 @@ PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWithRedun
if (baseStyle->getPropertyCSSValueInternal(CSSPropertyColor) && getRGBAFontColor(result.get()) == getRGBAFontColor(baseStyle))
result->removeProperty(CSSPropertyColor);
- if (baseStyle->getPropertyCSSValueInternal(CSSPropertyTextAlign) && getTextAlignment(result.get()) == getTextAlignment(baseStyle))
+ if (baseStyle->getPropertyCSSValueInternal(CSSPropertyTextAlign)
+ && textAlignResolvingStartAndEnd(result.get()) == textAlignResolvingStartAndEnd(baseStyle))
result->removeProperty(CSSPropertyTextAlign);
return result;