|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <../bidi.h> |
|
21 #include <aknutils.h> |
|
22 #include "WebPageZoomHandler.h" |
|
23 #include "SettingsContainer.h" |
|
24 #include <AknVolumePopup.h> |
|
25 #include "WebView.h" |
|
26 #include "BrCtl.h" |
|
27 #include "WebFrameView.h" |
|
28 #include "WebFrame.h" |
|
29 |
|
30 |
|
31 const int KZoomSliderDefaultValue = 50; |
|
32 const int KZoomSliderMinRange = 0; |
|
33 const int KZoomSliderStepSize = 10; |
|
34 const int KZoomSliderTimeout = 5; |
|
35 const int KBitmapUpdateTimeout = 100*1000; |
|
36 |
|
37 int bitmapUpdateTimerCb( void* ptr ); |
|
38 |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // WebPageZoomHandler::NewL |
|
44 // The two-phase Symbian constructor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 WebPageZoomHandler* WebPageZoomHandler::NewL(WebView& webView) |
|
48 { |
|
49 WebPageZoomHandler* self = new (ELeave) WebPageZoomHandler( webView ); |
|
50 CleanupStack::PushL(self); |
|
51 self->constructL(); |
|
52 CleanupStack::Pop(); //self |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // WebPageZoomHandler::WebPointerEventHandler |
|
58 // C++ default constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 WebPageZoomHandler::WebPageZoomHandler(WebView& webView) |
|
63 : m_webView(&webView), m_zoomSlider(0) |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // WebPageZoomHandler::constructL |
|
69 // The constructor that can contain code that might leave. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void WebPageZoomHandler::constructL() |
|
73 { |
|
74 m_bitmapUpdateTimer = CPeriodic::NewL(CActive::EPriorityHigh); |
|
75 m_stepSize = KZoomSliderStepSize; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // Destructor |
|
80 // ----------------------------------------------------------------------------- |
|
81 WebPageZoomHandler::~WebPageZoomHandler() |
|
82 { |
|
83 if ( m_bitmapUpdateTimer && m_bitmapUpdateTimer->IsActive() ) |
|
84 { |
|
85 m_bitmapUpdateTimer->Cancel(); |
|
86 } |
|
87 |
|
88 delete m_bitmapUpdateTimer; |
|
89 |
|
90 if ( m_zoomSlider ) |
|
91 { |
|
92 delete m_zoomSlider; |
|
93 } |
|
94 } |
|
95 // ----------------------------------------------------------------------------- |
|
96 |
|
97 void WebPageZoomHandler::showZoomSliderL() |
|
98 { |
|
99 if ( AknLayoutUtils::PenEnabled() ) |
|
100 { |
|
101 if (m_zoomSlider) { |
|
102 delete m_zoomSlider; |
|
103 m_zoomSlider = NULL; |
|
104 } |
|
105 m_zoomSlider = CAknVolumePopup::NewL( NULL, ETrue); |
|
106 m_zoomSlider->SetValueType( EAknSliderValuePercentage ); |
|
107 m_zoomSlider->SetStepSize( m_stepSize ); |
|
108 m_zoomSlider->SetAdjustmentIndicatorDisplay( ETrue ); |
|
109 m_zoomSlider->SetTimeOutAsSecond( KZoomSliderTimeout ); |
|
110 m_zoomSlider->ClosePopupWhenTappedOutside( EFalse ); |
|
111 m_zoomSlider->SetRange( m_webView->minZoomLevel(), m_webView->maxZoomLevel()); |
|
112 m_zoomSlider->SetValue( m_webView->scalingFactor()); |
|
113 m_zoomSlider->SetObserver(this); |
|
114 |
|
115 TRect currRect = m_webView->brCtl()->Rect(); |
|
116 TPoint newPos ( currRect.iTl.iX + ( currRect.iBr.iX - m_zoomSlider->Size().iWidth ) , currRect.iTl.iY + 30 ); |
|
117 |
|
118 m_zoomSlider->SetPosition( newPos ); |
|
119 m_zoomSlider->ShowVolumePopupL(); |
|
120 } |
|
121 } |
|
122 |
|
123 void WebPageZoomHandler::hideZoomSliderL() |
|
124 { |
|
125 if ( AknLayoutUtils::PenEnabled() ) |
|
126 { |
|
127 if (m_zoomSlider) |
|
128 { |
|
129 if( m_zoomSlider->IsVisible()) |
|
130 m_zoomSlider->CloseVolumePopup(); |
|
131 |
|
132 delete m_zoomSlider; |
|
133 m_zoomSlider = NULL; |
|
134 m_webView->notifyZoomSliderModeChangeL(false); |
|
135 } |
|
136 } |
|
137 } |
|
138 |
|
139 void WebPageZoomHandler::setZoomLevel(int zoomLevel) |
|
140 { |
|
141 m_webView->setBitmapZoomLevel(zoomLevel); |
|
142 } |
|
143 |
|
144 |
|
145 void WebPageZoomHandler::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
146 { |
|
147 if ( AknLayoutUtils::PenEnabled() ) |
|
148 { |
|
149 TBool sliderVisibility = false; |
|
150 TInt zoomValue = 0; |
|
151 |
|
152 if(m_zoomSlider == aControl) { |
|
153 |
|
154 if (m_bitmapUpdateTimer && m_bitmapUpdateTimer->IsActive()) |
|
155 m_bitmapUpdateTimer->Cancel(); |
|
156 |
|
157 sliderVisibility = m_zoomSlider->IsVisible(); |
|
158 |
|
159 switch(aEventType) { |
|
160 case EEventStateChanged: |
|
161 case EEventRequestFocus: |
|
162 if(sliderVisibility) { |
|
163 zoomValue = m_zoomSlider->Value(); |
|
164 if(zoomValue >= m_webView->minZoomLevel() && zoomValue <= m_webView->maxZoomLevel()){ |
|
165 setZoomLevel(zoomValue); |
|
166 } |
|
167 else if( zoomValue < m_webView->minZoomLevel()) { |
|
168 |
|
169 m_zoomSlider->SetValue( m_webView->scalingFactor() ); |
|
170 } |
|
171 } |
|
172 break; |
|
173 |
|
174 default: |
|
175 break; |
|
176 } |
|
177 if(sliderVisibility && m_bitmapUpdateTimer) |
|
178 m_bitmapUpdateTimer->Start( KBitmapUpdateTimeout,KBitmapUpdateTimeout,TCallBack(&bitmapUpdateTimerCb,this)); |
|
179 |
|
180 |
|
181 if( !sliderVisibility && EEventStateChanged == aEventType ) { |
|
182 m_webView->notifyZoomSliderModeChangeL(false); |
|
183 } |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 |
|
189 int WebPageZoomHandler::stepSize() |
|
190 { |
|
191 return m_stepSize; |
|
192 } |
|
193 |
|
194 |
|
195 WebView* WebPageZoomHandler::view( void ) |
|
196 { |
|
197 return m_webView; |
|
198 } |
|
199 |
|
200 bool WebPageZoomHandler::isActive( void ) |
|
201 { |
|
202 return ( m_zoomSlider && m_zoomSlider->IsVisible())?true:false; |
|
203 } |
|
204 void WebPageZoomHandler::updateBitmap(void) |
|
205 { |
|
206 m_bitmapUpdateTimer->Cancel(); |
|
207 m_webView->restoreZoomLevel(m_webView->scalingFactor()); |
|
208 } |
|
209 |
|
210 int bitmapUpdateTimerCb(void* ptr) |
|
211 { |
|
212 ((WebPageZoomHandler*)ptr)->updateBitmap(); |
|
213 return 0; |
|
214 } |
|
215 |
|
216 // End of File |