Changeset 106637 in webkit


Ignore:
Timestamp:
Feb 3, 2012 12:30:59 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore: Reimplement DETAILS and SUMMARY using selector query.
https://bugs.webkit.org/show_bug.cgi?id=75930

Patch by Shinya Kawanaka <shinyak@google.com> on 2012-02-03
Reviewed by Hajime Morita.

DETAILS is reimplemented using content element and its fallback feature.
We don't need to recreate DOM even if SUMMARY is removed from or added into DETAILS.

No new tests, should be covered by existing tests.

  • html/HTMLDetailsElement.cpp:

(WebCore::DetailsSummaryElement::fallbackSummary):

Takes fallback element of content summary.

(DetailsSummaryElement):
(WebCore::DetailsSummaryElement::create):

Creates a fallback element also.

(WebCore):
(WebCore::HTMLDetailsElement::create):
(WebCore::HTMLDetailsElement::HTMLDetailsElement):
(WebCore::HTMLDetailsElement::createShadowSubtree):
(WebCore::HTMLDetailsElement::findMainSummary):
(WebCore::HTMLDetailsElement::parseMappedAttribute):
(WebCore::HTMLDetailsElement::childShouldCreateRenderer):
(WebCore::HTMLDetailsElement::toggleOpen):

  • html/HTMLDetailsElement.h:

(HTMLDetailsElement):

  • html/HTMLSummaryElement.cpp:

(WebCore::HTMLSummaryElement::isMainSummary):

LayoutTests: Reimplement DETAILS and SUMMARY using selector query.
https://bugs.webkit.org/show_bug.cgi?id=75930

Since the implementation of DETAILS shadow tree, the path of caret position is also changed.

Patch by Shinya Kawanaka <shinyak@google.com> on 2012-02-03
Reviewed by Hajime Morita.

  • platform/chromium-win/fast/html/details-remove-summary-1-and-click-expected.txt:
  • platform/chromium-win/fast/html/details-remove-summary-4-and-click-expected.txt:
  • platform/gtk/fast/html/details-remove-summary-1-and-click-expected.txt:
  • platform/gtk/fast/html/details-remove-summary-4-and-click-expected.txt:
  • platform/mac/fast/html/details-remove-summary-1-and-click-expected.txt:
  • platform/mac/fast/html/details-remove-summary-4-and-click-expected.txt:
  • platform/qt/fast/html/details-remove-summary-1-and-click-expected.txt:
  • platform/qt/fast/html/details-remove-summary-4-and-click-expected.txt:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106633 r106637  
     12012-02-03  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Reimplement DETAILS and SUMMARY using selector query.
     4        https://bugs.webkit.org/show_bug.cgi?id=75930
     5
     6        Since the implementation of DETAILS shadow tree, the path of caret position is also changed.
     7
     8        Reviewed by Hajime Morita.
     9
     10        * platform/chromium-win/fast/html/details-remove-summary-1-and-click-expected.txt:
     11        * platform/chromium-win/fast/html/details-remove-summary-4-and-click-expected.txt:
     12        * platform/gtk/fast/html/details-remove-summary-1-and-click-expected.txt:
     13        * platform/gtk/fast/html/details-remove-summary-4-and-click-expected.txt:
     14        * platform/mac/fast/html/details-remove-summary-1-and-click-expected.txt:
     15        * platform/mac/fast/html/details-remove-summary-4-and-click-expected.txt:
     16        * platform/qt/fast/html/details-remove-summary-1-and-click-expected.txt:
     17        * platform/qt/fast/html/details-remove-summary-4-and-click-expected.txt:
     18
    1192012-02-02  Alexei Filippov  <alexeif@chromium.org>
    220
  • trunk/LayoutTests/platform/chromium-win/fast/html/details-remove-summary-1-and-click-expected.txt

    r87461 r106637  
    99          RenderText {#text} at (16,0) size 41x19
    1010            text run at (16,0) width 41: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/chromium-win/fast/html/details-remove-summary-4-and-click-expected.txt

    r87461 r106637  
    99          RenderText {#text} at (16,0) size 41x19
    1010            text run at (16,0) width 41: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/gtk/fast/html/details-remove-summary-1-and-click-expected.txt

    r101368 r106637  
    99          RenderText {#text} at (16,0) size 46x17
    1010            text run at (16,0) width 46: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/gtk/fast/html/details-remove-summary-4-and-click-expected.txt

    r101368 r106637  
    99          RenderText {#text} at (16,0) size 46x17
    1010            text run at (16,0) width 46: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/mac/fast/html/details-remove-summary-1-and-click-expected.txt

    r84632 r106637  
    99          RenderText {#text} at (16,0) size 44x18
    1010            text run at (16,0) width 44: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/mac/fast/html/details-remove-summary-4-and-click-expected.txt

    r84632 r106637  
    99          RenderText {#text} at (16,0) size 44x18
    1010            text run at (16,0) width 44: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/qt/fast/html/details-remove-summary-1-and-click-expected.txt

    r98015 r106637  
    99          RenderText {#text} at (16,0) size 50x21
    1010            text run at (16,0) width 50: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/LayoutTests/platform/qt/fast/html/details-remove-summary-4-and-click-expected.txt

    r98015 r106637  
    99          RenderText {#text} at (16,0) size 50x21
    1010            text run at (16,0) width 50: "Details"
    11 caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of {#shadow-root} of child 1 {DETAILS} of body
     11caret: position 0 of child 0 {DIV} of {#shadow-root} of child 0 {SUMMARY} of child 0 {DIV} of {#shadow-root} of child 1 {DETAILS} of body
  • trunk/Source/WebCore/ChangeLog

    r106636 r106637  
     12012-02-03  Shinya Kawanaka  <shinyak@google.com>
     2
     3       Reimplement DETAILS and SUMMARY using selector query.
     4        https://bugs.webkit.org/show_bug.cgi?id=75930
     5
     6        Reviewed by Hajime Morita.
     7
     8        DETAILS is reimplemented using content element and its fallback feature.
     9        We don't need to recreate DOM even if SUMMARY is removed from or added into DETAILS.
     10
     11        No new tests, should be covered by existing tests.
     12
     13        * html/HTMLDetailsElement.cpp:
     14        (WebCore::DetailsSummaryElement::fallbackSummary):
     15          Takes fallback element of content summary.
     16        (DetailsSummaryElement):
     17        (WebCore::DetailsSummaryElement::create):
     18          Creates a fallback element also.
     19        (WebCore):
     20        (WebCore::HTMLDetailsElement::create):
     21        (WebCore::HTMLDetailsElement::HTMLDetailsElement):
     22        (WebCore::HTMLDetailsElement::createShadowSubtree):
     23        (WebCore::HTMLDetailsElement::findMainSummary):
     24        (WebCore::HTMLDetailsElement::parseMappedAttribute):
     25        (WebCore::HTMLDetailsElement::childShouldCreateRenderer):
     26        (WebCore::HTMLDetailsElement::toggleOpen):
     27        * html/HTMLDetailsElement.h:
     28        (HTMLDetailsElement):
     29        * html/HTMLSummaryElement.cpp:
     30        (WebCore::HTMLSummaryElement::isMainSummary):
     31
    1322012-02-03  Jochen Eisinger  <jochen@chromium.org>
    233
  • trunk/Source/WebCore/html/HTMLDetailsElement.cpp

    r105249 r106637  
    6363    static PassRefPtr<DetailsSummaryElement> create(Document*);
    6464
     65    Element* fallbackSummary()
     66    {
     67        ASSERT(firstChild() && firstChild()->hasTagName(summaryTag));
     68        return toElement(firstChild());
     69    }
     70
    6571private:
    6672    DetailsSummaryElement(Document* document)
     
    7379PassRefPtr<DetailsSummaryElement> DetailsSummaryElement::create(Document* document)
    7480{
    75     return adoptRef(new DetailsSummaryElement(document));
     81    RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(summaryTag, document);
     82    defaultSummary->appendChild(Text::create(document, defaultDetailsSummaryText()), ASSERT_NO_EXCEPTION);
     83
     84    DetailsSummaryElement* elem = new DetailsSummaryElement(document);
     85    elem->appendChild(defaultSummary);
     86    return adoptRef(elem);
    7687}
    7788
    7889PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(const QualifiedName& tagName, Document* document)
    7990{
    80     RefPtr<HTMLDetailsElement> result = adoptRef(new HTMLDetailsElement(tagName, document));
    81     result->ensureShadowSubtreeOf(ForwardingSummary);
    82     return result;
     91    RefPtr<HTMLDetailsElement> elem = adoptRef(new HTMLDetailsElement(tagName, document));
     92    elem->createShadowSubtree();
     93
     94    return elem.release();
    8395}
    8496
    8597HTMLDetailsElement::HTMLDetailsElement(const QualifiedName& tagName, Document* document)
    8698    : HTMLElement(tagName, document)
    87     , m_summaryType(NoSummary)
    88     , m_mainSummary(0)
    8999    , m_isOpen(false)
    90100{
     
    97107}
    98108
    99 void HTMLDetailsElement::ensureShadowSubtreeOf(SummaryType type)
    100 {
    101     if (type == m_summaryType)
    102         return;
    103     m_summaryType = type;
    104     removeShadowRoot();
    105     createShadowSubtree();
    106 }
    107 
    108 static Node* findSummaryFor(PassRefPtr<ContainerNode> container)
    109 {
    110     for (Node* child = container->firstChild(); child; child = child->nextSibling()) {
    111         if (child->hasTagName(summaryTag))
    112             return child;
    113     }
    114 
    115     return 0;
    116 }
    117 
    118 Node* HTMLDetailsElement::ensureMainSummary()
    119 {
    120     Node* summary = findSummaryFor(this);
    121     if (summary) {
    122         ensureShadowSubtreeOf(ForwardingSummary);
    123         return summary;
    124     }
    125 
    126     ensureShadowSubtreeOf(DefaultSummary);
    127     return findSummaryFor(shadowRoot());
    128 }
    129 
    130 void HTMLDetailsElement::refreshMainSummary(RefreshRenderer refreshRenderer)
    131 {
    132     RefPtr<Node> oldSummary = m_mainSummary;
    133     m_mainSummary = ensureMainSummary();
    134 
    135     if (oldSummary == m_mainSummary || !attached())
    136         return;
    137 
    138     if (oldSummary && oldSummary->parentNodeForRenderingAndStyle())
    139         oldSummary->reattach();
    140     if (m_mainSummary && refreshRenderer == RefreshRendererAllowed)
    141         m_mainSummary->reattach();
    142 }
    143 
    144109void HTMLDetailsElement::createShadowSubtree()
    145110{
    146111    ASSERT(!shadowRoot());
    147     ExceptionCode ec = 0;
    148     if (m_summaryType == DefaultSummary) {
    149         RefPtr<HTMLSummaryElement> defaultSummary = HTMLSummaryElement::create(summaryTag, document());
    150         defaultSummary->appendChild(Text::create(document(), defaultDetailsSummaryText()), ec);
    151         ensureShadowRoot()->appendChild(defaultSummary, ec, true);
    152         ensureShadowRoot()->appendChild(DetailsContentElement::create(document()), ec, true);
    153     } else {
    154         ASSERT(m_summaryType == ForwardingSummary);
    155         ensureShadowRoot()->appendChild(DetailsSummaryElement::create(document()), ec, true);
    156         ensureShadowRoot()->appendChild(DetailsContentElement::create(document()), ec, true);
    157     }
     112    ensureShadowRoot()->appendChild(DetailsSummaryElement::create(document()), ASSERT_NO_EXCEPTION, true);
     113    ensureShadowRoot()->appendChild(DetailsContentElement::create(document()), ASSERT_NO_EXCEPTION, true);
    158114}
    159115
     116Element* HTMLDetailsElement::findMainSummary() const
     117{
     118    for (Node* child = firstChild(); child; child = child->nextSibling()) {
     119        if (child->hasTagName(summaryTag))
     120            return toElement(child);
     121    }
    160122
    161 void HTMLDetailsElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    162 {
    163     HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    164     // If childCountDelta is less then zero and the main summary has changed it must be because previous main
    165     // summary was removed. The new main summary was then inside the unrevealed content and needs to be
    166     // reattached to create its renderer. If childCountDelta is not less then zero then a new <summary> element
    167     // has been added and it will be attached without our help.
    168     if (!changedByParser)
    169         refreshMainSummary(childCountDelta < 0 ? RefreshRendererAllowed : RefreshRendererSupressed);
    170 }
    171 
    172 void HTMLDetailsElement::finishParsingChildren()
    173 {
    174     HTMLElement::finishParsingChildren();
    175     refreshMainSummary(RefreshRendererAllowed);
     123    return static_cast<DetailsSummaryElement*>(shadowRoot()->firstChild())->fallbackSummary();
    176124}
    177125
     
    189137bool HTMLDetailsElement::childShouldCreateRenderer(Node* child) const
    190138{
    191     return m_isOpen || child == m_mainSummary;
     139    if (m_isOpen)
     140        return true;
     141
     142    if (!child->hasTagName(summaryTag))
     143        return false;
     144
     145    return child == findMainSummary();
    192146}
    193147
  • trunk/Source/WebCore/html/HTMLDetailsElement.h

    r95901 r106637  
    2929public:
    3030    static PassRefPtr<HTMLDetailsElement> create(const QualifiedName& tagName, Document* document);
    31     Node* mainSummary() const { return m_mainSummary; }
    3231    void toggleOpen();
    3332
     33    Element* findMainSummary() const;
     34
    3435private:
    35     enum RefreshRenderer {
    36         RefreshRendererAllowed,
    37         RefreshRendererSupressed,
    38     };
    39 
    40     enum SummaryType {
    41         NoSummary,
    42         DefaultSummary,
    43         ForwardingSummary
    44     };
    45 
    4636    HTMLDetailsElement(const QualifiedName&, Document*);
    4737
    4838    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    49     virtual void childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta);
    50     virtual void finishParsingChildren();
    5139
    5240    void parseMappedAttribute(Attribute*);
    5341    bool childShouldCreateRenderer(Node*) const;
    5442
    55     Node* ensureMainSummary();
    56     void refreshMainSummary(RefreshRenderer);
    57     void ensureShadowSubtreeOf(SummaryType);
    5843    void createShadowSubtree();
    5944
    60     SummaryType m_summaryType;
    61     Node* m_mainSummary;
    6245    bool m_isOpen;
    6346
  • trunk/Source/WebCore/html/HTMLSummaryElement.cpp

    r105249 r106637  
    9090{
    9191    if (HTMLDetailsElement* details = detailsElement())
    92         return details->mainSummary() == this;
    93     return 0;
     92        return details->findMainSummary() == this;
     93
     94    return false;
    9495}
    9596
Note: See TracChangeset for help on using the changeset viewer.