| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/page/scrolling/ScrollState.h" | 5 #include "core/page/scrolling/ScrollState.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMNodeIds.h" | 7 #include "core/dom/DOMNodeIds.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/dom/ExceptionCode.h" | 9 #include "core/dom/ExceptionCode.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 Element* elementForId(int elementId) | 14 Element* elementForId(int elementId) |
| 15 { | 15 { |
| 16 Node* node = DOMNodeIds::nodeForId(elementId); | 16 Node* node = DOMNodeIds::nodeForId(elementId); |
| 17 ASSERT(node); | 17 ASSERT(node); |
| 18 if (!node) | 18 if (!node) |
| 19 return nullptr; | 19 return nullptr; |
| 20 ASSERT(node->isElementNode()); | 20 ASSERT(node->isElementNode()); |
| 21 if (!node->isElementNode()) | 21 if (!node->isElementNode()) |
| 22 return nullptr; | 22 return nullptr; |
| 23 return static_cast<Element*>(node); | 23 return static_cast<Element*>(node); |
| 24 } | 24 } |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create( | 27 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create( |
| 28 double deltaX, double deltaY, double deltaGranularity, double velocityX, | 28 double deltaX, double deltaY, int startPositionX, int startPositionY, double
velocityX, |
| 29 double velocityY, bool inInertialPhase, | 29 double velocityY, bool isBeginning, bool inInertialPhase, bool isEnding, |
| 30 bool isBeginning, bool isEnding, | 30 bool shouldPropagate, bool fromUserInput, bool isDirectManipulation, |
| 31 bool fromUserInput, bool shouldPropagate, | 31 double deltaGranularity, bool deltaConsumedForScrollSequence) |
| 32 bool deltaConsumedForScrollSequence) | |
| 33 { | 32 { |
| 34 OwnPtr<WebScrollStateData> data(adoptPtr(new WebScrollStateData(deltaX, delt
aY, deltaGranularity, velocityX, velocityY, | 33 OwnPtr<ScrollStateData> data(adoptPtr(new ScrollStateData(deltaX, deltaY, st
artPositionX, startPositionY, velocityX, velocityY, |
| 35 inInertialPhase, isBeginning, isEnding, fromUserInput, shouldPropagate, | 34 isBeginning, inInertialPhase, isEnding, shouldPropagate, fromUserInput, |
| 36 deltaConsumedForScrollSequence))); | 35 isDirectManipulation, deltaGranularity, deltaConsumedForScrollSequence))
); |
| 37 return adoptRefWillBeNoop(new ScrollState(data.release())); | 36 return adoptRefWillBeNoop(new ScrollState(data.release())); |
| 38 } | 37 } |
| 39 | 38 |
| 40 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create(PassOwnPtr<WebScrollStat
eData> data) | 39 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create(PassOwnPtr<ScrollStateDa
ta> data) |
| 41 { | 40 { |
| 42 ScrollState* scrollState = new ScrollState(data); | 41 ScrollState* scrollState = new ScrollState(data); |
| 43 return adoptRefWillBeNoop(scrollState); | 42 return adoptRefWillBeNoop(scrollState); |
| 44 } | 43 } |
| 45 | 44 |
| 46 ScrollState::ScrollState(PassOwnPtr<WebScrollStateData> data) | 45 ScrollState::ScrollState(PassOwnPtr<ScrollStateData> data) |
| 47 : m_data(data) | 46 : m_data(data) |
| 48 { | 47 { |
| 49 } | 48 } |
| 50 | 49 |
| 51 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat
e) | 50 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat
e) |
| 52 { | 51 { |
| 53 if ((m_data->deltaX > 0 && 0 > x) || (m_data->deltaX < 0 && 0 < x) || (m_dat
a->deltaY > 0 && 0 > y) || (m_data->deltaY < 0 && 0 < y)) { | 52 if ((m_data->delta_x > 0 && 0 > x) || (m_data->delta_x < 0 && 0 < x) || (m_d
ata->delta_y > 0 && 0 > y) || (m_data->delta_y < 0 && 0 < y)) { |
| 54 exceptionState.throwDOMException(InvalidModificationError, "Can't increa
se delta using consumeDelta"); | 53 exceptionState.throwDOMException(InvalidModificationError, "Can't increa
se delta using consumeDelta"); |
| 55 return; | 54 return; |
| 56 } | 55 } |
| 57 if (fabs(x) > fabs(m_data->deltaX) || fabs(y) > fabs(m_data->deltaY)) { | 56 if (fabs(x) > fabs(m_data->delta_x) || fabs(y) > fabs(m_data->delta_y)) { |
| 58 exceptionState.throwDOMException(InvalidModificationError, "Can't change
direction of delta using consumeDelta"); | 57 exceptionState.throwDOMException(InvalidModificationError, "Can't change
direction of delta using consumeDelta"); |
| 59 return; | 58 return; |
| 60 } | 59 } |
| 61 consumeDeltaNative(x, y); | 60 consumeDeltaNative(x, y); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void ScrollState::distributeToScrollChainDescendant() | 63 void ScrollState::distributeToScrollChainDescendant() |
| 65 { | 64 { |
| 66 if (!m_scrollChain.empty()) { | 65 if (!m_scrollChain.empty()) { |
| 67 int descendantId = m_scrollChain.front(); | 66 int descendantId = m_scrollChain.front(); |
| 68 m_scrollChain.pop_front(); | 67 m_scrollChain.pop_front(); |
| 69 elementForId(descendantId)->callDistributeScroll(*this); | 68 elementForId(descendantId)->callDistributeScroll(*this); |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 void ScrollState::consumeDeltaNative(double x, double y) | 72 void ScrollState::consumeDeltaNative(double x, double y) |
| 74 { | 73 { |
| 75 m_data->deltaX -= x; | 74 m_data->delta_x -= x; |
| 76 m_data->deltaY -= y; | 75 m_data->delta_y -= y; |
| 77 | 76 |
| 77 if (x) |
| 78 m_data->caused_scroll_x = true; |
| 79 if (y) |
| 80 m_data->caused_scroll_y = true; |
| 78 if (x || y) | 81 if (x || y) |
| 79 m_data->deltaConsumedForScrollSequence = true; | 82 m_data->delta_consumed_for_scroll_sequence = true; |
| 80 } | 83 } |
| 81 | 84 |
| 82 Element* ScrollState::currentNativeScrollingElement() const | 85 Element* ScrollState::currentNativeScrollingElement() const |
| 83 { | 86 { |
| 84 if (m_data->currentNativeScrollingElement == 0) | 87 uint64_t elementId = m_data->current_native_scrolling_element(); |
| 88 if (elementId == 0) |
| 85 return nullptr; | 89 return nullptr; |
| 86 return elementForId(m_data->currentNativeScrollingElement); | 90 return elementForId(elementId); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void ScrollState::setCurrentNativeScrollingElement(Element* element) | 93 void ScrollState::setCurrentNativeScrollingElement(Element* element) |
| 90 { | 94 { |
| 91 m_data->currentNativeScrollingElement = DOMNodeIds::idForNode(element); | 95 m_data->set_current_native_scrolling_element(DOMNodeIds::idForNode(element))
; |
| 92 } | |
| 93 | |
| 94 int ScrollState::currentNativeScrollingElementId() const | |
| 95 { | |
| 96 return m_data->currentNativeScrollingElement; | |
| 97 } | 96 } |
| 98 | 97 |
| 99 void ScrollState::setCurrentNativeScrollingElementById(int elementId) | 98 void ScrollState::setCurrentNativeScrollingElementById(int elementId) |
| 100 { | 99 { |
| 101 m_data->currentNativeScrollingElement = elementId; | 100 m_data->set_current_native_scrolling_element(elementId); |
| 102 } | 101 } |
| 103 | 102 |
| 104 } // namespace blink | 103 } // namespace blink |
| OLD | NEW |