ginebra/chromejsobject.h
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2010 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 #ifndef _GINEBRA_CHROME_JS_OBJECT_H_
       
    20 #define _GINEBRA_CHROME_JS_OBJECT_H_
       
    21 
       
    22 #include <QObject>
       
    23 #include <QString>
       
    24 #include <QList>
       
    25 #include "chromeview.h"
       
    26 
       
    27 // Comment out this define to disable logging via javascript.
       
    28 #define ENABLE_LOG
       
    29 
       
    30 class ChromeWindow;
       
    31 class QNetworkReply;
       
    32 class QUrl;
       
    33 class Download;
       
    34 
       
    35 /**
       
    36  * \brief The ChromeJSObject class provides a javascript API to global or system-wide
       
    37  * functionality.
       
    38  */
       
    39 class ChromeJSObject : public QObject
       
    40 
       
    41 {
       
    42   Q_OBJECT
       
    43 
       
    44   friend class ChromeView;
       
    45 
       
    46  public:
       
    47   ChromeJSObject(ChromeView* chrome);
       
    48 
       
    49   QList<int> getDisplaySize() const;
       
    50   Q_PROPERTY(QList<int> displaySize READ getDisplaySize)
       
    51 
       
    52   // \brief Returns either "portrait" or "landscape".
       
    53   QString getDisplayMode() const;
       
    54   Q_PROPERTY(QString displayMode READ getDisplayMode)
       
    55 
       
    56   // \brief Returns the bounding rectangle of the content window.
       
    57   QObject *getContentViewRect() const;
       
    58   Q_PROPERTY(QObject *contentViewRect READ getContentViewRect)
       
    59 
       
    60 public slots:   // Visible to javascript.
       
    61   // Load a new chrome from \a url.
       
    62   void loadChrome(const QString url);
       
    63   
       
    64   // Reload the current chrome.
       
    65   void reloadChrome();
       
    66   
       
    67 #ifdef USE_STATEMACHINE
       
    68   void requestChrome(const QString &url);
       
    69 #endif
       
    70   void updateViewPort();
       
    71   void setViewPort(int x1, int y1, int x2, int y2);
       
    72   void flipFromCurrentView(const QString& toId);
       
    73   void flipToCurrentView(const QString& fromId);
       
    74   
       
    75   // Write string \a msg to debug output.
       
    76   void alert(const QString msg);
       
    77   
       
    78 
       
    79 #ifdef ENABLE_LOG
       
    80   // Write string \a msg to log file "c:\Data\GinebraLog.txt".
       
    81   void log(const QString msg);
       
    82 #endif
       
    83   
       
    84   void setBackgroundColor(int r, int g, int b);  // !!! This should be a property.
       
    85   
       
    86   // Toggle the visibility of the snippet with id \a id.
       
    87   void toggleVisibility(const QString& id);
       
    88   
       
    89   // Show the snippet with id \a id.
       
    90   void show(const QString& id, int x=0, int y=0);
       
    91   
       
    92   // Hide the snippet with id \a id.
       
    93   void hide(const QString& id);
       
    94   
       
    95   void setLocation(const QString& id, int x, int y);
       
    96   void setAnchor(const QString& id, const QString& anchor);
       
    97   void toggleAttention(const QString & id);
       
    98   void setVisibilityAnimator(const QString& elementId, const QString & animatorName);
       
    99   void setAttentionAnimator(const QString& elementId, const QString & animatorName);
       
   100   QString guessUrlFromString(const QString &s);
       
   101   QString guessAndGotoUrl(const QString &s);
       
   102   QString searchUrl(const QString &s);
       
   103   void loadFromHistory();
       
   104   void clearHistory();
       
   105   void clearCookies();
       
   106   void clearCache();
       
   107   QString getLastUrl();
       
   108   int numberOfWindows();
       
   109   void loadLocalFile();
       
   110   void setViewofCurrentPage();
       
   111 
       
   112 #ifdef USE_DOWNLOAD_MANAGER
       
   113   void downloadCreated(Download * download);
       
   114   void downloadStarted(Download * download);
       
   115   void downloadProgress(Download * download);
       
   116   void downloadFinished(Download * download);
       
   117   void downloadPaused(Download * download, const QString & error);
       
   118   void downloadCancelled(Download * download, const QString & error);
       
   119   void downloadFailed(Download * download, const QString & error);
       
   120   void downloadNetworkLoss(Download * download, const QString & error);
       
   121   void downloadError(Download * download, const QString & error);
       
   122 #endif
       
   123 
       
   124  signals:
       
   125   // Sent when the chrome has finished loading.
       
   126   void loadComplete();
       
   127   // Sent when the viewport has been resized
       
   128   void viewPortResize(int x, int y, int w, int h);
       
   129   // Sent when the display mode changes from landscape to protrait or vice versa.
       
   130   void onDisplayModeChanged(const QString &orientation);
       
   131   // Sent when the display mode change starts from landscape to protrait or vice versa.
       
   132   void onDisplayModeChangeStart(const QString &orientation);
       
   133 
       
   134 #ifdef USE_STATEMACHINE
       
   135   // Sent when the chrome wants to load a different chrome.
       
   136   void onRequestChrome(const QString url);
       
   137 #endif
       
   138 
       
   139 #ifdef USE_DOWNLOAD_MANAGER
       
   140   void onDownloadCreated(int);
       
   141   void onDownloadStarted(int, const QString &, int);
       
   142   void onDownloadProgress(int, const QString &, int, int, int);
       
   143   void onDownloadFinished(int, const QString &, int, int, int);
       
   144   void onDownloadPaused(int, const QString &, int, int, int, const QString &);
       
   145   void onDownloadCancelled(int, const QString &, int, int, int, const QString &);
       
   146   void onDownloadFailed(int, const QString &, int, int, int, const QString &);
       
   147   void onDownloadNetworkLoss(int, const QString &, int, int, int, const QString &);
       
   148   void onDownloadError(int, const QString &, int, int, int, const QString &);
       
   149 #endif
       
   150 
       
   151  protected:
       
   152   void displayModeChanged(ChromeView::DisplayMode orientation);
       
   153   void displayModeChangeStart(ChromeView::DisplayMode orientation);
       
   154   void displayOrientationChanged(int angle);
       
   155   QString getLogPath();
       
   156 
       
   157 #ifdef ENABLE_LOG  
       
   158   void initLogFile();
       
   159 #endif
       
   160 
       
   161  private:
       
   162   ChromeView* m_chromeView;
       
   163 };
       
   164 
       
   165 #endif