Bug 773741 - Support touch events in resizers. r=enn

This commit is contained in:
Wes Johnston 2012-07-27 15:01:12 -07:00
parent cbca4b70ef
commit 4bc78c38b2
7 changed files with 61 additions and 52 deletions

View File

@ -33,6 +33,7 @@
#include "nsBoxLayoutState.h" #include "nsBoxLayoutState.h"
#include "nsBoxFrame.h" #include "nsBoxFrame.h"
#include "nsDOMTouchEvent.h"
#include "nsStyleContext.h" #include "nsStyleContext.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -2173,3 +2174,35 @@ nsBoxFrame::WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
nsXULEventRedirectorWrapper wrapper(this); nsXULEventRedirectorWrapper wrapper(this);
return wrapper.WrapLists(aBuilder, this, aIn, aOut); return wrapper.WrapLists(aBuilder, this, aIn, aOut);
} }
bool
nsBoxFrame::GetEventPoint(nsGUIEvent* aEvent, nsPoint &aPoint) {
nsIntPoint refPoint;
bool res = GetEventPoint(aEvent, refPoint);
aPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, refPoint, this);
return res;
}
bool
nsBoxFrame::GetEventPoint(nsGUIEvent* aEvent, nsIntPoint &aPoint) {
NS_ENSURE_TRUE(aEvent, false);
if (aEvent->eventStructType == NS_TOUCH_EVENT) {
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
// return false if there is more than one touch on the page, or if
// we can't find a touch point
if (touchEvent->touches.Length() != 1) {
return false;
}
nsIDOMTouch *touch = touchEvent->touches.SafeElementAt(0);
if (!touch) {
return false;
}
nsDOMTouch* domtouch = static_cast<nsDOMTouch*>(touch);
aPoint = domtouch->mRefPoint;
} else {
aPoint = aEvent->refPoint;
}
return true;
}

View File

@ -210,6 +210,13 @@ protected:
nsCOMPtr<nsBoxLayout> mLayoutManager; nsCOMPtr<nsBoxLayout> mLayoutManager;
// Get the point associated with this event. Returns true if a single valid
// point was found. Otherwise false.
bool GetEventPoint(nsGUIEvent *aEvent, nsPoint &aPoint);
// Gets the event coordinates relative to the widget offset associated with
// this frame. Return true if a single valid point was found.
bool GetEventPoint(nsGUIEvent *aEvent, nsIntPoint &aPoint);
protected: protected:
nsresult RegUnregAccessKey(bool aDoReg); nsresult RegUnregAccessKey(bool aDoReg);

View File

@ -62,9 +62,11 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
bool doDefault = true; bool doDefault = true;
switch (aEvent->message) { switch (aEvent->message) {
case NS_TOUCH_START:
case NS_MOUSE_BUTTON_DOWN: { case NS_MOUSE_BUTTON_DOWN: {
if (aEvent->eventStructType == NS_MOUSE_EVENT && if (aEvent->eventStructType == NS_TOUCH_EVENT ||
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) (aEvent->eventStructType == NS_MOUSE_EVENT &&
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton))
{ {
nsCOMPtr<nsIBaseWindow> window; nsCOMPtr<nsIBaseWindow> window;
nsIPresShell* presShell = aPresContext->GetPresShell(); nsIPresShell* presShell = aPresContext->GetPresShell();
@ -112,21 +114,26 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
&mMouseDownRect.width, &mMouseDownRect.height); &mMouseDownRect.width, &mMouseDownRect.height);
} }
// remember current mouse coordinates
nsIntPoint refPoint;
if (!GetEventPoint(aEvent, refPoint))
return NS_OK;
mMouseDownPoint = refPoint + aEvent->widget->WidgetToScreenOffset();
// we're tracking // we're tracking
mTrackingMouseMove = true; mTrackingMouseMove = true;
// remember current mouse coordinates
mMouseDownPoint = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED); nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
} }
} }
break; break;
case NS_TOUCH_END:
case NS_MOUSE_BUTTON_UP: { case NS_MOUSE_BUTTON_UP: {
if (mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT && if (aEvent->eventStructType == NS_TOUCH_EVENT ||
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) (aEvent->eventStructType == NS_MOUSE_EVENT &&
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton))
{ {
// we're done tracking. // we're done tracking.
mTrackingMouseMove = false; mTrackingMouseMove = false;
@ -138,6 +145,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
} }
break; break;
case NS_TOUCH_MOVE:
case NS_MOUSE_MOVE: { case NS_MOUSE_MOVE: {
if (mTrackingMouseMove) if (mTrackingMouseMove)
{ {
@ -160,7 +168,10 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
// retrieve the offset of the mousemove event relative to the mousedown. // retrieve the offset of the mousemove event relative to the mousedown.
// The difference is how much the resize needs to be // The difference is how much the resize needs to be
nsIntPoint screenPoint(aEvent->refPoint + aEvent->widget->WidgetToScreenOffset()); nsIntPoint refPoint;
if (!GetEventPoint(aEvent, refPoint))
return NS_OK;
nsIntPoint screenPoint(refPoint + aEvent->widget->WidgetToScreenOffset());
nsIntPoint mouseMove(screenPoint - mMouseDownPoint); nsIntPoint mouseMove(screenPoint - mMouseDownPoint);
// Determine which direction to resize by checking the dir attribute. // Determine which direction to resize by checking the dir attribute.

View File

@ -47,6 +47,7 @@ protected:
const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo); const SizeInfo& aSizeInfo, SizeInfo* aOriginalSizeInfo);
static void MaybePersistOriginalSize(nsIContent* aContent, const SizeInfo& aSizeInfo); static void MaybePersistOriginalSize(nsIContent* aContent, const SizeInfo& aSizeInfo);
static void RestoreOriginalSize(nsIContent* aContent); static void RestoreOriginalSize(nsIContent* aContent);
protected: protected:
nsIntRect mMouseDownRect; nsIntRect mMouseDownRect;
nsIntPoint mMouseDownPoint; nsIntPoint mMouseDownPoint;

View File

@ -574,40 +574,6 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext,
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
} }
bool
nsSliderFrame::GetEventPoint(nsGUIEvent* aEvent, nsPoint &aPoint) {
nsIntPoint refPoint;
nsresult rv;
if (aEvent->eventStructType == NS_TOUCH_EVENT) {
rv = GetTouchPoint(static_cast<nsTouchEvent*>(aEvent), refPoint);
if (NS_FAILED(rv))
return false;
} else {
refPoint = aEvent->refPoint;
}
aPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, refPoint, this);
return true;
}
bool
nsSliderFrame::GetTouchPoint(nsTouchEvent* aEvent, nsIntPoint &aPoint)
{
NS_ENSURE_TRUE(aEvent, false);
// return false if there is more than one touch on the page, or if
// we can't find a touch point
if (aEvent->touches.Length() != 1) {
return false;
}
nsIDOMTouch *touch = aEvent->touches.SafeElementAt(0);
if (!touch) {
return false;
}
nsDOMTouch* domtouch = static_cast<nsDOMTouch*>(touch);
aPoint = domtouch->mRefPoint;
return true;
}
// Helper function to collect the "scroll to click" metric. Beware of // Helper function to collect the "scroll to click" metric. Beware of
// caching this, users expect to be able to change the system preference // caching this, users expect to be able to change the system preference
// and see the browser change its behavior immediately. // and see the browser change its behavior immediately.

View File

@ -139,15 +139,6 @@ private:
nsresult CurrentPositionChanged(nsPresContext* aPresContext, nsresult CurrentPositionChanged(nsPresContext* aPresContext,
bool aImmediateRedraw); bool aImmediateRedraw);
// Get the point associated with this event. Returns true if a valid point
// was found. Otherwise false.
bool GetEventPoint(nsGUIEvent *aEvent, nsPoint &aPoint);
// Get the point associated with this touch event. Returns true if a valid point
// was found. False if there is more than one touch present on the page, or
// if a point could not be found for the given touch.
bool GetTouchPoint(nsTouchEvent *aEvent, nsIntPoint &aPoint);
void DragThumb(bool aGrabMouseEvents); void DragThumb(bool aGrabMouseEvents);
void AddListener(); void AddListener();
void RemoveListener(); void RemoveListener();

View File

@ -22,7 +22,7 @@ MOCHITEST_CHROME_FILES = test_bug381167.xhtml \
$(NULL) $(NULL)
ifneq (mobile,$(MOZ_BUILD_APP)) ifneq (mobile,$(MOZ_BUILD_APP))
MOCHITEST_FILES = test_resizer_incontent.xul MOCHITEST_FILES = test_resizer_incontent.xul \
MOCHITEST_CHROME_FILES += test_resizer.xul \ MOCHITEST_CHROME_FILES += test_resizer.xul \
window_resizer.xul \ window_resizer.xul \