webengine/osswebengine/WebKit/s60/plugins/PluginPlayer.cpp
changeset 0 dd21522fd290
child 13 10e98eab6f85
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 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 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:  Page overview control
       
    15 *
       
    16 */
       
    17 #include "../../bidi.h"
       
    18 
       
    19 #include "PluginPlayer.h"
       
    20 #include "BrCtl.h"
       
    21 #include "PluginWin.h"
       
    22 #include "PluginSkin.h"
       
    23 #include "WebView.h"
       
    24 #include "WebFrame.h"
       
    25 #include <AknUtils.h>
       
    26 
       
    27 PluginPlayer* PluginPlayer::NewL( CBrCtl& parent, PluginWin* plugin )
       
    28     {
       
    29     PluginPlayer* self = new (ELeave) PluginPlayer(parent, plugin );
       
    30     CleanupStack::PushL( self );
       
    31     self->ConstructL();
       
    32     CleanupStack::Pop();
       
    33     return self;
       
    34     }
       
    35 
       
    36 PluginPlayer::PluginPlayer( CBrCtl& parent, PluginWin* plugin )
       
    37     : m_brctl( parent ), m_plugin( plugin )
       
    38     {
       
    39     }
       
    40 
       
    41 void PluginPlayer::ConstructL()
       
    42     {
       
    43     SetContainerWindowL( m_brctl );
       
    44     SetRect( m_brctl.Rect() );
       
    45     if (AknLayoutUtils::PenEnabled()) {
       
    46         DrawableWindow()->SetPointerGrab(ETrue);
       
    47         EnableDragEvents();
       
    48     }
       
    49 
       
    50     ActivateL();
       
    51     }
       
    52 
       
    53 PluginPlayer::~PluginPlayer()
       
    54     {
       
    55     }
       
    56 
       
    57 void PluginPlayer::Draw( const TRect& rect ) const
       
    58     {
       
    59     CWindowGc& gc = SystemGc();
       
    60     
       
    61     // draw the background
       
    62     gc.SetPenStyle( CGraphicsContext::ESolidPen );
       
    63     gc.SetPenColor( TRgb( 128, 128, 128 ) );
       
    64     gc.SetBrushColor( TRgb( 192, 192, 192 ) );
       
    65     gc.SetBrushStyle( CGraphicsContext::EDiamondCrossHatchBrush );
       
    66     gc.DrawRect( rect );
       
    67     }
       
    68 
       
    69 TInt PluginPlayer::CountComponentControls() const
       
    70     {
       
    71     if( m_plugin )
       
    72         return 1;
       
    73     else
       
    74         return 0;
       
    75     }
       
    76 
       
    77 CCoeControl *PluginPlayer::ComponentControl(TInt /*aIndex*/) const
       
    78     {
       
    79     return m_plugin;
       
    80     }
       
    81 
       
    82 
       
    83 TKeyResponse PluginPlayer::OfferKeyEventL(const TKeyEvent keyEvent, TEventCode type)
       
    84     {
       
    85     return m_plugin->OfferKeyEventL( keyEvent, type );
       
    86     }
       
    87 
       
    88 void PluginPlayer::start()
       
    89     {
       
    90     m_orgparent = m_plugin->Parent();    
       
    91     m_orgrect = TRect( m_plugin->Position(), m_plugin->Size() );
       
    92     
       
    93     m_plugin->SetParent( this );
       
    94 
       
    95     // try to guess what part the user wants to see, this way
       
    96     // we can avoid unnecessary scrolling;
       
    97     // - if the content can be made fully visible, we just center the content.
       
    98     // - if any of the edge is clipped away, we try to show as much as possible while still
       
    99     // keep the opposite edge visible.
       
   100     // - if both edge are clipped away, don't do anything.
       
   101     const TRect& rect = Rect();
       
   102     TInt x = ( rect.Width() - m_orgrect.Width() )/2;
       
   103     TInt y = ( rect.Height() - m_orgrect.Height() )/2;
       
   104 
       
   105     // horizontal
       
   106     if( x < 0 )
       
   107         {
       
   108         if( m_orgrect.iBr.iX < rect.iBr.iX )
       
   109             x = m_orgrect.iTl.iX + rect.iBr.iX - m_orgrect.iBr.iX;    // right edge visible
       
   110         else if( m_orgrect.iTl.iX > rect.iTl.iX )
       
   111             x = rect.iTl.iX;                                        // left edge visible
       
   112         else
       
   113             x = m_orgrect.iTl.iX;                                    // both edges are clipped away
       
   114         }
       
   115 
       
   116     // vertical
       
   117     if( y < 0 )
       
   118         {
       
   119         if( m_orgrect.iBr.iY < rect.iBr.iY )
       
   120             y = m_orgrect.iTl.iY + rect.iBr.iY - m_orgrect.iBr.iY;    // bottom edge visible
       
   121         else if( m_orgrect.iTl.iY > rect.iTl.iY )
       
   122             y = rect.iTl.iY;                                        // top edge visible
       
   123         else
       
   124             y = m_orgrect.iTl.iY;                                    // both edges are clipped away
       
   125         }
       
   126         
       
   127     m_plugin->SetRect( TRect( TPoint(x,y), m_orgrect.Size() ) );
       
   128     m_plugin->makeVisible( ETrue );
       
   129 
       
   130     DrawNow();
       
   131     // not sure why we need this for bavp
       
   132     m_plugin->SetRect( TRect( TPoint(x,y), m_orgrect.Size() ) );
       
   133     m_plugin->setPluginFocusL(ETrue);
       
   134     
       
   135     }
       
   136 
       
   137 void PluginPlayer::stop()
       
   138     {
       
   139     m_plugin->setPluginFocusL(EFalse);
       
   140     m_plugin->SetParent( m_orgparent );
       
   141     m_plugin->SetRect( TRect( m_orgrect.iTl, m_orgrect.Size() ) );
       
   142     m_plugin->makeVisible( EFalse );
       
   143     }
       
   144 
       
   145 void PluginPlayer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   146 {
       
   147     m_plugin->HandlePointerEventL(aPointerEvent);
       
   148 }
       
   149 
       
   150 // END OF FILE