зеркало из https://github.com/mozilla/pjs.git
Bug 402089, nsDOMUIEvent should cache coordinates when DuplicatePrivateData is called, r+sr=jst, a=mtschrep
This commit is contained in:
Родитель
3513594bc8
Коммит
df3ce1145c
|
@ -55,7 +55,7 @@ nsDOMUIEvent::nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent)
|
|||
: nsDOMEvent(aPresContext, aEvent ?
|
||||
static_cast<nsEvent *>(aEvent) :
|
||||
static_cast<nsEvent *>(new nsUIEvent(PR_FALSE, 0, 0)))
|
||||
, mClientPoint(0,0)
|
||||
, mClientPoint(0, 0), mLayerPoint(0, 0), mPagePoint(0, 0)
|
||||
{
|
||||
if (aEvent) {
|
||||
mEventIsInternal = PR_FALSE;
|
||||
|
@ -148,12 +148,10 @@ nsPoint nsDOMUIEvent::GetClientPoint() {
|
|||
mEvent->eventStructType != NS_POPUP_EVENT &&
|
||||
mEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
||||
!NS_IS_DRAG_EVENT(mEvent)) ||
|
||||
!mPresContext) {
|
||||
return nsPoint(0, 0);
|
||||
}
|
||||
|
||||
if (!((nsGUIEvent*)mEvent)->widget)
|
||||
!mPresContext ||
|
||||
!((nsGUIEvent*)mEvent)->widget) {
|
||||
return mClientPoint;
|
||||
}
|
||||
|
||||
nsPoint pt(0, 0);
|
||||
nsIFrame* rootFrame = mPresContext->PresShell()->GetRootFrame();
|
||||
|
@ -209,7 +207,7 @@ nsDOMUIEvent::GetPagePoint()
|
|||
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
||||
}
|
||||
|
||||
return GetClientPoint();
|
||||
return mPagePoint;
|
||||
}
|
||||
|
||||
|
||||
|
@ -307,14 +305,15 @@ nsPoint nsDOMUIEvent::GetLayerPoint() {
|
|||
if (!mEvent ||
|
||||
(mEvent->eventStructType != NS_MOUSE_EVENT &&
|
||||
mEvent->eventStructType != NS_MOUSE_SCROLL_EVENT) ||
|
||||
!mPresContext) {
|
||||
return nsPoint(0,0);
|
||||
!mPresContext ||
|
||||
mEventIsInternal) {
|
||||
return mLayerPoint;
|
||||
}
|
||||
// XXX I'm not really sure this is correct; it's my best shot, though
|
||||
nsIFrame* targetFrame;
|
||||
mPresContext->EventStateManager()->GetEventTarget(&targetFrame);
|
||||
if (!targetFrame)
|
||||
return nsPoint(0,0);
|
||||
return mLayerPoint;
|
||||
nsIFrame* layer = nsLayoutUtils::GetClosestLayer(targetFrame);
|
||||
nsPoint pt(nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, layer));
|
||||
pt.x = nsPresContext::AppUnitsToIntCSSPixels(pt.x);
|
||||
|
@ -401,6 +400,21 @@ nsDOMUIEvent::GetQueryCaretRectReply(nsQueryCaretRectEventReply** aReply)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsDOMUIEvent::DuplicatePrivateData()
|
||||
{
|
||||
mClientPoint = GetClientPoint();
|
||||
mLayerPoint = GetLayerPoint();
|
||||
mPagePoint = GetPagePoint();
|
||||
// GetScreenPoint converts mEvent->refPoint to right coordinates.
|
||||
nsPoint screenPoint = GetScreenPoint();
|
||||
nsresult rv = nsDOMEvent::DuplicatePrivateData();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mEvent->refPoint = screenPoint;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
|
||||
nsPresContext* aPresContext,
|
||||
nsGUIEvent *aEvent)
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
|
||||
// nsIDOMNSUIEvent Interface
|
||||
NS_DECL_NSIDOMNSUIEVENT
|
||||
|
||||
// nsIPrivateDOMEvent interface
|
||||
NS_IMETHOD DuplicatePrivateData();
|
||||
|
||||
// nsIPrivateCompositionEvent interface
|
||||
NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply);
|
||||
|
@ -82,6 +85,9 @@ protected:
|
|||
nsCOMPtr<nsIDOMAbstractView> mView;
|
||||
PRInt32 mDetail;
|
||||
nsPoint mClientPoint;
|
||||
// Screenpoint is mEvent->refPoint.
|
||||
nsPoint mLayerPoint;
|
||||
nsPoint mPagePoint;
|
||||
};
|
||||
|
||||
#define NS_FORWARD_TO_NSDOMUIEVENT \
|
||||
|
|
|
@ -53,6 +53,7 @@ _TEST_FILES = \
|
|||
test_bug367781.html \
|
||||
test_bug379120.html \
|
||||
test_bug391568.xhtml \
|
||||
test_bug402089.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=402089
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 402089</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402089">Mozilla Bug 402089</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
<pre id="result1"></pre>
|
||||
<pre id="result2"></pre>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 402089 **/
|
||||
|
||||
var cachedEvent = null;
|
||||
|
||||
function testCachedEvent() {
|
||||
testEvent('result2');
|
||||
ok((document.getElementById('result1').textContent ==
|
||||
document.getElementById('result2').textContent),
|
||||
"Event coordinates should be the same after dispatching.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function testEvent(res) {
|
||||
var s = cachedEvent.type + "\n";
|
||||
s += "clientX: " + cachedEvent.clientX + ", clientY: " + cachedEvent.clientY + "\n";
|
||||
s += "screenX: " + cachedEvent.screenX + ", screenY: " + cachedEvent.screenY + "\n";
|
||||
s += "layerX: " + cachedEvent.layerX + ", layerY: " + cachedEvent.layerY + "\n";
|
||||
s += "pageX: " + cachedEvent.pageX + ", pageY: " + cachedEvent.pageY + "\n";
|
||||
document.getElementById(res).textContent += s;
|
||||
}
|
||||
|
||||
function clickHandler(e) {
|
||||
cachedEvent = e;
|
||||
testEvent('result1');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
window.removeEventListener("click", clickHandler, true);
|
||||
setTimeout(testCachedEvent, 10);
|
||||
}
|
||||
|
||||
function doTest() {
|
||||
window.addEventListener("click", clickHandler, true);
|
||||
document.body.boxObject = document.getBoxObjectFor(document.body);
|
||||
synthesizeMouse(document.body, 1, 1, { });
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(doTest);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Загрузка…
Ссылка в новой задаче