зеркало из https://github.com/mozilla/gecko-dev.git
Bug 734861 - Expose stylesheets, including UA, for a document via inIDOMUtils. r=bz
This patch adds an API to inspector utils that gets all stylesheets associated with a document, including UA sheets.
This commit is contained in:
Родитель
e6cd070d3d
Коммит
fd8eb7c308
|
@ -16,10 +16,13 @@ interface nsIDOMFontFaceList;
|
|||
interface nsIDOMRange;
|
||||
interface nsIDOMCSSStyleSheet;
|
||||
|
||||
[scriptable, uuid(8705a686-d081-476c-89fa-cb6b70e9bb2e)]
|
||||
[scriptable, uuid(ceae6c68-f5d4-4597-a3d9-ca5646c25f1a)]
|
||||
interface inIDOMUtils : nsISupports
|
||||
{
|
||||
// CSS utilities
|
||||
void getAllStyleSheets (in nsIDOMDocument aDoc,
|
||||
[optional] out unsigned long aLength,
|
||||
[array, size_is (aLength), retval] out nsISupports aSheets);
|
||||
nsISupportsArray getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo);
|
||||
unsigned long getRuleLine(in nsIDOMCSSStyleRule aRule);
|
||||
unsigned long getRuleColumn(in nsIDOMCSSStyleRule aRule);
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "mozilla/dom/InspectorUtilsBinding.h"
|
||||
#include "nsCSSProps.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsStyleSet.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::css;
|
||||
|
@ -56,6 +57,49 @@ NS_IMPL_ISUPPORTS1(inDOMUtils, inIDOMUtils)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inIDOMUtils
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength,
|
||||
nsISupports ***aSheets)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocument);
|
||||
|
||||
nsCOMArray<nsISupports> sheets;
|
||||
|
||||
nsCOMPtr<nsIDocument> document = do_QueryInterface(aDocument);
|
||||
MOZ_ASSERT(document);
|
||||
|
||||
// Get the agent, then user sheets in the style set.
|
||||
nsIPresShell* presShell = document->GetShell();
|
||||
if (presShell) {
|
||||
nsStyleSet* styleSet = presShell->StyleSet();
|
||||
nsStyleSet::sheetType sheetType = nsStyleSet::eAgentSheet;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
}
|
||||
sheetType = nsStyleSet::eUserSheet;
|
||||
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
||||
sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
||||
}
|
||||
}
|
||||
|
||||
// Get the document sheets.
|
||||
for (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
|
||||
sheets.AppendElement(document->GetStyleSheetAt(i));
|
||||
}
|
||||
|
||||
nsISupports** ret = static_cast<nsISupports**>(NS_Alloc(sheets.Count() *
|
||||
sizeof(nsISupports*)));
|
||||
|
||||
for (int32_t i = 0; i < sheets.Count(); i++) {
|
||||
NS_ADDREF(ret[i] = sheets[i]);
|
||||
}
|
||||
|
||||
*aLength = sheets.Count();
|
||||
*aSheets = ret;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
|
||||
bool *aReturn)
|
||||
|
|
|
@ -24,6 +24,7 @@ MOCHITEST_FILES =\
|
|||
bug856317.css \
|
||||
test_isinheritableproperty.html \
|
||||
test_bug877690.html \
|
||||
test_get_all_style_sheets.html \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=734861
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 734861</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 734861 **/
|
||||
|
||||
function runTest() {
|
||||
var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
|
||||
.getService(SpecialPowers.Ci.inIDOMUtils);
|
||||
var res = utils.getAllStyleSheets(document);
|
||||
|
||||
var foundUA = false;
|
||||
for (var i = 0; i < res.length; i++) {
|
||||
if (res[i].href === "resource://gre-resources/ua.css") {
|
||||
foundUA = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ok(foundUA, "UA sheet should be returned with all the other sheets.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="runTest();">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=734861">Mozilla Bug 734861</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче