1 | /* |
2 | * Copyright (c) 2016 Igalia S.L. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions are |
6 | * met: |
7 | * |
8 | * * Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * * Redistributions in binary form must reproduce the above |
11 | * copyright notice, this list of conditions and the following disclaimer |
12 | * in the documentation and/or other materials provided with the |
13 | * distribution. |
14 | * * Neither the name of Google Inc. nor the names of its |
15 | * contributors may be used to endorse or promote products derived from |
16 | * this software without specific prior written permission. |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
30 | |
31 | #include "config.h" |
32 | #include "ScrollAnimatorMock.h" |
33 | |
34 | #include "ScrollableArea.h" |
35 | #include <wtf/text/StringBuilder.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | ScrollAnimatorMock::ScrollAnimatorMock(ScrollableArea& scrollableArea, WTF::Function<void(const String&)>&& logger) |
40 | : ScrollAnimator(scrollableArea) |
41 | , m_logger(WTFMove(logger)) |
42 | { |
43 | } |
44 | |
45 | ScrollAnimatorMock::~ScrollAnimatorMock() = default; |
46 | |
47 | void ScrollAnimatorMock::didAddVerticalScrollbar(Scrollbar* scrollbar) |
48 | { |
49 | m_verticalScrollbar = scrollbar; |
50 | m_logger("didAddVerticalScrollbar" ); |
51 | ScrollAnimator::didAddVerticalScrollbar(scrollbar); |
52 | } |
53 | |
54 | void ScrollAnimatorMock::didAddHorizontalScrollbar(Scrollbar* scrollbar) |
55 | { |
56 | m_horizontalScrollbar = scrollbar; |
57 | m_logger("didAddHorizontalScrollbar" ); |
58 | ScrollAnimator::didAddHorizontalScrollbar(scrollbar); |
59 | } |
60 | |
61 | void ScrollAnimatorMock::willRemoveVerticalScrollbar(Scrollbar* scrollbar) |
62 | { |
63 | m_logger("willRemoveVerticalScrollbar" ); |
64 | ScrollAnimator::willRemoveVerticalScrollbar(scrollbar); |
65 | m_verticalScrollbar = nullptr; |
66 | } |
67 | |
68 | void ScrollAnimatorMock::willRemoveHorizontalScrollbar(Scrollbar* scrollbar) |
69 | { |
70 | m_logger("willRemoveHorizontalScrollbar" ); |
71 | ScrollAnimator::willRemoveHorizontalScrollbar(scrollbar); |
72 | m_horizontalScrollbar = nullptr; |
73 | } |
74 | |
75 | void ScrollAnimatorMock::mouseEnteredContentArea() |
76 | { |
77 | m_logger("mouseEnteredContentArea" ); |
78 | ScrollAnimator::mouseEnteredContentArea(); |
79 | } |
80 | |
81 | void ScrollAnimatorMock::mouseMovedInContentArea() |
82 | { |
83 | m_logger("mouseMovedInContentArea" ); |
84 | ScrollAnimator::mouseMovedInContentArea(); |
85 | } |
86 | |
87 | void ScrollAnimatorMock::mouseExitedContentArea() |
88 | { |
89 | m_logger("mouseExitedContentArea" ); |
90 | ScrollAnimator::mouseExitedContentArea(); |
91 | } |
92 | |
93 | void ScrollAnimatorMock::mouseEnteredScrollbar(Scrollbar* scrollbar) const |
94 | { |
95 | StringBuilder message; |
96 | message.appendLiteral("mouseEntered" ); |
97 | if (scrollbar == m_verticalScrollbar) |
98 | message.appendLiteral("Vertical" ); |
99 | else if (scrollbar == m_horizontalScrollbar) |
100 | message.appendLiteral("Horizontal" ); |
101 | else |
102 | message.appendLiteral("Unknown" ); |
103 | message.appendLiteral("Scrollbar" ); |
104 | m_logger(message.toString()); |
105 | ScrollAnimator::mouseEnteredScrollbar(scrollbar); |
106 | } |
107 | |
108 | void ScrollAnimatorMock::mouseExitedScrollbar(Scrollbar* scrollbar) const |
109 | { |
110 | StringBuilder message; |
111 | message.appendLiteral("mouseExited" ); |
112 | if (scrollbar == m_verticalScrollbar) |
113 | message.appendLiteral("Vertical" ); |
114 | else if (scrollbar == m_horizontalScrollbar) |
115 | message.appendLiteral("Horizontal" ); |
116 | else |
117 | message.appendLiteral("Unknown" ); |
118 | message.appendLiteral("Scrollbar" ); |
119 | m_logger(message.toString()); |
120 | ScrollAnimator::mouseExitedScrollbar(scrollbar); |
121 | } |
122 | |
123 | void ScrollAnimatorMock::mouseIsDownInScrollbar(Scrollbar* scrollbar, bool isPressed) const |
124 | { |
125 | StringBuilder message; |
126 | message.appendLiteral("mouseIs" ); |
127 | if (isPressed) |
128 | message.appendLiteral("Down" ); |
129 | else |
130 | message.appendLiteral("Up" ); |
131 | message.appendLiteral("In" ); |
132 | if (scrollbar == m_verticalScrollbar) |
133 | message.appendLiteral("Vertical" ); |
134 | else if (scrollbar == m_horizontalScrollbar) |
135 | message.appendLiteral("Horizontal" ); |
136 | else |
137 | message.appendLiteral("Unknown" ); |
138 | message.appendLiteral("Scrollbar" ); |
139 | m_logger(message.toString()); |
140 | ScrollAnimator::mouseIsDownInScrollbar(scrollbar, isPressed); |
141 | } |
142 | |
143 | } // namespace WebCore |
144 | |