|
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 <aknAppUi.h> |
|
22 #include <aknutils.h> |
|
23 #include "StaticObjectsContainer.h" |
|
24 #include "WebCannedImages.h" |
|
25 #include "WebPageFullScreenHandler.h" |
|
26 #include "WebView.h" |
|
27 #include "BrCtl.h" |
|
28 |
|
29 using namespace WebCore; |
|
30 |
|
31 const int KFullScreenButtonHight = 60; |
|
32 const int KFullScreenButtonWidth = 60; |
|
33 const int KFullScreenButtonBuff = 5; |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // WebPageFullScreenHandler::NewL |
|
37 // The two-phase Symbian constructor |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 WebPageFullScreenHandler* WebPageFullScreenHandler::NewL(WebView& webView) |
|
41 { |
|
42 WebPageFullScreenHandler* self = new (ELeave) WebPageFullScreenHandler( webView ); |
|
43 CleanupStack::PushL(self); |
|
44 self->constructL(); |
|
45 CleanupStack::Pop(); //self |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // WebPageFullScreenHandler::WebPointerEventHandler |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 WebPageFullScreenHandler::WebPageFullScreenHandler(WebView& webView) |
|
56 : m_webView(&webView), m_spriteVisible(EFalse), m_tappedOnSprite(EFalse) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // WebPageFullScreenHandler::constructL |
|
62 // The constructor that can contain code that might leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void WebPageFullScreenHandler::constructL() |
|
66 { |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Destructor |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 WebPageFullScreenHandler::~WebPageFullScreenHandler() |
|
74 { |
|
75 } |
|
76 |
|
77 |
|
78 //------------------------------------------------------------------------------- |
|
79 // WebPageFullScreenHandler::showEscBtnL |
|
80 // Draws the full screen button on the screen |
|
81 //------------------------------------------------------------------------------- |
|
82 |
|
83 void WebPageFullScreenHandler::showEscBtnL() |
|
84 { |
|
85 if (AknLayoutUtils::PenEnabled() && !m_spriteVisible) { |
|
86 constructSprite(); |
|
87 SizeChanged(); |
|
88 AddWsObserverToControl(); |
|
89 } |
|
90 } |
|
91 |
|
92 //------------------------------------------------------------------------------- |
|
93 // WebPageFullScreenHandler::hideEscBtnL |
|
94 // Draws the button on the screen |
|
95 //------------------------------------------------------------------------------- |
|
96 |
|
97 void WebPageFullScreenHandler::hideEscBtnL() |
|
98 { |
|
99 if (AknLayoutUtils::PenEnabled() && m_spriteVisible) { |
|
100 destructSprite(); |
|
101 m_eventMonitor->RemoveObserver(this); |
|
102 } |
|
103 } |
|
104 |
|
105 //------------------------------------------------------------------------------- |
|
106 // WebPageFullScreenHandler::SizeChanged |
|
107 // Handle changes in size of the displayable area. |
|
108 //------------------------------------------------------------------------------- |
|
109 |
|
110 void WebPageFullScreenHandler::SizeChanged(void) |
|
111 { |
|
112 if (AknLayoutUtils::PenEnabled() && m_spriteVisible) { |
|
113 m_pos = m_webView->Rect().iBr; |
|
114 m_pos -= TSize( KFullScreenButtonHight + KFullScreenButtonBuff, KFullScreenButtonWidth + KFullScreenButtonBuff); |
|
115 m_sprite.SetPosition(m_pos); |
|
116 } |
|
117 } |
|
118 |
|
119 //------------------------------------------------------------------------------- |
|
120 // WebPageFullScreenHandler::fullScreenMode |
|
121 // Returns true if a page is in the full screen mode |
|
122 //------------------------------------------------------------------------------- |
|
123 |
|
124 bool WebPageFullScreenHandler::isFullScreenMode() |
|
125 { |
|
126 return StaticObjectsContainer::instance()->fullScreenMode(); |
|
127 } |
|
128 |
|
129 |
|
130 //------------------------------------------------------------------------------- |
|
131 // WebPageFullScreenHandler::HitRegionContains |
|
132 // Defines a control's hit region |
|
133 //------------------------------------------------------------------------------- |
|
134 |
|
135 TBool WebPageFullScreenHandler::HitRegionContains(const TPoint& aPoint) |
|
136 { |
|
137 TRect spriteRect (m_pos, TSize(KFullScreenButtonHight, KFullScreenButtonWidth)); |
|
138 return spriteRect.Contains(aPoint); |
|
139 } |
|
140 |
|
141 |
|
142 //------------------------------------------------------------------------------- |
|
143 // WebPageFullScreenHandler::destructSprite |
|
144 // close/hide sprite for time being |
|
145 //------------------------------------------------------------------------------- |
|
146 |
|
147 void WebPageFullScreenHandler::destructSprite() |
|
148 { |
|
149 m_sprite.Close(); |
|
150 m_spriteVisible = EFalse; |
|
151 } |
|
152 |
|
153 //------------------------------------------------------------------------------- |
|
154 // WebPageFullScreenHandler::constructSprite |
|
155 // Show/create sprite at m_pos |
|
156 //------------------------------------------------------------------------------- |
|
157 |
|
158 void WebPageFullScreenHandler::constructSprite() |
|
159 { |
|
160 m_sprite = RWsSprite(m_webView->brCtl()->CCoeControlParent()->ControlEnv()->WsSession()); |
|
161 m_sprite.Construct(m_webView->brCtl()->CCoeControlParent()->ControlEnv()->RootWin(), m_pos, ESpriteNoShadows); |
|
162 TCannedImageData cannedImage = StaticObjectsContainer::instance()->webCannedImages()->getImage(WebCannedImages::EImageEscFullScreen); |
|
163 |
|
164 TSpriteMember spriteMem; |
|
165 spriteMem.iBitmap = cannedImage.m_img; |
|
166 spriteMem.iMaskBitmap = NULL; //masked bitmap still of the canned image need to be changed |
|
167 |
|
168 m_sprite.AppendMember(spriteMem); |
|
169 m_sprite.Activate(); |
|
170 |
|
171 m_spriteVisible = ETrue; |
|
172 } |
|
173 |
|
174 //------------------------------------------------------------------------------- |
|
175 // WebPageFullScreenHandler::HandleWsEventL |
|
176 // check if click region hits sprite |
|
177 //------------------------------------------------------------------------------- |
|
178 |
|
179 void WebPageFullScreenHandler::HandleWsEventL(const TWsEvent& aEvent,CCoeControl* aDestination) |
|
180 { |
|
181 if (!aDestination) return; |
|
182 |
|
183 if(aEvent.Type() == EEventPointer) |
|
184 { |
|
185 switch (aEvent.Pointer()->iType) |
|
186 { |
|
187 case TPointerEvent::EButton1Down: |
|
188 if (m_spriteVisible) |
|
189 { |
|
190 TPoint point (aDestination->PositionRelativeToScreen()); |
|
191 m_tappedOnSprite = HitRegionContains(aEvent.Pointer()->iPosition + point); |
|
192 } |
|
193 break; |
|
194 |
|
195 case TPointerEvent::EButton1Up: |
|
196 { |
|
197 TPoint point (aDestination->PositionRelativeToScreen()); |
|
198 if (m_spriteVisible && m_tappedOnSprite && |
|
199 HitRegionContains(aEvent.Pointer()->iPosition + point)) |
|
200 { |
|
201 hideEscBtnL(); |
|
202 m_webView->notifyFullscreenModeChangeL( false ); |
|
203 } |
|
204 m_tappedOnSprite = EFalse; |
|
205 } |
|
206 break; |
|
207 |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 //------------------------------------------------------------------------------- |
|
214 // WebPageFullScreenHandler::AddWsObserverToControl |
|
215 // register for events from WSession |
|
216 //------------------------------------------------------------------------------- |
|
217 |
|
218 void WebPageFullScreenHandler::AddWsObserverToControl() |
|
219 { |
|
220 m_eventMonitor = ((CAknAppUi*)m_webView->ControlEnv()->AppUi())->EventMonitor(); |
|
221 |
|
222 if(m_eventMonitor) |
|
223 { |
|
224 m_eventMonitor->AddObserverL(this); |
|
225 m_eventMonitor->Enable(ETrue); |
|
226 } |
|
227 } |