This source file includes following definitions.
- applyTextInsertionCommand
- dispatchBeforeTextInsertedEvent
- canAppendNewLineFeedToSelection
#include "config.h"
#include "core/editing/TextInsertionBaseCommand.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/events/BeforeTextInsertedEvent.h"
#include "core/dom/Element.h"
#include "core/dom/Node.h"
#include "core/editing/FrameSelection.h"
#include "core/frame/LocalFrame.h"
namespace WebCore {
TextInsertionBaseCommand::TextInsertionBaseCommand(Document& document)
: CompositeEditCommand(document)
{
}
void TextInsertionBaseCommand::applyTextInsertionCommand(LocalFrame* frame, PassRefPtr<TextInsertionBaseCommand> command, const VisibleSelection& selectionForInsertion, const VisibleSelection& endingSelection)
{
bool changeSelection = selectionForInsertion != endingSelection;
if (changeSelection) {
command->setStartingSelection(selectionForInsertion);
command->setEndingSelection(selectionForInsertion);
}
command->apply();
if (changeSelection) {
command->setEndingSelection(endingSelection);
frame->selection().setSelection(endingSelection);
}
}
String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelection& selectionForInsertion, bool insertionIsForUpdatingComposition)
{
if (insertionIsForUpdatingComposition)
return text;
String newText = text;
if (Node* startNode = selectionForInsertion.start().containerNode()) {
if (startNode->rootEditableElement()) {
RefPtrWillBeRawPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
startNode->rootEditableElement()->dispatchEvent(evt, IGNORE_EXCEPTION);
newText = evt->text();
}
}
return newText;
}
bool canAppendNewLineFeedToSelection(const VisibleSelection& selection)
{
Node* node = selection.rootEditableElement();
if (!node)
return false;
RefPtrWillBeRawPtr<BeforeTextInsertedEvent> event = BeforeTextInsertedEvent::create(String("\n"));
node->dispatchEvent(event, IGNORE_EXCEPTION);
return event->text().length();
}
}