browsercore/appfw/Api/Views/WidgetView.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2009 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 "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "../../webkit/WebCore/platform/SharedTimer.h"
       
    20 
       
    21 #include <QDebug>
       
    22 #include <QObject>
       
    23 #include <QMenu>
       
    24 
       
    25 #include "WidgetView_p.h"
       
    26 #include "WidgetView.h"
       
    27 #include "WrtPageManager.h"
       
    28 #include "wrtbrowsercontainer.h"
       
    29 
       
    30 
       
    31 namespace WRT {
       
    32 
       
    33 WidgetViewPrivate::WidgetViewPrivate(WrtPageManager * mgr, QWidget* parent) :
       
    34     m_pageManager(mgr),
       
    35     m_widgetParent(parent),
       
    36     m_graphicsWidgetParent(0),
       
    37     m_isActive(false)
       
    38 {
       
    39     // Verify/Create Page Manager
       
    40     Q_ASSERT(m_pageManager);
       
    41 }
       
    42 
       
    43 WidgetViewPrivate::WidgetViewPrivate(WrtPageManager * mgr, QGraphicsWidget* parent) :
       
    44     m_pageManager(mgr),
       
    45     m_widgetParent(0),
       
    46     m_graphicsWidgetParent(parent),
       
    47     m_isActive(false)
       
    48 {
       
    49     // Verify/Create Page Manager
       
    50     Q_ASSERT(m_pageManager);
       
    51 }
       
    52 
       
    53 WidgetViewPrivate::~WidgetViewPrivate()
       
    54 {
       
    55 }
       
    56 
       
    57 /*!
       
    58  * \class WidgetView
       
    59  *
       
    60  * \brief the public view for web widget application content
       
    61  *
       
    62  * This class is responsible for....
       
    63  */
       
    64 
       
    65 /*!
       
    66   Basic WidgetView constructor requires a PageManager to manage the pages
       
    67   and a parent QWidget
       
    68   @param mgr : WrtPageManager handle for this class
       
    69   @param parent : Widget parent for this class
       
    70   @see  WrtPageManager
       
    71 */
       
    72 WidgetView::WidgetView(WrtPageManager * mgr, QWidget* parent) :
       
    73     d(new WidgetViewPrivate(mgr,parent))
       
    74 {
       
    75 }
       
    76 
       
    77 /*!
       
    78   Basic WidgetView constructor requires a PageManager to manage the pages
       
    79   and a parent QGraphicsWidget
       
    80   Note: This functionality is not yet tested
       
    81   @param mgr : WrtPageManager handle for this class
       
    82   @param parent : Graphics Widget parent for this class
       
    83   @see  WrtPageManager
       
    84  
       
    85 */
       
    86 WidgetView::WidgetView(WrtPageManager * mgr, QGraphicsWidget* parent) :
       
    87     d(new WidgetViewPrivate(mgr,parent))
       
    88 {
       
    89 }
       
    90 
       
    91 WidgetView::~WidgetView()
       
    92 {
       
    93     delete d;
       
    94 }
       
    95 
       
    96 /*! 
       
    97   Retrieve the WrtPageManager associated with this ContentView
       
    98   @return  : WrtPageManager handle for this page
       
    99 */
       
   100 WrtPageManager * WidgetView::wrtPageManager()
       
   101 {
       
   102     return d->m_pageManager;
       
   103 }
       
   104 
       
   105 /*!
       
   106   Show the current web widget
       
   107 */
       
   108 void WidgetView::show()
       
   109 {
       
   110     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   111     
       
   112     if (currPage)
       
   113     {        
       
   114         currPage->webWidget()->show();
       
   115         currPage->widgetContainer()->notifyWidget(WRT::WidgetContainer::WrtWidgetOnshow);
       
   116         // start shared timers
       
   117         currPage->deferTimers(false);
       
   118     }
       
   119 }
       
   120 
       
   121 /*!
       
   122   Hide the current web widget
       
   123 */
       
   124 void WidgetView::hide()
       
   125 {
       
   126     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   127     if (currPage)
       
   128     {
       
   129         currPage->webWidget()->hide();
       
   130         currPage->widgetContainer()->notifyWidget(WRT::WidgetContainer::WrtWidgetOnhide);
       
   131         // stop shared timers
       
   132         currPage->deferTimers(true);
       
   133     }
       
   134 }
       
   135 
       
   136 /*!
       
   137   Return the web widgets qt widget handle of this view
       
   138   @return : Widget handle for this class
       
   139 */
       
   140 QWidget* WidgetView::widget()
       
   141 {
       
   142     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   143     Q_ASSERT(currPage);
       
   144     QWidget * webWidget = currPage->webWidget();
       
   145     return webWidget;
       
   146 }
       
   147 
       
   148 /*!
       
   149   Return the title of this view for display
       
   150   @return : Title string
       
   151 */
       
   152 QString WidgetView::title()
       
   153 {
       
   154     return d->m_pageManager->title();
       
   155 }
       
   156 
       
   157 /*!
       
   158   Tests if  this view is active or not
       
   159   @return true if view is active else false
       
   160 */
       
   161 bool WidgetView::isActive()
       
   162 {
       
   163     return d->m_isActive;
       
   164 }
       
   165 
       
   166 /*! 
       
   167   Return the list of public QActions most relevant to the view's current context
       
   168   (most approptiate for contextual menus, etc.)
       
   169   @return : list of pulicactions for this view.
       
   170 */
       
   171 QList<QAction*> WidgetView::getContext()
       
   172 {
       
   173     // for now, just return all actions, add logic throughout later
       
   174     QList<QAction*> contextList;
       
   175     return contextList;
       
   176 }
       
   177 
       
   178 QMenu* WidgetView::getMenu()
       
   179 {
       
   180     QMenu* menu = NULL;
       
   181 
       
   182     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   183     if (currPage)
       
   184     {
       
   185         WidgetContainer* widgetContainer = currPage->widgetContainer();
       
   186         if ( widgetContainer)
       
   187             menu = widgetContainer->menu();
       
   188     }
       
   189 
       
   190     return menu;
       
   191 }
       
   192 
       
   193 /*!
       
   194   activate the view's resources. Could be connected by client to view visibility
       
   195 */
       
   196 void WidgetView::activate()
       
   197 {
       
   198     Q_ASSERT(!d->m_isActive);
       
   199 
       
   200     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   201     Q_ASSERT(currPage);
       
   202 
       
   203     QWidget * webWidget = currPage->webWidget();
       
   204     webWidget->setParent(d->m_widgetParent);
       
   205     webWidget->resize(d->m_widgetParent->size());
       
   206 
       
   207     d->m_isActive = true;
       
   208 }
       
   209 
       
   210 /*!
       
   211   deactivate the view's resources. Could be connected by client to view visibility
       
   212 */
       
   213 void WidgetView::deactivate()
       
   214 {
       
   215     Q_ASSERT(d->m_isActive);
       
   216 
       
   217     WrtBrowserContainer * currPage = d->m_pageManager->currentPage();
       
   218     if (currPage)
       
   219     {
       
   220         currPage->webWidget()->hide();
       
   221         currPage->widgetContainer()->notifyWidget(WRT::WidgetContainer::WrtWidgetOnhide);
       
   222     }
       
   223 
       
   224     d->m_isActive = false;
       
   225 }
       
   226 
       
   227 } // namespace WRT