Changeset 109587 in webkit


Ignore:
Timestamp:
Mar 2, 2012 11:24:18 AM (12 years ago)
Author:
jchaffraix@webkit.org
Message:

Move the 'overflow' event dispatching logic out of RenderLayer
https://bugs.webkit.org/show_bug.cgi?id=80090

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/events/overflow-events-writing-mode.html

This moves the 'overflow' event dispatch from RenderLayer to an helper class
OverflowEventDispatcher. For now, the class lives in RenderBlock as it matches
the existing code but it may be moved later to its own class as FrameView could
benefit from it too or if we need to support 'overflow' events on RenderBoxes.

  • rendering/RenderBlock.cpp:

(WebCore):
(OverflowEventDispatcher):
(WebCore::OverflowEventDispatcher::OverflowEventDispatcher):
(WebCore::OverflowEventDispatcher::~OverflowEventDispatcher):
(WebCore::OverflowEventDispatcher::computeOverflowStatus):
RAII dispatcher class that stores the information before layout and compare
them after to dispatch the right information.

(WebCore::RenderBlock::layout): Added an instance of OverflowEventDispatcher.

  • rendering/RenderBox.h:

(WebCore::RenderBox::hasHorizontalLayoutOverflow):
(WebCore::RenderBox::hasVerticalLayoutOverflow):
Helper method to know if we have an horizontal / vertical layout overflow.

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::RenderLayer):
(WebCore::RenderLayer::updateScrollInfoAfterLayout):

  • rendering/RenderLayer.h:

Removed the scroll tracking logic as we don't need it anymore. This removes
3 booleans from RenderLayer.

LayoutTests:

  • fast/events/overflow-events-writing-mode.html: Added.
  • fast/events/overflow-events-writing-mode-expected.txt: Added.

Added a test for overflow events in a vertical writing mode.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r109586 r109587  
     12012-03-02  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Move the 'overflow' event dispatching logic out of RenderLayer
     4        https://bugs.webkit.org/show_bug.cgi?id=80090
     5
     6        Reviewed by Simon Fraser.
     7
     8        * fast/events/overflow-events-writing-mode.html: Added.
     9        * fast/events/overflow-events-writing-mode-expected.txt: Added.
     10        Added a test for overflow events in a vertical writing mode.
     11
    1122012-03-02  Adam Klein  <adamk@chromium.org>
    213
  • trunk/Source/WebCore/ChangeLog

    r109585 r109587  
     12012-03-02  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Move the 'overflow' event dispatching logic out of RenderLayer
     4        https://bugs.webkit.org/show_bug.cgi?id=80090
     5
     6        Reviewed by Simon Fraser.
     7
     8        Test: fast/events/overflow-events-writing-mode.html
     9
     10        This moves the 'overflow' event dispatch from RenderLayer to an helper class
     11        OverflowEventDispatcher. For now, the class lives in RenderBlock as it matches
     12        the existing code but it may be moved later to its own class as FrameView could
     13        benefit from it too or if we need to support 'overflow' events on RenderBoxes.
     14
     15        * rendering/RenderBlock.cpp:
     16        (WebCore):
     17        (OverflowEventDispatcher):
     18        (WebCore::OverflowEventDispatcher::OverflowEventDispatcher):
     19        (WebCore::OverflowEventDispatcher::~OverflowEventDispatcher):
     20        (WebCore::OverflowEventDispatcher::computeOverflowStatus):
     21        RAII dispatcher class that stores the information before layout and compare
     22        them after to dispatch the right information.
     23
     24        (WebCore::RenderBlock::layout): Added an instance of OverflowEventDispatcher.
     25
     26        * rendering/RenderBox.h:
     27        (WebCore::RenderBox::hasHorizontalLayoutOverflow):
     28        (WebCore::RenderBox::hasVerticalLayoutOverflow):
     29        Helper method to know if we have an horizontal / vertical layout overflow.
     30
     31        * rendering/RenderLayer.cpp:
     32        (WebCore::RenderLayer::RenderLayer):
     33        (WebCore::RenderLayer::updateScrollInfoAfterLayout):
     34        * rendering/RenderLayer.h:
     35        Removed the scroll tracking logic as we don't need it anymore. This removes
     36        3 booleans from RenderLayer.
     37
    1382012-03-02  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
    239
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r109512 r109587  
    3939#include "InlineTextBox.h"
    4040#include "LayoutRepainter.h"
     41#include "OverflowEvent.h"
    4142#include "PODFreeListArena.h"
    4243#include "Page.h"
     
    8586
    8687bool RenderBlock::s_canPropagateFloatIntoSibling = false;
     88
     89// This class helps dispatching the 'overflow' event on layout change. overflow can be set on RenderBoxes, yet the existing code
     90// only works on RenderBlocks. If this change, this class should be shared with other RenderBoxes.
     91class OverflowEventDispatcher {
     92    WTF_MAKE_NONCOPYABLE(OverflowEventDispatcher);
     93public:
     94    OverflowEventDispatcher(const RenderBlock* block)
     95        : m_block(block)
     96        , m_hadHorizontalLayoutOverflow(false)
     97        , m_hadVerticalLayoutOverflow(false)
     98    {
     99        m_shouldDispatchEvent = !m_block->isAnonymous() && m_block->hasOverflowClip() && m_block->document()->hasListenerType(Document::OVERFLOWCHANGED_LISTENER);
     100        if (m_shouldDispatchEvent) {
     101            m_hadHorizontalLayoutOverflow = m_block->hasHorizontalLayoutOverflow();
     102            m_hadVerticalLayoutOverflow = m_block->hasVerticalLayoutOverflow();
     103        }
     104    }
     105
     106    ~OverflowEventDispatcher()
     107    {
     108        if (!m_shouldDispatchEvent)
     109            return;
     110
     111        bool hasHorizontalLayoutOverflow = m_block->hasHorizontalLayoutOverflow();
     112        bool hasVerticalLayoutOverflow = m_block->hasVerticalLayoutOverflow();
     113
     114        bool horizontalLayoutOverflowChanged = hasHorizontalLayoutOverflow != m_hadHorizontalLayoutOverflow;
     115        bool verticalLayoutOverflowChanged = hasVerticalLayoutOverflow != m_hadVerticalLayoutOverflow;
     116        if (horizontalLayoutOverflowChanged || verticalLayoutOverflowChanged) {
     117            if (FrameView* frameView = m_block->document()->view())
     118                frameView->scheduleEvent(OverflowEvent::create(horizontalLayoutOverflowChanged, hasHorizontalLayoutOverflow, verticalLayoutOverflowChanged, hasVerticalLayoutOverflow), m_block->node());
     119        }
     120    }
     121
     122private:
     123    void computeOverflowStatus(bool& hasHorizontalLayoutOverflow, bool& hasVerticalLayoutOverflow)
     124    {
     125    }
     126
     127    const RenderBlock* m_block;
     128    bool m_shouldDispatchEvent;
     129    bool m_hadHorizontalLayoutOverflow;
     130    bool m_hadVerticalLayoutOverflow;
     131};
    87132
    88133// Our MarginInfo state used when laying out block children.
     
    13221367void RenderBlock::layout()
    13231368{
     1369    OverflowEventDispatcher dispatcher(this);
     1370
    13241371    // Update our first letter info now.
    13251372    updateFirstLetter();
  • trunk/Source/WebCore/rendering/RenderBox.h

    r109383 r109587  
    453453    virtual bool hasRelativeDimensions() const;
    454454
     455    bool hasHorizontalLayoutOverflow() const
     456    {
     457        if (RenderOverflow* overflow = hasRenderOverflow()) {
     458            LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
     459            flipForWritingMode(layoutOverflowRect);
     460            return layoutOverflowRect.x() < x() || layoutOverflowRect.maxX() > x() + logicalWidth();
     461        }
     462
     463        return false;
     464    }
     465
     466    bool hasVerticalLayoutOverflow() const
     467    {
     468        if (RenderOverflow* overflow = hasRenderOverflow()) {
     469            LayoutRect layoutOverflowRect = overflow->layoutOverflowRect();
     470            flipForWritingMode(layoutOverflowRect);
     471            return layoutOverflowRect.y() < y() || layoutOverflowRect.maxY() > y() + logicalHeight();
     472        }
     473
     474        return false;
     475    }
     476
    455477protected:
    456478    virtual void willBeDestroyed();
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r109512 r109587  
    154154    , m_inOverflowRelayout(false)
    155155    , m_repaintStatus(NeedsNormalRepaint)
    156     , m_overflowStatusDirty(true)
    157156    , m_visibleContentStatusDirty(true)
    158157    , m_hasVisibleContent(false)
     
    23192318}
    23202319
    2321 void RenderLayer::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow)
    2322 {
    2323     if (m_overflowStatusDirty) {
    2324         m_horizontalOverflow = horizontalOverflow;
    2325         m_verticalOverflow = verticalOverflow;
    2326         m_overflowStatusDirty = false;
    2327         return;
    2328     }
    2329    
    2330     bool horizontalOverflowChanged = (m_horizontalOverflow != horizontalOverflow);
    2331     bool verticalOverflowChanged = (m_verticalOverflow != verticalOverflow);
    2332    
    2333     if (horizontalOverflowChanged || verticalOverflowChanged) {
    2334         m_horizontalOverflow = horizontalOverflow;
    2335         m_verticalOverflow = verticalOverflow;
    2336        
    2337         if (FrameView* frameView = renderer()->document()->view()) {
    2338             frameView->scheduleEvent(OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow, verticalOverflowChanged, verticalOverflow),
    2339                 renderer()->node());
    2340         }
    2341     }
    2342 }
    2343 
    23442320void RenderLayer::updateScrollInfoAfterLayout()
    23452321{
     
    24352411    if (scrollOffsetOriginal != scrollOffset())
    24362412        scrollToOffsetWithoutAnimation(LayoutPoint(scrollXOffset(), scrollYOffset()));
    2437 
    2438     if (renderer()->node() && renderer()->document()->hasListenerType(Document::OVERFLOWCHANGED_LISTENER))
    2439         updateOverflowStatus(horizontalOverflow, verticalOverflow);
    24402413}
    24412414
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r109512 r109587  
    681681    IntSize scrollbarOffset(const Scrollbar*) const;
    682682   
    683     void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow);
    684 
    685683    void childVisibilityChanged(bool newVisibility);
    686684    void dirtyVisibleDescendantStatus();
     
    777775    unsigned m_repaintStatus : 2; // RepaintStatus
    778776
    779     bool m_overflowStatusDirty : 1;
    780     bool m_horizontalOverflow : 1;
    781     bool m_verticalOverflow : 1;
    782777    bool m_visibleContentStatusDirty : 1;
    783778    bool m_hasVisibleContent : 1;
Note: See TracChangeset for help on using the changeset viewer.