ginebra2/ContentViews/GWebContentView.h
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 9 b39122337a00
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     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
     4 *
     5 * under the terms of "Eclipse Public License v1.0"
     5 * This program is free software: you can redistribute it and/or modify
     6 * which accompanies this distribution, and is available
     6 * it under the terms of the GNU Lesser General Public License as published by
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * the Free Software Foundation, version 2.1 of the License.
     8 *
     8 *
     9 * Initial Contributors:
     9 * This program is distributed in the hope that it will be useful,
    10 * Nokia Corporation - initial contribution.
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 * Contributors:
    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 GWebContentView_H
    22 #ifndef GWebContentView_H
    20 #define GWebContentView_H
    23 #define GWebContentView_H
    21 
    24 
    22 #include <QObject>
    25 #include <QObject>
    23 #include <QVariant>
    26 #include <QVariant>
    24 #include <QGraphicsWidget>
    27 #include <QGraphicsWidget>
    25 #include <qwebelement.h>
    28 #include <QWebElement>
    26 #include "qgraphicswebview.h"
    29 #include <QGraphicsWebView>
    27 #include "controllableviewimpl.h"
    30 #include "controllableviewimpl.h"
    28 #include "messageboxproxy.h"
    31 #include "messageboxproxy.h"
    29 #include "ZoomMetaData.h"
    32 #include "ZoomMetaData.h"
    30 #include "GWebPage.h"
    33 #include "GSuperWebPage.h"
    31 #include "ContentViewDelegate.h"
    34 #include "ContentViewDelegate.h"
    32 #include "GWebTouchNavigation.h"
    35 #include "GContentViewTouchNavigation.h"
    33 
    36 
    34 class WebViewEventContext;
    37 class WebViewEventContext;
    35 class QContextMenuEvent;
    38 class QContextMenuEvent;
    36 class QWebPage;
    39 class QWebPage;
    37 class QWebFrame;
    40 class QWebFrame;
    38 class QTimeLine;
    41 class QTimeLine;
    39 class GWebContentViewWidget;
    42 class GWebContentViewWidget;
       
    43 
    40 namespace WRT {
    44 namespace WRT {
    41     class WrtBrowserContainer;
    45     class WrtBrowserContainer;
    42 }
    46 }
    43 
    47 
    44 namespace GVA {
    48 namespace GVA {
    45 
    49 
    46   class GWebPage;
    50   class GWebPage;
       
    51   class WebPageWrapper;
    47   class ChromeWidget;
    52   class ChromeWidget;
    48   class ContentViewDelegate;
    53   class ContentViewDelegate;
       
    54 #ifdef BEDROCK_TILED_BACKING_STORE
       
    55   class WebContentViewWidget;
       
    56 #endif
    49 
    57 
    50   class GWebContentView : public ControllableViewBase
    58   class GWebContentView : public ControllableViewBase
    51   {
    59   {
    52       Q_OBJECT
    60       Q_OBJECT
    53   public:
    61   public:
    57       static QString Type() { return "webView"; }
    65       static QString Type() { return "webView"; }
    58       virtual QString type() const { return Type(); }
    66       virtual QString type() const { return Type(); }
    59 
    67 
    60 // do we need both of these?
    68 // do we need both of these?
    61       QGraphicsWidget* widget() const;
    69       QGraphicsWidget* widget() const;
       
    70 #ifdef BEDROCK_TILED_BACKING_STORE
       
    71       QGraphicsWebView* webWidget() const;
       
    72 #else
    62       GWebContentViewWidget *webWidget() const;
    73       GWebContentViewWidget *webWidget() const;
    63 
    74 #endif
    64       // Returns the DOM 'window' object of the page.
    75       // Returns the DOM 'window' object of the page.
    65       QVariant getContentWindowObject();
    76       QVariant getContentWindowObject();
    66 
    77 
    67       virtual void connectAll();
    78       virtual void connectAll();
    68       virtual void activate();
    79       virtual void activate();
    73       virtual QString title() const;
    84       virtual QString title() const;
    74 
    85 
    75       QUrl url();
    86       QUrl url();
    76       QWebPage *currentPage();
    87       QWebPage *currentPage();
    77 
    88 
       
    89 #ifdef BEDROCK_TILED_BACKING_STORE
       
    90       qreal getZoomFactor();
       
    91 #else
    78       qreal getZoomFactor() const;
    92       qreal getZoomFactor() const;
    79 
    93 #endif
    80       static ControllableView* createNew(QWidget *parent);
    94       static ControllableView* createNew(QWidget *parent);
    81 
    95 
    82       /*!
    96       /*!
    83         Return the list of public QActions most relevant to the view's current context
    97         Return the list of public QActions most relevant to the view's current context
    84         (most approptiate for contextual menus, etc.
    98         (most approptiate for contextual menus, etc.
    92 
   106 
    93       void  changeZoomAction(qreal zoom);
   107       void  changeZoomAction(qreal zoom);
    94       void deactivateZoomActions();
   108       void deactivateZoomActions();
    95 
   109 
    96       // Super page methods.
   110       // Super page methods.
    97       GWebPage * createSuperPage(const QString &name);
   111       GSuperWebPage * createSuperPage(const QString &name, bool persist = false);
    98       void destroySuperPage(const QString &name);
   112       void destroySuperPage(const QString &name);
    99       QObjectList getSuperPages();
   113       QObjectList getSuperPages();
   100       void setCurrentSuperPage(const QString &name);
   114       bool setCurrentSuperPage(const QString &name);
   101       GWebPage * currentSuperPage() {return m_currentSuperPage.value();}
   115       GSuperWebPage * currentSuperPage() {return m_currentSuperPage.value();}
   102       void showSuperPage(const QString &name);
   116       void showSuperPage(const QString &name);
   103       GWebPage * superPage(const QString &name);
   117       GSuperWebPage * superPage(const QString &name);
   104       bool isSuperPage(const QString &name);
   118       bool isSuperPage(const QString &name);
   105       bool currentPageIsSuperPage() const;
   119       bool currentPageIsSuperPage() const;
       
   120 
   106       void bitmapZoomStop();
   121       void bitmapZoomStop();
   107       virtual void show() {
   122       virtual void show() {
   108           qDebug() << "GWebContentView::show: " << widget();
       
   109           widget()->show();
   123           widget()->show();
   110       }
   124       }
   111 
   125 
   112       virtual void hide() {
   126       virtual void hide() {
   113           qDebug() << "GWebContentView::hide: " << widget();
   127            widget()->hide();
   114           widget()->hide();
       
   115       }
   128       }
   116 
   129 
   117 	  bool gesturesEnabled() const { return m_touchNavigation->enabled(); }
   130       bool gesturesEnabled() const { 
   118       void setGesturesEnabled(bool value) { m_touchNavigation->setEnabled(value); }
   131 #ifndef BEDROCK_TILED_BACKING_STORE
       
   132 		return m_touchNavigation->enabled(); 
       
   133 #endif	
       
   134 		return false;
       
   135 	  }
       
   136 
       
   137       void setGesturesEnabled(bool value) { 
       
   138 #ifndef BEDROCK_TILED_BACKING_STORE		  
       
   139 		  m_touchNavigation->setEnabled(value); 
       
   140 #endif
       
   141 	  	}
       
   142 
       
   143       bool enabled() const;
       
   144       void setEnabled(bool value);
       
   145 
       
   146 
       
   147       bool frozen() const { 
       
   148 #ifndef BEDROCK_TILED_BACKING_STORE		  
       
   149 		  return webWidget()->frozen(); 
       
   150 #else	  
       
   151 		  return false;
       
   152 #endif
       
   153 	  }
       
   154 
       
   155       void freeze() { 
       
   156 #ifndef BEDROCK_TILED_BACKING_STORE			  
       
   157 		  return webWidget()->freeze(); 
       
   158 #endif
       
   159 	  }
       
   160       void unfreeze() { 
       
   161 #ifndef BEDROCK_TILED_BACKING_STORE			  
       
   162 		  return webWidget()->unfreeze(); 
       
   163 #endif
       
   164 		}
   119 
   165 
   120   signals:
   166   signals:
   121       void ContextChanged();
   167       void ContextChanged();
   122       void iconChanged();
   168       void iconChanged();
   123       void loadFinished(bool ok);
   169       void loadFinished(bool ok);
   129       void secureConnection(bool secure);
   175       void secureConnection(bool secure);
   130       void backEnabled(bool enabled);
   176       void backEnabled(bool enabled);
   131       void forwardEnabled(bool enabled);
   177       void forwardEnabled(bool enabled);
   132       void startingPanGesture(int);
   178       void startingPanGesture(int);
   133       void contentViewMouseEvent(QEvent::Type type);
   179       void contentViewMouseEvent(QEvent::Type type);
       
   180 	  void superPageShown(const QString &name);
       
   181 #ifdef BEDROCK_TILED_BACKING_STORE
       
   182       void contextEvent(::WebViewEventContext* context);
       
   183 #endif      
   134 
   184 
   135   public slots:
   185   public slots:
   136       void loadUrlToCurrentPage(const QString & url);
   186       void loadUrlToCurrentPage(const QString & url);
   137       void zoomIn(qreal factor = 0.1);
   187       void zoomIn(qreal factor = 0.1);
   138       void zoomOut(qreal factor = 0.1);
   188       void zoomOut(qreal factor = 0.1);
       
   189 #ifndef BEDROCK_TILED_BACKING_STORE
       
   190       void zoomP();
       
   191       void zoomN();
       
   192       void zoomBy(qreal delta) { zoomIn(delta); }
       
   193 #else
       
   194       void setZoomActions(bool enableZoomIn, bool enableZoomOut);
       
   195 #endif
   139       void setZoomFactor(qreal factor);
   196       void setZoomFactor(qreal factor);
   140       void showMessageBox(WRT::MessageBoxProxy* data);
   197       void showMessageBox(WRT::MessageBoxProxy* data);
   141       void zoomP();
       
   142       void zoomN();
       
   143       void stop();
   198       void stop();
   144       void back();
   199       void back();
   145       void forward();
   200       void forward();
   146       void reload();
   201       void reload();
   147       void zoomBy(qreal delta) { zoomIn(delta); }
       
   148       void zoom(bool in);
   202       void zoom(bool in);
   149       void toggleZoom();
   203       void toggleZoom();
   150       void stopZoom();
   204       void stopZoom();
   151       void scrollBy(int deltaX, int deltaY) { scrollViewBy(deltaX, deltaY); }
   205       void scrollBy(int deltaX, int deltaY) { scrollViewBy(deltaX, deltaY); }
       
   206       void scrollTo(int x, int y) { scrollViewTo(x,y);}
   152       int scrollX();
   207       int scrollX();
   153       int scrollY();
   208       int scrollY();
   154       int contentWidth();
   209       int contentWidth();
   155       int contentHeight();
   210       int contentHeight();
   156 
   211 
   168     // Called by the page controller when it creates a page.
   223     // Called by the page controller when it creates a page.
   169     void pageCreated(WRT::WrtBrowserContainer * pg);
   224     void pageCreated(WRT::WrtBrowserContainer * pg);
   170     // Called by the page controller when changes a page.
   225     // Called by the page controller when changes a page.
   171     void pageChanged(WRT::WrtBrowserContainer * , WRT::WrtBrowserContainer *);
   226     void pageChanged(WRT::WrtBrowserContainer * , WRT::WrtBrowserContainer *);
   172 
   227 
       
   228 #ifdef BEDROCK_TILED_BACKING_STORE
       
   229     void handleContextEventObject(QWebHitTestResult* eventTarget);
       
   230     void handleViewScrolled(QPoint& scrollPos, QPoint& delta);
       
   231 #endif
   173   protected:
   232   protected:
       
   233 #ifdef BEDROCK_TILED_BACKING_STORE
       
   234     QGraphicsWidget* webWidgetConst();
       
   235 #else
   174     GWebContentViewWidget *webWidgetConst() const { return m_widget; }
   236     GWebContentViewWidget *webWidgetConst() const { return m_widget; }
       
   237 #endif
   175     ChromeWidget *chrome() { return m_chrome; }
   238     ChromeWidget *chrome() { return m_chrome; }
   176     void updateWebPage(WRT::WrtBrowserContainer * pg);
   239     void updateWebPage(WRT::WrtBrowserContainer * pg);
   177     void changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage);
   240     void changeContentViewZoomInfo(WRT::WrtBrowserContainer* newPage);
   178     
   241 
   179   protected:
   242   protected:
       
   243 #ifdef BEDROCK_TILED_BACKING_STORE
       
   244     WebContentViewWidget* m_widget;
       
   245 #else
   180     GWebContentViewWidget *m_widget;
   246     GWebContentViewWidget *m_widget;
       
   247 #endif
   181     QNetworkAccessManager *m_networkMgr; //Owned
   248     QNetworkAccessManager *m_networkMgr; //Owned
       
   249     ChromeWidget *m_chrome;  // not owned
   182 
   250 
   183   private:
   251   private:
   184     void setZoomActions();
   252     void setActions();
   185 
   253     virtual void setJSObject(const QString &objectName);
   186     ChromeWidget *m_chrome;  // not owned
   254     QMap<QString, QAction*>  m_actions;
   187     QAction * m_actionZoomIn;
       
   188     QAction * m_actionZoomOut;
       
   189     QTimeLine * m_timeLine;
   255     QTimeLine * m_timeLine;
   190     bool m_zoomIn;
   256     bool m_zoomIn;
   191 
   257 
   192     GWebTouchNavigation* m_touchNavigation;
   258 #ifndef BEDROCK_TILED_BACKING_STORE
       
   259     GContentViewTouchNavigation* m_touchNavigation;
       
   260 #endif
   193     bool m_backEnabled;
   261     bool m_backEnabled;
   194     bool m_forwardEnabled;
   262     bool m_forwardEnabled;
   195 
   263 
   196     ChromeWidget *m_chromeWidget;  // not owned
   264     ChromeWidget *m_chromeWidget;  // not owned
   197     typedef QMap<QString, GWebPage *> PageMap;
   265     WebPageWrapper* m_sharedPage;
       
   266     typedef QMap<QString, GSuperWebPage *> PageMap;
   198     PageMap m_superPages;
   267     PageMap m_superPages;
   199     PageMap::iterator m_currentSuperPage;
   268     PageMap::iterator m_currentSuperPage;
   200     bool m_currentPageIsSuperPage;
   269     bool m_currentPageIsSuperPage;
   201     QTimer *m_timer;
   270     QTimer *m_timer;
   202     qreal m_value;
   271     qreal m_value;
   203     bool m_gesturesEnabled;
   272     bool m_gesturesEnabled;
       
   273     bool m_enabled;
   204   };
   274   };
   205 
   275 
   206 }
   276 }
   207 
   277 
   208 #endif // GWebContentView_H
   278 #endif // GWebContentView_H