Commit b704b429 authored by akling@apple.com's avatar akling@apple.com

Throttle resize events during live window resize.

<http://webkit.org/b/114292>
<rdar://problem/13411454>

Reviewed by Geoffrey Garen.

Limit resize events to one at max every 0.2 seconds during live window resize.
This mitigates heavy CPU usage during resize on pages with complex onresize handlers.
If there's a pending resize event when the live resize ends, it fires immediately.

* page/FrameView.cpp:
(WebCore::FrameView::sendResizeEvent):

    Factored out dispatch of the resize event after layout so we can call it on a timer
    instead of immediately while live window resize is active.

(WebCore::FrameView::FrameView):
(WebCore::FrameView::performPostLayoutTasks):
(WebCore::FrameView::delayedResizeEventTimerFired):
(WebCore::FrameView::willEndLiveResize):
(WebCore::FrameView::scheduleResizeEvent):
* page/FrameView.h:
* platform/ScrollableArea.h:

    Made willStartLiveResize() and willEndLiveResize() virtual so we can override
    them on FrameView.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 60947694
2013-04-09 Andreas Kling <akling@apple.com>
Throttle resize events during live window resize.
<http://webkit.org/b/114292>
<rdar://problem/13411454>
Reviewed by Geoffrey Garen.
Limit resize events to one at max every 0.2 seconds during live window resize.
This mitigates heavy CPU usage during resize on pages with complex onresize handlers.
If there's a pending resize event when the live resize ends, it fires immediately.
* page/FrameView.cpp:
(WebCore::FrameView::sendResizeEvent):
Factored out dispatch of the resize event after layout so we can call it on a timer
instead of immediately while live window resize is active.
(WebCore::FrameView::FrameView):
(WebCore::FrameView::performPostLayoutTasks):
(WebCore::FrameView::delayedResizeEventTimerFired):
(WebCore::FrameView::willEndLiveResize):
(WebCore::FrameView::scheduleResizeEvent):
* page/FrameView.h:
* platform/ScrollableArea.h:
Made willStartLiveResize() and willEndLiveResize() virtual so we can override
them on FrameView.
2013-04-09 Jeff Rogers <jrogers@rim.com>
Add webp to supported image mime types if WEBP feature is enabled/used
......@@ -122,6 +122,9 @@ double FrameView::s_maxDeferredRepaintDelayDuringLoading = 0;
double FrameView::s_deferredRepaintDelayIncrementDuringLoading = 0;
#endif
// While the browser window is being resized, resize events will be dispatched at most this often.
static const double minimumIntervalBetweenResizeEventsDuringLiveResizeInSeconds = 0.2;
// The maximum number of updateWidgets iterations that should be done before returning.
static const unsigned maxUpdateWidgetsIterations = 2;
......@@ -168,6 +171,7 @@ FrameView::FrameView(Frame* frame)
: m_frame(frame)
, m_canHaveScrollbars(true)
, m_slowRepaintObjectCount(0)
, m_delayedResizeEventTimer(this, &FrameView::delayedResizeEventTimerFired)
, m_layoutTimer(this, &FrameView::layoutTimerFired)
, m_layoutRoot(0)
, m_inSynchronousPostLayout(false)
......@@ -2735,20 +2739,51 @@ void FrameView::performPostLayoutTasks()
m_lastViewportSize = currentSize;
m_lastZoomFactor = currentZoomFactor;
if (resized) {
m_frame->eventHandler()->sendResizeEvent();
if (inLiveResize())
scheduleResizeEvent();
else
sendResizeEvent();
}
}
}
void FrameView::sendResizeEvent()
{
if (!m_frame)
return;
m_frame->eventHandler()->sendResizeEvent();
#if ENABLE(INSPECTOR)
if (InspectorInstrumentation::hasFrontends()) {
if (page) {
if (page->mainFrame() == m_frame) {
if (InspectorClient* inspectorClient = page->inspectorController()->inspectorClient())
inspectorClient->didResizeMainFrame(m_frame.get());
}
}
if (InspectorInstrumentation::hasFrontends()) {
if (Page* page = m_frame->page()) {
if (page->mainFrame() == m_frame) {
if (InspectorClient* inspectorClient = page->inspectorController()->inspectorClient())
inspectorClient->didResizeMainFrame(m_frame.get());
}
#endif
}
}
#endif
}
void FrameView::delayedResizeEventTimerFired(Timer<FrameView>*)
{
sendResizeEvent();
}
void FrameView::willEndLiveResize()
{
ScrollableArea::willEndLiveResize();
if (m_delayedResizeEventTimer.isActive()) {
m_delayedResizeEventTimer.stop();
sendResizeEvent();
}
}
void FrameView::scheduleResizeEvent()
{
if (!m_delayedResizeEventTimer.isActive())
m_delayedResizeEventTimer.startOneShot(minimumIntervalBetweenResizeEventsDuringLiveResizeInSeconds);
}
void FrameView::postLayoutTimerFired(Timer<FrameView>*)
......
......@@ -414,6 +414,8 @@ public:
virtual int footerHeight() const OVERRIDE { return m_footerHeight; }
void setFooterHeight(int);
virtual void willEndLiveResize() OVERRIDE;
protected:
virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect);
virtual void scrollContentsSlowPath(const IntRect& updateRect);
......@@ -480,6 +482,10 @@ private:
#endif
#endif
void scheduleResizeEvent();
void sendResizeEvent();
void delayedResizeEventTimerFired(Timer<FrameView>*);
void updateScrollableAreaSet();
virtual void notifyPageThatContentAreaWillPaint() const;
......@@ -526,6 +532,8 @@ private:
int m_borderX;
int m_borderY;
Timer<FrameView> m_delayedResizeEventTimer;
Timer<FrameView> m_layoutTimer;
bool m_delayedLayout;
RenderObject* m_layoutRoot;
......
......@@ -69,8 +69,8 @@ public:
ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
bool inLiveResize() const { return m_inLiveResize; }
void willStartLiveResize();
void willEndLiveResize();
virtual void willStartLiveResize();
virtual void willEndLiveResize();
void contentAreaWillPaint() const;
void mouseEnteredContentArea() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment