Commit d455eb63 authored by akling@apple.com's avatar akling@apple.com

EditCommand constructors should take Document&.

<https://webkit.org/b/120566>

Reviewed by Darin Adler.

Let EditCommand's and all subclass constructors take Document& instead of Document*.
EditCommand::document() now returns a Document&.

Added Editor::document() which returns Editor::frame().document() after asserting
that it's non-null, to make passing a Document& from Editor functions easier.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154938 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4c166d6b
2013-08-31 Andreas Kling <akling@apple.com>
EditCommand constructors should take Document&.
<https://webkit.org/b/120566>
Reviewed by Darin Adler.
Let EditCommand's and all subclass constructors take Document& instead of Document*.
EditCommand::document() now returns a Document&.
Added Editor::document() which returns Editor::frame().document() after asserting
that it's non-null, to make passing a Document& from Editor functions easier.
2013-08-31 Andreas Kling <akling@apple.com>
Make more use of toRenderFoo(RenderObject&) cast helpers.
......@@ -34,7 +34,7 @@
namespace WebCore {
AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node)
: SimpleEditCommand(&parent->document())
: SimpleEditCommand(parent->document())
, m_parent(parent)
, m_node(node)
{
......
......@@ -41,14 +41,14 @@ namespace WebCore {
using namespace HTMLNames;
ApplyBlockElementCommand::ApplyBlockElementCommand(Document* document, const QualifiedName& tagName, const AtomicString& inlineStyle)
ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const QualifiedName& tagName, const AtomicString& inlineStyle)
: CompositeEditCommand(document)
, m_tagName(tagName)
, m_inlineStyle(inlineStyle)
{
}
ApplyBlockElementCommand::ApplyBlockElementCommand(Document* document, const QualifiedName& tagName)
ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const QualifiedName& tagName)
: CompositeEditCommand(document)
, m_tagName(tagName)
{
......@@ -87,7 +87,7 @@ void ApplyBlockElementCommand::doApply()
formatSelection(startOfSelection, endOfSelection);
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
ASSERT(startScope == endScope);
ASSERT(startIndex >= 0);
......@@ -108,7 +108,7 @@ void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
if (isAtUnsplittableElement(start)) {
RefPtr<Element> blockquote = createBlockElement();
insertNodeAt(blockquote, start);
RefPtr<Element> placeholder = createBreakElement(document());
RefPtr<Element> placeholder = createBreakElement(&document());
appendNode(placeholder, blockquote);
setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()), DOWNSTREAM, endingSelection().isDirectional()));
return;
......@@ -278,7 +278,7 @@ VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN
PassRefPtr<Element> ApplyBlockElementCommand::createBlockElement() const
{
RefPtr<Element> element = createHTMLElement(document(), m_tagName);
RefPtr<Element> element = createHTMLElement(&document(), m_tagName);
if (m_inlineStyle.length())
element->setAttribute(styleAttr, m_inlineStyle);
return element.release();
......
......@@ -38,8 +38,8 @@ namespace WebCore {
class ApplyBlockElementCommand : public CompositeEditCommand {
protected:
ApplyBlockElementCommand(Document*, const QualifiedName& tagName, const AtomicString& inlineStyle);
ApplyBlockElementCommand(Document*, const QualifiedName& tagName);
ApplyBlockElementCommand(Document&, const QualifiedName& tagName, const AtomicString& inlineStyle);
ApplyBlockElementCommand(Document&, const QualifiedName& tagName);
virtual void formatSelection(const VisiblePosition& startOfSelection, const VisiblePosition& endOfSelection);
PassRefPtr<Element> createBlockElement() const;
......
......@@ -128,7 +128,7 @@ PassRefPtr<HTMLElement> createStyleSpanElement(Document* document)
return styleElement.release();
}
ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, EditAction editingAction, EPropertyLevel propertyLevel)
ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, EditAction editingAction, EPropertyLevel propertyLevel)
: CompositeEditCommand(document)
, m_style(style->copy())
, m_editingAction(editingAction)
......@@ -142,7 +142,7 @@ ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* sty
{
}
ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel)
ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel)
: CompositeEditCommand(document)
, m_style(style->copy())
, m_editingAction(editingAction)
......@@ -157,7 +157,7 @@ ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* sty
}
ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnly, EditAction editingAction)
: CompositeEditCommand(&element->document())
: CompositeEditCommand(element->document())
, m_style(EditingStyle::create())
, m_editingAction(editingAction)
, m_propertyLevel(PropertyDefault)
......@@ -170,7 +170,7 @@ ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
{
}
ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction)
ApplyStyleCommand::ApplyStyleCommand(Document& document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction)
: CompositeEditCommand(document)
, m_style(style->copy())
, m_editingAction(editingAction)
......@@ -245,7 +245,7 @@ void ApplyStyleCommand::applyBlockStyle(EditingStyle *style)
// update document layout once before removing styles
// so that we avoid the expense of updating before each and every call
// to check a computed style
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
// get positions we want to use for applying style
Position start = startPosition();
......@@ -266,8 +266,8 @@ void ApplyStyleCommand::applyBlockStyle(EditingStyle *style)
// addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoints.
// Calculate start and end indices from the start of the tree that they're in.
Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode());
RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> startRange = Range::create(&document(), firstPositionInNode(scope), visibleStart.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> endRange = Range::create(&document(), firstPositionInNode(scope), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
int startIndex = TextIterator::rangeLength(startRange.get(), true);
int endIndex = TextIterator::rangeLength(endRange.get(), true);
......@@ -392,7 +392,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
} else if (node->isTextNode() && node->renderer() && node->parentNode() != lastStyledNode) {
// Last styled node was not parent node of this text node, but we wish to style this
// text node. To make this possible, add a style span to surround this text node.
RefPtr<HTMLElement> span = createStyleSpanElement(document());
RefPtr<HTMLElement> span = createStyleSpanElement(&document());
surroundNodeRangeWithElement(node, node, span.get());
element = span.release();
} else {
......@@ -557,7 +557,7 @@ void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
// update document layout once before removing styles
// so that we avoid the expense of updating before each and every call
// to check a computed style
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
// adjust to the positions we want to use for applying style
Position start = startPosition();
......@@ -651,7 +651,7 @@ void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
// update document layout once before running the rest of the function
// so that we avoid the expense of updating before each and every call
// to check a computed style
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
RefPtr<EditingStyle> styleToApply = style;
if (hasTextDirection) {
......@@ -755,7 +755,7 @@ void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef
if (m_removeOnly)
return;
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
Vector<InlineRunToApplyStyle> runs;
RefPtr<Node> node = startNode;
......@@ -816,7 +816,7 @@ void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, PassRef
runs[i].positionForStyleComputation = positionToComputeInlineStyleChange(runs[i].start, runs[i].dummyElement);
}
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
for (size_t i = 0; i < runs.size(); i++)
runs[i].change = StyleChange(style, runs[i].positionForStyleComputation);
......@@ -1415,7 +1415,7 @@ Position ApplyStyleCommand::positionToComputeInlineStyleChange(PassRefPtr<Node>
{
// It's okay to obtain the style at the startNode because we've removed all relevant styles from the current run.
if (!startNode->isElementNode()) {
dummyElement = createStyleSpanElement(document());
dummyElement = createStyleSpanElement(&document());
insertNodeAt(dummyElement, positionBeforeNode(startNode.get()));
return firstPositionInOrBeforeNode(dummyElement.get());
}
......@@ -1455,7 +1455,7 @@ void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
if (styleChange.applyFontSize())
setNodeAttribute(fontContainer, sizeAttr, styleChange.fontSize());
} else {
RefPtr<Element> fontElement = createFontElement(document());
RefPtr<Element> fontElement = createFontElement(&document());
if (styleChange.applyFontColor())
fontElement->setAttribute(colorAttr, styleChange.fontColor());
if (styleChange.applyFontFace())
......@@ -1479,28 +1479,28 @@ void ApplyStyleCommand::applyInlineStyleChange(PassRefPtr<Node> passedStart, Pas
} else
setNodeAttribute(styleContainer, styleAttr, styleChange.cssStyle());
} else {
RefPtr<Element> styleElement = createStyleSpanElement(document());
RefPtr<Element> styleElement = createStyleSpanElement(&document());
styleElement->setAttribute(styleAttr, styleChange.cssStyle());
surroundNodeRangeWithElement(startNode, endNode, styleElement.release());
}
}
if (styleChange.applyBold())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), bTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), bTag));
if (styleChange.applyItalic())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), iTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), iTag));
if (styleChange.applyUnderline())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), uTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), uTag));
if (styleChange.applyLineThrough())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), strikeTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), strikeTag));
if (styleChange.applySubscript())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), subTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), subTag));
else if (styleChange.applySuperscript())
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(document(), supTag));
surroundNodeRangeWithElement(startNode, endNode, createHTMLElement(&document(), supTag));
if (m_styledInlineElement && addStyledElement == AddStyledElement)
surroundNodeRangeWithElement(startNode, endNode, m_styledInlineElement->cloneElementWithoutChildren());
......
......@@ -48,11 +48,11 @@ public:
enum EAddStyledElement { AddStyledElement, DoNotAddStyledElement };
typedef bool (*IsInlineElementToRemoveFunction)(const Element*);
static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
static PassRefPtr<ApplyStyleCommand> create(Document& document, const EditingStyle* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
{
return adoptRef(new ApplyStyleCommand(document, style, action, level));
}
static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
static PassRefPtr<ApplyStyleCommand> create(Document& document, const EditingStyle* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
{
return adoptRef(new ApplyStyleCommand(document, style, start, end, action, level));
}
......@@ -60,16 +60,16 @@ public:
{
return adoptRef(new ApplyStyleCommand(element, removeOnly, action));
}
static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes)
static PassRefPtr<ApplyStyleCommand> create(Document& document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes)
{
return adoptRef(new ApplyStyleCommand(document, style, isInlineElementToRemoveFunction, action));
}
private:
ApplyStyleCommand(Document*, const EditingStyle*, EditAction, EPropertyLevel);
ApplyStyleCommand(Document*, const EditingStyle*, const Position& start, const Position& end, EditAction, EPropertyLevel);
ApplyStyleCommand(Document&, const EditingStyle*, EditAction, EPropertyLevel);
ApplyStyleCommand(Document&, const EditingStyle*, const Position& start, const Position& end, EditAction, EPropertyLevel);
ApplyStyleCommand(PassRefPtr<Element>, bool removeOnly, EditAction);
ApplyStyleCommand(Document*, const EditingStyle*, bool (*isInlineElementToRemove)(const Element*), EditAction);
ApplyStyleCommand(Document&, const EditingStyle*, bool (*isInlineElementToRemove)(const Element*), EditAction);
virtual void doApply();
virtual EditAction editingAction() const;
......
......@@ -38,7 +38,7 @@ namespace WebCore {
using namespace HTMLNames;
BreakBlockquoteCommand::BreakBlockquoteCommand(Document *document)
BreakBlockquoteCommand::BreakBlockquoteCommand(Document& document)
: CompositeEditCommand(document)
{
}
......@@ -71,7 +71,7 @@ void BreakBlockquoteCommand::doApply()
if (!topBlockquote || !topBlockquote->parentNode() || !topBlockquote->isElementNode())
return;
RefPtr<Element> breakNode = createBreakElement(document());
RefPtr<Element> breakNode = createBreakElement(&document());
bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockquote);
......
......@@ -32,13 +32,13 @@ namespace WebCore {
class BreakBlockquoteCommand : public CompositeEditCommand {
public:
static PassRefPtr<BreakBlockquoteCommand> create(Document* document)
static PassRefPtr<BreakBlockquoteCommand> create(Document& document)
{
return adoptRef(new BreakBlockquoteCommand(document));
}
private:
explicit BreakBlockquoteCommand(Document*);
explicit BreakBlockquoteCommand(Document&);
virtual void doApply();
};
......
......@@ -89,7 +89,7 @@ public:
virtual bool shouldStopCaretBlinking() const { return false; }
protected:
explicit CompositeEditCommand(Document*);
explicit CompositeEditCommand(Document&);
//
// sugary-sweet convenience functions to help create and apply edit commands in composite commands
......
......@@ -32,7 +32,7 @@
namespace WebCore {
CreateLinkCommand::CreateLinkCommand(Document* document, const String& url)
CreateLinkCommand::CreateLinkCommand(Document& document, const String& url)
: CompositeEditCommand(document)
{
m_url = url;
......@@ -43,14 +43,14 @@ void CreateLinkCommand::doApply()
if (endingSelection().isNone())
return;
RefPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document());
RefPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(&document());
anchorElement->setHref(m_url);
if (endingSelection().isRange())
applyStyledElement(anchorElement.get());
else {
insertNodeAt(anchorElement.get(), endingSelection().start());
RefPtr<Text> textNode = Text::create(document(), m_url);
RefPtr<Text> textNode = Text::create(&document(), m_url);
appendNode(textNode.get(), anchorElement.get());
setEndingSelection(VisibleSelection(positionInParentBeforeNode(anchorElement.get()), positionInParentAfterNode(anchorElement.get()), DOWNSTREAM, endingSelection().isDirectional()));
}
......
......@@ -32,7 +32,7 @@ namespace WebCore {
class CreateLinkCommand : public CompositeEditCommand {
public:
static PassRefPtr<CreateLinkCommand> create(Document* document, const String& linkURL)
static PassRefPtr<CreateLinkCommand> create(Document& document, const String& linkURL)
{
return adoptRef(new CreateLinkCommand(document, linkURL));
}
......@@ -40,7 +40,7 @@ public:
bool isCreateLinkCommand() const { return true; }
private:
CreateLinkCommand(Document*, const String& linkURL);
CreateLinkCommand(Document&, const String& linkURL);
virtual void doApply();
virtual EditAction editingAction() const { return EditActionCreateLink; }
......
......@@ -363,13 +363,13 @@ void DeleteButtonController::disable()
class RemoveTargetCommand : public CompositeEditCommand {
public:
static PassRefPtr<RemoveTargetCommand> create(Document* document, PassRefPtr<Node> target)
static PassRefPtr<RemoveTargetCommand> create(Document& document, PassRefPtr<Node> target)
{
return adoptRef(new RemoveTargetCommand(document, target));
}
private:
RemoveTargetCommand(Document* document, PassRefPtr<Node> target)
RemoveTargetCommand(Document& document, PassRefPtr<Node> target)
: CompositeEditCommand(document)
, m_target(target)
{ }
......@@ -394,7 +394,8 @@ void DeleteButtonController::deleteTarget()
// within the target, we unconditionally update the selection to be
// a caret where the target had been.
Position pos = positionInParentBeforeNode(m_target.get());
applyCommand(RemoveTargetCommand::create(m_frame->document(), m_target));
ASSERT(m_frame->document());
applyCommand(RemoveTargetCommand::create(*m_frame->document(), m_target));
m_frame->selection().setSelection(VisiblePosition(pos));
}
#endif
......
......@@ -34,7 +34,7 @@
namespace WebCore {
DeleteFromTextNodeCommand::DeleteFromTextNodeCommand(PassRefPtr<Text> node, unsigned offset, unsigned count)
: SimpleEditCommand(&node->document())
: SimpleEditCommand(node->document())
, m_node(node)
, m_offset(offset)
, m_count(count)
......@@ -57,7 +57,7 @@ void DeleteFromTextNodeCommand::doApply()
return;
// Need to notify this before actually deleting the text
if (AXObjectCache* cache = document()->existingAXObjectCache())
if (AXObjectCache* cache = document().existingAXObjectCache())
cache->nodeTextChangeNotification(m_node.get(), AXObjectCache::AXTextDeleted, m_offset, m_text);
m_node->deleteData(m_offset, m_count, ec);
......@@ -72,7 +72,7 @@ void DeleteFromTextNodeCommand::doUnapply()
m_node->insertData(m_offset, m_text, IGNORE_EXCEPTION);
if (AXObjectCache* cache = document()->existingAXObjectCache())
if (AXObjectCache* cache = document().existingAXObjectCache())
cache->nodeTextChangeNotification(m_node.get(), AXObjectCache::AXTextInserted, m_offset, m_text);
}
......
......@@ -69,7 +69,7 @@ static bool isTableRowEmpty(Node* row)
return true;
}
DeleteSelectionCommand::DeleteSelectionCommand(Document *document, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool sanitizeMarkup)
DeleteSelectionCommand::DeleteSelectionCommand(Document& document, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool sanitizeMarkup)
: CompositeEditCommand(document)
, m_hasSelectionToDelete(false)
, m_smartDelete(smartDelete)
......@@ -88,7 +88,7 @@ DeleteSelectionCommand::DeleteSelectionCommand(Document *document, bool smartDel
}
DeleteSelectionCommand::DeleteSelectionCommand(const VisibleSelection& selection, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool sanitizeMarkup)
: CompositeEditCommand(&selection.start().anchorNode()->document())
: CompositeEditCommand(selection.start().anchorNode()->document())
, m_hasSelectionToDelete(true)
, m_smartDelete(smartDelete)
, m_mergeBlocksAfterDelete(mergeBlocksAfterDelete)
......@@ -377,7 +377,7 @@ void DeleteSelectionCommand::removeNode(PassRefPtr<Node> node, ShouldAssumeConte
}
// Make sure empty cell has some height, if a placeholder can be inserted.
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
RenderObject *r = node->renderer();
if (r && r->isTableCell() && toRenderTableCell(r)->contentHeight() <= 0) {
Position firstEditablePosition = firstEditablePositionInNode(node.get());
......@@ -566,7 +566,7 @@ void DeleteSelectionCommand::handleGeneralDelete()
void DeleteSelectionCommand::fixupWhitespace()
{
document()->updateLayoutIgnorePendingStylesheets();
document().updateLayoutIgnorePendingStylesheets();
// FIXME: isRenderedCharacter should be removed, and we should use VisiblePosition::characterAfter and VisiblePosition::characterBefore
if (m_leadingWhitespace.isNotNull() && !m_leadingWhitespace.isRenderedCharacter() && m_leadingWhitespace.deprecatedNode()->isTextNode()) {
Text* textNode = toText(m_leadingWhitespace.deprecatedNode());
......@@ -623,7 +623,7 @@ void DeleteSelectionCommand::mergeParagraphs()
// We need to merge into m_upstreamStart's block, but it's been emptied out and collapsed by deletion.
if (!mergeDestination.deepEquivalent().deprecatedNode() || !mergeDestination.deepEquivalent().deprecatedNode()->isDescendantOf(enclosingBlock(m_upstreamStart.containerNode())) || m_startsAtEmptyLine) {
insertNodeAt(createBreakElement(document()).get(), m_upstreamStart);
insertNodeAt(createBreakElement(&document()).get(), m_upstreamStart);
mergeDestination = VisiblePosition(m_upstreamStart);
}
......@@ -653,9 +653,9 @@ void DeleteSelectionCommand::mergeParagraphs()
return;
}
RefPtr<Range> range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
if (!document()->frame()->editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
RefPtr<Range> range = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> rangeToBeReplaced = Range::create(&document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
if (!document().frame()->editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
return;
// moveParagraphs will insert placeholders if it removes blocks that would require their use, don't let block
......@@ -728,7 +728,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete()
// In this case if we start typing, the new characters should have the same style as the just deleted ones,
// but, if we change the selection, come back and start typing that style should be lost. Also see
// preserveTypingStyle() below.
document()->frame()->selection().setTypingStyle(m_typingStyle);
document().frame()->selection().setTypingStyle(m_typingStyle);
}
void DeleteSelectionCommand::clearTransientState()
......@@ -756,8 +756,8 @@ String DeleteSelectionCommand::originalStringForAutocorrectionAtBeginningOfSelec
if (nextPosition.isNull())
return String();
RefPtr<Range> rangeOfFirstCharacter = Range::create(document(), startOfSelection.deepEquivalent(), nextPosition.deepEquivalent());
Vector<DocumentMarker*> markers = document()->markers().markersInRange(rangeOfFirstCharacter.get(), DocumentMarker::Autocorrected);
RefPtr<Range> rangeOfFirstCharacter = Range::create(&document(), startOfSelection.deepEquivalent(), nextPosition.deepEquivalent());
Vector<DocumentMarker*> markers = document().markers().markersInRange(rangeOfFirstCharacter.get(), DocumentMarker::Autocorrected);
for (size_t i = 0; i < markers.size(); ++i) {
const DocumentMarker* marker = markers[i];
int startOffset = marker->startOffset();
......@@ -801,7 +801,7 @@ void DeleteSelectionCommand::doApply()
if (!m_replace) {
Element* textControl = enclosingTextFormControl(m_selectionToDelete.start());
if (textControl && textControl->focused())
document()->frame()->editor().textWillBeDeletedInTextField(textControl);
document().frame()->editor().textWillBeDeletedInTextField(textControl);
}
// save this to later make the selection with
......@@ -847,7 +847,7 @@ void DeleteSelectionCommand::doApply()
removePreviouslySelectedEmptyTableRows();
RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(document()).get() : 0;
RefPtr<Node> placeholder = m_needPlaceholder ? createBreakElement(&document()).get() : 0;
if (placeholder) {
if (m_sanitizeMarkup)
......@@ -860,7 +860,7 @@ void DeleteSelectionCommand::doApply()
calculateTypingStyleAfterDelete();
if (!originalString.isEmpty()) {
if (Frame* frame = document()->frame())
if (Frame* frame = document().frame())
frame->editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
}
......
......@@ -34,7 +34,7 @@ class EditingStyle;
class DeleteSelectionCommand : public CompositeEditCommand {
public:
static PassRefPtr<DeleteSelectionCommand> create(Document* document, bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = false, bool sanitizeMarkup = true)
static PassRefPtr<DeleteSelectionCommand> create(Document& document, bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = false, bool sanitizeMarkup = true)
{
return adoptRef(new DeleteSelectionCommand(document, smartDelete, mergeBlocksAfterDelete, replace, expandForSpecialElements, sanitizeMarkup));
}
......@@ -44,7 +44,7 @@ public:
}
private:
DeleteSelectionCommand(Document*, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool santizeMarkup);
DeleteSelectionCommand(Document&, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool santizeMarkup);
DeleteSelectionCommand(const VisibleSelection&, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements, bool sanitizeMarkup);
virtual void doApply();
......
......@@ -80,7 +80,7 @@ private:
Vector<DictationAlternative> m_alternatives;
};
DictationCommand::DictationCommand(Document* document, const String& text, const Vector<DictationAlternative>& alternatives)
DictationCommand::DictationCommand(Document& document, const String& text, const Vector<DictationAlternative>& alternatives)
: TextInsertionBaseCommand(document)
, m_textToInsert(text)
, m_alternatives(alternatives)
......@@ -98,11 +98,11 @@ void DictationCommand::insertText(Document* document, const String& text, const
RefPtr<DictationCommand> cmd;
if (newText == text)
cmd = DictationCommand::create(document, newText, alternatives);
cmd = DictationCommand::create(*document, newText, alternatives);
else
// If the text was modified before insertion, the location of dictation alternatives
// will not be valid anymore. We will just drop the alternatives.
cmd = DictationCommand::create(document, newText, Vector<DictationAlternative>());
cmd = DictationCommand::create(*document, newText, Vector<DictationAlternative>());
applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
}
......
......@@ -39,12 +39,12 @@ public:
static void insertText(Document*, const String&, const Vector<DictationAlternative>& alternatives, const VisibleSelection&);
virtual bool isDictationCommand() const { return true; }
private:
static PassRefPtr<DictationCommand> create(Document* document, const String& text, const Vector<DictationAlternative>& alternatives)
static PassRefPtr<DictationCommand> create(Document& document, const String& text, const Vector<DictationAlternative>& alternatives)
{
return adoptRef(new DictationCommand(document, text, alternatives));
}
DictationCommand(Document*, const String& text, const Vector<DictationAlternative>& alternatives);
DictationCommand(Document&, const String& text, const Vector<DictationAlternative>& alternatives);
virtual void doApply();
......
/*
* Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved.
* Copyright (C) 2005, 2006, 2007, 2013 Apple, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -39,22 +39,20 @@
namespace WebCore {
EditCommand::EditCommand(Document* document)
: m_document(document)
EditCommand::EditCommand(Document& document)
: m_document(&document)
, m_parent(0)
{
ASSERT(m_document);
ASSERT(m_document->frame());
ASSERT(document.frame());
setStartingSelection(m_document->frame()->editor().avoidIntersectionWithDeleteButtonController(m_document->frame()->selection().selection()));
setEndingSelection(m_startingSelection);
}
EditCommand::EditCommand(Document* document, const VisibleSelection& startingSelection, const VisibleSelection& endingSelection)
: m_document(document)
EditCommand::EditCommand(Document& document, const VisibleSelection& startingSelection, const VisibleSelection& endingSelection)
: m_document(&document)
, m_parent(0)
{
ASSERT(m_document);
ASSERT(m_document->frame());
ASSERT(document.frame());
setStartingSelection(startingSelection);
setEndingSelection(endingSelection);
}
......
......@@ -58,10 +58,10 @@ public:
virtual void doApply() = 0;
protected:
explicit EditCommand(Document*);
EditCommand(Document*, const VisibleSelection&, const VisibleSelection&);
explicit EditCommand(Document&);
EditCommand(Document&, const VisibleSelection&, const VisibleSelection&);
Document* document() const { return m_document.get(); }
Document& document() const { return *m_document; }
CompositeEditCommand* parent() const { return m_parent; }
void setStartingSelection(const VisibleSelection&);
void setEndingSelection(const VisibleSelection&);
......@@ -88,7 +88,7 @@ public: