| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | |
| 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | |
| 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | |
| 6 * | |
| 7 * Redistribution and use in source and binary forms, with or without | |
| 8 * modification, are permitted provided that the following conditions | |
| 9 * are met: | |
| 10 * 1. Redistributions of source code must retain the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer. | |
| 12 * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 * notice, this list of conditions and the following disclaimer in the | |
| 14 * documentation and/or other materials provided with the distribution. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #include "sky/engine/config.h" | |
| 30 #include "sky/engine/core/page/AutoscrollController.h" | |
| 31 | |
| 32 #include "sky/engine/core/frame/FrameView.h" | |
| 33 #include "sky/engine/core/frame/LocalFrame.h" | |
| 34 #include "sky/engine/core/page/EventHandler.h" | |
| 35 #include "sky/engine/core/page/Page.h" | |
| 36 #include "sky/engine/core/rendering/HitTestResult.h" | |
| 37 #include "sky/engine/core/rendering/RenderBox.h" | |
| 38 #include "sky/engine/wtf/CurrentTime.h" | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 // Delay time in second for start autoscroll if pointer is in border edge of scr
ollable element. | |
| 43 static double autoscrollDelay = 0.2; | |
| 44 | |
| 45 PassOwnPtr<AutoscrollController> AutoscrollController::create(Page& page) | |
| 46 { | |
| 47 return adoptPtr(new AutoscrollController(page)); | |
| 48 } | |
| 49 | |
| 50 AutoscrollController::AutoscrollController(Page& page) | |
| 51 : m_page(page) | |
| 52 , m_autoscrollRenderer(0) | |
| 53 , m_autoscrollType(NoAutoscroll) | |
| 54 , m_dragAndDropAutoscrollStartTime(0) | |
| 55 { | |
| 56 } | |
| 57 | |
| 58 bool AutoscrollController::autoscrollInProgress() const | |
| 59 { | |
| 60 return m_autoscrollType == AutoscrollForSelection; | |
| 61 } | |
| 62 | |
| 63 bool AutoscrollController::autoscrollInProgress(const RenderBox* renderer) const | |
| 64 { | |
| 65 return m_autoscrollRenderer == renderer; | |
| 66 } | |
| 67 | |
| 68 void AutoscrollController::startAutoscrollForSelection(RenderObject* renderer) | |
| 69 { | |
| 70 // We don't want to trigger the autoscroll or the panScroll if it's already
active | |
| 71 if (m_autoscrollType != NoAutoscroll) | |
| 72 return; | |
| 73 RenderBox* scrollable = RenderBox::findAutoscrollable(renderer); | |
| 74 if (!scrollable) | |
| 75 return; | |
| 76 m_autoscrollType = AutoscrollForSelection; | |
| 77 m_autoscrollRenderer = scrollable; | |
| 78 startAutoscroll(); | |
| 79 } | |
| 80 | |
| 81 void AutoscrollController::stopAutoscroll() | |
| 82 { | |
| 83 RenderBox* scrollable = m_autoscrollRenderer; | |
| 84 m_autoscrollRenderer = 0; | |
| 85 | |
| 86 if (!scrollable) | |
| 87 return; | |
| 88 | |
| 89 scrollable->stopAutoscroll(); | |
| 90 | |
| 91 m_autoscrollType = NoAutoscroll; | |
| 92 } | |
| 93 | |
| 94 void AutoscrollController::stopAutoscrollIfNeeded(RenderObject* renderer) | |
| 95 { | |
| 96 if (m_autoscrollRenderer != renderer) | |
| 97 return; | |
| 98 m_autoscrollRenderer = 0; | |
| 99 m_autoscrollType = NoAutoscroll; | |
| 100 } | |
| 101 | |
| 102 void AutoscrollController::updateAutoscrollRenderer() | |
| 103 { | |
| 104 if (!m_autoscrollRenderer) | |
| 105 return; | |
| 106 | |
| 107 RenderObject* renderer = m_autoscrollRenderer; | |
| 108 | |
| 109 while (renderer && !(renderer->isBox() && toRenderBox(renderer)->canAutoscro
ll())) | |
| 110 renderer = renderer->parent(); | |
| 111 m_autoscrollRenderer = renderer && renderer->isBox() ? toRenderBox(renderer)
: 0; | |
| 112 } | |
| 113 | |
| 114 void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoin
t& eventPosition, double eventTime) | |
| 115 { | |
| 116 if (!dropTargetNode || !dropTargetNode->renderer()) { | |
| 117 stopAutoscroll(); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 if (m_autoscrollRenderer && m_autoscrollRenderer->frame() != dropTargetNode-
>renderer()->frame()) | |
| 122 return; | |
| 123 | |
| 124 RenderBox* scrollable = RenderBox::findAutoscrollable(dropTargetNode->render
er()); | |
| 125 if (!scrollable) { | |
| 126 stopAutoscroll(); | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 Page* page = scrollable->frame() ? scrollable->frame()->page() : 0; | |
| 131 if (!page) { | |
| 132 stopAutoscroll(); | |
| 133 return; | |
| 134 } | |
| 135 | |
| 136 IntSize offset = scrollable->calculateAutoscrollDirection(eventPosition); | |
| 137 if (offset.isZero()) { | |
| 138 stopAutoscroll(); | |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 m_dragAndDropAutoscrollReferencePosition = eventPosition + offset; | |
| 143 | |
| 144 if (m_autoscrollType == NoAutoscroll) { | |
| 145 m_autoscrollType = AutoscrollForDragAndDrop; | |
| 146 m_autoscrollRenderer = scrollable; | |
| 147 m_dragAndDropAutoscrollStartTime = eventTime; | |
| 148 startAutoscroll(); | |
| 149 } else if (m_autoscrollRenderer != scrollable) { | |
| 150 m_dragAndDropAutoscrollStartTime = eventTime; | |
| 151 m_autoscrollRenderer = scrollable; | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 // FIXME: This would get get better animation fidelity if it used the monotonicF
rameBeginTime instead | |
| 156 // of WTF::currentTime(). | |
| 157 void AutoscrollController::animate(double) | |
| 158 { | |
| 159 if (!m_autoscrollRenderer) { | |
| 160 stopAutoscroll(); | |
| 161 return; | |
| 162 } | |
| 163 | |
| 164 switch (m_autoscrollType) { | |
| 165 case AutoscrollForDragAndDrop: | |
| 166 if (WTF::currentTime() - m_dragAndDropAutoscrollStartTime > autoscrollDe
lay) | |
| 167 m_autoscrollRenderer->autoscroll(m_dragAndDropAutoscrollReferencePos
ition); | |
| 168 break; | |
| 169 case AutoscrollForSelection: | |
| 170 case NoAutoscroll: | |
| 171 break; | |
| 172 } | |
| 173 if (m_autoscrollType != NoAutoscroll) | |
| 174 startAutoscroll(); | |
| 175 } | |
| 176 | |
| 177 void AutoscrollController::startAutoscroll() | |
| 178 { | |
| 179 m_page.animator().scheduleVisualUpdate(); | |
| 180 } | |
| 181 | |
| 182 } // namespace blink | |
| OLD | NEW |