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 #include "wtf/PtrUtil.h" | |
11 #include <memory> | |
12 | 10 |
13 namespace blink { | 11 namespace blink { |
14 | 12 |
15 namespace { | 13 namespace { |
16 Element* elementForId(int elementId) | 14 Element* elementForId(int elementId) |
17 { | 15 { |
18 Node* node = DOMNodeIds::nodeForId(elementId); | 16 Node* node = DOMNodeIds::nodeForId(elementId); |
19 ASSERT(node); | 17 ASSERT(node); |
20 if (!node) | 18 if (!node) |
21 return nullptr; | 19 return nullptr; |
22 ASSERT(node->isElementNode()); | 20 ASSERT(node->isElementNode()); |
23 if (!node->isElementNode()) | 21 if (!node->isElementNode()) |
24 return nullptr; | 22 return nullptr; |
25 return static_cast<Element*>(node); | 23 return static_cast<Element*>(node); |
26 } | 24 } |
27 } // namespace | 25 } // namespace |
28 | 26 |
29 ScrollState* ScrollState::create(ScrollStateInit init) | 27 ScrollState* ScrollState::create(ScrollStateInit init) |
30 { | 28 { |
31 std::unique_ptr<ScrollStateData> scrollStateData = wrapUnique(new ScrollStat
eData()); | 29 OwnPtr<ScrollStateData> scrollStateData = adoptPtr(new ScrollStateData()); |
32 scrollStateData->delta_x = init.deltaX(); | 30 scrollStateData->delta_x = init.deltaX(); |
33 scrollStateData->delta_y = init.deltaY(); | 31 scrollStateData->delta_y = init.deltaY(); |
34 scrollStateData->position_x = init.positionX(); | 32 scrollStateData->position_x = init.positionX(); |
35 scrollStateData->position_y = init.positionY(); | 33 scrollStateData->position_y = init.positionY(); |
36 scrollStateData->velocity_x = init.velocityX(); | 34 scrollStateData->velocity_x = init.velocityX(); |
37 scrollStateData->velocity_y = init.velocityY(); | 35 scrollStateData->velocity_y = init.velocityY(); |
38 scrollStateData->is_beginning = init.isBeginning(); | 36 scrollStateData->is_beginning = init.isBeginning(); |
39 scrollStateData->is_in_inertial_phase = init.isInInertialPhase(); | 37 scrollStateData->is_in_inertial_phase = init.isInInertialPhase(); |
40 scrollStateData->is_ending = init.isEnding(); | 38 scrollStateData->is_ending = init.isEnding(); |
41 scrollStateData->should_propagate = init.shouldPropagate(); | 39 scrollStateData->should_propagate = init.shouldPropagate(); |
42 scrollStateData->from_user_input = init.fromUserInput(); | 40 scrollStateData->from_user_input = init.fromUserInput(); |
43 scrollStateData->is_direct_manipulation = init.isDirectManipulation(); | 41 scrollStateData->is_direct_manipulation = init.isDirectManipulation(); |
44 scrollStateData->delta_granularity = init.deltaGranularity(); | 42 scrollStateData->delta_granularity = init.deltaGranularity(); |
45 ScrollState* scrollState = new ScrollState(std::move(scrollStateData)); | 43 ScrollState* scrollState = new ScrollState(std::move(scrollStateData)); |
46 return scrollState; | 44 return scrollState; |
47 } | 45 } |
48 | 46 |
49 ScrollState* ScrollState::create(std::unique_ptr<ScrollStateData> data) | 47 ScrollState* ScrollState::create(PassOwnPtr<ScrollStateData> data) |
50 { | 48 { |
51 ScrollState* scrollState = new ScrollState(std::move(data)); | 49 ScrollState* scrollState = new ScrollState(std::move(data)); |
52 return scrollState; | 50 return scrollState; |
53 } | 51 } |
54 | 52 |
55 ScrollState::ScrollState(std::unique_ptr<ScrollStateData> data) | 53 ScrollState::ScrollState(PassOwnPtr<ScrollStateData> data) |
56 : m_data(std::move(data)) | 54 : m_data(std::move(data)) |
57 { | 55 { |
58 } | 56 } |
59 | 57 |
60 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat
e) | 58 void ScrollState::consumeDelta(double x, double y, ExceptionState& exceptionStat
e) |
61 { | 59 { |
62 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)) { | 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)) { |
63 exceptionState.throwDOMException(InvalidModificationError, "Can't increa
se delta using consumeDelta"); | 61 exceptionState.throwDOMException(InvalidModificationError, "Can't increa
se delta using consumeDelta"); |
64 return; | 62 return; |
65 } | 63 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 { | 102 { |
105 m_data->set_current_native_scrolling_element(DOMNodeIds::idForNode(element))
; | 103 m_data->set_current_native_scrolling_element(DOMNodeIds::idForNode(element))
; |
106 } | 104 } |
107 | 105 |
108 void ScrollState::setCurrentNativeScrollingElementById(int elementId) | 106 void ScrollState::setCurrentNativeScrollingElementById(int elementId) |
109 { | 107 { |
110 m_data->set_current_native_scrolling_element(elementId); | 108 m_data->set_current_native_scrolling_element(elementId); |
111 } | 109 } |
112 | 110 |
113 } // namespace blink | 111 } // namespace blink |
OLD | NEW |