Bug 1093686 - Add some debug logging code for PositionedEventTargeting.cpp. r=roc

This commit is contained in:
Kartikaya Gupta 2014-11-06 08:05:51 -05:00
parent 660348c385
commit 91f9a6243c
3 changed files with 54 additions and 0 deletions

View File

@ -67,6 +67,26 @@ AppendToString(std::stringstream& aStream, const gfxRGBA& c,
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsPoint& p,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString("(x=%d, y=%d)", p.x, p.y).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsRect& r,
const char* pfx, const char* sfx)
{
aStream << pfx;
aStream << nsPrintfCString(
"(x=%d, y=%d, w=%d, h=%d)",
r.x, r.y, r.width, r.height).get();
aStream << sfx;
}
void
AppendToString(std::stringstream& aStream, const nsIntPoint& p,
const char* pfx, const char* sfx)

View File

@ -45,6 +45,14 @@ void
AppendToString(std::stringstream& aStream, const gfxRGBA& c,
const char* pfx="", const char* sfx="");
void
AppendToString(std::stringstream& aStream, const nsPoint& p,
const char* pfx="", const char* sfx="");
void
AppendToString(std::stringstream& aStream, const nsRect& r,
const char* pfx="", const char* sfx="");
void
AppendToString(std::stringstream& aStream, const nsIntPoint& p,
const char* pfx="", const char* sfx="");

View File

@ -16,6 +16,12 @@
#include "nsDeviceContext.h"
#include "nsIFrame.h"
#include <algorithm>
#include "LayersLogging.h"
// If debugging this code you may wish to enable this logging, and also
// uncomment the DumpFrameTree call near the bottom of the file.
#define PET_LOG(...)
// #define PET_LOG(...) printf_stderr("PET: " __VA_ARGS__);
namespace mozilla {
@ -318,6 +324,7 @@ GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame,
nsRegion exposedRegion(aTargetRect);
for (uint32_t i = 0; i < aCandidates.Length(); ++i) {
nsIFrame* f = aCandidates[i];
PET_LOG("Checking candidate %p\n", f);
bool preservesAxisAlignedRectangles = false;
nsRect borderBox = nsLayoutUtils::TransformFrameRectToAncestor(f,
@ -326,6 +333,7 @@ GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame,
region.And(exposedRegion, borderBox);
if (region.IsEmpty()) {
PET_LOG(" candidate %p had empty hit region\n", f);
continue;
}
@ -336,14 +344,17 @@ GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame,
}
if (!IsElementClickable(f, nsGkAtoms::body)) {
PET_LOG(" candidate %p was not clickable\n", f);
continue;
}
// If our current closest frame is a descendant of 'f', skip 'f' (prefer
// the nested frame).
if (bestTarget && nsLayoutUtils::IsProperAncestorFrameCrossDoc(f, bestTarget, aRoot)) {
PET_LOG(" candidate %p was ancestor for bestTarget %p\n", f, bestTarget);
continue;
}
if (!nsLayoutUtils::IsAncestorFrameCrossDoc(aRestrictToDescendants, f, aRoot)) {
PET_LOG(" candidate %p was not descendant of restrictroot %p\n", f, aRestrictToDescendants);
continue;
}
@ -356,6 +367,7 @@ GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame,
distance *= aPrefs->mVisitedWeight / 100.0f;
}
if (distance < bestDistance) {
PET_LOG(" candidate %p is the new best\n", f);
bestDistance = distance;
bestTarget = f;
}
@ -373,9 +385,14 @@ FindFrameTargetedByInputEvent(WidgetGUIEvent* aEvent,
nsLayoutUtils::IGNORE_ROOT_SCROLL_FRAME : 0;
nsIFrame* target =
nsLayoutUtils::GetFrameForPoint(aRootFrame, aPointRelativeToRootFrame, flags);
PET_LOG("Found initial target %p for event class %s point %s relative to root frame %p\n",
target, (aEvent->mClass == eMouseEventClass ? "mouse" :
(aEvent->mClass == eTouchEventClass ? "touch" : "other")),
mozilla::layers::Stringify(aPointRelativeToRootFrame).c_str(), aRootFrame);
const EventRadiusPrefs* prefs = GetPrefsFor(aEvent->mClass);
if (!prefs || !prefs->mEnabled || (target && IsElementClickable(target, nsGkAtoms::body))) {
PET_LOG("Retargeting disabled or target %p is clickable\n", target);
return target;
}
@ -385,6 +402,7 @@ FindFrameTargetedByInputEvent(WidgetGUIEvent* aEvent,
prefs->mTouchOnly &&
aEvent->AsMouseEvent()->inputSource !=
nsIDOMMouseEvent::MOZ_SOURCE_TOUCH) {
PET_LOG("Mouse input event is not from a touch source\n");
return target;
}
@ -398,6 +416,8 @@ FindFrameTargetedByInputEvent(WidgetGUIEvent* aEvent,
nsRect targetRect = GetTargetRect(aRootFrame, aPointRelativeToRootFrame,
restrictToDescendants, prefs, aFlags);
PET_LOG("Expanded point to target rect %s\n",
mozilla::layers::Stringify(targetRect).c_str());
nsAutoTArray<nsIFrame*,8> candidates;
nsresult rv = nsLayoutUtils::GetFramesForArea(aRootFrame, targetRect, candidates, flags);
if (NS_FAILED(rv)) {
@ -410,6 +430,12 @@ FindFrameTargetedByInputEvent(WidgetGUIEvent* aEvent,
if (closestClickable) {
target = closestClickable;
}
PET_LOG("Final target is %p\n", target);
// Uncomment this to dump the frame tree to help with debugging.
// Note that dumping the frame tree at the top of the function may flood
// logcat on Android devices and cause the PET_LOGs to get dropped.
// aRootFrame->DumpFrameTree();
if (!target || !prefs->mRepositionEventCoords) {
// No repositioning required for this event