| Differences between
and this patch
- a/WebCore/ChangeLog +11 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2010-01-09  Luiz Agostini  <luiz.agostini@openbossa.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [Qt] Custom select popups.
6
        https://bugs.webkit.org/show_bug.cgi?id=33418
7
8
        qwebpopup.cpp added to WebCore.pro.
9
10
        * WebCore.pro:
11
1
2010-01-08  Adam Barth  <abarth@webkit.org>
12
2010-01-08  Adam Barth  <abarth@webkit.org>
2
13
3
        Unreviewed.  Fix namespace indent for SecurityOrigin.h.
14
        Unreviewed.  Fix namespace indent for SecurityOrigin.h.
- a/WebCore/WebCore.pro +1 lines
Lines 2472-2477 SOURCES += \ a/WebCore/WebCore.pro_sec1
2472
    ../WebKit/qt/WebCoreSupport/InspectorClientQt.cpp \
2472
    ../WebKit/qt/WebCoreSupport/InspectorClientQt.cpp \
2473
    ../WebKit/qt/Api/qwebframe.cpp \
2473
    ../WebKit/qt/Api/qwebframe.cpp \
2474
    ../WebKit/qt/Api/qgraphicswebview.cpp \
2474
    ../WebKit/qt/Api/qgraphicswebview.cpp \
2475
    ../WebKit/qt/Api/qwebpopup.cpp \
2475
    ../WebKit/qt/Api/qwebpage.cpp \
2476
    ../WebKit/qt/Api/qwebpage.cpp \
2476
    ../WebKit/qt/Api/qwebview.cpp \
2477
    ../WebKit/qt/Api/qwebview.cpp \
2477
    ../WebKit/qt/Api/qwebelement.cpp \
2478
    ../WebKit/qt/Api/qwebelement.cpp \
- a/WebKit/qt/Api/headers.pri -1 / +3 lines
Lines 11-14 WEBKIT_API_HEADERS = $$PWD/qwebframe.h \ a/WebKit/qt/Api/headers.pri_sec1
11
                     $$PWD/qwebpluginfactory.h \
11
                     $$PWD/qwebpluginfactory.h \
12
                     $$PWD/qwebhistory.h \
12
                     $$PWD/qwebhistory.h \
13
                     $$PWD/qwebinspector.h \
13
                     $$PWD/qwebinspector.h \
14
                     $$PWD/qwebkitversion.h
14
                     $$PWD/qwebkitversion.h \
15
                     $$PWD/qwebpopup.h \
16
                     $$PWD/qwebpopup_p.h
- a/WebKit/qt/Api/qwebpage.cpp -1 / +6 lines
Lines 1-5 a/WebKit/qt/Api/qwebpage.cpp_sec1
1
/*
1
/*
2
    Copyright (C) 2008, 2009 Nokia Corporation and/or its subsidiary(-ies)
2
    Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
3
    Copyright (C) 2007 Staikos Computing Services Inc.
3
    Copyright (C) 2007 Staikos Computing Services Inc.
4
    Copyright (C) 2007 Apple Inc.
4
    Copyright (C) 2007 Apple Inc.
5
5
Lines 1743-1748 QWebPage::~QWebPage() a/WebKit/qt/Api/qwebpage.cpp_sec2
1743
    delete d;
1743
    delete d;
1744
}
1744
}
1745
1745
1746
void qt_qwebpage_setPopupFactory(QWebPage* page, QWebPopupFactory* factory)
1747
{
1748
    page->d->chromeClient->setPopupFactory(factory);
1749
}
1750
1746
/*!
1751
/*!
1747
    Returns the main frame of the page.
1752
    Returns the main frame of the page.
1748
1753
- a/WebKit/qt/Api/qwebpage.h -1 / +5 lines
Lines 1-5 a/WebKit/qt/Api/qwebpage.h_sec1
1
/*
1
/*
2
    Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
2
    Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
3
    Copyright (C) 2007 Staikos Computing Services Inc.
3
    Copyright (C) 2007 Staikos Computing Services Inc.
4
4
5
    This library is free software; you can redistribute it and/or
5
    This library is free software; you can redistribute it and/or
Lines 49-54 class QWebPluginFactory; a/WebKit/qt/Api/qwebpage.h_sec2
49
class QWebHitTestResult;
49
class QWebHitTestResult;
50
class QWebHistoryItem;
50
class QWebHistoryItem;
51
51
52
class QWebPopupFactory;
53
52
namespace WebCore {
54
namespace WebCore {
53
    class ChromeClientQt;
55
    class ChromeClientQt;
54
    class EditorClientQt;
56
    class EditorClientQt;
Lines 363-368 private: a/WebKit/qt/Api/qwebpage.h_sec3
363
    friend class WebCore::InspectorClientQt;
365
    friend class WebCore::InspectorClientQt;
364
    friend class WebCore::ResourceHandle;
366
    friend class WebCore::ResourceHandle;
365
    friend class WebCore::QNetworkReplyHandler;
367
    friend class WebCore::QNetworkReplyHandler;
368
369
    friend void qt_qwebpage_setPopupFactory(QWebPage* page, QWebPopupFactory* factory);
366
};
370
};
367
371
368
Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
372
Q_DECLARE_OPERATORS_FOR_FLAGS(QWebPage::FindFlags)
- a/WebKit/qt/Api/qwebpage_p.h -1 / +3 lines
Lines 1-5 a/WebKit/qt/Api/qwebpage_p.h_sec1
1
/*
1
/*
2
    Copyright (C) 2008, 2009 Nokia Corporation and/or its subsidiary(-ies)
2
    Copyright (C) 2008, 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
3
    Copyright (C) 2008 Holger Hans Peter Freyther
3
    Copyright (C) 2008 Holger Hans Peter Freyther
4
4
5
    This library is free software; you can redistribute it and/or
5
    This library is free software; you can redistribute it and/or
Lines 185-188 public: a/WebKit/qt/Api/qwebpage_p.h_sec2
185
    static bool drtRun;
185
    static bool drtRun;
186
};
186
};
187
187
188
QWEBKIT_EXPORT void qt_qwebpage_setPopupFactory(QWebPage* page, QWebPopupFactory* factory);
189
188
#endif
190
#endif
- a/WebKit/qt/Api/qwebpopup.cpp +45 lines
Line 0 a/WebKit/qt/Api/qwebpopup.cpp_sec1
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library 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 GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 *
19
 */
20
21
#include "qwebpopup.h"
22
23
#include "qwebpopup_p.h"
24
25
QWebPopup::QWebPopup()
26
    : d(new QWebPopupPrivate())
27
{
28
}
29
30
QWebPopup::~QWebPopup()
31
{
32
    delete d;
33
}
34
35
void QWebPopup::didHide(bool acceptSuggestions)
36
{
37
    Q_ASSERT(d->observer);
38
    d->observer->didHide(acceptSuggestions);
39
}
40
41
void QWebPopup::setIndex(int index)
42
{
43
    Q_ASSERT(d->observer);
44
    d->observer->setIndex(index);
45
}
- a/WebKit/qt/Api/qwebpopup.h +69 lines
Line 0 a/WebKit/qt/Api/qwebpopup.h_sec1
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library 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 GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 *
19
 */
20
21
#ifndef qwebpopup_h
22
#define qwebpopup_h
23
24
#include "qwebkitglobal.h"
25
#include <QList>
26
#include <QRect>
27
#include <QString>
28
#include <QWidget>
29
30
class QWebPopupPrivate;
31
32
namespace WebCore {
33
class QWebPopupWrapper;
34
}
35
36
class QWEBKIT_EXPORT QWebPopup {
37
public:
38
    struct Item {
39
        enum { Option, Group, Separator } type;
40
        QString text;
41
        QString toolTip;
42
        bool enabled;
43
    };
44
45
    QWebPopup();
46
    virtual ~QWebPopup();
47
48
    virtual void show(const QRect& geometry, int selectedIndex) = 0;
49
    virtual void hide() = 0;
50
    virtual void populate(const QList<Item>& items) = 0;
51
    virtual void setParent(QWidget* parent) = 0;
52
53
protected:
54
    void didHide(bool acceptSuggestions);
55
    void setIndex(int index);
56
57
private:
58
    friend class WebCore::QWebPopupWrapper;
59
    QWebPopupPrivate* d;
60
};
61
62
class QWebPopupFactory {
63
public:
64
    virtual QWebPopup* create() = 0;
65
};
66
67
68
69
#endif // qwebpopup_h
- a/WebKit/qt/Api/qwebpopup_p.h +38 lines
Line 0 a/WebKit/qt/Api/qwebpopup_p.h_sec1
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library 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 GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 *
19
 */
20
21
#ifndef qwebpopup_p_h
22
#define qwebpopup_p_h
23
24
class QWebPopupObserver {
25
public:
26
    virtual void didHide(bool acceptSuggestions) = 0;
27
    virtual void setIndex(int index) = 0;
28
};
29
30
class QWebPopupPrivate {
31
public:
32
    QWebPopupObserver* observer;
33
34
    QWebPopupPrivate() : observer(0) {}
35
};
36
37
38
#endif // qwebpopup_p_h
- a/WebKit/qt/ChangeLog +54 lines
Lines 1-3 a/WebKit/qt/ChangeLog_sec1
1
2010-01-09  Luiz Agostini  <luiz.agostini@openbossa.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [Qt] Custom select popups.
6
        https://bugs.webkit.org/show_bug.cgi?id=33418
7
8
        Support for combobox popup customizations.
9
10
        Combobox popup customization can be made providing an instance of QWebPopupFactory to
11
        QWebPage. The factory will be used to create QWebPopup objects when needed. QWebPopup
12
        class is the base class for custom combobox popups.
13
14
        QWebPopupFactory inherited classes must implement method create and return an object
15
        of class QWebPopup.
16
17
        QWebPage interface has not been changed. No public API is avaliable to set QWebPage's
18
        factories. To use popup factories file qwebpage_p.h must be included and the factory
19
        can be set through function qtQWebPageSetPopupFactory.
20
21
        An usage example is available in QGVLauncher. Option 'Use custom popup' can be
22
        found in effects menu.
23
24
        * Api/headers.pri:
25
        * Api/qwebpage.cpp:
26
        (QWebPage::setPopupFactory):
27
        (qtQWebPageSetPopupFactory):
28
        * Api/qwebpage.h:
29
        * Api/qwebpage_p.h:
30
        * QGVLauncher/QGVLauncher.pro:
31
        * QGVLauncher/main.cpp:
32
        (factory):
33
        (WebPage::WebPage):
34
        (WebPage::setPopupFactory):
35
        (SharedScene::setPopupFactory):
36
        (MainWindow::useCustomPopup):
37
        (MainWindow::useDefaultPopup):
38
        (MainWindow::buildUI):
39
        * WebCoreSupport/ChromeClientQt.cpp:
40
        (WebCore::QWebPopupWrapper::QWebPopupWrapper):
41
        (WebCore::QWebPopupWrapper::~QWebPopupWrapper):
42
        (WebCore::QWebPopupWrapper::show):
43
        (WebCore::QWebPopupWrapper::hide):
44
        (WebCore::QWebPopupWrapper::populate):
45
        (WebCore::QWebPopupWrapper::setParent):
46
        (WebCore::QWebPopupWrapper::getItems):
47
        (WebCore::QWebPopupWrapper::didHide):
48
        (WebCore::QWebPopupWrapper::setIndex):
49
        (WebCore::ChromeClientQt::ChromeClientQt):
50
        (WebCore::ChromeClientQt::createPopup):
51
        * WebCoreSupport/ChromeClientQt.h:
52
        * WebCoreSupport/QtFallbackWebPopup.cpp:
53
        (WebCore::QtFallbackWebPopup::show):
54
1
2010-01-08  Luiz Agostini  <luiz.agostini@openbossa.org>
55
2010-01-08  Luiz Agostini  <luiz.agostini@openbossa.org>
2
56
3
        Reviewed by Kenneth Rohde Christiansen.
57
        Reviewed by Kenneth Rohde Christiansen.
- a/WebKit/qt/QGVLauncher/QGVLauncher.pro -1 / +2 lines
Lines 1-5 a/WebKit/qt/QGVLauncher/QGVLauncher.pro_sec1
1
TEMPLATE = app
1
TEMPLATE = app
2
SOURCES += main.cpp
2
SOURCES += main.cpp custompopup.cpp
3
HEADERS += custompopup.h
3
CONFIG -= app_bundle
4
CONFIG -= app_bundle
4
CONFIG += uitools
5
CONFIG += uitools
5
DESTDIR = ../../../bin
6
DESTDIR = ../../../bin
- a/WebKit/qt/QGVLauncher/custompopup.cpp +152 lines
Line 0 a/WebKit/qt/QGVLauncher/custompopup.cpp_sec1
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library 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 GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 *
19
 */
20
21
#include "custompopup.h"
22
23
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
24
#include <QPropertyAnimation>
25
#endif
26
#include <QStandardItemModel>
27
28
CustomListWidget::CustomListWidget()
29
{
30
}
31
32
void CustomListWidget::focusOutEvent(QFocusEvent* event)
33
{
34
    emit focusOut();
35
    QListWidget::focusOutEvent(event);
36
}
37
38
CustomPopup::CustomPopup()
39
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
40
    : m_animation(0)
41
#endif
42
{
43
    connect(&m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemChanged()));
44
    connect(&m_list, SIGNAL(focusOut()), this, SLOT(focusOut()));
45
}
46
47
CustomPopup::~CustomPopup()
48
{
49
}
50
51
void CustomPopup::setParent(QWidget* parent)
52
{
53
    m_list.setParent(parent);
54
}
55
56
void CustomPopup::show(const QRect& geometry, int selectedIndex)
57
{
58
    m_list.setGeometry(QRect(0, 0, geometry.width(), 250));
59
    m_list.setCurrentRow(selectedIndex);
60
    QPoint end = geometry.topLeft();
61
    QWidget* parent = m_list.parentWidget();
62
    if (parent) {
63
        end.setX(qMin(end.x(), parent->width() - m_list.width()));
64
        end.setY(qMin(end.y(), parent->height() - m_list.height()));
65
    }
66
    m_list.setGeometry(QRect(end.x(), end.y(), geometry.width(), 250));
67
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
68
    if (m_animation)
69
        m_animation->stop();
70
71
    QPoint start = QPoint(-m_list.width(), -m_list.height());
72
73
    if (parent) {
74
        start.setX(2 * end.x() < parent->width() ? -m_list.width() : parent->width());
75
        start.setY(2 * end.y() < parent->height() ? -m_list.height() : parent->height());
76
    }
77
78
    QPropertyAnimation* animation = new QPropertyAnimation();
79
    animation->setTargetObject(&m_list);
80
    animation->setPropertyName("pos");
81
    animation->setEasingCurve(QEasingCurve::OutBounce);
82
    animation->setDuration(1000);
83
    animation->setStartValue(start);
84
    animation->setEndValue(end);
85
86
    m_animation = animation;
87
    connect(animation, SIGNAL(finished()), this, SLOT(inAnimationEnd()));
88
    m_animation->start(QAbstractAnimation::DeleteWhenStopped);
89
#else
90
    inAnimationEnd();
91
#endif
92
    m_list.setVisible(true);
93
94
}
95
96
void CustomPopup::hide()
97
{
98
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
99
    if (m_animation)
100
        m_animation->stop();
101
102
    QPropertyAnimation* animation = new QPropertyAnimation;
103
    animation->setTargetObject(&m_list);
104
    animation->setPropertyName("pos");
105
    animation->setEasingCurve(QEasingCurve::OutCubic);
106
    animation->setDuration(500);
107
    animation->setEndValue(QPoint(-m_list.width(), -m_list.height()));
108
109
    m_animation = animation;
110
    connect(animation, SIGNAL(finished()), this, SLOT(outAnimationEnd()));
111
    m_animation->start(QAbstractAnimation::DeleteWhenStopped);
112
#else
113
    outAnimationEnd();
114
#endif
115
}
116
117
void CustomPopup::populate(const QList<Item>& items)
118
{
119
120
    m_list.clear();
121
122
    for (int i = 0; i < items.size(); i++) {
123
        if (items[i].type == QWebPopup::Item::Separator)
124
            m_list.addItem("--------------");
125
        else
126
            m_list.addItem(items[i].text);
127
    }
128
}
129
130
void CustomPopup::inAnimationEnd()
131
{
132
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
133
    m_animation = 0;
134
#endif
135
    m_list.setFocus();
136
}
137
138
void CustomPopup::outAnimationEnd()
139
{
140
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
141
    m_animation = 0;
142
#endif
143
    didHide(true);
144
    m_list.setParent(0);
145
    m_list.setVisible(false);
146
}
147
148
void CustomPopup::itemChanged()
149
{
150
    setIndex(m_list.currentIndex().row());
151
    hide();
152
}
- a/WebKit/qt/QGVLauncher/custompopup.h +75 lines
Line 0 a/WebKit/qt/QGVLauncher/custompopup.h_sec1
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library 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 GNU
12
 * Library General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Library General Public License
15
 * along with this library; see the file COPYING.LIB.  If not, write to
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 * Boston, MA 02110-1301, USA.
18
 *
19
 */
20
21
#ifndef custompopup_h
22
#define custompopup_h
23
24
#include "qwebpopup.h"
25
26
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
27
#include <QAbstractAnimation>
28
#endif
29
#include <QListWidget>
30
31
class CustomListWidget : public QListWidget {
32
    Q_OBJECT
33
public:
34
    CustomListWidget();
35
36
signals:
37
    void focusOut();
38
39
protected:
40
    virtual void focusOutEvent(QFocusEvent* event);
41
};
42
43
class CustomPopup : public QObject, public QWebPopup {
44
    Q_OBJECT
45
public:
46
    CustomPopup();
47
    ~CustomPopup();
48
49
50
    virtual void show(const QRect& geometry, int selectedIndex);
51
    virtual void hide();
52
    virtual void populate(const QList<Item>& items);
53
    virtual void setParent(QWidget* parent);
54
55
private:
56
    CustomListWidget m_list;
57
    QList<Item> m_items;
58
59
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
60
    QAbstractAnimation* m_animation;
61
#endif
62
63
private slots:
64
    void inAnimationEnd();
65
    void outAnimationEnd();
66
    void itemChanged();
67
    void focusOut() { hide(); }
68
};
69
70
class CustomPopupFactory : public QWebPopupFactory {
71
public:
72
    virtual QWebPopup* create() { return new CustomPopup; }
73
};
74
75
#endif // custompopup_h
- a/WebKit/qt/QGVLauncher/main.cpp -2 / +48 lines
Lines 1-5 a/WebKit/qt/QGVLauncher/main.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
2
 * Copyright (C) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies)
3
 * Copyright (C) 2006 George Staikos <staikos@kde.org>
3
 * Copyright (C) 2006 George Staikos <staikos@kde.org>
4
 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
4
 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
5
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
5
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
Lines 32-37 a/WebKit/qt/QGVLauncher/main.cpp_sec2
32
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
 */
33
 */
34
34
35
#include "custompopup.h"
35
#include <QDebug>
36
#include <QDebug>
36
#include <QFile>
37
#include <QFile>
37
#include <QGraphicsScene>
38
#include <QGraphicsScene>
Lines 47-52 a/WebKit/qt/QGVLauncher/main.cpp_sec3
47
#include <qwebframe.h>
48
#include <qwebframe.h>
48
#include <qgraphicswebview.h>
49
#include <qgraphicswebview.h>
49
#include <qwebpage.h>
50
#include <qwebpage.h>
51
#include <qwebpopup.h>
52
#include <qwebpopup_p.h>
50
#include <qwebsettings.h>
53
#include <qwebsettings.h>
51
#include <qwebview.h>
54
#include <qwebview.h>
52
55
Lines 93-98 private: a/WebKit/qt/QGVLauncher/main.cpp_sec4
93
    qreal m_yRotation;
96
    qreal m_yRotation;
94
};
97
};
95
98
99
static QWebPopupFactory* factory()
100
{
101
    static QWebPopupFactory* result(new CustomPopupFactory);
102
    return result;
103
}
104
96
class WebPage : public QWebPage {
105
class WebPage : public QWebPage {
97
    Q_OBJECT
106
    Q_OBJECT
98
107
Lines 101-109 public: a/WebKit/qt/QGVLauncher/main.cpp_sec5
101
        : QWebPage(parent)
110
        : QWebPage(parent)
102
    {
111
    {
103
        applyProxy();
112
        applyProxy();
113
        setPopupFactory(false);
104
    }
114
    }
105
    virtual QWebPage* createWindow(QWebPage::WebWindowType);
115
    virtual QWebPage* createWindow(QWebPage::WebWindowType);
106
116
117
    void setPopupFactory(bool useCustomPopup)
118
    {
119
        qt_qwebpage_setPopupFactory(this, useCustomPopup ? factory() : 0);
120
    }
121
107
private:
122
private:
108
    void applyProxy()
123
    void applyProxy()
109
    {
124
    {
Lines 222-227 public: a/WebKit/qt/QGVLauncher/main.cpp_sec6
222
    QGraphicsScene* scene() const { return m_scene; }
237
    QGraphicsScene* scene() const { return m_scene; }
223
    WebView* webView() const { return m_item; }
238
    WebView* webView() const { return m_item; }
224
239
240
    void setPopupFactory(bool useCustomPopup)
241
    {
242
        m_page->setPopupFactory(useCustomPopup);
243
    }
244
225
private:
245
private:
226
    QGraphicsScene* m_scene;
246
    QGraphicsScene* m_scene;
227
    WebView* m_item;
247
    WebView* m_item;
Lines 382-387 public slots: a/WebKit/qt/QGVLauncher/main.cpp_sec7
382
        view->animatedYFlip();
402
        view->animatedYFlip();
383
    }
403
    }
384
404
405
    void useCustomPopup()
406
    {
407
        m_useCustomPopup->setVisible(false);
408
        m_useDefaultPopup->setVisible(true);
409
        scene->setPopupFactory(true);
410
        m_reload->trigger();
411
    }
412
413
    void useDefaultPopup()
414
    {
415
        m_useCustomPopup->setVisible(true);
416
        m_useDefaultPopup->setVisible(false);
417
        scene->setPopupFactory(false);
418
        m_reload->trigger();
419
    }
420
385
private:
421
private:
386
422
387
    void loadURL(const QUrl& url)
423
    void loadURL(const QUrl& url)
Lines 404-410 private: a/WebKit/qt/QGVLauncher/main.cpp_sec8
404
        QToolBar* bar = addToolBar("Navigation");
440
        QToolBar* bar = addToolBar("Navigation");
405
        bar->addAction(page->action(QWebPage::Back));
441
        bar->addAction(page->action(QWebPage::Back));
406
        bar->addAction(page->action(QWebPage::Forward));
442
        bar->addAction(page->action(QWebPage::Forward));
407
        bar->addAction(page->action(QWebPage::Reload));
443
        m_reload = page->action(QWebPage::Reload);
444
        bar->addAction(m_reload);
408
        bar->addAction(page->action(QWebPage::Stop));
445
        bar->addAction(page->action(QWebPage::Stop));
409
        bar->addWidget(urlEdit);
446
        bar->addWidget(urlEdit);
410
447
Lines 428-439 private: a/WebKit/qt/QGVLauncher/main.cpp_sec9
428
        fxMenu->addAction("Flip", this, SLOT(flip()));
465
        fxMenu->addAction("Flip", this, SLOT(flip()));
429
        fxMenu->addAction("Animated Flip", this, SLOT(animatedFlip()), QKeySequence("Ctrl+R"));
466
        fxMenu->addAction("Animated Flip", this, SLOT(animatedFlip()), QKeySequence("Ctrl+R"));
430
        fxMenu->addAction("Animated Y-Flip", this, SLOT(animatedYFlip()), QKeySequence("Ctrl+Y"));
467
        fxMenu->addAction("Animated Y-Flip", this, SLOT(animatedYFlip()), QKeySequence("Ctrl+Y"));
468
469
        m_useCustomPopup = fxMenu->addAction("Use custom popup", this, SLOT(useCustomPopup()));
470
        m_useDefaultPopup = fxMenu->addAction("Use default popup", this, SLOT(useDefaultPopup()));
471
472
        useDefaultPopup();
431
    }
473
    }
432
474
433
private:
475
private:
434
    MainView* view;
476
    MainView* view;
435
    QExplicitlySharedDataPointer<SharedScene> scene;
477
    QExplicitlySharedDataPointer<SharedScene> scene;
436
478
479
    QAction* m_useCustomPopup;
480
    QAction* m_useDefaultPopup;
481
    QAction* m_reload;
482
437
    QLineEdit* urlEdit;
483
    QLineEdit* urlEdit;
438
};
484
};
439
485
- a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp +102 lines
Lines 1-4 a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
2
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
4
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
4
 *
5
 *
Lines 45-50 a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp_sec2
45
#include "qwebpage.h"
46
#include "qwebpage.h"
46
#include "qwebpage_p.h"
47
#include "qwebpage_p.h"
47
#include "qwebframe_p.h"
48
#include "qwebframe_p.h"
49
#include "qwebpopup.h"
50
#include "qwebpopup_p.h"
48
#include "qwebsecurityorigin.h"
51
#include "qwebsecurityorigin.h"
49
#include "qwebsecurityorigin_p.h"
52
#include "qwebsecurityorigin_p.h"
50
#include "qwebview.h"
53
#include "qwebview.h"
Lines 56-63 namespace WebCore a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp_sec3
56
{
59
{
57
60
58
61
62
class QWebPopupWrapper : public QtAbstractWebPopup, private QWebPopupObserver {
63
public:
64
    QWebPopupWrapper(QWebPopup* popup);
65
    ~QWebPopupWrapper();
66
67
public: // QtAbstractWebPopup
68
    virtual void show(const QRect& geometry, int selectedIndex);
69
    virtual void hide();
70
    virtual void populate(const QFont& font, const QList<Item>& items);
71
    virtual void setParent(QWidget* parent);
72
73
private:
74
    QWebPopup* m_popup;
75
76
    QList<QWebPopup::Item> getItems(const QList<Item>& items);
77
78
private: // QWebPopupObserver
79
    void didHide(bool acceptSuggestions);
80
    void setIndex(int index);
81
};
82
83
QWebPopupWrapper::QWebPopupWrapper(QWebPopup* popup)
84
    : m_popup(popup)
85
{
86
    Q_ASSERT(m_popup);
87
    m_popup->d->observer = this;
88
}
89
90
QWebPopupWrapper::~QWebPopupWrapper()
91
{
92
    delete m_popup;
93
}
94
95
void QWebPopupWrapper::show(const QRect& geometry, int selectedIndex)
96
{
97
    m_popup->show(geometry, selectedIndex);
98
}
99
100
void QWebPopupWrapper::hide()
101
{
102
    m_popup->hide();
103
}
104
105
void QWebPopupWrapper::populate(const QFont& font, const QList<Item>& items)
106
{
107
    Q_UNUSED(font);
108
    m_popup->populate(getItems(items));
109
}
110
111
void QWebPopupWrapper::setParent(QWidget* parent)
112
{
113
    m_popup->setParent(parent);
114
}
115
116
QList<QWebPopup::Item> QWebPopupWrapper::getItems(const QList<Item>& items)
117
{
118
    QList<QWebPopup::Item> result;
119
120
    for (int i = 0; i < items.size(); ++i) {
121
        QWebPopup::Item item;
122
123
        switch (items[i].type) {
124
        case Item::Option:
125
            item.type = QWebPopup::Item::Option;
126
        case Item::Separator:
127
            item.type = QWebPopup::Item::Separator;
128
        case Item::Group:
129
            item.type = QWebPopup::Item::Group;
130
        }
131
132
        item.text = items[i].text;
133
        item.toolTip = items[i].toolTip;
134
        item.enabled = items[i].enabled;
135
136
        result.append(item);
137
    }
138
139
    return result;
140
}
141
142
void QWebPopupWrapper::didHide(bool acceptSuggestions)
143
{
144
    popupDidHide(acceptSuggestions);
145
}
146
147
void QWebPopupWrapper::setIndex(int index)
148
{
149
    valueChanged(index);
150
}
151
152
59
ChromeClientQt::ChromeClientQt(QWebPage* webPage)
153
ChromeClientQt::ChromeClientQt(QWebPage* webPage)
60
    : m_webPage(webPage)
154
    : m_webPage(webPage)
155
    , m_popupFactory(0)
61
{
156
{
62
    toolBarsVisible = statusBarVisible = menuBarVisible = true;
157
    toolBarsVisible = statusBarVisible = menuBarVisible = true;
63
}
158
}
Lines 67-72 ChromeClientQt::~ChromeClientQt() a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp_sec4
67
162
68
}
163
}
69
164
165
void ChromeClientQt::setPopupFactory(QWebPopupFactory* popupFactory)
166
{
167
    m_popupFactory = popupFactory;
168
}
169
70
void ChromeClientQt::setWindowRect(const FloatRect& rect)
170
void ChromeClientQt::setWindowRect(const FloatRect& rect)
71
{
171
{
72
    if (!m_webPage)
172
    if (!m_webPage)
Lines 468-473 void ChromeClientQt::requestGeolocationPermissionForFrame(Frame*, Geolocation*) a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp_sec5
468
568
469
QtAbstractWebPopup* ChromeClientQt::createPopup()
569
QtAbstractWebPopup* ChromeClientQt::createPopup()
470
{
570
{
571
    if (m_popupFactory)
572
        return new QWebPopupWrapper(m_popupFactory->create());
471
    return new QtFallbackWebPopup;
573
    return new QtFallbackWebPopup;
472
}
574
}
473
575
- a/WebKit/qt/WebCoreSupport/ChromeClientQt.h +6 lines
Lines 1-4 a/WebKit/qt/WebCoreSupport/ChromeClientQt.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
2
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3
 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3
 *
4
 *
4
 * All rights reserved.
5
 * All rights reserved.
Lines 35-40 a/WebKit/qt/WebCoreSupport/ChromeClientQt.h_sec2
35
#include "PlatformString.h"
36
#include "PlatformString.h"
36
37
37
class QWebPage;
38
class QWebPage;
39
class QWebPopupFactory;
38
40
39
namespace WebCore {
41
namespace WebCore {
40
42
Lines 137-142 namespace WebCore { a/WebKit/qt/WebCoreSupport/ChromeClientQt.h_sec3
137
139
138
        QtAbstractWebPopup* createPopup();
140
        QtAbstractWebPopup* createPopup();
139
141
142
        void setPopupFactory(QWebPopupFactory* popupFactory);
143
140
        QWebPage* m_webPage;
144
        QWebPage* m_webPage;
141
        WebCore::KURL lastHoverURL;
145
        WebCore::KURL lastHoverURL;
142
        WebCore::String lastHoverTitle;
146
        WebCore::String lastHoverTitle;
Lines 145-150 namespace WebCore { a/WebKit/qt/WebCoreSupport/ChromeClientQt.h_sec4
145
        bool toolBarsVisible;
149
        bool toolBarsVisible;
146
        bool statusBarVisible;
150
        bool statusBarVisible;
147
        bool menuBarVisible;
151
        bool menuBarVisible;
152
153
        QWebPopupFactory* m_popupFactory;
148
    };
154
    };
149
}
155
}
150
156
- a/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp -9 lines
Lines 46-59 void QtFallbackWebPopup::show(const QRect& geometry, int selectedIndex) a/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp_sec1
46
{
46
{
47
    setCurrentIndex(selectedIndex);
47
    setCurrentIndex(selectedIndex);
48
48
49
    /*
50
    QWidget* parent = 0;
51
    if (client()->hostWindow() && client()->hostWindow()->platformPageClient())
52
       parent = client()->hostWindow()->platformPageClient()->ownerWidget();
53
54
    setParent(parent);
55
    */
56
57
    setGeometry(QRect(geometry.left(), geometry.top(), geometry.width(), sizeHint().height()));
49
    setGeometry(QRect(geometry.left(), geometry.top(), geometry.width(), sizeHint().height()));
58
50
59
    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
51
    QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton,
60
- 

Return to Bug 33418