| Index: Source/core/editing/ApplyStyleCommand.cpp
|
| diff --git a/Source/core/editing/ApplyStyleCommand.cpp b/Source/core/editing/ApplyStyleCommand.cpp
|
| index b090d25a187c36712ed7f7fc6d43cd7f26e5e270..00f9ab1e4f0374ddee3ead8552af4e3fb29483b0 100644
|
| --- a/Source/core/editing/ApplyStyleCommand.cpp
|
| +++ b/Source/core/editing/ApplyStyleCommand.cpp
|
| @@ -106,16 +106,14 @@ bool isEmptyFontTag(const Element* element, ShouldStyleAttributeBeEmpty shouldSt
|
| return hasNoAttributeOrOnlyStyleAttribute(toHTMLElement(element), shouldStyleAttributeBeEmpty);
|
| }
|
|
|
| -static PassRefPtr<Element> createFontElement(Document& document)
|
| +static PassRefPtrWillBeRawPtr<Element> createFontElement(Document& document)
|
| {
|
| - RefPtr<Element> fontNode = createHTMLElement(document, fontTag);
|
| - return fontNode.release();
|
| + return createHTMLElement(document, fontTag);
|
| }
|
|
|
| PassRefPtrWillBeRawPtr<HTMLElement> createStyleSpanElement(Document& document)
|
| {
|
| - RefPtrWillBeRawPtr<HTMLElement> styleElement = createHTMLElement(document, spanTag);
|
| - return styleElement.release();
|
| + return createHTMLElement(document, spanTag);
|
| }
|
|
|
| ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, EditAction editingAction, EPropertyLevel propertyLevel)
|
| @@ -146,7 +144,7 @@ ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* sty
|
| {
|
| }
|
|
|
| -ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnly, EditAction editingAction)
|
| +ApplyStyleCommand::ApplyStyleCommand(PassRefPtrWillBeRawPtr<Element> element, bool removeOnly, EditAction editingAction)
|
| : CompositeEditCommand(element->document())
|
| , m_style(EditingStyle::create())
|
| , m_editingAction(editingAction)
|
| @@ -207,7 +205,7 @@ void ApplyStyleCommand::doApply()
|
| switch (m_propertyLevel) {
|
| case PropertyDefault: {
|
| // Apply the block-centric properties of the style.
|
| - RefPtr<EditingStyle> blockStyle = m_style->extractAndRemoveBlockProperties();
|
| + RefPtrWillBeRawPtr<EditingStyle> blockStyle = m_style->extractAndRemoveBlockProperties();
|
| if (!blockStyle->isEmpty())
|
| applyBlockStyle(blockStyle.get());
|
| // Apply any remaining styles to the inline elements.
|
| @@ -266,9 +264,9 @@ void ApplyStyleCommand::applyBlockStyle(EditingStyle *style)
|
| while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) {
|
| StyleChange styleChange(style, paragraphStart.deepEquivalent());
|
| if (styleChange.cssStyle().length() || m_removeOnly) {
|
| - RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().deprecatedNode());
|
| + RefPtrWillBeRawPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().deprecatedNode());
|
| if (!m_removeOnly) {
|
| - RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent());
|
| + RefPtrWillBeRawPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent());
|
| if (newBlock)
|
| block = newBlock;
|
| }
|
| @@ -490,11 +488,11 @@ HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool b
|
| }
|
|
|
| // Split every ancestor through highest ancestor with embedding.
|
| - RefPtr<Node> currentNode = node;
|
| + RefPtrWillBeRawPtr<Node> currentNode = node;
|
| while (currentNode) {
|
| - RefPtr<Element> parent = toElement(currentNode->parentNode());
|
| + RefPtrWillBeRawPtr<Element> parent = toElement(currentNode->parentNode());
|
| if (before ? currentNode->previousSibling() : currentNode->nextSibling())
|
| - splitElement(parent, before ? currentNode : currentNode->nextSibling());
|
| + splitElement(parent, before ? currentNode.get() : currentNode->nextSibling());
|
| if (parent == highestAncestorWithUnicodeBidi)
|
| break;
|
| currentNode = parent;
|
| @@ -548,8 +546,8 @@ static Node* highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
|
|
|
| void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
|
| {
|
| - RefPtr<Node> startDummySpanAncestor = nullptr;
|
| - RefPtr<Node> endDummySpanAncestor = nullptr;
|
| + RefPtrWillBeRawPtr<Node> startDummySpanAncestor = nullptr;
|
| + RefPtrWillBeRawPtr<Node> endDummySpanAncestor = nullptr;
|
|
|
| // update document layout once before removing styles
|
| // so that we avoid the expense of updating before each and every call
|
| @@ -601,8 +599,8 @@ void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
|
| Position removeStart = start.upstream();
|
| WritingDirection textDirection = NaturalWritingDirection;
|
| bool hasTextDirection = style->textDirection(textDirection);
|
| - RefPtr<EditingStyle> styleWithoutEmbedding;
|
| - RefPtr<EditingStyle> embeddingStyle;
|
| + RefPtrWillBeRawPtr<EditingStyle> styleWithoutEmbedding = nullptr;
|
| + RefPtrWillBeRawPtr<EditingStyle> embeddingStyle = nullptr;
|
| if (hasTextDirection) {
|
| // Leave alone an ancestor that provides the desired single level embedding, if there is one.
|
| HTMLElement* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, textDirection);
|
| @@ -650,7 +648,7 @@ void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
|
| // to check a computed style
|
| document().updateLayoutIgnorePendingStylesheets();
|
|
|
| - RefPtr<EditingStyle> styleToApply = style;
|
| + RefPtrWillBeRawPtr<EditingStyle> styleToApply = style;
|
| if (hasTextDirection) {
|
| // Avoid applying the unicode-bidi and direction properties beneath ancestors that already have them.
|
| Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
|
| @@ -726,7 +724,9 @@ static bool containsNonEditableRegion(Node& node)
|
| return false;
|
| }
|
|
|
| -struct InlineRunToApplyStyle {
|
| +class InlineRunToApplyStyle {
|
| + ALLOW_ONLY_INLINE_ALLOCATION();
|
| +public:
|
| InlineRunToApplyStyle(Node* start, Node* end, Node* pastEndNode)
|
| : start(start)
|
| , end(end)
|
| @@ -740,24 +740,39 @@ struct InlineRunToApplyStyle {
|
| return start && end && start->inDocument() && end->inDocument();
|
| }
|
|
|
| - RefPtr<Node> start;
|
| - RefPtr<Node> end;
|
| - RefPtr<Node> pastEndNode;
|
| + void trace(Visitor* visitor)
|
| + {
|
| + visitor->trace(start);
|
| + visitor->trace(end);
|
| + visitor->trace(pastEndNode);
|
| + visitor->trace(positionForStyleComputation);
|
| + visitor->trace(dummyElement);
|
| + }
|
| +
|
| + RefPtrWillBeMember<Node> start;
|
| + RefPtrWillBeMember<Node> end;
|
| + RefPtrWillBeMember<Node> pastEndNode;
|
| Position positionForStyleComputation;
|
| - RefPtr<Node> dummyElement;
|
| + RefPtrWillBeMember<Node> dummyElement;
|
| StyleChange change;
|
| };
|
|
|
| -void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRefPtr<Node> startNode, PassRefPtr<Node> pastEndNode)
|
| +} // namespace WebCore
|
| +
|
| +WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(WebCore::InlineRunToApplyStyle);
|
| +
|
| +namespace WebCore {
|
| +
|
| +void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRefPtrWillBeRawPtr<Node> startNode, PassRefPtrWillBeRawPtr<Node> pastEndNode)
|
| {
|
| if (m_removeOnly)
|
| return;
|
|
|
| document().updateLayoutIgnorePendingStylesheets();
|
|
|
| - Vector<InlineRunToApplyStyle> runs;
|
| - RefPtr<Node> node = startNode;
|
| - for (RefPtr<Node> next; node && node != pastEndNode; node = next) {
|
| + WillBeHeapVector<InlineRunToApplyStyle> runs;
|
| + RefPtrWillBeRawPtr<Node> node = startNode;
|
| + for (RefPtrWillBeRawPtr<Node> next; node && node != pastEndNode; node = next) {
|
| next = NodeTraversal::next(*node);
|
|
|
| if (!node->renderer() || !node->rendererIsEditable())
|
| @@ -825,7 +840,7 @@ void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef
|
| }
|
|
|
| for (size_t i = 0; i < runs.size(); i++) {
|
| - InlineRunToApplyStyle& run = runs[i];
|
| + InlineRunToApplyStyle run = runs[i];
|
| if (run.dummyElement)
|
| removeNode(run.dummyElement);
|
| if (run.startAndEndAreStillInDocument())
|
| @@ -855,11 +870,11 @@ bool ApplyStyleCommand::shouldApplyInlineStyleToRun(EditingStyle* style, Node* r
|
| return false;
|
| }
|
|
|
| -void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, RefPtr<Node>& runStart, RefPtr<Node>& runEnd, PassRefPtr<Node> pastEndNode)
|
| +void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style, RefPtrWillBeMember<Node>& runStart, RefPtrWillBeMember<Node>& runEnd, PassRefPtrWillBeRawPtr<Node> pastEndNode)
|
| {
|
| ASSERT(runStart && runEnd);
|
| - RefPtr<Node> next = runStart;
|
| - for (RefPtr<Node> node = next; node && node->inDocument() && node != pastEndNode; node = next) {
|
| + RefPtrWillBeRawPtr<Node> next = runStart;
|
| + for (RefPtrWillBeRawPtr<Node> node = next; node && node->inDocument() && node != pastEndNode; node = next) {
|
| if (editingIgnoresContent(node.get())) {
|
| ASSERT(!node->contains(pastEndNode.get()));
|
| next = NodeTraversal::nextSkippingChildren(*node);
|
| @@ -869,9 +884,9 @@ void ApplyStyleCommand::removeConflictingInlineStyleFromRun(EditingStyle* style,
|
| if (!node->isHTMLElement())
|
| continue;
|
|
|
| - RefPtr<Node> previousSibling = node->previousSibling();
|
| - RefPtr<Node> nextSibling = node->nextSibling();
|
| - RefPtr<ContainerNode> parent = node->parentNode();
|
| + RefPtrWillBeRawPtr<Node> previousSibling = node->previousSibling();
|
| + RefPtrWillBeRawPtr<Node> nextSibling = node->nextSibling();
|
| + RefPtrWillBeRawPtr<ContainerNode> parent = node->parentNode();
|
| removeInlineStyleFromElement(style, toHTMLElement(node), RemoveAlways);
|
| if (!node->inDocument()) {
|
| // FIXME: We might need to update the start and the end of current selection here but need a test.
|
| @@ -1002,7 +1017,7 @@ void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
|
| if (!style || style->isEmpty() || !node->renderer() || isHTMLIFrameElement(*node))
|
| return;
|
|
|
| - RefPtr<EditingStyle> newInlineStyle = style;
|
| + RefPtrWillBeRawPtr<EditingStyle> newInlineStyle = style;
|
| if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) {
|
| newInlineStyle = style->copy();
|
| newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingStyle::OverrideValues);
|
| @@ -1031,20 +1046,20 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
|
| return;
|
|
|
| // The outer loop is traversing the tree vertically from highestAncestor to targetNode
|
| - RefPtr<Node> current = highestAncestor;
|
| + RefPtrWillBeRawPtr<Node> current = highestAncestor;
|
| // Along the way, styled elements that contain targetNode are removed and accumulated into elementsToPushDown.
|
| // Each child of the removed element, exclusing ancestors of targetNode, is then wrapped by clones of elements in elementsToPushDown.
|
| - Vector<RefPtr<Element> > elementsToPushDown;
|
| + WillBeHeapVector<RefPtrWillBeMember<Element> > elementsToPushDown;
|
| while (current && current != targetNode && current->contains(targetNode)) {
|
| NodeVector currentChildren;
|
| getChildNodes(*current, currentChildren);
|
| - RefPtr<Element> styledElement;
|
| + RefPtrWillBeRawPtr<Element> styledElement = nullptr;
|
| if (current->isStyledElement() && isStyledInlineElementToRemove(toElement(current))) {
|
| styledElement = toElement(current);
|
| elementsToPushDown.append(styledElement);
|
| }
|
|
|
| - RefPtr<EditingStyle> styleToPushDown = EditingStyle::create();
|
| + RefPtrWillBeRawPtr<EditingStyle> styleToPushDown = EditingStyle::create();
|
| if (current->isHTMLElement())
|
| removeInlineStyleFromElement(style, toHTMLElement(current), RemoveIfNeeded, styleToPushDown.get());
|
|
|
| @@ -1056,7 +1071,7 @@ void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle* style, Node*
|
| continue;
|
| if (!child->contains(targetNode) && elementsToPushDown.size()) {
|
| for (size_t i = 0; i < elementsToPushDown.size(); i++) {
|
| - RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElementWithoutChildren();
|
| + RefPtrWillBeRawPtr<Element> wrapper = elementsToPushDown[i]->cloneElementWithoutChildren();
|
| wrapper->removeAttribute(styleAttr);
|
| surroundNodeRangeWithElement(child, child, wrapper);
|
| }
|
| @@ -1110,9 +1125,9 @@ void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s
|
| Position s = start.isNull() || start.isOrphan() ? pushDownStart : start;
|
| Position e = end.isNull() || end.isOrphan() ? pushDownEnd : end;
|
|
|
| - RefPtr<Node> node = start.deprecatedNode();
|
| + RefPtrWillBeRawPtr<Node> node = start.deprecatedNode();
|
| while (node) {
|
| - RefPtr<Node> next;
|
| + RefPtrWillBeRawPtr<Node> next = nullptr;
|
| if (editingIgnoresContent(node.get())) {
|
| ASSERT(node == end.deprecatedNode() || !node->contains(end.deprecatedNode()));
|
| next = NodeTraversal::nextSkippingChildren(*node);
|
| @@ -1121,10 +1136,10 @@ void ApplyStyleCommand::removeInlineStyle(EditingStyle* style, const Position &s
|
| }
|
| if (node->isHTMLElement() && nodeFullySelected(node.get(), start, end)) {
|
| RefPtrWillBeRawPtr<HTMLElement> elem = toHTMLElement(node);
|
| - RefPtr<Node> prev = NodeTraversal::previousPostOrder(*elem);
|
| - RefPtr<Node> next = NodeTraversal::next(*elem);
|
| - RefPtr<EditingStyle> styleToPushDown;
|
| - RefPtr<Node> childNode;
|
| + RefPtrWillBeRawPtr<Node> prev = NodeTraversal::previousPostOrder(*elem);
|
| + RefPtrWillBeRawPtr<Node> next = NodeTraversal::next(*elem);
|
| + RefPtrWillBeRawPtr<EditingStyle> styleToPushDown = nullptr;
|
| + RefPtrWillBeRawPtr<Node> childNode = nullptr;
|
| if (isStyledInlineElementToRemove(elem.get())) {
|
| styleToPushDown = EditingStyle::create();
|
| childNode = elem->firstChild();
|
| @@ -1326,18 +1341,18 @@ bool ApplyStyleCommand::mergeEndWithNextIfIdentical(const Position& start, const
|
| return false;
|
| }
|
|
|
| -void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtr<Node> passedStartNode, PassRefPtr<Node> endNode, PassRefPtr<Element> elementToInsert)
|
| +void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtrWillBeRawPtr<Node> passedStartNode, PassRefPtrWillBeRawPtr<Node> endNode, PassRefPtrWillBeRawPtr<Element> elementToInsert)
|
| {
|
| ASSERT(passedStartNode);
|
| ASSERT(endNode);
|
| ASSERT(elementToInsert);
|
| - RefPtr<Node> node = passedStartNode;
|
| - RefPtr<Element> element = elementToInsert;
|
| + RefPtrWillBeRawPtr<Node> node = passedStartNode;
|
| + RefPtrWillBeRawPtr<Element> element = elementToInsert;
|
|
|
| insertNodeBefore(element, node);
|
|
|
| while (node) {
|
| - RefPtr<Node> next = node->nextSibling();
|
| + RefPtrWillBeRawPtr<Node> next = node->nextSibling();
|
| if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) {
|
| removeNode(node);
|
| appendNode(node, element);
|
| @@ -1347,8 +1362,8 @@ void ApplyStyleCommand::surroundNodeRangeWithElement(PassRefPtr<Node> passedStar
|
| node = next;
|
| }
|
|
|
| - RefPtr<Node> nextSibling = element->nextSibling();
|
| - RefPtr<Node> previousSibling = element->previousSibling();
|
| + RefPtrWillBeRawPtr<Node> nextSibling = element->nextSibling();
|
| + RefPtrWillBeRawPtr<Node> previousSibling = element->previousSibling();
|
| if (nextSibling && nextSibling->isElementNode() && nextSibling->rendererIsEditable()
|
| && areIdenticalElements(element.get(), toElement(nextSibling)))
|
| mergeIdenticalElements(element.get(), toElement(nextSibling));
|
| @@ -1383,13 +1398,13 @@ void ApplyStyleCommand::addBlockStyle(const StyleChange& styleChange, HTMLElemen
|
| setNodeAttribute(block, styleAttr, cssText.toAtomicString());
|
| }
|
|
|
| -void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtr<Node> passedStart, PassRefPtr<Node> passedEnd, EAddStyledElement addStyledElement)
|
| +void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtrWillBeRawPtr<Node> passedStart, PassRefPtrWillBeRawPtr<Node> passedEnd, EAddStyledElement addStyledElement)
|
| {
|
| if (!passedStart || !passedEnd || !passedStart->inDocument() || !passedEnd->inDocument())
|
| return;
|
|
|
| - RefPtr<Node> start = passedStart;
|
| - RefPtr<Node> dummyElement;
|
| + RefPtrWillBeRawPtr<Node> start = passedStart;
|
| + RefPtrWillBeMember<Node> dummyElement = nullptr;
|
| StyleChange styleChange(style, positionToComputeInlineStyleChange(start, dummyElement));
|
|
|
| if (dummyElement)
|
| @@ -1398,7 +1413,7 @@ void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtr<N
|
| applyInlineStyleChange(start, passedEnd, styleChange, addStyledElement);
|
| }
|
|
|
| -Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node> startNode, RefPtr<Node>& dummyElement)
|
| +Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtrWillBeRawPtr<Node> startNode, RefPtrWillBeMember<Node>& dummyElement)
|
| {
|
| // It's okay to obtain the style at the startNode because we've removed all relevant styles from the current run.
|
| if (!startNode->isElementNode()) {
|
| @@ -1410,10 +1425,10 @@ Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
|
| return firstPositionInOrBeforeNode(startNode.get());
|
| }
|
|
|
| -void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, PassRefPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement)
|
| +void ApplyStyleCommand::applyInlineStyleChange(PassRefPtrWillBeRawPtr<Node> passedStart, PassRefPtrWillBeRawPtr<Node> passedEnd, StyleChange& styleChange, EAddStyledElement addStyledElement)
|
| {
|
| - RefPtr<Node> startNode = passedStart;
|
| - RefPtr<Node> endNode = passedEnd;
|
| + RefPtrWillBeRawPtr<Node> startNode = passedStart;
|
| + RefPtrWillBeRawPtr<Node> endNode = passedEnd;
|
| ASSERT(startNode->inDocument());
|
| ASSERT(endNode->inDocument());
|
|
|
| @@ -1445,7 +1460,7 @@ void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
|
| if (styleChange.applyFontSize())
|
| setNodeAttribute(fontContainer, sizeAttr, AtomicString(styleChange.fontSize()));
|
| } else {
|
| - RefPtr<Element> fontElement = createFontElement(document());
|
| + RefPtrWillBeRawPtr<Element> fontElement = createFontElement(document());
|
| if (styleChange.applyFontColor())
|
| fontElement->setAttribute(colorAttr, AtomicString(styleChange.fontColor()));
|
| if (styleChange.applyFontFace())
|
| @@ -1470,7 +1485,7 @@ void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
|
| setNodeAttribute(styleContainer, styleAttr, AtomicString(styleChange.cssStyle()));
|
| }
|
| } else {
|
| - RefPtr<Element> styleElement = createStyleSpanElement(document());
|
| + RefPtrWillBeRawPtr<Element> styleElement = createStyleSpanElement(document());
|
| styleElement->setAttribute(styleAttr, AtomicString(styleChange.cssStyle()));
|
| surroundNodeRangeWithElement(startNode, endNode, styleElement.release());
|
| }
|
| @@ -1549,4 +1564,13 @@ void ApplyStyleCommand::joinChildTextNodes(Node* node, const Position& start, co
|
| updateStartEnd(newStart, newEnd);
|
| }
|
|
|
| +void ApplyStyleCommand::trace(Visitor* visitor)
|
| +{
|
| + visitor->trace(m_style);
|
| + visitor->trace(m_start);
|
| + visitor->trace(m_end);
|
| + visitor->trace(m_styledInlineElement);
|
| + CompositeEditCommand::trace(visitor);
|
| +}
|
| +
|
| }
|
|
|