Commit 2da9b7ad authored by inferno@chromium.org's avatar inferno@chromium.org

2011-03-30 Abhishek Arya <inferno@chromium.org>

        Reviewed by Simon Fraser.

        Tests that we do not crash when removing inline style
        from a node that is not a html element.
        https://bugs.webkit.org/show_bug.cgi?id=57348

        * editing/execCommand/remove-format-non-html-element-crash-expected.txt: Added.
        * editing/execCommand/remove-format-non-html-element-crash.html: Added.
2011-03-30  Abhishek Arya  <inferno@chromium.org>

        Reviewed by Simon Fraser.

        Fix wrong type assumptions in editing code. Move code
        from ASSERTs to hard checks.
        https://bugs.webkit.org/show_bug.cgi?id=57348

        Test: editing/execCommand/remove-format-non-html-element-crash.html

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::applyProperty):
        * editing/ApplyStyleCommand.cpp:
        (WebCore::getRGBAFontColor):
        (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
        * editing/DeleteButtonController.cpp:
        (WebCore::enclosingDeletableElement):
        * editing/EditingStyle.cpp:
        (WebCore::EditingStyle::textDirection):
        (WebCore::EditingStyle::prepareToApplyAt):
        * editing/Editor.cpp:
        (WebCore::Editor::textDirectionForSelection):
        * editing/FormatBlockCommand.cpp:
        (WebCore::FormatBlockCommand::elementForFormatBlockCommand):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@82503 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f88c8c95
2011-03-30 Abhishek Arya <inferno@chromium.org>
Reviewed by Simon Fraser.
Tests that we do not crash when removing inline style
from a node that is not a html element.
https://bugs.webkit.org/show_bug.cgi?id=57348
* editing/execCommand/remove-format-non-html-element-crash-expected.txt: Added.
* editing/execCommand/remove-format-non-html-element-crash.html: Added.
2011-03-30 Erik Arvidsson <arv@chromium.org>
Reviewed by Alexey Proskuryakov.
......
<html>
<body>
Test passes if it does not crash.
<div id="test" contenteditable="true">
<ins><math>ABCD</math></ins>
</div>
<script>
if (window.layoutTestController)
layoutTestController.dumpAsText();
var test = document.getElementById("test");
test.focus();
document.execCommand("SelectAll");
document.execCommand("RemoveFormat");
document.body.removeChild(test);
</script>
</body>
</html>
2011-03-30 Abhishek Arya <inferno@chromium.org>
Reviewed by Simon Fraser.
Fix wrong type assumptions in editing code. Move code
from ASSERTs to hard checks.
https://bugs.webkit.org/show_bug.cgi?id=57348
Test: editing/execCommand/remove-format-non-html-element-crash.html
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
* editing/ApplyStyleCommand.cpp:
(WebCore::getRGBAFontColor):
(WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
* editing/DeleteButtonController.cpp:
(WebCore::enclosingDeletableElement):
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::textDirection):
(WebCore::EditingStyle::prepareToApplyAt):
* editing/Editor.cpp:
(WebCore::Editor::textDirectionForSelection):
* editing/FormatBlockCommand.cpp:
(WebCore::FormatBlockCommand::elementForFormatBlockCommand):
2011-03-30 Stephen White <senorblanco@chromium.org>
Reviewed by Kenneth Russell.
......@@ -6123,8 +6123,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
if (list->length() != 2)
return;
for (unsigned i = 0; i < 2; ++i) {
ASSERT(list->itemWithoutBoundsCheck(i)->isPrimitiveValue());
CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(list->itemWithoutBoundsCheck(i));
CSSValue* item = list->itemWithoutBoundsCheck(i);
if (!item->isPrimitiveValue())
continue;
CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(item);
if (value->getIdent() == CSSValueFilled || value->getIdent() == CSSValueOpen)
m_style->setTextEmphasisFill(*value);
else
......
......@@ -57,11 +57,9 @@ using namespace HTMLNames;
static RGBA32 getRGBAFontColor(CSSStyleDeclaration* style)
{
RefPtr<CSSValue> colorValue = style->getPropertyCSSValue(CSSPropertyColor);
if (!colorValue)
if (!colorValue || !colorValue->isPrimitiveValue())
return Color::transparent;
ASSERT(colorValue->isPrimitiveValue());
CSSPrimitiveValue* primitiveColor = static_cast<CSSPrimitiveValue*>(colorValue.get());
RGBA32 rgba = 0;
if (primitiveColor->primitiveType() != CSSPrimitiveValue::CSS_RGBCOLOR) {
......@@ -1304,7 +1302,6 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
Vector<RefPtr<Element> > elementsToPushDown;
while (current != targetNode) {
ASSERT(current);
ASSERT(current->isHTMLElement());
ASSERT(current->contains(targetNode));
Node* child = current->firstChild();
Node* lastChild = current->lastChild();
......@@ -1313,8 +1310,10 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
styledElement = static_cast<StyledElement*>(current);
elementsToPushDown.append(styledElement);
}
RefPtr<EditingStyle> styleToPushDown = EditingStyle::create();
removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIfNeeded, styleToPushDown.get());
if (current->isHTMLElement())
removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIfNeeded, styleToPushDown.get());
// The inner loop will go through children on each level
// FIXME: we should aggregate inline child elements together so that we don't wrap each child separately.
......
......@@ -160,11 +160,7 @@ static HTMLElement* enclosingDeletableElement(const VisibleSelection& selection)
return 0;
Node* element = enclosingNodeOfType(firstPositionInNode(container), &isDeletableElement);
if (!element)
return 0;
ASSERT(element->isHTMLElement());
return toHTMLElement(element);
return element && element->isHTMLElement() ? toHTMLElement(element) : 0;
}
void DeleteButtonController::respondToChangedSelection(const VisibleSelection& oldSelection)
......
......@@ -377,15 +377,13 @@ bool EditingStyle::textDirection(WritingDirection& writingDirection) const
return false;
RefPtr<CSSValue> unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!unicodeBidi)
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
return false;
ASSERT(unicodeBidi->isPrimitiveValue());
int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent();
if (unicodeBidiValue == CSSValueEmbed) {
RefPtr<CSSValue> direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
ASSERT(!direction || direction->isPrimitiveValue());
if (!direction)
if (!direction || !direction->isPrimitiveValue())
return false;
writingDirection = static_cast<CSSPrimitiveValue*>(direction.get())->getIdent() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
......@@ -707,13 +705,10 @@ void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit
m_mutableStyle->removeProperty(CSSPropertyBackgroundColor, ec);
}
if (unicodeBidi) {
ASSERT(unicodeBidi->isPrimitiveValue());
if (unicodeBidi && unicodeBidi->isPrimitiveValue()) {
m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent());
if (direction) {
ASSERT(direction->isPrimitiveValue());
if (direction && direction->isPrimitiveValue())
m_mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
}
}
}
......
......@@ -653,10 +653,9 @@ WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbe
RefPtr<CSSComputedStyleDeclaration> style = computedStyle(n);
RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!unicodeBidi)
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
continue;
ASSERT(unicodeBidi->isPrimitiveValue());
int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent();
if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValueBidiOverride)
return NaturalWritingDirection;
......@@ -684,10 +683,9 @@ WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbe
RefPtr<CSSComputedStyleDeclaration> style = computedStyle(node);
RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (!unicodeBidi)
if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
continue;
ASSERT(unicodeBidi->isPrimitiveValue());
int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent();
if (unicodeBidiValue == CSSValueNormal)
continue;
......@@ -697,10 +695,9 @@ WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbe
ASSERT(unicodeBidiValue == CSSValueEmbed);
RefPtr<CSSValue> direction = style->getPropertyCSSValue(CSSPropertyDirection);
if (!direction)
if (!direction || !direction->isPrimitiveValue())
continue;
ASSERT(direction->isPrimitiveValue());
int directionValue = static_cast<CSSPrimitiveValue*>(direction.get())->getIdent();
if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
continue;
......
......@@ -112,8 +112,7 @@ Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range)
if (!rootEditableElement || commonAncestor->contains(rootEditableElement))
return 0;
ASSERT(commonAncestor->isElementNode());
return static_cast<Element*>(commonAncestor);
return commonAncestor->isElementNode() ? toElement(commonAncestor) : 0;
}
bool isElementForFormatBlock(const QualifiedName& tagName)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment