зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1427419 - Part 17: Move inIDOMUtils.isIgnorableWhitespace to InspectorUtils. r=bz
This is still being used by the old DOM Inspector in comm-central. MozReview-Commit-ID: B8fJzjUUewj
This commit is contained in:
Родитель
0c66b23322
Коммит
5a4d54c425
|
@ -51,6 +51,8 @@ namespace InspectorUtils {
|
|||
const unsigned long TYPE_IMAGE_RECT = 9;
|
||||
const unsigned long TYPE_NUMBER = 10;
|
||||
[Throws] boolean cssPropertySupportsType(DOMString property, unsigned long type);
|
||||
|
||||
boolean isIgnorableWhitespace(CharacterData dataNode);
|
||||
};
|
||||
|
||||
dictionary PropertyNamesOptions {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
||||
class nsAtom;
|
||||
class nsGenericDOMDataNode;
|
||||
class nsIDocument;
|
||||
class nsStyleContext;
|
||||
|
||||
|
@ -159,6 +160,13 @@ public:
|
|||
uint32_t aType,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static bool IsIgnorableWhitespace(GlobalObject& aGlobalObject,
|
||||
nsGenericDOMDataNode& aDataNode)
|
||||
{
|
||||
return IsIgnorableWhitespace(aDataNode);
|
||||
}
|
||||
static bool IsIgnorableWhitespace(nsGenericDOMDataNode& aDataNode);
|
||||
|
||||
private:
|
||||
static already_AddRefed<nsStyleContext>
|
||||
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "nsArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsGenericDOMDataNode.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIStyleSheetLinkingElement.h"
|
||||
|
@ -118,41 +119,26 @@ InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
|
||||
bool *aReturn)
|
||||
bool
|
||||
InspectorUtils::IsIgnorableWhitespace(nsGenericDOMDataNode& aDataNode)
|
||||
{
|
||||
NS_PRECONDITION(aReturn, "Must have an out parameter");
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aDataNode);
|
||||
|
||||
*aReturn = false;
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aDataNode);
|
||||
NS_ASSERTION(content, "Does not implement nsIContent!");
|
||||
|
||||
if (!content->TextIsOnlyWhitespace()) {
|
||||
return NS_OK;
|
||||
if (!aDataNode.TextIsOnlyWhitespace()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Okay. We have only white space. Let's check the white-space
|
||||
// property now and make sure that this isn't preformatted text...
|
||||
nsIFrame* frame = content->GetPrimaryFrame();
|
||||
if (frame) {
|
||||
const nsStyleText* text = frame->StyleText();
|
||||
*aReturn = !text->WhiteSpaceIsSignificant();
|
||||
}
|
||||
else {
|
||||
// empty inter-tag text node without frame, e.g., in between <table>\n<tr>
|
||||
*aReturn = true;
|
||||
if (nsIFrame* frame = aDataNode.GetPrimaryFrame()) {
|
||||
return !frame->StyleText()->WhiteSpaceIsSignificant();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
// empty inter-tag text node without frame, e.g., in between <table>\n<tr>
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
|
||||
bool aShowingAnonymousContent,
|
||||
|
|
|
@ -1228,11 +1228,6 @@ inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids,
|
|||
nsCOMPtr<nsIDOMNode> kid;
|
||||
uint16_t nodeType = 0;
|
||||
|
||||
// Try and get DOM Utils in case we don't have one yet.
|
||||
if (!mShowWhitespaceNodes && !mDOMUtils) {
|
||||
mDOMUtils = services::GetInDOMUtils();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < l; ++i) {
|
||||
aKids->Item(i, getter_AddRefs(kid));
|
||||
kid->GetNodeType(&nodeType);
|
||||
|
@ -1250,12 +1245,11 @@ inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids,
|
|||
if (mWhatToShow & filterForNodeType) {
|
||||
if ((nodeType == nsIDOMNode::TEXT_NODE ||
|
||||
nodeType == nsIDOMNode::COMMENT_NODE) &&
|
||||
!mShowWhitespaceNodes && mDOMUtils) {
|
||||
nsCOMPtr<nsIDOMCharacterData> data = do_QueryInterface(kid);
|
||||
!mShowWhitespaceNodes) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(kid);
|
||||
auto data = static_cast<nsGenericDOMDataNode*>(content.get());
|
||||
NS_ASSERTION(data, "Does not implement nsIDOMCharacterData!");
|
||||
bool ignore;
|
||||
mDOMUtils->IsIgnorableWhitespace(data, &ignore);
|
||||
if (ignore) {
|
||||
if (InspectorUtils::IsIgnorableWhitespace(*data)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ interface nsIDOMCSSStyleSheet;
|
|||
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
|
||||
interface inIDOMUtils : nsISupports
|
||||
{
|
||||
// DOM Node utilities
|
||||
boolean isIgnorableWhitespace(in nsIDOMCharacterData aDataNode);
|
||||
// Returns the "parent" of a node. The parent of a document node is the
|
||||
// frame/iframe containing that document. aShowingAnonymousContent says
|
||||
// whether we are showing anonymous content.
|
||||
|
|
|
@ -43,12 +43,11 @@ function do_test() {
|
|||
}
|
||||
|
||||
try {
|
||||
utils.isIgnorableWhitespace(null);
|
||||
InspectorUtils.isIgnorableWhitespace(null);
|
||||
ok(false, "expected an exception");
|
||||
}
|
||||
catch(e) {
|
||||
e = SpecialPowers.wrap(e);
|
||||
is(e.result, INVALID_POINTER, "got the expected exception");
|
||||
is(e.name, "TypeError", "got the expected exception");
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -49,7 +49,7 @@ function do_test() {
|
|||
catch(e) { ok(false, "got an unexpected exception:" + e); }
|
||||
|
||||
try {
|
||||
var res = utils.isIgnorableWhitespace(text);
|
||||
var res = InspectorUtils.isIgnorableWhitespace(text);
|
||||
is(res, false, "isIgnorableWhitespace");
|
||||
}
|
||||
catch(e) { ok(false, "got an unexpected exception:" + e); }
|
||||
|
|
Загрузка…
Ссылка в новой задаче