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