2011-02-22 Ryosuke Niwa <rniwa@webkit.org>
[WebKit-https.git] / Source / WebCore / editing / EditingStyle.cpp
index 191234c..507b376 100644 (file)
 #include "CSSMutableStyleDeclaration.h"
 #include "CSSValueKeywords.h"
 #include "Frame.h"
+#include "HTMLNames.h"
 #include "Node.h"
 #include "Position.h"
 #include "RenderStyle.h"
 #include "SelectionController.h"
+#include "StyledElement.h"
+#include "htmlediting.h"
 
 namespace WebCore {
 
@@ -322,6 +325,46 @@ void EditingStyle::collapseTextDecorationProperties()
     m_mutableStyle->removeProperty(CSSPropertyWebkitTextDecorationsInEffect);
 }
 
+bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement* element, Vector<CSSPropertyID>* conflictingProperties) const
+{
+    ASSERT(element);
+    ASSERT(!conflictingProperties || conflictingProperties->isEmpty());
+
+    CSSMutableStyleDeclaration* inlineStyle = element->inlineStyleDecl();
+    if (!m_mutableStyle || !inlineStyle)
+        return false;
+
+    if (!conflictingProperties) {
+        CSSMutableStyleDeclaration::const_iterator end = m_mutableStyle->end();
+        for (CSSMutableStyleDeclaration::const_iterator it = m_mutableStyle->begin(); it != end; ++it) {
+            CSSPropertyID propertyID = static_cast<CSSPropertyID>(it->id());
+
+            // We don't override whitespace property of a tab span because that would collapse the tab into a space.
+            if (propertyID == CSSPropertyWhiteSpace && isTabSpanNode(element))
+                continue;
+
+            if (inlineStyle->getPropertyCSSValue(propertyID))
+                return true;
+        }
+
+        return false;
+    }
+
+    CSSMutableStyleDeclaration::const_iterator end = m_mutableStyle->end();
+    for (CSSMutableStyleDeclaration::const_iterator it = m_mutableStyle->begin(); it != end; ++it) {
+        CSSPropertyID propertyID = static_cast<CSSPropertyID>(it->id());
+        if ((propertyID == CSSPropertyWhiteSpace && isTabSpanNode(element)) || !inlineStyle->getPropertyCSSValue(propertyID))
+            continue;
+
+        if (propertyID == CSSPropertyUnicodeBidi && inlineStyle->getPropertyCSSValue(CSSPropertyDirection))
+            conflictingProperties->append(CSSPropertyDirection);
+
+        conflictingProperties->append(propertyID);
+    }
+
+    return !conflictingProperties->isEmpty();
+}
+
 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWritingDirection shouldPreserveWritingDirection)
 {
     if (!m_mutableStyle)