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:
caillon%returnzero.com 2002-11-16 05:42:29 +00:00
Родитель 3dc37760d5
Коммит c13e41b4f6
4 изменённых файлов: 47 добавлений и 19 удалений

Просмотреть файл

@ -20,6 +20,7 @@
*
* Contributor(s):
* 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
@ -47,5 +48,6 @@ interface inIFlasher : nsISupports
{
void drawElementOutline(in nsIDOMElement aElement, in wstring aColor, in long aThickness, in boolean aInvert);
void repaintElement(in nsIDOMElement aElement);
void scrollElementIntoView(in nsIDOMElement aElement);
};

Просмотреть файл

@ -20,6 +20,7 @@
*
* Contributor(s):
* 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
@ -43,6 +44,8 @@
#include "nsIViewManager.h"
#include "nsIDeviceContext.h"
#include "nsIWidget.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
static NS_DEFINE_CID(kInspectorCSSUtilsCID, NS_INSPECTORCSSUTILS_CID);
@ -134,12 +137,37 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement, const PRUnichar* aColor,
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
NS_IMETHODIMP
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext)
nsresult
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nscolor aColor, PRUint32 aThickness, float aP2T,
nsIRenderingContext* aRenderContext)
{
aRenderContext->SetColor(aColor);
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;
}
NS_IMETHODIMP
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext)
nsresult
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
PRUint32 aThickness, PRBool aDir, PRBool aBounds,
float aP2T, nsIRenderingContext* aRenderContext)
{
nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T);
if (aDir) { // horizontal

Просмотреть файл

@ -43,10 +43,10 @@
#include "nsIInspectorCSSUtils.h"
#include "nsIDOMElement.h"
#include "nsIPresShell.h"
#include "nsIFrame.h"
#include "nsIRenderingContext.h"
#include "nsCOMPtr.h"
#define BOUND_INNER 0
#define BOUND_OUTER 1
@ -63,13 +63,12 @@ public:
virtual ~inFlasher();
protected:
nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell);
nsIPresShell* GetPresShellFor(nsISupports* aThing);
NS_IMETHOD DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext);
NS_IMETHOD DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext);
nsresult DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nscolor aColor, PRUint32 aThickness, float aP2T,
nsIRenderingContext* aRenderContext);
nsresult DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
PRBool aDir, PRBool aBounds, float aP2T,
nsIRenderingContext* aRenderContext);
nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
};

Просмотреть файл

@ -55,7 +55,7 @@ var gFlasherRegistry = [];
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.mThickness = aThickness;
this.duration = aDuration;
@ -91,9 +91,7 @@ Flasher.prototype =
{
if (val && val.nodeType == Node.ELEMENT_NODE) {
this.mElement = val;
if ("scrollIntoView" in val) {
val.scrollIntoView(false);
}
this.mShell.scrollElementIntoView(val);
} else
throw "Invalid node type.";
},