diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
commit | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (patch) | |
tree | b34b0daceb7c8e7fdde4b4ec43650ab7caadb0a9 /Source/WebCore/editing/EditingStyle.cpp | |
parent | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (diff) | |
download | qtwebkit-ad0d549d4cc13433f77c1ac8f0ab379c83d93f28.tar.gz |
Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790)
Diffstat (limited to 'Source/WebCore/editing/EditingStyle.cpp')
-rw-r--r-- | Source/WebCore/editing/EditingStyle.cpp | 103 |
1 files changed, 94 insertions, 9 deletions
diff --git a/Source/WebCore/editing/EditingStyle.cpp b/Source/WebCore/editing/EditingStyle.cpp index 98224f243..57291c1f5 100644 --- a/Source/WebCore/editing/EditingStyle.cpp +++ b/Source/WebCore/editing/EditingStyle.cpp @@ -378,7 +378,7 @@ void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) else if (isTabSpanNode(node)) node = node->parentNode(); - RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = computedStyle(node); + RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedStyleDeclaration::create(node); m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosition ? computedStyleAtPosition->copy() : editingStyleFromComputedStyle(computedStyleAtPosition); if (propertiesToInclude == EditingPropertiesInEffect) { @@ -558,8 +558,8 @@ void EditingStyle::removeStyleAddedByNode(Node* node) { if (!node || !node->parentNode()) return; - RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(computedStyle(node->parentNode()), AllEditingProperties); - RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(computedStyle(node), AllEditingProperties); + RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties); + RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node), AllEditingProperties); nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration()); m_mutableStyle->removeEquivalentProperties(nodeStyle->ensureCSSStyleDeclaration()); } @@ -569,8 +569,8 @@ void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node) if (!node || !node->parentNode() || !m_mutableStyle) return; - RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(computedStyle(node->parentNode()), AllEditingProperties); - RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(computedStyle(node), AllEditingProperties); + RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties); + RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComputedStyleDeclaration::create(node), AllEditingProperties); nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration()); unsigned propertyCount = nodeStyle->propertyCount(); @@ -641,7 +641,7 @@ TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const TriState state = FalseTriState; for (Node* node = selection.start().deprecatedNode(); node; node = node->traverseNextNode()) { - RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node); + RefPtr<CSSComputedStyleDeclaration> nodeStyle = CSSComputedStyleDeclaration::create(node); if (nodeStyle) { TriState nodeState = triStateOfStyle(nodeStyle.get(), node->isTextNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTextOnlyProperties); if (node == selection.start().deprecatedNode()) @@ -813,7 +813,7 @@ bool EditingStyle::extractConflictingImplicitStyleOfAttributes(HTMLElement* elem bool EditingStyle::styleIsPresentInComputedStyleOfNode(Node* node) const { - return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), computedStyle(node).get())->isEmpty(); + return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), CSSComputedStyleDeclaration::create(node).get())->isEmpty(); } bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* element) @@ -1061,7 +1061,7 @@ void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement* element) // The property value, if it's a percentage, may not reflect the actual computed value. // For example: style="height: 1%; overflow: visible;" in quirksmode // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot copy/paste fidelity problem - RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = computedStyle(element); + RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedStyleDeclaration::create(element); RefPtr<StylePropertySet> fromComputedStyle = StylePropertySet::create(); { unsigned propertyCount = m_mutableStyle->propertyCount(); @@ -1182,6 +1182,91 @@ PassRefPtr<EditingStyle> EditingStyle::styleAtSelectionStart(const VisibleSelect return style; } +WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection& selection, EditingStyle* typingStyle, bool& hasNestedOrMultipleEmbeddings) +{ + hasNestedOrMultipleEmbeddings = true; + + if (selection.isNone()) + return NaturalWritingDirection; + + Position position = selection.start().downstream(); + + Node* node = position.deprecatedNode(); + if (!node) + return NaturalWritingDirection; + + Position end; + if (selection.isRange()) { + end = selection.end().upstream(); + + Node* pastLast = Range::create(end.document(), position.parentAnchoredEquivalent(), end.parentAnchoredEquivalent())->pastLastNode(); + for (Node* n = node; n && n != pastLast; n = n->traverseNextNode()) { + if (!n->isStyledElement()) + continue; + + RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(n); + RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi); + if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) + continue; + + int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent(); + if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValueBidiOverride) + return NaturalWritingDirection; + } + } + + if (selection.isCaret()) { + WritingDirection direction; + if (typingStyle && typingStyle->textDirection(direction)) { + hasNestedOrMultipleEmbeddings = false; + return direction; + } + node = selection.visibleStart().deepEquivalent().deprecatedNode(); + } + + // The selection is either a caret with no typing attributes or a range in which no embedding is added, so just use the start position + // to decide. + Node* block = enclosingBlock(node); + WritingDirection foundDirection = NaturalWritingDirection; + + for (; node != block; node = node->parentNode()) { + if (!node->isStyledElement()) + continue; + + RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(node); + RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi); + if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) + continue; + + int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent(); + if (unicodeBidiValue == CSSValueNormal) + continue; + + if (unicodeBidiValue == CSSValueBidiOverride) + return NaturalWritingDirection; + + ASSERT(unicodeBidiValue == CSSValueEmbed); + RefPtr<CSSValue> direction = style->getPropertyCSSValue(CSSPropertyDirection); + if (!direction || !direction->isPrimitiveValue()) + continue; + + int directionValue = static_cast<CSSPrimitiveValue*>(direction.get())->getIdent(); + if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) + continue; + + if (foundDirection != NaturalWritingDirection) + 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)) + return NaturalWritingDirection; + + foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; + } + hasNestedOrMultipleEmbeddings = false; + return foundDirection; +} + static void reconcileTextDecorationProperties(StylePropertySet* style) { RefPtr<CSSValue> textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect); @@ -1487,7 +1572,7 @@ bool hasTransparentBackgroundColor(StylePropertySet* style) PassRefPtr<CSSValue> backgroundColorInEffect(Node* node) { for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { - RefPtr<CSSComputedStyleDeclaration> ancestorStyle = computedStyle(ancestor); + RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDeclaration::create(ancestor); if (!hasTransparentBackgroundColor(ancestorStyle.get())) return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); } |