Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Unified Diff: Source/core/page/AutoscrollController.cpp

Issue 46353003: Switch AutoscrollController to use animation system instead of timer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@gclient
Patch Set: addresses review feedback Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/page/AutoscrollController.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/AutoscrollController.cpp
diff --git a/Source/core/page/AutoscrollController.cpp b/Source/core/page/AutoscrollController.cpp
index 25eaf8a28b538b47a431f4f6ecea66d109a63936..6050c54432a6a6175d9159120df022ee245e0657 100644
--- a/Source/core/page/AutoscrollController.cpp
+++ b/Source/core/page/AutoscrollController.cpp
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
* Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
@@ -31,6 +32,7 @@
#include "core/page/EventHandler.h"
#include "core/frame/Frame.h"
#include "core/frame/FrameView.h"
+#include "core/page/Chrome.h"
#include "core/page/Page.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/RenderBox.h"
@@ -41,16 +43,13 @@ namespace WebCore {
// Delay time in second for start autoscroll if pointer is in border edge of scrollable element.
static double autoscrollDelay = 0.2;
-// When the autoscroll or the panScroll is triggered when do the scroll every 0.05s to make it smooth
-static const double autoscrollInterval = 0.05;
-
-PassOwnPtr<AutoscrollController> AutoscrollController::create()
+PassOwnPtr<AutoscrollController> AutoscrollController::create(Page& page)
{
- return adoptPtr(new AutoscrollController());
+ return adoptPtr(new AutoscrollController(page));
}
-AutoscrollController::AutoscrollController()
- : m_autoscrollTimer(this, &AutoscrollController::autoscrollTimerFired)
+AutoscrollController::AutoscrollController(Page& page)
+ : m_page(page)
, m_autoscrollRenderer(0)
, m_autoscrollType(NoAutoscroll)
, m_dragAndDropAutoscrollStartTime(0)
@@ -70,20 +69,19 @@ bool AutoscrollController::autoscrollInProgress(const RenderBox* renderer) const
void AutoscrollController::startAutoscrollForSelection(RenderObject* renderer)
{
// We don't want to trigger the autoscroll or the panScroll if it's already active
- if (m_autoscrollTimer.isActive())
+ if (m_autoscrollType != NoAutoscroll)
return;
RenderBox* scrollable = RenderBox::findAutoscrollable(renderer);
if (!scrollable)
return;
m_autoscrollType = AutoscrollForSelection;
m_autoscrollRenderer = scrollable;
- startAutoscrollTimer();
+ startAutoscroll();
}
-void AutoscrollController::stopAutoscrollTimer()
+void AutoscrollController::stopAutoscroll()
{
RenderBox* scrollable = m_autoscrollRenderer;
- m_autoscrollTimer.stop();
m_autoscrollRenderer = 0;
if (!scrollable)
@@ -108,7 +106,6 @@ void AutoscrollController::stopAutoscrollIfNeeded(RenderObject* renderer)
return;
m_autoscrollRenderer = 0;
m_autoscrollType = NoAutoscroll;
- m_autoscrollTimer.stop();
}
void AutoscrollController::updateAutoscrollRenderer()
@@ -133,7 +130,7 @@ void AutoscrollController::updateAutoscrollRenderer()
void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoint& eventPosition, double eventTime)
{
if (!dropTargetNode || !dropTargetNode->renderer()) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
@@ -142,19 +139,19 @@ void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoin
RenderBox* scrollable = RenderBox::findAutoscrollable(dropTargetNode->renderer());
if (!scrollable) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
Page* page = scrollable->frame() ? scrollable->frame()->page() : 0;
if (!page) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
IntSize offset = scrollable->calculateAutoscrollDirection(eventPosition);
if (offset.isZero()) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
@@ -164,7 +161,7 @@ void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoin
m_autoscrollType = AutoscrollForDragAndDrop;
m_autoscrollRenderer = scrollable;
m_dragAndDropAutoscrollStartTime = eventTime;
- startAutoscrollTimer();
+ startAutoscroll();
} else if (m_autoscrollRenderer != scrollable) {
m_dragAndDropAutoscrollStartTime = eventTime;
m_autoscrollRenderer = scrollable;
@@ -183,7 +180,7 @@ void AutoscrollController::handleMouseReleaseForPanScrolling(Frame* frame, const
m_autoscrollType = AutoscrollForPanCanStop;
break;
case AutoscrollForPanCanStop:
- stopAutoscrollTimer();
+ stopAutoscroll();
break;
}
}
@@ -196,7 +193,7 @@ bool AutoscrollController::panScrollInProgress() const
void AutoscrollController::startPanScrolling(RenderBox* scrollable, const IntPoint& lastKnownMousePosition)
{
// We don't want to trigger the autoscroll or the panScroll if it's already active
- if (m_autoscrollTimer.isActive())
+ if (m_autoscrollType != NoAutoscroll)
return;
m_autoscrollType = AutoscrollForPan;
@@ -205,7 +202,7 @@ void AutoscrollController::startPanScrolling(RenderBox* scrollable, const IntPoi
if (FrameView* view = scrollable->frame()->view())
view->addPanScrollIcon(lastKnownMousePosition);
- startAutoscrollTimer();
+ startAutoscroll();
}
#else
bool AutoscrollController::panScrollInProgress() const
@@ -214,10 +211,12 @@ bool AutoscrollController::panScrollInProgress() const
}
#endif
-void AutoscrollController::autoscrollTimerFired(Timer<AutoscrollController>*)
+// FIXME: This would get get better animation fidelity if it used the monotonicFrameBeginTime instead
+// of WTF::currentTime().
+void AutoscrollController::animate(double)
{
if (!m_autoscrollRenderer) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
@@ -229,7 +228,7 @@ void AutoscrollController::autoscrollTimerFired(Timer<AutoscrollController>*)
break;
case AutoscrollForSelection:
if (!eventHandler.mousePressed()) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
eventHandler.updateSelectionForMouseDrag();
@@ -241,7 +240,7 @@ void AutoscrollController::autoscrollTimerFired(Timer<AutoscrollController>*)
case AutoscrollForPanCanStop:
case AutoscrollForPan:
if (!panScrollInProgress()) {
- stopAutoscrollTimer();
+ stopAutoscroll();
return;
}
if (FrameView* view = m_autoscrollRenderer->frame()->view())
@@ -250,11 +249,13 @@ void AutoscrollController::autoscrollTimerFired(Timer<AutoscrollController>*)
break;
#endif
}
+ if (m_autoscrollType != NoAutoscroll)
+ m_page.chrome().scheduleAnimation();
}
-void AutoscrollController::startAutoscrollTimer()
+void AutoscrollController::startAutoscroll()
{
- m_autoscrollTimer.startRepeating(autoscrollInterval);
+ m_page.chrome().scheduleAnimation();
}
#if OS(WIN)
« no previous file with comments | « Source/core/page/AutoscrollController.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698