зеркало из https://github.com/mozilla/pjs.git
Bug 163137. Make DOM inspector scroll to put an element in view upon selecting it in the DOM tree view. This was previously only working for HTML elements.
r=rbs, sr=bzbarsky
This commit is contained in:
Родитель
3dc37760d5
Коммит
c13e41b4f6
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Joe Hewitt <hewitt@netscape.com> (original author)
|
* Joe Hewitt <hewitt@netscape.com> (original author)
|
||||||
|
* Christopher A. Aillon <christopher@aillon.com>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
@ -47,5 +48,6 @@ interface inIFlasher : nsISupports
|
||||||
{
|
{
|
||||||
void drawElementOutline(in nsIDOMElement aElement, in wstring aColor, in long aThickness, in boolean aInvert);
|
void drawElementOutline(in nsIDOMElement aElement, in wstring aColor, in long aThickness, in boolean aInvert);
|
||||||
void repaintElement(in nsIDOMElement aElement);
|
void repaintElement(in nsIDOMElement aElement);
|
||||||
|
void scrollElementIntoView(in nsIDOMElement aElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Joe Hewitt <hewitt@netscape.com> (original author)
|
* Joe Hewitt <hewitt@netscape.com> (original author)
|
||||||
|
* Christopher A. Aillon <christopher@aillon.com>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
@ -43,6 +44,8 @@
|
||||||
#include "nsIViewManager.h"
|
#include "nsIViewManager.h"
|
||||||
#include "nsIDeviceContext.h"
|
#include "nsIDeviceContext.h"
|
||||||
#include "nsIWidget.h"
|
#include "nsIWidget.h"
|
||||||
|
#include "nsIPresShell.h"
|
||||||
|
#include "nsIFrame.h"
|
||||||
|
|
||||||
static NS_DEFINE_CID(kInspectorCSSUtilsCID, NS_INSPECTORCSSUTILS_CID);
|
static NS_DEFINE_CID(kInspectorCSSUtilsCID, NS_INSPECTORCSSUTILS_CID);
|
||||||
|
|
||||||
|
@ -134,12 +137,37 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement, const PRUnichar* aColor,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
|
||||||
|
{
|
||||||
|
NS_PRECONDITION(aElement, "Dude, where's my arg?!");
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
|
||||||
|
if (!window) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
|
||||||
|
NS_ASSERTION(presShell, "Dude, where's my pres shell?!");
|
||||||
|
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
|
||||||
|
if (!frame) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
presShell->ScrollFrameIntoView(frame,
|
||||||
|
NS_PRESSHELL_SCROLL_ANYWHERE /* VPercent */,
|
||||||
|
NS_PRESSHELL_SCROLL_ANYWHERE /* HPercent */);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// inFlasher
|
// inFlasher
|
||||||
|
|
||||||
NS_IMETHODIMP
|
nsresult
|
||||||
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
|
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||||
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext)
|
nscolor aColor, PRUint32 aThickness, float aP2T,
|
||||||
|
nsIRenderingContext* aRenderContext)
|
||||||
{
|
{
|
||||||
aRenderContext->SetColor(aColor);
|
aRenderContext->SetColor(aColor);
|
||||||
DrawLine(aX, aY, aWidth, aThickness, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
|
DrawLine(aX, aY, aWidth, aThickness, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
|
||||||
|
@ -150,9 +178,10 @@ inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
nsresult
|
||||||
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
|
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
|
||||||
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext)
|
PRUint32 aThickness, PRBool aDir, PRBool aBounds,
|
||||||
|
float aP2T, nsIRenderingContext* aRenderContext)
|
||||||
{
|
{
|
||||||
nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T);
|
nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T);
|
||||||
if (aDir) { // horizontal
|
if (aDir) { // horizontal
|
||||||
|
|
|
@ -43,10 +43,10 @@
|
||||||
|
|
||||||
#include "nsIInspectorCSSUtils.h"
|
#include "nsIInspectorCSSUtils.h"
|
||||||
#include "nsIDOMElement.h"
|
#include "nsIDOMElement.h"
|
||||||
#include "nsIPresShell.h"
|
|
||||||
#include "nsIFrame.h"
|
|
||||||
#include "nsIRenderingContext.h"
|
#include "nsIRenderingContext.h"
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
#define BOUND_INNER 0
|
#define BOUND_INNER 0
|
||||||
#define BOUND_OUTER 1
|
#define BOUND_OUTER 1
|
||||||
|
|
||||||
|
@ -63,13 +63,12 @@ public:
|
||||||
virtual ~inFlasher();
|
virtual ~inFlasher();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell);
|
nsresult DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||||
nsIPresShell* GetPresShellFor(nsISupports* aThing);
|
nscolor aColor, PRUint32 aThickness, float aP2T,
|
||||||
|
nsIRenderingContext* aRenderContext);
|
||||||
NS_IMETHOD DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
|
nsresult DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
|
||||||
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext);
|
PRBool aDir, PRBool aBounds, float aP2T,
|
||||||
NS_IMETHOD DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
|
nsIRenderingContext* aRenderContext);
|
||||||
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
|
nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,7 @@ var gFlasherRegistry = [];
|
||||||
|
|
||||||
function Flasher(aColor, aThickness, aDuration, aSpeed, aInvert)
|
function Flasher(aColor, aThickness, aDuration, aSpeed, aInvert)
|
||||||
{
|
{
|
||||||
this.mShell = XPCU.createInstance("@mozilla.org/inspector/flasher;1", "inIFlasher");;
|
this.mShell = XPCU.createInstance("@mozilla.org/inspector/flasher;1", "inIFlasher");
|
||||||
this.color = aColor;
|
this.color = aColor;
|
||||||
this.mThickness = aThickness;
|
this.mThickness = aThickness;
|
||||||
this.duration = aDuration;
|
this.duration = aDuration;
|
||||||
|
@ -91,9 +91,7 @@ Flasher.prototype =
|
||||||
{
|
{
|
||||||
if (val && val.nodeType == Node.ELEMENT_NODE) {
|
if (val && val.nodeType == Node.ELEMENT_NODE) {
|
||||||
this.mElement = val;
|
this.mElement = val;
|
||||||
if ("scrollIntoView" in val) {
|
this.mShell.scrollElementIntoView(val);
|
||||||
val.scrollIntoView(false);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
throw "Invalid node type.";
|
throw "Invalid node type.";
|
||||||
},
|
},
|
||||||
|
|
Загрузка…
Ссылка в новой задаче