Index: Source/core/page/scrolling/ScrollState.cpp |
diff --git a/Source/core/page/scrolling/ScrollState.cpp b/Source/core/page/scrolling/ScrollState.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a9f319bc84db49af2684f118f47c848108f4949b |
--- /dev/null |
+++ b/Source/core/page/scrolling/ScrollState.cpp |
@@ -0,0 +1,69 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/page/scrolling/ScrollState.h" |
+ |
+#include "core/dom/Element.h" |
+#include "core/dom/ExceptionCode.h" |
+ |
+namespace blink { |
+ |
+ScrollState* ScrollState::create(double deltaX, double deltaY, double deltaGranularity, |
+ double velocityX, double velocityY, bool inInertialPhase, bool isEnding, |
+ bool fromUserInput, bool shouldPropagate) |
+{ |
+ return new ScrollState( |
+ deltaX, deltaY, deltaGranularity, velocityX, velocityY, |
+ inInertialPhase, isEnding, fromUserInput, shouldPropagate); |
+} |
+ |
+ScrollState::ScrollState(double deltaX, double deltaY, double deltaGranularity, |
+ double velocityX, double velocityY, bool inInertialPhase, bool isEnding, |
+ bool fromUserInput, bool shouldPropagate) |
+ : m_deltaX(deltaX) |
+ , m_deltaY(deltaY) |
+ , m_deltaGranularity(deltaGranularity) |
+ , m_velocityX(velocityX) |
+ , m_velocityY(velocityY) |
+ , m_inInertialPhase(inInertialPhase) |
+ , m_isEnding(isEnding) |
+ , m_fromUserInput(fromUserInput) |
+ , m_shouldPropagate(shouldPropagate) |
+{ |
+} |
+ |
+ScrollState::~ScrollState() |
+{ |
+} |
+ |
+void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionState) |
+{ |
+ if ((m_deltaX > 0 && 0 > x) || (m_deltaX < 0 && 0 < x) || (m_deltaY > 0 && 0 > y) || (m_deltaY < 0 && 0 < y)) { |
+ exceptionState.throwDOMException(InvalidModificationError, "Can't increase delta using consumeDelta"); |
+ } else if (fabs(x) > fabs(m_deltaX) || fabs(y) > fabs(m_deltaY)) { |
+ exceptionState.throwDOMException(InvalidModificationError, "Can't change direction of delta using consumeDelta"); |
+ } |
+ consumeDeltaNative(x, y); |
+} |
+ |
+void ScrollState::distributeToScrollChainDescendant() |
+{ |
+ if (m_scrollChain.isEmpty()) |
+ return; |
+ Element* element = m_scrollChain[0].get(); |
+ m_scrollChain.remove(0); |
+ element->callDistributeScroll(this); |
+} |
+ |
+void ScrollState::consumeDeltaNative(double x, double y) |
+{ |
+ m_deltaX -= x; |
+ m_deltaY -= y; |
+ |
+ if (x || y) |
+ m_scrollLockedToElement = true; |
+} |
+ |
+} // namespace blink |