| Differences between
and this patch
- WebCore/editing/EditorCommand.cpp +15 lines
Lines 914-919 WebCore/editing/EditorCommand.cpp_sec1
914
    return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitTextDecorationsInEffect, "none", "line-through");
914
    return executeToggleStyle(frame, source, EditActionChangeAttributes, CSSPropertyWebkitTextDecorationsInEffect, "none", "line-through");
915
}
915
}
916
916
917
static bool executeStyleWithCSS(Frame* frame, Event*, EditorCommandSource, const String& value)
918
{
919
    if (value != "false" && value != "true")
920
        return false;
921
    
922
    frame->editor()->setStyleWithCSS(value == "true" ? true : false);
923
    return true;
924
}
925
917
static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
926
static bool executeSubscript(Frame* frame, Event*, EditorCommandSource source, const String&)
918
{
927
{
919
    return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
928
    return executeToggleStyle(frame, source, EditActionSubscript, CSSPropertyVerticalAlign, "baseline", "sub");
Lines 1138-1143 WebCore/editing/EditorCommand.cpp_sec2
1138
    return stateStyle(frame, CSSPropertyTextDecoration, "line-through");
1147
    return stateStyle(frame, CSSPropertyTextDecoration, "line-through");
1139
}
1148
}
1140
1149
1150
static TriState stateStyleWithCSS(Frame* frame, Event*)
1151
{
1152
    return frame->editor()->styleWithCSS() ? TrueTriState : FalseTriState;
1153
}
1154
1141
static TriState stateSubscript(Frame* frame, Event*)
1155
static TriState stateSubscript(Frame* frame, Event*)
1142
{
1156
{
1143
    return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
1157
    return stateStyle(frame, CSSPropertyVerticalAlign, "sub");
Lines 1320-1325 WebCore/editing/EditorCommand.cpp_sec3
1320
        { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1334
        { "SelectWord", { executeSelectWord, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1321
        { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1335
        { "SetMark", { executeSetMark, supportedFromMenuOrKeyBinding, enabledVisibleSelection, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1322
        { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1336
        { "Strikethrough", { executeStrikethrough, supported, enabledInRichlyEditableText, stateStrikethrough, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1337
        { "StyleWithCSS", { executeStyleWithCSS, supported, enabledInRichlyEditableText, stateStyleWithCSS, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1323
        { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1338
        { "Subscript", { executeSubscript, supported, enabledInRichlyEditableText, stateSubscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1324
        { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1339
        { "Superscript", { executeSuperscript, supported, enabledInRichlyEditableText, stateSuperscript, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1325
        { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
1340
        { "SwapWithMark", { executeSwapWithMark, supportedFromMenuOrKeyBinding, enabledVisibleSelectionAndMark, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
- WebCore/editing/Editor.cpp +2 lines
Lines 936-941 WebCore/editing/Editor.cpp_sec1
936
    , m_deleteButtonController(new DeleteButtonController(frame))
936
    , m_deleteButtonController(new DeleteButtonController(frame))
937
    , m_ignoreCompositionSelectionChange(false)
937
    , m_ignoreCompositionSelectionChange(false)
938
    , m_shouldStartNewKillRingSequence(false)
938
    , m_shouldStartNewKillRingSequence(false)
939
    , m_styleWithCSS(false)
939
{ 
940
{ 
940
}
941
}
941
942
Lines 947-952 WebCore/editing/Editor.cpp_sec2
947
{
948
{
948
    m_compositionNode = 0;
949
    m_compositionNode = 0;
949
    m_customCompositionUnderlines.clear();
950
    m_customCompositionUnderlines.clear();
951
    m_styleWithCSS = false;
950
}
952
}
951
953
952
bool Editor::insertText(const String& text, Event* triggeringEvent)
954
bool Editor::insertText(const String& text, Event* triggeringEvent)
- WebCore/editing/Editor.h +4 lines
Lines 151-156 WebCore/editing/Editor.h_sec1
151
    bool selectionStartHasStyle(CSSStyleDeclaration*) const;
151
    bool selectionStartHasStyle(CSSStyleDeclaration*) const;
152
152
153
    bool clientIsEditable() const;
153
    bool clientIsEditable() const;
154
    
155
    void setStyleWithCSS(bool flag) { m_styleWithCSS = flag; }
156
    bool styleWithCSS() const { return m_styleWithCSS; }
154
157
155
    class Command {
158
    class Command {
156
    public:
159
    public:
Lines 278-283 WebCore/editing/Editor.h_sec2
278
    Vector<CompositionUnderline> m_customCompositionUnderlines;
281
    Vector<CompositionUnderline> m_customCompositionUnderlines;
279
    bool m_ignoreCompositionSelectionChange;
282
    bool m_ignoreCompositionSelectionChange;
280
    bool m_shouldStartNewKillRingSequence;
283
    bool m_shouldStartNewKillRingSequence;
284
    bool m_styleWithCSS;
281
285
282
    bool canDeleteRange(Range*) const;
286
    bool canDeleteRange(Range*) const;
283
    bool canSmartReplaceWithPasteboard(Pasteboard*);
287
    bool canSmartReplaceWithPasteboard(Pasteboard*);
- WebCore/editing/ApplyStyleCommand.cpp -31 / +16 lines
Lines 32-37 WebCore/editing/ApplyStyleCommand.cpp_sec1
32
#include "CSSPropertyNames.h"
32
#include "CSSPropertyNames.h"
33
#include "CSSValueKeywords.h"
33
#include "CSSValueKeywords.h"
34
#include "Document.h"
34
#include "Document.h"
35
#include "Editor.h"
36
#include "Frame.h"
35
#include "HTMLElement.h"
37
#include "HTMLElement.h"
36
#include "HTMLInterchange.h"
38
#include "HTMLInterchange.h"
37
#include "HTMLNames.h"
39
#include "HTMLNames.h"
Lines 50-62 WebCore/editing/ApplyStyleCommand.cpp_sec2
50
52
51
class StyleChange {
53
class StyleChange {
52
public:
54
public:
53
    enum ELegacyHTMLStyles { DoNotUseLegacyHTMLStyles, UseLegacyHTMLStyles };
55
    explicit StyleChange(CSSStyleDeclaration*, const Position&);
54
56
55
    explicit StyleChange(CSSStyleDeclaration*, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
56
    StyleChange(CSSStyleDeclaration*, const Position&, ELegacyHTMLStyles usesLegacyStyles=UseLegacyHTMLStyles);
57
58
    static ELegacyHTMLStyles styleModeForParseMode(bool);
59
60
    String cssStyle() const { return m_cssStyle; }
57
    String cssStyle() const { return m_cssStyle; }
61
    bool applyBold() const { return m_applyBold; }
58
    bool applyBold() const { return m_applyBold; }
62
    bool applyItalic() const { return m_applyItalic; }
59
    bool applyItalic() const { return m_applyItalic; }
Lines 70-76 WebCore/editing/ApplyStyleCommand.cpp_sec3
70
    String fontFace() { return m_applyFontFace; }
67
    String fontFace() { return m_applyFontFace; }
71
    String fontSize() { return m_applyFontSize; }
68
    String fontSize() { return m_applyFontSize; }
72
69
73
    bool usesLegacyStyles() const { return m_usesLegacyStyles; }
70
    bool usesLegacyFormattingTags() const { return m_usesLegacyFormattingTags; }
74
71
75
private:
72
private:
76
    void init(PassRefPtr<CSSStyleDeclaration>, const Position&);
73
    void init(PassRefPtr<CSSStyleDeclaration>, const Position&);
Lines 85-117 WebCore/editing/ApplyStyleCommand.cpp_sec4
85
    String m_applyFontColor;
82
    String m_applyFontColor;
86
    String m_applyFontFace;
83
    String m_applyFontFace;
87
    String m_applyFontSize;
84
    String m_applyFontSize;
88
    bool m_usesLegacyStyles;
85
    bool m_usesLegacyFormattingTags;
89
};
86
};
90
87
91
88
92
89
StyleChange::StyleChange(CSSStyleDeclaration* style, const Position& position)
93
StyleChange::StyleChange(CSSStyleDeclaration* style, ELegacyHTMLStyles usesLegacyStyles)
94
    : m_applyBold(false)
90
    : m_applyBold(false)
95
    , m_applyItalic(false)
91
    , m_applyItalic(false)
96
    , m_applySubscript(false)
92
    , m_applySubscript(false)
97
    , m_applySuperscript(false)
93
    , m_applySuperscript(false)
98
    , m_usesLegacyStyles(usesLegacyStyles)
94
    , m_usesLegacyFormattingTags(false)
99
{
95
{
100
    init(style, Position());
101
}
102
103
StyleChange::StyleChange(CSSStyleDeclaration* style, const Position& position, ELegacyHTMLStyles usesLegacyStyles)
104
    : m_applyBold(false)
105
    , m_applyItalic(false)
106
    , m_applySubscript(false)
107
    , m_applySuperscript(false)
108
    , m_usesLegacyStyles(usesLegacyStyles)
109
{
110
    init(style, position);
96
    init(style, position);
111
}
97
}
112
98
113
void StyleChange::init(PassRefPtr<CSSStyleDeclaration> style, const Position &position)
99
void StyleChange::init(PassRefPtr<CSSStyleDeclaration> style, const Position& position)
114
{
100
{
101
    if (position.node())
102
        if (Document* document = position.node()->document())
103
            m_usesLegacyFormattingTags = !document->frame()->editor()->styleWithCSS();
104
            
115
    RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
105
    RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
116
    
106
    
117
    String styleText("");
107
    String styleText("");
Lines 131-137 WebCore/editing/ApplyStyleCommand.cpp_sec5
131
            continue;
121
            continue;
132
        
122
        
133
        // If needed, figure out if this change is a legacy HTML style change.
123
        // If needed, figure out if this change is a legacy HTML style change.
134
        if (m_usesLegacyStyles && checkForLegacyHTMLStyleChange(property))
124
        if (m_usesLegacyFormattingTags && checkForLegacyHTMLStyleChange(property))
135
            continue;
125
            continue;
136
126
137
        if (property->id() == CSSPropertyDirection) {
127
        if (property->id() == CSSPropertyDirection) {
Lines 160-170 WebCore/editing/ApplyStyleCommand.cpp_sec6
160
    m_cssStyle = styleText.stripWhiteSpace();
150
    m_cssStyle = styleText.stripWhiteSpace();
161
}
151
}
162
152
163
StyleChange::ELegacyHTMLStyles StyleChange::styleModeForParseMode(bool isQuirksMode)
164
{
165
    return isQuirksMode ? UseLegacyHTMLStyles : DoNotUseLegacyHTMLStyles;
166
}
167
168
// This function is the mapping from CSS styles to styling tags (like font-weight: bold to <b>)
153
// This function is the mapping from CSS styles to styling tags (like font-weight: bold to <b>)
169
bool StyleChange::checkForLegacyHTMLStyleChange(const CSSProperty* property)
154
bool StyleChange::checkForLegacyHTMLStyleChange(const CSSProperty* property)
170
{
155
{
Lines 442-448 WebCore/editing/ApplyStyleCommand.cpp_sec7
442
    VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next());
427
    VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next());
443
    VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next());
428
    VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next());
444
    while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) {
429
    while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) {
445
        StyleChange styleChange(style, paragraphStart.deepEquivalent(), StyleChange::styleModeForParseMode(document()->inCompatMode()));
430
        StyleChange styleChange(style, paragraphStart.deepEquivalent());
446
        if (styleChange.cssStyle().length() > 0 || m_removeOnly) {
431
        if (styleChange.cssStyle().length() > 0 || m_removeOnly) {
447
            RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().node());
432
            RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().node());
448
            RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent());
433
            RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent());
Lines 1147-1153 WebCore/editing/ApplyStyleCommand.cpp_sec8
1147
1132
1148
    HTMLElement *element = static_cast<HTMLElement *>(node);
1133
    HTMLElement *element = static_cast<HTMLElement *>(node);
1149
        
1134
        
1150
    StyleChange styleChange(style, Position(element, 0), StyleChange::styleModeForParseMode(document()->inCompatMode()));
1135
    StyleChange styleChange(style, Position(element, 0));
1151
    if (styleChange.cssStyle().length() > 0) {
1136
    if (styleChange.cssStyle().length() > 0) {
1152
        String cssText = styleChange.cssStyle();
1137
        String cssText = styleChange.cssStyle();
1153
        CSSMutableStyleDeclaration *decl = element->inlineStyleDecl();
1138
        CSSMutableStyleDeclaration *decl = element->inlineStyleDecl();
Lines 1546-1552 WebCore/editing/ApplyStyleCommand.cpp_sec9
1546
    if (m_removeOnly)
1531
    if (m_removeOnly)
1547
        return;
1532
        return;
1548
1533
1549
    StyleChange styleChange(style, Position(startNode, 0), StyleChange::styleModeForParseMode(document()->inCompatMode()));
1534
    StyleChange styleChange(style, Position(startNode, 0));
1550
1535
1551
    //
1536
    //
1552
    // Font tags need to go outside of CSS so that CSS font sizes override leagcy font sizes.
1537
    // Font tags need to go outside of CSS so that CSS font sizes override leagcy font sizes.
- WebCore/ChangeLog +28 lines
Lines 1-3 WebCore/ChangeLog_sec1
1
2009-02-03  Justin Garcia  <justin.garcia@apple.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=13490
6
        Implement execCommand("styleWithCSS", ...)
7
        
8
        Determine whether or not to use HTML formatting tags for styling on the new
9
        boolean on Editor instead of whether or not the document is quirksmode.
10
11
        * editing/ApplyStyleCommand.cpp:
12
        (WebCore::StyleChange::usesLegacyFormattingTags): 
13
        (WebCore::StyleChange::StyleChange): 
14
        (WebCore::StyleChange::init): 
15
        (WebCore::ApplyStyleCommand::applyBlockStyle): 
16
        (WebCore::ApplyStyleCommand::applyTextDecorationStyle):
17
        (WebCore::ApplyStyleCommand::addInlineStyleIfNeeded): 
18
        * editing/Editor.cpp:
19
        (WebCore::Editor::Editor):
20
        (WebCore::Editor::clear): 
21
        * editing/Editor.h:
22
        (WebCore::Editor::setStyleWithCSS):
23
        (WebCore::Editor::styleWithCSS):
24
        * editing/EditorCommand.cpp:
25
        (WebCore::executeStyleWithCSS):
26
        (WebCore::stateStyleWithCSS):
27
        (WebCore::CommandEntry::):
28
1
2009-02-03  Eric Roman  <eroman@chromium.org>
29
2009-02-03  Eric Roman  <eroman@chromium.org>
2
30
3
        Reviewed by Holger Freyther.
31
        Reviewed by Holger Freyther.
- LayoutTests/editing/execCommand/5685604-1-expected.txt +2 lines
Line 0 LayoutTests/editing/execCommand/5685604-1-expected.txt_sec1
1
Success. execCommand("styleWithCSS", ...) is supported.
2
Success. A legacy formatting tag was used for styling by default, and execCommand("styleWithCSS", ..., true) activated the use of CSS styling.
- LayoutTests/editing/execCommand/5685604-1.html +40 lines
Line 0 LayoutTests/editing/execCommand/5685604-1.html_sec1
1
<body>
2
<p>This tests to make sure that execCommand("styleWithCSS", ...) is supported and turns on the use of legacy tags in leu of CSS-styled spans for formatting changes.</p>
3
<div contenteditable="true" id="div">The second and last words in this sentence should be bold.</div>
4
<ul id="console"></ul>
5
<script>
6
function log(msg) {
7
    console = document.getElementById("console");
8
    text = document.createTextNode(msg);
9
    li = document.createElement("li");
10
    console.appendChild(li);
11
    li.appendChild(text);
12
}
13
r = document.createRange();
14
div = document.getElementById("div");
15
text = div.firstChild;
16
window.getSelection().setBaseAndExtent(text, 4, text, 10);
17
document.execCommand("bold", false, "");
18
window.getSelection().setBaseAndExtent(text, text.length - 5, text, text.length - 1);
19
20
if (document.queryCommandSupported("styleWithCSS"))
21
    log("Success. execCommand(\"styleWithCSS\", ...) is supported.");
22
else
23
    log("Failure. execCommand(\"styleWithCSS\", ...) is not supported.");
24
    
25
document.execCommand("styleWithCSS", false, true);
26
document.execCommand("bold", false, "");
27
28
expectedHTML = "The <b>second</b> and last words in this sentence should be <span class=\"Apple-style-span\" style=\"font-weight: bold;\">bold</span>.";
29
30
if (div.innerHTML == expectedHTML)
31
    log("Success. A legacy formatting tag was used for styling by default, and execCommand(\"styleWithCSS\", ..., true) activated the use of CSS styling.");
32
else
33
    log("Failure. Expected: " + expectedHTML);
34
35
if (window.layoutTestController) {
36
    window.layoutTestController.dumpAsText();
37
    document.body.innerText = document.getElementById("console").innerText;
38
}
39
</script>
40
</body>

Return to Bug 13490