To send mouse input to a View, you should first create a MouseEvent
and then pass it to the function View::FireMouseEvent
.
You should send a Mouse Move event whenever the mouse changes position.
Here is an example of moving the mouse to (100, 100) coordinate with no buttons pressed:
MouseEvent evt;
evt.type = MouseEvent::kType_MouseMoved;
evt.x = 100;
evt.y = 100;
evt.button = MouseEvent::kButton_None;
view->FireMouseEvent(evt);
You should send a mouse down event whenever a mouse button is pressed.
Here is an example of pressing the left mouse-button at the (200, 200) coordinate:
MouseEvent evt;
evt.type = MouseEvent::kType_MouseDown;
evt.x = 200;
evt.y = 200;
evt.button = MouseEvent::kButton_Left;
view->FireMouseEvent(evt);
You should send a mouse down event whenever a mouse button is released.
Here is an example of releasing the left mouse-button at the (200, 200) coordinate:
MouseEvent evt;
evt.type = MouseEvent::kType_MouseUp;
evt.x = 200;
evt.y = 200;
evt.button = MouseEvent::kButton_Left;
view->FireMouseEvent(evt);
The View may sometimes change the displayed mouse cursor in response to user interactions (for example, the "hand" cursor should be displayed when a user hovers over a link).
To receive notification of cursor events, you should inherit from the ViewListener
class and handle the ViewListener::OnChangeCursor
callback:
class MyViewListener : public ViewListener {
public:
MyViewListener() {}
virtual ~MyViewListener() {}
// Inherited from ViewListener.
// The View will call this when the mouse cursor changes.
virtual void OnChangeCursor(ultralight::View* caller, Cursor cursor)
{
// Handle the event here.
}
};
You can bind MyViewListener
to a View
by calling View::set_view_listener
:
MyViewListener* listener = new MyViewListener();
view->set_view_listener(listener);