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