webengine/osswebengine/WebKit/s60/webview/WebFrameView.cpp
changeset 0 dd21522fd290
child 15 60c5402cb945
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Frame in webkit side
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "config.h"
       
    20 #include "../../bidi.h"
       
    21 #include "WebFrameView.h"
       
    22 #include "WebFrame.h"
       
    23 #include "WebView.h"
       
    24 #include "WebCursor.h"
       
    25 #include "WebFrameBridge.h"
       
    26 #include "WebCoreGraphicsContext.h"
       
    27 #include "GraphicsContext.h"
       
    28 #include "PlatformScrollbar.h"
       
    29 #include "PageScaler.h"
       
    30 #include "webkitlogger.h"
       
    31 #include "BrCtl.h"
       
    32 using namespace WebCore;
       
    33 
       
    34 WebFrameView::WebFrameView() : 
       
    35       m_parent(NULL),
       
    36       m_hasBorder(true),
       
    37       m_refCount(1)
       
    38 {
       
    39     m_hScrollbar = new WebCore::PlatformScrollbar(this, WebCore::HorizontalScrollbar, WebCore::RegularScrollbar);
       
    40     m_vScrollbar = new WebCore::PlatformScrollbar(this, WebCore::VerticalScrollbar, WebCore::RegularScrollbar); 
       
    41     m_horizontalScrollBarMode = ScrollbarAuto;
       
    42     m_verticalScrollBarMode = ScrollbarAuto;
       
    43 }
       
    44 
       
    45 WebFrameView::~WebFrameView() 
       
    46 {
       
    47     delete m_hScrollbar;
       
    48     delete m_vScrollbar;
       
    49 }
       
    50 
       
    51 void WebFrameView::setTopView(WebView* v)
       
    52 {
       
    53     m_topView = v;
       
    54 }
       
    55 
       
    56 void WebFrameView::setWebFrame(WebFrame* f)
       
    57 {
       
    58     m_frame = f;
       
    59 }
       
    60 
       
    61 WebFrameView* WebFrameView::initWithFrame(TRect frame)
       
    62 {
       
    63     setRect(frame);
       
    64     return this;
       
    65 }
       
    66 
       
    67 void WebFrameView::draw(WebCoreGraphicsContext& gc, const TRect& r)
       
    68 {
       
    69     TRect vr(visibleRect());
       
    70     TRect rect(r);
       
    71     if (isScaled() || m_frame->isFrameSet())
       
    72         rect.Grow(1,1);             // eliminate rounding errors
       
    73     TRect frameRect(m_frameRect);
       
    74 
       
    75     rect.Move(-frameRect.iTl);
       
    76     rect.Move(m_contentPos);
       
    77     if (vr.Intersects(rect)) {
       
    78         // save the gc state
       
    79         TWebCoreSavedContext saved(gc.save());
       
    80         // set the current frame
       
    81         gc.setView(*this);
       
    82 
       
    83         TPoint cpos(toViewCoords(m_contentPos));
       
    84 
       
    85         gc.setOrigin(gc.origin()+toViewCoords(m_frameRect.iTl)-cpos);
       
    86         rect.Intersection(vr);
       
    87         // calculate clip for zoom level
       
    88         TRect clip(toViewCoords(rect));
       
    89         
       
    90         // set clipping
       
    91         if (gc.hasClipping()) {
       
    92             TRect t(gc.clippingRect());
       
    93             t.Move(-toViewCoords(m_frameRect.iTl)+cpos);
       
    94             clip.Intersection(t);
       
    95         }
       
    96         
       
    97         gc.setClippingRect( clip );
       
    98 
       
    99         // draw frame content
       
   100         m_frame->paintRect(gc, rect);
       
   101         gc.cancelClipping();
       
   102         gc.setOrigin( gc.origin() + cpos);
       
   103         if (m_parent) {
       
   104             WebFrameView* parent = m_parent;
       
   105             TRect frameClip(0,0,KMaxTInt,KMaxTInt);
       
   106             do {
       
   107                 TRect pr = parent->visibleRect();
       
   108                 TRect fc(TRect(parent->frameCoordsInViewCoords(pr.iTl), parent->frameCoordsInViewCoords(pr.iBr))); 
       
   109                 frameClip.Intersection(fc);
       
   110                 parent = parent->m_parent;
       
   111             }
       
   112             while(parent);
       
   113             frameClip = TRect(viewCoordsInFrameCoords(frameClip.iTl), viewCoordsInFrameCoords(frameClip.iBr)); 
       
   114             frameClip = TRect(toViewCoords(frameClip));
       
   115             frameClip.Move(-cpos);
       
   116             gc.setClippingRect( frameClip );
       
   117         }
       
   118         // draw frame border
       
   119         CFbsBitGc& realgc = gc.gc();
       
   120         if (m_hasBorder && !m_frame->isFrameSet()) {
       
   121             // already moved the origin
       
   122             TRect borderRect(TPoint(-1,-1),toViewCoords(m_frameRect).Size());
       
   123             borderRect.iBr += TPoint(2,2);
       
   124             realgc.SetPenColor(TRgb(0x55,0x55,0x55));
       
   125             realgc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   126             realgc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   127             realgc.SetPenSize(TSize(1,1));
       
   128             realgc.DrawRect(borderRect);
       
   129             // double border in bottom/right
       
   130             borderRect.iBr += TPoint(1,1);
       
   131             realgc.DrawRect(borderRect);
       
   132         }
       
   133 
       
   134         // draw scrollbars
       
   135         rect.Move( -m_contentPos );
       
   136         WebCore::GraphicsContext ctx(&gc);
       
   137         if (m_vScrollbar->isEnabled())
       
   138             m_vScrollbar->paint(&ctx, rect);
       
   139         if (m_hScrollbar->isEnabled())
       
   140             m_hScrollbar->paint(&ctx, rect);
       
   141 
       
   142         gc.cancelClipping();
       
   143         gc.restore(saved);
       
   144     }
       
   145 }
       
   146 
       
   147 void WebFrameView::invalidateRect(const TRect& rect, TBool drawNow)
       
   148 {
       
   149     TRect r(rect);
       
   150     if (m_parent) {
       
   151         TRect frameRect(m_frameRect);
       
   152         r.Move(frameRect.iTl - m_contentPos);
       
   153         r.Intersection(frameRect);
       
   154         m_parent->invalidateRect(r, drawNow);
       
   155     }
       
   156     else {
       
   157         // fix rounding errors from zooming
       
   158         if (isScaled() || m_frame->isFrameSet())
       
   159             r.Grow(1,1);
       
   160     }
       
   161 
       
   162     if (!m_topView->isClosing()) {
       
   163         if(drawNow)
       
   164             m_topView->syncRepaint(r);
       
   165         else
       
   166             m_topView->scheduleRepaint(r);
       
   167     }
       
   168 }
       
   169 
       
   170 void WebFrameView::activate()
       
   171 {
       
   172 }
       
   173 
       
   174 void WebFrameView::setRect(const TRect& rect)
       
   175 {
       
   176     TRect frameRect(rect);
       
   177 
       
   178     if (m_frameRect!=frameRect) {
       
   179 
       
   180         m_frameRect = frameRect;
       
   181         checkScrollbarVisibility();
       
   182     }
       
   183 }
       
   184 
       
   185 int WebFrameView::getBidiWidth()
       
   186 {
       
   187     TInt bidiWidth = KMaxTInt;
       
   188     // don't limit bidi width for low subframes
       
   189     if (!(toViewCoords(m_frameRect).Height()<150 && m_parent))
       
   190         bidiWidth = m_topView->maxBidiSize().iWidth;
       
   191 
       
   192     return bidiWidth;
       
   193 }
       
   194 
       
   195 void WebFrameView::checkScrollbarVisibility()
       
   196 {
       
   197     if (!m_parent || m_parent->frame()->isFrameSet()) {
       
   198         m_vScrollbar->setEnabled(false);
       
   199         m_hScrollbar->setEnabled(false);
       
   200         return;
       
   201     }
       
   202     bool vScrollbar = m_vScrollbar->isEnabled();
       
   203     bool hScrollbar = m_hScrollbar->isEnabled();
       
   204     
       
   205     if (!m_allowsScrolling) {
       
   206         m_vScrollbar->setEnabled(false);
       
   207         m_hScrollbar->setEnabled(false);
       
   208         return;
       
   209     }
       
   210     TRect frameRect(m_frameRect);
       
   211     switch(m_verticalScrollBarMode) {
       
   212         default:
       
   213         case ScrollbarAlwaysOff:
       
   214             vScrollbar = false;
       
   215         break;
       
   216         case ScrollbarAlwaysOn:
       
   217             vScrollbar = true;
       
   218         break;
       
   219         case ScrollbarAuto:
       
   220             vScrollbar = contentSize().iHeight > frameRect.Height();
       
   221         break;
       
   222     }
       
   223 
       
   224     switch(m_horizontalScrollBarMode) {
       
   225         default:
       
   226         case ScrollbarAlwaysOff:
       
   227             hScrollbar = false;
       
   228         break;
       
   229         case ScrollbarAlwaysOn:
       
   230             hScrollbar = false;
       
   231         break;
       
   232         case ScrollbarAuto:
       
   233             hScrollbar = contentSize().iWidth > frameRect.Width();
       
   234         break;
       
   235     }
       
   236     
       
   237     m_hScrollbar->setEnabled(hScrollbar);
       
   238     m_vScrollbar->setEnabled(vScrollbar);
       
   239 
       
   240     TRect r(TPoint(0,0), frameRect.Size() - TSize(vScrollbar? KScrollbarWidth : 0, hScrollbar ? KScrollbarWidth : 0));
       
   241     if (hScrollbar) {
       
   242         m_hScrollbar->setRect(TRect(TPoint(r.iTl.iX, r.iBr.iY ), TSize(r.Width(), KScrollbarWidth)));
       
   243         m_hScrollbar->setProportion(r.Width(), m_contentSize.iWidth);
       
   244     }
       
   245 
       
   246     if (vScrollbar)  {
       
   247         m_vScrollbar->setRect(TRect(TPoint(r.iBr.iX, r.iTl.iY), TSize(KScrollbarWidth, r.Height())));
       
   248         m_vScrollbar->setProportion(r.Height(), m_contentSize.iHeight);
       
   249     }
       
   250 }
       
   251 
       
   252 void WebFrameView::setCursor(CursorTypes cursorType)
       
   253 {
       
   254     if (m_topView && StaticObjectsContainer::instance()->webCursor())
       
   255         StaticObjectsContainer::instance()->webCursor()->setCursor(cursorType);
       
   256 }
       
   257 
       
   258 void WebFrameView::setParent(MScrollView* parent)
       
   259 {
       
   260     m_parent = static_cast<WebFrameView*>(parent);
       
   261 }
       
   262 
       
   263 TRect WebFrameView::rect() const
       
   264 {
       
   265     return m_frameRect;
       
   266 }
       
   267 
       
   268 TRect WebFrameView::visibleRect() const
       
   269 {
       
   270     TSize s(m_frameRect.Size());
       
   271     return TRect(m_contentPos, s );
       
   272 }
       
   273 
       
   274 void WebFrameView::scrollTo(const TPoint& aPoint)
       
   275 {
       
   276     if (m_parent) {
       
   277         // tot:fixme frame scrolling when frame-flat is off
       
   278         if (m_frame->isIframe()) {
       
   279             // iframe, support scrolling
       
   280             if (aPoint != m_contentPos) {
       
   281                 TPoint p(nearestPointInFrame(aPoint));
       
   282                 m_contentPos = p;
       
   283                 m_frame->notifyPluginsOfScrolling();
       
   284                 m_topView->syncRepaint( TRect(0,0,KMaxTInt/2,KMaxTInt/2) );
       
   285             }
       
   286         }
       
   287         else {
       
   288             if (aPoint.iX==0 && aPoint.iY==0) {
       
   289                 // this gets called for all frames during loading, needs to be ignored (breaks some cases though)
       
   290                 return;
       
   291             }
       
   292 
       
   293             TPoint p(0, aPoint.iY); // don't to x shifts, they are confusing here
       
   294             // subframes don't scroll in the current implementation, scroll the main frame
       
   295             p += toDocCoords(rectInGlobalCoords().iTl);
       
   296             m_topView->mainFrame()->frameView()->scrollTo(p);
       
   297         }
       
   298     }
       
   299     else {
       
   300         // main frame, scroll
       
   301         if (aPoint != m_contentPos) {
       
   302             TPoint p( nearestPointInFrame(aPoint) );
       
   303             TBool copyScroll = m_mayUseCopyScroll;
       
   304 
       
   305             if( p != aPoint && m_topView->inFindState() ) {
       
   306                 p = aPoint;
       
   307                 m_topView->clearOffScreenBitmap();
       
   308                 copyScroll = EFalse;
       
   309             }
       
   310 
       
   311             TPoint from( toViewCoords(m_contentPos) );
       
   312             TPoint to( toViewCoords(p) );
       
   313 
       
   314             m_topView->scrollBuffer(to, from, copyScroll);
       
   315             m_contentPos = p;
       
   316 
       
   317             
       
   318             m_frame->notifyPluginsOfScrolling();
       
   319             
       
   320             
       
   321             if( m_topView->pageScaler() && m_topView->pageScaler()->Visible())
       
   322                 m_topView->pageScaler()->DocumentViewportMoved();
       
   323 
       
   324             //Update scroll bar , thumb position
       
   325             m_topView->updateScrollbars(m_contentSize.iHeight, m_contentPos.iY, m_contentSize.iWidth, m_contentPos.iX);
       
   326             
       
   327             // trigger painting
       
   328             m_topView->syncRepaint();
       
   329         }
       
   330     }
       
   331 }
       
   332 
       
   333 
       
   334 bool WebFrameView::needScroll(const TPoint& aPoint)
       
   335 {
       
   336     bool rv = false;
       
   337     if (m_parent) {
       
   338         if (m_frame->isIframe()) {
       
   339             if (aPoint != m_contentPos) {
       
   340                 rv = true;
       
   341             }
       
   342         }
       
   343         else {
       
   344             if (!(aPoint.iX==0 && aPoint.iY==0)){
       
   345                  rv = true;
       
   346             }
       
   347         }
       
   348     }
       
   349     else {
       
   350         // main frame
       
   351         if (aPoint != m_contentPos) {
       
   352             TPoint p( nearestPointInFrame(aPoint) );
       
   353             TBool copyScroll = m_mayUseCopyScroll;
       
   354 
       
   355             if( m_contentPos != p ){
       
   356                 rv = true;
       
   357             }
       
   358         }
       
   359     }
       
   360     return rv;
       
   361 }
       
   362 
       
   363 TPoint WebFrameView::nearestPointInFrame(const TPoint &aPoint)
       
   364 {
       
   365     if( m_parent && !m_frame->isIframe() ) return aPoint;
       
   366     TSize frameSize( m_frameRect.Size() );
       
   367     TPoint p(aPoint);
       
   368     p.iX = Min(contentSize().iWidth - frameSize.iWidth, p.iX);
       
   369     p.iY = Min(contentSize().iHeight - frameSize.iHeight, p.iY);
       
   370     p.iX = Max(0, p.iX);
       
   371     p.iY = Max(0, p.iY);
       
   372 
       
   373     return p;
       
   374 }
       
   375 
       
   376 void WebFrameView::resizeContent(const TSize &size)
       
   377 {
       
   378 
       
   379     if (!m_parent) {
       
   380         if (m_topView->brCtl()->capabilities()&TBrCtlDefs::ECapabilityFitToScreen) {
       
   381             if( size.iHeight != 0 && size.iWidth != 0 ){
       
   382                 m_topView->updateMinZoomLevel(size);
       
   383             }
       
   384         }
       
   385     }
       
   386 
       
   387     if (size != m_contentSize) {
       
   388 
       
   389         m_resizeByEngine = ETrue;
       
   390         m_contentSize = size;
       
   391         checkScrollbarVisibility();
       
   392         
       
   393         //maybe the content got smaller and we need to scroll back to view?
       
   394         TPoint p( nearestPointInFrame(m_contentPos) );
       
   395         if (p!=m_contentPos)
       
   396             // this will also update scrollbars is necessary
       
   397             scrollTo(p);
       
   398         else if (!m_parent) {
       
   399             // top level
       
   400             m_topView->updateScrollbars(m_contentSize.iHeight, m_contentPos.iY, m_contentSize.iWidth, m_contentPos.iX);
       
   401         }
       
   402     }
       
   403 }
       
   404 
       
   405 void WebFrameView::setMayUseCopyScroll(TBool aCopy)
       
   406 {
       
   407     m_mayUseCopyScroll = aCopy;
       
   408 }
       
   409 
       
   410 TPoint WebFrameView::convertContentToView(const TPoint& aConvert)
       
   411 {
       
   412     return frameCoordsInViewCoords(aConvert);
       
   413 }
       
   414 
       
   415 TPoint WebFrameView::convertViewToContent(const TPoint& aConvert)
       
   416 {
       
   417     return viewCoordsInFrameCoords( aConvert );
       
   418 }
       
   419 
       
   420 TBool WebFrameView::hasHorizontalScrollbar() const 
       
   421 {
       
   422     return m_vScrollbar != NULL;
       
   423 }
       
   424 
       
   425 TBool WebFrameView::hasVerticalScrollbar() const
       
   426 {
       
   427     return m_hScrollbar != NULL;
       
   428 }
       
   429 
       
   430 void WebFrameView::setHorizontalScrollingMode(ScrollbarMode aMode)
       
   431 {
       
   432     m_horizontalScrollBarMode = aMode;
       
   433     checkScrollbarVisibility();
       
   434 }
       
   435 
       
   436 WebCore::ScrollbarMode WebFrameView::verticalScrollingMode() 
       
   437 {
       
   438     return m_verticalScrollBarMode;
       
   439 }
       
   440 
       
   441 void WebFrameView::setVerticalScrollingMode(ScrollbarMode aMode)
       
   442 {
       
   443     m_verticalScrollBarMode = aMode;
       
   444     checkScrollbarVisibility();
       
   445 }
       
   446 
       
   447 WebCore::ScrollbarMode WebFrameView::horizontalScrollingMode()
       
   448 {
       
   449     return m_horizontalScrollBarMode;
       
   450 }
       
   451 
       
   452 void WebFrameView::setScrollingMode(ScrollbarMode aMode)
       
   453 {
       
   454     setHorizontalScrollingMode(aMode);
       
   455     setVerticalScrollingMode(aMode);
       
   456 }
       
   457 
       
   458 void WebFrameView::setScrollbarsSuppressed(TBool /*aSuppressed*/,TBool /*aRepaintOnUnsuppress*/ )
       
   459 {
       
   460     // ### NOT IMPLEMENTED
       
   461 }
       
   462 
       
   463 void WebFrameView::addChild(MWebCoreWidget* aChild)
       
   464 {
       
   465     if(aChild)
       
   466         aChild->setParent(this);
       
   467 }
       
   468 
       
   469 TInt WebFrameView::scalingFactor() const
       
   470 {
       
   471     if (m_topView)
       
   472         return m_topView->scalingFactor();
       
   473     return 100;
       
   474 }
       
   475 
       
   476 TPoint WebFrameView::viewCoordsInFrameCoords(const TPoint &aPoint)
       
   477 {
       
   478     TPoint pt = aPoint;
       
   479 
       
   480     pt += toViewCoords(m_contentPos);
       
   481     WebFrameView* pv = m_parent;
       
   482     while(pv)
       
   483         {
       
   484         pt += pv->toViewCoords(pv->m_contentPos);
       
   485         pv = pv->m_parent;
       
   486         }
       
   487 
       
   488     pt -= rectInGlobalCoords().iTl;
       
   489     pt = m_topView->mainFrame()->frameView()->toDocCoords(pt);
       
   490     return pt;
       
   491 }
       
   492 
       
   493 TPoint WebFrameView::frameCoordsInViewCoords(const TPoint &aPoint)
       
   494 {
       
   495     TPoint pt(aPoint);
       
   496 
       
   497     pt = m_topView->mainFrame()->frameView()->toViewCoords(aPoint);
       
   498     pt += rectInGlobalCoords().iTl;
       
   499     pt -= toViewCoords(m_contentPos);
       
   500     WebFrameView* pv= m_parent;
       
   501     while(pv)
       
   502         {
       
   503         pt -= pv->toViewCoords(pv->m_contentPos);
       
   504         pv = pv->m_parent;
       
   505         }
       
   506     return pt;
       
   507 }
       
   508 
       
   509 TRect WebFrameView::rectInGlobalCoords() const
       
   510 {
       
   511     TRect rect(toViewCoords(m_frameRect));
       
   512 
       
   513     for (WebFrameView* p = m_parent; p; p=p->m_parent)
       
   514         rect.Move(toViewCoords(p->m_frameRect.iTl));
       
   515 
       
   516     return rect;
       
   517 }
       
   518 
       
   519 void WebFrameView::setNeedsDisplay(TBool n) 
       
   520 {
       
   521 }
       
   522 
       
   523 void WebFrameView::setFocus(TBool aFocus) 
       
   524 {
       
   525 }
       
   526 
       
   527 void WebFrameView::makeVisible(TBool aVisible) 
       
   528 {
       
   529 }
       
   530 
       
   531 TBool WebFrameView::isFocused() const
       
   532 {
       
   533     return ETrue;
       
   534 }
       
   535 
       
   536 TBool WebFrameView::isVisible() const
       
   537 {
       
   538     return ETrue;
       
   539 }
       
   540 
       
   541 TSize WebFrameView::contentSize() const
       
   542 {
       
   543     return m_contentSize;
       
   544 }
       
   545 
       
   546 void WebFrameView::setAllowsScrolling(bool allowsScrolling)
       
   547 {
       
   548     m_allowsScrolling = allowsScrolling;
       
   549 }
       
   550 
       
   551 void WebFrameView::setMarginWidth(int marginWidth)
       
   552 {
       
   553 }
       
   554 
       
   555 void WebFrameView::setMarginHeight(int marginHeight)
       
   556 {
       
   557 }
       
   558 
       
   559 int WebFrameView::marginWidth() const
       
   560 {
       
   561     return 0;
       
   562 }
       
   563 
       
   564 int WebFrameView::marginHeight() const 
       
   565 {
       
   566     return 0;
       
   567 }
       
   568 
       
   569 WebFrameView* WebFrameView::viewClassForMIMEType(const WebCore::String& MIMEType) 
       
   570 {
       
   571     return NULL;
       
   572 }
       
   573 
       
   574 void WebFrameView::valueChanged(WebCore::Scrollbar*) 
       
   575 {
       
   576 }
       
   577 
       
   578 WebCore::IntRect WebFrameView::windowClipRect() const
       
   579 {
       
   580     return WebCore::IntRect();
       
   581 }
       
   582 
       
   583 void WebFrameView::setContentPos(TPoint pt)
       
   584 {
       
   585     m_contentPos = pt;
       
   586 }
       
   587 
       
   588 // END OF FILE