ginebra2/ChromeWidgetJSObject.h
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     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 #ifndef CHROMEWIDGETJSOBJECT_H_
    22 #ifndef CHROMEWIDGETJSOBJECT_H_
    20 #define CHROMEWIDGETJSOBJECT_H_
    23 #define CHROMEWIDGETJSOBJECT_H_
    21 
    24 
    22 #include <QObject>
    25 #include <QObject>
    23 #include <QUrl>
    26 #include <QUrl>
    24 
    27 
       
    28 #include "ChromeLayout.h"
    25 #include "ChromeWidget.h"
    29 #include "ChromeWidget.h"
       
    30 #include "ChromeEffect.h"
       
    31 
       
    32 // Comment out this define to disable logging via javascript.
       
    33 #define ENABLE_LOG
    26 
    34 
    27 namespace GVA {
    35 namespace GVA {
    28 
       
    29 class ChromeWidget;
       
    30 
    36 
    31 /*!
    37 /*!
    32  * \defgroup JavascriptAPI Javascript API objects.
    38  * \defgroup JavascriptAPI Javascript API objects.
    33  * All classes in this group provide Javascript API access to the underlying
    39  * All classes in this group provide Javascript API access to the underlying
    34  * C++ classes in the browser via their public slots, signals and properties.
    40  * C++ classes in the browser via their public slots, signals and properties.
    35  */
    41  */
    36 
    42 
    37 /*! \ingroup JavascriptAPI
    43 /*! \ingroup JavascriptAPI
    38  * \brief Javascript API wrapper for ChromeWidget.
    44  * \brief Javascript API wrapper for ChromeWidget.
       
    45  *
       
    46  * Javascript object name: "chrome".
       
    47  *
       
    48  * Example javascript code to connect the chromeComplete signal:
       
    49  * \code
       
    50  * chrome.chromeComplete.connect(function() {
       
    51  *    app.debug("chrome complete");
       
    52  *    }
       
    53  * );
       
    54  * \endcode
       
    55  * \sa ChromeWidget
    39  */
    56  */
    40 class ChromeWidgetJSObject : public QObject {
    57 class ChromeWidgetJSObject : public QObject {
    41   Q_OBJECT
    58   Q_OBJECT
    42 public:
    59 public:
    43   ChromeWidgetJSObject(QObject *parent, ChromeWidget *chromeWidget)
    60   ChromeWidgetJSObject(QObject *parent, ChromeWidget *chromeWidget);
    44     : QObject(parent),
       
    45       m_chromeWidget(chromeWidget) {
       
    46   }
       
    47 
    61 
    48 public slots:
    62 public slots:
    49   int width() { return m_chromeWidget->width(); }
    63   int width() { return m_chromeWidget->layout()->size().width(); }
    50   void alert(const QString & msg) { m_chromeWidget->alert(msg); }
    64   void alert(const QString & msg) { m_chromeWidget->alert(msg); }
    51   qreal slideView(qreal delta) { return m_chromeWidget->slideView(delta); }
    65   qreal slideView(qreal delta) { return m_chromeWidget->layout()->slideView(delta); }
    52   void chromeInitialized() { m_chromeWidget->chromeInitialized(); }
    66   void chromeInitialized() { m_chromeWidget->chromeInitialized(); }
    53   void reloadChrome() { m_chromeWidget->reloadChrome(); }
    67   void reloadChrome() { m_chromeWidget->reloadChrome(); }
    54   void loadUrlToCurrentPage(const QString & url) { m_chromeWidget->loadUrlToCurrentPage(url); }
    68   void loadUrlToCurrentPage(const QString & url) { m_chromeWidget->loadUrlToCurrentPage(url); }
       
    69   void updateChromeLayout() { m_chromeWidget->updateChromeLayout(); }
       
    70 
       
    71 #ifdef ENABLE_LOG
       
    72   /// Write string \a msg to log file "c:\Data\GinebraLog.txt".
       
    73   void log(const QString msg);
       
    74 #endif
    55 
    75 
    56 signals:
    76 signals:
    57   void chromeComplete();
    77   void chromeComplete();
    58   void aspectChanged(int aspect);
    78   void aspectChanged(int aspect);
    59   void prepareForGeometryChange();
    79   void prepareForGeometryChange();
    60   //NB: This should be symbian ifdef'd but that would require symbian-specific chrome
    80   //NB: This should be symbian ifdef'd but that would require symbian-specific chrome
    61   void symbianCarriageReturn();
    81   void symbianCarriageReturn();
       
    82   void popupShown(const QString &id);
       
    83   void popupHidden(const QString &id);
    62 
    84 
    63 public:
    85 public:
    64   /// Returns a list of all existing snippets.
    86   /// Returns a list of all existing snippets.
    65   QObjectList getSnippets() { return m_chromeWidget->getSnippets(); }
    87   QObjectList getSnippets() { return m_chromeWidget->getSnippets(); }
    66   Q_PROPERTY(QObjectList snippets READ getSnippets)
    88   Q_PROPERTY(QObjectList snippets READ getSnippets)
    67 
    89 
    68   /// \brief Returns either "portrait" or "landscape".
    90   /// \brief Returns either "portrait" or "landscape".
    69   QString getDisplayMode() const { return m_chromeWidget->getDisplayMode(); }
    91   QString getDisplayMode() const { return m_chromeWidget->layout()->getDisplayMode(); }
    70   Q_PROPERTY(QString displayMode READ getDisplayMode)
    92   Q_PROPERTY(QString displayMode READ getDisplayMode)
    71 
    93 
    72   QObject* getDisplaySize() const { return m_chromeWidget->getDisplaySize(); }
    94   QObject* getDisplaySize() const { return m_chromeWidget->getDisplaySize(); }
    73   Q_PROPERTY(QObject* displaySize READ getDisplaySize)
    95   Q_PROPERTY(QObject* displaySize READ getDisplaySize)
    74 
    96 
    75   /// Returns the path to the chrome directory.  Ex: "chrome/bedrockchrome".
    97   /// Returns the path to the chrome directory.  Ex: "chrome/bedrockchrome".
    76   QString getBaseDirectory() const { return m_chromeWidget->getBaseDirectory(); }
    98   QString getBaseDirectory() const { return m_chromeWidget->getBaseDirectory(); }
    77   Q_PROPERTY(QString baseDirectory READ getBaseDirectory)
    99   Q_PROPERTY(QString baseDirectory READ getBaseDirectory)
    78 
   100 
       
   101   /*! The color applied to disabled chrome snippets and views.
       
   102    * \sa disabledOpacity
       
   103    */
       
   104   Q_PROPERTY(QString disabledColor READ disabledColor WRITE setDisabledColor)
       
   105   QString disabledColor() const { return ChromeEffect::disabledColor.name(); }
       
   106   void setDisabledColor(const QString &value) { ChromeEffect::disabledColor.setNamedColor(value); }
       
   107 
       
   108   /*! The opacity of the color applied to disabled chrome snippets and views.
       
   109    * \sa disabledColor
       
   110    */
       
   111   Q_PROPERTY(qreal disabledOpacity READ disabledOpacity WRITE setDisabledOpacity)
       
   112   qreal disabledOpacity() const { return ChromeEffect::disabledOpacity; }
       
   113   void setDisabledOpacity(const qreal &value) { ChromeEffect::disabledOpacity = value; }
       
   114 
       
   115 protected:
       
   116 #ifdef ENABLE_LOG
       
   117   QString getLogPath();
       
   118   void initLogFile();
       
   119 #endif
       
   120 
    79 private:
   121 private:
    80   ChromeWidget *m_chromeWidget;
   122   ChromeWidget *m_chromeWidget;
    81 };
   123 };
    82 
   124 
    83 }
   125 }