|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of scrolling decelerator |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <../bidi.h> |
|
21 #include "WebScrollingDeceleratorGH.h" |
|
22 #include "WebView.h" |
|
23 #include "WebFrame.h" |
|
24 #include "WebFrameView.h" |
|
25 #include "WebPageScrollHandler.h" |
|
26 #include "PlatformScrollbar.h" |
|
27 #include "WebScrollbarDrawer.h" |
|
28 |
|
29 #include "WebKitLogger.h" |
|
30 |
|
31 using namespace RT_GestureHelper; |
|
32 // constants |
|
33 const int KRecordSize = 4; |
|
34 |
|
35 // The following deceleration curve is generated by a script |
|
36 // It lists the timeout dt values in microseconds. |
|
37 const int KDecelCurveSize = 10; |
|
38 |
|
39 const int KScrollIntervalTimeout = 60000; // scroll timer interval in microseconds |
|
40 |
|
41 const float KDecceleration = -700.0; |
|
42 |
|
43 int decelTimerCB(TAny* ptr); |
|
44 |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // WebScrollingDeceleratorGH::NewL |
|
50 // The two-phase Symbian constructor |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 |
|
54 WebScrollingDeceleratorGH* WebScrollingDeceleratorGH::NewL(WebView& webView) |
|
55 { |
|
56 WebScrollingDeceleratorGH* self = new (ELeave) WebScrollingDeceleratorGH(webView); |
|
57 |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(); //self |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // WebScrollingDeceleratorGH::WebScrollingDeceleratorGH |
|
66 // C++ default constructor can NOT contain any code, that |
|
67 // might leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 WebScrollingDeceleratorGH::WebScrollingDeceleratorGH(WebView& webView) |
|
71 : m_webView( webView ) |
|
72 { |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // WebScrollingDeceleratorGH::ConstructL |
|
77 // ----------------------------------------------------------------------------- |
|
78 void WebScrollingDeceleratorGH::ConstructL() |
|
79 { |
|
80 m_decelTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // Destructor |
|
85 // ----------------------------------------------------------------------------- |
|
86 WebScrollingDeceleratorGH::~WebScrollingDeceleratorGH() |
|
87 { |
|
88 delete m_decelTimer; |
|
89 } |
|
90 |
|
91 |
|
92 int WebScrollingDeceleratorGH::getDecceleration() |
|
93 { |
|
94 return KDecceleration; |
|
95 } |
|
96 |
|
97 |
|
98 int decelTimerCB(TAny* ptr) |
|
99 { |
|
100 (static_cast<WebScrollingDeceleratorGH*>(ptr))->scroll(); |
|
101 return false; |
|
102 } |
|
103 |
|
104 |
|
105 void WebScrollingDeceleratorGH::cancelDecel() |
|
106 { |
|
107 m_decelelatorSwitch = false; |
|
108 if (m_decelTimer->IsActive()) { |
|
109 m_decelTimer->Cancel(); |
|
110 } |
|
111 } |
|
112 |
|
113 void WebScrollingDeceleratorGH::startDecel(TRealPoint& speed, WebScrollbarDrawer* scrollbarDrawer) |
|
114 { |
|
115 m_decelelatorSwitch = true; |
|
116 m_scrollbarDrawer = scrollbarDrawer; |
|
117 m_initSpeed.iX = (-1) * speed.iX; |
|
118 m_initSpeed.iY = (-1) * speed.iY; |
|
119 |
|
120 m_numscrollsteps = 0; |
|
121 if (m_decelTimer->IsActive()) { |
|
122 m_decelTimer->Cancel(); |
|
123 } |
|
124 |
|
125 WebFrameView* scrollingView = m_webView.pageScrollHandler()->currentScrollingFrameView(); |
|
126 if (scrollingView) { |
|
127 m_startPos = scrollingView->contentPos(); |
|
128 m_lastPos = m_startPos; |
|
129 m_decelTimer->Start(0, KScrollIntervalTimeout, |
|
130 TCallBack(&decelTimerCB, this)); |
|
131 } |
|
132 } |
|
133 |
|
134 void WebScrollingDeceleratorGH::scroll() |
|
135 { |
|
136 if (!m_decelelatorSwitch) return; |
|
137 // X = Vst*t - 0.5*a*(t * t) |
|
138 TPoint dist; |
|
139 TReal32 intervalInSec = static_cast<TReal32>(KScrollIntervalTimeout) / 1000000; |
|
140 TReal32 t = (m_numscrollsteps++) * intervalInSec; |
|
141 TReal32 dx = 0.0; |
|
142 TReal32 dy = 0.0; |
|
143 TReal32 vx = 0.0; |
|
144 TReal32 vy = 0.0; |
|
145 TReal32 accelX = 0.0; |
|
146 TReal32 accelY = 0.0; |
|
147 |
|
148 if (m_initSpeed.iX) { |
|
149 accelX = (m_initSpeed.iX > 0) ? KDecceleration : (-1) * KDecceleration; |
|
150 vx = m_initSpeed.iX + accelX * t; |
|
151 dx = m_initSpeed.iX * t + 0.5 * accelX * (t * t); |
|
152 } |
|
153 |
|
154 if (m_initSpeed.iY) { |
|
155 accelY = (m_initSpeed.iY > 0) ? KDecceleration : (-1) * KDecceleration; |
|
156 vy = m_initSpeed.iY + accelY * t; |
|
157 dy = m_initSpeed.iY * t + 0.5 * accelY * (t * t); |
|
158 } |
|
159 |
|
160 dist.SetXY(static_cast<TInt>(dx), static_cast<TInt>(dy)); |
|
161 |
|
162 WebFrameView* scrollingView = m_webView.pageScrollHandler()->currentScrollingFrameView(); |
|
163 TPoint cpos = scrollingView->contentPos(); |
|
164 dist = scrollingView->toDocCoords(dist); |
|
165 TPoint pos = m_startPos + dist; |
|
166 |
|
167 if ((vx * m_initSpeed.iX < 0) || (vy * m_initSpeed.iY < 0) || (vx + vy == 0) || |
|
168 (m_numscrollsteps > 1 && !scrollingView->needScroll(pos))) { |
|
169 if (m_scrollbarDrawer) { |
|
170 m_scrollbarDrawer->fadeScrollbar(); |
|
171 } |
|
172 m_decelTimer->Cancel(); |
|
173 m_webView.setViewIsScrolling(false); |
|
174 m_webView.toggleRepaintTimer(true); |
|
175 } |
|
176 else { |
|
177 scrollingView->scrollTo(pos); |
|
178 if (m_scrollbarDrawer) { |
|
179 TPoint scrollDelta = pos - m_lastPos; |
|
180 scrollDelta.iX *= 100; |
|
181 scrollDelta.iY *= 100; |
|
182 m_webView.pageScrollHandler()->updateScrollbars(pos, scrollDelta); |
|
183 } |
|
184 m_lastPos = pos; |
|
185 } |
|
186 |
|
187 } |
|
188 |
|
189 |
|
190 // End of File |