⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 112919 in webkit


Ignore:
Timestamp:
Apr 2, 2012, 12:37:59 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

Scroll position is lost after hide/show element
https://bugs.webkit.org/show_bug.cgi?id=72852

Source/WebCore:

Maintain the scroll position of an overflowing element in the ElementRareData when the scrollable
RenderLayer is destroyed, which can be used to restore the scroll position if the same element gets
back a RenderLayer.

WebKit behaviour will be the same as Firefox and IE. It differs from Opera as it does not reset the
scroll position when an element is moved to another location in the same document. However Opera resets
the scroll position for elements moved to another document, which matches other browsers.

Patch by Rakesh KN <rakesh.kn@motorola.com> on 2012-04-02
Reviewed by Julien Chaffraix.

Test: fast/overflow/scroll-div-hide-show.html

  • dom/Element.cpp:

(WebCore::Element::removedFromDocument):
Reset the saved scroll offset if the node is moved to another location in the same document or another one.

(WebCore::Element::savedLayerScrollOffset):
(WebCore::Element::setSavedLayerScrollOffset):

  • dom/Element.h:

Add helper functions to access the layer scroll offset from the element's rare data.

  • dom/ElementRareData.h:

(ElementRareData):
Add the scroll offset book-keeping.

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::RenderLayer):
Restore the scroll offset.
(WebCore::RenderLayer::~RenderLayer):
Store the scroll offset if document is not being destroyed.

LayoutTests:

Patch by Rakesh KN <rakesh.kn@motorola.com> on 2012-04-02
Reviewed by Julien Chaffraix.

  • fast/overflow/scroll-div-hide-show-expected.txt: Added.
  • fast/overflow/scroll-div-hide-show.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r112918 r112919  
     12012-04-02  Rakesh KN  <rakesh.kn@motorola.com>
     2
     3        Scroll position is lost after hide/show element
     4        https://bugs.webkit.org/show_bug.cgi?id=72852
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        * fast/overflow/scroll-div-hide-show-expected.txt: Added.
     9        * fast/overflow/scroll-div-hide-show.html: Added.
     10
    1112012-04-02  Stephen Chenney  <schenney@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r112914 r112919  
     12012-04-02  Rakesh KN  <rakesh.kn@motorola.com>
     2
     3        Scroll position is lost after hide/show element
     4        https://bugs.webkit.org/show_bug.cgi?id=72852
     5
     6        Maintain the scroll position of an overflowing element in the ElementRareData when the scrollable
     7        RenderLayer is destroyed, which can be used to restore the scroll position if the same element gets
     8        back a RenderLayer.
     9
     10        WebKit behaviour will be the same as Firefox and IE. It differs from Opera as it does not reset the
     11        scroll position when an element is moved to another location in the same document. However Opera resets
     12        the scroll position for elements moved to another document, which matches other browsers.
     13
     14        Reviewed by Julien Chaffraix.
     15
     16        Test: fast/overflow/scroll-div-hide-show.html
     17
     18        * dom/Element.cpp:
     19        (WebCore::Element::removedFromDocument):
     20        Reset the saved scroll offset if the node is moved to another location in the same document or another one.
     21
     22        (WebCore::Element::savedLayerScrollOffset):
     23        (WebCore::Element::setSavedLayerScrollOffset):
     24        * dom/Element.h:
     25        Add helper functions to access the layer scroll offset from the element's rare data.
     26
     27        * dom/ElementRareData.h:
     28        (ElementRareData):
     29        Add the scroll offset book-keeping.
     30
     31        * rendering/RenderLayer.cpp:
     32        (WebCore::RenderLayer::RenderLayer):
     33        Restore the scroll offset.
     34        (WebCore::RenderLayer::~RenderLayer):
     35        Store the scroll offset if document is not being destroyed.
     36
    1372012-04-02  Alexis Menard  <alexis.menard@openbossa.org>
    238
  • trunk/Source/WebCore/dom/Element.cpp

    r112765 r112919  
    904904void Element::removedFromDocument()
    905905{
     906    setSavedLayerScrollOffset(IntSize());
     907
    906908    if (m_attributeData) {
    907909        if (hasID()) {
     
    20672069}
    20682070
     2071IntSize Element::savedLayerScrollOffset() const
     2072{
     2073    return hasRareData() ? rareData()->m_savedLayerScrollOffset : IntSize();
     2074}
     2075
     2076void Element::setSavedLayerScrollOffset(const IntSize& size)
     2077{
     2078    if (size.isZero() && !hasRareData())
     2079        return;
     2080    ensureRareData()->m_savedLayerScrollOffset = size;
     2081}
     2082
    20692083} // namespace WebCore
  • trunk/Source/WebCore/dom/Element.h

    r112170 r112919  
    403403    bool hasClass() const;
    404404
     405    IntSize savedLayerScrollOffset() const;
     406    void setSavedLayerScrollOffset(const IntSize&);
     407
    405408protected:
    406409    Element(const QualifiedName& tagName, Document* document, ConstructionType type)
  • trunk/Source/WebCore/dom/ElementRareData.h

    r112170 r112919  
    7575    bool m_styleAffectedByEmpty;
    7676
     77    IntSize m_savedLayerScrollOffset;
     78
    7779#if ENABLE(FULLSCREEN_API)
    7880    bool m_containsFullScreenElement;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r112745 r112919  
    195195        m_hasVisibleContent = renderer->style()->visibility() == VISIBLE;
    196196    }
     197
     198    Node* node = renderer->node();
     199    if (node && node->isElementNode()) {
     200        // We save and restore only the scrollOffset as the other scroll values are recalculated.
     201        Element* element = toElement(node);
     202        m_scrollOffset = element->savedLayerScrollOffset();
     203        element->setSavedLayerScrollOffset(IntSize());
     204    }
    197205}
    198206
     
    207215        if (FrameView* frameView = frame->view())
    208216            frameView->removeScrollableArea(this);
     217    }
     218
     219    if (!m_renderer->documentBeingDestroyed()) {
     220        Node* node = m_renderer->node();
     221        if (node && node->isElementNode())
     222            toElement(node)->setSavedLayerScrollOffset(m_scrollOffset);
    209223    }
    210224
Note: See TracChangeset for help on using the changeset viewer.