Add nsIDOMWindowUtils::getVisitedDependentComputedStyle for use in tests. (Bug 147777) r=bzbarsky

This commit is contained in:
L. David Baron 2010-04-02 18:58:25 -07:00
Родитель 4cf0bf0c58
Коммит 5d680f5d9b
4 изменённых файлов: 66 добавлений и 2 удалений

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

@ -66,6 +66,7 @@
#include "gfxContext.h"
#include "gfxImageSurface.h"
#include "nsLayoutUtils.h"
#include "nsComputedDOMStyle.h"
#if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
#include <gdk/gdk.h>
@ -1224,3 +1225,26 @@ nsDOMWindowUtils::GetClassName(char **aName)
*aName = NS_strdup(JS_GET_CLASS(cx, JSVAL_TO_OBJECT(argv[0]))->name);
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsDOMWindowUtils::GetVisitedDependentComputedStyle(
nsIDOMElement *aElement, const nsAString& aPseudoElement,
const nsAString& aPropertyName, nsAString& aResult)
{
aResult.Truncate();
if (!IsUniversalXPConnectCapable()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
nsresult rv =
mWindow->GetComputedStyle(aElement, aPseudoElement, getter_AddRefs(decl));
NS_ENSURE_SUCCESS(rv, rv);
static_cast<nsComputedDOMStyle*>(decl.get())->SetExposeVisitedStyle(PR_TRUE);
rv = decl->GetPropertyValue(aPropertyName, aResult);
static_cast<nsComputedDOMStyle*>(decl.get())->SetExposeVisitedStyle(PR_FALSE);
return rv;
}

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

@ -52,7 +52,7 @@ interface nsIDOMEvent;
interface nsITransferable;
interface nsIQueryContentEventResult;
[scriptable, uuid(00ca8d4f-61f1-4d9c-a7c1-82651b0cf02b)]
[scriptable, uuid(1e9d7efa-997d-42c0-acdf-f5f1cc8eb539)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -613,4 +613,22 @@ interface nsIDOMWindowUtils : nsISupports {
boolean sendSelectionSetEvent(in unsigned long aOffset,
in unsigned long aLength,
in boolean aReverse);
/**
* Perform the equivalent of:
* window.getComputedStyle(aElement, aPseudoElement).
* getPropertyValue(aPropertyName)
* except that, when the link whose presence in history is allowed to
* influence aElement's style is visited, get the value the property
* would have if allowed all properties to change as a result of
* :visited selectors (except for cases where getComputedStyle uses
* data from the frame).
*
* This is easier to implement than adding our property restrictions
* to this API, and is sufficient for the present testing
* requirements (which are essentially testing 'color').
*/
AString getVisitedDependentComputedStyle(in nsIDOMElement aElement,
in AString aPseudoElement,
in AString aPropertyName);
};

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

@ -132,7 +132,8 @@ GetContainingBlockFor(nsIFrame* aFrame) {
nsComputedDOMStyle::nsComputedDOMStyle()
: mDocumentWeak(nsnull), mOuterFrame(nsnull),
mInnerFrame(nsnull), mPresShell(nsnull), mAppUnitsPerInch(0)
mInnerFrame(nsnull), mPresShell(nsnull), mAppUnitsPerInch(0),
mExposeVisitedStyle(PR_FALSE)
{
}
@ -500,6 +501,19 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
"should not have pseudo-element data");
}
// mExposeVisitedStyle is set to true only by testing APIs that
// require UniversalXPConnect.
NS_ABORT_IF_FALSE(!mExposeVisitedStyle ||
nsContentUtils::IsCallerTrustedForCapability(
"UniversalXPConnect"),
"mExposeVisitedStyle set incorrectly");
if (mExposeVisitedStyle && mStyleContextHolder->RelevantLinkVisited()) {
nsStyleContext *styleIfVisited = mStyleContextHolder->GetStyleIfVisited();
if (styleIfVisited) {
mStyleContextHolder = styleIfVisited;
}
}
// Call our pointer-to-member-function.
nsresult rv = (this->*(propEntry->mGetter))(aReturn);

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

@ -92,6 +92,12 @@ public:
static nsIPresShell*
GetPresShellForContent(nsIContent* aContent);
// Helper for nsDOMWindowUtils::GetVisitedDependentComputedStyle
void SetExposeVisitedStyle(PRBool aExpose) {
NS_ASSERTION(aExpose != mExposeVisitedStyle, "should always be changing");
mExposeVisitedStyle = aExpose;
}
private:
void AssertFlushedPendingReflows() {
NS_ASSERTION(mFlushedPendingReflows,
@ -472,6 +478,8 @@ private:
PRInt32 mAppUnitsPerInch; /* For unit conversions */
PRPackedBool mExposeVisitedStyle;
#ifdef DEBUG
PRBool mFlushedPendingReflows;
#endif