mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 826025 - Part 1: Use "switch" instead of "else if" series in BrowserEventHandler.handleUserEvent(). r=cpeterson
This commit is contained in:
parent
02ef044da3
commit
80f48cde90
@ -3924,77 +3924,102 @@ var BrowserEventHandler = {
|
||||
},
|
||||
|
||||
handleUserEvent: function(aTopic, aData) {
|
||||
if (aTopic == "Gesture:Scroll") {
|
||||
// If we've lost our scrollable element, return. Don't cancel the
|
||||
// override, as we probably don't want Java to handle panning until the
|
||||
// user releases their finger.
|
||||
if (this._scrollableElement == null)
|
||||
return;
|
||||
switch (aTopic) {
|
||||
|
||||
// If this is the first scroll event and we can't scroll in the direction
|
||||
// the user wanted, and neither can any non-root sub-frame, cancel the
|
||||
// override so that Java can handle panning the main document.
|
||||
let data = JSON.parse(aData);
|
||||
|
||||
// round the scroll amounts because they come in as floats and might be
|
||||
// subject to minor rounding errors because of zoom values. I've seen values
|
||||
// like 0.99 come in here and get truncated to 0; this avoids that problem.
|
||||
let zoom = BrowserApp.selectedTab._zoom;
|
||||
data.x = Math.round(data.x / zoom);
|
||||
data.y = Math.round(data.y / zoom);
|
||||
|
||||
if (this._firstScrollEvent) {
|
||||
while (this._scrollableElement != null && !this._elementCanScroll(this._scrollableElement, data.x, data.y))
|
||||
this._scrollableElement = this._findScrollableElement(this._scrollableElement, false);
|
||||
|
||||
let doc = BrowserApp.selectedBrowser.contentDocument;
|
||||
if (this._scrollableElement == null || this._scrollableElement == doc.body || this._scrollableElement == doc.documentElement) {
|
||||
sendMessageToJava({ gecko: { type: "Panning:CancelOverride" } });
|
||||
case "Gesture:Scroll": {
|
||||
// If we've lost our scrollable element, return. Don't cancel the
|
||||
// override, as we probably don't want Java to handle panning until the
|
||||
// user releases their finger.
|
||||
if (this._scrollableElement == null)
|
||||
return;
|
||||
}
|
||||
|
||||
this._firstScrollEvent = false;
|
||||
}
|
||||
// If this is the first scroll event and we can't scroll in the direction
|
||||
// the user wanted, and neither can any non-root sub-frame, cancel the
|
||||
// override so that Java can handle panning the main document.
|
||||
let data = JSON.parse(aData);
|
||||
|
||||
// Scroll the scrollable element
|
||||
if (this._elementCanScroll(this._scrollableElement, data.x, data.y)) {
|
||||
this._scrollElementBy(this._scrollableElement, data.x, data.y);
|
||||
sendMessageToJava({ gecko: { type: "Gesture:ScrollAck", scrolled: true } });
|
||||
SelectionHandler.subdocumentScrolled(this._scrollableElement);
|
||||
} else {
|
||||
sendMessageToJava({ gecko: { type: "Gesture:ScrollAck", scrolled: false } });
|
||||
}
|
||||
} else if (aTopic == "Gesture:CancelTouch") {
|
||||
this._cancelTapHighlight();
|
||||
} else if (aTopic == "Gesture:SingleTap") {
|
||||
let element = this._highlightElement;
|
||||
if (element) {
|
||||
try {
|
||||
let data = JSON.parse(aData);
|
||||
if (ElementTouchHelper.isElementClickable(element)) {
|
||||
[data.x, data.y] = this._moveClickPoint(element, data.x, data.y);
|
||||
element = ElementTouchHelper.anyElementFromPoint(data.x, data.y);
|
||||
// round the scroll amounts because they come in as floats and might be
|
||||
// subject to minor rounding errors because of zoom values. I've seen values
|
||||
// like 0.99 come in here and get truncated to 0; this avoids that problem.
|
||||
let zoom = BrowserApp.selectedTab._zoom;
|
||||
data.x = Math.round(data.x / zoom);
|
||||
data.y = Math.round(data.y / zoom);
|
||||
|
||||
if (this._firstScrollEvent) {
|
||||
while (this._scrollableElement != null &&
|
||||
!this._elementCanScroll(this._scrollableElement, data.x, data.y))
|
||||
this._scrollableElement = this._findScrollableElement(this._scrollableElement, false);
|
||||
|
||||
let doc = BrowserApp.selectedBrowser.contentDocument;
|
||||
if (this._scrollableElement == null ||
|
||||
this._scrollableElement == doc.body ||
|
||||
this._scrollableElement == doc.documentElement) {
|
||||
sendMessageToJava({ gecko: { type: "Panning:CancelOverride" } });
|
||||
return;
|
||||
}
|
||||
|
||||
this._sendMouseEvent("mousemove", element, data.x, data.y);
|
||||
this._sendMouseEvent("mousedown", element, data.x, data.y);
|
||||
this._sendMouseEvent("mouseup", element, data.x, data.y);
|
||||
|
||||
// See if its a input element
|
||||
if ((element instanceof HTMLInputElement && element.mozIsTextField(false)) || (element instanceof HTMLTextAreaElement))
|
||||
SelectionHandler.showThumb(element);
|
||||
} catch(e) {
|
||||
Cu.reportError(e);
|
||||
this._firstScrollEvent = false;
|
||||
}
|
||||
|
||||
// Scroll the scrollable element
|
||||
if (this._elementCanScroll(this._scrollableElement, data.x, data.y)) {
|
||||
this._scrollElementBy(this._scrollableElement, data.x, data.y);
|
||||
sendMessageToJava({ gecko: { type: "Gesture:ScrollAck", scrolled: true } });
|
||||
SelectionHandler.subdocumentScrolled(this._scrollableElement);
|
||||
} else {
|
||||
sendMessageToJava({ gecko: { type: "Gesture:ScrollAck", scrolled: false } });
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
this._cancelTapHighlight();
|
||||
} else if (aTopic == "Gesture:DoubleTap") {
|
||||
this._cancelTapHighlight();
|
||||
this.onDoubleTap(aData);
|
||||
} else if (aTopic == "MozMagnifyGestureStart" || aTopic == "MozMagnifyGestureUpdate") {
|
||||
this.onPinch(aData);
|
||||
} else if (aTopic == "MozMagnifyGesture") {
|
||||
this.onPinchFinish(aData, this._mLastPinchPoint.x, this._mLastPinchPoint.y);
|
||||
|
||||
case "Gesture:CancelTouch":
|
||||
this._cancelTapHighlight();
|
||||
break;
|
||||
|
||||
case "Gesture:SingleTap": {
|
||||
let element = this._highlightElement;
|
||||
if (element) {
|
||||
try {
|
||||
let data = JSON.parse(aData);
|
||||
if (ElementTouchHelper.isElementClickable(element)) {
|
||||
[data.x, data.y] = this._moveClickPoint(element, data.x, data.y);
|
||||
element = ElementTouchHelper.anyElementFromPoint(data.x, data.y);
|
||||
}
|
||||
|
||||
this._sendMouseEvent("mousemove", element, data.x, data.y);
|
||||
this._sendMouseEvent("mousedown", element, data.x, data.y);
|
||||
this._sendMouseEvent("mouseup", element, data.x, data.y);
|
||||
|
||||
// See if its a input element
|
||||
if ((element instanceof HTMLInputElement && element.mozIsTextField(false)) ||
|
||||
(element instanceof HTMLTextAreaElement))
|
||||
SelectionHandler.showThumb(element);
|
||||
} catch(e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
}
|
||||
this._cancelTapHighlight();
|
||||
break;
|
||||
}
|
||||
|
||||
case"Gesture:DoubleTap":
|
||||
this._cancelTapHighlight();
|
||||
this.onDoubleTap(aData);
|
||||
break;
|
||||
|
||||
case "MozMagnifyGestureStart":
|
||||
case "MozMagnifyGestureUpdate":
|
||||
this.onPinch(aData);
|
||||
break;
|
||||
|
||||
case "MozMagnifyGesture":
|
||||
this.onPinchFinish(aData, this._mLastPinchPoint.x, this._mLastPinchPoint.y);
|
||||
break;
|
||||
|
||||
default:
|
||||
dump('BrowserEventHandler.handleUserEvent: unexpected topic "' + aTopic + '"');
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user