webengine/osswebengine/WebKit/s60/webview/WebView.cpp
changeset 0 dd21522fd290
child 8 7c90e6132015
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
       
     3 * Copyright (C) 2006 David Smith (catfish.man@gmail.com)
       
     4 * Copyright (C) 2007 Nokia
       
     5 *
       
     6 * Redistribution and use in source and binary forms, with or without
       
     7 * modification, are permitted provided that the following conditions
       
     8 * are met:
       
     9 *
       
    10 * 1.  Redistributions of source code must retain the above copyright
       
    11 *     notice, this list of conditions and the following disclaimer.
       
    12 * 2.  Redistributions in binary form must reproduce the above copyright
       
    13 *     notice, this list of conditions and the following disclaimer in the
       
    14 *     documentation and/or other materials provided with the distribution.
       
    15 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    16 *     its contributors may be used to endorse or promote products derived
       
    17 *     from this software without specific prior written permission.
       
    18 *
       
    19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29 */
       
    30 
       
    31 #include <Browser_platform_variant.hrh>
       
    32 #include "config.h"
       
    33 #include "../../bidi.h"
       
    34 #include "brctl.h"
       
    35 #include "HistoryController.h"
       
    36 #include "PageView.h"
       
    37 #include "SettingsContainer.h"
       
    38 #include "WebFrame.h"
       
    39 #include "WebFrameBridge.h"
       
    40 #include "WebFrameView.h"
       
    41 #include "WebView.h"
       
    42 #include "WebTabbedNavigation.h"
       
    43 #include "WebChromeClient.h"
       
    44 #include "WebCoreGraphicsContext.h"
       
    45 #include "WebContextMenuClient.h"
       
    46 #include "WebEditorClient.h"
       
    47 #include "WebDragClient.h"
       
    48 #include "WebFrameLoaderClient.h"
       
    49 #include "WebInspectorClient.h"
       
    50 #include "WebFepTextEditor.h"
       
    51 #include "WebSurface.h"
       
    52 #include "WebCursor.h"
       
    53 #include "WebFormFill.h"
       
    54 #include "WebFormFillPopup.h"
       
    55 #include "WebToolBarInterface.h"
       
    56 #include "WebPointerEventHandler.h"
       
    57 #include "WebPageScrollHandler.h"
       
    58 #include "WebPopupDrawer.h"
       
    59 #include "PluginSkin.h"
       
    60 #include "PluginWin.h"
       
    61 #include "PluginPlayer.h"
       
    62 
       
    63 
       
    64 #include "Page.h"
       
    65 #include "Settings.h"
       
    66 #include "Frame.h"
       
    67 #include "FrameView.h"
       
    68 #include "FrameTree.h"
       
    69 #include "FrameLoader.h"
       
    70 #include "HistoryItem.h"
       
    71 #include "EventHandler.h"
       
    72 #include "ResourceRequest.h"
       
    73 #include "PlatformString.h"
       
    74 #include "SelectionController.h"
       
    75 #include "PlatformKeyboardEvent.h"
       
    76 #include "PlatformScrollbar.h"
       
    77 #include "DocumentLoader.h"
       
    78 #include "StaticObjectsContainer.h"
       
    79 #include "ToolBar.h"
       
    80 #include "Document.h"
       
    81 #include "FocusController.h"
       
    82 #include "WebUtil.h"
       
    83 #include "WidgetExtension.h"
       
    84 #include "Cache.h"
       
    85 #include "RenderWidget.h"
       
    86 
       
    87 #include <AknUtils.h>
       
    88 #include <CUserAgent.h>
       
    89 #include "WebPageZoomHandler.h"
       
    90 
       
    91 #include "PlatformFontCache.h"
       
    92 #include "WebPageFullScreenHandler.h"
       
    93 #include "eikon.hrh"
       
    94 #include "WebScrollbarDrawer.h"
       
    95 
       
    96 
       
    97 using namespace WebCore;
       
    98 
       
    99 const int KRepaintDelayLoading = 500*1000; // dont do repaints more often than this during loading (0.5s)
       
   100 const int KRepaintDelayComplete = 100*1000; // faster updates after load so dynamic scripts etc have better frame rate (0.1s)
       
   101 const int KNormalScrollRange = 60;
       
   102 
       
   103 const int KPanningStartSpeed = 30;
       
   104 const int KPanningStartTime = 900;
       
   105 const int KPanningPageScalerStart = 1300;
       
   106 const int KPanningMaxSpeed = 90;
       
   107 const int KPanningMaxTime = 3000;
       
   108 const int KAllowSelection = 1;
       
   109 
       
   110 const int KScalerVisibilityTime = 1100*1000; //1.1s
       
   111 
       
   112 const int KCursorUpdateFrquency = 20*1000; // 20ms
       
   113 const int KCursorInitialDelay = 200*1000;  // 200ms
       
   114 const TKeyEvent KNullKeyEvent = {0,0,0,0};
       
   115 const int KSmallPageScale = 13*13;    // if the area of page is less than 169% (130%*130%) of the viewport area, it's considered to be a small page
       
   116 const int KZoomLevelDelta = 10; //set 10% for each increasment
       
   117 
       
   118 const int KZoomLevelDefaultValue = 100;
       
   119 const int KZoomLevelMaxValue = 200;
       
   120 const int KZoomLevelMinValue = 10;
       
   121 
       
   122 const int KZoomBgRectColor = 209;
       
   123 const int KZoomDefaultLevel = 8; //100%
       
   124 const int defaultCacheCapacity = 256 * 1024;
       
   125 
       
   126 // LOCAL FUNCTION PROTOTYPES
       
   127 TInt doRepaintCb( TAny* ptr );
       
   128 TInt doFepCb( TAny* ptr );
       
   129 
       
   130 static WebFrame* incrementFrame(WebFrame* curr, bool forward, bool wrapFlag)
       
   131 {
       
   132     Frame* coreFrame = core(curr);
       
   133     return kit(forward
       
   134         ? coreFrame->tree()->traverseNextWithWrap(wrapFlag)
       
   135         : coreFrame->tree()->traversePreviousWithWrap(wrapFlag));
       
   136 }
       
   137 
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CWebKitView::NewL
       
   142 // Public Class Method
       
   143 // Two-phased constructor.
       
   144 // -----------------------------------------------------------------------------
       
   145 WebView* WebView::NewL(
       
   146                        CCoeControl& parent, CBrCtl* brctl )
       
   147 {
       
   148     WebView* self = new (ELeave) WebView( brctl );
       
   149 
       
   150     CleanupStack::PushL( self );
       
   151     self->ConstructL( parent );
       
   152     CleanupStack::Pop(); // self
       
   153 
       
   154     return self;
       
   155 }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CWebKitView::CWebKitView
       
   159 // Private Class Method
       
   160 // C++ default constructor can NOT contain any code, that might leave.
       
   161 // -----------------------------------------------------------------------------
       
   162 WebView::WebView( CBrCtl* brctl ) :
       
   163 m_brctl(brctl)
       
   164 , m_isEditable(false)
       
   165 , m_currentEventKey(KNullKeyEvent)
       
   166 , m_scrollingSpeed(KNormalScrollRange*KZoomLevelDefaultValue/100)
       
   167 , m_focusedElementType(TBrCtlDefs::EElementNone)
       
   168 , m_pageScaler(NULL)
       
   169 , m_pageScalerEnabled(false)
       
   170 , m_inFindState(false)
       
   171 , m_pageView(NULL)
       
   172 , m_savedCursorPosition(KInitialOffset, KInitialOffset)
       
   173 , m_findKeyword(NULL)
       
   174 , m_webFormFill(NULL)
       
   175 , m_fepTimer(0)
       
   176 , m_isClosing(false)
       
   177 , m_widgetextension(0)
       
   178 , m_userAgent(NULL)
       
   179 , m_pageZoomHandler(NULL)
       
   180 , m_currentZoomLevel(KZoomLevelDefaultValue)
       
   181 , m_lastZoomLevel(KZoomLevelMinValue)
       
   182 , m_maxZoomLevel(KZoomLevelMaxValue)
       
   183 , m_minZoomLevel(KZoomLevelMinValue)
       
   184 , m_defaultZoomLevel(KZoomLevelDefaultValue)
       
   185 , m_pageFullScreenHandler(NULL)
       
   186 , m_viewIsScrolling(false)
       
   187 , m_ptrbuffer(0)
       
   188 , m_pluginActivated(false)
       
   189 , m_showCursor(false)
       
   190 , m_allowRepaints(true)
       
   191 {
       
   192 }
       
   193 
       
   194 WebView::~WebView()
       
   195 {
       
   196     // the zoom handler is a client of WebView (also owned by
       
   197     // WebView--a circular dependency) so it must be deleted before
       
   198     // the WebView object is destroyed because in its destructor it
       
   199     // operates on the WebView object
       
   200     delete m_pageZoomHandler;
       
   201     m_pageZoomHandler = NULL;
       
   202 
       
   203     // prevent frameViews to access members when topView is
       
   204     // closing down.
       
   205     m_isClosing = true;
       
   206     m_page->setGroupName(String());
       
   207 
       
   208     if (m_fastScrollTimer)
       
   209         m_fastScrollTimer->Cancel();
       
   210     delete m_fastScrollTimer;
       
   211 
       
   212     delete [] m_ptrbuffer;
       
   213     delete m_repainttimer;
       
   214     delete m_webfeptexteditor;
       
   215     delete m_webcorecontext;
       
   216     delete m_bitmapdevice;
       
   217     delete m_page;
       
   218     delete m_pageScaler;
       
   219     delete m_pageView;
       
   220     delete m_webFormFill;
       
   221     delete m_toolbar;
       
   222     delete m_toolbarinterface;
       
   223     delete m_widgetextension;
       
   224     delete m_webpointerEventHandler;
       
   225     delete m_pageScrollHandler;
       
   226     delete m_pluginplayer;
       
   227     delete m_fepTimer;
       
   228     delete m_popupDrawer;
       
   229     delete m_tabbedNavigation;
       
   230     delete m_userAgent;
       
   231     delete m_pageFullScreenHandler;
       
   232 }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CWebKitView::ConstructL
       
   236 // Private Class Method
       
   237 // Symbian 2nd phase constructor can leave.
       
   238 // -----------------------------------------------------------------------------
       
   239 void WebView::ConstructL(
       
   240                          CCoeControl& parent)
       
   241 {
       
   242     SetContainerWindowL(parent);
       
   243 
       
   244     CCoeControl::MakeVisible(ETrue);
       
   245 
       
   246     WebFrameView *frameView = new WebFrameView();
       
   247     m_page = new Page(new WebChromeClient(this), new WebContextMenuClient(), new WebEditorClient(this), new WebDragClient(), new WebInspectorClient());
       
   248     m_page->backForwardList()->setCapacity(0);
       
   249     m_page->setGroupName("com.s60.browser");
       
   250     //
       
   251     WebCore::Settings* settings = m_page->settings();
       
   252     settings->setLoadsImagesAutomatically(true);
       
   253     settings->setJavaScriptEnabled(true);
       
   254 
       
   255     settings->setMinimumFontSize(7);
       
   256     settings->setMinimumLogicalFontSize(9);
       
   257     settings->setDefaultFontSize(12);
       
   258     settings->setDefaultFixedFontSize(12);
       
   259     settings->setPluginsEnabled(true);
       
   260     settings->setJavaScriptCanOpenWindowsAutomatically(true);
       
   261     settings->setPluginsEnabled(true);
       
   262 
       
   263     m_tabbedNavigation = new WebTabbedNavigation(this);
       
   264 
       
   265     WebFrameBridge* bridge = new WebFrameBridge();
       
   266     bridge->initMainFrameWithPage(m_page, "", frameView);
       
   267 
       
   268     // Create and offscreen device and context
       
   269     m_bitmapdevice = CFbsBitmapDevice::NewL( StaticObjectsContainer::instance()->webSurface()->offscreenBitmap() );
       
   270     m_webcorecontext = WebCoreGraphicsContext::NewL( m_bitmapdevice, StaticObjectsContainer::instance()->webSurface()->offscreenBitmap(), mainFrame()->frameView());
       
   271     //
       
   272     m_repainttimer = CPeriodic::NewL(CActive::EPriorityHigh);
       
   273 
       
   274     m_webfeptexteditor = new CWebFepTextEditor(this);
       
   275 
       
   276     m_fastScrollTimer = CPeriodic::NewL(CActive::EPriorityHigh);
       
   277 
       
   278     m_dirtyZoomMode = false;
       
   279     m_currentZoomLevel = StaticObjectsContainer::instance()->fontCache()->fontZoomFactor();
       
   280     m_startZoomLevel = m_currentZoomLevel;
       
   281 
       
   282     m_pageZoomHandler = WebPageZoomHandler::NewL( *this );
       
   283     if ( brCtl()->capabilities()&TBrCtlDefs::ECapabilityFitToScreen ) {
       
   284         m_minZoomLevel = (KZoomLevelDefaultValue / m_pageZoomHandler->stepSize())*m_pageZoomHandler->stepSize();
       
   285         //could happen only if m_minZoomLevel < stepSize
       
   286         if (!m_minZoomLevel) m_minZoomLevel = m_pageZoomHandler->stepSize();
       
   287     }
       
   288 
       
   289     // construct the zoom array from the default level
       
   290     m_zoomLevelArray.Append(KZoomLevelDefaultValue);
       
   291     TInt toAddZoomLevel = KZoomLevelDefaultValue + KZoomLevelDefaultValue*KZoomLevelDelta/100;
       
   292     while (toAddZoomLevel <= m_maxZoomLevel)
       
   293         {
       
   294         // add the zoom level after default one
       
   295         m_zoomLevelArray.Append(toAddZoomLevel);
       
   296         toAddZoomLevel = toAddZoomLevel + toAddZoomLevel*KZoomLevelDelta/100;
       
   297         }
       
   298 
       
   299     // now go the minimum one
       
   300     toAddZoomLevel = KZoomLevelDefaultValue - KZoomLevelDefaultValue*KZoomLevelDelta/100;
       
   301     while (toAddZoomLevel >= m_minZoomLevel)
       
   302         {
       
   303         //add the zoom level after default one
       
   304         m_zoomLevelArray.Insert(toAddZoomLevel, 0);
       
   305         toAddZoomLevel = toAddZoomLevel - toAddZoomLevel*KZoomLevelDelta/100;
       
   306         }
       
   307 
       
   308     m_pageFullScreenHandler = WebPageFullScreenHandler::NewL( *this );
       
   309 
       
   310     if ( m_brctl->capabilities() & TBrCtlDefs::ECapabilityWebKitLite ) {
       
   311         m_pageScalerEnabled = false;
       
   312     }
       
   313     else  {
       
   314         initializePageScalerL();
       
   315         m_pageScalerEnabled = true;
       
   316     }
       
   317     if (m_brctl->capabilities() & TBrCtlDefs::ECapabilityAutoFormFill) {
       
   318         m_webFormFill = new WebFormFill(this);
       
   319     }
       
   320 
       
   321     // Create the PointerEventHandler
       
   322     m_ptrbuffer = new TPoint[256];
       
   323     m_webpointerEventHandler = WebPointerEventHandler::NewL(this);
       
   324 
       
   325     // Create the ScrollHandler
       
   326     m_pageScrollHandler = WebPageScrollHandler::NewL( *this );
       
   327     if (AknLayoutUtils::PenEnabled()) {
       
   328         DrawableWindow()->SetPointerGrab(ETrue);
       
   329         EnableDragEvents();
       
   330     }
       
   331 
       
   332     CUserAgent* usrAgnt = CUserAgent::NewL();
       
   333     CleanupStack::PushL( usrAgnt );
       
   334     HBufC8* userAgent8 = usrAgnt->UserAgentL();
       
   335     CleanupStack::PushL( userAgent8 );
       
   336     m_userAgent = HBufC::NewL(userAgent8->Length());
       
   337     m_userAgent->Des().Copy(userAgent8->Des());
       
   338     CleanupStack::PopAndDestroy(2); // userAgent8, usrAgnt
       
   339 
       
   340     MakeViewVisible(ETrue);
       
   341     m_isPluginsVisible=ETrue;
       
   342     CCoeControl::SetFocus(ETrue);
       
   343 
       
   344     cache()->setCapacities(0, 0, defaultCacheCapacity);
       
   345 }
       
   346 
       
   347 void WebView::initializePageScalerL()
       
   348 {
       
   349     TBool lowQuality = !( m_brctl->capabilities() & TBrCtlDefs::ECapabilityGraphicalHistory );
       
   350     m_pageScaler = CPageScaler::NewL( *this, EColor64K, lowQuality );
       
   351     m_pageScaler->SetVisible( EFalse );
       
   352     //update the minimap support info from page scaler
       
   353     m_pageScalerEnabled = (m_pageScaler->HasOverlaySupport());
       
   354 }
       
   355 
       
   356 
       
   357 void WebView::fepTimerFired(Timer<WebView>*)
       
   358 {
       
   359     CCoeEnv::Static()->SimulateKeyEventL(m_keyevent, m_eventcode);
       
   360 }
       
   361 
       
   362 //-------------------------------------------------------------------------------
       
   363 // Draw ( from CCoeControl )
       
   364 // BitBlts the offscreen bitmap to the GraphicsContext
       
   365 //-------------------------------------------------------------------------------
       
   366 void WebView::Draw(
       
   367                    const TRect& rect ) const
       
   368 {
       
   369     if (m_pluginFullscreen) return;
       
   370 
       
   371     CWindowGc& gc = SystemGc();
       
   372     CEikBorderedControl::Draw( rect );
       
   373 
       
   374     // put offscreen bitmap onto the screen
       
   375 
       
   376     if ( !m_dirtyZoomMode ) {
       
   377         StaticObjectsContainer::instance()->webSurface()->flip( Rect().iTl, gc );
       
   378         if (m_widgetextension){
       
   379             m_widgetextension->DrawTransition(gc,StaticObjectsContainer::instance()->webSurface()->offscreenBitmap());
       
   380         }
       
   381     }
       
   382     else {
       
   383         gc.DrawBitmap( m_destRectForZooming, StaticObjectsContainer::instance()->webSurface()->offscreenBitmap(), m_srcRectForZooming );
       
   384 
       
   385         if ( m_startZoomLevel > m_currentZoomLevel) {
       
   386 
       
   387             TRect rectLeft( TPoint( rect.iTl.iX + m_destRectForZooming.Width() - 2, rect.iTl.iY ),
       
   388                             TPoint( rect.iBr ));
       
   389 
       
   390             TRect rectBottom( TPoint( rect.iTl.iX, rect.iTl.iY + m_destRectForZooming.Height() - 2 ),
       
   391                               TPoint( rect.iBr.iX + m_destRectForZooming.Width(), rect.iBr.iY ));
       
   392 
       
   393 
       
   394             const TRgb colorTest(KZoomBgRectColor,KZoomBgRectColor,KZoomBgRectColor);
       
   395             gc.SetPenColor(colorTest);
       
   396             gc.SetBrushStyle( CGraphicsContext::EForwardDiagonalHatchBrush );
       
   397             gc.SetBrushColor(colorTest);
       
   398             gc.DrawRect( rectLeft );
       
   399             gc.DrawRect( rectBottom );
       
   400 
       
   401         }
       
   402 
       
   403     }
       
   404 
       
   405     if (m_pageScalerEnabled && m_pageScaler->Visible()) {
       
   406         m_pageScaler->Draw( gc, rect );
       
   407     }
       
   408 
       
   409     if (m_toolbar) {
       
   410         m_toolbar->Draw();
       
   411     }
       
   412 
       
   413     if (m_popupDrawer)
       
   414     {
       
   415         m_popupDrawer->drawPopup();
       
   416     }
       
   417 
       
   418     if (m_widgetextension){
       
   419         m_widgetextension->DrawTransition(gc,StaticObjectsContainer::instance()->webSurface()->offscreenBitmap());
       
   420     }
       
   421 
       
   422 
       
   423 }
       
   424 
       
   425 
       
   426 WebCore::Page* WebView::page()
       
   427 {
       
   428     return m_page;
       
   429 }
       
   430 
       
   431 
       
   432 WebFrame* WebView::mainFrame()
       
   433 {
       
   434     if (!m_page)
       
   435         return NULL;
       
   436     return kit(m_page->mainFrame());
       
   437 }
       
   438 
       
   439 //-------------------------------------------------------------------------------
       
   440 // SyncRepaint
       
   441 // Repaint the given rectangle synchronously
       
   442 //-------------------------------------------------------------------------------
       
   443 void WebView::syncRepaint(
       
   444                           const TRect& rect)
       
   445 {
       
   446     m_repaints.AddRect( rect );
       
   447     syncRepaint();
       
   448 }
       
   449 
       
   450 void WebView::MakeVisible(TBool visible)
       
   451 {
       
   452     if (visible == IsVisible()) return;
       
   453     CCoeControl::MakeVisible(visible);
       
   454     MakeViewVisible(visible);
       
   455 }
       
   456 
       
   457 void WebView::MakeViewVisible(TBool visible)
       
   458 {
       
   459     if ( visible ) {
       
   460         // resize the offscreen surface, this is needed
       
   461         // because the shared surface is changed.
       
   462         StaticObjectsContainer::instance()->webSurface()->setView( this );
       
   463         m_bitmapdevice->Resize( m_offscreenrect.Size() );
       
   464         m_webcorecontext->resized();
       
   465     }
       
   466     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   467     if (cursor) {
       
   468         if (visible) {
       
   469             cursor->setCurrentView(*this);
       
   470             //Reset the iFocusedElementType to be the same as before the second window is opened.
       
   471             cursor->setPosition(m_savedCursorPosition);
       
   472             cursor->updatePositionAndElemType(m_savedCursorPosition);
       
   473         } else
       
   474             m_savedCursorPosition = cursor->position();
       
   475         cursor->cursorUpdate(visible & !AknLayoutUtils::PenEnabled());
       
   476     }
       
   477     Frame* f = m_page->mainFrame();
       
   478     while ( f ) {
       
   479         PassRefPtr<HTMLCollection> objects = f->document()->objects();
       
   480         for (Node* n = objects->firstItem(); n; n = objects->nextItem()) {
       
   481             MWebCoreObjectWidget* w = widget(n);
       
   482             if (w)
       
   483                 w->makeVisible(visible);
       
   484         }
       
   485         PassRefPtr<HTMLCollection> embeds = f->document()->embeds();
       
   486         for (Node* n = embeds->firstItem(); n; n = embeds->nextItem()) {
       
   487             MWebCoreObjectWidget* w = widget(n);
       
   488             if (w)
       
   489                 w->makeVisible(visible);
       
   490         }
       
   491         f = f->tree()->traverseNext();
       
   492     }
       
   493     if ( m_pageScaler )  {
       
   494         m_pageScaler->SetContainerRect(TRect(Rect().Size()));
       
   495     }
       
   496     if ( m_webFormFillPopup ){
       
   497         // don't show the popup if view's visibility changes.
       
   498         m_webFormFillPopup->MakeVisible(EFalse);
       
   499     }
       
   500 
       
   501     if ( visible ) {
       
   502       clearOffScreenBitmap();
       
   503       syncRepaint( mainFrame()->frameView()->visibleRect() );
       
   504     }
       
   505 
       
   506 }
       
   507 
       
   508 
       
   509 
       
   510 void WebView::doLayout()
       
   511 {
       
   512 
       
   513     int zoomLevel = m_currentZoomLevel;
       
   514     if(!(   m_widgetextension && m_widgetextension->IsWidgetPublising())) {
       
   515         zoomLevelChanged( KZoomLevelDefaultValue );
       
   516     }
       
   517     Frame* f = m_page->mainFrame();
       
   518 
       
   519     while ( f ) {
       
   520         f->sendResizeEvent();
       
   521         f->view()->layout();
       
   522         f = f->tree()->traverseNext();
       
   523     }
       
   524         // maybe it got bigger in layout?
       
   525     TRect rect(m_repaints.BoundingRect());
       
   526 
       
   527     TPoint p( mainFrame()->frameView()->contentPos());
       
   528 
       
   529     rect.Move(-p);
       
   530 
       
   531       // draw to back buffer
       
   532 
       
   533    
       
   534     if(!(   m_widgetextension && m_widgetextension->IsWidgetPublising())) {
       
   535         mainFrame()->frameView()->draw( *m_webcorecontext, rect );
       
   536         if ( zoomLevel < m_minZoomLevel ) zoomLevel = m_minZoomLevel;
       
   537         zoomLevelChanged( zoomLevel );
       
   538     }
       
   539 }
       
   540 //-------------------------------------------------------------------------------
       
   541 // SyncRepaint
       
   542 // Repaint the current repaint region synchronously and clear it
       
   543 //-------------------------------------------------------------------------------
       
   544 void WebView::syncRepaint()
       
   545 {
       
   546     if (m_pageScaler && m_pageScaler->FullScreenMode()) {
       
   547       ScaledPageChanged(m_pageScaler->Rect(), EFalse, EFalse);
       
   548       return;
       
   549     }
       
   550 
       
   551     if (!IsVisible()) {
       
   552       return;
       
   553     }
       
   554 
       
   555     if (isPluginFullscreen()) return;
       
   556     CFbsBitGc& gc = m_webcorecontext->gc();
       
   557     gc.Reset();
       
   558 
       
   559     TRect viewRect( mainFrame()->frameView()->visibleRect() );
       
   560     TPoint p( mainFrame()->frameView()->contentPos());
       
   561     Frame* f = m_page->mainFrame();
       
   562     bool layoutPending = false;
       
   563     while (f && !layoutPending) {
       
   564         layoutPending = f->view()->layoutPending();
       
   565         f = f->tree()->traverseNext();
       
   566     }
       
   567     if (!layoutPending) {
       
   568         bool needsDraw = false;
       
   569         m_repaints.Tidy();
       
   570         for (int i=0; i<m_repaints.Count(); ++i) {
       
   571             TRect r = m_repaints[i];
       
   572             if (r.Intersects(viewRect)) {
       
   573                 r.Move(-p);
       
   574                 mainFrame()->frameView()->draw( *m_webcorecontext, r );
       
   575                 needsDraw = true;
       
   576             }
       
   577         }
       
   578 
       
   579         if (needsDraw){
       
   580             // blit the whole backbuffer to the screen (in Draw())
       
   581             // This could be optimized further to blit only the affected area.
       
   582             // Not a big win, scrolling is the most critical case and there you
       
   583             // need to blit the whole buffer anyway.
       
   584             m_brctl->DrawNow();
       
   585         }
       
   586 
       
   587         // dont do next async repaint until KRepaintDelay
       
   588         m_repaints.Clear();
       
   589     }
       
   590     m_repainttimer->Cancel();
       
   591     // tot:fixme TBool complete = iWebkitControl->IsProgressComplete(); && CImageRendererFactory::Instance()->DecodeCount()==0;
       
   592 
       
   593     TBool complete = ETrue;
       
   594     if ( !m_pageZoomHandler->isActive() && m_allowRepaints){
       
   595         m_repainttimer->Start(complete ? KRepaintDelayComplete : KRepaintDelayLoading,
       
   596         0, TCallBack( &doRepaintCb, this ) );
       
   597     }
       
   598     // need to draw formfill popup here.
       
   599     if (m_webFormFillPopup && m_webFormFillPopup->IsVisible()) {
       
   600         m_webFormFillPopup->reDraw();
       
   601     }
       
   602 }
       
   603 
       
   604 //-------------------------------------------------------------------------------
       
   605 // DoRepaintCb
       
   606 // C-style TCallback function
       
   607 //-------------------------------------------------------------------------------
       
   608 TInt doRepaintCb(
       
   609                  TAny* ptr )
       
   610 {
       
   611     static_cast<WebView*>(ptr)->doRepaint();
       
   612     return EFalse;
       
   613 }
       
   614 
       
   615 //-------------------------------------------------------------------------------
       
   616 // DoRepaint
       
   617 // Perform a scheduled repaint
       
   618 //-------------------------------------------------------------------------------
       
   619 void WebView::doRepaint()
       
   620 {
       
   621     // the timer must always be canceled here!
       
   622       m_repainttimer->Cancel();
       
   623 
       
   624     // only repaint when this view owns the surface
       
   625       if ( StaticObjectsContainer::instance()->webSurface()->topView() != this ) return;
       
   626 
       
   627     // anything to do?
       
   628       if ( !m_repaints.IsEmpty() ) {
       
   629           syncRepaint( );
       
   630       }
       
   631 }
       
   632 
       
   633 //-------------------------------------------------------------------------------
       
   634 // CollectOffscreenbitmap
       
   635 // Get offscreen bitmap
       
   636 //-------------------------------------------------------------------------------
       
   637 void WebView::collectOffscreenbitmapL(CFbsBitmap& snapshot)
       
   638 {
       
   639    
       
   640     (snapshot).Create(m_brctl->Size(), StaticObjectsContainer::instance()->webSurface()->displayMode());
       
   641 
       
   642     CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( &snapshot);
       
   643     CleanupStack::PushL(device);
       
   644 
       
   645     WebCoreGraphicsContext* gc = WebCoreGraphicsContext::NewL( device, &snapshot, mainFrame()->frameView());
       
   646     CleanupStack::PushL(gc);
       
   647 
       
   648     mainFrame()->frameView()->draw( *gc, mainFrame()->frameView()->visibleRect() );
       
   649 
       
   650     CleanupStack::PopAndDestroy(2);
       
   651 
       
   652 }
       
   653 
       
   654 //-------------------------------------------------------------------------------
       
   655 // ScheduleRepaint
       
   656 // Schedule an asynchronous repaint
       
   657 //-------------------------------------------------------------------------------
       
   658 void WebView::scheduleRepaint(
       
   659                               const TRect& rect )
       
   660 {
       
   661     m_repaints.AddRect( rect );
       
   662     if(   m_widgetextension && m_widgetextension->IsWidgetPublising())
       
   663         {
       
   664 #ifdef BRDO_WRT_HS_FF
       
   665         // Draw the miniview
       
   666         m_brctl->brCtlLayoutObserver()->NotifyLayoutChange(EOriginTopLeft);
       
   667 #endif
       
   668         }
       
   669     // if we are active, we'll repaint when timer fires
       
   670     if( !m_repainttimer->IsActive() && !m_pageZoomHandler->isActive() && 
       
   671          m_allowRepaints) {
       
   672         // no timer yet, repaint immediatly (but asynchronously)
       
   673         m_repainttimer->Start( 0, 0, TCallBack( &doRepaintCb, this ) );
       
   674     }
       
   675 }
       
   676 
       
   677 void WebView::pageLoadFinished()
       
   678 {
       
   679 
       
   680     if (m_brctl->settings() && m_brctl->settings()->getTabbedNavigation()) {
       
   681         m_tabbedNavigation->initializeForPage();
       
   682     }
       
   683     else {
       
   684 
       
   685         // Temp solution to fix a problem with scrolling large pages:
       
   686         // if user starts scrolling while loading a page - at the end of the load we should not restore
       
   687         // the content position from the history controller
       
   688         // As of now scroll events are not passed to WebCore and this will be changed in future
       
   689         // then this code should be replaces with the commented one below
       
   690 
       
   691         TPoint ptInit(0,0);
       
   692         TPoint ptFromHistory = m_brctl->historyHandler()->historyController()->currentEntryPosition();
       
   693         TPoint ptCurr = mainFrame()->frameView()->contentPos();
       
   694 
       
   695         if ( ptCurr != ptFromHistory ) {
       
   696             if ( ptInit == ptCurr ) {
       
   697                 mainFrame()->frameView()->scrollTo(ptFromHistory);
       
   698             }
       
   699             else {
       
   700                 m_brctl->historyHandler()->historyController()->updateCurrentEntryPositionIfNeeded();
       
   701             }
       
   702         }
       
   703         /*
       
   704         if ( !core(mainFrame())->view()->wasScrolledByUser())
       
   705             mainFrame()->frameView()->scrollTo(m_brctl->historyHandler()->historyController()->currentEntryPosition());*/
       
   706 
       
   707     }
       
   708 
       
   709     if (FrameLoadTypeStandard == core( mainFrame())->loader()->loadType()){
       
   710         if (m_brctl->capabilities()&TBrCtlDefs::ECapabilityFitToScreen){
       
   711             updateMinZoomLevel( mainFrame()->frameView()->contentSize());
       
   712         }
       
   713     }
       
   714 
       
   715     setHistoryLoad(false);
       
   716     setRedirectWithLockedHistory(false);
       
   717 
       
   718     int zoomLevel = m_brctl->historyHandler()->historyController()->currentEntryZoomLevel();
       
   719     if ( zoomLevel != m_currentZoomLevel) {
       
   720         m_brctl->historyHandler()->historyController()->updateCurrentEntryZoomLevelIfNeeded();
       
   721     }
       
   722     if ( m_pageScaler ) {
       
   723         m_pageScaler->DocumentCompleted();
       
   724         TRAP_IGNORE(m_pageScaler->DocumentChangedL());
       
   725     }
       
   726 
       
   727     Node* focusedNode = NULL;
       
   728     Frame* focusedFrame = page()->focusController()->focusedFrame();
       
   729 
       
   730     if (focusedFrame)
       
   731         {
       
   732         focusedNode = focusedFrame->document()->focusedNode();
       
   733 
       
   734         if (focusedNode) { // based on focused element
       
   735             m_focusedElementType = nodeTypeB(focusedNode, focusedFrame);
       
   736         }
       
   737         else {
       
   738             m_focusedElementType = TBrCtlDefs::EElementNone;
       
   739         }
       
   740     }
       
   741     else {
       
   742         m_focusedElementType = TBrCtlDefs::EElementNone;
       
   743     }
       
   744     m_brctl->updateDefaultSoftkeys();
       
   745 }
       
   746 
       
   747 void WebView::updatePageScaler()
       
   748 {
       
   749     if (m_brctl->capabilities() & TBrCtlDefs::ECapabilityGraphicalPage) {
       
   750         TRAP_IGNORE(if (m_pageScaler) m_pageScaler->DocumentChangedL());
       
   751     }
       
   752 }
       
   753 
       
   754 void WebView::openUrl(const TDesC& url)
       
   755 {
       
   756     mainFrame()->loadRequest(WebCore::ResourceRequest(url, true));
       
   757 }
       
   758 
       
   759 WebCore::DOMDocument* WebView::mainFrameDocument()
       
   760 {
       
   761     return mainFrame()->DOMDocument();
       
   762 }
       
   763 
       
   764 TBool WebView::shouldClose()
       
   765 {
       
   766     Frame* coreFrame = core(mainFrame());
       
   767     if (!coreFrame)
       
   768         return ETrue;
       
   769     return coreFrame->shouldClose();
       
   770 }
       
   771 
       
   772 TBool WebView::isLoading()
       
   773 {
       
   774     return m_page->mainFrame()->loader()->activeDocumentLoader()->isLoading();
       
   775 }
       
   776 
       
   777 TInt WebView::CountComponentControls() const
       
   778 {
       
   779     int count = (m_webFormFillPopup && m_webFormFillPopup->IsVisible()) ? 1 : 0;
       
   780     return count;
       
   781 }
       
   782 
       
   783 CCoeControl* WebView::ComponentControl(TInt aIndex) const
       
   784 {
       
   785     CCoeControl* rv = NULL;
       
   786 
       
   787     if ( aIndex == 0)
       
   788         if ( m_webFormFillPopup && m_webFormFillPopup->IsVisible()) rv = m_webFormFillPopup;
       
   789 
       
   790     return rv;
       
   791 }
       
   792 
       
   793 TKeyResponse WebView::OfferKeyEventL(const TKeyEvent& keyevent, TEventCode eventcode )
       
   794 {
       
   795     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
   796     //hijack
       
   797     if (isSynchRequestPending()) {
       
   798         return EKeyWasNotConsumed;
       
   799     }
       
   800     if (m_toolbar)
       
   801         return m_toolbar->HandleOfferKeyEventL(keyevent, eventcode);
       
   802 
       
   803     if (m_popupDrawer)
       
   804         return m_popupDrawer->handleOfferKeyEventL(keyevent, eventcode );
       
   805 
       
   806     if ( m_webFormFillPopup && m_webFormFillPopup->IsVisible() && AknLayoutUtils::PenEnabled() ) {
       
   807 	    if (EKeyWasConsumed == m_webFormFillPopup->HandleKeyEventL(keyevent, eventcode)) {
       
   808             return EKeyWasConsumed;
       
   809 	        }
       
   810     }
       
   811 
       
   812     bool consumed = false;
       
   813     Frame* coreFrame = core(mainFrame());
       
   814     if (!coreFrame)
       
   815         return EKeyWasNotConsumed;
       
   816 
       
   817     coreFrame = page()->focusController()->focusedOrMainFrame();
       
   818 
       
   819     // edit events
       
   820     if (m_isEditable) {
       
   821         consumed = page()->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(PlatformKeyboardEvent(keyevent,eventcode));
       
   822         // exit input on up/down key
       
   823         // EXCEPT on touch-enabled devices. We'll just consume in that case
       
   824             if ( !consumed
       
   825                  && (    keyevent.iCode == EKeyUpArrow         // North
       
   826                       || keyevent.iCode == EKeyRightUpArrow    // Northeast
       
   827                       || keyevent.iCode == EStdKeyDevice11     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   828                       || keyevent.iCode == EKeyRightArrow      // East
       
   829                       || keyevent.iCode == EKeyRightDownArrow  // Southeast
       
   830                       || keyevent.iCode == EStdKeyDevice12     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   831                       || keyevent.iCode == EKeyDownArrow       // South
       
   832                       || keyevent.iCode == EKeyLeftDownArrow   // Southwest
       
   833                       || keyevent.iCode == EStdKeyDevice13     //   : Extra KeyEvent supports diagonal event simulator wedge
       
   834                       || keyevent.iCode == EKeyLeftArrow       // West
       
   835                       || keyevent.iCode == EKeyLeftUpArrow     // Northwest
       
   836                       || keyevent.iCode == EStdKeyDevice10 ) ) //   : Extra KeyEvent supports diagonal event simulator wedge
       
   837                 {
       
   838                 if (m_webfeptexteditor->validateTextFormat() ) {
       
   839                     setFocusNone();
       
   840                 } else {
       
   841                     consumed = true;
       
   842                 }
       
   843             }
       
   844     }
       
   845 
       
   846     // scroll events
       
   847     if (!consumed) {
       
   848         switch( eventcode ) {
       
   849         case EEventKeyDown:
       
   850             m_currentEventKey = keyevent;
       
   851             //page()->mainFrame()->setFocusedNodeIfNeeded();
       
   852             //coreFrame->eventHandler()->mousePressNode()->focus();
       
   853 
       
   854             break;
       
   855         case EEventKey:
       
   856             if (keyevent.iScanCode != m_currentEventKey.iScanCode ) return EKeyWasNotConsumed;
       
   857             //
       
   858             m_currentEventKey = keyevent;
       
   859             if (keyevent.iCode == EKeyDevice3) {
       
   860                 // pass it to webcore
       
   861                 TPointerEvent event;
       
   862                 event.iPosition = StaticObjectsContainer::instance()->webCursor()->position();
       
   863                 event.iModifiers = 0;
       
   864                 event.iType = TPointerEvent::EButton1Down ;
       
   865                 coreFrame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
       
   866 
       
   867                 // mimic ccb's behavior of onFocus
       
   868                 Node* node = page()->focusController()->focusedOrMainFrame()->eventHandler()->mousePressNode();
       
   869                 for (Node* n = node; n; n = n->parentNode()) {
       
   870                     if ( n->isFocusable() ) {
       
   871                         page()->focusController()->setFocusedNode(n, page()->focusController()->focusedOrMainFrame());
       
   872                     }
       
   873                 }
       
   874 
       
   875                 // Toolbar is activated on long key press only if the element
       
   876                 // type is EElementNone during EEventKeyDown and EEventKey.
       
   877                 // This prevents toolbar from popping up in DHTML pages. Also,
       
   878                 // toolbar is activated when the user is not in fast scroll
       
   879                 // mode, or in page overview mode, or on wml page.
       
   880                 if ( ( m_focusedElementType == TBrCtlDefs::EElementNone ||
       
   881                        m_focusedElementType == TBrCtlDefs::EElementBrokenImage ) &&
       
   882                        keyevent.iRepeats && !m_brctl->wmlMode() )
       
   883                     {
       
   884                     launchToolBarL();
       
   885                     }
       
   886                 consumed = true;
       
   887             } else if (    keyevent.iCode == EKeyUpArrow              // North
       
   888                         || keyevent.iCode == EKeyRightUpArrow         // Northeast
       
   889                         || keyevent.iCode == EStdKeyDevice11          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   890                         || keyevent.iCode == EKeyRightArrow           // East
       
   891                         || keyevent.iCode == EKeyRightDownArrow       // Southeast
       
   892                         || keyevent.iCode == EStdKeyDevice12          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   893                         || keyevent.iCode == EKeyDownArrow            // South
       
   894                         || keyevent.iCode == EKeyLeftDownArrow        // Southwest
       
   895                         || keyevent.iCode == EStdKeyDevice13          //   : Extra KeyEvent supports diagonal event simulator wedge
       
   896                         || keyevent.iCode == EKeyLeftArrow            // West
       
   897                         || keyevent.iCode == EKeyLeftUpArrow          // Northwest
       
   898                         || keyevent.iCode == EStdKeyDevice10 )        //   : Extra KeyEvent supports diagonal event simulator wedge
       
   899             {
       
   900                 if (m_brctl->settings()->getTabbedNavigation()) {
       
   901                     int horizontal = 0;
       
   902                     int vertical = 0;
       
   903                     switch(keyevent.iCode)
       
   904                     {
       
   905                         case EKeyUpArrow:             // North
       
   906                             vertical = -1;
       
   907                             break;
       
   908 
       
   909                         case EKeyRightUpArrow:        // Northeast
       
   910                         case EStdKeyDevice11:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   911                             vertical   = -1;
       
   912                             horizontal = +1;
       
   913                             break;
       
   914 
       
   915                         case EKeyRightArrow:          // East
       
   916                             horizontal = +1;
       
   917                             break;
       
   918 
       
   919                         case EKeyRightDownArrow:      // Southeast
       
   920                         case EStdKeyDevice12:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   921                             vertical   = +1;
       
   922                             horizontal = +1;
       
   923                             break;
       
   924 
       
   925                         case EKeyDownArrow:           // South
       
   926                             vertical   = +1;
       
   927                             break;
       
   928 
       
   929                         case EKeyLeftDownArrow:       // Southwest
       
   930                         case EStdKeyDevice13:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   931                             vertical   = +1;
       
   932                             horizontal = -1;
       
   933                             break;
       
   934 
       
   935                         case EKeyLeftArrow:           // West
       
   936                             horizontal = -1;
       
   937                             break;
       
   938 
       
   939                         case EKeyLeftUpArrow:         // Northwest
       
   940                         case EStdKeyDevice10:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   941                             vertical   = -1;
       
   942                             horizontal = -1;
       
   943                             break;
       
   944 
       
   945                         default:                      // (Should never get here)
       
   946                             break;
       
   947 
       
   948                     }
       
   949                     
       
   950                    	consumed = m_tabbedNavigation->navigate(horizontal, vertical);
       
   951                 }
       
   952                 else {
       
   953                     // start fast scrolling
       
   954 					m_showCursor = true;
       
   955                     if (!cursor->isVisible()) {
       
   956                         cursor->cursorUpdate(true);
       
   957                     }
       
   958                     bool fastscroll(m_fastScrollTimer->IsActive());
       
   959                     m_savedPosition = mainFrame()->frameView()->contentPos();
       
   960                     cursor->scrollAndMoveCursor(keyevent.iCode, m_scrollingSpeed, fastscroll);
       
   961                     if (!fastscroll) {
       
   962                         m_fastScrollTimer->Start(KCursorInitialDelay,KCursorUpdateFrquency,TCallBack(&scrollTimerCb,this));
       
   963                         m_scrollingStartTime.HomeTime();
       
   964                     }
       
   965                     // and minimap comes on
       
   966                     int scrollingTime = millisecondsScrolled();
       
   967                     if (!AknLayoutUtils::PenEnabled() && m_pageScalerEnabled && m_pageScaler && !isSmallPage() &&
       
   968                         m_brctl->settings()->brctlSetting(TBrCtlDefs::ESettingsPageOverview) &&
       
   969                         (scrollingTime > KPanningPageScalerStart || m_pageScaler->Visible())) {
       
   970                         m_pageScaler->SetVisibleUntil(KScalerVisibilityTime);
       
   971 					}
       
   972                     //
       
   973                     if (!fastscroll) {
       
   974                       TPointerEvent event;
       
   975                       event.iPosition = cursor->position();
       
   976                       event.iModifiers = 0;
       
   977                       event.iType = TPointerEvent::EMove;
       
   978                       coreFrame->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event));
       
   979                     }
       
   980                     consumed = true;
       
   981                 } // if (m_brctl->settings()->getTabbedNavigation()
       
   982             } else {
       
   983                 // activate hovered input element by just start typing
       
   984                 if (m_focusedElementType == TBrCtlDefs::EElementInputBox || m_focusedElementType == TBrCtlDefs::EElementSelectBox
       
   985                     || m_focusedElementType == TBrCtlDefs::EElementSelectMultiBox || m_focusedElementType == TBrCtlDefs::EElementTextAreaBox) {
       
   986                     TPointerEvent event;
       
   987                     event.iModifiers = 0;
       
   988                     event.iPosition = cursor->position();
       
   989                     event.iType = TPointerEvent::EButton1Down ;
       
   990                     coreFrame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
       
   991                     event.iType = TPointerEvent::EButton1Up;
       
   992                     coreFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
       
   993 
       
   994 
       
   995                     if (m_focusedElementType == TBrCtlDefs::EElementInputBox || m_focusedElementType == TBrCtlDefs::EElementTextAreaBox) {
       
   996                         if (!m_fepTimer)
       
   997                             m_fepTimer = new WebCore::Timer<WebView>(this, &WebView::fepTimerFired);
       
   998 
       
   999                         m_fepTimer->startOneShot(0.2f);
       
  1000                         setEditable(true);
       
  1001                     }
       
  1002                     m_keyevent = keyevent;
       
  1003                     m_eventcode = eventcode;
       
  1004 
       
  1005                     consumed = true;
       
  1006             }
       
  1007             }
       
  1008             break;
       
  1009         case EEventKeyUp:
       
  1010             m_fastScrollTimer->Cancel();
       
  1011             m_scrollingSpeed = KNormalScrollRange*100/scalingFactor();
       
  1012 
       
  1013             if (viewIsFastScrolling()) {
       
  1014 	      setViewIsFastScrolling(false);
       
  1015               toggleRepaintTimer(true);
       
  1016               if (AknLayoutUtils::PenEnabled() && !inPageViewMode()) {
       
  1017                   m_pageScrollHandler->scrollbarDrawer()->fadeScrollbar();
       
  1018               }
       
  1019             }
       
  1020             m_currentEventKey = KNullKeyEvent;
       
  1021             if ( (keyevent.iScanCode == EStdKeyDevice3) || (keyevent.iScanCode == EStdKeyEnter) ){
       
  1022                 // pass it to webcore
       
  1023                 TPointerEvent event;
       
  1024                 if (m_focusedElementType == TBrCtlDefs::EElementInputBox || 
       
  1025                         m_focusedElementType == TBrCtlDefs::EElementTextAreaBox)
       
  1026                     {
       
  1027                     setEditable(true);
       
  1028                     }
       
  1029                 event.iPosition = cursor->position();
       
  1030                 event.iType = TPointerEvent::EButton1Up;
       
  1031                 coreFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
       
  1032                 consumed = true;
       
  1033             }
       
  1034             break;
       
  1035         }
       
  1036     }
       
  1037 
       
  1038     // keyevents
       
  1039     if (!consumed) {
       
  1040         consumed = coreFrame->eventHandler()->keyEvent(PlatformKeyboardEvent(keyevent,eventcode));
       
  1041         if (!consumed && eventcode == EEventKey && (m_brctl->capabilities() & TBrCtlDefs::ECapabilityAccessKeys)) {
       
  1042             TKeyEvent ke = keyevent;
       
  1043             TChar c(ke.iCode);
       
  1044             // Not consumed by WebCore, is alphanumeric and does not have any modifier
       
  1045             if (c.IsAlphaDigit() && !(ke.iModifiers & (EModifierCtrl | EModifierAlt | EModifierShift))) {
       
  1046                 ke.iModifiers = EModifierCtrl;
       
  1047                 coreFrame->eventHandler()->keyEvent(PlatformKeyboardEvent(ke,EEventKeyDown));
       
  1048                 consumed = true;
       
  1049             }
       
  1050         }
       
  1051     }
       
  1052 
       
  1053     //setEditable();
       
  1054 
       
  1055     return (consumed)?EKeyWasConsumed:EKeyWasNotConsumed;
       
  1056 }
       
  1057 
       
  1058 
       
  1059 void WebView::updateScrollbars(int documentHeight, int displayPosY, int documentWidth, int displayPosX)
       
  1060 {
       
  1061     m_brctl->updateScrollbars((documentHeight * scalingFactor()) / 100, Rect().Height(),
       
  1062         (displayPosY * scalingFactor()) / 100, (documentWidth * scalingFactor()) / 100, Rect().Width(),
       
  1063         (displayPosX * scalingFactor()) / 100);
       
  1064 }
       
  1065 
       
  1066 void WebView::openPageViewL()
       
  1067 {
       
  1068     // don't show pageview if we are in lite mode
       
  1069     if ( m_brctl->capabilities() & TBrCtlDefs::ECapabilityWebKitLite )
       
  1070         return;
       
  1071     if (!m_pageView) {
       
  1072         m_pageView = CPageView::NewL(*this);
       
  1073         MakeVisible(EFalse);
       
  1074         m_savedPosition = mainFrame()->frameView()->contentPos();
       
  1075         m_brctl->reportStateChanged(TBrCtlDefs::EStateThumbnailView, ETrue);
       
  1076     }
       
  1077 }
       
  1078 
       
  1079 void WebView::closePageView()
       
  1080 {
       
  1081     if ( m_brctl->capabilities() & TBrCtlDefs::ECapabilityWebKitLite )
       
  1082         return;
       
  1083     if (m_pageView) {
       
  1084         delete m_pageView;
       
  1085         m_pageView = 0;
       
  1086         MakeVisible(ETrue);
       
  1087         m_brctl->DrawNow();
       
  1088         m_brctl->reportStateChanged(TBrCtlDefs::EStateThumbnailView, EFalse);
       
  1089     }
       
  1090 }
       
  1091 
       
  1092 void WebView::cancelPageView()
       
  1093 {
       
  1094     if ( m_brctl->capabilities() & TBrCtlDefs::ECapabilityWebKitLite )
       
  1095         return;
       
  1096     if (m_pageView) {
       
  1097         mainFrame()->frameView()->scrollTo(m_savedPosition);
       
  1098         closePageView();
       
  1099     }
       
  1100 }
       
  1101 
       
  1102 //-------------------------------------------------------------------------------
       
  1103 // launchToolBarL
       
  1104 //-------------------------------------------------------------------------------
       
  1105 void WebView::launchToolBarL()
       
  1106 {
       
  1107     if ( AknLayoutUtils::PenEnabled() || m_brctl->wmlMode() ) {
       
  1108         return;
       
  1109     }
       
  1110 
       
  1111     if ( !(m_brctl->capabilities() & TBrCtlDefs::ECapabilityToolBar) ) {
       
  1112         return;
       
  1113     }
       
  1114 
       
  1115     if ( !m_brctl->settings()->brctlSetting(TBrCtlDefs::ESettingsToolbarOnOff) ) {
       
  1116         return;
       
  1117     }
       
  1118 
       
  1119     delete m_toolbar;
       
  1120     m_toolbar = 0;
       
  1121 
       
  1122     delete m_toolbarinterface;
       
  1123     m_toolbarinterface = 0;
       
  1124 
       
  1125     m_toolbarinterface = new WebToolBarInterface(this);
       
  1126     TRAPD(leave, m_toolbar = CToolBar::NewL(*m_toolbarinterface));
       
  1127     if (leave != KErrNone)
       
  1128         return;
       
  1129 
       
  1130     /*EnableDragEvents();*/
       
  1131 
       
  1132     m_brctl->DrawNow();
       
  1133     m_brctl->reportStateChanged(TBrCtlDefs::EStateToolBarMode, ETrue);
       
  1134 
       
  1135 }
       
  1136 
       
  1137 //-------------------------------------------------------------------------------
       
  1138 // closeToolBarL
       
  1139 //-------------------------------------------------------------------------------
       
  1140 void WebView::closeToolBarL()
       
  1141 {
       
  1142     delete m_toolbar;
       
  1143     m_toolbar = 0;
       
  1144 
       
  1145     delete m_toolbarinterface;
       
  1146     m_toolbarinterface = 0;
       
  1147 
       
  1148     if (IsVisible())
       
  1149     {
       
  1150         StaticObjectsContainer::instance()->webCursor()->cursorUpdate(ETrue);
       
  1151         m_brctl->DrawNow();
       
  1152     }
       
  1153 
       
  1154     m_brctl->reportStateChanged(TBrCtlDefs::EStateToolBarMode, EFalse);
       
  1155 }
       
  1156 
       
  1157 //-------------------------------------------------------------------------------
       
  1158 // DrawDocumentPart ( from MPageScalerCallback )
       
  1159 //
       
  1160 //
       
  1161 //-------------------------------------------------------------------------------
       
  1162 void WebView::DrawDocumentPart(
       
  1163                                CFbsBitGc& aGc,
       
  1164                                CFbsBitmap* aBitmap,
       
  1165                                const TRect& aDocumentAreaToDraw )
       
  1166 {
       
  1167     TRect r( mainFrame()->frameView()->toDocCoords(aDocumentAreaToDraw) ) ;
       
  1168     WebCoreGraphicsContext* wcgc = 0;
       
  1169     TRAPD( err, wcgc = WebCoreGraphicsContext::NewL( aGc, aBitmap, mainFrame()->frameView()));
       
  1170     if ( err == KErrNone )
       
  1171     {
       
  1172         // ensure all documents have valid layout
       
  1173         // tot:fixme
       
  1174         //mainFrame->LayoutRecursive();
       
  1175 
       
  1176         TWebCoreSavedContext saved( wcgc->save() );
       
  1177 
       
  1178         wcgc->setOrigin( -aDocumentAreaToDraw.iTl );
       
  1179         wcgc->setClippingRect( aDocumentAreaToDraw );
       
  1180 
       
  1181         // draw using bridge directly as frame::draw clips drawing to view size
       
  1182         mainFrame()->paintRect( *wcgc, r );
       
  1183         wcgc->restore(saved);
       
  1184         delete wcgc;
       
  1185     }
       
  1186 }
       
  1187 
       
  1188 //-------------------------------------------------------------------------------
       
  1189 // DocumentViewport ( from MPageScalerCallback )
       
  1190 //
       
  1191 //
       
  1192 //-------------------------------------------------------------------------------
       
  1193 TRect WebView::DocumentViewport()
       
  1194 {
       
  1195     return mainFrame()->frameView()->toViewCoords(mainFrame()->frameView()->visibleRect());
       
  1196 }
       
  1197 
       
  1198 //-------------------------------------------------------------------------------
       
  1199 // ScaledPageChanged ( from MPageScalerCallback )
       
  1200 //
       
  1201 //
       
  1202 //-------------------------------------------------------------------------------
       
  1203 void WebView::ScaledPageChanged(
       
  1204                                 const TRect& aRect,
       
  1205                                 TBool aFullScreen,
       
  1206                                 TBool aScroll )
       
  1207 {
       
  1208     if (!aScroll) {
       
  1209         Window().Invalidate( aRect );
       
  1210     }
       
  1211 
       
  1212     if ( !aScroll && aFullScreen )
       
  1213     {
       
  1214         // update the history with new bitmap
       
  1215         CFbsBitmap* scaledPage = m_pageScaler->ScaledPage();
       
  1216         if (scaledPage) {
       
  1217             // Get the browser control rect
       
  1218             TRAP_IGNORE( m_brctl->historyHandler()->historyController()->updateHistoryEntryThumbnailL(scaledPage));
       
  1219 
       
  1220             m_brctl->HandleBrowserLoadEventL( TBrCtlDefs::EEventThumbnailAvailable, 0, 0 );
       
  1221         }
       
  1222         // ignore err since we will use the default image
       
  1223     }
       
  1224 }
       
  1225 
       
  1226 //-------------------------------------------------------------------------------
       
  1227 // DocumentSize ( from MPageScalerCallback )
       
  1228 //
       
  1229 //
       
  1230 //-------------------------------------------------------------------------------
       
  1231 TSize WebView::DocumentSize()
       
  1232 {
       
  1233     return mainFrame()->frameView()->toViewCoords(mainFrame()->frameView()->contentSize());
       
  1234 }
       
  1235 
       
  1236 //-------------------------------------------------------------------------------
       
  1237 // TouchScrolling ( from MPageScalerCallback )
       
  1238 //
       
  1239 //
       
  1240 //-------------------------------------------------------------------------------
       
  1241 TBool WebView::TouchScrolling()
       
  1242 {
       
  1243     return m_pageScrollHandler->touchScrolling();
       
  1244 }
       
  1245 
       
  1246 CCoeControl& WebView::PageControlView()
       
  1247 {
       
  1248     return *(m_brctl->CCoeControlParent());
       
  1249 }
       
  1250 
       
  1251 void WebView::setEditable(TBool editable)
       
  1252 {
       
  1253     Frame* frame = core(mainFrame());
       
  1254     if (!frame || m_isEditable == editable)
       
  1255         return;
       
  1256 
       
  1257     m_isEditable = editable;
       
  1258 
       
  1259     Node* focusedNode = NULL;
       
  1260     Frame* focusedFrame = page()->focusController()->focusedFrame();
       
  1261 
       
  1262     if (editable && focusedFrame) {
       
  1263         m_webfeptexteditor->UpdateEditingMode();
       
  1264         focusedNode = focusedFrame->document()->focusedNode();
       
  1265     }
       
  1266     else {
       
  1267         m_webfeptexteditor->CancelEditingMode();
       
  1268     }
       
  1269 
       
  1270     WebCursor* c = StaticObjectsContainer::instance()->webCursor();
       
  1271     //
       
  1272     if (focusedNode)
       
  1273         // based on focused element
       
  1274         m_focusedElementType = nodeTypeB(focusedNode, focusedFrame);
       
  1275     else {
       
  1276         m_focusedElementType = TBrCtlDefs::EElementNone;
       
  1277 
       
  1278         // based on cursor pos
       
  1279         c->updatePositionAndElemType(c->position());
       
  1280     }
       
  1281     c->cursorUpdate(!m_isEditable);
       
  1282     m_brctl->updateDefaultSoftkeys();
       
  1283     iCoeEnv->InputCapabilitiesChanged();
       
  1284 }
       
  1285 
       
  1286 TCoeInputCapabilities WebView::InputCapabilities() const
       
  1287 {
       
  1288     return m_webfeptexteditor->InputCapabilities();
       
  1289 }
       
  1290 
       
  1291 void WebView::FocusChanged(TDrawNow aDrawNow)
       
  1292 {
       
  1293 if (m_isPluginsVisible && !m_pluginActivated) {
       
  1294         Frame* coreFrame =core(mainFrame());
       
  1295         MWebCoreObjectWidget* view = NULL;
       
  1296         TBool focus(IsFocused());
       
  1297         for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
       
  1298             PassRefPtr<HTMLCollection> objects = frame->document()->objects();
       
  1299             for (Node* n = objects->firstItem(); n; n = objects->nextItem()) {
       
  1300                 view = widget(n);
       
  1301                 if (view) {
       
  1302                     static_cast<PluginSkin*>(view)->viewFocusChanged(focus);
       
  1303                 }
       
  1304             }
       
  1305 
       
  1306             PassRefPtr<HTMLCollection> embeds = frame->document()->embeds();
       
  1307             for (Node* n = embeds->firstItem(); n; n = embeds->nextItem()) {
       
  1308                 view = widget(n);
       
  1309                 if (view) {
       
  1310                     static_cast<PluginSkin*>(view)->viewFocusChanged(focus);
       
  1311                 }
       
  1312             }
       
  1313         }
       
  1314     }
       
  1315     if (m_pageFullScreenHandler && m_pageFullScreenHandler->isFullScreenMode()) {
       
  1316         if (IsFocused()) m_pageFullScreenHandler->showEscBtnL();
       
  1317         else m_pageFullScreenHandler->hideEscBtnL();
       
  1318     }
       
  1319 }
       
  1320 
       
  1321 void WebView::SizeChanged()
       
  1322 {
       
  1323     adjustOffscreenRect();
       
  1324     //
       
  1325     if (mainFrame()) {
       
  1326         mainFrame()->frameView()->setRect(mainFrame()->frameView()->toDocCoords(Rect()));
       
  1327     }
       
  1328     if ( m_pageScaler )
       
  1329         m_pageScaler->SetContainerRect(TRect(Rect().Size()));
       
  1330     if (m_webFormFillPopup && m_webFormFillPopup->IsVisible()) {
       
  1331         m_webFormFill->updatePopupView();
       
  1332     }
       
  1333     if (m_pageFullScreenHandler) {
       
  1334         m_pageFullScreenHandler->SizeChanged();
       
  1335     }
       
  1336     if (m_viewIsScrolling) {
       
  1337         m_pageScrollHandler->scrollbarDrawer()->redrawScrollbar();
       
  1338     }
       
  1339 }
       
  1340 
       
  1341 TSize WebView::maxBidiSize() const
       
  1342 {
       
  1343     return TSize((Rect().Size().iWidth-20),(Rect().Size().iHeight-20));
       
  1344 }
       
  1345 
       
  1346 void WebView::clearOffScreenBitmap()
       
  1347 {
       
  1348     m_webcorecontext->gc().Reset();
       
  1349     m_webcorecontext->gc().Clear();
       
  1350 }
       
  1351 
       
  1352 void WebView::scrollBuffer(TPoint to, TPoint from, TBool usecopyscroll)
       
  1353 {
       
  1354     TRect rect(m_offscreenrect);
       
  1355 
       
  1356     TSize bufSize( rect.Size() );
       
  1357 
       
  1358     CFbsBitGc& gc = m_webcorecontext->gc();
       
  1359     gc.Reset();
       
  1360 
       
  1361     TRect paintArea;
       
  1362 
       
  1363     int dx = from.iX - to.iX;
       
  1364     int dy = from.iY - to.iY;
       
  1365 
       
  1366     if (usecopyscroll && abs(dx) < bufSize.iWidth && abs(dy) < bufSize.iHeight) {
       
  1367         TPoint fromPt(dx<0?-dx:0, dy<0?-dy:0);
       
  1368         TRect fromRt(fromPt, TSize(bufSize.iWidth-abs(dx), bufSize.iHeight-abs(dy)));
       
  1369         TRect toRt(TPoint(fromPt.iX+dx, fromPt.iY+dy), fromRt.Size());
       
  1370 
       
  1371         gc.CopyRect(TPoint(dx, dy), fromRt);
       
  1372 
       
  1373         RRegion region;
       
  1374         region.AddRect(TRect(TPoint(0, 0), bufSize));
       
  1375         region.AddRect(toRt);
       
  1376         region.SubRect(toRt, 0);
       
  1377 
       
  1378         for (int i=0; i<region.Count(); ++i) {
       
  1379             TRect r = region[i];
       
  1380             r.Move(to);
       
  1381             r = mainFrame()->frameView()->toDocCoords(r);
       
  1382             if (mainFrame()->frameView()->isScaled())
       
  1383                 r.Grow(1, 1);
       
  1384             m_repaints.AddRect(r);
       
  1385         }
       
  1386     }
       
  1387     else {
       
  1388         TRect r(to, bufSize);
       
  1389         r = mainFrame()->frameView()->toDocCoords(r);
       
  1390         if (mainFrame()->frameView()->isScaled())
       
  1391             r.Grow(1, 1);
       
  1392         m_repaints.AddRect(r);
       
  1393     }
       
  1394 
       
  1395 }
       
  1396 
       
  1397 int WebView::scalingFactor() const
       
  1398 {
       
  1399     return m_currentZoomLevel;
       
  1400 }
       
  1401 
       
  1402 CPluginHandler* WebView::pluginForExtension(const WebCore::String& pluginExtension)
       
  1403 {
       
  1404     return NULL;
       
  1405 }
       
  1406 
       
  1407 bool WebView::isMIMETypeRegisteredAsPlugin(const WebCore::String& MIMEType)
       
  1408 {
       
  1409     return false;
       
  1410 }
       
  1411 
       
  1412 void WebView::adjustOffscreenRect()
       
  1413 {
       
  1414     TRect rect(Rect());
       
  1415 
       
  1416     if ( m_offscreenrect != rect ) {
       
  1417         m_offscreenrect = rect;
       
  1418         TSize bmSize = StaticObjectsContainer::instance()->webSurface()->offscreenBitmap()->SizeInPixels();
       
  1419         if (bmSize.iWidth != rect.Width() || bmSize.iHeight != rect.Height()) {
       
  1420             m_bitmapdevice->Resize(rect.Size());
       
  1421             m_webcorecontext->resized();
       
  1422         }
       
  1423     }
       
  1424 }
       
  1425 
       
  1426 void WebView::autoScroll()
       
  1427 {
       
  1428     // update scrolling speed
       
  1429     int milli = millisecondsScrolled();
       
  1430     setViewIsFastScrolling(true);
       
  1431     toggleRepaintTimer(false);
       
  1432     m_scrollingSpeed = milli>=KPanningMaxTime ? KPanningMaxSpeed : KPanningStartSpeed+(KPanningMaxSpeed-KPanningStartSpeed)*Max(milli-KPanningStartTime,0)/KPanningMaxTime;
       
  1433     m_scrollingSpeed = m_scrollingSpeed*100/scalingFactor();
       
  1434     TPoint scrollDelta = mainFrame()->frameView()->contentPos() - m_savedPosition;
       
  1435     scrollDelta.iX *= 100;
       
  1436     scrollDelta.iY *= 100;
       
  1437     if (AknLayoutUtils::PenEnabled() && !inPageViewMode()) {
       
  1438         m_pageScrollHandler->scrollbarDrawer()->drawScrollbar(this, scrollDelta);
       
  1439     }
       
  1440     OfferKeyEventL(m_currentEventKey, EEventKey);
       
  1441 }
       
  1442 
       
  1443 int WebView::millisecondsScrolled() const
       
  1444 {
       
  1445     TTime timeNow;
       
  1446     timeNow.HomeTime();
       
  1447     return I64INT(timeNow.MicroSecondsFrom(m_scrollingStartTime).Int64()/1000);
       
  1448 }
       
  1449 
       
  1450 TInt WebView::scrollTimerCb(TAny* aAny)
       
  1451 {
       
  1452     WebView* v = static_cast<WebView*>(aAny);
       
  1453     v->autoScroll();
       
  1454     return ETrue;
       
  1455 }
       
  1456 
       
  1457 int WebView::searchFor(const TPtrC& keyword)
       
  1458 {
       
  1459     m_inFindState = true;
       
  1460     delete m_findKeyword;
       
  1461     m_findKeyword = NULL;
       
  1462     m_findKeyword = keyword.Alloc();
       
  1463     if (!m_findKeyword || keyword.Length() == 0) {
       
  1464         WebFrame* frame = mainFrame()->findFrameWithSelection();
       
  1465         if(frame)
       
  1466             frame->clearSelection();
       
  1467         return TBrCtlDefs::EFindNoMatches;
       
  1468     }
       
  1469     m_findKeyword->Des().LowerCase();
       
  1470     return search(keyword, true, true);
       
  1471 }
       
  1472 
       
  1473 int WebView::searchAgain(bool forward)
       
  1474 {
       
  1475     if (!m_findKeyword) {
       
  1476         WebFrame* frame = mainFrame()->findFrameWithSelection();
       
  1477         if(frame) {
       
  1478 			frame->clearSelection();
       
  1479         }
       
  1480         return TBrCtlDefs::EFindNoMatches;
       
  1481     }
       
  1482     return search(*m_findKeyword, forward, true);
       
  1483 }
       
  1484 
       
  1485 int WebView::search(TPtrC keyword, bool forward, bool wrapFlag)
       
  1486 {
       
  1487     // Get the frame holding the selection, or start with the main frame
       
  1488     WebFrame* startFrame = mainFrame()->findFrameWithSelection();
       
  1489     WebFrame* lastFrame = NULL;
       
  1490     if (!startFrame)  {
       
  1491         if (StaticObjectsContainer::instance()->webCursor()) {
       
  1492             startFrame = StaticObjectsContainer::instance()->webCursor()->getFrameUnderCursor();
       
  1493         }
       
  1494         else {
       
  1495             startFrame = mainFrame();
       
  1496         }
       
  1497     }
       
  1498     WebFrame* frame = startFrame;
       
  1499     do {
       
  1500         WebFrame* nextFrame = incrementFrame(frame, forward, wrapFlag);
       
  1501         bool onlyOneFrame = (frame == nextFrame);
       
  1502         if (frame == startFrame)
       
  1503             lastFrame = frame;
       
  1504 
       
  1505         bool foundString = false;
       
  1506         // In some cases we have to search some content twice; see comment later in this method.
       
  1507         // We can avoid ever doing this in the common one-frame case by passing YES for wrapFlag
       
  1508         // here, and then bailing out before we get to the code that would search again in the
       
  1509         // same content.
       
  1510         bool wrapOnThisPass = wrapFlag && onlyOneFrame;
       
  1511         if (!core(frame)->isFrameSet() ) {
       
  1512             foundString = frame->bridge()->searchFor(keyword, forward, false, wrapOnThisPass, true);
       
  1513         }
       
  1514         if (foundString)  {
       
  1515             if (frame != startFrame)
       
  1516                 startFrame->clearSelection();
       
  1517             return TBrCtlDefs::EFindMatch;
       
  1518         }
       
  1519         if (onlyOneFrame) {
       
  1520 			startFrame->clearSelection();
       
  1521             return TBrCtlDefs::EFindNoMatches;
       
  1522         }
       
  1523         frame = nextFrame;
       
  1524     } while (frame && frame != startFrame);
       
  1525 
       
  1526     // If there are multiple frames and wrapFlag is true and we've visited each one without finding a result, we still need to search in the
       
  1527     // first-searched frame up to the selection. However, the API doesn't provide a way to search only up to a particular point. The only
       
  1528     // way to make sure the entire frame is searched is to pass YES for the wrapFlag. When there are no matches, this will search again
       
  1529     // some content that we already searched on the first pass. In the worst case, we could search the entire contents of this frame twice.
       
  1530     // To fix this, we'd need to add a mechanism to specify a range in which to search.
       
  1531     if (wrapFlag && lastFrame) {
       
  1532         if (frame->bridge()->searchFor(keyword, forward, false, true, false))
       
  1533             return TBrCtlDefs::EFindMatch;
       
  1534     }
       
  1535 
       
  1536 	if(frame) {
       
  1537 		frame->clearSelection();
       
  1538 	}		
       
  1539     return TBrCtlDefs::EFindNoMatches;
       
  1540 }
       
  1541 
       
  1542 void WebView::exitFindState()
       
  1543 {
       
  1544     m_inFindState = false;
       
  1545     delete m_findKeyword;
       
  1546     m_findKeyword = NULL;
       
  1547     WebFrame* selectedFrame = mainFrame()->findFrameWithSelection();
       
  1548     selectedFrame->clearSelection();
       
  1549 }
       
  1550 
       
  1551 bool WebView::isSmallPage()
       
  1552 {
       
  1553     TSize docSize = DocumentSize();
       
  1554     TSize viewSize = DocumentViewport().Size();
       
  1555     return ((docSize.iWidth * docSize.iHeight*100)/(viewSize.iWidth*viewSize.iHeight) < KSmallPageScale);
       
  1556 }
       
  1557 
       
  1558 void WebView::willSubmitForm(FormState* formState)
       
  1559 {
       
  1560     if (m_webFormFill) {
       
  1561         m_webFormFill->willSubmitForm(formState);
       
  1562     }
       
  1563 }
       
  1564 
       
  1565 
       
  1566 //-------------------------------------------------------------------------------
       
  1567 // HandlePointerBufferReadyL
       
  1568 // Handles Pointer Move Events
       
  1569 //-------------------------------------------------------------------------------
       
  1570 void WebView::HandlePointerBufferReadyL()
       
  1571 {
       
  1572     memset(m_ptrbuffer,0,256*sizeof(TPoint));
       
  1573     TPtr8 ptr((TUint8 *)m_ptrbuffer,256*sizeof(TPoint));
       
  1574 
       
  1575     TInt numPnts = Window().RetrievePointerMoveBuffer(ptr);
       
  1576 
       
  1577     for (int i = 0; i < numPnts; i++) {
       
  1578         TPointerEvent pe;
       
  1579         pe.iType = TPointerEvent::EDrag;
       
  1580         pe.iPosition = m_ptrbuffer[i];
       
  1581         m_webpointerEventHandler->HandlePointerEventL(pe);
       
  1582     }
       
  1583 }
       
  1584 
       
  1585 //-------------------------------------------------------------------------------
       
  1586 // HandlePointerEventL
       
  1587 // Handles Pointer Events
       
  1588 //-------------------------------------------------------------------------------
       
  1589 void WebView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
  1590 {
       
  1591     m_webpointerEventHandler->HandlePointerEventL(aPointerEvent);
       
  1592 }
       
  1593 
       
  1594 void WebView::notifyMetaData(String& name, String& value)
       
  1595 {
       
  1596     if (name == "navigation") {
       
  1597         if (value == "tabbed") {
       
  1598             m_brctl->settings()->setTabbedNavigation(true);
       
  1599             StaticObjectsContainer::instance()->webCursor()->cursorUpdate(true);
       
  1600         }
       
  1601     }
       
  1602 }
       
  1603 
       
  1604 //-------------------------------------------------------------------------------
       
  1605 // HandleShowAnchorHref()
       
  1606 // Display a popup with the url of an anchor
       
  1607 //-------------------------------------------------------------------------------
       
  1608 void WebView::handleShowAnchorHrefL()
       
  1609 {
       
  1610     HBufC* url = NULL;
       
  1611     IntPoint p;
       
  1612     WebFrame* f = frameAndPointUnderCursor(p, *this);
       
  1613     String urlStr = getNodeUrlAtPointInFrame(*f, p);
       
  1614 
       
  1615     if (urlStr.length() > 0)
       
  1616         url = urlStr.des().AllocL();
       
  1617     else
       
  1618         User::Leave(KErrNotSupported);
       
  1619 
       
  1620     CleanupStack::PushL(url);
       
  1621 
       
  1622 
       
  1623     TRect elRect;
       
  1624     TBrCtlDefs::TBrCtlElementType elType = TBrCtlDefs::EElementNone;
       
  1625     WebFrame* frm = StaticObjectsContainer::instance()->webCursor()->getFrameUnderCursor();
       
  1626     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
  1627     TPoint pt(frm->frameView()->viewCoordsInFrameCoords(cursor->position()));
       
  1628     StaticObjectsContainer::instance()->webCursor()->navigableNodeUnderCursor(*(frm), pt, elType, elRect);
       
  1629 
       
  1630 
       
  1631     TRect rect(elRect);
       
  1632     rect.SetRect(f->frameView()->frameCoordsInViewCoords(rect.iTl), f->frameView()->frameCoordsInViewCoords(rect.iBr));
       
  1633 
       
  1634     TPtrC urlPtr(url->Des());
       
  1635     m_popupDrawer = WebPopupDrawer::NewL(*this, urlPtr, rect);
       
  1636     DrawNow();
       
  1637 
       
  1638     CleanupStack::PopAndDestroy(); // url
       
  1639 }
       
  1640 
       
  1641 //-------------------------------------------------------------------------------
       
  1642 // FocusedImageLC()
       
  1643 // Return the image that is under the cursor
       
  1644 //-------------------------------------------------------------------------------
       
  1645 TBrCtlImageCarrier* WebView::focusedImageLC()
       
  1646 {
       
  1647     if (m_focusedElementType != TBrCtlDefs::EElementImageBox && m_focusedElementType != TBrCtlDefs::EElementAreaBox) {
       
  1648         User::Leave(KErrNotSupported);
       
  1649     }
       
  1650     TBrCtlImageCarrier* imageCarrier = NULL;
       
  1651     User::LeaveIfError(focusedImage(this, imageCarrier));
       
  1652     CleanupStack::PushL(imageCarrier);
       
  1653     return imageCarrier;
       
  1654 }
       
  1655 
       
  1656 //-------------------------------------------------------------------------------
       
  1657 // LoadFocusedImageL()
       
  1658 // Load the image that is under the cursor
       
  1659 //-------------------------------------------------------------------------------
       
  1660 void WebView::loadFocusedImageL()
       
  1661 {
       
  1662     // Ensure cursor is on a broken image and image loading is disabled
       
  1663     if (m_focusedElementType != TBrCtlDefs::EElementBrokenImage || m_brctl->settings()->brctlSetting(TBrCtlDefs::ESettingsAutoLoadImages)) {
       
  1664         User::Leave(KErrNotSupported);
       
  1665     }
       
  1666     loadFocusedImage(this);
       
  1667 }
       
  1668 
       
  1669 //-------------------------------------------------------------------------------
       
  1670 // RemovePopup()
       
  1671 // Delete the popupDrawer
       
  1672 //-------------------------------------------------------------------------------
       
  1673 void WebView::removePopup()
       
  1674 {
       
  1675     if (m_popupDrawer) {
       
  1676         delete m_popupDrawer;
       
  1677         m_popupDrawer = NULL;
       
  1678         DrawNow();
       
  1679     }
       
  1680 }
       
  1681 
       
  1682 //-------------------------------------------------------------------------------
       
  1683 //-------------------------------------------------------------------------------
       
  1684 RArray<TUint>* WebView::zoomLevels()
       
  1685 {
       
  1686     return &m_zoomLevelArray;
       
  1687 }
       
  1688 
       
  1689 //-------------------------------------------------------------------------------
       
  1690 //-------------------------------------------------------------------------------
       
  1691 void WebView::setZoomLevel(int zoomLevel)
       
  1692 {
       
  1693     m_dirtyZoomMode = false;
       
  1694     if (zoomLevel < KZoomLevelMinValue ||
       
  1695         zoomLevel > m_maxZoomLevel ||
       
  1696         zoomLevel == m_currentZoomLevel)
       
  1697         return;
       
  1698     zoomLevelChanged(zoomLevel);
       
  1699 }
       
  1700 
       
  1701 //-------------------------------------------------------------------------------
       
  1702 //-------------------------------------------------------------------------------
       
  1703 void WebView::setBitmapZoomLevel(int zoomLevel)
       
  1704 {
       
  1705     m_zoomLevelChangedByUser = true;
       
  1706     WebFrameView* view = mainFrame()->frameView();
       
  1707     if (!view) return;
       
  1708 
       
  1709     m_dirtyZoomMode = true;
       
  1710     m_isPluginsVisible = false;
       
  1711     mainFrame()->makeVisiblePlugins(false);
       
  1712 
       
  1713     if (zoomLevel > m_startZoomLevel) {
       
  1714 
       
  1715         // cut m_srcRectForZooming from m_offscreenrect and enlarge it to fit the view rect
       
  1716 
       
  1717         float newWidth =   m_offscreenrect.Width() *  zoomLevel / m_startZoomLevel;
       
  1718         float newHeight =  m_offscreenrect.Height() * zoomLevel / m_startZoomLevel;
       
  1719 
       
  1720         newWidth =  (float)(m_offscreenrect.Width() * (float)m_offscreenrect.Width()) / newWidth;
       
  1721         newHeight = (float)m_offscreenrect.Height() * (float)m_offscreenrect.Height() / newHeight;
       
  1722 
       
  1723         TSize docSize = DocumentSize();
       
  1724         TSize viewSize = DocumentViewport().Size();
       
  1725         TSize contentSize = view->contentSize();
       
  1726 
       
  1727 
       
  1728         m_srcRectForZooming.iTl.iX = 0;
       
  1729         m_srcRectForZooming.iTl.iY = 0;
       
  1730 
       
  1731         m_srcRectForZooming.iBr.iX = newWidth;
       
  1732         m_srcRectForZooming.iBr.iY = newHeight;
       
  1733 
       
  1734         m_destRectForZooming = Rect();
       
  1735 
       
  1736     }
       
  1737     else {
       
  1738        // take the whole rect and calculate new rect to fit it the rest of view rect paint gray colour
       
  1739 
       
  1740         TInt newWidth  = m_offscreenrect.Width() * zoomLevel / m_startZoomLevel;
       
  1741         TInt newHeight = m_offscreenrect.Height() * zoomLevel / m_startZoomLevel;
       
  1742 
       
  1743         m_srcRectForZooming = m_offscreenrect;
       
  1744 
       
  1745         m_destRectForZooming.iTl.iX = 0;
       
  1746         m_destRectForZooming.iTl.iY = 0;
       
  1747 
       
  1748         m_destRectForZooming.iBr.iX = newWidth;
       
  1749         m_destRectForZooming.iBr.iY = newHeight;
       
  1750     }
       
  1751 
       
  1752     m_currentZoomLevel = zoomLevel;
       
  1753 
       
  1754     DrawNow();
       
  1755 }
       
  1756 
       
  1757 //-------------------------------------------------------------------------------
       
  1758 //-------------------------------------------------------------------------------
       
  1759 void WebView::restoreZoomLevel(int zoomLevel)
       
  1760 {
       
  1761     m_dirtyZoomMode = false;
       
  1762     clearOffScreenBitmap();
       
  1763     zoomLevelChanged(zoomLevel);
       
  1764     mainFrame()->notifyPluginsOfScrolling();
       
  1765     m_isPluginsVisible = false;
       
  1766     mainFrame()->makeVisiblePlugins(true);
       
  1767     m_isPluginsVisible = true;
       
  1768 }
       
  1769 
       
  1770 //-------------------------------------------------------------------------------
       
  1771 //-------------------------------------------------------------------------------
       
  1772 void WebView::resetZoomLevel(void)
       
  1773 {
       
  1774     if(   m_widgetextension && m_widgetextension->IsWidgetPublising()) {
       
  1775         return ;
       
  1776         }
       
  1777     if (m_historyLoad) {
       
  1778         int zoomLevel = m_brctl->historyHandler()->historyController()->currentEntryZoomLevel();
       
  1779         if (!zoomLevel) zoomLevel = KZoomLevelDefaultValue;
       
  1780         if (m_currentZoomLevel != zoomLevel) {
       
  1781             m_currentZoomLevel = zoomLevel;
       
  1782         }
       
  1783         int minZoomLevel = m_brctl->historyHandler()->historyController()->currentEntryMinZoomLevel();
       
  1784         if (!minZoomLevel)
       
  1785             minZoomLevel = (KZoomLevelDefaultValue/ m_pageZoomHandler->stepSize())*m_pageZoomHandler->stepSize();
       
  1786         else
       
  1787             minZoomLevel = (minZoomLevel / m_pageZoomHandler->stepSize())*m_pageZoomHandler->stepSize();
       
  1788         //could happen only if m_minZoomLevel < stepSize
       
  1789         if (!m_minZoomLevel) m_minZoomLevel = m_pageZoomHandler->stepSize();
       
  1790 
       
  1791         if (m_minZoomLevel != minZoomLevel) {
       
  1792             m_minZoomLevel = minZoomLevel;
       
  1793         }
       
  1794         m_currentZoomLevel = zoomLevel;
       
  1795     //set to settings
       
  1796     m_brctl->settings()->setBrctlSetting(TBrCtlDefs::ESettingsCurrentZoomLevelIndex, m_currentZoomLevel);
       
  1797     }
       
  1798     else {
       
  1799     if (m_currentZoomLevel != KZoomLevelDefaultValue)
       
  1800     //set default current zoom index
       
  1801     {
       
  1802           m_currentZoomLevel = KZoomLevelDefaultValue;
       
  1803       //set to settings
       
  1804           m_brctl->settings()->setBrctlSetting(TBrCtlDefs::ESettingsCurrentZoomLevelIndex, m_currentZoomLevel);
       
  1805     }
       
  1806     }
       
  1807     clearOffScreenBitmap();
       
  1808     m_zoomLevelChangedByUser = false;
       
  1809     mainFrame()->scalingFactorChanged(m_currentZoomLevel);
       
  1810     mainFrame()->frameView()->setRect(mainFrame()->frameView()->toDocCoords(Rect()));
       
  1811     m_startZoomLevel = m_currentZoomLevel;
       
  1812 }
       
  1813 
       
  1814 //-------------------------------------------------------------------------------
       
  1815 //-------------------------------------------------------------------------------
       
  1816 void WebView::updateMinZoomLevel(TSize size)
       
  1817 {
       
  1818     int newMinZoomLevel;
       
  1819     if (size.iWidth && size.iHeight) {
       
  1820         TRect screenSize(Rect().Size());
       
  1821 
       
  1822         float minWidth = ((float)screenSize.Width()) * 100 /(float)( size.iWidth);
       
  1823         float minHeight = ((float)screenSize.Height()) * 100 /(float)( size.iHeight);
       
  1824 
       
  1825         newMinZoomLevel = ( minWidth > minHeight )?minWidth:minHeight;
       
  1826 
       
  1827         if ( newMinZoomLevel < KZoomLevelMinValue ) newMinZoomLevel = KZoomLevelMinValue;
       
  1828         if ( newMinZoomLevel > KZoomLevelDefaultValue ) newMinZoomLevel = KZoomLevelDefaultValue;
       
  1829         if ( newMinZoomLevel > m_currentZoomLevel ) newMinZoomLevel = m_currentZoomLevel;
       
  1830     }
       
  1831     else {
       
  1832         newMinZoomLevel = KZoomLevelDefaultValue;
       
  1833     }
       
  1834 
       
  1835     newMinZoomLevel = (newMinZoomLevel/m_pageZoomHandler->stepSize())*m_pageZoomHandler->stepSize();
       
  1836 
       
  1837   TBool needsUpdateArray = EFalse;
       
  1838   //Update the new array
       
  1839   if ( m_minZoomLevel!= newMinZoomLevel)
       
  1840   {
       
  1841     needsUpdateArray = ETrue;
       
  1842   }
       
  1843 
       
  1844      //could happen only if m_minZoomLevel < stepSize
       
  1845     if (!newMinZoomLevel) newMinZoomLevel = m_pageZoomHandler->stepSize();
       
  1846 
       
  1847     if (m_minZoomLevel != newMinZoomLevel)
       
  1848     {
       
  1849        m_minZoomLevel = newMinZoomLevel;
       
  1850       if (m_pageZoomHandler->isActive()) {
       
  1851           m_pageZoomHandler->hideZoomSliderL();
       
  1852           m_pageZoomHandler->showZoomSliderL();
       
  1853       }
       
  1854       else {
       
  1855         UpdateZoomArray(); //for non-touch
       
  1856       }
       
  1857   } //endof if (m_minZoomLevel != newMinZoomLevel)
       
  1858 }
       
  1859 
       
  1860 //-------------------------------------------------------------------------------
       
  1861 //-------------------------------------------------------------------------------
       
  1862 void WebView::UpdateZoomArray()
       
  1863 {
       
  1864     //only for non-touch device
       
  1865     if (m_pageZoomHandler->isActive())
       
  1866     {
       
  1867     return;
       
  1868     }
       
  1869 
       
  1870     m_zoomLevelArray.Reset();
       
  1871 
       
  1872     m_minZoomLevel = TInt(m_minZoomLevel/10) * 10;
       
  1873     m_zoomLevelArray.Append(KZoomLevelDefaultValue);
       
  1874 
       
  1875     //construct the zoom array from the default level
       
  1876     TInt toAddZoomLevel = KZoomLevelDefaultValue + KZoomLevelDefaultValue*KZoomLevelDelta/100;
       
  1877     while (toAddZoomLevel <= m_maxZoomLevel)
       
  1878     {
       
  1879         //add the zoom level after default one
       
  1880         m_zoomLevelArray.Append(toAddZoomLevel);
       
  1881         toAddZoomLevel = toAddZoomLevel + toAddZoomLevel*KZoomLevelDelta/100;
       
  1882     }
       
  1883 
       
  1884     //now goes the minimum one
       
  1885     toAddZoomLevel = KZoomLevelDefaultValue - KZoomLevelDefaultValue*KZoomLevelDelta/100;
       
  1886     while (toAddZoomLevel >= m_minZoomLevel)
       
  1887     {
       
  1888         //add the zoom level after default one
       
  1889         m_zoomLevelArray.Insert(toAddZoomLevel, 0);
       
  1890         toAddZoomLevel = toAddZoomLevel - toAddZoomLevel*KZoomLevelDelta/100;
       
  1891     }
       
  1892 
       
  1893 }
       
  1894 
       
  1895 //-------------------------------------------------------------------------------
       
  1896 //-------------------------------------------------------------------------------
       
  1897 void WebView::zoomLevelChanged(int newZoomLevel)
       
  1898 {
       
  1899     int currZoomLevel = m_startZoomLevel;
       
  1900     m_dirtyZoomMode = false;
       
  1901     // instead of clearOffScreen bitmap, just reset.
       
  1902     m_webcorecontext->gc().Reset();
       
  1903     m_currentZoomLevel = newZoomLevel;
       
  1904     TSize sz( m_offscreenrect.Size() );
       
  1905     WebFrameView* view = mainFrame()->frameView();
       
  1906     if (!view) return;
       
  1907 
       
  1908     TPoint pt( view->contentPos() );
       
  1909         TSize contentSize( view->contentSize() );
       
  1910         int z = m_currentZoomLevel;
       
  1911         if ( pt.iX * z > contentSize.iWidth * z - sz.iWidth * 100 )
       
  1912         pt.iX = ( contentSize.iWidth - sz.iWidth * 100 / z );
       
  1913 
       
  1914         if ( pt.iY * z > contentSize.iHeight * z - sz.iHeight * 100 )
       
  1915         pt.iY = ( contentSize.iHeight - sz.iHeight * 100 / z );
       
  1916 
       
  1917         if ( pt.iY < 0 ) pt.iY = 0;
       
  1918         if ( pt.iX < 0 ) pt.iX = 0;
       
  1919 
       
  1920 
       
  1921     view->setContentPos( pt );
       
  1922     mainFrame()->scalingFactorChanged(z);
       
  1923     view->checkScrollbarVisibility();
       
  1924 
       
  1925     TRect rect = view->rect();
       
  1926 
       
  1927     TInt tlx = (rect.iTl.iX * currZoomLevel) / m_currentZoomLevel;
       
  1928     TInt tly = (rect.iTl.iY * currZoomLevel) / m_currentZoomLevel;
       
  1929     TInt brx = (rect.iBr.iX * currZoomLevel) / m_currentZoomLevel;
       
  1930     TInt bry = (rect.iBr.iY * currZoomLevel) / m_currentZoomLevel;
       
  1931 
       
  1932     // rounding
       
  1933 
       
  1934     if (( rect.iTl.iX * currZoomLevel) % m_currentZoomLevel ){
       
  1935         tlx -= 1;
       
  1936     }
       
  1937     if (( rect.iTl.iY * currZoomLevel) % m_currentZoomLevel ){
       
  1938         tly -= 1;
       
  1939     }
       
  1940     if ((rect.iBr.iX * currZoomLevel) % m_currentZoomLevel ){
       
  1941         brx += 1;
       
  1942     }
       
  1943     if ((rect.iBr.iY * currZoomLevel) % m_currentZoomLevel ){
       
  1944         bry += 1;
       
  1945     }
       
  1946 
       
  1947     view->setRect(TRect(tlx, tly, brx, bry));
       
  1948 
       
  1949     // now just do a repaint, should be very fast
       
  1950     if ( currZoomLevel > newZoomLevel ) {
       
  1951         clearOffScreenBitmap();
       
  1952     }
       
  1953 
       
  1954 
       
  1955     m_startZoomLevel = m_currentZoomLevel;
       
  1956 
       
  1957     updateScrollbars(mainFrame()->frameView()->contentSize().iHeight, mainFrame()->frameView()->contentPos().iY,
       
  1958         mainFrame()->frameView()->contentSize().iWidth, mainFrame()->frameView()->contentPos().iX);
       
  1959 
       
  1960     syncRepaint(view->visibleRect());
       
  1961 
       
  1962     int zoomLevel = m_brctl->historyHandler()->historyController()->currentEntryZoomLevel();
       
  1963     if (zoomLevel != m_currentZoomLevel) m_brctl->historyHandler()->historyController()->updateCurrentEntryZoomLevelIfNeeded();
       
  1964 }
       
  1965 
       
  1966 //-------------------------------------------------------------------------------
       
  1967 //-------------------------------------------------------------------------------
       
  1968 void WebView::resetLastZoomLevelIfNeeded()
       
  1969 {
       
  1970     if (m_lastZoomLevel == m_maxZoomLevel)
       
  1971         m_lastZoomLevel = 100;
       
  1972 }
       
  1973 
       
  1974 //-----------------------------------------------------------------------------
       
  1975 // setZoomLevelAdaptively()
       
  1976 //-----------------------------------------------------------------------------
       
  1977 void WebView::setZoomLevelAdaptively()
       
  1978 {
       
  1979     int zoomLevel = KZoomLevelDefaultValue;
       
  1980 
       
  1981   // Double Tap Zooming: it toggles between default, maxiZoomLevel.
       
  1982   // Depending on the current zoom level:
       
  1983   //   A. If the current is already the max, it zooms to the max 
       
  1984   //   B. If the current is bigger than/equal to the default zoom level zooms to the default, it zooms to the max
       
  1985   //   C. Otherwise it zooms to the default level first. 
       
  1986   // For the mobile pages, such as google.com and cnn.com, minimum zoom level equals
       
  1987   // to the default zoom level. Zooming is only possible between default and maximum
       
  1988   // zoom level, double tap only won't reach logic C
       
  1989   //
       
  1990   // For both mobile and non-mobile pages, it creates the same end user double tap 
       
  1991   // experiences 
       
  1992   
       
  1993     if (m_currentZoomLevel == m_maxZoomLevel ) {
       
  1994         zoomLevel = KZoomLevelDefaultValue;    	
       
  1995     }
       
  1996     else if (m_currentZoomLevel >= KZoomLevelDefaultValue ) {
       
  1997         zoomLevel = m_maxZoomLevel;
       
  1998     }	
       
  1999     else {
       
  2000         zoomLevel = KZoomLevelDefaultValue;    	
       
  2001     } 
       
  2002 
       
  2003     // move the content
       
  2004     WebFrameView* view = mainFrame()->frameView();
       
  2005     if (!view) return;
       
  2006     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
  2007     if (cursor) {
       
  2008         TPoint pt = cursor->position();
       
  2009         int z = zoomLevel * 100 / m_currentZoomLevel;
       
  2010         int xOff = (pt.iX * z / 100 - pt.iX)*100/zoomLevel;
       
  2011         int yOff = (pt.iY * z / 100 - pt.iY)*100/zoomLevel;
       
  2012         TPoint cp = view->contentPos();
       
  2013         cp += TPoint(xOff, yOff);
       
  2014         view->setContentPos(cp);
       
  2015     }
       
  2016 
       
  2017     // zoom it
       
  2018     m_lastZoomLevel = m_currentZoomLevel;
       
  2019 
       
  2020     setZoomLevel(zoomLevel);
       
  2021     mainFrame()->notifyPluginsOfScrolling();
       
  2022 }
       
  2023 
       
  2024 //-------------------------------------------------------------------------------
       
  2025 // Called when user clicks a plugin which is able to accept user input,
       
  2026 // this feature is only used in US build
       
  2027 //-------------------------------------------------------------------------------
       
  2028 void WebView::openPluginPlayer(PluginWin* plugin)
       
  2029 {
       
  2030     if (!m_pluginplayer) {
       
  2031         PluginSkin* pluginskin = mainFrame()->focusedPlugin();
       
  2032 
       
  2033         if ( !pluginskin || !pluginskin->isInteractive() ) return;
       
  2034 
       
  2035         // we only create the player when the plugin content is ready and
       
  2036         // the plugin is not allowed to interact inside html page.
       
  2037         if ( pluginskin->CanInteract() ) return;
       
  2038 
       
  2039         m_pluginplayer = PluginPlayer::NewL( *m_brctl, plugin );
       
  2040         MakeVisible(EFalse);
       
  2041         m_brctl->reportStateChanged(TBrCtlDefs::EStatePluginPlayer, ETrue);
       
  2042         // now start playing the content
       
  2043         m_pluginplayer->start();
       
  2044     }
       
  2045 }
       
  2046 
       
  2047 void WebView::setFocusNone()
       
  2048 {
       
  2049     page()->focusController()->setFocusedNode(NULL, page()->focusController()->focusedOrMainFrame());
       
  2050 }
       
  2051 //-------------------------------------------------------------------------------
       
  2052 //-------------------------------------------------------------------------------
       
  2053 void WebView::closePluginPlayer()
       
  2054 {
       
  2055     // stop playing
       
  2056     m_pluginplayer->stop();
       
  2057     MakeVisible( ETrue );
       
  2058 
       
  2059     delete m_pluginplayer;
       
  2060     m_pluginplayer = 0;
       
  2061     m_brctl->reportStateChanged(TBrCtlDefs::EStatePluginPlayer, EFalse);
       
  2062     // redraw the control
       
  2063     m_brctl->DrawNow();
       
  2064 }
       
  2065 
       
  2066 //-------------------------------------------------------------------------------
       
  2067 //-------------------------------------------------------------------------------
       
  2068 CWidgetExtension* WebView::createWidgetExtension(MWidgetCallback &aWidgetCallback)
       
  2069 {
       
  2070     if (!m_widgetextension) {
       
  2071         m_widgetextension = CWidgetExtension::NewL(*this, aWidgetCallback);
       
  2072 #if USE(LOW_BANDWIDTH_DISPLAY)
       
  2073         m_page->mainFrame()->loader()->setUseLowBandwidthDisplay(false);
       
  2074 #endif
       
  2075     }
       
  2076 
       
  2077     return m_widgetextension;
       
  2078 }
       
  2079 
       
  2080 //-------------------------------------------------------------------------------
       
  2081 //-------------------------------------------------------------------------------
       
  2082 void WebView::forceLayoutAndResize(WebFrame* frame)
       
  2083 {
       
  2084     if (frame) {
       
  2085         Frame* f = core(frame);
       
  2086         FrameView* v = f->view();
       
  2087         Document* doc = f->document();
       
  2088         if (v && doc) {
       
  2089             Node* node = doc;
       
  2090             while (node) {
       
  2091                 if (node->renderer()) {
       
  2092                     node->renderer()->setNeedsLayoutAndPrefWidthsRecalc();
       
  2093                     RenderStyle* style = node->renderer()->style();
       
  2094                     if (style) {
       
  2095                         RenderStyle* newstyle = new (node->renderer()->renderArena()) RenderStyle(*style);
       
  2096                         node->renderer()->setStyle(newstyle);
       
  2097                     }
       
  2098                 }
       
  2099                 node = node->traverseNextNode();
       
  2100             }
       
  2101             f->document()->recalcStyle(Node::Force);
       
  2102             v->setNeedsLayout();
       
  2103             v->layout();
       
  2104         }
       
  2105     }
       
  2106 }
       
  2107 
       
  2108 //-------------------------------------------------------------------------------
       
  2109 //-------------------------------------------------------------------------------
       
  2110 void WebView::showZoomSliderL()
       
  2111 {
       
  2112     if ( !inPageViewMode()) {
       
  2113         m_pageZoomHandler->showZoomSliderL();
       
  2114         if ( m_repainttimer->IsActive())
       
  2115         {
       
  2116             m_repainttimer->Cancel();
       
  2117         }
       
  2118     }
       
  2119     m_startZoomLevel = m_currentZoomLevel;
       
  2120 }
       
  2121 
       
  2122 //-------------------------------------------------------------------------------
       
  2123 //-------------------------------------------------------------------------------
       
  2124 void WebView::hideZoomSliderL()
       
  2125 {
       
  2126     if ( !inPageViewMode()) {
       
  2127         m_pageZoomHandler->hideZoomSliderL();
       
  2128     }
       
  2129 }
       
  2130 
       
  2131 //-------------------------------------------------------------------------------
       
  2132 //-------------------------------------------------------------------------------
       
  2133 void WebView::notifyZoomSliderModeChangeL( bool mode )
       
  2134 {
       
  2135     m_dirtyZoomMode = false;
       
  2136     clearOffScreenBitmap();
       
  2137     zoomLevelChanged( m_currentZoomLevel );
       
  2138     m_brctl->reportStateChanged(TBrCtlDefs::EStateZoomSliderMode, mode );
       
  2139 }
       
  2140 
       
  2141 //-------------------------------------------------------------------------------
       
  2142 //-------------------------------------------------------------------------------
       
  2143 int WebView::maxZoomLevel()
       
  2144 {
       
  2145     return m_maxZoomLevel;
       
  2146 }
       
  2147 
       
  2148 //-------------------------------------------------------------------------------
       
  2149 //-------------------------------------------------------------------------------
       
  2150 int WebView::minZoomLevel()
       
  2151 {
       
  2152     return m_minZoomLevel;
       
  2153 }
       
  2154 
       
  2155 //-------------------------------------------------------------------------------
       
  2156 //-------------------------------------------------------------------------------
       
  2157 void WebView::updateZoomLevel( TBrCtlDefs::TBrCtlSettings setting, unsigned int value)
       
  2158 {
       
  2159    switch( setting ) {
       
  2160        case TBrCtlDefs::ESettingsZoomLevelMax:
       
  2161        {
       
  2162         if (value != m_maxZoomLevel)
       
  2163           {
       
  2164       //maxzoomlevel is different, needs to reset the zoom
       
  2165           m_maxZoomLevel = value;
       
  2166           UpdateZoomArray();
       
  2167           }
       
  2168        }
       
  2169 
       
  2170             break;
       
  2171        case TBrCtlDefs::ESettingsZoomLevelDefault:
       
  2172             m_scrollingSpeed = KNormalScrollRange*100/scalingFactor();
       
  2173             break;
       
  2174 
       
  2175         default:
       
  2176             break;   // should not occur
       
  2177     }
       
  2178 }
       
  2179 
       
  2180 //-------------------------------------------------------------------------------
       
  2181 //-------------------------------------------------------------------------------
       
  2182 void WebView::EnterFullscreenBrowsingL()
       
  2183 {
       
  2184     if (m_pageFullScreenHandler) {
       
  2185          m_pageFullScreenHandler->showEscBtnL();
       
  2186          StaticObjectsContainer::instance()->setFullScreenMode(true);
       
  2187      }
       
  2188 }
       
  2189 
       
  2190 //-------------------------------------------------------------------------------
       
  2191 //-------------------------------------------------------------------------------
       
  2192 void WebView::LeaveFullscreenBrowsingL()
       
  2193 {
       
  2194     if (m_pageFullScreenHandler) {
       
  2195         m_pageFullScreenHandler->hideEscBtnL();
       
  2196         StaticObjectsContainer::instance()->setFullScreenMode(false);
       
  2197     }
       
  2198 }
       
  2199 
       
  2200 //-------------------------------------------------------------------------------
       
  2201 //-------------------------------------------------------------------------------
       
  2202 void WebView::notifyFullscreenModeChangeL(bool mode)
       
  2203 {
       
  2204     if (m_pageFullScreenHandler )
       
  2205          m_brctl->reportStateChanged(TBrCtlDefs::EStateFullscreenBrowsing, mode );
       
  2206 }
       
  2207 
       
  2208 //-------------------------------------------------------------------------------
       
  2209 //-------------------------------------------------------------------------------
       
  2210 void WebView::checkForZoomChange()
       
  2211 {
       
  2212      zoomLevelChanged(m_currentZoomLevel);
       
  2213 }
       
  2214 
       
  2215 
       
  2216 void WebView::activateVirtualKeyboard()
       
  2217 {
       
  2218     if (isEditable() && iCoeEnv->Fep()) {
       
  2219         fepTextEditor()->CancelEditingMode();
       
  2220         fepTextEditor()->UpdateEditingMode();
       
  2221         iCoeEnv->Fep()->HandleChangeInFocus();
       
  2222         fepTextEditor()->ActivatePenInputRequest();
       
  2223     }
       
  2224 }
       
  2225 
       
  2226 void WebView::Stop()
       
  2227 {
       
  2228     mainFrame()->stopLoading();
       
  2229 }
       
  2230 void WebView::synchRequestPending(bool flag)
       
  2231 {
       
  2232     m_synchRequestPending = flag;
       
  2233 
       
  2234     // TODO - nl - Disabled for now - there's no cursor in S60 5.0 release
       
  2235     //WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
  2236 
       
  2237     if (flag) {
       
  2238         m_brctl->reportStateChanged(TBrCtlDefs::EStateSynchRequestMode, ETrue);
       
  2239         //cursor->setWaitCursor(ETrue);
       
  2240         if (AknLayoutUtils::PenEnabled()) {
       
  2241             // Disable (block) pointer events
       
  2242             DrawableWindow()->SetPointerGrab(EFalse);
       
  2243         }
       
  2244     }
       
  2245     else {
       
  2246         if (AknLayoutUtils::PenEnabled()) {
       
  2247             // Reenable pointer events
       
  2248             DrawableWindow()->SetPointerGrab(ETrue);
       
  2249         }
       
  2250         //cursor->setWaitCursor(EFalse);
       
  2251         m_brctl->reportStateChanged(TBrCtlDefs::EStateSynchRequestMode, EFalse);
       
  2252     }
       
  2253 }
       
  2254 
       
  2255 void WebView::setHistoryLoad(bool value) {
       
  2256      m_historyLoad = value;
       
  2257 }
       
  2258 void WebView::setRedirectWithLockedHistory(bool value) {
       
  2259      m_redirectWithLockedHistory = value;
       
  2260 }
       
  2261 //-------------------------------------------------------------------------------
       
  2262 // Webview notifies plugins to handle play/pause of .swf files when user switches to menu/another application
       
  2263 //-------------------------------------------------------------------------------
       
  2264 void WebView::notifyPlugins(TBool focus)
       
  2265 {
       
  2266     Frame* coreFrame =core(mainFrame());
       
  2267     MWebCoreObjectWidget* view = NULL;
       
  2268     for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {
       
  2269         PassRefPtr<HTMLCollection> objects = frame->document()->objects();
       
  2270         for (Node* n = objects->firstItem(); n; n = objects->nextItem()) {
       
  2271             view = widget(n);
       
  2272             if (view) {
       
  2273                 static_cast<PluginSkin*>(view)->handlePluginForeground(focus);
       
  2274             }
       
  2275         }
       
  2276 
       
  2277         PassRefPtr<HTMLCollection> embeds = frame->document()->embeds();
       
  2278         for (Node* n = embeds->firstItem(); n; n = embeds->nextItem()) {
       
  2279             view = widget(n);
       
  2280             if (view) {
       
  2281                 static_cast<PluginSkin*>(view)->handlePluginForeground(focus);
       
  2282             }
       
  2283         }
       
  2284     }
       
  2285 }
       
  2286 
       
  2287 
       
  2288 void WebView::setFastScrollingMode(bool fastScrolling)
       
  2289 {
       
  2290   if (fastScrolling != m_viewIsFastScrolling) {
       
  2291   setViewIsFastScrolling (fastScrolling);
       
  2292   m_isPluginsVisible = false;
       
  2293   mainFrame()->makeVisiblePlugins(!m_viewIsFastScrolling);
       
  2294   m_isPluginsVisible = !m_viewIsFastScrolling;
       
  2295 
       
  2296   if (!m_viewIsFastScrolling) {
       
  2297     mainFrame()->notifyPluginsOfScrolling();
       
  2298   }
       
  2299   toggleRepaintTimer(!m_viewIsFastScrolling);
       
  2300 }
       
  2301 }
       
  2302 
       
  2303 void WebView::toggleRepaintTimer(bool on)
       
  2304 {
       
  2305   if ( m_repainttimer->IsActive()) {
       
  2306       m_repainttimer->Cancel();
       
  2307   }
       
  2308 
       
  2309   if (on) {
       
  2310       m_repainttimer->Start(0, 0, TCallBack( &doRepaintCb, this ) );
       
  2311   }
       
  2312   m_allowRepaints = on;
       
  2313 }
       
  2314 
       
  2315 
       
  2316 //-----------------------------------------------------------------------------
       
  2317 // setZoomCursorPosition(TBool)
       
  2318 // Set the cursor position while zooming, this is only for non-touch device
       
  2319 //-----------------------------------------------------------------------------
       
  2320 void WebView::setZoomCursorPosition(TBool isZoomIn)
       
  2321 {
       
  2322     int zoomLevel = m_currentZoomLevel;
       
  2323 
       
  2324     TInt index = FindCurrentZoomIndex(m_currentZoomLevel);
       
  2325     if (index == -1)
       
  2326     {
       
  2327         //Shouldn't happen -- do nothing
       
  2328         return;
       
  2329     }
       
  2330 
       
  2331     if (isZoomIn && index <=m_zoomLevelArray.Count()-2)
       
  2332     {
       
  2333         index++;
       
  2334         zoomLevel = m_zoomLevelArray[index];
       
  2335     }
       
  2336     else if (!isZoomIn && index > 0 )
       
  2337     {
       
  2338         index--;
       
  2339         zoomLevel = m_zoomLevelArray[index];
       
  2340     }
       
  2341 
       
  2342     // move the content
       
  2343     WebFrameView* view = mainFrame()->frameView();
       
  2344     if (!view) return;
       
  2345     WebCursor* cursor = StaticObjectsContainer::instance()->webCursor();
       
  2346     if (cursor) {
       
  2347 
       
  2348         TPoint pt = cursor->position();
       
  2349         int z = zoomLevel * 100 / m_currentZoomLevel;
       
  2350         int xOff = (pt.iX * z / 100 - pt.iX)*100/zoomLevel;
       
  2351         int yOff = (pt.iY * z / 100 - pt.iY)*100/zoomLevel;
       
  2352         TPoint cp = view->contentPos();
       
  2353         cp += TPoint(xOff, yOff);
       
  2354         view->setContentPos(cp);
       
  2355     }
       
  2356     //setZoomLevel(zoomLevel);
       
  2357     mainFrame()->notifyPluginsOfScrolling();
       
  2358 }
       
  2359 
       
  2360 
       
  2361 // ---------------------------------------------------------------------------
       
  2362 // FindCurrentZoomIndex
       
  2363 // ---------------------------------------------------------------------------
       
  2364 TInt WebView::FindCurrentZoomIndex(TInt aCurrentZoomLevel)
       
  2365 {
       
  2366     TInt aIndex = -1;
       
  2367 
       
  2368     for (aIndex=0; aIndex<m_zoomLevelArray.Count()-1; aIndex++)
       
  2369     {
       
  2370         TInt tmpZoomLevel = m_zoomLevelArray[aIndex];
       
  2371         if (aCurrentZoomLevel == m_zoomLevelArray[aIndex] )
       
  2372         {
       
  2373             break;
       
  2374         }
       
  2375     }
       
  2376     return aIndex;
       
  2377 }
       
  2378 
       
  2379 TInt WebView::getWidgetId()
       
  2380 {
       
  2381     return m_widgetextension ? m_widgetextension->GetWidgetId():0;
       
  2382 }
       
  2383 
       
  2384 void WebView::setShowCursor(TBool showCursor) 
       
  2385 {
       
  2386     m_showCursor = showCursor;
       
  2387     StaticObjectsContainer::instance()->webCursor()->setCursorVisible(showCursor);
       
  2388 }
       
  2389 
       
  2390 // END OF FILE