ginebra2/ChromeWidget.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include <QWebElement>
    22 #include <QWebElement>
    20 #include <QWebPage>
    23 #include <QWebPage>
    21 #include <QWebFrame>
    24 #include <QWebFrame>
    22 #include <QList>
    25 #include <QList>
    23 #include <QKeyEvent>
    26 #include <QKeyEvent>
    24 #include <QDebug>
    27 #include <QDebug>
       
    28 #include <QDesktopServices>
    25 #include <QGraphicsSceneContextMenuEvent>
    29 #include <QGraphicsSceneContextMenuEvent>
    26 
    30 
       
    31 #include "bedrockprovisioning.h"
    27 #include "ChromeWidgetJSObject.h"
    32 #include "ChromeWidgetJSObject.h"
    28 #include "ChromeRenderer.h"
    33 #include "ChromeRenderer.h"
    29 #include "ChromeDOM.h"
    34 #include "ChromeDOM.h"
    30 #include "Snippets.h"
    35 #include "Snippets.h"
       
    36 #include "ChromeEffect.h"
    31 #include "ChromeSnippet.h"
    37 #include "ChromeSnippet.h"
    32 #include "ChromeWidget.h"
    38 #include "ChromeWidget.h"
    33 #include "WebChromeContainerSnippet.h"
    39 #include "WebChromeContainerSnippet.h"
    34 #include "Application.h"
    40 #include "Application.h"
    35 #include "AppContentView.h"
       
    36 #include "BlueChromeSnippet.h"
       
    37 #include "GreenChromeSnippet.h"
       
    38 #include "ViewController.h"
    41 #include "ViewController.h"
    39 #include "ViewStack.h"
    42 #include "ViewStack.h"
    40 //#include "CollapsingWidget.h"
    43 //#include "CollapsingWidget.h"
    41 #include "SlidingWidget.h"
    44 #include "SlidingWidget.h"
    42 #include "ProgressSnippet.h"
       
    43 #include "GWebPage.h"
    45 #include "GWebPage.h"
    44 #include "webpagecontroller.h"
    46 #include "webpagecontroller.h"
    45 //#include "ViewStack.h"
    47 //#include "ViewStack.h"
    46 #include "BookmarksManager.h"
    48 #include "BookmarksManager.h"
    47 #include "ScriptObjects.h"
    49 #include "ScriptObjects.h"
    48 #include "LocaleDelegate.h"
    50 #include "LocaleDelegate.h"
    49 #include "DeviceDelegate.h"
    51 #include "DeviceDelegate.h"
    50 
    52 #include "NetworkDelegate.h"
    51 #ifdef USE_DOWNLOAD_MANAGER
    53 #include "ObjectCharm.h"
       
    54 #include "bedrockprovisioning.h"
       
    55 #include "Utilities.h"
       
    56 #include "PopupWebChromeItem.h"
       
    57 #ifdef QT_MOBILITY_SYSINFO
       
    58 #include "SystemDeviceImpl.h"
       
    59 #include "SystemNetworkImpl.h"
       
    60 #endif
       
    61 
    52 #include "Downloads.h"
    62 #include "Downloads.h"
    53 #endif
       
    54 
    63 
    55 #include "wrtbrowsercontainer.h"
    64 #include "wrtbrowsercontainer.h"
    56 #include "webpagecontroller.h"
    65 #include "webpagecontroller.h"
    57 
    66 
       
    67 #include "GAlternateFileChooser.h"
       
    68 
    58 namespace GVA {
    69 namespace GVA {
    59 
    70 
    60 // -----------------------------
    71 // -----------------------------
    61 
    72 
    62   ChromeWidget::ChromeWidget(QGraphicsItem * parent, Qt::WindowFlags wFlags) 
    73   ChromeWidget::ChromeWidget(QGraphicsItem * parent, Qt::WindowFlags wFlags)
    63     : QGraphicsWidget(parent, wFlags),
    74     : QGraphicsWidget(parent, wFlags),
    64       m_renderer(0),
    75       m_renderer(0),
    65       m_dom(0),
    76       m_dom(0),
    66       m_viewController(new ViewController()),
    77       m_viewController(new ViewController()),
    67       m_topBar(0),
    78       m_topBar(0),
    69       m_leftBar(0),
    80       m_leftBar(0),
    70       m_rightBar(0),
    81       m_rightBar(0),
    71       m_aspect(portrait),
    82       m_aspect(portrait),
    72       m_jsObject(new ChromeWidgetJSObject(0, this)),
    83       m_jsObject(new ChromeWidgetJSObject(0, this)),
    73       m_localeDelegate(new LocaleDelegate(this)),
    84       m_localeDelegate(new LocaleDelegate(this)),
    74       m_deviceDelegate(new DeviceDelegate()),
    85       m_downloads(new Downloads()),
    75       m_downloads(0)
    86       m_bottomBarHeight(0)
    76   {
    87   {
    77     m_scene = new QGraphicsScene();
    88     DeviceImpl *deviceImpl = new DEVICEIMPL();
       
    89     NetworkImpl *networkImpl = new NETWORKIMPL();
       
    90     m_deviceDelegate = new DeviceDelegate(deviceImpl);
       
    91     m_networkDelegate = new NetworkDelegate(networkImpl);
       
    92 
       
    93     BEDROCK_PROVISIONING::BedrockProvisioning *provisioning = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning();
       
    94     ChromeEffect::disabledColor.setNamedColor(provisioning->valueAsString("DisabledColor", "#FFFFFF"));
       
    95     ChromeEffect::disabledOpacity = static_cast<qreal>(provisioning->valueAsString("DisabledOpacity", "0.65").toFloat());
       
    96 
    78     //Keep key events not otherwise consumed from going to the scene
    97     //Keep key events not otherwise consumed from going to the scene
    79     //installEventFilter(this);
    98     //installEventFilter(this);
    80     //This is the root of the scene hierarchy
       
    81     m_scene->addItem(this);
       
    82     m_layout = new QGraphicsAnchorLayout();
    99     m_layout = new QGraphicsAnchorLayout();
    83     m_layout->setContentsMargins(0,0,0,0);
   100     m_layout->setContentsMargins(0,0,0,0);
    84     m_layout->setSpacing(0);
   101     m_layout->setSpacing(0);
    85     setLayout(m_layout);
   102     setLayout(m_layout);
    86     addAnchors();
   103     addAnchors();
   107     // Pass some signals from this object to the Javascript object.
   124     // Pass some signals from this object to the Javascript object.
   108     QObject::connect(this, SIGNAL(chromeComplete()), m_jsObject, SIGNAL(chromeComplete()));
   125     QObject::connect(this, SIGNAL(chromeComplete()), m_jsObject, SIGNAL(chromeComplete()));
   109     QObject::connect(this, SIGNAL(aspectChanged(int)), m_jsObject, SIGNAL(aspectChanged(int)));
   126     QObject::connect(this, SIGNAL(aspectChanged(int)), m_jsObject, SIGNAL(aspectChanged(int)));
   110     QObject::connect(this, SIGNAL(prepareForGeometryChange()), m_jsObject, SIGNAL(prepareForGeometryChange()));
   127     QObject::connect(this, SIGNAL(prepareForGeometryChange()), m_jsObject, SIGNAL(prepareForGeometryChange()));
   111     QObject::connect(this, SIGNAL(symbianCarriageReturn()), m_jsObject, SIGNAL(symbianCarriageReturn()));
   128     QObject::connect(this, SIGNAL(symbianCarriageReturn()), m_jsObject, SIGNAL(symbianCarriageReturn()));
       
   129     QObject::connect(this, SIGNAL(popupShown(const QString &)), m_jsObject, SIGNAL(popupShown(const QString &)));
       
   130     QObject::connect(this, SIGNAL(popupHidden(const QString &)), m_jsObject, SIGNAL(popupHidden(const QString &)));
   112 
   131 
   113     //addJSObjectToEngine(this);
   132     //addJSObjectToEngine(this);
   114     m_app = new GinebraApplication();
   133     m_app = new GinebraApplication();
   115     //addJSObjectToEngine(m_app);
   134     //addJSObjectToEngine(m_app);
   116 
   135 
   117 #ifdef USE_DOWNLOAD_MANAGER
       
   118     m_downloads = new Downloads();
       
   119     QObject::connect(
   136     QObject::connect(
   120             WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   137             WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)),
   121             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   138             this, SLOT(pageCreated(WRT::WrtBrowserContainer*)));
   122 #endif
   139 
   123     
       
   124     QObject::connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
   140     QObject::connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
   125     QObject::connect(m_page, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
   141     QObject::connect(m_page, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
   126     QObject::connect(m_page->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(exportJSObjects()));
   142     QObject::connect(m_page->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(exportJSObjects()));
   127 
   143 
   128 #endif
   144 #endif
   129     
   145 
   130     ViewStack::getSingleton()->setViewController(m_viewController);
   146     ViewStack * vs = ViewStack::getSingleton();
       
   147     vs->setViewController(m_viewController);
       
   148     vs->setChromeWidget(this);
       
   149 
   131     // TO DO: need a better home for this.
   150     // TO DO: need a better home for this.
   132     qMetaTypeId<QObjectList>();
   151     qMetaTypeId<QObjectList>();
   133     qRegisterMetaType<QObjectList>("QObjectList");
   152     qRegisterMetaType<QObjectList>("QObjectList");
   134   }
   153   }
   135 
   154 
   142     }
   161     }
   143   }
   162   }
   144 
   163 
   145   void ChromeWidget::pageCreated(WRT::WrtBrowserContainer * page)
   164   void ChromeWidget::pageCreated(WRT::WrtBrowserContainer * page)
   146   {
   165   {
   147 #ifdef USE_DOWNLOAD_MANAGER
   166 #ifdef Q_OS_SYMBIAN
   148     if (m_downloads) {
   167     QString path = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
   149         m_downloads->handlePage(page);
   168     GAlternateFileChooser * chooser = new GAlternateFileChooser(path);
   150     }
   169     page->setFileChooser(chooser); // chooser is now owned by page
   151 #else
   170 #endif
   152     Q_UNUSED(page)
   171     m_downloads->handlePage(page);
   153 #endif
       
   154   }
   172   }
   155 
   173 
   156   ChromeWidget::~ChromeWidget()
   174   ChromeWidget::~ChromeWidget()
   157   {
   175   {
   158     // clearChrome(); // crashes on exit
   176     // clearChrome(); // Crashes on exit
   159     delete m_viewController;
   177     delete m_viewController;
       
   178     delete m_jsObject;
   160     delete m_bottomBar;
   179     delete m_bottomBar;
   161     delete m_topBar;
   180     delete m_topBar;
   162     delete m_leftBar;
   181     delete m_leftBar;
   163     delete m_rightBar;
   182     delete m_rightBar;
   164     delete m_viewPort;
   183     delete m_viewPort;
   165     // delete m_viewLayout; // crashes on exit
   184     // delete m_viewLayout; // Crashes on exit
   166     delete m_renderer;
   185     delete m_renderer;
   167     delete m_dom;
   186     delete m_dom;
   168     delete m_page;
   187     delete m_page;
   169     // delete m_scene;  // crashes on exit
   188     // delete m_scene; // Crashes on exit
   170     delete m_snippets;
   189     delete m_snippets;
   171     // delete m_layout; // crashes on exit
   190     // delete m_layout; // Crashes on exit
   172     delete m_localeDelegate;
   191     delete m_localeDelegate;
   173     delete m_deviceDelegate;
   192     delete m_deviceDelegate;
   174 #ifdef USE_DOWNLOAD_MANAGER
   193     delete m_networkDelegate;
       
   194     delete m_app;
   175     delete m_downloads;
   195     delete m_downloads;
   176 #endif
   196   }
   177   }
   197 
   178  
       
   179 
   198 
   180   //Eat key events not otherwise consumed.
   199   //Eat key events not otherwise consumed.
   181   /*bool ChromeWidget::eventFilter(QObject * obj, QEvent * ev)
   200   /*bool ChromeWidget::eventFilter(QObject * obj, QEvent * ev)
   182   {
   201   {
   183    if(ev->type() == QEvent::KeyPress){
   202    if (ev->type() == QEvent::KeyPress){
   184       return true;
   203       return true;
   185     }
   204     }
   186     return QObject::eventFilter(obj,ev);
   205     return QObject::eventFilter(obj,ev);
   187  
   206 
   188   }*/
   207   }*/
   189 
   208 
   190   void ChromeWidget::resizeEvent(QGraphicsSceneResizeEvent *ev)
   209   void ChromeWidget::resizeEvent(QGraphicsSceneResizeEvent *ev)
   191   {
   210   {
   192 #ifndef __gva_no_chrome__
   211 #ifndef __gva_no_chrome__
   193     if(m_dom && m_renderer) {
   212     if (m_dom && m_renderer) {
   194       emit prepareForGeometryChange();
   213       emit prepareForGeometryChange();
   195       m_renderer->setGeometry(QRectF(-1200,-1200, ev->newSize().width(), m_dom->height()));
   214      // m_renderer->setGeometry(QRectF(-1200,-1200, ev->newSize().width(), m_dom->height()));
       
   215       m_renderer->resize(QSizeF(ev->newSize().width(), m_dom->height()));
   196     }
   216     }
   197     int aspect = m_aspect;
   217     int aspect = m_aspect;
   198     m_aspect = (ev->newSize().width() > ev->newSize().height())?landscape:portrait;
   218     m_aspect = (ev->newSize().width() > ev->newSize().height())?landscape:portrait;
   199     if(m_aspect != aspect) {
   219     if (m_aspect != aspect) {
   200       QString mode = (m_aspect == landscape ? "Landscape" : "Portrait");
   220       QString mode = (m_aspect == landscape ? "Landscape" : "Portrait");
   201       ControllableViewBase* cview = m_viewController->currentView();
   221       ControllableViewBase* cview = m_viewController->currentView();
   202       if (cview)
   222       if (cview)
   203         cview->displayModeChanged(mode);
   223         cview->displayModeChanged(mode);
   204       emit aspectChanged(m_aspect);
   224       emit aspectChanged(m_aspect);
   205     }
   225     }
   206 #endif
   226 #endif
   207     QGraphicsWidget::resizeEvent(ev);    
   227     QGraphicsWidget::resizeEvent(ev);
   208     
   228   }
       
   229 
       
   230   void ChromeWidget::updateChromeLayout() {
       
   231     qDebug() << "ChromeWidget::updateChromeLayout";
       
   232     m_renderer->updateChromeLayout();
   209   }
   233   }
   210 
   234 
   211   /*
   235   /*
   212   //For layout debugging
   236   //For layout debugging
   213   void ChromeWidget::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget){
   237   void ChromeWidget::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget){
   222   void ChromeWidget::setChromeFile(const QString filePath)
   246   void ChromeWidget::setChromeFile(const QString filePath)
   223   {
   247   {
   224 #ifndef __gva_no_chrome__
   248 #ifndef __gva_no_chrome__
   225     qDebug() << "ChromeWidget::setChromeFile: " << m_baseDirectory << filePath;
   249     qDebug() << "ChromeWidget::setChromeFile: " << m_baseDirectory << filePath;
   226     m_page->mainFrame()->load(QUrl(m_baseDirectory + filePath));
   250     m_page->mainFrame()->load(QUrl(m_baseDirectory + filePath));
       
   251     qDebug() << "ChromeWidget::setChromeFile: done";
   227 #else
   252 #else
   228     Q_UNUSED(filePath)
   253     Q_UNUSED(filePath)
   229 #endif
   254 #endif
   230   }  
   255   }
   231 
   256 
   232   void ChromeWidget::reloadChrome()
   257   void ChromeWidget::reloadChrome()
   233   {
   258   {
   234     clearChrome();
   259     clearChrome();
   235     m_page->triggerAction(QWebPage::Reload);
   260     m_page->triggerAction(QWebPage::Reload);
   236   }
   261   }
   237 
   262 
   238   void ChromeWidget::addViewToLayout(ControllableViewBase * controllableView){
   263   void ChromeWidget::addViewToLayout(ControllableViewBase * controllableView){
   239     //qDebug() << "ChromeWidget::addViewToLayout: " << controllableView->widget();
   264     //qDebug() << "ChromeWidget::addViewToLayout: " << controllableView->widget();
   240     if(controllableView->widget()) {
   265     if (controllableView->widget()) {
   241       m_viewPort->setWindow(controllableView->widget());
   266       m_viewPort->setWindow(controllableView->widget());
   242       controllableView->widget()->setFocusPolicy(Qt::ClickFocus); //NB: Is this needed? Does it break anything?
   267       controllableView->widget()->setFocusPolicy(Qt::ClickFocus); //NB: Is this needed? Does it break anything?
   243       controllableView->widget()->setZValue(-1.0); //Make sure we are behind any center anchored snippets
   268       controllableView->widget()->setZValue(-1.0); //Make sure we are behind any center anchored snippets
   244     }
   269     }
   245   }
   270   }
   247   void ChromeWidget::addView(ControllableViewBase * controllableView) {
   272   void ChromeWidget::addView(ControllableViewBase * controllableView) {
   248     //qDebug() << "ChromeWidget::addView: " << controllableView->widget();
   273     //qDebug() << "ChromeWidget::addView: " << controllableView->widget();
   249     m_viewController->addView(controllableView);
   274     m_viewController->addView(controllableView);
   250 
   275 
   251     /*
   276     /*
   252     if(controllableView->widget()) {
   277     if (controllableView->widget()) {
   253       addViewToLayout(controllableView);
   278       addViewToLayout(controllableView);
   254     }
   279     }
   255     else {
   280     else {
   256       qWarning() << "ChromeWidget::addView: view has no widget. " << controllableView;
   281       qWarning() << "ChromeWidget::addView: view has no widget. " << controllableView;
   257       connect(controllableView, SIGNAL(instantiated(ControllableViewBase *)), this, SLOT(onViewInstantiated(ControllableViewBase *)));
   282       connect(controllableView, SIGNAL(instantiated(ControllableViewBase *)), this, SLOT(onViewInstantiated(ControllableViewBase *)));
   268   {
   293   {
   269     Q_UNUSED(where)
   294     Q_UNUSED(where)
   270       //m_viewBar->addItem(snippet);
   295       //m_viewBar->addItem(snippet);
   271     m_viewPort->attachItem(snippet->widget());
   296     m_viewPort->attachItem(snippet->widget());
   272   }
   297   }
   273  
   298 
   274   void ChromeWidget::detachFromView(ChromeSnippet* snippet, const QString& where)
   299   void ChromeWidget::detachFromView(ChromeSnippet* snippet, const QString& where)
   275   {
   300   {
   276     Q_UNUSED(where)
   301     Q_UNUSED(where)
   277       //  m_viewBar->removeItem(snippet);
   302       //  m_viewBar->removeItem(snippet);
   278     m_viewPort->detachItem(snippet->widget());
   303     m_viewPort->detachItem(snippet->widget());
   279   }
   304   }
   280 
   305 
   281   void ChromeWidget::anchorTogether(ChromeSnippet* first, const QString& secondId, qreal x, qreal y)
   306   void ChromeWidget::anchorTogether(ChromeSnippet* first, const QString& secondId, qreal x, qreal y)
   282   { 
   307   {
   283     ChromeSnippet* second = getSnippet(secondId);
   308     ChromeSnippet* second = getSnippet(secondId);
   284     if (second){
   309     if (second){
   285       //qDebug() << "Anchoring: " << first->objectName() << " to: " << second->objectName();
   310       //qDebug() << "Anchoring: " << first->objectName() << " to: " << second->objectName();
   286       first->widget()->setParentItem(second->widget());
   311       first->widget()->setParentItem(second->widget());
   287       first->widget()->setPos(x,y);
   312       first->widget()->setPos(x,y);
   288     }
   313     }
       
   314     else {
       
   315       qDebug() << "ChromeWidget::anchorTogether: error, not found: " << secondId;
       
   316     }
   289   }
   317   }
   290 
   318 
   291   void ChromeWidget::unAnchor(ChromeSnippet* snippet)
   319   void ChromeWidget::unAnchor(ChromeSnippet* snippet)
   292   {
   320   {
   293     snippet->widget()->setParentItem(0);
   321     snippet->widget()->setParentItem(0);
   294     snippet->widget()->setParentItem(this);
   322     snippet->widget()->setParentItem(this);
   295   }
   323   }
   296 
   324 
       
   325   qreal ChromeWidget::shrinkView(qreal delta)
       
   326     {
       
   327       m_viewPort->setShrinkMax(bottomBarHeight());
       
   328       return m_viewPort->shrink(delta);
       
   329     }
       
   330 
   297   qreal ChromeWidget::slideView(qreal delta)
   331   qreal ChromeWidget::slideView(qreal delta)
   298   {
   332   {
   299     //return m_viewBar->collapse(delta);
   333     //return m_viewBar->collapse(delta);
   300     return m_viewPort->slide(delta);
   334     return m_viewPort->slide(delta);
   301   }
   335   }
   302 
   336 
   303   ControllableViewBase * ChromeWidget::getView(const QString& view)
   337   ControllableViewBase * ChromeWidget::getView(const QString& view)
   304   {
   338   {
   305     return m_viewController->view(view);
   339     return m_viewController->view(view);
   306   }  
   340   }
   307 
   341 
   308   void ChromeWidget::showView(const QString &name) {
   342   void ChromeWidget::showView(const QString &name) {
   309     qDebug() << "ChromeWidget::showView: " << name;
   343     qDebug() << "ChromeWidget::showView: " << name;
   310     m_viewController->showView(name);
   344     m_viewController->showView(name);
   311   }
   345   }
   313   void ChromeWidget::onCurrentViewChanged() {
   347   void ChromeWidget::onCurrentViewChanged() {
   314     addViewToLayout(m_viewController->currentView());
   348     addViewToLayout(m_viewController->currentView());
   315   }
   349   }
   316 
   350 
   317   // Clean up all existing snippets;
   351   // Clean up all existing snippets;
   318   
   352 
   319   void ChromeWidget::clearChrome() 
   353   void ChromeWidget::clearChrome()
   320   {
   354   {
   321     m_snippets->clear();
   355     m_snippets->clear();
   322   }
   356   }
   323 
   357 
   324   void ChromeWidget::loadStarted() // slot
   358   void ChromeWidget::loadStarted() // slot
   326     clearChrome();
   360     clearChrome();
   327   }
   361   }
   328 
   362 
   329   void ChromeWidget::loadFinished(bool ok)  // slot
   363   void ChromeWidget::loadFinished(bool ok)  // slot
   330   {
   364   {
   331     //qDebug() << "ChromeWidget::loadFinished";
   365     qDebug() << "ChromeWidget::loadFinished: " << ok;
   332     if(!ok)
   366     if (!ok) {
   333       {
       
   334       qDebug() << "ChromeWidget::loadFinished: error";
   367       qDebug() << "ChromeWidget::loadFinished: error";
   335       return;
   368       return;
   336       }
   369     }
   337     //NB: do we really need to instantiate a new renderer?
   370     //NB: do we really need to instantiate a new renderer?
   338     if(m_renderer)
   371     if (m_renderer)
   339       delete m_renderer;
   372       delete m_renderer;
   340     // qDebug() << "Instantiate renderer";
   373     // qDebug() << "Instantiate renderer";
   341     m_renderer = new ChromeRenderer(m_page, this);
   374     m_renderer = new ChromeRenderer(m_page, this);
   342     // qDebug() << "Resize the renderer 1";
   375     // qDebug() << "Resize the renderer 1";
   343     m_renderer->resize(size());
   376     m_renderer->resize(size());
   344     m_renderer->setPos(-1200, -1200);
   377    // m_renderer->setPos(-1200, -1200);
   345     m_renderer->setZValue(-3);
   378    // m_renderer->setZValue(-3);
   346 #ifdef Q_OS_SYMBIAN
   379 #ifdef Q_OS_SYMBIAN
   347     connect(m_renderer, SIGNAL(symbianCarriageReturn()), this, SIGNAL(symbianCarriageReturn()));
   380    //connect(m_renderer, SIGNAL(symbianCarriageReturn()), this, SIGNAL(symbianCarriageReturn()));
   348 #endif
   381 #endif
   349     if(m_dom) 
   382     if (m_dom)
   350       delete m_dom; // NB: This may need some further investigation
   383       delete m_dom; // NB: This may need some further investigation
   351     m_dom = new ChromeDOM(m_page, this);
   384     m_dom = new ChromeDOM(m_page, this);
   352     getInitialSnippets();
   385     getInitialSnippets();
   353     //Set the final renderer size to match the chrome
   386     //Set the final renderer size to match the chrome
   354     m_renderer->resize(size().width(), m_dom->height());
   387     //m_renderer->resize(size().width(), m_dom->height());
       
   388     m_renderer->resize(QSizeF(size().width(), m_dom->height()));
   355     //qDebug() << m_dom->getCacheableScript();
   389     //qDebug() << m_dom->getCacheableScript();
   356 
   390 
   357     // Let internal objects know that the chrome is complete.
   391     // Let internal objects know that the chrome is complete.
   358     emit internalChromeComplete();
   392     emit internalChromeComplete();
   359     // Now let the javascript world know that it is complete.
   393     // Now let the javascript world know that it is complete.
   360     emit chromeComplete();
   394     emit chromeComplete();
       
   395 
       
   396     // connect ViewStack to creatingPage signal
       
   397     connect( WebPageController::getSingleton(), SIGNAL(creatingPage(WRT::WrtBrowserContainer*)),
       
   398              ViewStack::getSingleton(), SLOT(creatingPage(WRT::WrtBrowserContainer*)));
       
   399     qDebug() << "ChromeWidget::loadFinished: done";
   361   }
   400   }
   362 
   401 
   363   void ChromeWidget::chromeInitialized()
   402   void ChromeWidget::chromeInitialized()
   364   {
   403   {
   365     //NB: Don't want to implement this, but just in case
   404     //NB: Don't want to implement this, but just in case
   378     addJSObjectToPage(WebPageController::getSingleton(), page);
   417     addJSObjectToPage(WebPageController::getSingleton(), page);
   379     addJSObjectToPage(WRT::BookmarksManager::getSingleton(), page);
   418     addJSObjectToPage(WRT::BookmarksManager::getSingleton(), page);
   380     addJSObjectToPage(ViewStack::getSingleton(), page);
   419     addJSObjectToPage(ViewStack::getSingleton(), page);
   381     addJSObjectToPage(m_localeDelegate, page);
   420     addJSObjectToPage(m_localeDelegate, page);
   382     addJSObjectToPage(m_deviceDelegate, page);
   421     addJSObjectToPage(m_deviceDelegate, page);
       
   422     addJSObjectToPage(m_networkDelegate, page);
   383     // Dynamically added objects
   423     // Dynamically added objects
   384     foreach(QObject * jsObj, m_jsObjects) {
   424     //foreach(QObject * jsObj, m_jsObjects) {
   385       addJSObjectToPage(jsObj, page);
   425     //  addJSObjectToPage(jsObj, page);
   386     }
   426     // }
   387 #ifdef USE_DOWNLOAD_MANAGER
   427     addJSObjectToPage(m_downloads, page);
   388     if (m_downloads != 0) {
       
   389         addJSObjectToPage(m_downloads, page);
       
   390     }
       
   391 #endif
       
   392   }
   428   }
   393 
   429 
   394   void ChromeWidget::getInitialSnippets()
   430   void ChromeWidget::getInitialSnippets()
   395   {
   431   {
   396     //TODO: get the list of containers form m_dom (via new method to be added).
   432     //TODO: get the list of containers form m_dom (via new method to be added).
   397     QList <QWebElement> initialSnippets = m_dom->getInitialElements();
   433     QList <QWebElement> initialSnippets = m_dom->getInitialElements();
   398     foreach(QWebElement element, initialSnippets) {
   434     foreach(QWebElement element, initialSnippets) {
   399       ChromeSnippet * s = getSnippet(element.attribute("id"));
   435       ChromeSnippet * s = getSnippet(element.attribute("id"));
   400       if(s->initiallyVisible())
   436       if (s->initiallyVisible())
   401         s->setVisible(true);
   437         s->setVisible(true);
   402     }
   438     }
   403   }
   439   }
   404 
   440 
   405   void ChromeWidget::addAnchors(){
   441   void ChromeWidget::addAnchors(){
   406     if(!m_bottomBar){
   442     if (!m_bottomBar){
   407       m_bottomBar = new QGraphicsWidget(this);
   443       m_bottomBar = new QGraphicsWidget(this);
   408       m_bottomBar->setPreferredHeight(0);
   444       m_bottomBar->setPreferredHeight(0);
   409       m_bottomBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
   445       m_bottomBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
   410       m_layout->addAnchor(m_bottomBar, Qt::AnchorBottom, m_layout, Qt::AnchorBottom);
   446       m_layout->addAnchor(m_bottomBar, Qt::AnchorBottom, m_layout, Qt::AnchorBottom);
   411       m_layout->addAnchors(m_bottomBar, m_layout, Qt::Horizontal);
   447       m_layout->addAnchors(m_bottomBar, m_layout, Qt::Horizontal);
   412     }
   448     }
   413     if(!m_topBar){
   449     if (!m_topBar){
   414       m_topBar = new QGraphicsWidget(this);
   450       m_topBar = new QGraphicsWidget(this);
   415       m_topBar->setPreferredHeight(0);
   451       m_topBar->setPreferredHeight(0);
   416       m_topBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
   452       m_topBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
   417       m_layout->addAnchor(m_topBar, Qt::AnchorTop, m_layout, Qt::AnchorTop);
   453       m_layout->addAnchor(m_topBar, Qt::AnchorTop, m_layout, Qt::AnchorTop);
   418       m_layout->addAnchors(m_topBar, m_layout, Qt::Horizontal);
   454       m_layout->addAnchors(m_topBar, m_layout, Qt::Horizontal);
   419     }
   455     }
   420     if(!m_leftBar){
   456     if (!m_leftBar){
   421       m_leftBar = new QGraphicsWidget(this);
   457       m_leftBar = new QGraphicsWidget(this);
   422       m_leftBar->setPreferredWidth(0);
   458       m_leftBar->setPreferredWidth(0);
   423       m_leftBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
   459       m_leftBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
   424       m_layout->addAnchor(m_leftBar, Qt::AnchorLeft, m_layout, Qt::AnchorLeft);
   460       m_layout->addAnchor(m_leftBar, Qt::AnchorLeft, m_layout, Qt::AnchorLeft);
   425       m_layout->addAnchors(m_leftBar, m_layout, Qt::Vertical);
   461       m_layout->addAnchors(m_leftBar, m_layout, Qt::Vertical);
   426     }
   462     }
   427     if(!m_rightBar){
   463     if (!m_rightBar){
   428       m_rightBar = new QGraphicsWidget(this);
   464       m_rightBar = new QGraphicsWidget(this);
   429       m_rightBar->setPreferredWidth(0);
   465       m_rightBar->setPreferredWidth(0);
   430       m_rightBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
   466       m_rightBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
   431       m_layout->addAnchor(m_rightBar, Qt::AnchorRight, m_layout, Qt::AnchorRight);
   467       m_layout->addAnchor(m_rightBar, Qt::AnchorRight, m_layout, Qt::AnchorRight);
   432       m_layout->addAnchors(m_rightBar, m_layout, Qt::Vertical);
   468       m_layout->addAnchors(m_rightBar, m_layout, Qt::Vertical);
   433     }
   469     }
   434   }
   470   }
   435   
   471 
   436   //Check to see if snippet has an anchor and lay it out accordingly.
   472   //Check to see if snippet has an anchor and lay it out accordingly.
   437   //Otherwise snippets determine their own positions from html
   473   //Otherwise snippets determine their own positions from html
   438 
   474 
   439   void ChromeWidget::anchorSnippet(ChromeSnippet * snippet)
   475   void ChromeWidget::anchorSnippet(ChromeSnippet * snippet)
   440   {
   476   {
   441     if(snippet->anchor() == anchorBottom){
   477     if (snippet->anchor() == anchorBottom){
   442       if(snippet->hidesContent()){
   478       if (snippet->hidesContent()){
   443 	m_layout->addAnchor(snippet->widget(), Qt::AnchorBottom, m_bottomBar, Qt::AnchorTop);
   479     m_layout->addAnchor(snippet->widget(), Qt::AnchorBottom, m_bottomBar, Qt::AnchorTop);
   444 	m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_bottomBar, Qt::AnchorHorizontalCenter);
   480     m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_bottomBar, Qt::AnchorHorizontalCenter);
   445       } else {
   481       } else {
   446 	snippet->widget()->setParentItem(m_bottomBar);
   482     snippet->widget()->setParentItem(m_bottomBar);
   447 	snippet->widget()->setY(-snippet->anchorOffset());
   483     snippet->widget()->setY(-snippet->anchorOffset());
   448       }
   484       }
   449     }
   485     }
   450     else if (snippet->anchor() == anchorTop){
   486     else if (snippet->anchor() == anchorTop){
   451       if(snippet->hidesContent()){
   487       if (snippet->hidesContent()){
   452 	m_layout->addAnchor(snippet->widget(),Qt::AnchorTop, m_topBar, Qt::AnchorBottom);
   488     m_layout->addAnchor(snippet->widget(),Qt::AnchorTop, m_topBar, Qt::AnchorBottom);
   453 	m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_topBar, Qt::AnchorHorizontalCenter);
   489     m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_topBar, Qt::AnchorHorizontalCenter);
   454       }
   490       }
   455       else {
   491       else {
   456 	snippet->widget()->setParentItem(m_topBar);
   492     snippet->widget()->setParentItem(m_topBar);
   457 	snippet->widget()->setY(snippet->anchorOffset());
   493     snippet->widget()->setY(snippet->anchorOffset());
   458       }
   494       }
   459     }
   495     }
   460     else if (snippet->anchor() == anchorLeft){
   496     else if (snippet->anchor() == anchorLeft){
   461       if(snippet->hidesContent())
   497       if (snippet->hidesContent())
   462 	m_layout->addAnchor(snippet->widget(),Qt::AnchorLeft, m_leftBar, Qt::AnchorRight);
   498     m_layout->addAnchor(snippet->widget(),Qt::AnchorLeft, m_leftBar, Qt::AnchorRight);
   463       else {
   499       else {
   464 	snippet->widget()->setParentItem(m_leftBar);
   500     snippet->widget()->setParentItem(m_leftBar);
   465 	snippet->widget()->setX(snippet->anchorOffset());
   501     snippet->widget()->setX(snippet->anchorOffset());
   466       }
   502       }
   467     }
   503     }
   468     else if (snippet->anchor() == anchorRight){
   504     else if (snippet->anchor() == anchorRight){
   469       if(snippet->hidesContent())
   505       if (snippet->hidesContent())
   470 	m_layout->addAnchor(snippet->widget(),Qt::AnchorRight, m_rightBar, Qt::AnchorLeft);
   506     m_layout->addAnchor(snippet->widget(),Qt::AnchorRight, m_rightBar, Qt::AnchorLeft);
   471       else {
   507       else {
   472 	snippet->widget()->setParentItem(m_rightBar);
   508     snippet->widget()->setParentItem(m_rightBar);
   473 	snippet->widget()->setX(-snippet->anchorOffset());
   509     snippet->widget()->setX(-snippet->anchorOffset());
   474       }
   510       }
   475     }
   511     }
   476     else if (snippet->anchor() == anchorCenter) {
   512     else if (snippet->anchor() == anchorCenter) {
   477       snippet->widget()->setParentItem(m_viewPort);
   513       snippet->widget()->setParentItem(m_viewPort);
   478       snippet->widget()->setZValue(0.0);
   514       snippet->widget()->setZValue(0.0);
   494 
   530 
   495   void ChromeWidget:: addSnippet(ChromeSnippet * snippet, const QString & docElementId )
   531   void ChromeWidget:: addSnippet(ChromeSnippet * snippet, const QString & docElementId )
   496   {
   532   {
   497     m_snippets->addSnippet(snippet, docElementId);
   533     m_snippets->addSnippet(snippet, docElementId);
   498     snippet->widget()->setParentItem(this);
   534     snippet->widget()->setParentItem(this);
   499     
   535 
   500     if(!snippet->parentId().isNull()){
   536     if (!snippet->parentId().isNull()){
   501       ChromeSnippet * container = getSnippet(snippet->parentId());
   537       ChromeSnippet * container = getSnippet(snippet->parentId());
   502       if(container)
   538       if (container)
   503 	container->addChild(snippet);
   539     container->addChild(snippet);
   504     }
   540     }
   505     
   541 
   506     anchorSnippet(snippet);
   542     anchorSnippet(snippet);
   507   }
   543   }
   508 
   544 
   509   //NB: This really shouldn't be necessary: anchor bars should be implemented as an expanding
   545   //NB: This really shouldn't be necessary: anchor bars should be implemented as an expanding
   510   //widget class !!!!!!
   546   //widget class !!!!!!
   511 
   547 
   512   void ChromeWidget::adjustAnchorOffset(ChromeSnippet * snippet, qreal delta)
   548   void ChromeWidget::adjustAnchorOffset(ChromeSnippet * snippet, qreal delta)
   513   {
   549   {
   514     if(snippet->anchor() == anchorBottom)
   550     if (snippet->anchor() == anchorBottom)
   515       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + delta);
   551       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + delta);
   516     else if(snippet->anchor() == anchorTop)
   552     else if (snippet->anchor() == anchorTop)
   517       m_topBar->setPreferredHeight(m_topBar->preferredHeight() + delta);
   553       m_topBar->setPreferredHeight(m_topBar->preferredHeight() + delta);
   518     else if(snippet->anchor() == anchorLeft){
   554     else if (snippet->anchor() == anchorLeft){
   519       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + delta);
   555       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + delta);
   520     }
   556     }
   521     else if(snippet->anchor() == anchorRight){
   557     else if (snippet->anchor() == anchorRight){
   522       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + delta);
   558       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + delta);
   523     }
   559     }
   524   }
   560   }
   525 
   561 
   526   // Call after a snippet changes to visible state
   562   // Call after a snippet changes to visible state
   529   // At a minimum should assert that the anchor "bars"
   565   // At a minimum should assert that the anchor "bars"
   530   // are not null.)
   566   // are not null.)
   531 
   567 
   532   void ChromeWidget::snippetShown(ChromeSnippet * snippet)
   568   void ChromeWidget::snippetShown(ChromeSnippet * snippet)
   533   {
   569   {
   534     if(snippet->hidesContent())
   570      if (snippet->hidesContent()) {
   535       return;
   571         if (snippet->anchor() == anchorBottom) {
   536     if(snippet->anchor() == anchorBottom)
   572             /* snippet->widget()->size().height() is zero for  WebChromeContainerSnippet
       
   573                when default visible container snippet is shown, get ownerArea height instead */
       
   574             WebChromeContainerSnippet * s = dynamic_cast<WebChromeContainerSnippet *>(snippet);
       
   575             if (!s) {
       
   576                 m_bottomBarHeight = snippet->widget()->size().height();
       
   577             }
       
   578             else {
       
   579                 m_bottomBarHeight = s->ownerArea().height();
       
   580             }
       
   581         }
       
   582         return;
       
   583     }
       
   584     if (snippet->anchor() == anchorBottom)
   537       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + snippet->widget()->preferredHeight());
   585       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + snippet->widget()->preferredHeight());
   538     else if(snippet->anchor() == anchorTop)
   586     else if (snippet->anchor() == anchorTop)
   539       m_topBar->setPreferredHeight(m_topBar->preferredHeight() + snippet->widget()->preferredHeight());
   587       m_topBar->setPreferredHeight(m_topBar->preferredHeight() + snippet->widget()->preferredHeight());
   540     else if(snippet->anchor() == anchorLeft){
   588     else if (snippet->anchor() == anchorLeft){
   541       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + snippet->widget()->preferredWidth());
   589       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + snippet->widget()->preferredWidth());
   542     }
   590     }
   543     else if(snippet->anchor() == anchorRight){
   591     else if (snippet->anchor() == anchorRight){
   544       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + snippet->widget()->preferredWidth());
   592       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + snippet->widget()->preferredWidth());
   545     }
   593     }
   546   }
   594   }
   547 
   595 
   548   // Call before a snippet changes to invisible state
   596   // Call before a snippet changes to invisible state
   551   // At a minimum should assert that the anchor "bars"
   599   // At a minimum should assert that the anchor "bars"
   552   // are not null.)
   600   // are not null.)
   553 
   601 
   554   void ChromeWidget::snippetHiding(ChromeSnippet * snippet)
   602   void ChromeWidget::snippetHiding(ChromeSnippet * snippet)
   555   {
   603   {
   556     if(snippet->hidesContent())
   604     if (snippet->hidesContent())
   557       return;
   605       return;
   558     if(snippet->anchor() == anchorBottom)
   606     if (snippet->anchor() == anchorBottom)
   559       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() - snippet->widget()->preferredHeight());
   607       m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() - snippet->widget()->preferredHeight());
   560     else if(snippet->anchor() == anchorTop)
   608     else if (snippet->anchor() == anchorTop)
   561       m_topBar->setPreferredHeight(m_topBar->preferredHeight() - snippet->widget()->preferredHeight());
   609       m_topBar->setPreferredHeight(m_topBar->preferredHeight() - snippet->widget()->preferredHeight());
   562     else if(snippet->anchor() == anchorLeft){
   610     else if (snippet->anchor() == anchorLeft){
   563       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() - snippet->widget()->preferredWidth());
   611       m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() - snippet->widget()->preferredWidth());
   564     }
   612     }
   565     else if(snippet->anchor() == anchorRight){
   613     else if (snippet->anchor() == anchorRight){
   566       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() - snippet->widget()->preferredWidth());
   614       m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() - snippet->widget()->preferredWidth());
   567     }
   615     }
   568   }
   616   }
   569 
   617 
   570   ChromeSnippet *ChromeWidget::getSnippet(const QString & docElementId, QGraphicsItem * parent) {
   618   ChromeSnippet *ChromeWidget::getSnippet(const QString & docElementId, QGraphicsItem * parent) {
   571  
       
   572     ChromeSnippet *result = m_snippets->getSnippet(docElementId);
   619     ChromeSnippet *result = m_snippets->getSnippet(docElementId);
   573     if(!result){
   620     if (!result){
   574       result = m_dom->getSnippet(docElementId, parent);
   621       result = m_dom->getSnippet(docElementId, parent);
   575       if(result) {
   622       if (result) {
   576 	result->setParent(m_snippets); // Exports to "Snippets" JS object
   623         result->setParent(m_snippets); // Exports to "Snippets" JS object
   577         addSnippet(result, docElementId);
   624         addSnippet(result, docElementId);
   578       }
   625       }
   579       else{
   626       else{
   580 	qDebug() << "Snippet not found: " << docElementId;
   627         qDebug() << "Snippet not found: " << docElementId;
   581 	return 0;
   628         return 0;
   582       }
   629       }
   583     }else{
   630     }else{
   584       //qDebug() << "Found existing snippet: " << docElementId;
   631       //qDebug() << "Found existing snippet: " << docElementId;
   585     }
   632     }
   586     
   633 
   587     return result;
   634     return result;
   588   }
   635   }
   589 
   636 
   590   QRect ChromeWidget::getSnippetRect(const QString &docElementId)
   637   QRect ChromeWidget::getSnippetRect(const QString &docElementId)
   591   {
   638   {
   592     return m_dom->getElementRect(docElementId);
   639     return m_dom->getElementRect(docElementId);
   593   }
   640   }
   594 
   641 
   595   void ChromeWidget::addJSObjectToWindow(QObject *object) 
   642   void ChromeWidget::addJSObjectToWindow(QObject *object)
   596   {
   643   {
   597     m_page->mainFrame()->addToJavaScriptWindowObject(object->objectName(), object);
   644     m_page->mainFrame()->addToJavaScriptWindowObject(object->objectName(), object);
   598   }
   645   }
   599 
   646 
   600   void ChromeWidget::addJSObjectToPage(QObject *object, QWebPage *page)
   647   void ChromeWidget::addJSObjectToPage(QObject *object, QWebPage *page)
   618   void ChromeWidget::onViewInstantiated(ControllableViewBase *view) {   // slot
   665   void ChromeWidget::onViewInstantiated(ControllableViewBase *view) {   // slot
   619     qDebug() << "ChromeWidget::onViewInstantiated: "; // << view;
   666     qDebug() << "ChromeWidget::onViewInstantiated: "; // << view;
   620     addViewToLayout(view);
   667     addViewToLayout(view);
   621   }
   668   }
   622 
   669 
   623   QObject*  ChromeWidget::getDisplaySize() const 
   670   QObject*  ChromeWidget::getDisplaySize() const
   624   {
   671   {
   625     ScriptSize * sz = new ScriptSize(size().toSize());
   672     ScriptSize * sz = new ScriptSize(size().toSize());
   626     m_page->mainFrame()->addToJavaScriptWindowObject("size", sz, QScriptEngine::ScriptOwnership);
   673     m_page->mainFrame()->addToJavaScriptWindowObject("size", sz, QScriptEngine::ScriptOwnership);
   627     return sz;
   674     return sz;
   628 
   675 
   629   }
   676   }
   630   
   677 
   631 void ChromeWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) 
   678 void ChromeWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
   632 {
   679 {
   633     event->accept();
   680     event->accept();
   634 }
   681 }
   635   
   682 
   636   /*
   683   /*
   637   void ChromeWidget::addJSObjectToEngine(QObject *object)
   684   void ChromeWidget::addJSObjectToEngine(QObject *object)
   638   {
   685   {
   639     QScriptValue val = m_engine.newQObject(object);
   686     QScriptValue val = m_engine.newQObject(object);
   640     m_engine.globalObject().setProperty(object->objectName(), val);
   687     m_engine.globalObject().setProperty(object->objectName(), val);
   643   QScriptValue ChromeWidget::evalWithEngineContext(const QString& program)
   690   QScriptValue ChromeWidget::evalWithEngineContext(const QString& program)
   644   {
   691   {
   645     return m_engine.evaluate(program);
   692     return m_engine.evaluate(program);
   646   }
   693   }
   647   */
   694   */
       
   695 
       
   696   void ChromeWidget::setScene(QGraphicsScene *scene)
       
   697   {
       
   698     m_scene = scene;
       
   699     //This is the root of the scene hierarchy
       
   700     m_scene->addItem(this);
       
   701 
       
   702     // For testing, turn on red dot that appears in response to various mouse events.
       
   703     if(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("EnableTouchCircle", false)) {
       
   704         new TouchCircleCharm(m_scene, this);
       
   705     }
       
   706   }
       
   707 
       
   708   void ChromeWidget::emitPopupShown(const QString &popupId) {
       
   709       qDebug() << "ChromeWidget::emitPopupShown: " << popupId;
       
   710       emit popupShown(popupId);
       
   711   }
       
   712 
       
   713   void ChromeWidget::emitPopupHidden(const QString &popupId) {
       
   714       emit popupHidden(popupId);
       
   715   }
   648 
   716 
   649   void ChromeWidget::dump() {
   717   void ChromeWidget::dump() {
   650     qDebug() << "---------------------";
   718     qDebug() << "---------------------";
   651     qDebug() << "ChromeWidget::dump";
   719     qDebug() << "ChromeWidget::dump";
   652     m_snippets->dump();
   720     m_snippets->dump();