webengine/osswebengine/WebKit/s60/webview/WebCursor.cpp
changeset 1 7c90e6132015
parent 0 dd21522fd290
child 5 10e98eab6f85
equal deleted inserted replaced
0:dd21522fd290 1:7c90e6132015
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:   Implemetation of CWebKiCursor
    14 * Description:   Implementation of CWebKiCursor
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "config.h"
    19 #include "config.h"
    81     }
    81     }
    82 
    82 
    83 // ============================ MEMBER FUNCTIONS ===============================
    83 // ============================ MEMBER FUNCTIONS ===============================
    84 
    84 
    85 // -----------------------------------------------------------------------------
    85 // -----------------------------------------------------------------------------
    86 // CWebKitCursor::NewL
    86 // WebCursor::NewL
    87 // Two-phased constructor.
    87 // Two-phased constructor.
    88 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    89 WebCursor* WebCursor::NewL()
    89 WebCursor* WebCursor::NewL()
    90     {
    90     {
    91     WebCursor* self = new (ELeave) WebCursor();
    91     WebCursor* self = new (ELeave) WebCursor();
   130     m_transtimer = CPeriodic::NewL(CActive::EPriorityStandard);
   130     m_transtimer = CPeriodic::NewL(CActive::EPriorityStandard);
   131     m_visible = !AknLayoutUtils::PenEnabled();
   131     m_visible = !AknLayoutUtils::PenEnabled();
   132     }
   132     }
   133 
   133 
   134 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   135 // WebCursor::SetCurrentView
   135 // WebCursor::setCurrentView
   136 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   137 void WebCursor::setCurrentView(WebView& view)
   137 void WebCursor::setCurrentView(WebView& view)
   138     {
   138     {
   139     if (!m_view)
   139     if (!m_view)
   140     {
   140     {
   145     setOpaqueUntil(KTransparencyTime);
   145     setOpaqueUntil(KTransparencyTime);
   146     m_transcount = 0;
   146     m_transcount = 0;
   147     }
   147     }
   148 
   148 
   149 // -----------------------------------------------------------------------------
   149 // -----------------------------------------------------------------------------
   150 // WebCursor::ConstructSprite
   150 // WebCursor::constructSprite
   151 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   152 void WebCursor::constructSprite()
   152 void WebCursor::constructSprite()
   153     {
   153     {
   154 
   154 
   155     //tot:fixme
   155     //tot:fixme
   192     m_sprite.AppendMember(spriteMem);
   192     m_sprite.AppendMember(spriteMem);
   193     m_sprite.Activate();
   193     m_sprite.Activate();
   194     }
   194     }
   195 
   195 
   196 // -----------------------------------------------------------------------------
   196 // -----------------------------------------------------------------------------
   197 // WebCursor::CursorUpdate
   197 // WebCursor::setCursor
   198 // -----------------------------------------------------------------------------
   198 // -----------------------------------------------------------------------------
   199 void WebCursor::setCursor(CursorTypes type)
   199 void WebCursor::setCursor(CursorTypes type)
   200 {
   200 {
   201     m_sprite.SetPosition( m_pos );
   201     m_sprite.SetPosition( m_pos );
   202     m_type = type;
   202     m_type = type;
   203     if (m_visible) {
   203     if (m_visible && !(m_view->brCtl()->settings()->getTabbedNavigation())) {
   204         TSpriteMember spriteMem;
   204         TSpriteMember spriteMem;
   205         switch( type )
   205         switch( type )
   206             {
   206             {
   207             case PointerCursor:
   207             case PointerCursor:
   208             default:
   208             default:
   255         m_sprite.UpdateMember( 0, spriteMem );
   255         m_sprite.UpdateMember( 0, spriteMem );
   256     }
   256     }
   257 }
   257 }
   258 
   258 
   259 // -----------------------------------------------------------------------------
   259 // -----------------------------------------------------------------------------
   260 // WebCursor::CursorUpdate
   260 // WebCursor::cursorUpdate
   261 // -----------------------------------------------------------------------------
   261 // -----------------------------------------------------------------------------
   262 void WebCursor::cursorUpdate(bool visible)
   262 void WebCursor::cursorUpdate(bool visible)
   263 {
   263 {
   264     if (!m_view || !m_view->brCtl()->settings())
   264     if (!m_view || !m_view->brCtl()->settings())
   265         return;
   265         return;
   266     if ( m_view->showCursor() ) {
   266     if ( m_view->showCursor() ) {
   267         m_visible = visible && (!m_view->brCtl()->settings()->getTabbedNavigation() || m_view->focusedElementType() == TBrCtlDefs::EElementSelectMultiBox); // check for tabbedNavigation here because it is called from so many places.
   267         m_visible = visible && (!m_view->brCtl()->settings()->getTabbedNavigation() || m_view->focusedElementType() == TBrCtlDefs::EElementSelectMultiBox); // check for tabbedNavigation here because it is called from so many places.
   268     }
   268     }
   269     
   269 
   270     resetTransparency();
   270     resetTransparency();
   271     CursorTypes type = PointerCursor;
   271     CursorTypes type = PointerCursor;
   272     TBrCtlDefs::TBrCtlElementType elType = m_view->focusedElementType();
   272     TBrCtlDefs::TBrCtlElementType elType = m_view->focusedElementType();
       
   273 
   273     if (m_visible) {
   274     if (m_visible) {
   274         if (elType == TBrCtlDefs::EElementNone || elType == TBrCtlDefs::EElementBrokenImage)
   275         if      (    elType == TBrCtlDefs::EElementNone
       
   276                   || elType == TBrCtlDefs::EElementImageBox
       
   277                   || elType == TBrCtlDefs::EElementBrokenImage )
   275             type = PointerCursor;
   278             type = PointerCursor;
   276         else if (elType == TBrCtlDefs::EElementSmartLinkTel || elType == TBrCtlDefs::EElementSmartLinkEmail)
   279         else if (    elType == TBrCtlDefs::EElementSmartLinkTel
       
   280                   || elType == TBrCtlDefs::EElementSmartLinkEmail )
   277             type = IBeamCursor;
   281             type = IBeamCursor;
   278         else if (m_view->brCtl()->settings()->getTabbedNavigation() && elType == TBrCtlDefs::EElementSelectMultiBox)
   282         else if (    elType == TBrCtlDefs::EElementSelectMultiBox && m_view->brCtl()->settings()->getTabbedNavigation() )
   279             type = SelectMultiCursor;
   283             type = SelectMultiCursor;
   280         else
   284         else
   281             type = HandCursor;
   285             type = HandCursor;
   282     }
   286     }
       
   287 
   283     setCursor(type);
   288     setCursor(type);
   284 }
   289 }
   285 
   290 
   286 
   291 
   287 
   292 
   288 // -----------------------------------------------------------------------------
   293 // -----------------------------------------------------------------------------
   289 // CWebKitCursor::getFrameAtPoint
   294 // WebCursor::getFrameAtPoint
   290 // -----------------------------------------------------------------------------
   295 // -----------------------------------------------------------------------------
   291 WebFrame* WebCursor::getFrameAtPoint(const TPoint& viewPos_)
   296 WebFrame* WebCursor::getFrameAtPoint(const TPoint& viewPos_)
   292     {
   297     {
   293     if (!m_view)
   298     if (!m_view)
   294         return 0;
   299         return 0;
   297         frameAtPoint = m_view->mainFrame();
   302         frameAtPoint = m_view->mainFrame();
   298     return frameAtPoint;
   303     return frameAtPoint;
   299     }
   304     }
   300 
   305 
   301 // -----------------------------------------------------------------------------
   306 // -----------------------------------------------------------------------------
   302 // WebCursor::Reset
   307 // WebCursor::reset
   303 // -----------------------------------------------------------------------------
   308 // -----------------------------------------------------------------------------
   304 void WebCursor::reset()
   309 void WebCursor::reset()
   305     {
   310     {
   306     m_view->setFocusedElementType(TBrCtlDefs::EElementNone);
   311     m_view->setFocusedElementType(TBrCtlDefs::EElementNone);
   307     cursorUpdate(true);
   312     cursorUpdate(true);
   308     m_nodeRect = TRect();
   313     m_nodeRect = TRect();
   309     }
   314     }
   310 
   315 
   311 // -----------------------------------------------------------------------------
   316 // -----------------------------------------------------------------------------
   312 // WebCursor::SetWaitCursor
   317 // WebCursor::setWaitCursor
   313 // -----------------------------------------------------------------------------
   318 // -----------------------------------------------------------------------------
   314 void WebCursor::setWaitCursor(bool waiton)
   319 void WebCursor::setWaitCursor(bool waiton)
   315     {
   320     {
   316     m_waiton = waiton;
   321     m_waiton = waiton;
   317     if (m_waiton)
   322     if (m_waiton)
   319     else
   324     else
   320         cursorUpdate(m_visible);
   325         cursorUpdate(m_visible);
   321     }
   326     }
   322 
   327 
   323 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   324 // WebCursor::OffsetCursor
   329 // WebCursor::offsetCursor
   325 // -----------------------------------------------------------------------------
   330 // -----------------------------------------------------------------------------
   326 void WebCursor::offsetCursor(const TPoint& offset)
   331 void WebCursor::offsetCursor(const TPoint& offset)
   327     {
   332     {
   328     m_pos -= offset;
   333     m_pos -= offset;
   329     m_nodeRect.Move(-offset.iX,-offset.iY);
   334     m_nodeRect.Move(-offset.iX,-offset.iY);
   330     }
   335     }
   331 
   336 
   332 // -----------------------------------------------------------------------------
   337 // -----------------------------------------------------------------------------
   333 // WebCursor::SetTransparent
   338 // WebCursor::setTransparent
   334 // -----------------------------------------------------------------------------
   339 // -----------------------------------------------------------------------------
   335 void WebCursor::setTransparent(bool transparent)
   340 void WebCursor::setTransparent(bool transparent)
   336 {
   341 {
   337     if (transparent)
   342     if (transparent)
   338         m_transtimer->Cancel();
   343         m_transtimer->Cancel();
   345             cursorUpdate(m_visible);
   350             cursorUpdate(m_visible);
   346     }
   351     }
   347 }
   352 }
   348 
   353 
   349 // -----------------------------------------------------------------------------
   354 // -----------------------------------------------------------------------------
   350 // WebCursor::SetOpaqueUntil
   355 // WebCursor::setOpaqueUntil
   351 // -----------------------------------------------------------------------------
   356 // -----------------------------------------------------------------------------
   352 void WebCursor::setOpaqueUntil(int microsecs)
   357 void WebCursor::setOpaqueUntil(int microsecs)
   353     {
   358     {
   354     setTransparent(false);
   359     setTransparent(false);
   355     m_transtimer->Cancel();
   360     m_transtimer->Cancel();
   356     m_transtimer->Start(microsecs,0,TCallBack(TransparencyTimerCb,this));
   361     m_transtimer->Start(microsecs,0,TCallBack(TransparencyTimerCb,this));
   357     }
   362     }
   358 
   363 
   359 // -----------------------------------------------------------------------------
   364 // -----------------------------------------------------------------------------
   360 // WebCursor::IncreaseTransparencyMoveCount
   365 // WebCursor::increaseTransparencyMoveCount
   361 // -----------------------------------------------------------------------------
   366 // -----------------------------------------------------------------------------
   362 void WebCursor::increaseTransparencyMoveCount()
   367 void WebCursor::increaseTransparencyMoveCount()
   363     {
   368     {
   364     ++m_transcount;
   369     ++m_transcount;
   365     }
   370     }
   366 
   371 
   367 // -----------------------------------------------------------------------------
   372 // -----------------------------------------------------------------------------
   368 // WebCursor::ResetTransparency
   373 // WebCursor::resetTransparency
   369 // -----------------------------------------------------------------------------
   374 // -----------------------------------------------------------------------------
   370 void WebCursor::resetTransparency()
   375 void WebCursor::resetTransparency()
   371     {
   376     {
   372     m_transcount = 0;
   377     m_transcount = 0;
   373     setOpaqueUntil(KTransparencyTime);
   378     setOpaqueUntil(KTransparencyTime);
   554   return ret_frame;
   559   return ret_frame;
   555 }
   560 }
   556 
   561 
   557 
   562 
   558 //-------------------------------------------------------------------------------
   563 //-------------------------------------------------------------------------------
       
   564 // WebCursor::scrollAndMoveCursor
       
   565 //
   559 // Method that scrolls and moves the cursor based on the navigation algorithm
   566 // Method that scrolls and moves the cursor based on the navigation algorithm
   560 // TODO: Investigate "autoscroll" and diagonal events from real HW and the
   567 // TODO: Investigate "autoscroll" and diagonal events from real HW and the
   561 //       diagonal event simulator wedge.
   568 //       diagonal event simulator wedge.
   562 //-------------------------------------------------------------------------------
   569 //-------------------------------------------------------------------------------
   563 void WebCursor::scrollAndMoveCursor(int dir, int scrollRange, bool autoscroll)
   570 void WebCursor::scrollAndMoveCursor(int dir, int scrollRange, bool autoscroll)
   699         }
   706         }
   700     }
   707     }
   701 }
   708 }
   702 
   709 
   703 // -----------------------------------------------------------------------------
   710 // -----------------------------------------------------------------------------
   704 // WebCursor::setPosition
   711 // WebCursor::updatePositionAndElemType
   705 // -----------------------------------------------------------------------------
   712 // -----------------------------------------------------------------------------
   706 void WebCursor::updatePositionAndElemType(const TPoint& pt)
   713 void WebCursor::updatePositionAndElemType(const TPoint& pt)
   707 {
   714 {
   708     m_pos = pt;
   715     m_pos = pt;
   709     m_sprite.SetPosition(pt);
   716     m_sprite.SetPosition(pt);
   715         m_view->setFocusedElementType(elType);
   722         m_view->setFocusedElementType(elType);
   716     }
   723     }
   717 }
   724 }
   718 
   725 
   719 // -----------------------------------------------------------------------------
   726 // -----------------------------------------------------------------------------
   720 // WebCursor::movecursor
   727 // WebCursor::moveCursor
   721 // -----------------------------------------------------------------------------
   728 // -----------------------------------------------------------------------------
   722 void WebCursor::moveCursor(int lr,int tb, int scrollRange)
   729 void WebCursor::moveCursor(int lr,int tb, int scrollRange)
   723     {
   730     {
   724     TPoint cp(m_pos);
   731     TPoint cp(m_pos);
   725     int z = m_view->scalingFactor();
   732     int z = m_view->scalingFactor();
   817         return;
   824         return;
   818         }
   825         }
   819     }
   826     }
   820 
   827 
   821 
   828 
       
   829 // -----------------------------------------------------------------------------
       
   830 // WebCursor::navigableNodeUnderCursor
       
   831 // -----------------------------------------------------------------------------
   822 bool WebCursor::navigableNodeUnderCursor(WebFrame& webFrame, TPoint& aPoint, TBrCtlDefs::TBrCtlElementType& aElType, TRect& aFocusRect) const
   832 bool WebCursor::navigableNodeUnderCursor(WebFrame& webFrame, TPoint& aPoint, TBrCtlDefs::TBrCtlElementType& aElType, TRect& aFocusRect) const
   823 {
   833 {
   824     Frame* coreFrame = core(&webFrame);
   834     Frame* coreFrame = core(&webFrame);
   825     if (!coreFrame->renderer() )
   835     if (!coreFrame->renderer() )
   826         return false;
   836         return false;
   832     }
   842     }
   833 
   843 
   834     return false;
   844     return false;
   835 }
   845 }
   836 
   846 
       
   847 // -----------------------------------------------------------------------------
       
   848 // WebCursor::determineCursorPosition
       
   849 // -----------------------------------------------------------------------------
   837 bool WebCursor::determineCursorPosition( WebFrame& webFrame, TBrCtlDefs::TBrCtlElementType& aElType,
   850 bool WebCursor::determineCursorPosition( WebFrame& webFrame, TBrCtlDefs::TBrCtlElementType& aElType,
   838                                          TRect& aFocusRect, TRect& aSearchRect,
   851                                          TRect& aFocusRect, TRect& aSearchRect,
   839                                          TPoint &aCursorPosition, bool aInitialize)
   852                                          TPoint &aCursorPosition, bool aInitialize)
   840 {
   853 {
   841     // FIXME: cursor navigation not implemented
   854     // FIXME: cursor navigation not implemented
   866     aCursorPosition = newPos;
   879     aCursorPosition = newPos;
   867     return retest;
   880     return retest;
   868 }
   881 }
   869 
   882 
   870 
   883 
       
   884 // -----------------------------------------------------------------------------
       
   885 // WebCursor::calcSearchRect
       
   886 // -----------------------------------------------------------------------------
   871 TRect WebCursor::calcSearchRect(int lr, int tb, int scrollRange)
   887 TRect WebCursor::calcSearchRect(int lr, int tb, int scrollRange)
   872 {
   888 {
   873     TRect searchRect;
   889     TRect searchRect;
   874     TPoint pt(m_nodeRect.iTl);
   890     TPoint pt(m_nodeRect.iTl);
   875     TSize nodeSz(m_view->mainFrame()->frameView()->toDocCoords(m_nodeRect.Size()));
   891     TSize nodeSz(m_view->mainFrame()->frameView()->toDocCoords(m_nodeRect.Size()));
   896           increaseSearchRect(lr, tb, searchRect);
   912           increaseSearchRect(lr, tb, searchRect);
   897     }
   913     }
   898     return searchRect;
   914     return searchRect;
   899 }
   915 }
   900 
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // WebCursor::increaseSearchRect
       
   919 // -----------------------------------------------------------------------------
   901 void WebCursor::increaseSearchRect(int lr,int tb,TRect& aRect)
   920 void WebCursor::increaseSearchRect(int lr,int tb,TRect& aRect)
   902 {
   921 {
   903     int width(aRect.Width());
   922     int width(aRect.Width());
   904     int height(aRect.Height());
   923     int height(aRect.Height());
   905 
   924 
   916             aRect.iTl.iY -= height*KAggressiveSearch/100;           // up
   935             aRect.iTl.iY -= height*KAggressiveSearch/100;           // up
   917     }
   936     }
   918     m_flipCounter = 0;
   937     m_flipCounter = 0;
   919 }
   938 }
   920 
   939 
       
   940 // -----------------------------------------------------------------------------
       
   941 // WebCursor::decideCursorPosition
       
   942 // -----------------------------------------------------------------------------
   921 bool WebCursor::decideCursorPosition(WebFrame& webFrame, const IntRect& searchRect, IntPoint& cursorPosition)
   943 bool WebCursor::decideCursorPosition(WebFrame& webFrame, const IntRect& searchRect, IntPoint& cursorPosition)
   922 {
   944 {
   923     int distance = -1;
   945     int distance = -1;
   924     bool found = false;
   946     bool found = false;
   925     IntPoint cp = cursorPosition;
   947     IntPoint cp = cursorPosition;
   961     }
   983     }
   962 
   984 
   963     return found;
   985     return found;
   964 }
   986 }
   965 
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // WebCursor::getFrameUnderCursor
       
   990 // -----------------------------------------------------------------------------
   966 WebFrame* WebCursor::getFrameUnderCursor()
   991 WebFrame* WebCursor::getFrameUnderCursor()
   967 {
   992 {
   968   return getFrameAtPoint(m_pos);
   993   return getFrameAtPoint(m_pos);
   969 }
   994 }
   970 
   995