|
1 /* |
|
2 * Copyright (c) 2003-2006 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 "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 * Base class for SMIL Player media renderers |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <eikenv.h> |
|
22 #include <AknUtils.h> |
|
23 |
|
24 // DRM |
|
25 #include <DRMHelper.h> |
|
26 #include <caf/data.h> |
|
27 |
|
28 // LAF |
|
29 #include <AknUtils.h> |
|
30 #include <aknlayoutscalable_apps.cdl.h> |
|
31 #include <aknlayoutscalable_avkon.cdl.h> |
|
32 |
|
33 |
|
34 #include "SmilMediaRendererBase.h" |
|
35 |
|
36 //These are from LAF: |
|
37 const TInt KScrollBarBGColorID = 218; |
|
38 const TInt KScrollBarFGColorID = 221; |
|
39 const TInt KScrollBarLineColorID = 0; |
|
40 |
|
41 using namespace ContentAccess; |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // CSmilMediaRendererBase::CSmilMediaRendererBase |
|
45 // C++ default constructor. Initializes class member variables. |
|
46 // --------------------------------------------------------- |
|
47 // |
|
48 CSmilMediaRendererBase::CSmilMediaRendererBase( TMsgMediaType aMediaType, |
|
49 MSmilMedia* aMedia, |
|
50 DRMCommon& aDrmCommon, |
|
51 CDRMHelper& aDrmHelper ) : |
|
52 iMediaType( aMediaType ), |
|
53 iDrmCommon( aDrmCommon ), |
|
54 iDrmHelper( aDrmHelper ), |
|
55 iDrmProtection( DRMCommon::ENoDCFFile ), |
|
56 iMedia( aMedia ) |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CSmilMediaRendererBase::BaseConstructL |
|
62 // Base class 2nd phase constructor. Should be called from derived classes if |
|
63 // base class services are used. |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 void CSmilMediaRendererBase::BaseConstructL( RFile& aFileHandle ) |
|
67 { |
|
68 HBufC8* drmMime = NULL; // dummy |
|
69 TUint drmData = 0; |
|
70 |
|
71 iDrmCommon.GetFileInfo( aFileHandle, |
|
72 iDrmProtection, |
|
73 drmMime, |
|
74 iDrmUri, |
|
75 drmData ); |
|
76 |
|
77 delete drmMime; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------- |
|
81 // CSmilMediaRendererBase::~CSmilMediaRendererBase |
|
82 // Destructor |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 CSmilMediaRendererBase::~CSmilMediaRendererBase() |
|
86 { |
|
87 if( iDrmProtection != DRMCommon::ENoDCFFile && |
|
88 iDrmRightConsumed ) |
|
89 { |
|
90 iDrmHelper.Consume2( *iDrmUri, |
|
91 Intent(), |
|
92 CDRMHelper::EFinish ); |
|
93 } |
|
94 |
|
95 delete iDrmUri; |
|
96 delete iEventArray; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CSmilMediaRendererBase::Close |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CSmilMediaRendererBase::Close() |
|
104 { |
|
105 delete this; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CSmilMediaRendererBase::IsVisual |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 TBool CSmilMediaRendererBase::IsVisual() const |
|
113 { |
|
114 return EFalse; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CSmilMediaRendererBase::IsOpaque |
|
119 // --------------------------------------------------------- |
|
120 // |
|
121 TBool CSmilMediaRendererBase::IsOpaque() const |
|
122 { |
|
123 return EFalse; |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CSmilMediaRendererBase::IsScrollable |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 TBool CSmilMediaRendererBase::IsScrollable() const |
|
131 { |
|
132 return EFalse; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------- |
|
136 // CSmilMediaRendererBase::IsControl |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 TBool CSmilMediaRendererBase::IsControl() const |
|
140 { |
|
141 return ETrue; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CSmilMediaRendererBase::IntrinsicWidth |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 TInt CSmilMediaRendererBase::IntrinsicWidth() const |
|
149 { |
|
150 return 0; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CSmilMediaRendererBase::IntrinsicHeight |
|
155 // --------------------------------------------------------- |
|
156 // |
|
157 TInt CSmilMediaRendererBase::IntrinsicHeight() const |
|
158 { |
|
159 return 0; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CSmilMediaRendererBase::IntrinsicDuration |
|
164 // --------------------------------------------------------- |
|
165 // |
|
166 TSmilTime CSmilMediaRendererBase::IntrinsicDuration() const |
|
167 { |
|
168 return 0; |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // CSmilMediaRendererBase::Draw |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 void CSmilMediaRendererBase::Draw( CGraphicsContext& /*aGc*/, |
|
176 const TRect& /*aRect*/, |
|
177 CSmilTransitionFilter* /*aTransitionFilter*/, |
|
178 const MSmilFocus* /*aFocus*/ ) |
|
179 { |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------- |
|
183 // void CSmilMediaRendererBase::Scroll |
|
184 // --------------------------------------------------------- |
|
185 // |
|
186 void CSmilMediaRendererBase::Scroll( TInt /*aDirX*/, |
|
187 TInt /*aDirY*/ ) |
|
188 { |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------- |
|
192 // CSmilMediaRendererBase::SetVolume |
|
193 // -------------------------------------------------------- |
|
194 // |
|
195 void CSmilMediaRendererBase::SetVolume( TInt /*aVolume*/ ) |
|
196 { |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CSmilMediaRendererBase::MediaType |
|
201 // -------------------------------------------------------- |
|
202 // |
|
203 EXPORT_C TMsgMediaType CSmilMediaRendererBase::MediaType() const |
|
204 { |
|
205 return iMediaType; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // CSmilMediaRendererBase::ActivateRendererL |
|
210 // -------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C void CSmilMediaRendererBase::ActivateRendererL() |
|
213 { |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------- |
|
217 // CSmilMediaRendererBase::SendingDrmFileAllowedL |
|
218 // -------------------------------------------------------- |
|
219 // |
|
220 TBool CSmilMediaRendererBase::SendingDrmFileAllowedL( RFile& aFileHandle ) |
|
221 { |
|
222 TBool result( ETrue ); |
|
223 |
|
224 if ( iDrmProtection != DRMCommon::ENoDCFFile ) |
|
225 { |
|
226 if ( iDrmProtection == DRMCommon::ESuperDistributable ) |
|
227 { |
|
228 CData* content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ); |
|
229 |
|
230 TInt sendingAllowed( 0 ); |
|
231 |
|
232 if ( content->GetAttribute( EIsForwardable, sendingAllowed ) == KErrNone ) |
|
233 { |
|
234 if ( sendingAllowed == 0) |
|
235 { |
|
236 result = EFalse; |
|
237 } |
|
238 } |
|
239 else |
|
240 { |
|
241 result = EFalse; |
|
242 } |
|
243 |
|
244 delete content; |
|
245 } |
|
246 else |
|
247 { |
|
248 result = EFalse; |
|
249 } |
|
250 } |
|
251 |
|
252 return result; |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------- |
|
256 // CSmilMediaRendererBase::DrawFocus |
|
257 // --------------------------------------------------------- |
|
258 // |
|
259 void CSmilMediaRendererBase::DrawFocus( CGraphicsContext& aGc, |
|
260 const MSmilFocus* aFocus ) const |
|
261 { |
|
262 if ( aFocus ) |
|
263 { |
|
264 TRect rect = iFocusRect.IsEmpty() ? aFocus->Rect() : iFocusRect; |
|
265 |
|
266 aGc.Reset(); |
|
267 aGc.SetClippingRect( rect ); |
|
268 |
|
269 rect.iTl.iX += 1; |
|
270 rect.iTl.iY += 1; |
|
271 aGc.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
272 aGc.SetPenColor( KRgbGray ); |
|
273 aGc.DrawRect( rect ); |
|
274 if (aFocus->IsSelected()) |
|
275 { |
|
276 aGc.SetPenColor( KRgbBlue ); |
|
277 } |
|
278 else |
|
279 { |
|
280 aGc.SetPenColor( KRgbBlack ); |
|
281 } |
|
282 rect.Move( -1, -1 ); |
|
283 aGc.DrawRect( rect ); |
|
284 } |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CSmilMediaRendererBase::DrawScrollBars |
|
289 // --------------------------------------------------------- |
|
290 // |
|
291 void CSmilMediaRendererBase::DrawScrollBars( CGraphicsContext& aGc, |
|
292 const TRect& aRegionRect, |
|
293 const TRect& aMediaRect ) const |
|
294 { |
|
295 aGc.Reset(); |
|
296 aGc.SetClippingRect( aRegionRect ); |
|
297 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
298 |
|
299 TInt regionHeight = aRegionRect.Height(); |
|
300 TInt regionWidth = aRegionRect.Width(); |
|
301 TInt mediaHeight = aMediaRect.Height(); |
|
302 TInt mediaWidth = aMediaRect.Width(); |
|
303 |
|
304 if ( mediaWidth && |
|
305 ( aMediaRect.iTl.iX < aRegionRect.iTl.iX || |
|
306 aMediaRect.iBr.iX > aRegionRect.iBr.iX ) ) |
|
307 { |
|
308 // Draw horizontal scrollbar... |
|
309 |
|
310 // Calculate relative width of the elevator |
|
311 // (using simple proportion): |
|
312 // |
|
313 // indicatorWidth region total width |
|
314 // ------------------ = -------------------- |
|
315 // region total width media total width |
|
316 // |
|
317 TInt indicatorWidth = regionWidth * regionWidth / mediaWidth; |
|
318 indicatorWidth = Min( indicatorWidth, regionWidth ); |
|
319 |
|
320 // Calculate relative position of the elevator |
|
321 // (using simple proportion): |
|
322 // |
|
323 // indicatorXPos media to the left of region |
|
324 // ------------------- = --------------------------- |
|
325 // region total width media total width |
|
326 // |
|
327 TInt indicatorXPos = |
|
328 ( aRegionRect.iTl.iX - aMediaRect.iTl.iX ) * regionWidth / mediaWidth; |
|
329 indicatorXPos = Max( 0, indicatorXPos ); |
|
330 |
|
331 // Calculate the top left Y-coordinate for the scroll bar |
|
332 // Leave space for focus + one pixel between focus & scroll bar |
|
333 TInt topLeftY = aRegionRect.iBr.iY; |
|
334 topLeftY -= KScrollElevatorSize; |
|
335 topLeftY -= 1; |
|
336 topLeftY -= KFocusSize; |
|
337 |
|
338 // Calculate the rect of the scroll bar elevator |
|
339 // |
|
340 TRect xIndicator( |
|
341 TPoint( aRegionRect.iTl.iX + indicatorXPos, topLeftY ), |
|
342 TSize( indicatorWidth, KScrollElevatorSize ) ); |
|
343 |
|
344 // Draw scroll bar background |
|
345 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarBGColorID ) ); |
|
346 aGc.SetBrushColor( AKN_LAF_COLOR( KScrollBarBGColorID ) ); |
|
347 aGc.DrawRect( TRect( |
|
348 TPoint( aRegionRect.iTl.iX, xIndicator.iTl.iY ), |
|
349 TSize( regionWidth, xIndicator.Height() ) ) ); |
|
350 |
|
351 // Draw scroll bar elevator |
|
352 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarFGColorID ) ); |
|
353 aGc.SetBrushColor( AKN_LAF_COLOR( KScrollBarFGColorID ) ); |
|
354 aGc.DrawRect( xIndicator ); |
|
355 |
|
356 // Draw scroll bar vertical lines |
|
357 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarLineColorID ) ); |
|
358 aGc.DrawLine( |
|
359 TPoint( xIndicator.iTl.iX, xIndicator.iTl.iY ), |
|
360 TPoint( xIndicator.iTl.iX, xIndicator.iBr.iY ) ); |
|
361 aGc.DrawLine( |
|
362 TPoint( xIndicator.iBr.iX, xIndicator.iTl.iY ), |
|
363 TPoint( xIndicator.iBr.iX, xIndicator.iBr.iY ) ); |
|
364 |
|
365 } |
|
366 |
|
367 if ( mediaHeight && |
|
368 ( aMediaRect.iTl.iY < aRegionRect.iTl.iY || |
|
369 aMediaRect.iBr.iY > aRegionRect.iBr.iY ) ) |
|
370 { |
|
371 // Draw vertical scrollbar... |
|
372 |
|
373 |
|
374 // Calculate relative height of the elevator |
|
375 TInt indicatorHeight = regionHeight * regionHeight / mediaHeight; |
|
376 indicatorHeight = Min( indicatorHeight, regionHeight ); |
|
377 |
|
378 // Calculate relative position of the elevator |
|
379 TInt indicatorYPos = |
|
380 ( aRegionRect.iTl.iY - aMediaRect.iTl.iY ) * regionHeight / mediaHeight; |
|
381 indicatorYPos = Max( 0, indicatorYPos ); |
|
382 |
|
383 // Determine whether the scroll bar should be |
|
384 // on the left or on the right side of the region |
|
385 // |
|
386 // NOTE: There's one pixel wide margin both on the left |
|
387 // and the right side of the actual elevator -> thus |
|
388 // "+1" or "-1" for the x-coordinates |
|
389 TInt topLeftX = AknLayoutUtils::LayoutMirrored() |
|
390 ? aRegionRect.iTl.iX + KFocusSize + 1 |
|
391 : aRegionRect.iBr.iX - KScrollElevatorSize - 1 - KFocusSize; |
|
392 |
|
393 // Calculate the rect of the scroll bar elevator |
|
394 // |
|
395 TRect yIndicator( |
|
396 TPoint( topLeftX, aRegionRect.iTl.iY + indicatorYPos ), |
|
397 TSize( KScrollElevatorSize, indicatorHeight ) ); |
|
398 |
|
399 // Draw scroll bar background |
|
400 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarBGColorID ) ); |
|
401 aGc.SetBrushColor( AKN_LAF_COLOR( KScrollBarBGColorID ) ); |
|
402 aGc.DrawRect( TRect( |
|
403 TPoint( yIndicator.iTl.iX, aRegionRect.iTl.iY ), |
|
404 TSize( yIndicator.Width(), aRegionRect.Height() ) ) ); |
|
405 |
|
406 // Draw scroll bar elevator |
|
407 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarFGColorID ) ); |
|
408 aGc.SetBrushColor( AKN_LAF_COLOR( KScrollBarFGColorID ) ); |
|
409 aGc.DrawRect( yIndicator ); |
|
410 |
|
411 // Draw scroll bar horizontal lines |
|
412 aGc.SetPenColor( AKN_LAF_COLOR( KScrollBarLineColorID ) ); |
|
413 aGc.DrawLine( |
|
414 TPoint( yIndicator.iTl.iX, yIndicator.iTl.iY ), |
|
415 TPoint( yIndicator.iBr.iX, yIndicator.iTl.iY ) ); |
|
416 aGc.DrawLine( |
|
417 TPoint( yIndicator.iTl.iX, yIndicator.iBr.iY ), |
|
418 TPoint( yIndicator.iBr.iX, yIndicator.iBr.iY ) ); |
|
419 |
|
420 } |
|
421 |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------- |
|
425 // CSmilMediaRendererBase::BeginActiveWait |
|
426 // |
|
427 // Begins active wait. |
|
428 // --------------------------------------------------------- |
|
429 // |
|
430 void CSmilMediaRendererBase::BeginActiveWait() |
|
431 { |
|
432 if( !iWait.IsStarted() ) |
|
433 { |
|
434 TRAP_IGNORE( iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityCba ) ); |
|
435 iWait.Start(); |
|
436 } |
|
437 } |
|
438 |
|
439 // --------------------------------------------------------- |
|
440 // CSmilMediaRendererBase::EndActiveWait |
|
441 // |
|
442 // Ends active wait. |
|
443 // --------------------------------------------------------- |
|
444 // |
|
445 void CSmilMediaRendererBase::EndActiveWait() |
|
446 { |
|
447 if( iWait.IsStarted() ) |
|
448 { |
|
449 iEikonEnv->EikAppUi()->RemoveFromStack( this ); |
|
450 if ( iEventArray ) |
|
451 { |
|
452 for ( TInt current = 0; current < iEventArray->Count(); current++ ) |
|
453 { |
|
454 iCoeEnv->WsSession().SimulateKeyEvent( iEventArray->At( current ) ); |
|
455 } |
|
456 iEventArray->Reset(); |
|
457 } |
|
458 iWait.AsyncStop(); |
|
459 } |
|
460 } |
|
461 |
|
462 // --------------------------------------------------------- |
|
463 // CSmilMediaRendererBase::Intent |
|
464 // |
|
465 // Returns correct access intent for this media type. |
|
466 // --------------------------------------------------------- |
|
467 // |
|
468 ContentAccess::TIntent CSmilMediaRendererBase::Intent() const |
|
469 { |
|
470 ContentAccess::TIntent result( ContentAccess::EUnknown ); |
|
471 |
|
472 switch( iMediaType ) |
|
473 { |
|
474 case EMsgMediaAudio: |
|
475 case EMsgMediaVideo: |
|
476 { |
|
477 result = ContentAccess::EPlay; |
|
478 break; |
|
479 } |
|
480 case EMsgMediaImage: |
|
481 case EMsgMediaText: |
|
482 case EMsgMediaSvg: |
|
483 { |
|
484 result = ContentAccess::EView; |
|
485 break; |
|
486 } |
|
487 default: |
|
488 { |
|
489 break; |
|
490 } |
|
491 } |
|
492 |
|
493 return result; |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------- |
|
497 // CSmilMediaRendererBase::ConsumeDRMRightsL |
|
498 // |
|
499 // Consumes DRM rights if media object is DRM protected. |
|
500 // --------------------------------------------------------- |
|
501 // |
|
502 TInt CSmilMediaRendererBase::ConsumeDRMRightsL() |
|
503 { |
|
504 TInt result( DRMCommon::EOk ); |
|
505 |
|
506 if ( iDrmProtection != DRMCommon::ENoDCFFile && |
|
507 !iDrmRightConsumed ) |
|
508 { |
|
509 result = iDrmHelper.Consume2( *iDrmUri, |
|
510 Intent(), |
|
511 CDRMHelper::EStart ); |
|
512 |
|
513 iDrmRightConsumed = ETrue; |
|
514 } |
|
515 |
|
516 return result; |
|
517 } |
|
518 |
|
519 // --------------------------------------------------------- |
|
520 // CSmilMediaRendererBase::CheckDRMRights |
|
521 // |
|
522 // Checks DRM rights if media object is DRM protected. |
|
523 // --------------------------------------------------------- |
|
524 // |
|
525 TInt CSmilMediaRendererBase::CheckDRMRights() |
|
526 { |
|
527 TInt result( DRMCommon::EOk ); |
|
528 |
|
529 if ( iDrmProtection != DRMCommon::ENoDCFFile ) |
|
530 { |
|
531 result = iDrmCommon.CheckContentRights( *iDrmUri, |
|
532 Intent() ); |
|
533 |
|
534 } |
|
535 |
|
536 return result; |
|
537 } |
|
538 |
|
539 // --------------------------------------------------------- |
|
540 // CSmilMediaRendererBase::OfferKeyEventL |
|
541 // |
|
542 // Consumes all key events. |
|
543 // --------------------------------------------------------- |
|
544 // |
|
545 TKeyResponse CSmilMediaRendererBase::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
546 TEventCode /*aType*/ ) |
|
547 { |
|
548 if ( !iEventArray ) |
|
549 { |
|
550 iEventArray = new( ELeave ) CArrayFixFlat<TKeyEvent>( 2 ); |
|
551 } |
|
552 iEventArray->AppendL( aKeyEvent ); |
|
553 return EKeyWasConsumed; |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------- |
|
557 // CSmilMediaRendererBase::RetrieveIconSize |
|
558 // |
|
559 // Retrieves correct icon size from LAF. |
|
560 // --------------------------------------------------------- |
|
561 // |
|
562 TSize CSmilMediaRendererBase::RetrieveIconSize() const |
|
563 { |
|
564 TRect appWindowRect; |
|
565 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow, appWindowRect ); |
|
566 |
|
567 TAknLayoutRect mainPane; |
|
568 mainPane.LayoutRect( appWindowRect, AknLayoutScalable_Avkon::main_pane( 0 ) ); |
|
569 |
|
570 TAknLayoutRect mainSmilPane; |
|
571 mainSmilPane.LayoutRect( mainPane.Rect(), AknLayoutScalable_Apps::main_smil_pane() ); |
|
572 |
|
573 TAknLayoutRect iconLayout; |
|
574 iconLayout.LayoutRect( mainSmilPane.Rect(), AknLayoutScalable_Apps::msg_data_pane_g7() ); |
|
575 |
|
576 return iconLayout.Rect().Size(); |
|
577 } |
|
578 |
|
579 |
|
580 // End of file |