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

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/ScrollState.cpp

Issue 1646663002: Refactor Scroll Customization to share cc::ScrollStateData with blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix linking. Created 4 years, 10 months 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 unified diff | Download patch
OLDNEW
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(ScrollStateInit init)
28 double deltaX, double deltaY, double deltaGranularity, double velocityX,
29 double velocityY, bool inInertialPhase,
30 bool isBeginning, bool isEnding,
31 bool fromUserInput, bool shouldPropagate,
32 bool deltaConsumedForScrollSequence)
33 { 28 {
34 OwnPtr<WebScrollStateData> data(adoptPtr(new WebScrollStateData(deltaX, delt aY, deltaGranularity, velocityX, velocityY, 29 OwnPtr<ScrollStateData> scrollStateData = adoptPtr(new ScrollStateData());
35 inInertialPhase, isBeginning, isEnding, fromUserInput, shouldPropagate, 30 scrollStateData->delta_x = init.deltaX();
36 deltaConsumedForScrollSequence))); 31 scrollStateData->delta_y = init.deltaY();
37 return adoptRefWillBeNoop(new ScrollState(data.release())); 32 scrollStateData->start_position_x = init.startPositionX();
33 scrollStateData->start_position_y = init.startPositionY();
34 scrollStateData->velocity_x = init.velocityX();
35 scrollStateData->velocity_y = init.velocityY();
36 scrollStateData->is_beginning = init.isBeginning();
37 scrollStateData->is_in_inertial_phase = init.isInInertialPhase();
38 scrollStateData->is_ending = init.isEnding();
39 scrollStateData->should_propagate = init.shouldPropagate();
40 scrollStateData->from_user_input = init.fromUserInput();
41 scrollStateData->is_direct_manipulation = init.isDirectManipulation();
42 scrollStateData->delta_granularity = init.deltaGranularity();
43 ScrollState* scrollState = new ScrollState(scrollStateData.release());
44 return adoptRefWillBeNoop(scrollState);
38 } 45 }
39 46
40 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create(PassOwnPtr<WebScrollStat eData> data) 47 PassRefPtrWillBeRawPtr<ScrollState> ScrollState::create(PassOwnPtr<ScrollStateDa ta> data)
41 { 48 {
42 ScrollState* scrollState = new ScrollState(data); 49 ScrollState* scrollState = new ScrollState(data);
43 return adoptRefWillBeNoop(scrollState); 50 return adoptRefWillBeNoop(scrollState);
44 } 51 }
45 52
46 ScrollState::ScrollState(PassOwnPtr<WebScrollStateData> data) 53 ScrollState::ScrollState(PassOwnPtr<ScrollStateData> data)
47 : m_data(data) 54 : m_data(data)
48 { 55 {
49 } 56 }
50 57
51 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat e) 58 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat e)
52 { 59 {
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)) { 60 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"); 61 exceptionState.throwDOMException(InvalidModificationError, "Can't increa se delta using consumeDelta");
55 return; 62 return;
56 } 63 }
57 if (fabs(x) > fabs(m_data->deltaX) || fabs(y) > fabs(m_data->deltaY)) { 64 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"); 65 exceptionState.throwDOMException(InvalidModificationError, "Can't change direction of delta using consumeDelta");
59 return; 66 return;
60 } 67 }
61 consumeDeltaNative(x, y); 68 consumeDeltaNative(x, y);
62 } 69 }
63 70
64 void ScrollState::distributeToScrollChainDescendant() 71 void ScrollState::distributeToScrollChainDescendant()
65 { 72 {
66 if (!m_scrollChain.empty()) { 73 if (!m_scrollChain.empty()) {
67 int descendantId = m_scrollChain.front(); 74 int descendantId = m_scrollChain.front();
68 m_scrollChain.pop_front(); 75 m_scrollChain.pop_front();
69 elementForId(descendantId)->callDistributeScroll(*this); 76 elementForId(descendantId)->callDistributeScroll(*this);
70 } 77 }
71 } 78 }
72 79
73 void ScrollState::consumeDeltaNative(double x, double y) 80 void ScrollState::consumeDeltaNative(double x, double y)
74 { 81 {
75 m_data->deltaX -= x; 82 m_data->delta_x -= x;
76 m_data->deltaY -= y; 83 m_data->delta_y -= y;
77 84
85 if (x)
86 m_data->caused_scroll_x = true;
87 if (y)
88 m_data->caused_scroll_y = true;
78 if (x || y) 89 if (x || y)
79 m_data->deltaConsumedForScrollSequence = true; 90 m_data->delta_consumed_for_scroll_sequence = true;
80 } 91 }
81 92
82 Element* ScrollState::currentNativeScrollingElement() const 93 Element* ScrollState::currentNativeScrollingElement() const
83 { 94 {
84 if (m_data->currentNativeScrollingElement == 0) 95 uint64_t elementId = m_data->current_native_scrolling_element();
96 if (elementId == 0)
85 return nullptr; 97 return nullptr;
86 return elementForId(m_data->currentNativeScrollingElement); 98 return elementForId(elementId);
87 } 99 }
88 100
89 void ScrollState::setCurrentNativeScrollingElement(Element* element) 101 void ScrollState::setCurrentNativeScrollingElement(Element* element)
90 { 102 {
91 m_data->currentNativeScrollingElement = DOMNodeIds::idForNode(element); 103 m_data->set_current_native_scrolling_element(DOMNodeIds::idForNode(element)) ;
92 }
93
94 int ScrollState::currentNativeScrollingElementId() const
95 {
96 return m_data->currentNativeScrollingElement;
97 } 104 }
98 105
99 void ScrollState::setCurrentNativeScrollingElementById(int elementId) 106 void ScrollState::setCurrentNativeScrollingElementById(int elementId)
100 { 107 {
101 m_data->currentNativeScrollingElement = elementId; 108 m_data->set_current_native_scrolling_element(elementId);
102 } 109 }
103 110
104 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698