Changed webbrowser to use cef touch events

rather than injected mouse events.
This commit is contained in:
Mikael Pettersson
2020-02-13 09:58:56 +01:00
committed by Mikael Pettersson
parent 4753d562f1
commit c9b5ffd021
4 changed files with 35 additions and 43 deletions
+1 -4
View File
@@ -84,10 +84,7 @@ public:
void draw();
void close(bool force = false);
void sendTouchPressEvent(const CefMouseEvent & event,
CefBrowserHost::MouseButtonType button, const int clickCount);
void sendResleasePressEvent(const CefMouseEvent & event,
CefBrowserHost::MouseButtonType button, const int clickCount);
void sendTouchEvent(const CefTouchEvent& event) const;
bool sendKeyEvent(const CefKeyEvent& event);
bool sendMouseClickEvent(const CefMouseEvent& event,
@@ -84,6 +84,8 @@ private:
*/
CefMouseEvent mouseEvent(KeyModifier mods = KeyModifier::NoModifier);
CefTouchEvent touchEvent(const TouchInput& input,
const cef_touch_event_type_t eventType) const;
/**
* Find the CEF key event to use for a given action.
*
+2 -12
View File
@@ -149,18 +149,8 @@ bool BrowserInstance::sendMouseClickEvent(const CefMouseEvent& event,
return hasContent(event.x, event.y);
}
void BrowserInstance::sendTouchPressEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType button,
const int clickCount)
{
_browser->GetHost()->SendMouseClickEvent(event, button, false, clickCount);
}
void BrowserInstance::sendResleasePressEvent(const CefMouseEvent& event,
CefBrowserHost::MouseButtonType button,
const int clickCount)
{
_browser->GetHost()->SendMouseClickEvent(event, button, true, clickCount);
void BrowserInstance::sendTouchEvent(const CefTouchEvent& event) const{
_browser->GetHost()->SendTouchEvent(event);
}
bool BrowserInstance::sendMouseMoveEvent(const CefMouseEvent& event) {
+30 -27
View File
@@ -208,15 +208,11 @@ void EventHandler::initialize() {
}
if (_validTouchStates.empty()) {
_mousePosition.x = windowPos.x;
_mousePosition.y = windowPos.y;
_leftButton.down = true;
_browserInstance->sendMouseClickEvent(
mouseEvent(),
MBT_LEFT,
false,
BrowserInstance::SingleClick
CefTouchEvent event = touchEvent(
input,
cef_touch_event_type_t::CEF_TET_PRESSED
);
_browserInstance->sendTouchEvent(event);
_validTouchStates.emplace_back(input);
}
else {
@@ -245,11 +241,11 @@ void EventHandler::initialize() {
);
if (it == _validTouchStates.cbegin()) {
glm::vec2 windowPos = input.currentWindowCoordinates();
_mousePosition.x = windowPos.x;
_mousePosition.y = windowPos.y;
_leftButton.down = true;
_browserInstance->sendMouseMoveEvent(mouseEvent());
CefTouchEvent event = touchEvent(
input,
cef_touch_event_type_t::CEF_TET_MOVED
);
_browserInstance->sendTouchEvent(event);
return true;
}
else if (it != _validTouchStates.cend()){
@@ -280,20 +276,12 @@ void EventHandler::initialize() {
if (found == _validTouchStates.cend()) {
return;
}
CefTouchEvent event = touchEvent(
input,
cef_touch_event_type_t::CEF_TET_RELEASED
);
_browserInstance->sendTouchEvent(event);
_validTouchStates.erase(found);
if (_validTouchStates.empty()) {
glm::vec2 windowPos = input.currentWindowCoordinates();
_mousePosition.x = windowPos.x;
_mousePosition.y = windowPos.y;
_leftButton.down = false;
_browserInstance->sendMouseClickEvent(
mouseEvent(),
MBT_LEFT,
true,
BrowserInstance::SingleClick
);
}
}
);
}
@@ -337,7 +325,7 @@ bool EventHandler::mouseButtonCallback(MouseButton button, MouseAction action,
bool EventHandler::isDoubleClick(const MouseButtonState& button) const {
// check time
using namespace std::chrono;
auto now = high_resolution_clock::now();
milliseconds maxTimeDifference(doubleClickTime());
auto requiredTime = button.lastClickTime + maxTimeDifference;
@@ -438,6 +426,21 @@ CefMouseEvent EventHandler::mouseEvent(KeyModifier mods) {
return event;
}
CefTouchEvent EventHandler::touchEvent(const TouchInput& input,
const cef_touch_event_type_t eventType) const
{
const glm::vec2 windowPos = input.currentWindowCoordinates();
CefTouchEvent event = {};
event.id = static_cast<int>(input.fingerId);
event.x = windowPos.x;
event.y = windowPos.y;
event.type = eventType;
//TODO: We should probably use key mods for touch as well:
// event.modifiers = mods;
event.pointer_type = cef_pointer_type_t::CEF_POINTER_TYPE_TOUCH;
return event;
}
void EventHandler::setBrowserInstance(BrowserInstance* browserInstance) {
LDEBUG("Setting browser instance.");
_browserInstance = browserInstance;