Commit a62b4777 authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Introduce StyleCommands to split EditorCommand.cpp

This CL introduces "StyleCommands.h" to move the declarations of some
static functions related to style commands to the header file to make
EditorCommand simpler for improving code health.

Bug: 818552
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: Ic30cfa48855dbb482a92d2d2e2d657a9cdfb7ae7
Reviewed-on: https://chromium-review.googlesource.com/985596Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546779}
parent bd784801
...@@ -177,6 +177,7 @@ blink_core_sources("editing") { ...@@ -177,6 +177,7 @@ blink_core_sources("editing") {
"commands/SplitTextNodeCommand.h", "commands/SplitTextNodeCommand.h",
"commands/SplitTextNodeContainingElementCommand.cpp", "commands/SplitTextNodeContainingElementCommand.cpp",
"commands/SplitTextNodeContainingElementCommand.h", "commands/SplitTextNodeContainingElementCommand.h",
"commands/StyleCommands.h",
"commands/TypingCommand.cpp", "commands/TypingCommand.cpp",
"commands/TypingCommand.h", "commands/TypingCommand.h",
"commands/UndoStack.cpp", "commands/UndoStack.cpp",
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "core/editing/commands/InsertCommands.h" #include "core/editing/commands/InsertCommands.h"
#include "core/editing/commands/MoveCommands.h" #include "core/editing/commands/MoveCommands.h"
#include "core/editing/commands/RemoveFormatCommand.h" #include "core/editing/commands/RemoveFormatCommand.h"
#include "core/editing/commands/StyleCommands.h"
#include "core/editing/commands/TypingCommand.h" #include "core/editing/commands/TypingCommand.h"
#include "core/editing/commands/UnlinkCommand.h" #include "core/editing/commands/UnlinkCommand.h"
#include "core/editing/iterators/TextIterator.h" #include "core/editing/iterators/TextIterator.h"
...@@ -253,9 +254,9 @@ class EditorInternalCommand { ...@@ -253,9 +254,9 @@ class EditorInternalCommand {
static const bool kNotTextInsertion = false; static const bool kNotTextInsertion = false;
static const bool kIsTextInsertion = true; static const bool kIsTextInsertion = true;
static void ApplyStyle(LocalFrame& frame, void StyleCommands::ApplyStyle(LocalFrame& frame,
CSSPropertyValueSet* style, CSSPropertyValueSet* style,
InputEvent::InputType input_type) { InputEvent::InputType input_type) {
const VisibleSelection& selection = const VisibleSelection& selection =
frame.Selection().ComputeVisibleSelectionInDOMTreeDeprecated(); frame.Selection().ComputeVisibleSelectionInDOMTreeDeprecated();
if (selection.IsNone()) if (selection.IsNone())
...@@ -273,19 +274,19 @@ static void ApplyStyle(LocalFrame& frame, ...@@ -273,19 +274,19 @@ static void ApplyStyle(LocalFrame& frame,
->Apply(); ->Apply();
} }
static void ApplyStyleToSelection(LocalFrame& frame, void StyleCommands::ApplyStyleToSelection(LocalFrame& frame,
CSSPropertyValueSet* style, CSSPropertyValueSet* style,
InputEvent::InputType input_type) { InputEvent::InputType input_type) {
if (!style || style->IsEmpty() || !frame.GetEditor().CanEditRichly()) if (!style || style->IsEmpty() || !frame.GetEditor().CanEditRichly())
return; return;
ApplyStyle(frame, style, input_type); ApplyStyle(frame, style, input_type);
} }
static bool ApplyCommandToFrame(LocalFrame& frame, bool StyleCommands::ApplyCommandToFrame(LocalFrame& frame,
EditorCommandSource source, EditorCommandSource source,
InputEvent::InputType input_type, InputEvent::InputType input_type,
CSSPropertyValueSet* style) { CSSPropertyValueSet* style) {
// FIXME: We don't call shouldApplyStyle when the source is DOM; is there a // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
// good reason for that? // good reason for that?
switch (source) { switch (source) {
...@@ -300,11 +301,11 @@ static bool ApplyCommandToFrame(LocalFrame& frame, ...@@ -300,11 +301,11 @@ static bool ApplyCommandToFrame(LocalFrame& frame,
return false; return false;
} }
static bool ExecuteApplyStyle(LocalFrame& frame, bool StyleCommands::ExecuteApplyStyle(LocalFrame& frame,
EditorCommandSource source, EditorCommandSource source,
InputEvent::InputType input_type, InputEvent::InputType input_type,
CSSPropertyID property_id, CSSPropertyID property_id,
const String& property_value) { const String& property_value) {
DCHECK(frame.GetDocument()); DCHECK(frame.GetDocument());
MutableCSSPropertyValueSet* style = MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode); MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
...@@ -313,11 +314,11 @@ static bool ExecuteApplyStyle(LocalFrame& frame, ...@@ -313,11 +314,11 @@ static bool ExecuteApplyStyle(LocalFrame& frame,
return ApplyCommandToFrame(frame, source, input_type, style); return ApplyCommandToFrame(frame, source, input_type, style);
} }
static bool ExecuteApplyStyle(LocalFrame& frame, bool StyleCommands::ExecuteApplyStyle(LocalFrame& frame,
EditorCommandSource source, EditorCommandSource source,
InputEvent::InputType input_type, InputEvent::InputType input_type,
CSSPropertyID property_id, CSSPropertyID property_id,
CSSValueID property_value) { CSSValueID property_value) {
MutableCSSPropertyValueSet* style = MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode); MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
style->SetProperty(property_id, property_value); style->SetProperty(property_id, property_value);
...@@ -328,11 +329,11 @@ static bool ExecuteApplyStyle(LocalFrame& frame, ...@@ -328,11 +329,11 @@ static bool ExecuteApplyStyle(LocalFrame& frame,
// <b><u>hello</u>world</b> properly. This function must use // <b><u>hello</u>world</b> properly. This function must use
// EditingStyle::SelectionHasStyle to determine the current style but we cannot // EditingStyle::SelectionHasStyle to determine the current style but we cannot
// fix this until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved. // fix this until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
static bool ExecuteToggleStyleInList(LocalFrame& frame, bool StyleCommands::ExecuteToggleStyleInList(LocalFrame& frame,
EditorCommandSource source, EditorCommandSource source,
InputEvent::InputType input_type, InputEvent::InputType input_type,
CSSPropertyID property_id, CSSPropertyID property_id,
CSSValue* value) { CSSValue* value) {
EditingStyle* selection_style = EditingStyle* selection_style =
EditingStyleUtilities::CreateStyleAtSelectionStart( EditingStyleUtilities::CreateStyleAtSelectionStart(
frame.Selection().ComputeVisibleSelectionInDOMTree()); frame.Selection().ComputeVisibleSelectionInDOMTree());
...@@ -363,9 +364,9 @@ static bool ExecuteToggleStyleInList(LocalFrame& frame, ...@@ -363,9 +364,9 @@ static bool ExecuteToggleStyleInList(LocalFrame& frame,
return ApplyCommandToFrame(frame, source, input_type, new_mutable_style); return ApplyCommandToFrame(frame, source, input_type, new_mutable_style);
} }
static bool SelectionStartHasStyle(LocalFrame& frame, bool StyleCommands::SelectionStartHasStyle(LocalFrame& frame,
CSSPropertyID property_id, CSSPropertyID property_id,
const String& value) { const String& value) {
const SecureContextMode secure_context_mode = const SecureContextMode secure_context_mode =
frame.GetDocument()->GetSecureContextMode(); frame.GetDocument()->GetSecureContextMode();
...@@ -379,12 +380,12 @@ static bool SelectionStartHasStyle(LocalFrame& frame, ...@@ -379,12 +380,12 @@ static bool SelectionStartHasStyle(LocalFrame& frame,
EditingTriState::kFalse; EditingTriState::kFalse;
} }
static bool ExecuteToggleStyle(LocalFrame& frame, bool StyleCommands::ExecuteToggleStyle(LocalFrame& frame,
EditorCommandSource source, EditorCommandSource source,
InputEvent::InputType input_type, InputEvent::InputType input_type,
CSSPropertyID property_id, CSSPropertyID property_id,
const char* off_value, const char* off_value,
const char* on_value) { const char* on_value) {
// Style is considered present when // Style is considered present when
// Mac: present at the beginning of selection // Mac: present at the beginning of selection
// other: present throughout the selection // other: present throughout the selection
...@@ -478,9 +479,9 @@ static EditingTriState SelectionListState(const FrameSelection& selection, ...@@ -478,9 +479,9 @@ static EditingTriState SelectionListState(const FrameSelection& selection,
return EditingTriState::kFalse; return EditingTriState::kFalse;
} }
static EditingTriState StateStyle(LocalFrame& frame, EditingTriState StyleCommands::StateStyle(LocalFrame& frame,
CSSPropertyID property_id, CSSPropertyID property_id,
const char* desired_value) { const char* desired_value) {
frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (frame.GetEditor().Behavior().ShouldToggleStyleBasedOnStartOfSelection()) { if (frame.GetEditor().Behavior().ShouldToggleStyleBasedOnStartOfSelection()) {
return SelectionStartHasStyle(frame, property_id, desired_value) return SelectionStartHasStyle(frame, property_id, desired_value)
...@@ -490,8 +491,9 @@ static EditingTriState StateStyle(LocalFrame& frame, ...@@ -490,8 +491,9 @@ static EditingTriState StateStyle(LocalFrame& frame,
return EditingStyle::SelectionHasStyle(frame, property_id, desired_value); return EditingStyle::SelectionHasStyle(frame, property_id, desired_value);
} }
static String SelectionStartCSSPropertyValue(LocalFrame& frame, String StyleCommands::SelectionStartCSSPropertyValue(
CSSPropertyID property_id) { LocalFrame& frame,
CSSPropertyID property_id) {
EditingStyle* const selection_style = EditingStyle* const selection_style =
EditingStyleUtilities::CreateStyleAtSelectionStart( EditingStyleUtilities::CreateStyleAtSelectionStart(
frame.Selection().ComputeVisibleSelectionInDOMTreeDeprecated(), frame.Selection().ComputeVisibleSelectionInDOMTreeDeprecated(),
...@@ -504,7 +506,7 @@ static String SelectionStartCSSPropertyValue(LocalFrame& frame, ...@@ -504,7 +506,7 @@ static String SelectionStartCSSPropertyValue(LocalFrame& frame,
return selection_style->Style()->GetPropertyValue(property_id); return selection_style->Style()->GetPropertyValue(property_id);
} }
static String ValueStyle(LocalFrame& frame, CSSPropertyID property_id) { String StyleCommands::ValueStyle(LocalFrame& frame, CSSPropertyID property_id) {
frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
// FIXME: Rather than retrieving the style at the start of the current // FIXME: Rather than retrieving the style at the start of the current
...@@ -513,7 +515,8 @@ static String ValueStyle(LocalFrame& frame, CSSPropertyID property_id) { ...@@ -513,7 +515,8 @@ static String ValueStyle(LocalFrame& frame, CSSPropertyID property_id) {
return SelectionStartCSSPropertyValue(frame, property_id); return SelectionStartCSSPropertyValue(frame, property_id);
} }
static bool IsUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID value_id) { bool StyleCommands::IsUnicodeBidiNestedOrMultipleEmbeddings(
CSSValueID value_id) {
return value_id == CSSValueEmbed || value_id == CSSValueBidiOverride || return value_id == CSSValueEmbed || value_id == CSSValueBidiOverride ||
value_id == CSSValueWebkitIsolate || value_id == CSSValueWebkitIsolate ||
value_id == CSSValueWebkitIsolateOverride || value_id == CSSValueWebkitIsolateOverride ||
...@@ -523,7 +526,7 @@ static bool IsUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID value_id) { ...@@ -523,7 +526,7 @@ static bool IsUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID value_id) {
// TODO(editing-dev): We should make |textDirectionForSelection()| to take // TODO(editing-dev): We should make |textDirectionForSelection()| to take
// |selectionInDOMTree|. // |selectionInDOMTree|.
static WritingDirection TextDirectionForSelection( WritingDirection StyleCommands::TextDirectionForSelection(
const VisibleSelection& selection, const VisibleSelection& selection,
EditingStyle* typing_style, EditingStyle* typing_style,
bool& has_nested_or_multiple_embeddings) { bool& has_nested_or_multiple_embeddings) {
...@@ -627,8 +630,9 @@ static WritingDirection TextDirectionForSelection( ...@@ -627,8 +630,9 @@ static WritingDirection TextDirectionForSelection(
return found_direction; return found_direction;
} }
static EditingTriState StateTextWritingDirection(LocalFrame& frame, EditingTriState StyleCommands::StateTextWritingDirection(
WritingDirection direction) { LocalFrame& frame,
WritingDirection direction) {
frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
bool has_nested_or_multiple_embeddings; bool has_nested_or_multiple_embeddings;
...@@ -658,10 +662,10 @@ static EphemeralRange UnionEphemeralRanges(const EphemeralRange& range1, ...@@ -658,10 +662,10 @@ static EphemeralRange UnionEphemeralRanges(const EphemeralRange& range1,
// Execute command functions // Execute command functions
static bool ExecuteBackColor(LocalFrame& frame, bool StyleCommands::ExecuteBackColor(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String& value) { const String& value) {
return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone, return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone,
CSSPropertyBackgroundColor, value); CSSPropertyBackgroundColor, value);
} }
...@@ -925,18 +929,18 @@ static bool ExecuteFindString(LocalFrame& frame, ...@@ -925,18 +929,18 @@ static bool ExecuteFindString(LocalFrame& frame,
return frame.GetEditor().FindString(value, kCaseInsensitive | kWrapAround); return frame.GetEditor().FindString(value, kCaseInsensitive | kWrapAround);
} }
static bool ExecuteFontName(LocalFrame& frame, bool StyleCommands::ExecuteFontName(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String& value) { const String& value) {
return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone, return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone,
CSSPropertyFontFamily, value); CSSPropertyFontFamily, value);
} }
static bool ExecuteFontSize(LocalFrame& frame, bool StyleCommands::ExecuteFontSize(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String& value) { const String& value) {
CSSValueID size; CSSValueID size;
if (!HTMLFontElement::CssValueFromFontSizeNumber(value, size)) if (!HTMLFontElement::CssValueFromFontSizeNumber(value, size))
return false; return false;
...@@ -944,18 +948,18 @@ static bool ExecuteFontSize(LocalFrame& frame, ...@@ -944,18 +948,18 @@ static bool ExecuteFontSize(LocalFrame& frame,
CSSPropertyFontSize, size); CSSPropertyFontSize, size);
} }
static bool ExecuteFontSizeDelta(LocalFrame& frame, bool StyleCommands::ExecuteFontSizeDelta(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String& value) { const String& value) {
return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone, return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone,
CSSPropertyWebkitFontSizeDelta, value); CSSPropertyWebkitFontSizeDelta, value);
} }
static bool ExecuteForeColor(LocalFrame& frame, bool StyleCommands::ExecuteForeColor(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String& value) { const String& value) {
return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone, return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone,
CSSPropertyColor, value); CSSPropertyColor, value);
} }
...@@ -1061,10 +1065,11 @@ static bool ExecuteJustifyRight(LocalFrame& frame, ...@@ -1061,10 +1065,11 @@ static bool ExecuteJustifyRight(LocalFrame& frame,
CSSPropertyTextAlign, "right"); CSSPropertyTextAlign, "right");
} }
static bool ExecuteMakeTextWritingDirectionLeftToRight(LocalFrame& frame, bool StyleCommands::ExecuteMakeTextWritingDirectionLeftToRight(
Event*, LocalFrame& frame,
EditorCommandSource, Event*,
const String&) { EditorCommandSource,
const String&) {
MutableCSSPropertyValueSet* style = MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode); MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
style->SetProperty(CSSPropertyUnicodeBidi, CSSValueIsolate); style->SetProperty(CSSPropertyUnicodeBidi, CSSValueIsolate);
...@@ -1073,10 +1078,10 @@ static bool ExecuteMakeTextWritingDirectionLeftToRight(LocalFrame& frame, ...@@ -1073,10 +1078,10 @@ static bool ExecuteMakeTextWritingDirectionLeftToRight(LocalFrame& frame,
return true; return true;
} }
static bool ExecuteMakeTextWritingDirectionNatural(LocalFrame& frame, bool StyleCommands::ExecuteMakeTextWritingDirectionNatural(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String&) { const String&) {
MutableCSSPropertyValueSet* style = MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode); MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
style->SetProperty(CSSPropertyUnicodeBidi, CSSValueNormal); style->SetProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
...@@ -1084,10 +1089,11 @@ static bool ExecuteMakeTextWritingDirectionNatural(LocalFrame& frame, ...@@ -1084,10 +1089,11 @@ static bool ExecuteMakeTextWritingDirectionNatural(LocalFrame& frame,
return true; return true;
} }
static bool ExecuteMakeTextWritingDirectionRightToLeft(LocalFrame& frame, bool StyleCommands::ExecuteMakeTextWritingDirectionRightToLeft(
Event*, LocalFrame& frame,
EditorCommandSource, Event*,
const String&) { EditorCommandSource,
const String&) {
MutableCSSPropertyValueSet* style = MutableCSSPropertyValueSet* style =
MutableCSSPropertyValueSet::Create(kHTMLQuirksMode); MutableCSSPropertyValueSet::Create(kHTMLQuirksMode);
style->SetProperty(CSSPropertyUnicodeBidi, CSSValueIsolate); style->SetProperty(CSSPropertyUnicodeBidi, CSSValueIsolate);
...@@ -1255,10 +1261,10 @@ static bool ExecuteSetMark(LocalFrame& frame, ...@@ -1255,10 +1261,10 @@ static bool ExecuteSetMark(LocalFrame& frame,
return true; return true;
} }
static bool ExecuteStrikethrough(LocalFrame& frame, bool StyleCommands::ExecuteStrikethrough(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
CSSIdentifierValue* line_through = CSSIdentifierValue* line_through =
CSSIdentifierValue::Create(CSSValueLineThrough); CSSIdentifierValue::Create(CSSValueLineThrough);
return ExecuteToggleStyleInList( return ExecuteToggleStyleInList(
...@@ -1266,37 +1272,37 @@ static bool ExecuteStrikethrough(LocalFrame& frame, ...@@ -1266,37 +1272,37 @@ static bool ExecuteStrikethrough(LocalFrame& frame,
CSSPropertyWebkitTextDecorationsInEffect, line_through); CSSPropertyWebkitTextDecorationsInEffect, line_through);
} }
static bool ExecuteStyleWithCSS(LocalFrame& frame, bool StyleCommands::ExecuteStyleWithCSS(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
frame.GetEditor().SetShouldStyleWithCSS( frame.GetEditor().SetShouldStyleWithCSS(
!DeprecatedEqualIgnoringCase(value, "false")); !DeprecatedEqualIgnoringCase(value, "false"));
return true; return true;
} }
static bool ExecuteUseCSS(LocalFrame& frame, bool StyleCommands::ExecuteUseCSS(LocalFrame& frame,
Event*, Event*,
EditorCommandSource, EditorCommandSource,
const String& value) { const String& value) {
frame.GetEditor().SetShouldStyleWithCSS( frame.GetEditor().SetShouldStyleWithCSS(
DeprecatedEqualIgnoringCase(value, "false")); DeprecatedEqualIgnoringCase(value, "false"));
return true; return true;
} }
static bool ExecuteSubscript(LocalFrame& frame, bool StyleCommands::ExecuteSubscript(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
return ExecuteToggleStyle(frame, source, return ExecuteToggleStyle(frame, source,
InputEvent::InputType::kFormatSubscript, InputEvent::InputType::kFormatSubscript,
CSSPropertyVerticalAlign, "baseline", "sub"); CSSPropertyVerticalAlign, "baseline", "sub");
} }
static bool ExecuteSuperscript(LocalFrame& frame, bool StyleCommands::ExecuteSuperscript(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
return ExecuteToggleStyle(frame, source, return ExecuteToggleStyle(frame, source,
InputEvent::InputType::kFormatSuperscript, InputEvent::InputType::kFormatSuperscript,
CSSPropertyVerticalAlign, "baseline", "super"); CSSPropertyVerticalAlign, "baseline", "super");
...@@ -1321,18 +1327,18 @@ static bool ExecuteSwapWithMark(LocalFrame& frame, ...@@ -1321,18 +1327,18 @@ static bool ExecuteSwapWithMark(LocalFrame& frame,
return true; return true;
} }
static bool ExecuteToggleBold(LocalFrame& frame, bool StyleCommands::ExecuteToggleBold(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
return ExecuteToggleStyle(frame, source, InputEvent::InputType::kFormatBold, return ExecuteToggleStyle(frame, source, InputEvent::InputType::kFormatBold,
CSSPropertyFontWeight, "normal", "bold"); CSSPropertyFontWeight, "normal", "bold");
} }
static bool ExecuteToggleItalic(LocalFrame& frame, bool StyleCommands::ExecuteToggleItalic(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
return ExecuteToggleStyle(frame, source, InputEvent::InputType::kFormatItalic, return ExecuteToggleStyle(frame, source, InputEvent::InputType::kFormatItalic,
CSSPropertyFontStyle, "normal", "italic"); CSSPropertyFontStyle, "normal", "italic");
} }
...@@ -1401,10 +1407,10 @@ static bool ExecuteTranspose(LocalFrame& frame, ...@@ -1401,10 +1407,10 @@ static bool ExecuteTranspose(LocalFrame& frame,
return true; return true;
} }
static bool ExecuteUnderline(LocalFrame& frame, bool StyleCommands::ExecuteUnderline(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
CSSIdentifierValue* underline = CSSIdentifierValue::Create(CSSValueUnderline); CSSIdentifierValue* underline = CSSIdentifierValue::Create(CSSValueUnderline);
return ExecuteToggleStyleInList( return ExecuteToggleStyleInList(
frame, source, InputEvent::InputType::kFormatUnderline, frame, source, InputEvent::InputType::kFormatUnderline,
...@@ -1427,10 +1433,10 @@ static bool ExecuteUnlink(LocalFrame& frame, ...@@ -1427,10 +1433,10 @@ static bool ExecuteUnlink(LocalFrame& frame,
return UnlinkCommand::Create(*frame.GetDocument())->Apply(); return UnlinkCommand::Create(*frame.GetDocument())->Apply();
} }
static bool ExecuteUnscript(LocalFrame& frame, bool StyleCommands::ExecuteUnscript(LocalFrame& frame,
Event*, Event*,
EditorCommandSource source, EditorCommandSource source,
const String&) { const String&) {
return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone, return ExecuteApplyStyle(frame, source, InputEvent::InputType::kNone,
CSSPropertyVerticalAlign, "baseline"); CSSPropertyVerticalAlign, "baseline");
} }
...@@ -1676,52 +1682,55 @@ static EditingTriState StateNone(LocalFrame&, Event*) { ...@@ -1676,52 +1682,55 @@ static EditingTriState StateNone(LocalFrame&, Event*) {
return EditingTriState::kFalse; return EditingTriState::kFalse;
} }
static EditingTriState StateBold(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateBold(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyFontWeight, "bold"); return StateStyle(frame, CSSPropertyFontWeight, "bold");
} }
static EditingTriState StateItalic(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateItalic(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyFontStyle, "italic"); return StateStyle(frame, CSSPropertyFontStyle, "italic");
} }
static EditingTriState StateOrderedList(LocalFrame& frame, Event*) { EditingTriState StateOrderedList(LocalFrame& frame, Event*) {
return SelectionListState(frame.Selection(), olTag); return SelectionListState(frame.Selection(), olTag);
} }
static EditingTriState StateStrikethrough(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateStrikethrough(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, return StateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect,
"line-through"); "line-through");
} }
static EditingTriState StateStyleWithCSS(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateStyleWithCSS(LocalFrame& frame, Event*) {
return frame.GetEditor().ShouldStyleWithCSS() ? EditingTriState::kTrue return frame.GetEditor().ShouldStyleWithCSS() ? EditingTriState::kTrue
: EditingTriState::kFalse; : EditingTriState::kFalse;
} }
static EditingTriState StateSubscript(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateSubscript(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyVerticalAlign, "sub"); return StateStyle(frame, CSSPropertyVerticalAlign, "sub");
} }
static EditingTriState StateSuperscript(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateSuperscript(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyVerticalAlign, "super"); return StateStyle(frame, CSSPropertyVerticalAlign, "super");
} }
static EditingTriState StateTextWritingDirectionLeftToRight(LocalFrame& frame, EditingTriState StyleCommands::StateTextWritingDirectionLeftToRight(
Event*) { LocalFrame& frame,
Event*) {
return StateTextWritingDirection(frame, LeftToRightWritingDirection); return StateTextWritingDirection(frame, LeftToRightWritingDirection);
} }
static EditingTriState StateTextWritingDirectionNatural(LocalFrame& frame, EditingTriState StyleCommands::StateTextWritingDirectionNatural(
Event*) { LocalFrame& frame,
Event*) {
return StateTextWritingDirection(frame, NaturalWritingDirection); return StateTextWritingDirection(frame, NaturalWritingDirection);
} }
static EditingTriState StateTextWritingDirectionRightToLeft(LocalFrame& frame, EditingTriState StyleCommands::StateTextWritingDirectionRightToLeft(
Event*) { LocalFrame& frame,
Event*) {
return StateTextWritingDirection(frame, RightToLeftWritingDirection); return StateTextWritingDirection(frame, RightToLeftWritingDirection);
} }
static EditingTriState StateUnderline(LocalFrame& frame, Event*) { EditingTriState StyleCommands::StateUnderline(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect, return StateStyle(frame, CSSPropertyWebkitTextDecorationsInEffect,
"underline"); "underline");
} }
...@@ -1731,19 +1740,19 @@ static EditingTriState StateUnorderedList(LocalFrame& frame, Event*) { ...@@ -1731,19 +1740,19 @@ static EditingTriState StateUnorderedList(LocalFrame& frame, Event*) {
} }
static EditingTriState StateJustifyCenter(LocalFrame& frame, Event*) { static EditingTriState StateJustifyCenter(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyTextAlign, "center"); return StyleCommands::StateStyle(frame, CSSPropertyTextAlign, "center");
} }
static EditingTriState StateJustifyFull(LocalFrame& frame, Event*) { static EditingTriState StateJustifyFull(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyTextAlign, "justify"); return StyleCommands::StateStyle(frame, CSSPropertyTextAlign, "justify");
} }
static EditingTriState StateJustifyLeft(LocalFrame& frame, Event*) { static EditingTriState StateJustifyLeft(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyTextAlign, "left"); return StyleCommands::StateStyle(frame, CSSPropertyTextAlign, "left");
} }
static EditingTriState StateJustifyRight(LocalFrame& frame, Event*) { static EditingTriState StateJustifyRight(LocalFrame& frame, Event*) {
return StateStyle(frame, CSSPropertyTextAlign, "right"); return StyleCommands::StateStyle(frame, CSSPropertyTextAlign, "right");
} }
// Value functions // Value functions
...@@ -1765,9 +1774,9 @@ static String ValueEmpty(const EditorInternalCommand&, LocalFrame&, Event*) { ...@@ -1765,9 +1774,9 @@ static String ValueEmpty(const EditorInternalCommand&, LocalFrame&, Event*) {
return g_empty_string; return g_empty_string;
} }
static String ValueBackColor(const EditorInternalCommand&, String StyleCommands::ValueBackColor(const EditorInternalCommand&,
LocalFrame& frame, LocalFrame& frame,
Event*) { Event*) {
return ValueStyle(frame, CSSPropertyBackgroundColor); return ValueStyle(frame, CSSPropertyBackgroundColor);
} }
...@@ -1785,27 +1794,27 @@ static String ValueDefaultParagraphSeparator(const EditorInternalCommand&, ...@@ -1785,27 +1794,27 @@ static String ValueDefaultParagraphSeparator(const EditorInternalCommand&,
return String(); return String();
} }
static String ValueFontName(const EditorInternalCommand&, String StyleCommands::ValueFontName(const EditorInternalCommand&,
LocalFrame& frame, LocalFrame& frame,
Event*) { Event*) {
return ValueStyle(frame, CSSPropertyFontFamily); return ValueStyle(frame, CSSPropertyFontFamily);
} }
static String ValueFontSize(const EditorInternalCommand&, String StyleCommands::ValueFontSize(const EditorInternalCommand&,
LocalFrame& frame, LocalFrame& frame,
Event*) { Event*) {
return ValueStyle(frame, CSSPropertyFontSize); return ValueStyle(frame, CSSPropertyFontSize);
} }
static String ValueFontSizeDelta(const EditorInternalCommand&, String StyleCommands::ValueFontSizeDelta(const EditorInternalCommand&,
LocalFrame& frame, LocalFrame& frame,
Event*) { Event*) {
return ValueStyle(frame, CSSPropertyWebkitFontSizeDelta); return ValueStyle(frame, CSSPropertyWebkitFontSizeDelta);
} }
static String ValueForeColor(const EditorInternalCommand&, String StyleCommands::ValueForeColor(const EditorInternalCommand&,
LocalFrame& frame, LocalFrame& frame,
Event*) { Event*) {
return ValueStyle(frame, CSSPropertyColor); return ValueStyle(frame, CSSPropertyColor);
} }
...@@ -1848,16 +1857,17 @@ static const EditorInternalCommand* InternalCommand( ...@@ -1848,16 +1857,17 @@ static const EditorInternalCommand* InternalCommand(
{WebEditingCommandType::kAlignRight, ExecuteJustifyRight, {WebEditingCommandType::kAlignRight, ExecuteJustifyRight,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateNone,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kBackColor, ExecuteBackColor, Supported, {WebEditingCommandType::kBackColor, StyleCommands::ExecuteBackColor,
EnabledInRichlyEditableText, StateNone, ValueBackColor, Supported, EnabledInRichlyEditableText, StateNone,
kNotTextInsertion, CanNotExecuteWhenDisabled}, StyleCommands::ValueBackColor, kNotTextInsertion,
CanNotExecuteWhenDisabled},
// FIXME: remove BackwardDelete when Safari for Windows stops using it. // FIXME: remove BackwardDelete when Safari for Windows stops using it.
{WebEditingCommandType::kBackwardDelete, ExecuteDeleteBackward, {WebEditingCommandType::kBackwardDelete, ExecuteDeleteBackward,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kBold, ExecuteToggleBold, Supported, {WebEditingCommandType::kBold, StyleCommands::ExecuteToggleBold,
EnabledInRichlyEditableText, StateBold, ValueStateOrNull, Supported, EnabledInRichlyEditableText, StyleCommands::StateBold,
kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kCopy, ClipboardCommands::ExecuteCopy, Supported, {WebEditingCommandType::kCopy, ClipboardCommands::ExecuteCopy, Supported,
ClipboardCommands::EnabledCopy, StateNone, ValueStateOrNull, ClipboardCommands::EnabledCopy, StateNone, ValueStateOrNull,
kNotTextInsertion, ClipboardCommands::CanWriteClipboard}, kNotTextInsertion, ClipboardCommands::CanWriteClipboard},
...@@ -1911,26 +1921,31 @@ static const EditorInternalCommand* InternalCommand( ...@@ -1911,26 +1921,31 @@ static const EditorInternalCommand* InternalCommand(
{WebEditingCommandType::kFindString, ExecuteFindString, Supported, {WebEditingCommandType::kFindString, ExecuteFindString, Supported,
Enabled, StateNone, ValueStateOrNull, kNotTextInsertion, Enabled, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kFontName, ExecuteFontName, Supported, {WebEditingCommandType::kFontName, StyleCommands::ExecuteFontName,
EnabledInRichlyEditableText, StateNone, ValueFontName, kNotTextInsertion, Supported, EnabledInRichlyEditableText, StateNone,
StyleCommands::ValueFontName, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kFontSize, ExecuteFontSize, Supported, {WebEditingCommandType::kFontSize, StyleCommands::ExecuteFontSize,
EnabledInRichlyEditableText, StateNone, ValueFontSize, kNotTextInsertion, Supported, EnabledInRichlyEditableText, StateNone,
StyleCommands::ValueFontSize, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kFontSizeDelta,
StyleCommands::ExecuteFontSizeDelta, Supported,
EnabledInRichlyEditableText, StateNone,
StyleCommands::ValueFontSizeDelta, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kForeColor, StyleCommands::ExecuteForeColor,
Supported, EnabledInRichlyEditableText, StateNone,
StyleCommands::ValueForeColor, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kFontSizeDelta, ExecuteFontSizeDelta, Supported,
EnabledInRichlyEditableText, StateNone, ValueFontSizeDelta,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kForeColor, ExecuteForeColor, Supported,
EnabledInRichlyEditableText, StateNone, ValueForeColor,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kFormatBlock, ExecuteFormatBlock, Supported, {WebEditingCommandType::kFormatBlock, ExecuteFormatBlock, Supported,
EnabledInRichlyEditableText, StateNone, ValueFormatBlock, EnabledInRichlyEditableText, StateNone, ValueFormatBlock,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kForwardDelete, ExecuteForwardDelete, Supported, {WebEditingCommandType::kForwardDelete, ExecuteForwardDelete, Supported,
EnabledInEditableText, StateNone, ValueStateOrNull, kNotTextInsertion, EnabledInEditableText, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kHiliteColor, ExecuteBackColor, Supported, {WebEditingCommandType::kHiliteColor, StyleCommands::ExecuteBackColor,
EnabledInRichlyEditableText, StateNone, ValueStateOrNull, Supported, EnabledInRichlyEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kIgnoreSpelling, ExecuteIgnoreSpelling, {WebEditingCommandType::kIgnoreSpelling, ExecuteIgnoreSpelling,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone,
...@@ -1982,9 +1997,9 @@ static const EditorInternalCommand* InternalCommand( ...@@ -1982,9 +1997,9 @@ static const EditorInternalCommand* InternalCommand(
InsertCommands::ExecuteInsertUnorderedList, Supported, InsertCommands::ExecuteInsertUnorderedList, Supported,
EnabledInRichlyEditableText, StateUnorderedList, ValueStateOrNull, EnabledInRichlyEditableText, StateUnorderedList, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kItalic, ExecuteToggleItalic, Supported, {WebEditingCommandType::kItalic, StyleCommands::ExecuteToggleItalic,
EnabledInRichlyEditableText, StateItalic, ValueStateOrNull, Supported, EnabledInRichlyEditableText, StyleCommands::StateItalic,
kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kJustifyCenter, ExecuteJustifyCenter, Supported, {WebEditingCommandType::kJustifyCenter, ExecuteJustifyCenter, Supported,
EnabledInRichlyEditableText, StateJustifyCenter, ValueStateOrNull, EnabledInRichlyEditableText, StateJustifyCenter, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
...@@ -2001,18 +2016,19 @@ static const EditorInternalCommand* InternalCommand( ...@@ -2001,18 +2016,19 @@ static const EditorInternalCommand* InternalCommand(
EnabledInRichlyEditableText, StateJustifyRight, ValueStateOrNull, EnabledInRichlyEditableText, StateJustifyRight, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kMakeTextWritingDirectionLeftToRight, {WebEditingCommandType::kMakeTextWritingDirectionLeftToRight,
ExecuteMakeTextWritingDirectionLeftToRight, StyleCommands::ExecuteMakeTextWritingDirectionLeftToRight,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
StateTextWritingDirectionLeftToRight, ValueStateOrNull, StyleCommands::StateTextWritingDirectionLeftToRight, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kMakeTextWritingDirectionNatural, {WebEditingCommandType::kMakeTextWritingDirectionNatural,
ExecuteMakeTextWritingDirectionNatural, SupportedFromMenuOrKeyBinding, StyleCommands::ExecuteMakeTextWritingDirectionNatural,
EnabledInRichlyEditableText, StateTextWritingDirectionNatural, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, StyleCommands::StateTextWritingDirectionNatural, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kMakeTextWritingDirectionRightToLeft, {WebEditingCommandType::kMakeTextWritingDirectionRightToLeft,
ExecuteMakeTextWritingDirectionRightToLeft, StyleCommands::ExecuteMakeTextWritingDirectionRightToLeft,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
StateTextWritingDirectionRightToLeft, ValueStateOrNull, StyleCommands::StateTextWritingDirectionRightToLeft, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kMoveBackward, MoveCommands::ExecuteMoveBackward, {WebEditingCommandType::kMoveBackward, MoveCommands::ExecuteMoveBackward,
SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInEditableText, StateNone,
...@@ -2266,51 +2282,54 @@ static const EditorInternalCommand* InternalCommand( ...@@ -2266,51 +2282,54 @@ static const EditorInternalCommand* InternalCommand(
{WebEditingCommandType::kSetMark, ExecuteSetMark, {WebEditingCommandType::kSetMark, ExecuteSetMark,
SupportedFromMenuOrKeyBinding, EnabledVisibleSelection, StateNone, SupportedFromMenuOrKeyBinding, EnabledVisibleSelection, StateNone,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kStrikethrough, ExecuteStrikethrough, Supported, {WebEditingCommandType::kStrikethrough,
EnabledInRichlyEditableText, StateStrikethrough, ValueStateOrNull, StyleCommands::ExecuteStrikethrough, Supported,
kNotTextInsertion, CanNotExecuteWhenDisabled}, EnabledInRichlyEditableText, StyleCommands::StateStrikethrough,
{WebEditingCommandType::kStyleWithCSS, ExecuteStyleWithCSS, Supported, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
Enabled, StateStyleWithCSS, ValueEmpty, kNotTextInsertion, {WebEditingCommandType::kStyleWithCSS, StyleCommands::ExecuteStyleWithCSS,
CanNotExecuteWhenDisabled}, Supported, Enabled, StyleCommands::StateStyleWithCSS, ValueEmpty,
{WebEditingCommandType::kSubscript, ExecuteSubscript, Supported,
EnabledInRichlyEditableText, StateSubscript, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kSuperscript, ExecuteSuperscript, Supported,
EnabledInRichlyEditableText, StateSuperscript, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kSwapWithMark, ExecuteSwapWithMark, {WebEditingCommandType::kSubscript, StyleCommands::ExecuteSubscript,
SupportedFromMenuOrKeyBinding, EnabledVisibleSelectionAndMark, StateNone, Supported, EnabledInRichlyEditableText, StyleCommands::StateSubscript,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kToggleBold, ExecuteToggleBold, {WebEditingCommandType::kSuperscript, StyleCommands::ExecuteSuperscript,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateBold, Supported, EnabledInRichlyEditableText, StyleCommands::StateSuperscript,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kToggleItalic, ExecuteToggleItalic, {WebEditingCommandType::kSwapWithMark, ExecuteSwapWithMark,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateItalic, SupportedFromMenuOrKeyBinding, EnabledVisibleSelectionAndMark, StateNone,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kToggleUnderline, ExecuteUnderline, {WebEditingCommandType::kToggleBold, StyleCommands::ExecuteToggleBold,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
StyleCommands::StateBold, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kToggleItalic, StyleCommands::ExecuteToggleItalic,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
StateUnderline, ValueStateOrNull, kNotTextInsertion, StyleCommands::StateItalic, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled},
{WebEditingCommandType::kToggleUnderline, StyleCommands::ExecuteUnderline,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText,
StyleCommands::StateUnderline, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kTranspose, ExecuteTranspose, Supported, {WebEditingCommandType::kTranspose, ExecuteTranspose, Supported,
EnableCaretInEditableText, StateNone, ValueStateOrNull, EnableCaretInEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUnderline, ExecuteUnderline, Supported, {WebEditingCommandType::kUnderline, StyleCommands::ExecuteUnderline,
EnabledInRichlyEditableText, StateUnderline, ValueStateOrNull, Supported, EnabledInRichlyEditableText, StyleCommands::StateUnderline,
kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUndo, ExecuteUndo, Supported, EnabledUndo, {WebEditingCommandType::kUndo, ExecuteUndo, Supported, EnabledUndo,
StateNone, ValueStateOrNull, kNotTextInsertion, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUnlink, ExecuteUnlink, Supported, {WebEditingCommandType::kUnlink, ExecuteUnlink, Supported,
EnabledRangeInRichlyEditableText, StateNone, ValueStateOrNull, EnabledRangeInRichlyEditableText, StateNone, ValueStateOrNull,
kNotTextInsertion, CanNotExecuteWhenDisabled}, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUnscript, ExecuteUnscript, {WebEditingCommandType::kUnscript, StyleCommands::ExecuteUnscript,
SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateNone, SupportedFromMenuOrKeyBinding, EnabledInRichlyEditableText, StateNone,
ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled}, ValueStateOrNull, kNotTextInsertion, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUnselect, ExecuteUnselect, Supported, {WebEditingCommandType::kUnselect, ExecuteUnselect, Supported,
EnabledUnselect, StateNone, ValueStateOrNull, kNotTextInsertion, EnabledUnselect, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kUseCSS, ExecuteUseCSS, Supported, Enabled, {WebEditingCommandType::kUseCSS, StyleCommands::ExecuteUseCSS, Supported,
StateNone, ValueStateOrNull, kNotTextInsertion, Enabled, StateNone, ValueStateOrNull, kNotTextInsertion,
CanNotExecuteWhenDisabled}, CanNotExecuteWhenDisabled},
{WebEditingCommandType::kYank, ExecuteYank, SupportedFromMenuOrKeyBinding, {WebEditingCommandType::kYank, ExecuteYank, SupportedFromMenuOrKeyBinding,
EnabledInEditableText, StateNone, ValueStateOrNull, kNotTextInsertion, EnabledInEditableText, StateNone, ValueStateOrNull, kNotTextInsertion,
......
/*
* 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 StyleCommands_h
#define StyleCommands_h
#include "core/editing/WritingDirection.h"
#include "core/events/InputEvent.h"
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Forward.h"
namespace blink {
class CSSPropertyValueSet;
class EditingStyle;
class EditorInternalCommand;
class Event;
class LocalFrame;
enum class EditingTriState;
enum class EditorCommandSource;
// This class provides static functions about commands related to style.
class StyleCommands {
STATIC_ONLY(StyleCommands);
public:
// Returns |bool| value for Document#execCommand().
static bool ExecuteBackColor(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteForeColor(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteFontName(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteFontSize(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteFontSizeDelta(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteToggleBold(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteToggleItalic(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteSubscript(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteSuperscript(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteUnscript(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteStrikethrough(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteUnderline(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteMakeTextWritingDirectionLeftToRight(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteMakeTextWritingDirectionNatural(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteMakeTextWritingDirectionRightToLeft(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteStyleWithCSS(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
static bool ExecuteUseCSS(LocalFrame&,
Event*,
EditorCommandSource,
const String&);
// State functions
static EditingTriState StateStyle(LocalFrame&, CSSPropertyID, const char*);
static EditingTriState StateBold(LocalFrame&, Event*);
static EditingTriState StateItalic(LocalFrame&, Event*);
static EditingTriState StateStrikethrough(LocalFrame&, Event*);
static EditingTriState StateStyleWithCSS(LocalFrame&, Event*);
static EditingTriState StateSubscript(LocalFrame&, Event*);
static EditingTriState StateSuperscript(LocalFrame&, Event*);
static EditingTriState StateTextWritingDirectionLeftToRight(LocalFrame&,
Event*);
static EditingTriState StateTextWritingDirectionNatural(LocalFrame&, Event*);
static EditingTriState StateTextWritingDirectionRightToLeft(LocalFrame&,
Event*);
static EditingTriState StateUnderline(LocalFrame&, Event*);
// Value functions
static String ValueBackColor(const EditorInternalCommand&,
LocalFrame&,
Event*);
static String ValueForeColor(const EditorInternalCommand&,
LocalFrame&,
Event*);
static String ValueFontName(const EditorInternalCommand&,
LocalFrame&,
Event*);
static String ValueFontSize(const EditorInternalCommand&,
LocalFrame&,
Event*);
static String ValueFontSizeDelta(const EditorInternalCommand&,
LocalFrame&,
Event*);
private:
static void ApplyStyle(LocalFrame&,
CSSPropertyValueSet*,
InputEvent::InputType);
static void ApplyStyleToSelection(LocalFrame&,
CSSPropertyValueSet*,
InputEvent::InputType);
static bool ApplyCommandToFrame(LocalFrame&,
EditorCommandSource,
InputEvent::InputType,
CSSPropertyValueSet*);
static bool ExecuteApplyStyle(LocalFrame&,
EditorCommandSource,
InputEvent::InputType,
CSSPropertyID,
const String&);
static bool ExecuteApplyStyle(LocalFrame&,
EditorCommandSource,
InputEvent::InputType,
CSSPropertyID,
CSSValueID);
static bool ExecuteToggleStyle(LocalFrame&,
EditorCommandSource,
InputEvent::InputType,
CSSPropertyID,
const char* off_value,
const char* on_value);
// FIXME: executeToggleStyleInList does not handle complicated cases such as
// <b><u>hello</u>world</b> properly. This function must use
// EditingStyle::SelectionHasStyle to determine the current style but we
// cannot fix this until https://bugs.webkit.org/show_bug.cgi?id=27818 is
// resolved.
static bool ExecuteToggleStyleInList(LocalFrame&,
EditorCommandSource,
InputEvent::InputType,
CSSPropertyID,
CSSValue*);
static bool SelectionStartHasStyle(LocalFrame&, CSSPropertyID, const String&);
static String SelectionStartCSSPropertyValue(LocalFrame&, CSSPropertyID);
static String ValueStyle(LocalFrame&, CSSPropertyID);
static bool IsUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID);
// TODO(editing-dev): We should make |textDirectionForSelection()| to take
// |selectionInDOMTree|.
static WritingDirection TextDirectionForSelection(const VisibleSelection&,
EditingStyle*,
bool&);
static EditingTriState StateTextWritingDirection(LocalFrame&,
WritingDirection);
};
} // 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