Permalink
Browse files

Watch for cursor change events and notify the

LLEmbeddedBrowserWindowObserver of the changes so they can change the
cursor adding a new onCursorChanged function to
LLEmbeddedBrowserWindowObserver and an enum e_cursor to LLMozLib
Issue: MOZ-20
  • Loading branch information...
Benjamin C Meyer
Benjamin C Meyer committed Mar 25, 2009
1 parent 8db2857 commit 867b47f7940075ca1684b334d468c2232587a6d7
@@ -69,7 +69,8 @@ LLEmbeddedBrowserWindow::LLEmbeddedBrowserWindow()
d = new LLEmbeddedBrowserWindowPrivate();
d->mPage->window = this;
- d->mView = new QWebView;
+ d->mView = new WebView;
+ d->mView->window = this;
d->mView->setPage(d->mPage);
d->mGraphicsScene = new GraphicsScene;
d->mGraphicsScene->window = this;
@@ -296,8 +297,8 @@ bool LLEmbeddedBrowserWindow::userAction(LLMozLib::EUserAction action)
qDebug() << "LLEmbeddedBrowserWindow" << __FUNCTION__ << action;
#endif
bool result = true;
-
- switch(action)
+
+ switch(action)
{
case LLMozLib::UA_EDIT_CUT:
d->mPage->triggerAction(QWebPage::Cut);
@@ -336,7 +337,7 @@ bool LLEmbeddedBrowserWindow::userActionIsEnabled(LLMozLib::EUserAction action)
bool result;
- switch(action)
+ switch(action)
{
case LLMozLib::UA_EDIT_CUT:
result = d->mPage->action(QWebPage::Cut)->isEnabled();
@@ -604,3 +605,47 @@ void GraphicsScene::repaintRequestedSlot(const QList<QRectF> &regions)
}
}
+#include <qcursor.h>
+WebView::WebView(QWidget *parent)
+ : QWebView(parent)
+ , window(0)
+{
+}
+
+bool WebView::event(QEvent *event)
+{
+ if (event->type() == QEvent::CursorChange
+ && window
+ && currentShape != cursor().shape()) {
+ currentShape = cursor().shape();
+ LLMozLib::ECursor llcursor;
+ switch(currentShape)
+ {
+ case Qt::ArrowCursor:
+ llcursor = LLMozLib::C_ARROW;
+ break;
+ case Qt::PointingHandCursor:
+ llcursor = LLMozLib::C_POINTINGHAND;
+ break;
+ case Qt::IBeamCursor:
+ llcursor = LLMozLib::C_IBEAM;
+ break;
+ case Qt::SplitVCursor:
+ llcursor = LLMozLib::C_SPLITV;
+ break;
+ case Qt::SplitHCursor:
+ llcursor = LLMozLib::C_SPLITH;
+ break;
+ default:
+ qWarning() << "Unhandled cursor shape:" << currentShape;
+ }
+
+ LLEmbeddedBrowserWindowEvent event(
+ window->getWindowId(),
+ window->getCurrentUri(),
+ ((int)llcursor));
+ window->d->mEventEmitter.update(&LLEmbeddedBrowserWindowObserver::onCursorChanged, event);
+ }
+ return QWebView::event(event);
+}
+
@@ -128,6 +128,7 @@ class LLEmbeddedBrowserWindow
private:
friend class LLWebPage;
friend class GraphicsScene;
+ friend class WebView;
LLEmbeddedBrowserWindowPrivate *d;
};
@@ -119,6 +119,20 @@ private slots:
};
+class WebView : public QWebView
+{
+ Q_OBJECT
+
+public:
+ WebView(QWidget *parent = 0);
+ LLEmbeddedBrowserWindow *window;
+
+protected:
+ bool event(QEvent *event);
+
+ Qt::CursorShape currentShape;
+};
+
class LLEmbeddedBrowserWindowPrivate
{
@@ -155,7 +169,7 @@ class LLEmbeddedBrowserWindowPrivate
LLWebPage *mPage;
QImage mImage;
- QWebView *mView;
+ WebView *mView;
GraphicsScene *mGraphicsScene;
QGraphicsView *mGraphicsView;
Qt::MouseButton mCurrentMouseDown;
View
@@ -621,6 +621,10 @@ LLEmbeddedBrowserWindowObserver::~LLEmbeddedBrowserWindowObserver()
{
}
+void LLEmbeddedBrowserWindowObserver::onCursorChanged(const EventType&)
+{
+}
+
void LLEmbeddedBrowserWindowObserver::onPageChanged(const EventType&)
{
}
View
@@ -161,6 +161,7 @@ class LLEmbeddedBrowserWindowObserver
virtual ~LLEmbeddedBrowserWindowObserver();
typedef LLEmbeddedBrowserWindowEvent EventType;
+ virtual void onCursorChanged(const EventType& event);
virtual void onPageChanged(const EventType& event);
virtual void onNavigateBegin(const EventType& event);
virtual void onNavigateComplete(const EventType& event);
@@ -183,7 +184,16 @@ class LLEmbeddedBrowserWindowObserver
class LLMozLib
{
public:
- typedef enum e_user_action
+ typedef enum e_cursor
+ {
+ C_ARROW,
+ C_IBEAM,
+ C_SPLITV,
+ C_SPLITH,
+ C_POINTINGHAND
+ } ECursor;
+
+ typedef enum e_user_action
{
UA_EDIT_CUT,
UA_EDIT_COPY,

0 comments on commit 867b47f

Please sign in to comment.