Commit bd66c04e authored by ariya@webkit.org's avatar ariya@webkit.org

2009-04-21 Antonio Gomes <antonio.gomes@openbossa.org>

        Reviewed by Ariya Hidayat.

        QWebElementSelection renamed to QWebElementCollection.

        * Api/qwebelement.cpp:
        (QWebElement::findAll):
        (QWebElementCollectionPrivate::QWebElementCollectionPrivate):
        (QWebElementCollectionPrivate::create):
        (QWebElementCollection::QWebElementCollection):
        (QWebElementCollection::operator=):
        (QWebElementCollection::~QWebElementCollection):
        (QWebElementCollection::operator+):
        (QWebElementCollection::append):
        (QWebElementCollection::count):
        (QWebElementCollection::at):
        (QWebElementCollection::toList):
        * Api/qwebelement.h:
        * Api/qwebframe.cpp:
        (QWebFrame::findAllElements):
        * Api/qwebframe.h:
        * QtLauncher/main.cpp:
        (MainWindow::selectElements):
        * tests/qwebelement/tst_qwebelement.cpp:
        (tst_QWebElement::simpleCollection):
        (tst_QWebElement::iteration):
        (tst_QWebElement::emptyCollection):
        (tst_QWebElement::appendCollection):
        (tst_QWebElement::nullSelect):

git-svn-id: svn://svn.chromium.org/blink/trunk@42710 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent cd80ce0f
...@@ -31,7 +31,7 @@ namespace WebCore { ...@@ -31,7 +31,7 @@ namespace WebCore {
} }
class QWebFrame; class QWebFrame;
class QWebElementSelection; class QWebElementCollection;
class QWebElementPrivate; class QWebElementPrivate;
class QWEBKIT_EXPORT QWebElement class QWEBKIT_EXPORT QWebElement
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
bool isNull() const; bool isNull() const;
QWebElementSelection findAll(const QString &query) const; QWebElementCollection findAll(const QString &query) const;
QWebElement findFirst(const QString &query) const; QWebElement findFirst(const QString &query) const;
void setPlainText(const QString &text); void setPlainText(const QString &text);
...@@ -93,7 +93,7 @@ public: ...@@ -93,7 +93,7 @@ public:
QWebElement document() const; QWebElement document() const;
QWebFrame *webFrame() const; QWebFrame *webFrame() const;
// TODO: Add QWebElementSelection overloads // TODO: Add QWebElementCollection overloads
void append(const QString &html); void append(const QString &html);
void append(QWebElement element); void append(QWebElement element);
...@@ -130,31 +130,31 @@ private: ...@@ -130,31 +130,31 @@ private:
QWebElement(WebCore::Element *domElement); QWebElement(WebCore::Element *domElement);
friend class QWebFrame; friend class QWebFrame;
friend class QWebElementSelection; friend class QWebElementCollection;
friend class QWebHitTestResult; friend class QWebHitTestResult;
QWebElementPrivate *d; QWebElementPrivate *d;
WebCore::Element *m_element; WebCore::Element *m_element;
}; };
class QWebElementSelectionPrivate; class QWebElementCollectionPrivate;
class QWEBKIT_EXPORT QWebElementSelection class QWEBKIT_EXPORT QWebElementCollection
{ {
public: public:
QWebElementSelection(); QWebElementCollection();
QWebElementSelection(const QWebElement &contextElement, const QString &query); QWebElementCollection(const QWebElement &contextElement, const QString &query);
QWebElementSelection(const QWebElementSelection &); QWebElementCollection(const QWebElementCollection &);
QWebElementSelection &operator=(const QWebElementSelection &); QWebElementCollection &operator=(const QWebElementCollection &);
~QWebElementSelection(); ~QWebElementCollection();
QWebElementSelection operator+(const QWebElementSelection &other) const; QWebElementCollection operator+(const QWebElementCollection &other) const;
inline QWebElementSelection &operator+=(const QWebElementSelection &other) inline QWebElementCollection &operator+=(const QWebElementCollection &other)
{ {
append(other); return *this; append(other); return *this;
} }
void append(const QWebElementSelection &selection); void append(const QWebElementCollection &collection);
int count() const; int count() const;
QWebElement at(int i) const; QWebElement at(int i) const;
...@@ -167,9 +167,9 @@ public: ...@@ -167,9 +167,9 @@ public:
class const_iterator { class const_iterator {
public: public:
int i; int i;
const QWebElementSelection *s; const QWebElementCollection *s;
inline const_iterator(const QWebElementSelection *selection, int index) : i(index), s(selection) {} inline const_iterator(const QWebElementCollection *collection, int index) : i(index), s(collection) {}
inline const_iterator(const const_iterator &o) : i(o.i), s(o.s) {} inline const_iterator(const const_iterator &o) : i(o.i), s(o.s) {}
inline const QWebElement operator*() const { return s->at(i); } inline const QWebElement operator*() const { return s->at(i); }
...@@ -200,7 +200,7 @@ public: ...@@ -200,7 +200,7 @@ public:
inline const QWebElement operator[](int i) const { return at(i); } inline const QWebElement operator[](int i) const { return at(i); }
private: private:
QExplicitlySharedDataPointer<QWebElementSelectionPrivate> d; QExplicitlySharedDataPointer<QWebElementCollectionPrivate> d;
}; };
#endif // QWEBELEMENT_H #endif // QWEBELEMENT_H
...@@ -982,10 +982,10 @@ QWebElement QWebFrame::documentElement() const ...@@ -982,10 +982,10 @@ QWebElement QWebFrame::documentElement() const
/*! /*!
\since 4.6 \since 4.6
Returns a new selection of elements that are children of the frame's Returns a new collection of elements that are children of the frame's
document element and that match the given CSS selector \a query. document element and that match the given CSS selector \a query.
*/ */
QWebElementSelection QWebFrame::findAllElements(const QString &query) const QWebElementCollection QWebFrame::findAllElements(const QString &query) const
{ {
return documentElement().findAll(query); return documentElement().findAll(query);
} }
......
...@@ -50,7 +50,7 @@ class QWebHitTestResult; ...@@ -50,7 +50,7 @@ class QWebHitTestResult;
class QWebHistoryItem; class QWebHistoryItem;
class QWebSecurityOrigin; class QWebSecurityOrigin;
class QWebElement; class QWebElement;
class QWebElementSelection; class QWebElementCollection;
namespace WebCore { namespace WebCore {
class WidgetPrivate; class WidgetPrivate;
...@@ -179,7 +179,7 @@ public: ...@@ -179,7 +179,7 @@ public:
QSize contentsSize() const; QSize contentsSize() const;
QWebElement documentElement() const; QWebElement documentElement() const;
QWebElementSelection findAllElements(const QString &query) const; QWebElementCollection findAllElements(const QString &query) const;
QWebElement findFirstElement(const QString &query) const; QWebElement findFirstElement(const QString &query) const;
QWebHitTestResult hitTestContent(const QPoint &pos) const; QWebHitTestResult hitTestContent(const QPoint &pos) const;
......
2009-04-21 Antonio Gomes <antonio.gomes@openbossa.org>
Reviewed by Ariya Hidayat.
QWebElementSelection renamed to QWebElementCollection.
* Api/qwebelement.cpp:
(QWebElement::findAll):
(QWebElementCollectionPrivate::QWebElementCollectionPrivate):
(QWebElementCollectionPrivate::create):
(QWebElementCollection::QWebElementCollection):
(QWebElementCollection::operator=):
(QWebElementCollection::~QWebElementCollection):
(QWebElementCollection::operator+):
(QWebElementCollection::append):
(QWebElementCollection::count):
(QWebElementCollection::at):
(QWebElementCollection::toList):
* Api/qwebelement.h:
* Api/qwebframe.cpp:
(QWebFrame::findAllElements):
* Api/qwebframe.h:
* QtLauncher/main.cpp:
(MainWindow::selectElements):
* tests/qwebelement/tst_qwebelement.cpp:
(tst_QWebElement::simpleCollection):
(tst_QWebElement::iteration):
(tst_QWebElement::emptyCollection):
(tst_QWebElement::appendCollection):
(tst_QWebElement::nullSelect):
2009-04-17 Laszlo Gombos <laszlo.1.gombos@nokia.com> 2009-04-17 Laszlo Gombos <laszlo.1.gombos@nokia.com>
Reviewed by Simon Hausmann. Reviewed by Simon Hausmann.
......
...@@ -188,7 +188,7 @@ protected slots: ...@@ -188,7 +188,7 @@ protected slots:
QString str = QInputDialog::getText(this, "Select elements", "Choose elements", QString str = QInputDialog::getText(this, "Select elements", "Choose elements",
QLineEdit::Normal, "a", &ok); QLineEdit::Normal, "a", &ok);
if (ok && !str.isEmpty()) { if (ok && !str.isEmpty()) {
QWebElementSelection result = view->page()->mainFrame()->findAllElements(str); QWebElementCollection result = view->page()->mainFrame()->findAllElements(str);
foreach (QWebElement e, result) foreach (QWebElement e, result)
e.setStyleProperty("background-color", "yellow"); e.setStyleProperty("background-color", "yellow");
statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000); statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000);
......
...@@ -65,7 +65,7 @@ public slots: ...@@ -65,7 +65,7 @@ public slots:
private slots: private slots:
void textHtml(); void textHtml();
void simpleSelection(); void simpleCollection();
void attributes(); void attributes();
void attributesNS(); void attributesNS();
void classes(); void classes();
...@@ -77,9 +77,9 @@ private slots: ...@@ -77,9 +77,9 @@ private slots:
void functionNames(); void functionNames();
void documentElement(); void documentElement();
void frame(); void frame();
void emptySelection(); void emptyCollection();
void style(); void style();
void appendSelection(); void appendCollection();
void properties(); void properties();
void appendAndPrepend(); void appendAndPrepend();
void insertBeforeAndAfter(); void insertBeforeAndAfter();
...@@ -132,13 +132,13 @@ void tst_QWebElement::textHtml() ...@@ -132,13 +132,13 @@ void tst_QWebElement::textHtml()
QCOMPARE(body.toXml(QWebElement::InnerXml), html); QCOMPARE(body.toXml(QWebElement::InnerXml), html);
} }
void tst_QWebElement::simpleSelection() void tst_QWebElement::simpleCollection()
{ {
QString html = "<body><p>first para</p><p>second para</p></body>"; QString html = "<body><p>first para</p><p>second para</p></body>";
m_mainFrame->setHtml(html); m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QWebElementSelection paras = body.findAll("p"); QWebElementCollection paras = body.findAll("p");
QCOMPARE(paras.count(), 2); QCOMPARE(paras.count(), 2);
QList<QWebElement> list = paras.toList(); QList<QWebElement> list = paras.toList();
...@@ -294,7 +294,7 @@ void tst_QWebElement::iteration() ...@@ -294,7 +294,7 @@ void tst_QWebElement::iteration()
m_mainFrame->setHtml(html); m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QWebElementSelection paras = body.findAll("p"); QWebElementCollection paras = body.findAll("p");
QList<QWebElement> referenceList = paras.toList(); QList<QWebElement> referenceList = paras.toList();
QList<QWebElement> foreachList; QList<QWebElement> foreachList;
...@@ -410,10 +410,10 @@ void tst_QWebElement::frame() ...@@ -410,10 +410,10 @@ void tst_QWebElement::frame()
QVERIFY(secondPara.webFrame() == secondFrame); QVERIFY(secondPara.webFrame() == secondFrame);
} }
void tst_QWebElement::emptySelection() void tst_QWebElement::emptyCollection()
{ {
QWebElementSelection emptySelection; QWebElementCollection emptyCollection;
QCOMPARE(emptySelection.count(), 0); QCOMPARE(emptyCollection.count(), 0);
} }
void tst_QWebElement::style() void tst_QWebElement::style()
...@@ -432,34 +432,34 @@ void tst_QWebElement::style() ...@@ -432,34 +432,34 @@ void tst_QWebElement::style()
QCOMPARE(p.styleProperty("cursor"), QLatin1String("auto")); QCOMPARE(p.styleProperty("cursor"), QLatin1String("auto"));
} }
void tst_QWebElement::appendSelection() void tst_QWebElement::appendCollection()
{ {
QString html = "<body><span class='a'>aaa</span><p>first para</p><div>foo</div>" QString html = "<body><span class='a'>aaa</span><p>first para</p><div>foo</div>"
"<span class='b'>bbb</span><p>second para</p><div>bar</div></body>"; "<span class='b'>bbb</span><p>second para</p><div>bar</div></body>";
m_mainFrame->setHtml(html); m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement(); QWebElement body = m_mainFrame->documentElement();
QWebElementSelection selection = body.findAll("p"); QWebElementCollection collection = body.findAll("p");
QCOMPARE(selection.count(), 2); QCOMPARE(collection.count(), 2);
selection.append(body.findAll("div")); collection.append(body.findAll("div"));
QCOMPARE(selection.count(), 4); QCOMPARE(collection.count(), 4);
selection += body.findAll("span.a"); collection += body.findAll("span.a");
QCOMPARE(selection.count(), 5); QCOMPARE(collection.count(), 5);
QWebElementSelection all = selection + body.findAll("span.b"); QWebElementCollection all = collection + body.findAll("span.b");
QCOMPARE(all.count(), 6); QCOMPARE(all.count(), 6);
QCOMPARE(selection.count(), 5); QCOMPARE(collection.count(), 5);
all += selection; all += collection;
QCOMPARE(all.count(), 11); QCOMPARE(all.count(), 11);
QCOMPARE(selection.count(), 5); QCOMPARE(collection.count(), 5);
QWebElementSelection test; QWebElementCollection test;
test.append(selection); test.append(collection);
QCOMPARE(test.count(), 5); QCOMPARE(test.count(), 5);
test.append(QWebElementSelection()); test.append(QWebElementCollection());
QCOMPARE(test.count(), 5); QCOMPARE(test.count(), 5);
} }
...@@ -696,8 +696,8 @@ void tst_QWebElement::nullSelect() ...@@ -696,8 +696,8 @@ void tst_QWebElement::nullSelect()
{ {
m_mainFrame->setHtml("<body><p>Test"); m_mainFrame->setHtml("<body><p>Test");
QWebElementSelection selection = m_mainFrame->findAllElements("invalid{syn(tax;;%#$f223e>>"); QWebElementCollection collection = m_mainFrame->findAllElements("invalid{syn(tax;;%#$f223e>>");
QVERIFY(selection.count() == 0); QVERIFY(collection.count() == 0);
} }
void tst_QWebElement::firstChildNextSibling() void tst_QWebElement::firstChildNextSibling()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment