webengine/webkitutils/HistoryProvider/HistoryView.cpp
changeset 0 dd21522fd290
child 64 ac77f89b1d9e
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  History View
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <../bidi.h>
       
    22 #include    "HistoryView.h"
       
    23 #include    "HistoryController.h"
       
    24 #include    "HistoryEntry.h"
       
    25 #include    <coemain.h>
       
    26 #include    "WebSurface.h"
       
    27 #include "eikon.hrh"
       
    28 
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 //extern  ?external_data;
       
    32 
       
    33 // EXTERNAL FUNCTION PROTOTYPES
       
    34 //extern ?external_function( ?arg_type,?arg_type );
       
    35 
       
    36 // CONSTANTS
       
    37 const int KHistoryViewOffsetX = 2;
       
    38 const int KAutoScrollPeriodic = 300 * 1000;
       
    39 
       
    40 //Animation related factors
       
    41 const int KResizeFactorIncr = 20;
       
    42 const int KAnimFactorInc = 25;
       
    43 const int KDragDelta = 7;
       
    44 const int KFastScrollAnimFactorInc = 40;
       
    45 const int KMaxAnimFactor = 100;
       
    46 const int KMinAnimFactor = 0;
       
    47 const int KMinimumScroll = 20;
       
    48 
       
    49 #define KCenterImageBorderColor KRgbRed
       
    50 #define KSideImageBorderColor KRgbBlack
       
    51 
       
    52 // ============================= LOCAL FUNCTIONS ===============================
       
    53 
       
    54 TBool animRepaint(TAny* aAny)
       
    55 {
       
    56     HistoryView* historyView = static_cast<HistoryView*> (aAny);
       
    57     bool result = historyView->calcRepaintRect();
       
    58     return result;
       
    59 }
       
    60 
       
    61 TBool animPlaceHolderRepaint(TAny* aAny)
       
    62 {
       
    63     HistoryView* historyView = static_cast<HistoryView*> (aAny);
       
    64     bool result = historyView->animatePlaceHolderPosition();
       
    65     return result;
       
    66 }
       
    67 
       
    68 TInt autoScrollCallback( TAny* aPtr )
       
    69 {
       
    70     static_cast<HistoryView*>(aPtr)->autoScroll();
       
    71     return KErrNone;
       
    72 }
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // HistoryView::HistoryView
       
    78 // C++ default constructor can NOT contain any code, that
       
    79 // might leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 HistoryView::HistoryView(HistoryController& historyController, bool previous)
       
    83     : m_historyController( &historyController ),
       
    84     m_resizeFactor (KMinAnimFactor),
       
    85     m_placeHolderResizeFactor(KMinAnimFactor)
       
    86 {
       
    87     m_historyStackIndex = historyController.currentIndex();
       
    88     m_centerPageIndex = m_historyStackIndex;
       
    89     if (previous) {
       
    90         // we can assume that index is greater than 1 if ShowView
       
    91         // is invoked as a result of "Back" operation
       
    92         m_centerPageIndex--;
       
    93     }
       
    94 }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // ?HistoryView::ConstructL
       
    98 // Symbian 2nd phase constructor can leave.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void HistoryView::ConstructL()
       
   102 {
       
   103     CCoeControl* parent = m_historyController->historyCallback()->parent();
       
   104     SetContainerWindowL(*parent);
       
   105     m_repaintTimer = CIdle::NewL( CActive::EPriorityHigh );
       
   106     // rendering surface
       
   107     m_renderTarget = m_historyController->historyCallback()->surface();
       
   108     // Create an offscreen device and context
       
   109     m_bitmapDevice = CFbsBitmapDevice::NewL( m_renderTarget->offscreenBitmap() );
       
   110     User::LeaveIfError(m_bitmapDevice->CreateContext(m_bitmapContext));
       
   111     SetRect(parent->Rect());
       
   112     m_repaintTimer->Start(TCallBack(&animRepaint,this));
       
   113 }
       
   114 
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // HistoryView::NewL
       
   118 // Two-phased constructor.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 HistoryView* HistoryView::NewL(HistoryController& historyController, bool previous)
       
   122 {
       
   123     HistoryView* self = new( ELeave ) HistoryView(historyController, previous);
       
   124     CleanupStack::PushL( self );
       
   125     self->ConstructL();
       
   126     CleanupStack::Pop();
       
   127     return self;
       
   128 }
       
   129 
       
   130 
       
   131 // Destructor
       
   132 HistoryView::~HistoryView()
       
   133 {
       
   134     delete m_bitmapDevice;
       
   135     delete m_bitmapContext;
       
   136     if (m_repaintTimer->IsActive()) {
       
   137         m_repaintTimer->Cancel();
       
   138     }
       
   139     delete m_repaintTimer;
       
   140     if (m_autoScrollPeriodic) {
       
   141         m_autoScrollPeriodic->Cancel();
       
   142         delete m_autoScrollPeriodic;
       
   143     }
       
   144 }
       
   145 
       
   146 bool HistoryView::calcRepaintRect()
       
   147 {
       
   148     if (m_resizeFactor == KMaxAnimFactor) {
       
   149         m_repaintRect.SetRect(Rect().iTl,Rect().Size());
       
   150         m_historyController->updateDisplay();
       
   151         return false;
       
   152     }
       
   153     m_repaintRect.SetRect(Rect().iTl,TSize(Rect().Width()*m_resizeFactor/100,Rect().Height()*m_resizeFactor/100));
       
   154     m_resizeFactor += KResizeFactorIncr;
       
   155     m_historyController->updateDisplay();
       
   156     return true;
       
   157 }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // HistoryView::OfferKeyEventL
       
   161 // Processes Key Event
       
   162 // (other items were commented in a header).
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 TKeyResponse HistoryView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode )
       
   166 {
       
   167     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   168     m_fastScroll = false;
       
   169     // Determine the key event and handle it
       
   170     switch (aKeyEvent.iCode)
       
   171         {
       
   172         // The arrow key events
       
   173         case EKeyRightUpArrow:        // Northeast
       
   174         case EStdKeyDevice11:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   175         case EKeyRightArrow:          // East
       
   176         case EKeyRightDownArrow:      // Southeast
       
   177         case EStdKeyDevice12:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   178             {
       
   179                 if (aKeyEvent.iRepeats>0) {
       
   180                     m_fastScroll = true;
       
   181                 }
       
   182                 int historyLength = m_historyController->historyLength();
       
   183                 if (m_centerPageIndex < ( historyLength -1 )) {
       
   184                     m_direction = 1;
       
   185                     //Start Animation
       
   186                     if (m_repaintTimer->IsActive()) {
       
   187                         m_repaintTimer->Cancel();
       
   188                         m_resizeFactor = KMaxAnimFactor;
       
   189                     }
       
   190                     m_repaintTimer->Start(TCallBack(&animPlaceHolderRepaint,this));
       
   191                     keyResponse = EKeyWasConsumed;
       
   192                 }
       
   193                 break;
       
   194             }
       
   195 
       
   196         case EKeyLeftUpArrow:         // Northwest
       
   197         case EStdKeyDevice10:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   198         case EKeyLeftArrow:           // West
       
   199         case EKeyLeftDownArrow:       // Southwest
       
   200         case EStdKeyDevice13:         //   : Extra KeyEvent supports diagonal event simulator wedge
       
   201             {
       
   202                 if (aKeyEvent.iRepeats>0) {
       
   203                     m_fastScroll = true;
       
   204                 }
       
   205                 if (m_centerPageIndex > 0) {
       
   206                     m_direction = -1;
       
   207                     //Start Animation
       
   208                     if (m_repaintTimer->IsActive()) {
       
   209                         m_repaintTimer->Cancel();
       
   210                         m_resizeFactor = KMaxAnimFactor;
       
   211                     }
       
   212                     m_repaintTimer->Start(TCallBack(&animPlaceHolderRepaint,this));
       
   213                     keyResponse = EKeyWasConsumed;
       
   214                 }
       
   215                 break;
       
   216             }
       
   217 
       
   218 
       
   219             // The enter key events. aka activate key:
       
   220 
       
   221         case EKeyEnter:
       
   222         case EKeyDevice3:
       
   223             {
       
   224                 //history
       
   225                 int index = m_historyController->currentIndex();
       
   226                 HistoryEntry* entryCenter = m_historyController->entryByIndex( m_centerPageIndex );
       
   227                 HistoryEntry* entryCurrent = m_historyController->entryByIndex( index );
       
   228                 if (entryCenter && entryCenter->ifWml()) {   // look at last known history stack info if WML
       
   229                     m_historyController->setPossibleWmlOEB( false );
       
   230                     if (m_centerPageIndex < index ) {
       
   231                         m_historyController->setPossibleWmlOEB( true );  // this is always a possibility when navigating back to wml from html
       
   232                     }
       
   233                     if ( entryCurrent && entryCurrent->ifWml() == false || ((m_centerPageIndex != index) && ((m_centerPageIndex -1 ) != index) && ((m_centerPageIndex + 1) != index)) ) {
       
   234                         loadUrl();
       
   235                     }
       
   236                     else {
       
   237                         m_historyController->historyCallback()->handleWmlBackL();
       
   238                     }
       
   239                 }
       
   240                 else {
       
   241                     if (m_centerPageIndex != index)
       
   242                     {
       
   243                     	loadUrl();	
       
   244                     }
       
   245                 }
       
   246                 keyResponse = EKeyWasConsumed;
       
   247                 m_historyController->closeHistoryView();
       
   248                 break;
       
   249             }
       
   250 
       
   251         default:
       
   252             break;
       
   253         }
       
   254     return keyResponse;
       
   255 }
       
   256 
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // HistoryView::updateDisplay
       
   260 // Processes Key Event
       
   261 // (other items were commented in a header).
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void HistoryView::updateDisplay()
       
   265 {
       
   266     m_bitmapContext->Clear();
       
   267     m_bitmapContext->Reset();
       
   268 
       
   269     // updateDisplay something to the bitmap
       
   270     m_centerEntry = m_historyController->entryByIndex( m_centerPageIndex );
       
   271     HistoryEntry* leftEntry = m_historyController->entryByIndex( m_centerPageIndex-1 );
       
   272     HistoryEntry* rightEntry = m_historyController->entryByIndex( m_centerPageIndex+1 );
       
   273     if (leftEntry) {
       
   274         if (!leftEntry->thumbnail()) {
       
   275             TRAP_IGNORE(leftEntry->constructThumbnailL());
       
   276         }
       
   277         if (leftEntry->thumbnail()) {
       
   278             m_bitmapContext->BitBlt( m_leftPlaceHolderRect.iTl, leftEntry->thumbnail(), TRect(TPoint(0,0), m_leftPlaceHolderRect.Size()) );
       
   279         }
       
   280         m_bitmapContext->SetPenColor( KSideImageBorderColor );
       
   281         m_bitmapContext->DrawRect(m_leftPlaceHolderRect);
       
   282     }
       
   283     // updateDisplay the next thumbnail
       
   284     if (rightEntry) {
       
   285         if (!rightEntry->thumbnail()) {
       
   286             TRAP_IGNORE(rightEntry->constructThumbnailL());
       
   287         }
       
   288         if (rightEntry->thumbnail()) {
       
   289             m_bitmapContext->BitBlt( m_rightPlaceHolderRect.iTl, rightEntry->thumbnail(), TRect(TPoint(0,0), m_rightPlaceHolderRect.Size()) );
       
   290         }
       
   291         m_bitmapContext->SetPenColor( KSideImageBorderColor );
       
   292         m_bitmapContext->DrawRect(m_rightPlaceHolderRect);
       
   293     }
       
   294     // updateDisplay the center thumbnail
       
   295     if (m_centerEntry ) {
       
   296         if (!m_centerEntry->thumbnail()) {
       
   297             TRAP_IGNORE(m_centerEntry->constructThumbnailL());
       
   298         }
       
   299         if (m_centerEntry->thumbnail()) {
       
   300             m_bitmapContext->BitBlt( m_centerPlaceHolderRect.iTl, m_centerEntry->thumbnail(), TRect(TPoint(0,0), m_centerPlaceHolderRect.Size()) );
       
   301         }
       
   302     }
       
   303     m_bitmapContext->SetPenColor( KCenterImageBorderColor );
       
   304 
       
   305     m_bitmapContext->DrawRect( m_centerPlaceHolderRect );
       
   306 
       
   307     // Reset Brush
       
   308     m_bitmapContext->SetBrushColor(TRgb(255,255,255));
       
   309     m_bitmapContext->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   310   // updateState(-1);
       
   311 }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 // HistoryView::getCenterEntryTitle
       
   315 //
       
   316 // return page title of center entry
       
   317 // ----------------------------------------------------------------------------
       
   318 TPtrC HistoryView::getCenterEntryTitle()
       
   319 {
       
   320     if (m_direction == 0) {
       
   321         if ( m_centerEntry ) {
       
   322             return m_centerEntry->pageTitle();
       
   323         }
       
   324         return KNullDesC();
       
   325     }
       
   326     if (m_repaintTimer->IsActive()) {
       
   327         if (m_direction == 1) {
       
   328             return m_historyController->entryByIndex( m_centerPageIndex + 1)->pageTitle();
       
   329         }
       
   330         else {
       
   331             return m_historyController->entryByIndex( m_centerPageIndex - 1)->pageTitle();
       
   332         }
       
   333     }
       
   334     return TPtrC();
       
   335 }
       
   336 
       
   337 
       
   338 // ----------------------------------------------------------------------------
       
   339 // HistoryView::Draw
       
   340 //
       
   341 // Draws the bitmap
       
   342 // for the viewable content.
       
   343 // ----------------------------------------------------------------------------
       
   344 void HistoryView::Draw(const TRect& ) const
       
   345 {
       
   346     CWindowGc& gc = SystemGc();
       
   347     if (m_resizeFactor!=KMaxAnimFactor) {
       
   348         gc.DrawBitmap(m_repaintRect,m_renderTarget->offscreenBitmap());
       
   349         gc.DrawRect(Rect());
       
   350     }
       
   351     else {
       
   352         // put offscreen bitmap onto the screen
       
   353         gc.BitBlt( m_offscreenRect.iTl, m_renderTarget->offscreenBitmap());
       
   354     }
       
   355 }
       
   356 
       
   357 // ----------------------------------------------------------------------------
       
   358 // HistoryView::SetRect
       
   359 // public Class Method
       
   360 // Updates the size of the offscreen bitmap  to improve performance.
       
   361 // ----------------------------------------------------------------------------
       
   362 void HistoryView::SizeChanged()
       
   363 {
       
   364     if ( m_offscreenRect != Rect() ) {
       
   365         // Set the Offscreen rect adjusted for scrollbars
       
   366         m_offscreenRect = Rect();
       
   367         // need to resize the bitmap...
       
   368         updateOffscreenBitmapL();
       
   369         calculateLayout();
       
   370         updateDisplay();
       
   371         MakeVisible(true);
       
   372     }
       
   373 }
       
   374 
       
   375 void HistoryView::calculateLayout()
       
   376 {
       
   377     TSize screenSize = m_offscreenRect.Size();
       
   378     TSize viewSize((screenSize.iWidth -2*KHistoryViewOffsetX), screenSize.iHeight);
       
   379     int centerImageWidth(viewSize.iWidth*KCenterThumbnailWidthPercent/100);
       
   380     int centerImageHeight(viewSize.iHeight*KCenterThumbnailHeightPercent/100);
       
   381     TSize centerImageSize(centerImageWidth, centerImageHeight);
       
   382 
       
   383     int sideImageWidth(viewSize.iWidth*KSideThumbnailWidthPercent/100);
       
   384     int sideImageHeight(viewSize.iHeight*KSideThumbnailHeightPercent/100);
       
   385     TSize sideImageSize(sideImageWidth, sideImageHeight);
       
   386 
       
   387     int centerImageX(KHistoryViewOffsetX+sideImageWidth);
       
   388     int centerImageY(viewSize.iHeight*(100-KCenterThumbnailHeightPercent)/(2*100));
       
   389     TPoint centerImageOrigin(centerImageX, centerImageY);
       
   390 
       
   391     m_centerPlaceHolderRect.SetRect(centerImageOrigin, centerImageSize);
       
   392     int sideImageY(viewSize.iHeight*(100-KSideThumbnailHeightPercent)/(2*100));
       
   393     TPoint leftThumbnailOrigin( KHistoryViewOffsetX, sideImageY );
       
   394     TPoint rightThumbnailOrigin( (int)(KHistoryViewOffsetX+sideImageWidth+centerImageWidth), sideImageY );
       
   395 
       
   396     m_leftPlaceHolderRect.SetRect(leftThumbnailOrigin,sideImageSize);
       
   397     m_rightPlaceHolderRect.SetRect(rightThumbnailOrigin,sideImageSize);
       
   398 
       
   399     int xPos(m_centerPlaceHolderRect.iBr.iX - m_centerPlaceHolderRect.Size().iWidth/2);
       
   400     int yPos(m_centerPlaceHolderRect.iBr.iY);
       
   401     int dH(Rect().iBr.iY - m_centerPlaceHolderRect.iBr.iY - 6);
       
   402 
       
   403     m_leftArrow[0] = TPoint( KHistoryViewOffsetX + dH, yPos + 3 );
       
   404     m_leftArrow[1] = TPoint( KHistoryViewOffsetX + dH, yPos + dH );
       
   405     m_leftArrow[2] = TPoint( m_leftArrow[0].iX - (m_leftArrow[1].iY-m_leftArrow[0].iY), (m_leftArrow[0].iY + m_leftArrow[1].iY)/2);
       
   406 
       
   407     m_rightArrow[0] = TPoint( viewSize.iWidth - KHistoryViewOffsetX - dH, yPos + 3 );
       
   408     m_rightArrow[1] = TPoint( viewSize.iWidth - KHistoryViewOffsetX - dH, yPos + dH );
       
   409     m_rightArrow[2] = TPoint( m_rightArrow[0].iX+(m_rightArrow[1].iY-m_rightArrow[0].iY), (m_rightArrow[0].iY+m_rightArrow[1].iY)/2 );
       
   410 
       
   411 }
       
   412 
       
   413 bool HistoryView::animatePlaceHolderPosition()
       
   414 {
       
   415     if (m_placeHolderResizeFactor >= KMaxAnimFactor) {
       
   416         //Restore old values and end AO
       
   417         if (m_direction == 1) {
       
   418             m_centerPageIndex++;
       
   419             // delete thumbnail going out of the view
       
   420             HistoryEntry* entry = m_historyController->entryByIndex( m_centerPageIndex-2 );
       
   421             if (entry) {
       
   422                 entry->deleteThumbnail();
       
   423             }
       
   424         }
       
   425         if (m_direction == -1) {
       
   426             m_centerPageIndex--;
       
   427             // delete thumbnail going out of the view
       
   428             HistoryEntry* entry = m_historyController->entryByIndex( m_centerPageIndex+2 );
       
   429             if (entry) {
       
   430                 entry->deleteThumbnail();
       
   431             }
       
   432         }
       
   433         m_placeHolderResizeFactor = 0;
       
   434         m_direction = 0;
       
   435         updateDisplay();
       
   436         m_historyController->updateDisplay();
       
   437         return false;
       
   438     }
       
   439     TRect rect[4];
       
   440     int dw = 0;
       
   441     int dh = 0;
       
   442     int dx = 0;
       
   443     //left movement
       
   444     if (m_direction == -1) {
       
   445         TPoint pt(m_leftPlaceHolderRect.iTl.iX,m_leftPlaceHolderRect.iTl.iY+ m_leftPlaceHolderRect.Height()/2);
       
   446         rect[0] = TRect(pt,TSize(0,0));
       
   447         dw = m_leftPlaceHolderRect.Width()*m_placeHolderResizeFactor/200;
       
   448         dh = m_leftPlaceHolderRect.Height()*m_placeHolderResizeFactor/200;
       
   449         rect[0].Grow(dw,dh);
       
   450         rect[0].Move(dw,0);
       
   451 
       
   452         rect[1] = m_leftPlaceHolderRect;
       
   453         dx = (m_centerPlaceHolderRect.iTl.iX - m_leftPlaceHolderRect.iTl.iX)*m_placeHolderResizeFactor/100;
       
   454         dw = (m_centerPlaceHolderRect.Width() - m_leftPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   455         dh = (m_centerPlaceHolderRect.Height() - m_leftPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   456         rect[1].Grow(dw,dh);
       
   457         rect[1].Move(dx + dw,0);
       
   458 
       
   459         rect[2] = m_centerPlaceHolderRect;
       
   460         dx = (m_rightPlaceHolderRect.iTl.iX - m_centerPlaceHolderRect.iTl.iX)*m_placeHolderResizeFactor/100;
       
   461         dw = (m_centerPlaceHolderRect.Width() - m_rightPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   462         dh = (m_centerPlaceHolderRect.Height() - m_rightPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   463         rect[2].Shrink(dw,dh);
       
   464         rect[2].Move(dx - dw,0);
       
   465 
       
   466         rect[3] = m_rightPlaceHolderRect;
       
   467         dw = (m_rightPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   468         dh = (m_rightPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   469         rect[3].Shrink(dw,dh);
       
   470         rect[3].Move(2*dw,0);
       
   471 
       
   472         HistoryEntry* entry = 0;
       
   473         //Here we clear the rectangle where we are going to repaint
       
   474         m_bitmapContext->SetPenStyle(CGraphicsContext::ENullPen);
       
   475         m_bitmapContext->SetBrushColor(TRgb(255,255,255));
       
   476         m_bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   477         m_bitmapContext->DrawRect(TRect(TPoint(0,m_centerPlaceHolderRect.iTl.iY),TSize(Rect().Width(),m_centerPlaceHolderRect.Height())));
       
   478         for (int i = 0;i<4;i++)
       
   479         {
       
   480             entry = m_historyController->entryByIndex( m_centerPageIndex-2 + i );
       
   481             if (entry && entry->thumbnail())
       
   482             {
       
   483                 TRect intersectRect(TPoint(0,0),m_renderTarget->offscreenBitmap()->SizeInPixels());
       
   484                 intersectRect.Intersection(rect[i]);
       
   485                 if (!intersectRect.IsEmpty())
       
   486                 {
       
   487                     m_bitmapContext->BitBlt( intersectRect.iTl, entry->thumbnail(), TRect(TPoint(0,0), rect[i].Size()) );
       
   488                     m_bitmapContext->SetPenStyle(CGraphicsContext::ESolidPen);
       
   489                     m_bitmapContext->SetPenColor( KSideImageBorderColor );
       
   490                     m_bitmapContext->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   491                     m_bitmapContext->DrawRect(intersectRect);
       
   492                 }
       
   493             }
       
   494         }
       
   495     }
       
   496 
       
   497     if (m_direction == 1)
       
   498     {
       
   499         rect[0] = m_leftPlaceHolderRect;
       
   500         dw = m_leftPlaceHolderRect.Width()*m_placeHolderResizeFactor/200;
       
   501         dh = m_leftPlaceHolderRect.Height()*m_placeHolderResizeFactor/200;
       
   502         rect[0].Shrink(dw,dh);
       
   503         rect[0].Move(-2*dw,0);
       
   504 
       
   505         rect[1] = m_centerPlaceHolderRect;
       
   506         dx = (m_centerPlaceHolderRect.iTl.iX - m_leftPlaceHolderRect.iTl.iX)*m_placeHolderResizeFactor/100;
       
   507         dw = (m_centerPlaceHolderRect.Width() - m_leftPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   508         dh = (m_centerPlaceHolderRect.Height() - m_leftPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   509         rect[1].Shrink(dw,dh);
       
   510         rect[1].Move(-dx-dw,0);
       
   511 
       
   512         rect[2] = m_rightPlaceHolderRect;
       
   513         dx = (m_rightPlaceHolderRect.iTl.iX - m_centerPlaceHolderRect.iTl.iX)*m_placeHolderResizeFactor/100;
       
   514         dw = (m_centerPlaceHolderRect.Width() - m_rightPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   515         dh = (m_centerPlaceHolderRect.Height() - m_rightPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   516         rect[2].Grow(dw,dh);
       
   517         rect[2].Move(-dx + dw,0);
       
   518 
       
   519         TPoint pt(m_rightPlaceHolderRect.iTl.iX + m_rightPlaceHolderRect.Width(),m_rightPlaceHolderRect.iTl.iY+ m_rightPlaceHolderRect.Height()/2);
       
   520         rect[3] = TRect(pt,TSize(0,0));
       
   521         dw = (m_rightPlaceHolderRect.Width())*m_placeHolderResizeFactor/200;
       
   522         dh = (m_rightPlaceHolderRect.Height())*m_placeHolderResizeFactor/200;
       
   523         rect[3].Grow(dw,dh);
       
   524         rect[3].Move(-dw,0);
       
   525 
       
   526         HistoryEntry* entry = 0;
       
   527         //Here we clear the rectangle where we are going to repaint
       
   528         m_bitmapContext->SetPenStyle(CGraphicsContext::ENullPen);
       
   529         m_bitmapContext->SetBrushColor(TRgb(255,255,255));
       
   530         m_bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   531         m_bitmapContext->DrawRect(TRect(TPoint(0,m_centerPlaceHolderRect.iTl.iY),TSize(Rect().Width(),m_centerPlaceHolderRect.Height())));
       
   532         for (int i = 0;i<4;i++)
       
   533         {
       
   534             entry = m_historyController->entryByIndex( m_centerPageIndex- 1 +i);
       
   535             if (entry && !entry->thumbnail())
       
   536             {
       
   537                 TRAP_IGNORE(entry->constructThumbnailL());
       
   538             }
       
   539             if (entry && entry->thumbnail())
       
   540             {
       
   541                 TRect intersectRect(TPoint(0,0),m_renderTarget->offscreenBitmap()->SizeInPixels());
       
   542                 intersectRect.Intersection(rect[i]);
       
   543                 if (!intersectRect.IsEmpty())
       
   544                 {
       
   545                     m_bitmapContext->BitBlt( intersectRect.iTl, entry->thumbnail(), TRect(TPoint(0,0), rect[i].Size()) );
       
   546                     m_bitmapContext->SetPenStyle(CGraphicsContext::ESolidPen);
       
   547                     m_bitmapContext->SetPenColor( KSideImageBorderColor );
       
   548                     m_bitmapContext->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   549                     m_bitmapContext->DrawRect(intersectRect);
       
   550                 }
       
   551             }
       
   552         }
       
   553     }
       
   554     if (!m_fastScroll) {
       
   555         m_placeHolderResizeFactor += KAnimFactorInc;
       
   556     }
       
   557     else {
       
   558         m_placeHolderResizeFactor += KFastScrollAnimFactorInc;
       
   559     }
       
   560     m_historyController->updateDisplay();
       
   561     return true;
       
   562 }
       
   563 
       
   564 void HistoryView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   565 {
       
   566     TRect leftRect(m_leftArrow[2].iX,m_leftArrow[0].iY, m_leftArrow[1].iX, m_leftArrow[1].iY );
       
   567     TRect rightRect(m_rightArrow[0].iX,m_rightArrow[0].iY, m_rightArrow[2].iX, m_rightArrow[1].iY );
       
   568     if (aPointerEvent.iType == TPointerEvent::EButton1Down) {
       
   569         if (m_leftPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   570             m_historyViewComponent = EHistoryComponentLeftPlaceHolder;
       
   571         }
       
   572         else if (m_rightPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   573             m_historyViewComponent = EHistoryComponentRightPlaceHolder;
       
   574         }
       
   575         else if (m_centerPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   576             m_historyViewComponent = EHistoryComponentMiddlePlaceHolder;
       
   577         }
       
   578         else if (leftRect.Contains(aPointerEvent.iPosition)) {
       
   579             m_historyViewComponent = EHistoryComponentLeftArrow;
       
   580         }
       
   581         else if (rightRect.Contains(aPointerEvent.iPosition)) {
       
   582             m_historyViewComponent = EHistoryComponentRightArrow;
       
   583         }
       
   584         // Start repeat timer
       
   585         if (m_historyViewComponent == EHistoryComponentLeftArrow || m_historyViewComponent == EHistoryComponentRightArrow) {
       
   586             if (m_autoScrollPeriodic) {
       
   587                 m_autoScrollPeriodic->Cancel();
       
   588             }
       
   589             else {
       
   590                 m_autoScrollPeriodic = CPeriodic::NewL(CActive::EPriorityStandard);
       
   591             }
       
   592             m_autoScrollPeriodic->Start(KAutoScrollPeriodic, KAutoScrollPeriodic, TCallBack(&autoScrollCallback, this));
       
   593         }
       
   594     }
       
   595 
       
   596     if (aPointerEvent.iType == TPointerEvent::EButton1Down)  {
       
   597         m_lastpointerposition = aPointerEvent.iPosition;
       
   598     }
       
   599 
       
   600     if (aPointerEvent.iType == TPointerEvent::EDrag)  {
       
   601         if (Abs(m_lastpointerposition.iX - aPointerEvent.iPosition.iX) < KMinimumScroll )
       
   602             return;
       
   603         if (m_lastpointerposition.iX + KDragDelta < aPointerEvent.iPosition.iX ) {
       
   604             performTransition(-1);
       
   605         }
       
   606         else if (m_lastpointerposition.iX > aPointerEvent.iPosition.iX + KDragDelta){
       
   607             performTransition(1);
       
   608         }
       
   609         return;
       
   610     }
       
   611 
       
   612     if (aPointerEvent.iType == TPointerEvent::EButton1Up) {
       
   613         if (m_autoScrollPeriodic) {
       
   614             m_autoScrollPeriodic->Cancel();
       
   615         }
       
   616         if (Abs(m_lastpointerposition.iX - aPointerEvent.iPosition.iX) > KDragDelta ) return;
       
   617         TKeyEvent keyEvent;
       
   618         keyEvent.iModifiers = 0;
       
   619         keyEvent.iRepeats = 0;
       
   620         switch (m_historyViewComponent)
       
   621         {
       
   622         case EHistoryComponentNone:
       
   623         default:
       
   624             break;
       
   625         case EHistoryComponentLeftPlaceHolder:
       
   626             // Left entry
       
   627             if (m_leftPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   628                 if (m_centerPageIndex > 0) {
       
   629                     m_centerPageIndex--;
       
   630                     keyEvent.iCode = EKeyDevice3; //0x0000f842;
       
   631                     keyEvent.iScanCode = EStdKeyDevice3; //0x000000a7;
       
   632                     CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   633                 }
       
   634             }
       
   635             break;
       
   636         case EHistoryComponentMiddlePlaceHolder:
       
   637             // Center entry
       
   638             if (m_centerPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   639                 keyEvent.iCode = EKeyDevice3; //0x0000f842;
       
   640                 keyEvent.iScanCode = EStdKeyDevice3; //0x000000a7;
       
   641                 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   642             }
       
   643             break;
       
   644         case EHistoryComponentRightPlaceHolder:
       
   645             // Right entry
       
   646             if (m_rightPlaceHolderRect.Contains(aPointerEvent.iPosition)) {
       
   647                 int historyLength = m_historyController->historyLength();
       
   648                 if (m_centerPageIndex < ( historyLength -1 )) {
       
   649                     m_centerPageIndex++;
       
   650                     keyEvent.iCode = EKeyDevice3; //0x0000f842;
       
   651                     keyEvent.iScanCode = EStdKeyDevice3; //0x000000a7;
       
   652                     CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   653                 }
       
   654             }
       
   655             break;
       
   656         case EHistoryComponentLeftArrow:
       
   657             // Left arrow
       
   658             if (leftRect.Contains(aPointerEvent.iPosition)) {
       
   659                 keyEvent.iCode = EKeyLeftArrow;
       
   660                 keyEvent.iScanCode = EStdKeyLeftArrow;
       
   661                 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   662             }
       
   663             break;
       
   664         case EHistoryComponentRightArrow:
       
   665             // Right arrow
       
   666             if (rightRect.Contains(aPointerEvent.iPosition)) {
       
   667                 keyEvent.iCode = EKeyRightArrow;
       
   668                 keyEvent.iScanCode = EStdKeyRightArrow;
       
   669                 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKeyUp );
       
   670             }
       
   671             break;
       
   672         }
       
   673     }
       
   674     m_pointerEvent = aPointerEvent;
       
   675 }
       
   676 
       
   677 // ----------------------------------------------------------------------------
       
   678 // HistoryView::autoScroll()
       
   679 // Public Class Method
       
   680 // Called v=by timer callback when user presses an arrow and does not let go
       
   681 // ----------------------------------------------------------------------------
       
   682 void HistoryView::autoScroll()
       
   683 {
       
   684     if (m_historyViewComponent == EHistoryComponentLeftArrow) {
       
   685         TRect leftRect(m_leftArrow[2].iX,m_leftArrow[0].iY, m_leftArrow[1].iX, m_leftArrow[1].iY );
       
   686         if (leftRect.Contains(m_pointerEvent.iPosition)) {
       
   687             performTransition(-1);
       
   688         }
       
   689     }
       
   690     else if (m_historyViewComponent == EHistoryComponentRightArrow) {
       
   691         TRect rightRect(m_rightArrow[0].iX,m_rightArrow[0].iY, m_rightArrow[2].iX, m_rightArrow[1].iY );
       
   692         if (rightRect.Contains(m_pointerEvent.iPosition)) {
       
   693             performTransition(1);
       
   694         }
       
   695     }
       
   696 }
       
   697 
       
   698 // Private
       
   699 
       
   700 // ----------------------------------------------------------------------------
       
   701 // HistoryView::CreateOffscreenBitmapL
       
   702 // Private Class Method
       
   703 // Creates the bitmap offscreen to improve performance.  The bitmap is created
       
   704 // for the viewable content.
       
   705 // ----------------------------------------------------------------------------
       
   706 void HistoryView::updateOffscreenBitmapL()
       
   707 {
       
   708     m_renderTarget->setView( 0 );
       
   709     m_bitmapDevice->Resize( m_offscreenRect.Size() );
       
   710     m_bitmapContext->Resized();
       
   711 }
       
   712 
       
   713 // ----------------------------------------------------------------------------
       
   714 // HistoryView::LoadUrl()
       
   715 // Private Class Method
       
   716 // Get current url from history and call LoadUrlL(url)
       
   717 // ----------------------------------------------------------------------------
       
   718 void HistoryView::loadUrl()
       
   719 {
       
   720     const HistoryEntry* entry = m_historyController->entryByIndex( m_centerPageIndex );
       
   721     if ( entry ) {
       
   722         TPtrC8 url = entry->requestUrl();
       
   723         if (entry->postContentType().Length() && entry->formData()) {
       
   724             if ( m_historyController->historyCallback()->doHistoryPost(url, TBrCtlDefs::ECacheModeHistory,
       
   725                 entry->postContentType(), entry->formData()) == KErrNone) {
       
   726                 m_historyController->setCurrentIndex( m_centerPageIndex );
       
   727             }
       
   728         }
       
   729         else {
       
   730             m_historyController->setCurrentIndex( m_centerPageIndex );
       
   731             m_historyController->historyCallback()->doHistoryGet( url, TBrCtlDefs::ECacheModeHistory );
       
   732         }
       
   733     }
       
   734 }
       
   735 
       
   736 // ----------------------------------------------------------------------------
       
   737 // HistoryView::performTransition()
       
   738 // Private Class Method
       
   739 // Start animation
       
   740 // ----------------------------------------------------------------------------
       
   741 void HistoryView::performTransition(int dir)
       
   742 {
       
   743     if (dir == -1) {
       
   744        if (m_centerPageIndex > 0) {
       
   745            m_direction = -1;
       
   746            //Start Animation
       
   747            if (m_repaintTimer->IsActive()) {
       
   748                m_repaintTimer->Cancel();
       
   749                m_resizeFactor = KMaxAnimFactor;
       
   750            }
       
   751            m_repaintTimer->Start(TCallBack(&animPlaceHolderRepaint,this));
       
   752        }
       
   753     }
       
   754     else if (dir == 1)  {
       
   755           int historyLength = m_historyController->historyLength();
       
   756           if (m_centerPageIndex < ( historyLength -1 )) {
       
   757               m_direction = 1;
       
   758               //Start Animation
       
   759               if (m_repaintTimer->IsActive()) {
       
   760                   m_repaintTimer->Cancel();
       
   761                   m_resizeFactor = KMaxAnimFactor;
       
   762               }
       
   763               m_repaintTimer->Start(TCallBack(&animPlaceHolderRepaint,this));
       
   764           }
       
   765     }
       
   766 
       
   767     updateState(dir);
       
   768 }
       
   769 
       
   770 // ----------------------------------------------------------------------------
       
   771 // HistoryView::performTransition()
       
   772 // Private Class Method
       
   773 // Start animation
       
   774 // ----------------------------------------------------------------------------
       
   775 void HistoryView::updateState(int dir)
       
   776 {
       
   777     if (dir ==0)
       
   778     {
       
   779         if (m_centerPageIndex == 0) {
       
   780             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryBeginning, true);
       
   781         }
       
   782         else {
       
   783             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryBeginning, false);
       
   784         }
       
   785         if (m_centerPageIndex >= ( m_historyController->historyLength() - 1 )){
       
   786             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryEnd, true);
       
   787         }
       
   788         else {
       
   789             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryEnd, false);
       
   790         }
       
   791     }
       
   792     else
       
   793     {
       
   794         if ((dir == -1) && (m_centerPageIndex <= 1)) {
       
   795             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryBeginning, true);
       
   796         }
       
   797         else {
       
   798             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryBeginning, false);
       
   799         }
       
   800         if ((dir == 1) && (m_centerPageIndex >= ( m_historyController->historyLength() - 2 ))){
       
   801             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryEnd, true);
       
   802         }
       
   803         else {
       
   804             m_historyController->historyCallback()->navigationStateChanged(TBrCtlDefs::EStateHistoryEnd, false);
       
   805         }
       
   806 
       
   807     }
       
   808 }
       
   809 //  End of File