webengine/osswebengine/WebKit/s60/plugins/PluginWin.cpp
changeset 0 dd21522fd290
child 8 7c90e6132015
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:  Acts as an adapter between plugin and browser.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "../../bidi.h"
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <e32def.h>
       
    23 #include <eikdef.h>
       
    24 #include <eikenv.h>
       
    25 #include <eikappui.h>
       
    26 #include <SysUtil.h>
       
    27 #include <AknUtils.h>
       
    28 
       
    29 #include "WebFrame.h"
       
    30 #include "HttpDefs.h"
       
    31 #include "BrCtlDefs.h"
       
    32 #include "StaticObjectsContainer.h"
       
    33 #include <PluginAdapterInterface.h>
       
    34 #include "PluginWin.h"
       
    35 #include "PluginSkin.h"
       
    36 #include "PluginHandler.h"
       
    37 #include "PluginStream.h"
       
    38 #include "WebView.h"
       
    39 #include "WebFrameView.h"
       
    40 #include "WebSurface.h"
       
    41 #include "BrCtl.h"
       
    42 #include "Frame.h"
       
    43 #include "WebCursor.h"
       
    44 #include "WebPageScrollHandler.h"
       
    45 
       
    46 using namespace WebCore;
       
    47 // CONSTANTS
       
    48 const TInt KPluginGranularity = 3;
       
    49 _LIT(KPath,"c:\\system\\temp\\");
       
    50 
       
    51 void panicPlugin(TInt error = KErrNone)
       
    52 {
       
    53     User::Panic(_L("Plugin Handling Panic"), error);
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // PluginWin::PluginWin
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 PluginWin::PluginWin(PluginSkin* pluginskin)
       
    63     : m_pluginskin(pluginskin)
       
    64     , m_windowedPlugin(true), m_fullscreen(false), m_windowCreated(false)
       
    65 {
       
    66 }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // PluginWin::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 void PluginWin::ConstructL( const WebView& view )
       
    73 {
       
    74     if (m_windowedPlugin) {
       
    75         CreateWindowL((CCoeControl*)&view);
       
    76         ActivateL();
       
    77 		m_windowCreated = true;
       
    78     } else {
       
    79         SetContainerWindowL(*view.brCtl()->CCoeControlParent());
       
    80         m_bitmap = new (ELeave) CFbsBitmap();
       
    81         m_bitmap->Create(TSize(0,0),WebCore::StaticObjectsContainer::instance()->webSurface()->displayMode());
       
    82         m_mask = new (ELeave) CFbsBitmap();
       
    83         m_mask->Create(TSize(0,0),EGray2);
       
    84     }
       
    85     // Add the focus/foreground observer
       
    86     ControlEnv()->AddForegroundObserverL( *this ) ;
       
    87 }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // PluginWin::~PluginWin
       
    91 // Deconstructor.
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 PluginWin::~PluginWin()
       
    95 {
       
    96 
       
    97     TRAP_IGNORE( setPluginFocusL( EFalse ) );
       
    98 
       
    99     // Remove the foreground observer
       
   100     ControlEnv()->RemoveForegroundObserver( *this );
       
   101     delete m_bitmap;
       
   102     delete m_mask;
       
   103     delete m_bitmapDeviceMask;
       
   104     delete m_bitmapContextMask;
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // PluginWin::NewL
       
   109 // Two-phased constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 PluginWin* PluginWin::NewL( PluginSkin* pluginskin,
       
   113                             const WebView& view  )
       
   114 {
       
   115     PluginWin* self = new( ELeave ) PluginWin(pluginskin);
       
   116     return self;
       
   117 }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // PluginWin::PositionChanged
       
   121 // Update the size of the control.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void PluginWin::PositionChanged()
       
   125 {
       
   126     windowChanged();
       
   127 }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // PluginWin::SizeChanged
       
   131 // Update the size of the control.
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void PluginWin::SizeChanged()
       
   135 {
       
   136     windowChanged();
       
   137 }
       
   138 
       
   139 void PluginWin::windowChanged()
       
   140 {
       
   141     TRAPD(ret, windowChangedL());
       
   142     if (ret != KErrNone) {
       
   143         delete m_bitmap;
       
   144         m_bitmap = NULL;
       
   145         delete m_mask;
       
   146         m_mask = NULL;
       
   147         delete m_bitmapDeviceMask;
       
   148         m_bitmapDeviceMask = NULL;
       
   149         delete m_bitmapContextMask;
       
   150         m_bitmapContextMask = NULL;
       
   151     }
       
   152     if (m_forceScroll)
       
   153     	m_forceScroll = EFalse;
       
   154 }
       
   155 
       
   156 void PluginWin::windowChangedL()
       
   157 {
       
   158     if (m_fullscreen) return;
       
   159     if (m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->setwindow ){
       
   160         NPWindow  window;
       
   161     TRect rect( m_pluginskin->getPluginWinRect() );
       
   162     TRect clipRect = m_pluginskin->getClipRect();
       
   163     TRect myRect = Rect();
       
   164         if (!m_windowedPlugin) {
       
   165             myRect.Move(-myRect.iTl.iX, -myRect.iTl.iY); // windowed CCoeControl uses its own coordinates
       
   166         }
       
   167     TRect passedRect = clipRect;
       
   168     passedRect.Intersection(rect);
       
   169     TPoint tl = myRect.iTl - passedRect.iTl;
       
   170         // Coordinates for the plugin always start from (0,0) and are relative
       
   171         // to the parent CCoeControl
       
   172         rect.Move(tl);
       
   173         clipRect.Move(tl);
       
   174         clipRect.Intersection(myRect);
       
   175         window.x = rect.iTl.iX;
       
   176         window.y = rect.iTl.iY;
       
   177         window.width = rect.Width();
       
   178         window.height = rect.Height();
       
   179         window.type = m_windowedPlugin ? NPWindowTypeWindow : NPWindowTypeDrawable ;
       
   180         clipRect.iTl.iX = Max(clipRect.iTl.iX, 0);
       
   181         clipRect.iTl.iY = Max(clipRect.iTl.iY, 0);
       
   182         clipRect.iBr.iX = Max(clipRect.iBr.iX, 0);
       
   183         clipRect.iBr.iY = Max(clipRect.iBr.iY, 0);
       
   184         window.clipRect.top = clipRect.iTl.iY;
       
   185         window.clipRect.left = clipRect.iTl.iX;
       
   186         window.clipRect.bottom =clipRect.iBr.iY;
       
   187         window.clipRect.right = clipRect.iBr.iX;
       
   188 
       
   189         if (m_windowedPlugin) {
       
   190              window.window =  (MPluginAdapter*)this;
       
   191         } else {
       
   192              //m_bitmap->Resize(myRect.Size());
       
   193              // Resize does not work!
       
   194              // Once the bug is fixed we can call Resize() instead of creating a new bitmap every time.
       
   195              if (!m_bitmap || m_bitmap->SizeInPixels() != myRect.Size()) {
       
   196                  delete m_bitmap;
       
   197                  m_bitmap = NULL;
       
   198                  m_bitmap = new (ELeave) CFbsBitmap();
       
   199                  TDisplayMode mode = m_transparentPlugin ? EColor16MA : WebCore::StaticObjectsContainer::instance()->webSurface()->displayMode();
       
   200                  m_bitmap->Create(myRect.Size(), mode);
       
   201                  delete m_mask;
       
   202                  m_mask = NULL;
       
   203                  if (m_transparentPlugin) {
       
   204                      m_mask = new (ELeave) CFbsBitmap();
       
   205                      m_mask->Create(myRect.Size(), mode);
       
   206                      m_bitmapDeviceMask = CFbsBitmapDevice::NewL( m_mask );
       
   207                      User::LeaveIfError(m_bitmapDeviceMask->CreateContext(m_bitmapContextMask));
       
   208                  }
       
   209              }
       
   210              window.window = (CFbsBitmap*)m_bitmap;
       
   211         }
       
   212 		if (!m_windowedPlugin || m_windowCreated)
       
   213 			m_pluginskin->getNPPluginFucs()->setwindow(m_pluginskin->getNPP(), &window );
       
   214 
       
   215     }
       
   216 }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // PluginWin::ProcessEventL
       
   220 // Procces a user interface event.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void PluginWin::processEventL( TPluginEventType eventType,
       
   224                                 TBool& consumed )
       
   225 {
       
   226 	  CBrCtl*   brCtl = control(m_pluginskin->frame());
       
   227 	  WebView*  view = brCtl->webView();
       
   228     consumed = EFalse;
       
   229 
       
   230     switch ( eventType ) {
       
   231         case EEventActivate:
       
   232                 if ( m_notifier )
       
   233                 {
       
   234                     TPoint pt = StaticObjectsContainer::instance()->webCursor()->position() - Position();
       
   235                     m_notifier->NotifyL( MPluginNotifier::EPluginActivated, (void*) &pt );
       
   236                 }
       
   237             consumed = ETrue;
       
   238             view->setPluginActivated(true);   //Setting pluginactivated flag in webview
       
   239             setPluginFocusL( ETrue );
       
   240         break;
       
   241 
       
   242         case EEventDeactivate:
       
   243                 if( m_notifier )
       
   244                 {
       
   245                     m_notifier->NotifyL( MPluginNotifier::EPluginDeactivated, (void*) 0 );
       
   246                 }
       
   247             consumed = ETrue;
       
   248             view->setPluginActivated(false);
       
   249             setPluginFocusL( EFalse );
       
   250         break;
       
   251 
       
   252         case EEventLoseFocus:
       
   253         if ( m_notifier ) {
       
   254             HandleLosingForeground();
       
   255             consumed = ETrue;
       
   256         }
       
   257         break;
       
   258 
       
   259         case EEventGainFocus:
       
   260             HandleGainingForeground();
       
   261             consumed = ETrue;
       
   262         break;
       
   263 
       
   264         default:
       
   265         break;
       
   266     }
       
   267 
       
   268 }
       
   269 
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // PluginWin::OfferKeyEventL
       
   273 // Hands a key event to the control.
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TKeyResponse PluginWin::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   277                                          TEventCode aType )
       
   278 {
       
   279     TKeyResponse ret = EKeyWasNotConsumed;
       
   280     if ( m_control ) {
       
   281         ret = m_control->OfferKeyEventL( aKeyEvent, aType );
       
   282     }
       
   283     else if (!m_windowedPlugin && m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->event) {
       
   284         NPEvent event;
       
   285         NPEventKey eventKey;
       
   286         event.event = ENppEventKey;
       
   287         eventKey.keyEvent = &aKeyEvent;
       
   288         eventKey.type = aType;
       
   289         eventKey.reserved = NULL;
       
   290         event.param = &eventKey;
       
   291         ret = (TKeyResponse)m_pluginskin->getNPPluginFucs()->event(m_pluginskin->getNPP(), static_cast<void*>(&event));
       
   292     }
       
   293     return ret;
       
   294 }
       
   295 
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // PluginWin::ComponentControl
       
   299 // Return the child control by index.
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 CCoeControl* PluginWin::ComponentControl( TInt /*aIndex*/ ) const
       
   303 {
       
   304     return 0;
       
   305 }
       
   306 // -----------------------------------------------------------------------------
       
   307 // PluginWin::CountComponentControls
       
   308 // Return the number of child controls.
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 TInt PluginWin::CountComponentControls() const
       
   312 {
       
   313     return 0;
       
   314 }
       
   315 
       
   316 //-------------------------------------------------------------------------------
       
   317 // HandlePointerEventL
       
   318 // Handles Pointer Events
       
   319 //-------------------------------------------------------------------------------
       
   320 void PluginWin::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   321 {
       
   322     if (!m_windowedPlugin && m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->event) {
       
   323         NPEvent event;
       
   324         NPEventPointer ep;
       
   325         event.event = ENppEventPointer;
       
   326 
       
   327         TPoint pt;
       
   328         if (m_pluginskin->pluginPlayer()) {
       
   329             pt = aPointerEvent.iPosition;
       
   330             pt -= Rect().iTl;
       
   331             pt = m_pluginskin->frame()->frameView()->toDocCoords(pt);
       
   332         }
       
   333         else {
       
   334             pt = m_pluginskin->frame()->frameView()->viewCoordsInFrameCoords(aPointerEvent.iPosition);
       
   335             pt -= m_pluginskin->rect().iTl;
       
   336         }
       
   337         TPointerEvent pe(aPointerEvent);
       
   338         pe.iPosition = pt;
       
   339 
       
   340         ep.pointerEvent = &pe;
       
   341         ep.reserved = NULL;
       
   342         event.param = &ep;
       
   343         m_pluginskin->getNPPluginFucs()->event(m_pluginskin->getNPP(), static_cast<void*>(&event));
       
   344     }
       
   345 }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // PluginWin::RefreshPlugin
       
   349 //
       
   350 // Refresh the plugin. - Called by PluginSkin
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 TInt PluginWin::refreshPlugin(CFbsBitGc& bitmapContext)
       
   354 {
       
   355     if (m_control && IsVisible() && m_control->DrawableWindow())
       
   356         m_control->DrawNow();
       
   357     if (!m_windowedPlugin && m_bitmap) {
       
   358         NPEvent event;
       
   359         event.event = ENppEventDraw;
       
   360         event.param = 0;
       
   361         if (m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->event) {
       
   362             m_pluginskin->getNPPluginFucs()->event(m_pluginskin->getNPP(), static_cast<void*>(&event));
       
   363         }
       
   364         WebFrameView* fv = m_pluginskin->frame()->frameView();
       
   365         TRect rect(Rect());
       
   366         rect = TRect(fv->viewCoordsInFrameCoords(Rect().iTl), fv->viewCoordsInFrameCoords(Rect().iBr));
       
   367         rect = fv->toViewCoords(rect);
       
   368         rect.SetSize(m_bitmap->SizeInPixels()); // toViewCoords sometimes grows the rect by 1, which wil cause the bitmap to not draw
       
   369         if (m_transparentPlugin) {
       
   370             m_bitmapContextMask->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   371             m_bitmapContextMask->SetPenStyle( CGraphicsContext::ESolidPen );
       
   372             m_bitmapContextMask->SetPenColor( TRgb( 30, 30, 30 ) );
       
   373             m_bitmapContextMask->SetBrushColor( TRgb( 30, 30, 30 ) );
       
   374             m_bitmapContextMask->DrawRect(m_mask->SizeInPixels() );
       
   375             bitmapContext.DrawBitmapMasked(rect, m_bitmap, rect.Size(), m_mask, true);
       
   376         }
       
   377         else {
       
   378             bitmapContext.DrawBitmap(rect, m_bitmap, rect.Size());
       
   379         }
       
   380     }
       
   381     return KErrNone;
       
   382 }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // PluginWin::MakeVisible
       
   386 //
       
   387 // Hides or shows the PluginInst.
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 void PluginWin::makeVisible( TBool visible )
       
   391     {
       
   392     if(IsVisible() != visible) 
       
   393     {
       
   394         CCoeControl::MakeVisible(visible);
       
   395     }
       
   396     NotifyPluginVisible(visible);
       
   397     if (!m_windowedPlugin && m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->event) {
       
   398         NPEvent event;
       
   399         NpEventVisibility ev;
       
   400         event.event = ENppEventVisibility;
       
   401         ev.visible = visible;
       
   402         ev.reserved = 0;
       
   403         event.param = &ev;
       
   404         m_pluginskin->getNPPluginFucs()->event(m_pluginskin->getNPP(), static_cast<void*>(&event));
       
   405     }
       
   406 }
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // PluginWin::HandleControlEventL
       
   410 //
       
   411 // Handles an event from an observed control.
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 void PluginWin::HandleControlEventL( CCoeControl* /*aControl*/,
       
   415                                       TCoeEvent /*aEventType*/ )
       
   416 {
       
   417 }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // PluginWin::ViewFocusChanged
       
   421 //
       
   422 // Invoked by CCoeControl to WebKitView to PluginWin when the Browser focus
       
   423 // changes. This method notifies all plugins of thier current focus state.
       
   424 // NOTES:
       
   425 // iBrowserBackground means that the browser app is not top application,
       
   426 // such as when bookmarks, idle screen, or another app/view is in foreground.
       
   427 // aFocused is true if browser has focus and false if browser is out of focus
       
   428 // and a plugin has taken focus.
       
   429 // -----------------------------------------------------------------------------
       
   430 void PluginWin::viewFocusChanged( TBool focused )
       
   431 {
       
   432 if (m_notifier)
       
   433 		{
       
   434 		if (focused)
       
   435 			{
       
   436 			// The browser brings back the focus, and so are plugins.
       
   437 			    HandleGainingForeground();
       
   438 			}
       
   439 		else
       
   440 			{
       
   441 			// The browser doesn't have focus and this plugin focus state is...
       
   442 			if ( m_pluginfocus )
       
   443 				{
       
   444 				// This plugin is selected to be activate, so the focus is on this plugin now.
       
   445 				   HandleGainingForeground();
       
   446 				}
       
   447 			else
       
   448 				{
       
   449 				// The focus on the plugin is cancelled. This happens when deactivate the selected plugin
       
   450 				   HandleLosingForeground();
       
   451 				}
       
   452 			}
       
   453 		}
       
   454 }
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 // PluginWin::SetPluginFocusL
       
   458 // Give or take focus from the plugin. The calls AddToStackL or RemoveFromStackL
       
   459 // will cause the CCoeControl architecture to call SetFocus, which will end up
       
   460 // calling ViewFocusChanged().
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void PluginWin::setPluginFocusL(TBool focus)
       
   464 {
       
   465     if (focus) {
       
   466 
       
   467         if (!m_pluginfocus) {
       
   468             m_pluginfocus = ETrue;
       
   469             iEikonEnv->EikAppUi()->AddToStackL(this);
       
   470             SetFocus(ETrue);
       
   471         }
       
   472     }
       
   473     else {
       
   474 
       
   475         if (m_pluginfocus) {
       
   476             m_pluginfocus = EFalse;
       
   477             iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   478             SetFocus(EFalse);
       
   479         }
       
   480     }
       
   481 }
       
   482 
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // PluginWin::ResizePluginRect
       
   486 //
       
   487 // Resize the plugin rect. This requires that we set the iRect and re-layout
       
   488 // the render object.
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 void PluginWin::resizePluginRect(TRect& rect)
       
   492 {
       
   493     // Get our current rect
       
   494     TRect skinRect( m_pluginskin->rect() );
       
   495 
       
   496     // If the rect sizes are the same, we don't need to save and relayout
       
   497     if (skinRect.Size() == rect.Size()) {
       
   498         return;
       
   499     }
       
   500 
       
   501     // Set the PluginSkin rect, used by WebCore and PluginWin for layout.
       
   502     // The adjusted rect has the new size, but same starting point
       
   503     TRect adjustedRect (skinRect.iTl, rect.Size() );
       
   504     m_pluginskin->setRect(adjustedRect);
       
   505 
       
   506     m_pluginskin->resized();
       
   507 }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // PluginWin::HandleGainingForeground
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 void PluginWin::HandleGainingForeground()
       
   514 {
       
   515     if (m_notifier) {
       
   516         TRAP_IGNORE(m_notifier->NotifyL(MPluginNotifier::EApplicationFocusChanged, (void*)1));
       
   517     }
       
   518 }
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // PluginWin::HandleLosingForeground
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 void PluginWin::HandleLosingForeground()
       
   525 {
       
   526     if (m_notifier) {
       
   527         TRAP_IGNORE(m_notifier->NotifyL(MPluginNotifier::EApplicationFocusChanged, (void*)0));
       
   528     }
       
   529 }
       
   530 
       
   531 
       
   532 // Functions from MPluginAdapter
       
   533 HBufC8* PluginWin::PluginDataUrl()
       
   534 {
       
   535     if (m_pluginskin)
       
   536         return m_pluginskin->url();
       
   537     return NULL;
       
   538 }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // PluginWin::addPluginOptionsL
       
   542 //
       
   543 // Add the Option Menu items to the menuPane, these will be handled by the
       
   544 // plugin. The menu items are added in this method and then handled in the
       
   545 // HandlePluginCommandL method. If the Option Menu Handler is not defined, then
       
   546 // the plugin doesn't handle custom menu commands.
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 void PluginWin::addPluginOptionsL(CEikMenuPane& menuPane, TInt commandBase, TInt after)
       
   550     {
       
   551     if (m_optionmenuhandler)
       
   552         {
       
   553         m_optionmenuhandler->AddPluginOptionMenuItemsL(menuPane, commandBase, after);
       
   554         }
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // PluginWin::handlePluginCommandL
       
   559 //
       
   560 // Add the Option Menu items to the menuPane, these will be handled by the
       
   561 // plugin. The menu items are added in this method and then handled in the
       
   562 // HandlePluginCommandL method. If the Option Menu Handler is not defined, then
       
   563 // the plugin doesn't handle custom menu commands.
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 void PluginWin::handlePluginCommandL(TInt id)
       
   567     {
       
   568     if (m_optionmenuhandler)
       
   569         {
       
   570         m_optionmenuhandler->HandlePluginCommandL(id);
       
   571         }
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // PluginWin::FocusChanged
       
   576 //
       
   577 // virtual function from CCoeControl for plugin win
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 void PluginWin::FocusChanged(TDrawNow aDrawNow)
       
   581 {
       
   582     if(m_pluginfocus) {
       
   583         m_pluginskin->pluginFocusChanged(IsFocused());
       
   584     }
       
   585 }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 NPObject* PluginWin::windowScriptNPObject()
       
   590     {
       
   591     Frame* f = core(m_pluginskin->frame());
       
   592     if (f)
       
   593         return f->windowScriptNPObject();
       
   594     return 0;
       
   595     }
       
   596 
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // PluginWin::ForceRedraw
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void PluginWin::forceRedraw(bool drawNow)
       
   603     {
       
   604     if (m_pluginskin->pluginPlayer()) {
       
   605         DrawNow();
       
   606     }
       
   607     else {
       
   608         WebFrame* mf = (m_pluginskin->frame());
       
   609         WebFrameView* fv = mf->frameView();
       
   610         TRect rect(Rect());
       
   611         rect = TRect(fv->viewCoordsInFrameCoords(Rect().iTl), fv->viewCoordsInFrameCoords(Rect().iBr));
       
   612     if (mf && mf->frameView())
       
   613             mf->frameView()->invalidateRect(rect, drawNow);
       
   614     }
       
   615 }
       
   616 
       
   617 // -----------------------------------------------------------------------------
       
   618 // CPluginWin::MoveWindow
       
   619 // Move/scroll window by aOffset and also sets the current cursor position
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 void PluginWin::moveWindow(const TPoint& aOffset)
       
   623     {
       
   624     // set force scroll to true, when plugin gives move command, 
       
   625     // browser needs to move window according to offset value
       
   626     m_forceScroll = ETrue;
       
   627     // This plug-in has focus, so hide the Browser's cursor. The Plugin
       
   628     // can display its own cursor, if it needs one.
       
   629 
       
   630     WebFrame* mf = mainFrame(m_pluginskin->frame());
       
   631     WebCursor* c = StaticObjectsContainer::instance()->webCursor();
       
   632     if (c && mf && mf->frameView() && !m_pluginskin->pluginPlayer())
       
   633         {
       
   634             // Offset sent by plugins doesn't take care of zoom level. Calculate currect offset value
       
   635             WebView *view = control(m_pluginskin->frame())->webView();
       
   636             TInt zoomlevel = view->zoomLevel();
       
   637 		    TPoint oldPos(mf->frameView()->contentPos());
       
   638 		    TPoint newPos ((aOffset.iX  * 100)/zoomlevel, (aOffset.iY  * 100)/zoomlevel);
       
   639 	        c->offsetCursor( aOffset );
       
   640             mf->frameView()->scrollTo(oldPos + newPos);
       
   641             c->cursorUpdate(EFalse);        
       
   642         }
       
   643 
       
   644     }
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CPluginWin::PluginDeactivate
       
   648 // Deactivate the plugin
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 void PluginWin::pluginDeactivate()
       
   652     {
       
   653     m_pluginskin->deActivate();
       
   654     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // CPluginWin::HitRegionContains
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 TBool PluginWin::HitRegionContains(const TPoint &aPoint, const CCoeControl &/*aControl*/) const
       
   661     {
       
   662 
       
   663     if (m_pluginskin->frame()->frameView()->topView()->focusedElementType() != TBrCtlDefs::EElementActivatedObjectBox)
       
   664         {
       
   665 
       
   666         if ( !m_pluginskin->CanInteract() && !m_pluginskin->pluginPlayer() )
       
   667         {
       
   668             m_pluginskin->activate();
       
   669         }
       
   670         else {
       
   671         TPoint point = m_pluginskin->getPluginWinRect().iTl + aPoint;
       
   672 
       
   673         // Plugin gets pointer event. Activate plugin
       
   674 	      control(m_pluginskin->frame())->webView()->setFocusNone();
       
   675 
       
   676         WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   677         cursor->setPosition(point);
       
   678         TKeyEvent keyEvent;
       
   679         keyEvent.iModifiers = 0;
       
   680         keyEvent.iRepeats = 0;
       
   681         keyEvent.iCode = EKeyDevice3;
       
   682         keyEvent.iScanCode = EStdKeyDevice3;
       
   683         CCoeEnv::Static()->SimulateKeyEventL(keyEvent, EEventKeyDown);
       
   684         CCoeEnv::Static()->SimulateKeyEventL(keyEvent, EEventKey);
       
   685         CCoeEnv::Static()->SimulateKeyEventL(keyEvent, EEventKeyUp);
       
   686         PluginWin* win = const_cast<PluginWin*>(this);
       
   687         }
       
   688         }
       
   689     return ETrue;
       
   690     }
       
   691 
       
   692 
       
   693 // -----------------------------------------------------------------------------
       
   694 // CPluginWin::PluginConstructedL
       
   695 //
       
   696 // Notify the associated PluginInst that it's control has been created.
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 void PluginWin::PluginConstructedL( CCoeControl *aControl )
       
   700     {
       
   701     m_control = aControl;
       
   702     aControl->SetHitTest(this);
       
   703     }
       
   704 
       
   705 // -----------------------------------------------------------------------------
       
   706 // CPluginWin::Draw
       
   707 //
       
   708 // Draw the plugin, called only when in the PluginPlayer.
       
   709 // -----------------------------------------------------------------------------
       
   710 //
       
   711 void PluginWin::Draw( const TRect& /*rect*/ ) const
       
   712 {
       
   713     if (m_pluginskin->pluginPlayer() && !m_windowedPlugin && m_bitmap) {
       
   714         NPEvent event;
       
   715         event.event = ENppEventDraw;
       
   716         event.param = 0;
       
   717         if (m_pluginskin->getNPPluginFucs() && m_pluginskin->getNPPluginFucs()->event) {
       
   718             m_pluginskin->getNPPluginFucs()->event(m_pluginskin->getNPP(), static_cast<void*>(&event));
       
   719         }
       
   720         CWindowGc& gc = SystemGc();
       
   721         gc.BitBlt(Rect().iTl, m_bitmap);
       
   722     }
       
   723 }
       
   724 
       
   725 void PluginWin::TogleScreenMode(bool aFullScreen)
       
   726 {
       
   727   m_fullscreen = aFullScreen;
       
   728   WebFrame* mf = mainFrame(m_pluginskin->frame());
       
   729   CBrCtl*   brCtl = control(m_pluginskin->frame());
       
   730   WebView*  view = brCtl->webView();
       
   731 
       
   732   view->setPluginFullscreen(aFullScreen);
       
   733   brCtl->reportStateChanged(TBrCtlDefs::EStatePluginFullScreen, m_fullscreen);
       
   734 }
       
   735 
       
   736 void PluginWin::NotifyPluginVisible (TBool visible)
       
   737 
       
   738 {
       
   739   if(m_notifier)
       
   740     {
       
   741       if(visible && IsVisible())
       
   742       {
       
   743         TRAP_IGNORE(m_notifier->NotifyL(MPluginNotifier::EPluginInvisible, (void*)1));
       
   744       }
       
   745       else
       
   746       {
       
   747         TRAP_IGNORE(m_notifier->NotifyL(MPluginNotifier::EPluginInvisible, (void*)0));
       
   748       }	
       
   749     }
       
   750 }