Changeset 68670 in webkit


Ignore:
Timestamp:
Sep 29, 2010 11:44:02 AM (14 years ago)
Author:
rniwa@webkit.org
Message:

2010-09-29 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

queryCommandValue "formatBlock" always returns false
https://bugs.webkit.org/show_bug.cgi?id=21305

Implemented queryCommandValue('formatBlock'). We match the Firefox's behavior exactly
because Firefox and Internet Explorer support the same set of elements
(address, h1, h2, h3, h4, h5, h6, and p) and Firefox's behavior is more compatible with Opera.
See the bug for the detailed discussion.

WebKit's implementation returns the local name of the lowest common ancestor
of the selection with the tag name address, h1, h2, h3, h4, h5, h6, or p.
It returns "" when there is no such an ancestor or there is no selection.

Test: editing/execCommand/query-format-block.html

  • editing/Editor.cpp: (WebCore::isElementForFormatBlockCommand): (WebCore::Editor::elementForFormatBlockCommand):
  • editing/Editor.h:
  • editing/EditorCommand.cpp: (WebCore::valueFormatBlock): (WebCore::createCommandMap):

2010-09-29 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

queryCommandValue "formatBlock" always returns false
https://bugs.webkit.org/show_bug.cgi?id=21305

Added a test for queryCommandValue('formatBlock').

  • editing/execCommand/query-format-block-expected.txt: Added.
  • editing/execCommand/query-format-block.html: Added.
  • editing/execCommand/script-tests/query-format-block.js: Added. (queryFormatBlock): (selectFirstPosition): (selectMiddleOfHelloWorld):
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r68665 r68670  
     12010-09-29  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        queryCommandValue "formatBlock" always returns false
     6        https://bugs.webkit.org/show_bug.cgi?id=21305
     7
     8        Added a test for queryCommandValue('formatBlock').
     9
     10        * editing/execCommand/query-format-block-expected.txt: Added.
     11        * editing/execCommand/query-format-block.html: Added.
     12        * editing/execCommand/script-tests/query-format-block.js: Added.
     13        (queryFormatBlock):
     14        (selectFirstPosition):
     15        (selectMiddleOfHelloWorld):
     16
    1172010-09-29  Martin Robinson  <mrobinson@igalia.com>
    218
  • trunk/WebCore/ChangeLog

    r68666 r68670  
     12010-09-29  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        queryCommandValue "formatBlock" always returns false
     6        https://bugs.webkit.org/show_bug.cgi?id=21305
     7
     8        Implemented queryCommandValue('formatBlock'). We match the Firefox's behavior exactly
     9        because Firefox and Internet Explorer support the same set of elements
     10        (address, h1, h2, h3, h4, h5, h6, and p) and Firefox's behavior is more compatible with Opera.
     11        See the bug for the detailed discussion.
     12
     13        WebKit's implementation returns the local name of the lowest common ancestor
     14        of the selection with the tag name address, h1, h2, h3, h4, h5, h6, or p.
     15        It returns "" when there is no such an ancestor or there is no selection.
     16
     17        Test: editing/execCommand/query-format-block.html
     18
     19        * editing/Editor.cpp:
     20        (WebCore::isElementForFormatBlockCommand):
     21        (WebCore::Editor::elementForFormatBlockCommand):
     22        * editing/Editor.h:
     23        * editing/EditorCommand.cpp:
     24        (WebCore::valueFormatBlock):
     25        (WebCore::createCommandMap):
     26
    1272010-09-29  Matt Perry  <mpcomplete@chromium.org>
    228
  • trunk/WebCore/editing/Editor.cpp

    r68547 r68670  
    967967}
    968968
     969static bool isElementForFormatBlockCommand(const Node* node)
     970{
     971    return node->hasTagName(addressTag)
     972        || node->hasTagName(h1Tag)
     973        || node->hasTagName(h2Tag)
     974        || node->hasTagName(h3Tag)
     975        || node->hasTagName(h4Tag)
     976        || node->hasTagName(h5Tag)
     977        || node->hasTagName(h6Tag)
     978        || node->hasTagName(pTag)
     979        || node->hasTagName(preTag);
     980}
     981
     982Element* Editor::elementForFormatBlockCommand() const
     983{
     984    const VisibleSelection& selection = m_frame->selection()->selection();
     985    if (!selection.isNonOrphanedCaretOrRange() || !selection.isContentEditable())
     986        return 0;
     987
     988    ExceptionCode ec;
     989    Node* commonAncestor = selection.firstRange()->commonAncestorContainer(ec);
     990    while (commonAncestor && !isElementForFormatBlockCommand(commonAncestor))
     991        commonAncestor = commonAncestor->parentNode();
     992
     993    if (!commonAncestor)
     994        return 0;
     995
     996    ASSERT(commonAncestor->isElementNode());
     997    return static_cast<Element*>(commonAncestor);
     998}
     999
    9691000void Editor::indent()
    9701001{
  • trunk/WebCore/editing/Editor.h

    r68103 r68670  
    126126    TriState selectionHasStyle(CSSStyleDeclaration*) const;
    127127    String selectionStartCSSPropertyValue(int propertyID);
     128    Element* elementForFormatBlockCommand() const;
    128129    const SimpleFontData* fontForSelection(bool&) const;
    129130    WritingDirection textDirectionForSelection(bool&) const;
  • trunk/WebCore/editing/EditorCommand.cpp

    r68465 r68670  
    13471347}
    13481348
     1349static String valueFormatBlock(Frame* frame, Event*)
     1350{
     1351    Element* formatBlockElement = frame->editor()->elementForFormatBlockCommand();
     1352    if (!formatBlockElement)
     1353        return "";
     1354    return formatBlockElement->localName();
     1355}
     1356
    13491357// Map of functions
    13501358
     
    13831391        { "FontSizeDelta", { executeFontSizeDelta, supported, enabledInEditableText, stateNone, valueFontSizeDelta, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    13841392        { "ForeColor", { executeForeColor, supported, enabledInRichlyEditableText, stateNone, valueForeColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    1385         { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
     1393        { "FormatBlock", { executeFormatBlock, supported, enabledInRichlyEditableText, stateNone, valueFormatBlock, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    13861394        { "ForwardDelete", { executeForwardDelete, supported, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
    13871395        { "HiliteColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
Note: See TracChangeset for help on using the changeset viewer.