Commit 1b03f7f6 authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Introduce InsertCommands to split EditorCommand.cpp

This CL introduces "InsertCommands.h", move the declarations of some
static functions related to insert commands to the header file. Make
EditorCommand simpler for improving code health.

Bug: 818552
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: I4fc744dc58da885071760ba691baa03e8015d63c
Reviewed-on: https://chromium-review.googlesource.com/977365Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545746}
parent 0d69f055
...@@ -129,6 +129,7 @@ blink_core_sources("editing") { ...@@ -129,6 +129,7 @@ blink_core_sources("editing") {
"commands/FormatBlockCommand.h", "commands/FormatBlockCommand.h",
"commands/IndentOutdentCommand.cpp", "commands/IndentOutdentCommand.cpp",
"commands/IndentOutdentCommand.h", "commands/IndentOutdentCommand.h",
"commands/InsertCommands.h",
"commands/InsertIncrementalTextCommand.cpp", "commands/InsertIncrementalTextCommand.cpp",
"commands/InsertIncrementalTextCommand.h", "commands/InsertIncrementalTextCommand.h",
"commands/InsertIntoTextNodeCommand.cpp", "commands/InsertIntoTextNodeCommand.cpp",
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "core/editing/commands/EditorCommandNames.h" #include "core/editing/commands/EditorCommandNames.h"
#include "core/editing/commands/FormatBlockCommand.h" #include "core/editing/commands/FormatBlockCommand.h"
#include "core/editing/commands/IndentOutdentCommand.h" #include "core/editing/commands/IndentOutdentCommand.h"
#include "core/editing/commands/InsertCommands.h"
#include "core/editing/commands/InsertListCommand.h" #include "core/editing/commands/InsertListCommand.h"
#include "core/editing/commands/RemoveFormatCommand.h" #include "core/editing/commands/RemoveFormatCommand.h"
#include "core/editing/commands/ReplaceSelectionCommand.h" #include "core/editing/commands/ReplaceSelectionCommand.h"
...@@ -261,7 +262,7 @@ static const bool kIsTextInsertion = true; ...@@ -261,7 +262,7 @@ static const bool kIsTextInsertion = true;
// Related to Editor::selectionForCommand. // Related to Editor::selectionForCommand.
// Certain operations continue to use the target control's selection even if the // Certain operations continue to use the target control's selection even if the
// event handler already moved the selection outside of the text control. // event handler already moved the selection outside of the text control.
static LocalFrame* TargetFrame(LocalFrame& frame, Event* event) { LocalFrame* InsertCommands::TargetFrame(LocalFrame& frame, Event* event) {
if (!event) if (!event)
return &frame; return &frame;
Node* node = event->target()->ToNode(); Node* node = event->target()->ToNode();
...@@ -444,8 +445,8 @@ static bool ExecuteApplyParagraphStyle(LocalFrame& frame, ...@@ -444,8 +445,8 @@ static bool ExecuteApplyParagraphStyle(LocalFrame& frame,
return false; return false;
} }
static bool ExecuteInsertFragment(LocalFrame& frame, bool InsertCommands::ExecuteInsertFragment(LocalFrame& frame,
DocumentFragment* fragment) { DocumentFragment* fragment) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return ReplaceSelectionCommand::Create( return ReplaceSelectionCommand::Create(
*frame.GetDocument(), fragment, *frame.GetDocument(), fragment,
...@@ -454,7 +455,8 @@ static bool ExecuteInsertFragment(LocalFrame& frame, ...@@ -454,7 +455,8 @@ static bool ExecuteInsertFragment(LocalFrame& frame,
->Apply(); ->Apply();
} }
static bool ExecuteInsertElement(LocalFrame& frame, HTMLElement* content) { bool InsertCommands::ExecuteInsertElement(LocalFrame& frame,
HTMLElement* content) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
DocumentFragment* fragment = DocumentFragment::Create(*frame.GetDocument()); DocumentFragment* fragment = DocumentFragment::Create(*frame.GetDocument());
DummyExceptionStateForTesting exception_state; DummyExceptionStateForTesting exception_state;
...@@ -464,8 +466,8 @@ static bool ExecuteInsertElement(LocalFrame& frame, HTMLElement* content) { ...@@ -464,8 +466,8 @@ static bool ExecuteInsertElement(LocalFrame& frame, HTMLElement* content) {
return ExecuteInsertFragment(frame, fragment); return ExecuteInsertFragment(frame, fragment);
} }
static bool ExpandSelectionToGranularity(LocalFrame& frame, bool ExpandSelectionToGranularity(LocalFrame& frame,
TextGranularity granularity) { TextGranularity granularity) {
const VisibleSelection& selection = CreateVisibleSelectionWithGranularity( const VisibleSelection& selection = CreateVisibleSelectionWithGranularity(
SelectionInDOMTree::Builder() SelectionInDOMTree::Builder()
.SetBaseAndExtent( .SetBaseAndExtent(
...@@ -1087,19 +1089,19 @@ static bool ExecuteIndent(LocalFrame& frame, ...@@ -1087,19 +1089,19 @@ static bool ExecuteIndent(LocalFrame& frame,
->Apply(); ->Apply();
} }
static bool ExecuteInsertBacktab(LocalFrame& frame, bool InsertCommands::ExecuteInsertBacktab(LocalFrame& frame,
Event* event, Event* event,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
return TargetFrame(frame, event) return TargetFrame(frame, event)
->GetEventHandler() ->GetEventHandler()
.HandleTextInputEvent("\t", event); .HandleTextInputEvent("\t", event);
} }
static bool ExecuteInsertHorizontalRule(LocalFrame& frame, bool InsertCommands::ExecuteInsertHorizontalRule(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
HTMLHRElement* rule = HTMLHRElement::Create(*frame.GetDocument()); HTMLHRElement* rule = HTMLHRElement::Create(*frame.GetDocument());
if (!value.IsEmpty()) if (!value.IsEmpty())
...@@ -1107,19 +1109,19 @@ static bool ExecuteInsertHorizontalRule(LocalFrame& frame, ...@@ -1107,19 +1109,19 @@ static bool ExecuteInsertHorizontalRule(LocalFrame& frame,
return ExecuteInsertElement(frame, rule); return ExecuteInsertElement(frame, rule);
} }
static bool ExecuteInsertHTML(LocalFrame& frame, bool InsertCommands::ExecuteInsertHTML(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return ExecuteInsertFragment( return ExecuteInsertFragment(
frame, CreateFragmentFromMarkup(*frame.GetDocument(), value, "")); frame, CreateFragmentFromMarkup(*frame.GetDocument(), value, ""));
} }
static bool ExecuteInsertImage(LocalFrame& frame, bool InsertCommands::ExecuteInsertImage(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
HTMLImageElement* image = HTMLImageElement::Create(*frame.GetDocument()); HTMLImageElement* image = HTMLImageElement::Create(*frame.GetDocument());
if (!value.IsEmpty()) if (!value.IsEmpty())
...@@ -1127,10 +1129,10 @@ static bool ExecuteInsertImage(LocalFrame& frame, ...@@ -1127,10 +1129,10 @@ static bool ExecuteInsertImage(LocalFrame& frame,
return ExecuteInsertElement(frame, image); return ExecuteInsertElement(frame, image);
} }
static bool ExecuteInsertLineBreak(LocalFrame& frame, bool InsertCommands::ExecuteInsertLineBreak(LocalFrame& frame,
Event* event, Event* event,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
switch (source) { switch (source) {
case EditorCommandSource::kMenuOrKeyBinding: case EditorCommandSource::kMenuOrKeyBinding:
return TargetFrame(frame, event) return TargetFrame(frame, event)
...@@ -1148,66 +1150,66 @@ static bool ExecuteInsertLineBreak(LocalFrame& frame, ...@@ -1148,66 +1150,66 @@ static bool ExecuteInsertLineBreak(LocalFrame& frame,
return false; return false;
} }
static bool ExecuteInsertNewline(LocalFrame& frame, bool InsertCommands::ExecuteInsertNewline(LocalFrame& frame,
Event* event, Event* event,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
LocalFrame* target_frame = blink::TargetFrame(frame, event); LocalFrame* target_frame = TargetFrame(frame, event);
return target_frame->GetEventHandler().HandleTextInputEvent( return target_frame->GetEventHandler().HandleTextInputEvent(
"\n", event, "\n", event,
target_frame->GetEditor().CanEditRichly() ? kTextEventInputKeyboard target_frame->GetEditor().CanEditRichly() ? kTextEventInputKeyboard
: kTextEventInputLineBreak); : kTextEventInputLineBreak);
} }
static bool ExecuteInsertNewlineInQuotedContent(LocalFrame& frame, bool InsertCommands::ExecuteInsertNewlineInQuotedContent(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparatorInQuotedContent( return TypingCommand::InsertParagraphSeparatorInQuotedContent(
*frame.GetDocument()); *frame.GetDocument());
} }
static bool ExecuteInsertOrderedList(LocalFrame& frame, bool InsertCommands::ExecuteInsertOrderedList(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(), return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kOrderedList) InsertListCommand::kOrderedList)
->Apply(); ->Apply();
} }
static bool ExecuteInsertParagraph(LocalFrame& frame, bool InsertCommands::ExecuteInsertParagraph(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparator(*frame.GetDocument()); return TypingCommand::InsertParagraphSeparator(*frame.GetDocument());
} }
static bool ExecuteInsertTab(LocalFrame& frame, bool InsertCommands::ExecuteInsertTab(LocalFrame& frame,
Event* event, Event* event,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
return TargetFrame(frame, event) return TargetFrame(frame, event)
->GetEventHandler() ->GetEventHandler()
.HandleTextInputEvent("\t", event); .HandleTextInputEvent("\t", event);
} }
static bool ExecuteInsertText(LocalFrame& frame, bool InsertCommands::ExecuteInsertText(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
TypingCommand::InsertText(*frame.GetDocument(), value, 0); TypingCommand::InsertText(*frame.GetDocument(), value, 0);
return true; return true;
} }
static bool ExecuteInsertUnorderedList(LocalFrame& frame, bool InsertCommands::ExecuteInsertUnorderedList(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(), return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kUnorderedList) InsertListCommand::kUnorderedList)
...@@ -2646,44 +2648,50 @@ static const EditorInternalCommand* InternalCommand( ...@@ -2646,44 +2648,50 @@ static const EditorInternalCommand* InternalCommand(
{WebEditingCommandType::kIndent, ExecuteIndent, Supported, {WebEditingCommandType::kIndent, ExecuteIndent, Supported,
EnabledInRichlyEditableText, StateNone, ValueStateOrNull, EnabledInRichlyEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertBacktab, ExecuteInsertBacktab, {WebEditingCommandType::kInsertBacktab,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, InsertCommands::ExecuteInsertBacktab, SupportedFromMenuOrKeyBinding,
ValueStateOrNull, kIsTextInsertion, CanNotExecuteWhenDisabled}, EnabledInEditableText, StateNone, ValueStateOrNull, kIsTextInsertion,
{WebEditingCommandType::kInsertHTML, ExecuteInsertHTML, Supported,
EnabledInEditableText, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertHTML, InsertCommands::ExecuteInsertHTML,
Supported, EnabledInEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertHorizontalRule, {WebEditingCommandType::kInsertHorizontalRule,
ExecuteInsertHorizontalRule, Supported, EnabledInRichlyEditableText, InsertCommands::ExecuteInsertHorizontalRule, Supported,
StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertImage, ExecuteInsertImage, Supported,
EnabledInRichlyEditableText, StateNone, ValueStateOrNull, EnabledInRichlyEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertLineBreak, ExecuteInsertLineBreak, {WebEditingCommandType::kInsertImage, InsertCommands::ExecuteInsertImage,
Supported, EnabledInEditableText, StateNone, ValueStateOrNull, Supported, EnabledInRichlyEditableText, StateNone, ValueStateOrNull,
kIsTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertNewline, ExecuteInsertNewline, {WebEditingCommandType::kInsertLineBreak,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, InsertCommands::ExecuteInsertLineBreak, Supported, EnabledInEditableText,
ValueStateOrNull, kIsTextInsertion, CanNotExecuteWhenDisabled}, StateNone, ValueStateOrNull, kIsTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertNewline,
InsertCommands::ExecuteInsertNewline, SupportedFromMenuOrKeyBinding,
EnabledInEditableText, StateNone, ValueStateOrNull, kIsTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertNewlineInQuotedContent, {WebEditingCommandType::kInsertNewlineInQuotedContent,
ExecuteInsertNewlineInQuotedContent, Supported, InsertCommands::ExecuteInsertNewlineInQuotedContent, Supported,
EnabledInRichlyEditableText, StateNone, ValueStateOrNull, EnabledInRichlyEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertOrderedList, ExecuteInsertOrderedList, {WebEditingCommandType::kInsertOrderedList,
Supported, EnabledInRichlyEditableText, StateOrderedList, InsertCommands::ExecuteInsertOrderedList, Supported,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, EnabledInRichlyEditableText, StateOrderedList, ValueStateOrNull,
{WebEditingCommandType::kInsertParagraph, ExecuteInsertParagraph,
Supported, EnabledInEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertTab, ExecuteInsertTab, {WebEditingCommandType::kInsertParagraph,
InsertCommands::ExecuteInsertParagraph, Supported, EnabledInEditableText,
StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertTab, InsertCommands::ExecuteInsertTab,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone,
ValueStateOrNull, kIsTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kIsTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertText, ExecuteInsertText, Supported, {WebEditingCommandType::kInsertText, InsertCommands::ExecuteInsertText,
EnabledInEditableText, StateNone, ValueStateOrNull, kIsTextInsertion, Supported, EnabledInEditableText, StateNone, ValueStateOrNull,
CanNotExecuteWhenDisabled}, kIsTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kInsertUnorderedList, ExecuteInsertUnorderedList, {WebEditingCommandType::kInsertUnorderedList,
Supported, EnabledInRichlyEditableText, StateUnorderedList, InsertCommands::ExecuteInsertUnorderedList, Supported,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, EnabledInRichlyEditableText, StateUnorderedList, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kItalic, ExecuteToggleItalic, Supported, {WebEditingCommandType::kItalic, ExecuteToggleItalic, Supported,
EnabledInRichlyEditableText, StateItalic, ValueStateOrNull, EnabledInRichlyEditableText, StateItalic, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
......
/*
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2009 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef InsertCommands_h
#define InsertCommands_h
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Forward.h"
namespace blink {
class DocumentFragment;
class Event;
class HTMLElement;
class LocalFrame;
enum class EditorCommandSource;
// This class provides static functions about commands related to insert.
class InsertCommands {
STATIC_ONLY(InsertCommands);
public:
// Returns |bool| value for Document#execCommand().
static bool ExecuteInsertBacktab(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertHorizontalRule(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertHTML(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertImage(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertLineBreak(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertNewline(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertNewlineInQuotedContent(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertOrderedList(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertParagraph(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertTab(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertText(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteInsertUnorderedList(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
private:
static bool ExecuteInsertFragment(LocalFrame&, DocumentFragment*);
static bool ExecuteInsertElement(LocalFrame&, HTMLElement*);
// Related to Editor::selectionForCommand.
// Certain operations continue to use the target control's selection even if
// the event handler already moved the selection outside of the text control.
static LocalFrame* TargetFrame(LocalFrame&, Event*);
};
} // namespace blink
#endif
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