1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/inspector/nsFontFaceList.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsFontFaceList.h" 1.9 +#include "nsFontFace.h" 1.10 +#include "nsFontFaceLoader.h" 1.11 +#include "nsIFrame.h" 1.12 +#include "gfxFont.h" 1.13 +#include "mozilla/gfx/2D.h" 1.14 + 1.15 +nsFontFaceList::nsFontFaceList() 1.16 +{ 1.17 +} 1.18 + 1.19 +nsFontFaceList::~nsFontFaceList() 1.20 +{ 1.21 +} 1.22 + 1.23 +//////////////////////////////////////////////////////////////////////// 1.24 +// nsISupports 1.25 + 1.26 +NS_IMPL_ISUPPORTS(nsFontFaceList, nsIDOMFontFaceList) 1.27 + 1.28 +//////////////////////////////////////////////////////////////////////// 1.29 +// nsIDOMFontFaceList 1.30 + 1.31 +/* nsIDOMFontFace item (in unsigned long index); */ 1.32 +struct FindByIndexData { 1.33 + uint32_t mTarget; 1.34 + uint32_t mCurrent; 1.35 + nsIDOMFontFace* mResult; 1.36 +}; 1.37 + 1.38 +static PLDHashOperator 1.39 +FindByIndex(gfxFontEntry* aKey, nsIDOMFontFace* aData, void* aUserData) 1.40 +{ 1.41 + FindByIndexData* data = static_cast<FindByIndexData*>(aUserData); 1.42 + if (data->mCurrent == data->mTarget) { 1.43 + data->mResult = aData; 1.44 + return PL_DHASH_STOP; 1.45 + } 1.46 + data->mCurrent++; 1.47 + return PL_DHASH_NEXT; 1.48 +} 1.49 + 1.50 +NS_IMETHODIMP 1.51 +nsFontFaceList::Item(uint32_t index, nsIDOMFontFace **_retval) 1.52 +{ 1.53 + NS_ENSURE_TRUE(index < mFontFaces.Count(), NS_ERROR_INVALID_ARG); 1.54 + FindByIndexData userData; 1.55 + userData.mTarget = index; 1.56 + userData.mCurrent = 0; 1.57 + userData.mResult = nullptr; 1.58 + mFontFaces.EnumerateRead(FindByIndex, &userData); 1.59 + NS_ASSERTION(userData.mResult != nullptr, "null entry in nsFontFaceList?"); 1.60 + NS_IF_ADDREF(*_retval = userData.mResult); 1.61 + return NS_OK; 1.62 +} 1.63 + 1.64 +/* readonly attribute unsigned long length; */ 1.65 +NS_IMETHODIMP 1.66 +nsFontFaceList::GetLength(uint32_t *aLength) 1.67 +{ 1.68 + *aLength = mFontFaces.Count(); 1.69 + return NS_OK; 1.70 +} 1.71 + 1.72 +//////////////////////////////////////////////////////////////////////// 1.73 +// nsFontFaceList 1.74 + 1.75 +nsresult 1.76 +nsFontFaceList::AddFontsFromTextRun(gfxTextRun* aTextRun, 1.77 + uint32_t aOffset, uint32_t aLength) 1.78 +{ 1.79 + gfxTextRun::GlyphRunIterator iter(aTextRun, aOffset, aLength); 1.80 + while (iter.NextRun()) { 1.81 + gfxFontEntry *fe = iter.GetGlyphRun()->mFont->GetFontEntry(); 1.82 + // if we have already listed this face, just make sure the match type is 1.83 + // recorded 1.84 + nsFontFace* existingFace = 1.85 + static_cast<nsFontFace*>(mFontFaces.GetWeak(fe)); 1.86 + if (existingFace) { 1.87 + existingFace->AddMatchType(iter.GetGlyphRun()->mMatchType); 1.88 + } else { 1.89 + // A new font entry we haven't seen before 1.90 + nsRefPtr<nsFontFace> ff = 1.91 + new nsFontFace(fe, aTextRun->GetFontGroup(), 1.92 + iter.GetGlyphRun()->mMatchType); 1.93 + mFontFaces.Put(fe, ff); 1.94 + } 1.95 + } 1.96 + 1.97 + return NS_OK; 1.98 +}