Commit 8bc8fd3d authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Move InsertCommands to InsertCommands.cpp from EditorCommand.cpp.

This CL introduce "InsertCommands.cpp" with moving |InsertCommands|
member into it. Make EditorCommand simpler for improving code health.

Bug: 818552
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: Ic1fbdccc3c451fc1ad113b3db22cd704fbc21e04
Reviewed-on: https://chromium-review.googlesource.com/981714Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546058}
parent 15a15430
......@@ -129,6 +129,7 @@ blink_core_sources("editing") {
"commands/FormatBlockCommand.h",
"commands/IndentOutdentCommand.cpp",
"commands/IndentOutdentCommand.h",
"commands/InsertCommands.cpp",
"commands/InsertCommands.h",
"commands/InsertIncrementalTextCommand.cpp",
"commands/InsertIncrementalTextCommand.h",
......
......@@ -34,7 +34,6 @@
#include "core/css/CSSValueList.h"
#include "core/css_property_names.h"
#include "core/css_value_keywords.h"
#include "core/dom/DocumentFragment.h"
#include "core/dom/TagCollection.h"
#include "core/dom/events/Event.h"
#include "core/editing/EditingStyleUtilities.h"
......@@ -55,19 +54,14 @@
#include "core/editing/commands/FormatBlockCommand.h"
#include "core/editing/commands/IndentOutdentCommand.h"
#include "core/editing/commands/InsertCommands.h"
#include "core/editing/commands/InsertListCommand.h"
#include "core/editing/commands/RemoveFormatCommand.h"
#include "core/editing/commands/ReplaceSelectionCommand.h"
#include "core/editing/commands/TypingCommand.h"
#include "core/editing/commands/UnlinkCommand.h"
#include "core/editing/iterators/TextIterator.h"
#include "core/editing/serializers/Serialization.h"
#include "core/editing/spellcheck/SpellChecker.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/LocalFrameView.h"
#include "core/html/HTMLFontElement.h"
#include "core/html/HTMLHRElement.h"
#include "core/html/HTMLImageElement.h"
#include "core/html_names.h"
#include "core/input/EventHandler.h"
#include "core/layout/LayoutBox.h"
......@@ -259,18 +253,6 @@ class EditorInternalCommand {
static const bool kNotTextInsertion = false;
static const bool kIsTextInsertion = true;
// 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.
LocalFrame* InsertCommands::TargetFrame(LocalFrame& frame, Event* event) {
if (!event)
return &frame;
Node* node = event->target()->ToNode();
if (!node)
return &frame;
return node->GetDocument().GetFrame();
}
static void ApplyStyle(LocalFrame& frame,
CSSPropertyValueSet* style,
InputEvent::InputType input_type) {
......@@ -445,27 +427,6 @@ static bool ExecuteApplyParagraphStyle(LocalFrame& frame,
return false;
}
bool InsertCommands::ExecuteInsertFragment(LocalFrame& frame,
DocumentFragment* fragment) {
DCHECK(frame.GetDocument());
return ReplaceSelectionCommand::Create(
*frame.GetDocument(), fragment,
ReplaceSelectionCommand::kPreventNesting,
InputEvent::InputType::kNone)
->Apply();
}
bool InsertCommands::ExecuteInsertElement(LocalFrame& frame,
HTMLElement* content) {
DCHECK(frame.GetDocument());
DocumentFragment* fragment = DocumentFragment::Create(*frame.GetDocument());
DummyExceptionStateForTesting exception_state;
fragment->AppendChild(content, exception_state);
if (exception_state.HadException())
return false;
return ExecuteInsertFragment(frame, fragment);
}
bool ExpandSelectionToGranularity(LocalFrame& frame,
TextGranularity granularity) {
const VisibleSelection& selection = CreateVisibleSelectionWithGranularity(
......@@ -1089,133 +1050,6 @@ static bool ExecuteIndent(LocalFrame& frame,
->Apply();
}
bool InsertCommands::ExecuteInsertBacktab(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
return TargetFrame(frame, event)
->GetEventHandler()
.HandleTextInputEvent("\t", event);
}
bool InsertCommands::ExecuteInsertHorizontalRule(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
HTMLHRElement* rule = HTMLHRElement::Create(*frame.GetDocument());
if (!value.IsEmpty())
rule->SetIdAttribute(AtomicString(value));
return ExecuteInsertElement(frame, rule);
}
bool InsertCommands::ExecuteInsertHTML(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
return ExecuteInsertFragment(
frame, CreateFragmentFromMarkup(*frame.GetDocument(), value, ""));
}
bool InsertCommands::ExecuteInsertImage(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
HTMLImageElement* image = HTMLImageElement::Create(*frame.GetDocument());
if (!value.IsEmpty())
image->SetSrc(value);
return ExecuteInsertElement(frame, image);
}
bool InsertCommands::ExecuteInsertLineBreak(LocalFrame& frame,
Event* event,
EditorCommandSource source,
const String&) {
switch (source) {
case EditorCommandSource::kMenuOrKeyBinding:
return TargetFrame(frame, event)
->GetEventHandler()
.HandleTextInputEvent("\n", event, kTextEventInputLineBreak);
case EditorCommandSource::kDOM:
// Doesn't scroll to make the selection visible, or modify the kill ring.
// InsertLineBreak is not implemented in IE or Firefox, so this behavior
// is only needed for backward compatibility with ourselves, and for
// consistency with other commands.
DCHECK(frame.GetDocument());
return TypingCommand::InsertLineBreak(*frame.GetDocument());
}
NOTREACHED();
return false;
}
bool InsertCommands::ExecuteInsertNewline(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
LocalFrame* target_frame = TargetFrame(frame, event);
return target_frame->GetEventHandler().HandleTextInputEvent(
"\n", event,
target_frame->GetEditor().CanEditRichly() ? kTextEventInputKeyboard
: kTextEventInputLineBreak);
}
bool InsertCommands::ExecuteInsertNewlineInQuotedContent(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparatorInQuotedContent(
*frame.GetDocument());
}
bool InsertCommands::ExecuteInsertOrderedList(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kOrderedList)
->Apply();
}
bool InsertCommands::ExecuteInsertParagraph(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparator(*frame.GetDocument());
}
bool InsertCommands::ExecuteInsertTab(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
return TargetFrame(frame, event)
->GetEventHandler()
.HandleTextInputEvent("\t", event);
}
bool InsertCommands::ExecuteInsertText(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
TypingCommand::InsertText(*frame.GetDocument(), value, 0);
return true;
}
bool InsertCommands::ExecuteInsertUnorderedList(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kUnorderedList)
->Apply();
}
static bool ExecuteJustifyCenter(LocalFrame& frame,
Event*,
EditorCommandSource source,
......
/*
* 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.
#include "core/editing/commands/InsertCommands.h"
#include "core/dom/DocumentFragment.h"
#include "core/editing/Editor.h"
#include "core/editing/commands/InsertListCommand.h"
#include "core/editing/commands/ReplaceSelectionCommand.h"
#include "core/editing/commands/TypingCommand.h"
#include "core/editing/serializers/Serialization.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLHRElement.h"
#include "core/html/HTMLImageElement.h"
#include "core/input/EventHandler.h"
namespace blink {
LocalFrame& InsertCommands::TargetFrame(LocalFrame& frame, Event* event) {
if (!event)
return frame;
const Node* node = event->target()->ToNode();
if (!node)
return frame;
LocalFrame* local_frame = node->GetDocument().GetFrame();
DCHECK(local_frame);
return *local_frame;
}
bool InsertCommands::ExecuteInsertFragment(LocalFrame& frame,
DocumentFragment* fragment) {
DCHECK(frame.GetDocument());
return ReplaceSelectionCommand::Create(
*frame.GetDocument(), fragment,
ReplaceSelectionCommand::kPreventNesting,
InputEvent::InputType::kNone)
->Apply();
}
bool InsertCommands::ExecuteInsertElement(LocalFrame& frame,
HTMLElement* content) {
DCHECK(frame.GetDocument());
DocumentFragment* const fragment =
DocumentFragment::Create(*frame.GetDocument());
DummyExceptionStateForTesting exception_state;
fragment->AppendChild(content, exception_state);
if (exception_state.HadException())
return false;
return ExecuteInsertFragment(frame, fragment);
}
bool InsertCommands::ExecuteInsertBacktab(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
return TargetFrame(frame, event)
.GetEventHandler()
.HandleTextInputEvent("\t", event);
}
bool InsertCommands::ExecuteInsertHorizontalRule(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
HTMLHRElement* const rule = HTMLHRElement::Create(*frame.GetDocument());
if (!value.IsEmpty())
rule->SetIdAttribute(AtomicString(value));
return ExecuteInsertElement(frame, rule);
}
bool InsertCommands::ExecuteInsertHTML(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
return ExecuteInsertFragment(
frame, CreateFragmentFromMarkup(*frame.GetDocument(), value, ""));
}
bool InsertCommands::ExecuteInsertImage(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
HTMLImageElement* const image =
HTMLImageElement::Create(*frame.GetDocument());
if (!value.IsEmpty())
image->SetSrc(value);
return ExecuteInsertElement(frame, image);
}
bool InsertCommands::ExecuteInsertLineBreak(LocalFrame& frame,
Event* event,
EditorCommandSource source,
const String&) {
switch (source) {
case EditorCommandSource::kMenuOrKeyBinding:
return TargetFrame(frame, event)
.GetEventHandler()
.HandleTextInputEvent("\n", event, kTextEventInputLineBreak);
case EditorCommandSource::kDOM:
// Doesn't scroll to make the selection visible, or modify the kill ring.
// InsertLineBreak is not implemented in IE or Firefox, so this behavior
// is only needed for backward compatibility with ourselves, and for
// consistency with other commands.
DCHECK(frame.GetDocument());
return TypingCommand::InsertLineBreak(*frame.GetDocument());
}
NOTREACHED();
return false;
}
bool InsertCommands::ExecuteInsertNewline(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
const LocalFrame& target_frame = TargetFrame(frame, event);
return target_frame.GetEventHandler().HandleTextInputEvent(
"\n", event,
target_frame.GetEditor().CanEditRichly() ? kTextEventInputKeyboard
: kTextEventInputLineBreak);
}
bool InsertCommands::ExecuteInsertNewlineInQuotedContent(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparatorInQuotedContent(
*frame.GetDocument());
}
bool InsertCommands::ExecuteInsertOrderedList(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kOrderedList)
->Apply();
}
bool InsertCommands::ExecuteInsertParagraph(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return TypingCommand::InsertParagraphSeparator(*frame.GetDocument());
}
bool InsertCommands::ExecuteInsertTab(LocalFrame& frame,
Event* event,
EditorCommandSource,
const String&) {
return TargetFrame(frame, event)
.GetEventHandler()
.HandleTextInputEvent("\t", event);
}
bool InsertCommands::ExecuteInsertText(LocalFrame& frame,
Event*,
EditorCommandSource,
const String& value) {
DCHECK(frame.GetDocument());
TypingCommand::InsertText(*frame.GetDocument(), value, 0);
return true;
}
bool InsertCommands::ExecuteInsertUnorderedList(LocalFrame& frame,
Event*,
EditorCommandSource,
const String&) {
DCHECK(frame.GetDocument());
return InsertListCommand::Create(*frame.GetDocument(),
InsertListCommand::kUnorderedList)
->Apply();
}
} // namespace blink
......@@ -106,7 +106,7 @@ class InsertCommands {
// 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*);
static LocalFrame& TargetFrame(LocalFrame&, Event*);
};
} // namespace blink
......
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