Bug 1015754 - Cleanup mouse events in the QT widget. r=romaxa

This commit is contained in:
Tom Schuster 2014-05-26 18:25:40 +02:00
Родитель f78d29b988
Коммит 367a375f64
2 изменённых файлов: 61 добавлений и 76 удалений

Просмотреть файл

@ -909,6 +909,47 @@ nsWindow::mouseMoveEvent(QMouseEvent* aEvent)
return nsEventStatus_eIgnore;
}
static void
InitMouseEvent(WidgetMouseEvent& aMouseEvent, QMouseEvent* aEvent,
int aClickCount)
{
aMouseEvent.refPoint.x = nscoord(aEvent->pos().x());
aMouseEvent.refPoint.y = nscoord(aEvent->pos().y());
aMouseEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
aEvent->modifiers() & Qt::AltModifier,
aEvent->modifiers() & Qt::ShiftModifier,
aEvent->modifiers() & Qt::MetaModifier);
aMouseEvent.clickCount = aClickCount;
switch (aEvent->button()) {
case Qt::LeftButton:
aMouseEvent.button = WidgetMouseEvent::eLeftButton;
break;
case Qt::RightButton:
aMouseEvent.button = WidgetMouseEvent::eRightButton;
break;
case Qt::MiddleButton:
aMouseEvent.button = WidgetMouseEvent::eMiddleButton;
break;
default:
break;
}
}
static bool
IsAcceptedButton(Qt::MouseButton button)
{
switch (button) {
case Qt::LeftButton:
case Qt::RightButton:
case Qt::MiddleButton:
return true;
default:
return false;
}
}
nsEventStatus
nsWindow::mousePressEvent(QMouseEvent* aEvent)
{
@ -922,37 +963,28 @@ nsWindow::mousePressEvent(QMouseEvent* aEvent)
if (mWidget)
pos = mWidget->mapToGlobal(pos);
if (CheckForRollup( pos.x(), pos.y(), false))
if (CheckForRollup(pos.x(), pos.y(), false))
return nsEventStatus_eIgnore;
uint16_t domButton;
switch (aEvent->button()) {
case Qt::MidButton:
domButton = WidgetMouseEvent::eMiddleButton;
break;
case Qt::RightButton:
domButton = WidgetMouseEvent::eRightButton;
break;
default:
domButton = WidgetMouseEvent::eLeftButton;
break;
if (!IsAcceptedButton(aEvent->button())) {
if (aEvent->button() == Qt::BackButton)
return DispatchCommandEvent(nsGkAtoms::Back);
if (aEvent->button() == Qt::ForwardButton)
return DispatchCommandEvent(nsGkAtoms::Forward);
return nsEventStatus_eIgnore;
}
WidgetMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this,
WidgetMouseEvent::eReal);
event.button = domButton;
InitButtonEvent(event, aEvent, 1);
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
InitMouseEvent(event, aEvent, 1);
nsEventStatus status = DispatchEvent(&event);
// right menu click on linux should also pop up a context menu
if (domButton == WidgetMouseEvent::eRightButton &&
// Right click on linux should also pop up a context menu.
if (event.button == WidgetMouseEvent::eRightButton &&
MOZ_LIKELY(!mIsDestroyed)) {
WidgetMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
WidgetMouseEvent::eReal);
InitButtonEvent(contextMenuEvent, aEvent, 1);
InitMouseEvent(contextMenuEvent, aEvent, 1);
DispatchEvent(&contextMenuEvent, status);
}
@ -965,55 +997,27 @@ nsWindow::mouseReleaseEvent(QMouseEvent* aEvent)
// The user has done something.
UserActivity();
uint16_t domButton;
switch (aEvent->button()) {
case Qt::MidButton:
domButton = WidgetMouseEvent::eMiddleButton;
break;
case Qt::RightButton:
domButton = WidgetMouseEvent::eRightButton;
break;
default:
domButton = WidgetMouseEvent::eLeftButton;
break;
}
LOG(("%s [%p] button: %d\n", __PRETTY_FUNCTION__, (void*)this, domButton));
if (!IsAcceptedButton(aEvent->button()))
return nsEventStatus_eIgnore;
WidgetMouseEvent event(true, NS_MOUSE_BUTTON_UP, this,
WidgetMouseEvent::eReal);
event.button = domButton;
InitButtonEvent(event, aEvent, 1);
nsEventStatus status = DispatchEvent(&event);
return status;
InitMouseEvent(event, aEvent, 1);
return DispatchEvent(&event);
}
nsEventStatus
nsWindow::mouseDoubleClickEvent(QMouseEvent* aEvent)
{
uint32_t eventType;
// The user has done something.
UserActivity();
switch (aEvent->button()) {
case Qt::MidButton:
eventType = WidgetMouseEvent::eMiddleButton;
break;
case Qt::RightButton:
eventType = WidgetMouseEvent::eRightButton;
break;
default:
eventType = WidgetMouseEvent::eLeftButton;
break;
}
if (!IsAcceptedButton(aEvent->button()))
return nsEventStatus_eIgnore;
WidgetMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this,
WidgetMouseEvent::eReal);
event.button = eventType;
InitButtonEvent(event, aEvent, 2);
//pressed
InitMouseEvent(event, aEvent, 2);
return DispatchEvent(&event);
}
@ -1554,21 +1558,6 @@ nsWindow::tabletEvent(QTabletEvent* aEvent)
// Helpers
void
nsWindow::InitButtonEvent(WidgetMouseEvent& aMoveEvent,
QMouseEvent* aEvent,
int aClickCount)
{
aMoveEvent.refPoint.x = nscoord(aEvent->pos().x());
aMoveEvent.refPoint.y = nscoord(aEvent->pos().y());
aMoveEvent.InitBasicModifiers(aEvent->modifiers() & Qt::ControlModifier,
aEvent->modifiers() & Qt::AltModifier,
aEvent->modifiers() & Qt::ShiftModifier,
aEvent->modifiers() & Qt::MetaModifier);
aMoveEvent.clickCount = aClickCount;
}
nsEventStatus
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent)
{

Просмотреть файл

@ -177,10 +177,6 @@ protected:
MozQWidget* mWidget;
private:
void InitButtonEvent(mozilla::WidgetMouseEvent& event,
QMouseEvent* aEvent,
int aClickCount = 1);
// event handling code
nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
void DispatchActivateEvent(void);