InsertTextCommand.h [plain text]
#ifndef InsertTextCommand_h
#define InsertTextCommand_h
#include "CompositeEditCommand.h"
namespace WebCore {
class DocumentMarkerController;
class Text;
class TextInsertionMarkerSupplier : public RefCounted<TextInsertionMarkerSupplier> {
public:
virtual ~TextInsertionMarkerSupplier() { }
virtual void addMarkersToTextNode(Text*, unsigned offsetOfInsertion, const String& textInserted) = 0;
protected:
TextInsertionMarkerSupplier() { }
};
class InsertTextCommand : public CompositeEditCommand {
public:
enum RebalanceType {
RebalanceLeadingAndTrailingWhitespaces,
RebalanceAllWhitespaces
};
static PassRefPtr<InsertTextCommand> create(Document* document, const String& text, bool selectInsertedText = false,
RebalanceType rebalanceType = RebalanceLeadingAndTrailingWhitespaces)
{
return adoptRef(new InsertTextCommand(document, text, selectInsertedText, rebalanceType));
}
static PassRefPtr<InsertTextCommand> createWithMarkerSupplier(Document* document, const String& text, PassRefPtr<TextInsertionMarkerSupplier> markerSupplier)
{
return adoptRef(new InsertTextCommand(document, text, markerSupplier));
}
private:
InsertTextCommand(Document*, const String& text, bool selectInsertedText, RebalanceType);
InsertTextCommand(Document*, const String& text, PassRefPtr<TextInsertionMarkerSupplier>);
void deleteCharacter();
virtual void doApply();
#if PLATFORM(IOS)
virtual bool isInsertTextCommand() const OVERRIDE { return true; }
#endif
Position positionInsideTextNode(const Position&);
Position insertTab(const Position&);
bool performTrivialReplace(const String&, bool selectInsertedText);
bool performOverwrite(const String&, bool selectInsertedText);
void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition);
friend class TypingCommand;
String m_text;
bool m_selectInsertedText;
RebalanceType m_rebalanceType;
RefPtr<TextInsertionMarkerSupplier> m_markerSupplier;
};
}
#endif // InsertTextCommand_h