summaryrefslogtreecommitdiff
path: root/browser/browserview.h
blob: 853c66f09b2d50d382c9fcaa77947e216dc70eba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * Copyright (C) 2014, Pelagicore
 *
 * Author: Jonatan PĂ„lsson <jonatan.palsson@pelagicore.com>
 *
 * This file is part of the GENIVI project Browser Proof-Of-Concept
 * For further information, see http://genivi.org/
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef BROWSERVIEW_H
#define BROWSERVIEW_H

#include <QGraphicsWebView>
#include <QGraphicsView>
#include <QResizeEvent>
#include <QWebElement>
#include <QDebug>
#include <QSemaphore>
#include <QNetworkAccessManager>

#include "cachemanager.h"
#include "../common/browserdefs.h"

class WebPageWaiter : public QObject {
Q_OBJECT
public slots:
    void loadFinished() { finishedSem.release(1); }
public:
    QSemaphore finishedSem;
};

class InputHandler : public QObject {
Q_OBJECT
public slots:
    void setScrollPosition (const int &x, const int &y) {
        emit onScroll ((uint)x,(uint)y);
    }
    void setCurrentFocus (const QWebElement &elem) {
    emit onInputText (elem.attribute("name"), elem.attribute("value"),
                      elem.attribute("type", "0").toInt(),
                      elem.attribute("maxlength", "0").toInt(),
                      elem.attribute("max", "0").toInt(),
                      elem.attribute("min","0").toInt(),
                      elem.attribute("step","0").toInt());
    }
    const QWebElement *currentFocus () { return m_elem; }

signals:
    void onInputText(QString name, QString value, int type, int maxlength,
                     int max, int min, int step);
    void onScroll(uint x, uint y);

private:
    QWebElement *m_elem;
};

class BrowserView : public QGraphicsView
{
     Q_OBJECT
public:
    BrowserView();
    bool load(const QString &a_Url);
    int getProgress() { return m_currentProgress; }
    QString getUrl() { return m_webview.url().toString(); }
    const QString getTitle() { return m_webview.title(); }
    void goBack() { m_webview.back(); }
    void goForward() { m_webview.forward(); }
    void pageReload() { m_webview.reload(); }
    void pageStop() { m_webview.stop(); }
    void scroll (conn::brw::SCROLL_DIRECTION dir, conn::brw::SCROLL_TYPE type);
    void inputText (QString input);
    QSize contentSize();
    void setZoomFactor(double);
    double getZoomFactor();
    void getScrollPosition(uint&, uint&);
    void setScrollPosition(uint, uint);
    QString createScreenshot(QString url);
    QString getFaviconFilePath(QString url);
    void activate();
    void select();
    void setCacheManager (cachemanager *nm);

signals:
    void pageLoadStarted();
    void pageLoadFinished(bool);
    void pageLoadProgress(int);
    void onInputText(QString name, QString value, int type, int maxlength,
                     int max, int min, int step);
    void onUrlChanged(QString url);
    void onTitleChanged(QString title);
    void onLinkClicked(QString);
    void onSelectionChanged();
    void onStatusTextChanged(QString);
    void onVisibilityChanged(bool);
    void onScrollPositionChanged(uint,uint);
    void onZoomFactorChanged(double);
    void onLinkHovered(QString);
    void onActionStateChanged(uint);
    void onContentSizeChanged(uint, uint);
    void onFaviconReceived();

protected:
    virtual void resizeEvent (QResizeEvent *event);
    virtual bool eventFilter (QObject *obj, QEvent *evt);

protected slots:
    void loadProgress(int);
    void loadFinished(bool);
    void urlChanged(QUrl);
    void titleChanged(QString);
    void linkClicked(QUrl);
    void scrollPositionChanged(uint x, uint y);
    void contentSizeChanged(const QSize&);

private:
    QGraphicsWebView m_webview;
    InputHandler m_inputHandler;
    int m_currentProgress;
    uint m_scrollPositionX;
    uint m_scrollPositionY;
    cachemanager *m_cacheManager = NULL;
};


#endif /* BROWSERVIEW_H */