Commit 2bb5409c authored by hausmann@webkit.org's avatar hausmann@webkit.org

2009-04-29 Simon Hausmann <simon.hausmann@nokia.com>

        Reviewed by Ariya Hidayat.

        Replaced QWebElementCollection with QList<QWebElement>.

git-svn-id: svn://svn.chromium.org/blink/trunk@42994 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 05604217
......@@ -31,7 +31,6 @@ namespace WebCore {
}
class QWebFrame;
class QWebElementCollection;
class QWebElementPrivate;
class QWEBKIT_EXPORT QWebElement
......@@ -47,7 +46,7 @@ public:
bool isNull() const;
QWebElementCollection findAll(const QString &selectorQuery) const;
QList<QWebElement> findAll(const QString &selectorQuery) const;
QWebElement findFirst(const QString &selectorQuery) const;
void setPlainText(const QString &text);
......@@ -90,7 +89,7 @@ public:
QWebElement document() const;
QWebFrame *webFrame() const;
// TODO: Add QWebElementCollection overloads
// TODO: Add QList<QWebElement> overloads
// docs need example snippet
void appendInside(const QString &markup);
void appendInside(const QWebElement &element);
......@@ -135,77 +134,10 @@ private:
QWebElement(WebCore::Element *domElement);
friend class QWebFrame;
friend class QWebElementCollection;
friend class QWebHitTestResult;
QWebElementPrivate *d;
WebCore::Element *m_element;
};
class QWebElementCollectionPrivate;
class QWEBKIT_EXPORT QWebElementCollection
{
public:
QWebElementCollection();
QWebElementCollection(const QWebElement &contextElement, const QString &query);
QWebElementCollection(const QWebElementCollection &);
QWebElementCollection &operator=(const QWebElementCollection &);
~QWebElementCollection();
QWebElementCollection operator+(const QWebElementCollection &other) const;
inline QWebElementCollection &operator+=(const QWebElementCollection &other)
{
append(other); return *this;
}
void append(const QWebElementCollection &collection);
int count() const;
QWebElement at(int i) const;
inline QWebElement first() const { return at(0); }
inline QWebElement last() const { return at(count() - 1); }
QList<QWebElement> toList() const;
class const_iterator {
public:
int i;
const QWebElementCollection *s;
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 QWebElement operator*() const { return s->at(i); }
inline bool operator==(const const_iterator& o) const { return i == o.i && s == o.s; }
inline bool operator!=(const const_iterator& o) const { return i != o.i || s != o.s; }
inline bool operator<(const const_iterator& o) const { return i < o.i; }
inline bool operator<=(const const_iterator& o) const { return i <= o.i; }
inline bool operator>(const const_iterator& o) const { return i > o.i; }
inline bool operator>=(const const_iterator& o) const { return i >= o.i; }
inline const_iterator &operator++() { ++i; return *this; }
inline const_iterator operator++(int) { const_iterator n(s, i); ++i; return n; }
inline const_iterator &operator--() { i--; return *this; }
inline const_iterator operator--(int) { const_iterator n(s, i); i--; return n; }
inline const_iterator &operator+=(int j) { i += j; return *this; }
inline const_iterator &operator-=(int j) { i -= j; return *this; }
inline const_iterator operator+(int j) const { return const_iterator(s, i + j); }
inline const_iterator operator-(int j) const { return const_iterator(s, i - j); }
inline int operator-(const_iterator j) const { return i - j.i; }
private:
inline const_iterator() : i(0), s(0) {}
};
friend class const_iterator;
inline const_iterator begin() const { return const_iterator(this, 0); }
inline const_iterator end() const { return const_iterator(this, count()); }
inline const QWebElement operator[](int i) const { return at(i); }
private:
QExplicitlySharedDataPointer<QWebElementCollectionPrivate> d;
};
#endif // QWEBELEMENT_H
......@@ -985,7 +985,7 @@ QWebElement QWebFrame::documentElement() const
Returns a new collection of elements that are children of the frame's
document element and that match the given CSS selector \a selectorQuery.
*/
QWebElementCollection QWebFrame::findAllElements(const QString &selectorQuery) const
QList<QWebElement> QWebFrame::findAllElements(const QString &selectorQuery) const
{
return documentElement().findAll(selectorQuery);
}
......
......@@ -50,7 +50,6 @@ class QWebHitTestResult;
class QWebHistoryItem;
class QWebSecurityOrigin;
class QWebElement;
class QWebElementCollection;
namespace WebCore {
class WidgetPrivate;
......@@ -179,7 +178,7 @@ public:
QSize contentsSize() const;
QWebElement documentElement() const;
QWebElementCollection findAllElements(const QString &selectorQuery) const;
QList<QWebElement> findAllElements(const QString &selectorQuery) const;
QWebElement findFirstElement(const QString &selectorQuery) const;
QWebHitTestResult hitTestContent(const QPoint &pos) const;
......
2009-04-29 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Ariya Hidayat.
Replaced QWebElementCollection with QList<QWebElement>.
* Api/qwebelement.cpp:
(QWebElement::findAll):
* 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::namespaceURI):
(tst_QWebElement::nullSelect):
2009-04-28 Simon Hausmann <simon.hausmann@nokia.com>
Reviewed by Tor Arne Vestbø.
......
......@@ -188,7 +188,7 @@ protected slots:
QString str = QInputDialog::getText(this, "Select elements", "Choose elements",
QLineEdit::Normal, "a", &ok);
if (ok && !str.isEmpty()) {
QWebElementCollection result = view->page()->mainFrame()->findAllElements(str);
QList<QWebElement> result = view->page()->mainFrame()->findAllElements(str);
foreach (QWebElement e, result)
e.setStyleProperty("background-color", "yellow");
statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000);
......
......@@ -70,17 +70,14 @@ private slots:
void attributesNS();
void classes();
void namespaceURI();
void iteration();
void foreachManipulation();
void callFunction();
void callFunctionSubmitForm();
void functionNames();
void documentElement();
void frame();
void emptyCollection();
void style();
void computedStyle();
void appendCollection();
void properties();
void appendAndPrepend();
void insertBeforeAndAfter();
......@@ -137,10 +134,7 @@ void tst_QWebElement::simpleCollection()
m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement();
QWebElementCollection paras = body.findAll("p");
QCOMPARE(paras.count(), 2);
QList<QWebElement> list = paras.toList();
QList<QWebElement> list = body.findAll("p");
QCOMPARE(list.count(), 2);
QCOMPARE(list.at(0).toPlainText(), QString("first para"));
QCOMPARE(list.at(1).toPlainText(), QString("second para"));
......@@ -265,7 +259,7 @@ void tst_QWebElement::namespaceURI()
QWebElement body = m_mainFrame->documentElement();
QCOMPARE(body.namespaceUri(), QLatin1String("http://www.w3.org/1999/xhtml"));
QWebElement svg = body.findAll("*#foobar").toList().at(0);
QWebElement svg = body.findAll("*#foobar").at(0);
QCOMPARE(svg.prefix(), QLatin1String("svg"));
QCOMPARE(svg.localName(), QLatin1String("svg"));
QCOMPARE(svg.tagName(), QLatin1String("svg:svg"));
......@@ -273,41 +267,6 @@ void tst_QWebElement::namespaceURI()
}
void tst_QWebElement::iteration()
{
QString html = "<body><p>first para</p><p>second para</p></body>";
m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement();
QWebElementCollection paras = body.findAll("p");
QList<QWebElement> referenceList = paras.toList();
QList<QWebElement> foreachList;
foreach(QWebElement p, paras) {
foreachList.append(p);
}
QVERIFY(foreachList.count() == 2);
QCOMPARE(foreachList.count(), referenceList.count());
QCOMPARE(foreachList.at(0), referenceList.at(0));
QCOMPARE(foreachList.at(1), referenceList.at(1));
QList<QWebElement> forLoopList;
for (int i = 0; i < paras.count(); ++i) {
forLoopList.append(paras.at(i));
}
QVERIFY(foreachList.count() == 2);
QCOMPARE(foreachList.count(), referenceList.count());
QCOMPARE(foreachList.at(0), referenceList.at(0));
QCOMPARE(foreachList.at(1), referenceList.at(1));
for (int i = 0; i < paras.count(); ++i) {
QCOMPARE(paras.at(i), paras[i]);
}
QCOMPARE(paras.at(0), paras.first());
QCOMPARE(paras.at(1), paras.last());
}
void tst_QWebElement::foreachManipulation()
{
QString html = "<body><p>first para</p><p>second para</p></body>";
......@@ -395,12 +354,6 @@ void tst_QWebElement::frame()
QVERIFY(secondPara.webFrame() == secondFrame);
}
void tst_QWebElement::emptyCollection()
{
QWebElementCollection emptyCollection;
QCOMPARE(emptyCollection.count(), 0);
}
void tst_QWebElement::style()
{
QString html = "<body><p style=\"color: blue;\">some text</p></body>";
......@@ -435,37 +388,6 @@ void tst_QWebElement::computedStyle()
QCOMPARE(p.styleProperty("color"), QLatin1String("red"));
}
void tst_QWebElement::appendCollection()
{
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>";
m_mainFrame->setHtml(html);
QWebElement body = m_mainFrame->documentElement();
QWebElementCollection collection = body.findAll("p");
QCOMPARE(collection.count(), 2);
collection.append(body.findAll("div"));
QCOMPARE(collection.count(), 4);
collection += body.findAll("span.a");
QCOMPARE(collection.count(), 5);
QWebElementCollection all = collection + body.findAll("span.b");
QCOMPARE(all.count(), 6);
QCOMPARE(collection.count(), 5);
all += collection;
QCOMPARE(all.count(), 11);
QCOMPARE(collection.count(), 5);
QWebElementCollection test;
test.append(collection);
QCOMPARE(test.count(), 5);
test.append(QWebElementCollection());
QCOMPARE(test.count(), 5);
}
void tst_QWebElement::properties()
{
m_mainFrame->setHtml("<body><form><input type=checkbox id=ourcheckbox checked=true>");
......@@ -699,7 +621,7 @@ void tst_QWebElement::nullSelect()
{
m_mainFrame->setHtml("<body><p>Test");
QWebElementCollection collection = m_mainFrame->findAllElements("invalid{syn(tax;;%#$f223e>>");
QList<QWebElement> collection = m_mainFrame->findAllElements("invalid{syn(tax;;%#$f223e>>");
QVERIFY(collection.count() == 0);
}
......
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