Changeset 137726 in webkit


Ignore:
Timestamp:
Dec 14, 2012 12:32:28 AM (11 years ago)
Author:
yosin@chromium.org
Message:

Handling autoscroll in EventHandler should be re-factor
https://bugs.webkit.org/show_bug.cgi?id=104764

Reviewed by Hajime Morita.

This patch introduces new class AutoscrollController for moving autoscroll
and panscroll from EventHandler class for ease of maintenance of
EventHandler and ease of adding autoscroll related features, e.g. autoscroll
during drag-and-drop, autoscoll by gesture.

No new tests. This patch doesn't change behavior.

  • CMakeLists.txt: Changed to add page/AutoscrollController.cpp
  • GNUmakefile.list.am: Changed to add page/AutoscrollController.{cpp,h}
  • Target.pri: Changed to add page/AutoscrollController.cpp
  • WebCore.gypi: Changed to add page/AutoscrollController.{cpp,h}
  • WebCore.vcproj/WebCore.vcproj: Changed to add page/AutoscrollController.{cpp,h}
  • WebCore.xcodeproj/project.pbxproj: Changed to add page/AutoscrollController.{cpp,h}
  • page/AutoscrollController.cpp: Added.

(WebCore::getMainFrame): Helper function.
(WebCore::AutoscrollController::AutoscrollController): Moved from EventHandler.
(WebCore::AutoscrollController::autoscrollRenderer): Moved from EventHandler.
(WebCore::AutoscrollController::autoscrollInProgress): Moved from EventHandler.
(WebCore::AutoscrollController::startAutoscrollForSelection): Replacement of EventHandler::handleAutoscroll().
(WebCore::AutoscrollController::stopAutoscrollTimer): Moveed from EventHandler.
(WebCore::AutoscrollController::updateAutoscrollRenderer): ditto
(WebCore::AutoscrollController::didPanScrollStart): Added for updating pan scrolling status of main frame.
(WebCore::AutoscrollController::didPanScrollStop): ditto
(WebCore::AutoscrollController::handleMouseReleaseEvent): Extracted from EventHandler.
(WebCore::AutoscrollController::panScrollInProgress): Replacement of EventHandler::m_panScrollInProgress.
(WebCore::AutoscrollController::startPanScrolling): Moved from EventHandler::startPanScrolling()
(WebCore::AutoscrollController::autoscrollTimerFired): Moved from EventHandler::autoscrollTimerFired().
(WebCore::AutoscrollController::startAutoscrollTimer): Moved from EventHandler::startAutoscrollTimer().
(WebCore::AutoscrollController::updatePanScrollState): Moved from EventHandler::updatePanScrollState().

  • page/AutoscrollController.h: Added.

(AutoscrollController):

  • page/EventHandler.cpp:

(WebCore::EventHandler::EventHandler): Changed autoscroll and panscroll related member variable initializations to m_autoscrollController initialization.
(WebCore::EventHandler::handleMouseDraggedEvent): Changed to call AutoscrollController::startAutoscrollForSelection().
(WebCore::EventHandler::handleMouseReleaseEvent): Changed to remove m_autoscrollInProgress reference.
(WebCore::EventHandler::didPanScrollStart): Added for updating pan scrolling status of main frame.
(WebCore::EventHandler::didPanScrollStop): ditto
(WebCore::EventHandler::startPanScrolling): Changed to call AutoscrollController::startPanScrolling().
(WebCore::EventHandler::autoscrollRenderer): Changed to use AutoscrollController.
(WebCore::EventHandler::updateAutoscrollRenderer): ditto
(WebCore::EventHandler::autoscrollInProgress): ditto
(WebCore::EventHandler::panScrollInProgress): Added to replace m_panScrollInProgress.
(WebCore::EventHandler::stopAutoscrollTimer): Changed to use AutoscrollController.
(WebCore::EventHandler::selectCursor): Changed to use panScrollInProgress().
(WebCore::EventHandler::handleMousePressEvent): Chagned to call AutoscrollController::handleMousePressEvent().
(WebCore::EventHandler::keyEvent): Changed to use panScrollInProgress().

  • page/EventHandler.h:

(WebCore::EventHandler::autoscrollController): Added for using main frame's panScrollInProgress().
(WebCore::EventHandler::mouseDownWasInSubframe): Added for AutoscrollController.

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::canAutoscroll): Moved from EventHandler.cpp.
(WebCore::RenderBox::findAutoscrollable): Moved from EventHandler.cpp.

  • rendering/RenderBox.h:

(RenderBox): Added new functions canAutoscroll() and findAutoscrollable().

Location:
trunk/Source/WebCore
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r137715 r137726  
    17211721    mathml/MathMLTextElement.cpp
    17221722
     1723    page/AutoscrollController.cpp
    17231724    page/BarInfo.cpp
    17241725    page/Chrome.cpp
  • trunk/Source/WebCore/ChangeLog

    r137724 r137726  
     12012-12-14  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        Handling autoscroll in EventHandler should be re-factor
     4        https://bugs.webkit.org/show_bug.cgi?id=104764
     5
     6        Reviewed by Hajime Morita.
     7
     8        This patch introduces new class AutoscrollController for moving autoscroll
     9        and panscroll from EventHandler class for ease of maintenance of
     10        EventHandler and ease of adding autoscroll related features, e.g. autoscroll
     11        during drag-and-drop, autoscoll by gesture.
     12
     13        No new tests. This patch doesn't change behavior.
     14
     15        * CMakeLists.txt: Changed to add page/AutoscrollController.cpp
     16        * GNUmakefile.list.am:  Changed to add page/AutoscrollController.{cpp,h}
     17        * Target.pri:  Changed to add page/AutoscrollController.cpp
     18        * WebCore.gypi: Changed to add page/AutoscrollController.{cpp,h}
     19        * WebCore.vcproj/WebCore.vcproj: Changed to add page/AutoscrollController.{cpp,h}
     20        * WebCore.xcodeproj/project.pbxproj: Changed to add page/AutoscrollController.{cpp,h}
     21        * page/AutoscrollController.cpp: Added.
     22        (WebCore::getMainFrame): Helper function.
     23        (WebCore::AutoscrollController::AutoscrollController): Moved from EventHandler.
     24        (WebCore::AutoscrollController::autoscrollRenderer): Moved from EventHandler.
     25        (WebCore::AutoscrollController::autoscrollInProgress): Moved from EventHandler.
     26        (WebCore::AutoscrollController::startAutoscrollForSelection): Replacement of EventHandler::handleAutoscroll().
     27        (WebCore::AutoscrollController::stopAutoscrollTimer): Moveed from EventHandler.
     28        (WebCore::AutoscrollController::updateAutoscrollRenderer): ditto
     29        (WebCore::AutoscrollController::didPanScrollStart): Added for updating pan scrolling status of main frame.
     30        (WebCore::AutoscrollController::didPanScrollStop): ditto
     31        (WebCore::AutoscrollController::handleMouseReleaseEvent): Extracted from EventHandler.
     32        (WebCore::AutoscrollController::panScrollInProgress): Replacement of EventHandler::m_panScrollInProgress.
     33        (WebCore::AutoscrollController::startPanScrolling): Moved from EventHandler::startPanScrolling()
     34        (WebCore::AutoscrollController::autoscrollTimerFired): Moved from EventHandler::autoscrollTimerFired().
     35        (WebCore::AutoscrollController::startAutoscrollTimer): Moved from EventHandler::startAutoscrollTimer().
     36        (WebCore::AutoscrollController::updatePanScrollState): Moved from EventHandler::updatePanScrollState().
     37        * page/AutoscrollController.h: Added.
     38        (AutoscrollController):
     39        * page/EventHandler.cpp:
     40        (WebCore::EventHandler::EventHandler): Changed autoscroll and panscroll related member variable initializations to m_autoscrollController initialization.
     41        (WebCore::EventHandler::handleMouseDraggedEvent): Changed to call AutoscrollController::startAutoscrollForSelection().
     42        (WebCore::EventHandler::handleMouseReleaseEvent): Changed to remove m_autoscrollInProgress reference.
     43        (WebCore::EventHandler::didPanScrollStart): Added for updating pan scrolling status of main frame.
     44        (WebCore::EventHandler::didPanScrollStop): ditto
     45        (WebCore::EventHandler::startPanScrolling): Changed to call AutoscrollController::startPanScrolling().
     46        (WebCore::EventHandler::autoscrollRenderer): Changed to use AutoscrollController.
     47        (WebCore::EventHandler::updateAutoscrollRenderer): ditto
     48        (WebCore::EventHandler::autoscrollInProgress): ditto
     49        (WebCore::EventHandler::panScrollInProgress): Added to replace m_panScrollInProgress.
     50        (WebCore::EventHandler::stopAutoscrollTimer): Changed to use AutoscrollController.
     51        (WebCore::EventHandler::selectCursor): Changed to use panScrollInProgress().
     52        (WebCore::EventHandler::handleMousePressEvent): Chagned to call AutoscrollController::handleMousePressEvent().
     53        (WebCore::EventHandler::keyEvent): Changed to use panScrollInProgress().
     54        * page/EventHandler.h:
     55        (WebCore::EventHandler::autoscrollController): Added for using main frame's panScrollInProgress().
     56        (WebCore::EventHandler::mouseDownWasInSubframe): Added for AutoscrollController.
     57        * rendering/RenderBox.cpp:
     58        (WebCore::RenderBox::canAutoscroll): Moved from EventHandler.cpp.
     59        (WebCore::RenderBox::findAutoscrollable): Moved from EventHandler.cpp.
     60        * rendering/RenderBox.h:
     61        (RenderBox): Added new functions canAutoscroll() and findAutoscrollable().
     62
    1632012-12-14  David Dorwin  <ddorwin@chromium.org>
    264
  • trunk/Source/WebCore/GNUmakefile.list.am

    r137715 r137726  
    40054005        Source/WebCore/page/AdjustViewSizeOrNot.h \
    40064006        Source/WebCore/page/AlternativeTextClient.h \
     4007        Source/WebCore/page/AutoscrollController.cpp \
     4008        Source/WebCore/page/AutoscrollController.h \
    40074009        Source/WebCore/page/BarInfo.cpp \
    40084010        Source/WebCore/page/BarInfo.h \
  • trunk/Source/WebCore/Target.pri

    r137715 r137726  
    870870    page/animation/ImplicitAnimation.cpp \
    871871    page/animation/KeyframeAnimation.cpp \
     872    page/AutoscrollController.cpp \
    872873    page/BarInfo.cpp \
    873874    page/Chrome.cpp \
     
    20172018    page/animation/KeyframeAnimation.h \
    20182019    page/AdjustViewSizeOrNot.h \
     2020    page/AutoscrollController.h \
    20192021    page/BarInfo.h \
    20202022    page/Chrome.h \
  • trunk/Source/WebCore/WebCore.gypi

    r137715 r137726  
    20292029            'mathml/MathMLTextElement.cpp',
    20302030            'mathml/MathMLTextElement.h',
     2031            'page/AutoscrollController.cpp',
     2032            'page/AutoscrollController.h',
    20312033            'page/BarInfo.cpp',
    20322034            'page/BarInfo.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r137703 r137726  
    2679926799                        </File>
    2680026800                        <File
     26801                                RelativePath="..\page\AutoscrollController.cpp"
     26802                                >
     26803                        </File>
     26804                        <File
     26805                                RelativePath="..\page\AutoscrollController.h"
     26806                                >
     26807                        </File>
     26808                        <File
    2680126809                                RelativePath="..\page\BarInfo.cpp"
    2680226810                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r137715 r137726  
    12331233                453EB636159C570400001BB7 /* DateTimeFormat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 453EB634159C570400001BB7 /* DateTimeFormat.cpp */; };
    12341234                453EB637159C570400001BB7 /* DateTimeFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 453EB635159C570400001BB7 /* DateTimeFormat.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1235                45830D4D1679B4F800ACF8C3 /* AutoscrollController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */; };
     1236                45830D4E1679B4F800ACF8C3 /* AutoscrollController.h in Headers */ = {isa = PBXBuildFile; fileRef = 45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12351237                45861C72161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45861C70161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.cpp */; };
    12361238                45861C73161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = 45861C71161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.h */; };
     
    84778479                453EB634159C570400001BB7 /* DateTimeFormat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateTimeFormat.cpp; sourceTree = "<group>"; };
    84788480                453EB635159C570400001BB7 /* DateTimeFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateTimeFormat.h; sourceTree = "<group>"; };
     8481                45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutoscrollController.cpp; sourceTree = "<group>"; };
     8482                45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoscrollController.h; sourceTree = "<group>"; };
    84798483                45861C70161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseMultipleFieldsDateAndTimeInputType.cpp; sourceTree = "<group>"; };
    84808484                45861C71161949DC00010F3A /* BaseMultipleFieldsDateAndTimeInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseMultipleFieldsDateAndTimeInputType.h; sourceTree = "<group>"; };
     
    1595615960                                BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
    1595715961                                CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */,
     15962                                45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */,
     15963                                45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */,
    1595815964                                BC124EE40C2641CD009E2349 /* BarInfo.cpp */,
    1595915965                                BC124EE50C2641CD009E2349 /* BarInfo.h */,
     
    2268522691                                514C764C0CE9234E007EF3CD /* AuthenticationMac.h in Headers */,
    2268622692                                51E1ECB30C91C55600DC255B /* AutodrainedPool.h in Headers */,
     22693                                45830D4E1679B4F800ACF8C3 /* AutoscrollController.h in Headers */,
    2268722694                                A8CFF04E0A154F09000A4234 /* AutoTableLayout.h in Headers */,
    2268822695                                29A812380FBB9C1D00510293 /* AXObjectCache.h in Headers */,
     
    2632326330                                514C764D0CE9234E007EF3CD /* AuthenticationMac.mm in Sources */,
    2632426331                                51E1ECAF0C91C54600DC255B /* AutodrainedPool.mm in Sources */,
     26332                                45830D4D1679B4F800ACF8C3 /* AutoscrollController.cpp in Sources */,
    2632526333                                A8CFF0500A154F09000A4234 /* AutoTableLayout.cpp in Sources */,
    2632626334                                29A8124B0FBB9CA900510293 /* AXObjectCacheMac.mm in Sources */,
  • trunk/Source/WebCore/page/EventHandler.cpp

    r137703 r137726  
    3030
    3131#include "AXObjectCache.h"
     32#include "AutoscrollController.h"
    3233#include "CachedImage.h"
    3334#include "Chrome.h"
     
    138139#endif
    139140
    140 // When the autoscroll or the panScroll is triggered when do the scroll every 0.05s to make it smooth
    141 const double autoscrollInterval = 0.05;
    142 
    143141// The amount of time to wait before sending a fake mouse event, triggered
    144142// during a scroll. The short interval is used if the content responds to the mouse events quickly enough,
     
    332330    , m_mouseDownWasSingleClickInSelection(false)
    333331    , m_selectionInitiationState(HaveNotStartedSelection)
    334     , m_panScrollInProgress(false)
    335     , m_panScrollButtonPressed(false)
    336     , m_springLoadedPanScrollInProgress(false)
    337332    , m_hoverTimer(this, &EventHandler::hoverTimerFired)
    338     , m_autoscrollTimer(this, &EventHandler::autoscrollTimerFired)
    339     , m_autoscrollRenderer(0)
    340     , m_autoscrollInProgress(false)
     333    , m_autoscrollController(adoptPtr(new AutoscrollController))
    341334    , m_mouseDownMayStartAutoscroll(false)
    342335    , m_mouseDownWasInSubframe(false)
     
    705698}
    706699
    707 // There are two kinds of renderer that can autoscroll.
    708 static bool canAutoscroll(RenderObject* renderer)
    709 {
    710     if (!renderer->isBox())
    711         return false;
    712 
    713     // Check for a box that can be scrolled in its own right.
    714     if (toRenderBox(renderer)->canBeScrolledAndHasScrollableArea())
    715         return true;
    716 
    717     // Check for a box that represents the top level of a web page.
    718     // This can be scrolled by calling Chrome::scrollRectIntoView.
    719     // This only has an effect on the Mac platform in applications
    720     // that put web views into scrolling containers, such as Mac OS X Mail.
    721     // The code for this is in RenderLayer::scrollRectToVisible.
    722     if (renderer->node() != renderer->document())
    723         return false;
    724     Frame* frame = renderer->frame();
    725     if (!frame)
    726         return false;
    727     Page* page = frame->page();
    728     return page && page->mainFrame() == frame;
    729 }
    730 
    731700#if ENABLE(DRAG_SUPPORT)
    732701bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& event)
     
    755724    m_mouseDownMayStartDrag = false;
    756725
    757     if (m_mouseDownMayStartAutoscroll && !m_panScrollInProgress) {           
    758         // Find a renderer that can autoscroll.
    759         while (renderer && !canAutoscroll(renderer)) {
    760             if (!renderer->parent() && renderer->node() == renderer->document() && renderer->document()->ownerElement())
    761                 renderer = renderer->document()->ownerElement()->renderer();
    762             else
    763                 renderer = renderer->parent();
    764         }
    765        
    766         if (renderer) {
    767             m_autoscrollInProgress = true;
    768             handleAutoscroll(renderer);
    769         }
    770        
     726    if (m_mouseDownMayStartAutoscroll && !panScrollInProgress()) {
     727        m_autoscrollController->startAutoscrollForSelection(renderer);
    771728        m_mouseDownMayStartAutoscroll = false;
    772729    }
     
    936893bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& event)
    937894{
    938     if (m_autoscrollInProgress)
     895    if (autoscrollInProgress())
    939896        stopAutoscrollTimer();
    940897
     
    991948}
    992949
    993 void EventHandler::handleAutoscroll(RenderObject* renderer)
    994 {
    995     // We don't want to trigger the autoscroll or the panScroll if it's already active
    996     if (m_autoscrollTimer.isActive())
    997         return;     
    998 
    999     setAutoscrollRenderer(renderer);
    1000 
    1001950#if ENABLE(PAN_SCROLLING)
    1002     if (m_panScrollInProgress) {
    1003         m_panScrollStartPos = lastKnownMousePosition();
    1004         if (FrameView* view = m_frame->view())
    1005             view->addPanScrollIcon(m_panScrollStartPos);
    1006         // If we're not in the top frame we notify it that we doing a panScroll.
    1007         if (Page* page = m_frame->page()) {
    1008             Frame* mainFrame = page->mainFrame();
    1009             if (m_frame != mainFrame)
    1010                 mainFrame->eventHandler()->m_panScrollInProgress = true;
    1011         }
    1012     }
    1013 #endif
    1014 
    1015     startAutoscrollTimer();
    1016 }
    1017 
    1018 void EventHandler::autoscrollTimerFired(Timer<EventHandler>*)
    1019 {
    1020     RenderObject* r = autoscrollRenderer();
    1021     if (!r || !r->isBox()) {
    1022         stopAutoscrollTimer();
     951
     952void EventHandler::didPanScrollStart()
     953{
     954    m_autoscrollController->didPanScrollStart();
     955}
     956
     957void EventHandler::didPanScrollStop()
     958{
     959    m_autoscrollController->didPanScrollStop();
     960}
     961
     962void EventHandler::startPanScrolling(RenderObject* renderer)
     963{
     964    if (!renderer->isBox())
    1023965        return;
    1024     }
    1025 
    1026     if (m_autoscrollInProgress) {
    1027         if (!m_mousePressed) {
    1028             stopAutoscrollTimer();
    1029             return;
    1030         }
    1031         toRenderBox(r)->autoscroll();
    1032     } else {
    1033         // we verify that the main frame hasn't received the order to stop the panScroll
    1034         if (Page* page = m_frame->page()) {
    1035             if (!page->mainFrame()->eventHandler()->m_panScrollInProgress) {
    1036                 stopAutoscrollTimer();
    1037                 return;
    1038             }
    1039         }
    1040 #if ENABLE(PAN_SCROLLING)
    1041         updatePanScrollState();
    1042         toRenderBox(r)->panScroll(m_panScrollStartPos);
    1043 #endif
    1044     }
    1045 }
    1046 
    1047 #if ENABLE(PAN_SCROLLING)
    1048 
    1049 void EventHandler::startPanScrolling(RenderObject* renderer)
    1050 {
    1051     m_panScrollInProgress = true;
    1052     m_panScrollButtonPressed = true;
    1053     handleAutoscroll(renderer);
     966    m_autoscrollController->startPanScrolling(toRenderBox(renderer), lastKnownMousePosition());
    1054967    invalidateClick();
    1055968}
    1056969
    1057 void EventHandler::updatePanScrollState()
    1058 {
    1059     FrameView* view = m_frame->view();
    1060     if (!view)
    1061         return;
    1062 
    1063     // At the original click location we draw a 4 arrowed icon. Over this icon there won't be any scroll
    1064     // So we don't want to change the cursor over this area
    1065     bool east = m_panScrollStartPos.x() < (m_lastKnownMousePosition.x() - ScrollView::noPanScrollRadius);
    1066     bool west = m_panScrollStartPos.x() > (m_lastKnownMousePosition.x() + ScrollView::noPanScrollRadius);
    1067     bool north = m_panScrollStartPos.y() > (m_lastKnownMousePosition.y() + ScrollView::noPanScrollRadius);
    1068     bool south = m_panScrollStartPos.y() < (m_lastKnownMousePosition.y() - ScrollView::noPanScrollRadius);
    1069          
    1070     if ((east || west || north || south) && m_panScrollButtonPressed)
    1071         m_springLoadedPanScrollInProgress = true;
    1072 
    1073     if (north) {
    1074         if (east)
    1075             view->setCursor(northEastPanningCursor());
    1076         else if (west)
    1077             view->setCursor(northWestPanningCursor());
    1078         else
    1079             view->setCursor(northPanningCursor());
    1080     } else if (south) {
    1081         if (east)
    1082             view->setCursor(southEastPanningCursor());
    1083         else if (west)
    1084             view->setCursor(southWestPanningCursor());
    1085         else
    1086             view->setCursor(southPanningCursor());
    1087     } else if (east)
    1088         view->setCursor(eastPanningCursor());
    1089     else if (west)
    1090         view->setCursor(westPanningCursor());
    1091     else
    1092         view->setCursor(middlePanningCursor());
    1093 }
    1094 
    1095970#endif // ENABLE(PAN_SCROLLING)
    1096971
    1097972RenderObject* EventHandler::autoscrollRenderer() const
    1098973{
    1099     return m_autoscrollRenderer;
     974    return m_autoscrollController->autoscrollRenderer();
    1100975}
    1101976
    1102977void EventHandler::updateAutoscrollRenderer()
    1103978{
    1104     if (!m_autoscrollRenderer)
    1105         return;
    1106 
    1107     HitTestResult hitTest = hitTestResultAtPoint(m_panScrollStartPos, true);
    1108 
    1109     if (Node* nodeAtPoint = hitTest.innerNode())
    1110         m_autoscrollRenderer = nodeAtPoint->renderer();
    1111 
    1112     while (m_autoscrollRenderer && !canAutoscroll(m_autoscrollRenderer))
    1113         m_autoscrollRenderer = m_autoscrollRenderer->parent();
    1114 }
    1115 
    1116 void EventHandler::setAutoscrollRenderer(RenderObject* renderer)
    1117 {
    1118     m_autoscrollRenderer = renderer;
     979    m_autoscrollController->updateAutoscrollRenderer();
     980}
     981
     982bool EventHandler::autoscrollInProgress() const
     983{
     984    return m_autoscrollController->autoscrollInProgress();
     985}
     986
     987bool EventHandler::panScrollInProgress() const
     988{
     989    return m_autoscrollController->panScrollInProgress();
    1119990}
    1120991
     
    11961067}
    11971068
    1198 
    1199 void EventHandler::startAutoscrollTimer()
    1200 {
    1201     m_autoscrollTimer.startRepeating(autoscrollInterval);
    1202 }
    1203 
    12041069void EventHandler::stopAutoscrollTimer(bool rendererIsBeingDestroyed)
    12051070{
    1206     if (m_autoscrollInProgress) {
    1207         if (m_mouseDownWasInSubframe) {
    1208             if (Frame* subframe = subframeForTargetNode(m_mousePressNode.get()))
    1209                 subframe->eventHandler()->stopAutoscrollTimer(rendererIsBeingDestroyed);
    1210             return;
    1211         }
    1212     }
    1213 
    1214     if (autoscrollRenderer()) {
    1215         if (!rendererIsBeingDestroyed && (m_autoscrollInProgress || m_panScrollInProgress))
    1216             toRenderBox(autoscrollRenderer())->stopAutoscroll();
    1217 #if ENABLE(PAN_SCROLLING)
    1218         if (m_panScrollInProgress) {
    1219             if (FrameView* view = m_frame->view()) {
    1220                 view->removePanScrollIcon();
    1221                 view->setCursor(pointerCursor());
    1222             }
    1223         }
    1224 #endif
    1225 
    1226         setAutoscrollRenderer(0);
    1227     }
    1228 
    1229     m_autoscrollTimer.stop();
    1230 
    1231     m_panScrollInProgress = false;
    1232     m_springLoadedPanScrollInProgress = false;
    1233 
    1234     // If we're not in the top frame we notify it that we are not doing a panScroll any more.
    1235     if (Page* page = m_frame->page()) {
    1236         Frame* mainFrame = page->mainFrame();
    1237         if (m_frame != mainFrame)
    1238             mainFrame->eventHandler()->m_panScrollInProgress = false;
    1239     }
    1240 
    1241     m_autoscrollInProgress = false;
     1071    m_autoscrollController->stopAutoscrollTimer(rendererIsBeingDestroyed);
    12421072}
    12431073
     
    14221252    if (!page)
    14231253        return NoCursorChange;
    1424     if (page->mainFrame()->eventHandler()->m_panScrollInProgress)
     1254#if ENABLE(PAN_SCROLLING)
     1255    if (page->mainFrame()->eventHandler()->panScrollInProgress())
    14251256        return NoCursorChange;
     1257#endif
    14261258
    14271259    Node* node = event.targetNode();
     
    16531485#if ENABLE(PAN_SCROLLING)
    16541486    // We store whether pan scrolling is in progress before calling stopAutoscrollTimer()
    1655     // because it will set m_panScrollInProgress to false on return.
    1656     bool isPanScrollInProgress = m_frame->page() && m_frame->page()->mainFrame()->eventHandler()->m_panScrollInProgress;
    1657     if (isPanScrollInProgress || m_autoscrollInProgress)
    1658         stopAutoscrollTimer();
     1487    // because it will set m_autoscrollType to NoAutoscroll on return.
     1488    bool isPanScrollInProgress = m_frame->page() && m_frame->page()->mainFrame()->eventHandler()->panScrollInProgress();
     1489    stopAutoscrollTimer();
    16591490    if (isPanScrollInProgress) {
    16601491        // We invalidate the click when exiting pan scrolling so that we don't inadvertently navigate
     
    19511782
    19521783#if ENABLE(PAN_SCROLLING)
    1953     if (mouseEvent.button() == MiddleButton)
    1954         m_panScrollButtonPressed = false;
    1955     if (m_springLoadedPanScrollInProgress)
    1956         stopAutoscrollTimer();
     1784    m_autoscrollController->handleMouseReleaseEvent(mouseEvent);
    19571785#endif
    19581786
     
    31442972#if ENABLE(PAN_SCROLLING)
    31452973    if (Page* page = m_frame->page()) {
    3146         if (page->mainFrame()->eventHandler()->m_panScrollInProgress) {
     2974        if (page->mainFrame()->eventHandler()->panScrollInProgress()) {
    31472975            // If a key is pressed while the panScroll is in progress then we want to stop
    31482976            if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent.type() == PlatformEvent::RawKeyDown)
  • trunk/Source/WebCore/page/EventHandler.h

    r137703 r137726  
    5252namespace WebCore {
    5353
     54class AutoscrollController;
    5455class Clipboard;
    5556class Event;
     
    110111    void setMousePressNode(PassRefPtr<Node>);
    111112
     113#if ENABLE(PAN_SCROLLING)
     114    void didPanScrollStart();
     115    void didPanScrollStop();
    112116    void startPanScrolling(RenderObject*);
     117#endif
    113118
    114119    void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
    115120    RenderObject* autoscrollRenderer() const;
    116121    void updateAutoscrollRenderer();
    117     bool autoscrollInProgress() const { return m_autoscrollInProgress; }
     122    bool autoscrollInProgress() const;
     123    bool mouseDownWasInSubframe() const { return m_mouseDownWasInSubframe; }
     124    bool panScrollInProgress() const;
    118125
    119126    void dispatchFakeMouseMoveEventSoon();
     
    270277
    271278    OptionalCursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
    272 #if ENABLE(PAN_SCROLLING)
    273     void updatePanScrollState();
    274 #endif
    275 
    276279    void hoverTimerFired(Timer<EventHandler>*);
    277280
    278     void handleAutoscroll(RenderObject*);
    279     void startAutoscrollTimer();
    280     void setAutoscrollRenderer(RenderObject*);
    281     void autoscrollTimerFired(Timer<EventHandler>*);
    282281    bool logicalScrollOverflow(ScrollLogicalDirection, ScrollGranularity, Node* startingNode = 0);
    283282   
     
    402401#endif
    403402
    404     IntPoint m_panScrollStartPos;
    405     bool m_panScrollInProgress;
    406 
    407403    bool m_panScrollButtonPressed;
    408     bool m_springLoadedPanScrollInProgress;
    409404
    410405    Timer<EventHandler> m_hoverTimer;
    411    
    412     Timer<EventHandler> m_autoscrollTimer;
    413     RenderObject* m_autoscrollRenderer;
    414     bool m_autoscrollInProgress;
     406
     407    OwnPtr<AutoscrollController> m_autoscrollController;
    415408    bool m_mouseDownMayStartAutoscroll;
    416409    bool m_mouseDownWasInSubframe;
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r137703 r137726  
    3535#include "htmlediting.h"
    3636#include "HTMLElement.h"
     37#include "HTMLFrameOwnerElement.h"
    3738#include "HTMLNames.h"
    3839#include "ImageBuffer.h"
     
    641642    if (layer())
    642643        layer()->autoscroll();
     644}
     645
     646// There are two kinds of renderer that can autoscroll.
     647bool RenderBox::canAutoscroll() const
     648{
     649    // Check for a box that can be scrolled in its own right.
     650    if (canBeScrolledAndHasScrollableArea())
     651        return true;
     652
     653    // Check for a box that represents the top level of a web page.
     654    // This can be scrolled by calling Chrome::scrollRectIntoView.
     655    // This only has an effect on the Mac platform in applications
     656    // that put web views into scrolling containers, such as Mac OS X Mail.
     657    // The code for this is in RenderLayer::scrollRectToVisible.
     658    if (node() != document())
     659        return false;
     660    Frame* frame = this->frame();
     661    if (!frame)
     662        return false;
     663    Page* page = frame->page();
     664    return page && page->mainFrame() == frame;
     665}
     666
     667RenderBox* RenderBox::findAutoscrollable(RenderObject* renderer)
     668{
     669    while (renderer && !(renderer->isBox() && toRenderBox(renderer)->canAutoscroll())) {
     670        if (!renderer->parent() && renderer->node() == renderer->document() && renderer->document()->ownerElement())
     671            renderer = renderer->document()->ownerElement()->renderer();
     672        else
     673            renderer = renderer->parent();
     674    }
     675
     676    return renderer && renderer->isBox() ? toRenderBox(renderer) : 0;
    643677}
    644678
  • trunk/Source/WebCore/rendering/RenderBox.h

    r137703 r137726  
    440440    virtual bool canBeProgramaticallyScrolled() const;
    441441    virtual void autoscroll();
     442    bool canAutoscroll() const;
     443    static RenderBox* findAutoscrollable(RenderObject*);
    442444    virtual void stopAutoscroll() { }
    443445    virtual void panScroll(const IntPoint&);
Note: See TracChangeset for help on using the changeset viewer.