Bug 1427419 - Part 22: Move inIDOMUtils.getUsedFontFaces to InspectorUtils. r=bz

This also changes the function to return a sequence (JS Array) instead of
an nsFontFaceList object, and converts nsFontFace/nsIDOMFontFace into a
Web IDL implemented object too.

MozReview-Commit-ID: 1iAW3DYe5kO

--HG--
rename : layout/inspector/nsFontFace.cpp => layout/inspector/InspectorFontFace.cpp
This commit is contained in:
Cameron McCormack 2018-01-11 12:38:01 +08:00
Родитель 25abd91980
Коммит c4663ea0f0
24 изменённых файлов: 260 добавлений и 366 удалений

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

@ -1770,7 +1770,6 @@ DebuggerServer.ObjectActorPreviewers.Object = [
rawObj instanceof Ci.nsIDOMCSSRuleList ||
rawObj instanceof Ci.nsIDOMCSSValueList ||
rawObj instanceof Ci.nsIDOMFileList ||
rawObj instanceof Ci.nsIDOMFontFaceList ||
rawObj instanceof Ci.nsIDOMMediaList ||
rawObj instanceof Ci.nsIDOMNodeList ||
rawObj instanceof Ci.nsIDOMStyleSheetList)) {

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

@ -272,11 +272,11 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
// We don't get fonts for a node, but for a range
let rng = contentDocument.createRange();
rng.selectNodeContents(actualNode);
let fonts = DOMUtils.getUsedFontFaces(rng);
let fonts = InspectorUtils.getUsedFontFaces(rng);
let fontsArray = [];
for (let i = 0; i < fonts.length; i++) {
let font = fonts.item(i);
let font = fonts[i];
let fontFace = {
name: font.name,
CSSFamilyName: font.CSSFamilyName,

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

@ -25,7 +25,6 @@
#include "nsContentUtils.h"
#include "nsGenericDOMDataNode.h"
#include "nsTextFrame.h"
#include "nsFontFaceList.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/DocumentType.h"
#include "mozilla/dom/RangeBinding.h"
@ -39,6 +38,7 @@
#include "nsStyleStruct.h"
#include "nsStyleStructInlines.h"
#include "nsComputedDOMStyle.h"
#include "mozilla/dom/InspectorFontFace.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -3467,11 +3467,9 @@ nsRange::GetClientRectsAndTexts(
mStart.Container(), mStart.Offset(), mEnd.Container(), mEnd.Offset(), true, true);
}
NS_IMETHODIMP
nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
nsresult
nsRange::GetUsedFontFaces(nsTArray<nsAutoPtr<InspectorFontFace>>& aResult)
{
*aResult = nullptr;
NS_ENSURE_TRUE(mStart.Container(), NS_ERROR_UNEXPECTED);
nsCOMPtr<nsINode> startContainer = do_QueryInterface(mStart.Container());
@ -3485,7 +3483,11 @@ nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
// Recheck whether we're still in the document
NS_ENSURE_TRUE(mStart.Container()->IsInUncomposedDoc(), NS_ERROR_UNEXPECTED);
RefPtr<nsFontFaceList> fontFaceList = new nsFontFaceList();
// A table to map gfxFontEntry objects to InspectorFontFace objects.
// (We hold on to the InspectorFontFaces strongly due to the nsAutoPtrs
// in the nsClassHashtable, until we move them out into aResult at the end
// of the function.)
nsLayoutUtils::UsedFontFaceTable fontFaces;
RangeSubtreeIterator iter;
nsresult rv = iter.Init(this);
@ -3510,20 +3512,25 @@ nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
int32_t offset = startContainer == endContainer ?
mEnd.Offset() : content->GetText()->GetLength();
nsLayoutUtils::GetFontFacesForText(frame, mStart.Offset(), offset,
true, fontFaceList);
true, fontFaces);
continue;
}
if (node == endContainer) {
nsLayoutUtils::GetFontFacesForText(frame, 0, mEnd.Offset(),
true, fontFaceList);
true, fontFaces);
continue;
}
}
nsLayoutUtils::GetFontFacesForFrames(frame, fontFaceList);
nsLayoutUtils::GetFontFacesForFrames(frame, fontFaces);
}
// Take ownership of the InspectorFontFaces in the table and move them into
// the aResult outparam.
for (auto iter = fontFaces.Iter(); !iter.Done(); iter.Next()) {
aResult.AppendElement(Move(iter.Data()));
}
fontFaceList.forget(aResult);
return NS_OK;
}

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

@ -33,6 +33,7 @@ class DocGroup;
class DocumentFragment;
class DOMRect;
class DOMRectList;
class InspectorFontFace;
class Selection;
} // namespace dom
} // namespace mozilla
@ -280,7 +281,8 @@ public:
return parentNode;
}
NS_IMETHOD GetUsedFontFaces(nsIDOMFontFaceList** aResult);
nsresult GetUsedFontFaces(
nsTArray<nsAutoPtr<mozilla::dom::InspectorFontFace>>& aResult);
// nsIMutationObserver methods
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED

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

@ -517,6 +517,10 @@ DOMInterfaces = {
'notflattened': True
},
'InspectorFontFace': {
'wrapperCache': False,
},
'IntersectionObserver': {
'nativeType': 'mozilla::dom::DOMIntersectionObserver',
},

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

@ -80,7 +80,3 @@ interface nsIDOMRange;
// Crypto
interface nsIDOMCrypto;
// Used font face (for inspector)
interface nsIDOMFontFace;
interface nsIDOMFontFaceList;

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

@ -63,6 +63,7 @@ namespace InspectorUtils {
unsigned long long state,
optional boolean clearActiveDocument = false);
unsigned long long getContentState(Element element);
[NewObject, Throws] sequence<InspectorFontFace> getUsedFontFaces(Range range);
};
dictionary PropertyNamesOptions {
@ -81,3 +82,26 @@ dictionary InspectorRGBATuple {
double b = 0;
double a = 1;
};
[ChromeOnly]
interface InspectorFontFace {
// An indication of how we found this font during font-matching.
// Note that the same physical font may have been found in multiple ways within a range.
readonly attribute boolean fromFontGroup;
readonly attribute boolean fromLanguagePrefs;
readonly attribute boolean fromSystemFallback;
// available for all fonts
readonly attribute DOMString name; // full font name as obtained from the font resource
readonly attribute DOMString CSSFamilyName; // a family name that could be used in CSS font-family
// (not necessarily the actual name that was used,
// due to aliases, generics, localized names, etc)
// meaningful only when the font is a user font defined using @font-face
readonly attribute CSSFontFaceRule? rule; // null if no associated @font-face rule
readonly attribute long srcIndex; // index in the rule's src list, -1 if no @font-face rule
readonly attribute DOMString URI; // empty string if not a downloaded font, i.e. local
readonly attribute DOMString localName; // empty string if not a src:local(...) rule
readonly attribute DOMString format; // as per http://www.w3.org/TR/css3-webfonts/#referencing
readonly attribute DOMString metadata; // XML metadata from WOFF file (if any)
};

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

@ -21,15 +21,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1121643
/** Test for Bug 1121643 **/
const DOMUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(SpecialPowers.Ci.inIDOMUtils);
const InspectorUtils = SpecialPowers.InspectorUtils;
// Given an element id, returns the first font face name encountered.
let fontUsed = id => {
let element = document.getElementById(id),
range = document.createRange();
range.selectNode(element);
return DOMUtils.getUsedFontFaces(range).item(0).CSSFamilyName;
return InspectorUtils.getUsedFontFaces(range)[0].CSSFamilyName;
}
// A map of the default mono, sans and serif fonts, obtained when

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

@ -719,7 +719,7 @@ gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
// Because platform font activation code may replace the name table
// in the font with a synthetic one, we save the original name so that
// it can be reported via the nsIDOMFontFace API.
// it can be reported via the InspectorUtils API.
nsAutoString originalFullName;
// Call the OTS sanitizer; this will also decode WOFF to sfnt
@ -785,7 +785,7 @@ gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
if (fe) {
fe->mComputedSizeOfUserFont = computedSize;
// Save a copy of the metadata block (if present) for nsIDOMFontFace
// Save a copy of the metadata block (if present) for InspectorUtils
// to use if required. Ownership of the metadata block will be passed
// to the gfxUserFontData record below.
FallibleTArray<uint8_t> metadata;

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

@ -88,7 +88,6 @@
#include "nsDataHashtable.h"
#include "nsTableWrapperFrame.h"
#include "nsTextFrame.h"
#include "nsFontFaceList.h"
#include "nsFontInflationData.h"
#include "nsSVGIntegrationUtils.h"
#include "nsSVGUtils.h"
@ -133,6 +132,7 @@
#include "nsDeckFrame.h"
#include "nsIEffectiveTLDService.h" // for IsInStyloBlocklist
#include "mozilla/StylePrefs.h"
#include "mozilla/dom/InspectorFontFace.h"
#ifdef MOZ_XUL
#include "nsXULPopupManager.h"
@ -7999,14 +7999,15 @@ nsLayoutUtils::AssertTreeOnlyEmptyNextInFlows(nsIFrame *aSubtreeRoot)
#endif
static void
GetFontFacesForFramesInner(nsIFrame* aFrame, nsFontFaceList* aFontFaceList)
GetFontFacesForFramesInner(nsIFrame* aFrame,
nsLayoutUtils::UsedFontFaceTable& aFontFaces)
{
NS_PRECONDITION(aFrame, "NULL frame pointer");
if (aFrame->IsTextFrame()) {
if (!aFrame->GetPrevContinuation()) {
nsLayoutUtils::GetFontFacesForText(aFrame, 0, INT32_MAX, true,
aFontFaceList);
aFontFaces);
}
return;
}
@ -8018,32 +8019,56 @@ GetFontFacesForFramesInner(nsIFrame* aFrame, nsFontFaceList* aFontFaceList)
for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
nsIFrame* child = e.get();
child = nsPlaceholderFrame::GetRealFrameFor(child);
GetFontFacesForFramesInner(child, aFontFaceList);
GetFontFacesForFramesInner(child, aFontFaces);
}
}
}
/* static */
nsresult
/* static */ nsresult
nsLayoutUtils::GetFontFacesForFrames(nsIFrame* aFrame,
nsFontFaceList* aFontFaceList)
UsedFontFaceTable& aFontFaces)
{
NS_PRECONDITION(aFrame, "NULL frame pointer");
while (aFrame) {
GetFontFacesForFramesInner(aFrame, aFontFaceList);
GetFontFacesForFramesInner(aFrame, aFontFaces);
aFrame = GetNextContinuationOrIBSplitSibling(aFrame);
}
return NS_OK;
}
/* static */
nsresult
static void
AddFontsFromTextRun(gfxTextRun* aTextRun,
uint32_t aOffset,
uint32_t aLength,
nsLayoutUtils::UsedFontFaceTable& aFontFaces)
{
gfxTextRun::Range range(aOffset, aOffset + aLength);
gfxTextRun::GlyphRunIterator iter(aTextRun, range);
while (iter.NextRun()) {
gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
// if we have already listed this face, just make sure the match type is
// recorded
InspectorFontFace* existingFace = aFontFaces.Get(fe);
if (existingFace) {
existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType);
} else {
// A new font entry we haven't seen before
InspectorFontFace* ff =
new InspectorFontFace(fe, aTextRun->GetFontGroup(),
iter.GetGlyphRun()->mMatchType);
aFontFaces.Put(fe, ff);
}
}
}
/* static */ nsresult
nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
int32_t aStartOffset, int32_t aEndOffset,
int32_t aStartOffset,
int32_t aEndOffset,
bool aFollowContinuations,
nsFontFaceList* aFontFaceList)
UsedFontFaceTable& aFontFaces)
{
NS_PRECONDITION(aFrame, "NULL frame pointer");
@ -8078,7 +8103,7 @@ nsLayoutUtils::GetFontFacesForText(nsIFrame* aFrame,
uint32_t skipStart = iter.ConvertOriginalToSkipped(fstart);
uint32_t skipEnd = iter.ConvertOriginalToSkipped(fend);
aFontFaceList->AddFontsFromTextRun(textRun, skipStart, skipEnd - skipStart);
AddFontsFromTextRun(textRun, skipStart, skipEnd - skipStart, aFontFaces);
curr = next;
} while (aFollowContinuations && curr);

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

@ -36,6 +36,7 @@
#include <limits>
#include <algorithm>
#include "gfxPoint.h"
#include "nsClassHashtable.h"
class gfxContext;
class nsPresContext;
@ -81,6 +82,7 @@ class Element;
class HTMLImageElement;
class HTMLCanvasElement;
class HTMLVideoElement;
class InspectorFontFace;
class OffscreenCanvas;
class Selection;
} // namespace dom
@ -2267,12 +2269,15 @@ public:
*/
static bool NeedsPrintPreviewBackground(nsPresContext* aPresContext);
typedef nsClassHashtable<nsPtrHashKey<gfxFontEntry>,
mozilla::dom::InspectorFontFace> UsedFontFaceTable;
/**
* Adds all font faces used in the frame tree starting from aFrame
* to the list aFontFaceList.
*/
static nsresult GetFontFacesForFrames(nsIFrame* aFrame,
nsFontFaceList* aFontFaceList);
UsedFontFaceTable& aResult);
/**
* Adds all font faces used within the specified range of text in aFrame,
@ -2284,7 +2289,7 @@ public:
int32_t aStartOffset,
int32_t aEndOffset,
bool aFollowContinuations,
nsFontFaceList* aFontFaceList);
UsedFontFaceTable& aResult);
/**
* Walks the frame tree starting at aFrame looking for textRuns.

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

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsFontFace.h"
#include "nsIDOMCSSFontFaceRule.h"
#include "InspectorFontFace.h"
#include "nsCSSRules.h"
#include "gfxTextRun.h"
#include "gfxUserFontSet.h"
@ -15,56 +15,29 @@
#include "zlib.h"
#include "mozilla/dom/FontFaceSet.h"
using namespace mozilla;
using namespace mozilla::dom;
namespace mozilla {
namespace dom {
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry,
gfxFontGroup* aFontGroup,
uint8_t aMatchType)
: mFontEntry(aFontEntry),
mFontGroup(aFontGroup),
mMatchType(aMatchType)
bool
InspectorFontFace::FromFontGroup()
{
return mMatchType & gfxTextRange::kFontGroup;
}
nsFontFace::~nsFontFace()
bool
InspectorFontFace::FromLanguagePrefs()
{
return mMatchType & gfxTextRange::kPrefsFallback;
}
////////////////////////////////////////////////////////////////////////
// nsISupports
NS_IMPL_ISUPPORTS(nsFontFace, nsIDOMFontFace)
////////////////////////////////////////////////////////////////////////
// nsIDOMFontFace
NS_IMETHODIMP
nsFontFace::GetFromFontGroup(bool * aFromFontGroup)
bool
InspectorFontFace::FromSystemFallback()
{
*aFromFontGroup =
(mMatchType & gfxTextRange::kFontGroup) != 0;
return NS_OK;
return mMatchType & gfxTextRange::kSystemFallback;
}
NS_IMETHODIMP
nsFontFace::GetFromLanguagePrefs(bool * aFromLanguagePrefs)
{
*aFromLanguagePrefs =
(mMatchType & gfxTextRange::kPrefsFallback) != 0;
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetFromSystemFallback(bool * aFromSystemFallback)
{
*aFromSystemFallback =
(mMatchType & gfxTextRange::kSystemFallback) != 0;
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetName(nsAString & aName)
void
InspectorFontFace::GetName(nsAString& aName)
{
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
@ -72,18 +45,16 @@ nsFontFace::GetName(nsAString & aName)
} else {
aName = mFontEntry->RealFaceName();
}
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetCSSFamilyName(nsAString & aCSSFamilyName)
void
InspectorFontFace::GetCSSFamilyName(nsAString& aCSSFamilyName)
{
aCSSFamilyName = mFontEntry->FamilyName();
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetRule(nsIDOMCSSFontFaceRule **aRule)
nsCSSFontFaceRule*
InspectorFontFace::GetRule()
{
// check whether this font entry is associated with an @font-face rule
// in the relevant font group's user font set
@ -98,41 +69,36 @@ nsFontFace::GetRule(nsIDOMCSSFontFaceRule **aRule)
}
}
}
NS_IF_ADDREF(*aRule = rule);
return NS_OK;
return rule;
}
NS_IMETHODIMP
nsFontFace::GetSrcIndex(int32_t * aSrcIndex)
int32_t
InspectorFontFace::SrcIndex()
{
if (mFontEntry->IsUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
*aSrcIndex = mFontEntry->mUserFontData->mSrcIndex;
} else {
*aSrcIndex = -1;
return mFontEntry->mUserFontData->mSrcIndex;
}
return NS_OK;
return -1;
}
NS_IMETHODIMP
nsFontFace::GetURI(nsAString & aURI)
void
InspectorFontFace::GetURI(nsAString& aURI)
{
aURI.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
if (mFontEntry->mUserFontData->mURI) {
nsAutoCString spec;
nsresult rv = mFontEntry->mUserFontData->mURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
mFontEntry->mUserFontData->mURI->GetSpec(spec);
AppendUTF8toUTF16(spec, aURI);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetLocalName(nsAString & aLocalName)
void
InspectorFontFace::GetLocalName(nsAString& aLocalName)
{
if (mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
@ -140,11 +106,10 @@ nsFontFace::GetLocalName(nsAString & aLocalName)
} else {
aLocalName.Truncate();
}
return NS_OK;
}
static void
AppendToFormat(nsAString & aResult, const char* aFormat)
AppendToFormat(nsAString& aResult, const char* aFormat)
{
if (!aResult.IsEmpty()) {
aResult.Append(',');
@ -152,8 +117,8 @@ AppendToFormat(nsAString & aResult, const char* aFormat)
aResult.AppendASCII(aFormat);
}
NS_IMETHODIMP
nsFontFace::GetFormat(nsAString & aFormat)
void
InspectorFontFace::GetFormat(nsAString& aFormat)
{
aFormat.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
@ -181,11 +146,10 @@ nsFontFace::GetFormat(nsAString & aFormat)
AppendToFormat(aFormat, "woff2");
}
}
return NS_OK;
}
NS_IMETHODIMP
nsFontFace::GetMetadata(nsAString & aMetadata)
void
InspectorFontFace::GetMetadata(nsAString& aMetadata)
{
aMetadata.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
@ -223,5 +187,7 @@ nsFontFace::GetMetadata(nsAString & aMetadata)
}
}
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_InspectorFontFace_h
#define mozilla_InspectorFontFace_h
#include "mozilla/dom/InspectorUtilsBinding.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
class gfxFontEntry;
class gfxFontGroup;
class nsCSSFontFaceRule;
namespace mozilla {
namespace dom {
/**
* Information on font face usage by a given DOM Range, as returned by
* InspectorUtils.getUsedFontFaces.
*/
class InspectorFontFace final : public NonRefcountedDOMObject
{
public:
InspectorFontFace(gfxFontEntry* aFontEntry,
gfxFontGroup* aFontGroup,
uint8_t aMatchType)
: mFontEntry(aFontEntry)
, mFontGroup(aFontGroup)
, mMatchType(aMatchType)
{
MOZ_COUNT_CTOR(InspectorFontFace);
}
~InspectorFontFace()
{
MOZ_COUNT_DTOR(InspectorFontFace);
}
gfxFontEntry* GetFontEntry() const { return mFontEntry; }
void AddMatchType(uint8_t aMatchType) { mMatchType |= aMatchType; }
// Web IDL
bool FromFontGroup();
bool FromLanguagePrefs();
bool FromSystemFallback();
void GetName(nsAString& aName);
void GetCSSFamilyName(nsAString& aCSSFamilyName);
nsCSSFontFaceRule* GetRule();
int32_t SrcIndex();
void GetURI(nsAString& aURI);
void GetLocalName(nsAString& aLocalName);
void GetFormat(nsAString& aFormat);
void GetMetadata(nsAString& aMetadata);
bool WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto,
JS::MutableHandle<JSObject*> aReflector)
{
return InspectorFontFaceBinding::Wrap(aCx, this, aGivenProto, aReflector);
}
protected:
RefPtr<gfxFontEntry> mFontEntry;
RefPtr<gfxFontGroup> mFontGroup;
uint8_t mMatchType;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_InspectorFontFace_h

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

@ -22,6 +22,7 @@ class Rule;
} // namespace css
namespace dom {
class Element;
class InspectorFontFace;
} // namespace dom
} // namespace mozilla
@ -217,6 +218,11 @@ public:
ErrorResult& aRv);
static uint64_t GetContentState(GlobalObject& aGlobal, Element& aElement);
static void GetUsedFontFaces(GlobalObject& aGlobal,
nsRange& aRange,
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
ErrorResult& aRv);
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);

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

@ -56,6 +56,7 @@
#include "mozilla/ServoStyleRuleMap.h"
#include "mozilla/ServoCSSParser.h"
#include "mozilla/dom/InspectorUtils.h"
#include "mozilla/dom/InspectorFontFace.h"
using namespace mozilla;
using namespace mozilla::css;
@ -973,16 +974,21 @@ InspectorUtils::GetCleanStyleContextForElement(dom::Element* aElement,
return styleContext.forget();
}
/* static */ void
InspectorUtils::GetUsedFontFaces(GlobalObject& aGlobalObject,
nsRange& aRange,
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
ErrorResult& aRv)
{
nsresult rv = aRange.GetUsedFontFaces(aResult);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
} // namespace dom
} // namespace mozilla
NS_IMETHODIMP
inDOMUtils::GetUsedFontFaces(nsIDOMRange* aRange,
nsIDOMFontFaceList** aFontFaceList)
{
return static_cast<nsRange*>(aRange)->GetUsedFontFaces(aFontFaceList);
}
static EventStates
GetStatesForPseudoClass(const nsAString& aStatePseudo)
{

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

@ -20,8 +20,6 @@ interface nsIDOMCSSStyleSheet;
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
nsIDOMFontFaceList getUsedFontFaces(in nsIDOMRange aRange);
/**
* Get the names of all the supported pseudo-elements.
* Pseudo-elements which are only accepted in UA style sheets are

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

@ -15,22 +15,16 @@ XPIDL_SOURCES += [
'inIDOMView.idl',
'inISearchObserver.idl',
'inISearchProcess.idl',
'nsIDOMFontFace.idl',
'nsIDOMFontFaceList.idl',
]
XPIDL_MODULE = 'inspector'
EXPORTS += [
'nsFontFace.h',
'nsFontFaceList.h',
]
EXPORTS.mozilla += [
'ServoStyleRuleMap.h',
]
EXPORTS.mozilla.dom += [
'InspectorFontFace.h',
'InspectorUtils.h',
]
@ -39,8 +33,7 @@ UNIFIED_SOURCES += [
'inDeepTreeWalker.cpp',
'inDOMUtils.cpp',
'inLayoutUtils.cpp',
'nsFontFace.cpp',
'nsFontFaceList.cpp',
'InspectorFontFace.cpp',
'ServoStyleRuleMap.cpp',
]

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

@ -1,39 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsFontFace_h__
#define __nsFontFace_h__
#include "nsIDOMFontFace.h"
class gfxFontEntry;
class gfxFontGroup;
class nsFontFace : public nsIDOMFontFace
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMFONTFACE
nsFontFace(gfxFontEntry* aFontEntry,
gfxFontGroup* aFontGroup,
uint8_t aMatchInfo);
gfxFontEntry* GetFontEntry() const { return mFontEntry.get(); }
void AddMatchType(uint8_t aMatchType) {
mMatchType |= aMatchType;
}
protected:
virtual ~nsFontFace();
RefPtr<gfxFontEntry> mFontEntry;
RefPtr<gfxFontGroup> mFontGroup;
uint8_t mMatchType;
};
#endif // __nsFontFace_h__

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

@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsFontFaceList.h"
#include "nsFontFace.h"
#include "nsFontFaceLoader.h"
#include "nsIFrame.h"
#include "gfxTextRun.h"
#include "mozilla/gfx/2D.h"
nsFontFaceList::nsFontFaceList()
{
}
nsFontFaceList::~nsFontFaceList()
{
}
////////////////////////////////////////////////////////////////////////
// nsISupports
NS_IMPL_ISUPPORTS(nsFontFaceList, nsIDOMFontFaceList)
////////////////////////////////////////////////////////////////////////
// nsIDOMFontFaceList
NS_IMETHODIMP
nsFontFaceList::Item(uint32_t index, nsIDOMFontFace **_retval)
{
NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG);
uint32_t current = 0;
nsIDOMFontFace* result = nullptr;
for (auto iter = mFontFaces.Iter(); !iter.Done(); iter.Next()) {
if (current == index) {
result = iter.UserData();
break;
}
current++;
}
NS_ASSERTION(result != nullptr, "null entry in nsFontFaceList?");
NS_IF_ADDREF(*_retval = result);
return NS_OK;
}
NS_IMETHODIMP
nsFontFaceList::GetLength(uint32_t *aLength)
{
*aLength = mFontFaces.Count();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsFontFaceList
nsresult
nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun,
uint32_t aOffset, uint32_t aLength)
{
gfxTextRun::Range range(aOffset, aOffset + aLength);
gfxTextRun::GlyphRunIterator iter(aTextRun, range);
while (iter.NextRun()) {
gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry();
// if we have already listed this face, just make sure the match type is
// recorded
nsFontFace* existingFace =
static_cast<nsFontFace*>(mFontFaces.GetWeak(fe));
if (existingFace) {
existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType);
} else {
// A new font entry we haven't seen before
RefPtr<nsFontFace> ff =
new nsFontFace(fe, aTextRun->GetFontGroup(),
iter.GetGlyphRun()->mMatchType);
mFontFaces.Put(fe, ff);
}
}
return NS_OK;
}

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

@ -1,36 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsFontFaceList_h__
#define __nsFontFaceList_h__
#include "nsIDOMFontFaceList.h"
#include "nsIDOMFontFace.h"
#include "nsCOMPtr.h"
#include "nsInterfaceHashtable.h"
#include "nsHashKeys.h"
class gfxFontEntry;
class gfxTextRun;
class nsFontFaceList : public nsIDOMFontFaceList
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMFONTFACELIST
nsFontFaceList();
nsresult AddFontsFromTextRun(gfxTextRun* aTextRun,
uint32_t aOffset, uint32_t aLength);
protected:
virtual ~nsFontFaceList();
nsInterfaceHashtable<nsPtrHashKey<gfxFontEntry>,nsIDOMFontFace> mFontFaces;
};
#endif // __nsFontFaceList_h__

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

@ -1,32 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIDOMCSSFontFaceRule;
interface nsIDOMCSSStyleDeclaration;
[scriptable, uuid(9a3b1272-6585-4f41-b08f-fdc5da444cd0)]
interface nsIDOMFontFace : nsISupports
{
// An indication of how we found this font during font-matching.
// Note that the same physical font may have been found in multiple ways within a range.
readonly attribute boolean fromFontGroup;
readonly attribute boolean fromLanguagePrefs;
readonly attribute boolean fromSystemFallback;
// available for all fonts
readonly attribute DOMString name; // full font name as obtained from the font resource
readonly attribute DOMString CSSFamilyName; // a family name that could be used in CSS font-family
// (not necessarily the actual name that was used,
// due to aliases, generics, localized names, etc)
// meaningful only when the font is a user font defined using @font-face
readonly attribute nsIDOMCSSFontFaceRule rule; // null if no associated @font-face rule
readonly attribute long srcIndex; // index in the rule's src list, -1 if no @font-face rule
readonly attribute DOMString URI; // null if not a downloaded font, i.e. local
readonly attribute DOMString localName; // null if not a src:local(...) rule
readonly attribute DOMString format; // as per http://www.w3.org/TR/css3-webfonts/#referencing
readonly attribute DOMString metadata; // XML metadata from WOFF file (if any)
};

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

@ -1,14 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIDOMFontFace;
[scriptable, uuid(2538579c-9472-4fd9-8dc1-d44ce4c1b7ba)]
interface nsIDOMFontFaceList : nsISupports
{
nsIDOMFontFace item(in unsigned long index);
readonly attribute unsigned long length;
};

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

@ -25,17 +25,14 @@ function RunTest() {
const kIsMac = navigator.platform.indexOf("Mac") == 0;
const kIsWin = navigator.platform.indexOf("Win") == 0;
var domUtils =
CC["@mozilla.org/inspector/dom-utils;1"].getService(CI.inIDOMUtils);
var rng = document.createRange();
var elem, fonts, f;
elem = document.getElementById("test1");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts for simple Latin text");
f = fonts.item(0);
f = fonts[0];
is(f.rule, null, "rule");
is(f.srcIndex, -1, "srcIndex");
is(f.localName, "", "local name");
@ -46,22 +43,22 @@ function RunTest() {
elem = document.getElementById("test2");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 3, "number of fonts for mixed serif, sans and monospaced text");
// report(elem.id, fonts);
elem = document.getElementById("test3");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "number of fonts for mixed Latin & Chinese");
// report(elem.id, fonts);
// get properties of a @font-face font
elem = document.getElementById("test4");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts in @font-face test");
f = fonts.item(0);
f = fonts[0];
isnot(f.rule, null, "missing rule");
is(f.srcIndex, 1, "srcIndex");
is(f.localName, "", "local name");
@ -77,21 +74,21 @@ function RunTest() {
// initial latin substring...
rng.setStart(elem, 0);
rng.setEnd(elem, 20); // "supercalifragilistic"
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts (Latin-only)");
f = fonts.item(0);
f = fonts[0];
is(f.name, "Gentium Plus", "font name");
is(f.CSSFamilyName, "font-face-test-family", "family name");
is(f.fromFontGroup, true, "font matched in font group");
// extend to include a chinese character
rng.setEnd(elem, 21);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "number of fonts (incl Chinese)");
if (kIsMac || kIsWin) { // these are only implemented by the Mac & Win font backends
var i;
for (i = 0; i < fonts.length; ++i) {
f = fonts.item(i);
f = fonts[i];
if (f.rule) {
is(f.fromFontGroup, true, "@font-face font matched in group");
is(f.fromLanguagePrefs, false, "not from language prefs");
@ -109,33 +106,33 @@ function RunTest() {
rng.setStart(elem, elem.length - 1);
rng.setEnd(elem, elem.length);
is(rng.toString(), "!", "content of range");
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts for last char");
f = fonts.item(0);
f = fonts[0];
is(f.name, "Gentium Plus", "font name");
// include the preceding character as well
rng.setStart(elem, elem.length - 2);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "number of fonts for last two chars");
// then trim the final one
rng.setEnd(elem, elem.length - 1);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts for Chinese char");
f = fonts.item(0);
f = fonts[0];
isnot(f.name, "Gentium Plus", "font name for Chinese char");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
// report("test5", fonts);
elem = document.getElementById("test6");
rng.selectNode(elem);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "number of font faces for regular & italic");
is(fonts.item(0).CSSFamilyName, fonts.item(1).CSSFamilyName, "same family for regular & italic");
isnot(fonts.item(0).name, fonts.item(1).name, "different faces for regular & italic");
is(fonts[0].CSSFamilyName, fonts[1].CSSFamilyName, "same family for regular & italic");
isnot(fonts[0].name, fonts[1].name, "different faces for regular & italic");
// report(elem.id, fonts);
SimpleTest.finish();

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

@ -19,48 +19,45 @@ function RunTest() {
const CI = Components.interfaces;
const CC = Components.classes;
var domUtils =
CC["@mozilla.org/inspector/dom-utils;1"].getService(CI.inIDOMUtils);
var rng = document.createRange();
var elem, fonts, f;
elem = document.getElementById("test").childNodes[0];
rng.setStart(elem, 0);
rng.setEnd(elem, 14);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 2, "number of fonts used for entire text");
// initial latin substring...
rng.setStart(elem, 0);
rng.setEnd(elem, 5); // "Hello"
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts (1)");
f = fonts.item(0);
f = fonts[0];
is(f.name, "Gentium Plus", "font name (1)");
// the space (where the line wraps) should also be Gentium
rng.setStart(elem, 5);
rng.setEnd(elem, 6); // space
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts (2)");
f = fonts.item(0);
f = fonts[0];
is(f.name, "Gentium Plus", "font name (2)");
// the Chinese text "ni hao" should NOT be in Gentium
rng.setStart(elem, 6);
rng.setEnd(elem, 8); // two Chinese characters on second line
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts (3)");
f = fonts.item(0);
f = fonts[0];
isnot(f.name, "Gentium Plus", "font name (3)");
// space and "world" should be Gentium again
rng.setStart(elem, 8);
rng.setEnd(elem, 14);
fonts = domUtils.getUsedFontFaces(rng);
fonts = InspectorUtils.getUsedFontFaces(rng);
is(fonts.length, 1, "number of fonts (4)");
f = fonts.item(0);
f = fonts[0];
is(f.name, "Gentium Plus", "font name (4)");
SimpleTest.finish();