From 6a294f8f19763c7fa9e80fcbe9b2e7d7b521e780 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 31 Aug 2009 10:02:31 +1000 Subject: Element-at functionality Not used yet. --- src/declarative/fx/qfxwebview.cpp | 20 ++++++++++++++++++++ src/declarative/fx/qfxwebview.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index b150ca0..cd60a76 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -1190,6 +1190,26 @@ void QFxWebView::setNewWindowParent(QFxItem *parent) d->newWindowParent = parent; } +/*! + Returns the area of the largest element at position (\a x,\a y) that is no larger + than \a maxwidth by \a maxheight pixels. + + May return an area larger in the case when no smaller element is at the position. +*/ +QRect QFxWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const +{ + QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QWebElement element = hit.enclosingBlockElement(); + QWebElement parent = element.parent(); + if (maxwidth<=0) maxwidth = INT_MAX; + if (maxheight<=0) maxheight = INT_MAX; + while (!parent.isNull() && parent.geometry().width() <= maxwidth && parent.geometry().height() <= maxheight) { + element = parent; + parent = element.parent(); + } + return element.geometry(); +} + /*! diff --git a/src/declarative/fx/qfxwebview.h b/src/declarative/fx/qfxwebview.h index f084d61..29284a4 100644 --- a/src/declarative/fx/qfxwebview.h +++ b/src/declarative/fx/qfxwebview.h @@ -222,6 +222,7 @@ protected: virtual void focusChanged(bool); virtual bool sceneEvent(QEvent *event); QFxWebView *createWindow(QWebPage::WebWindowType type); + QRect elementAreaAt(int x, int y, int minwidth, int minheight) const; private: void init(); -- cgit v0.12