static void CopyChunkToBlock(AudioChunk& aInput, AudioBlock *aBlock, uint32_t aOffsetInBlock) { uint32_t blockChannels = aBlock->ChannelCount(); AutoTArray<const T*,2> channels; if (aInput.IsNull()) { channels.SetLength(blockChannels); PodZero(channels.Elements(), blockChannels); } else { const nsTArray<const T*>& inputChannels = aInput.ChannelData<T>(); channels.SetLength(inputChannels.Length()); PodCopy(channels.Elements(), inputChannels.Elements(), channels.Length()); if (channels.Length() != blockChannels) { // We only need to upmix here because aBlock's channel count has been // chosen to be a superset of the channel count of every chunk. AudioChannelsUpMix(&channels, blockChannels, static_cast<T*>(nullptr)); } } for (uint32_t c = 0; c < blockChannels; ++c) { float* outputData = aBlock->ChannelFloatsForWrite(c) + aOffsetInBlock; if (channels[c]) { ConvertAudioSamplesWithScale(channels[c], outputData, aInput.GetDuration(), aInput.mVolume); } else { PodZero(outputData, aInput.GetDuration()); } } }
Reverb::Reverb(ThreadSharedFloatArrayBufferList* impulseResponse, size_t impulseResponseBufferLength, size_t maxFFTSize, bool useBackgroundThreads, bool normalize, float sampleRate) { float scale = 1; AutoTArray<const float*,4> irChannels; for (size_t i = 0; i < impulseResponse->GetChannels(); ++i) { irChannels.AppendElement(impulseResponse->GetData(i)); } AutoTArray<float,1024> tempBuf; if (normalize) { scale = calculateNormalizationScale(impulseResponse, impulseResponseBufferLength, sampleRate); if (scale) { tempBuf.SetLength(irChannels.Length()*impulseResponseBufferLength); for (uint32_t i = 0; i < irChannels.Length(); ++i) { float* buf = &tempBuf[i*impulseResponseBufferLength]; AudioBufferCopyWithScale(irChannels[i], scale, buf, impulseResponseBufferLength); irChannels[i] = buf; } } } initialize(irChannels, impulseResponseBufferLength, maxFFTSize, useBackgroundThreads); }
int32_t nsTreeContentView::EnsureSubtree(int32_t aIndex) { Row* row = mRows[aIndex]; nsIContent* child; child = nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treechildren); if (!child || !child->IsXULElement()) { return 0; } AutoTArray<nsAutoPtr<Row>, 8> rows; int32_t index = 0; Serialize(child, aIndex, &index, rows); // We can't use InsertElementsAt since the destination can't steal // ownership from its const source argument. for (nsTArray<Row>::index_type i = 0; i < rows.Length(); i++) { nsAutoPtr<Row>* newRow = mRows.InsertElementAt(aIndex + i + 1); *newRow = rows[i]; } int32_t count = rows.Length(); row->mSubtreeSize += count; UpdateSubtreeSizes(row->mParentIndex, count); // Update parent indexes, but skip newly added rows. // They already have correct values. UpdateParentIndexes(aIndex, count + 1, count); return count; }
int32_t nsTreeContentView::InsertRow(int32_t aParentIndex, int32_t aIndex, nsIContent* aContent) { AutoTArray<nsAutoPtr<Row>, 8> rows; if (aContent->IsXULElement(nsGkAtoms::treeitem)) { SerializeItem(aContent, aParentIndex, &aIndex, rows); } else if (aContent->IsXULElement(nsGkAtoms::treeseparator)) { SerializeSeparator(aContent, aParentIndex, &aIndex, rows); } // We can't use InsertElementsAt since the destination can't steal // ownership from its const source argument. for (nsTArray<Row>::index_type i = 0; i < rows.Length(); i++) { nsAutoPtr<Row>* newRow = mRows.InsertElementAt(aParentIndex + aIndex + i + 1); *newRow = rows[i]; } int32_t count = rows.Length(); UpdateSubtreeSizes(aParentIndex, count); // Update parent indexes, but skip added rows. // They already have correct values. UpdateParentIndexes(aParentIndex + aIndex, count + 1, count); return count; }
int32_t nsTreeContentView::EnsureSubtree(int32_t aIndex) { Row* row = mRows[aIndex].get(); nsIContent* child; child = nsTreeUtils::GetImmediateChild(row->mContent, nsGkAtoms::treechildren); if (!child || !child->IsXULElement()) { return 0; } AutoTArray<UniquePtr<Row>, 8> rows; int32_t index = 0; Serialize(child, aIndex, &index, rows); // Insert |rows| into |mRows| at position |aIndex|, by first creating empty // UniquePtr entries and then Move'ing |rows|'s entries into them. (Note // that we can't simply use InsertElementsAt with an array argument, since // the destination can't steal ownership from its const source argument.) UniquePtr<Row>* newRows = mRows.InsertElementsAt(aIndex + 1, rows.Length()); for (nsTArray<Row>::index_type i = 0; i < rows.Length(); i++) { newRows[i] = Move(rows[i]); } int32_t count = rows.Length(); row->mSubtreeSize += count; UpdateSubtreeSizes(row->mParentIndex, count); // Update parent indexes, but skip newly added rows. // They already have correct values. UpdateParentIndexes(aIndex, count + 1, count); return count; }
/*static*/ void AudioTrackEncoder::InterleaveTrackData(AudioChunk& aChunk, int32_t aDuration, uint32_t aOutputChannels, AudioDataValue* aOutput) { switch(aChunk.mBufferFormat) { case AUDIO_FORMAT_S16: { AutoTArray<const int16_t*, 2> array; array.SetLength(aOutputChannels); for (uint32_t i = 0; i < array.Length(); i++) { array[i] = static_cast<const int16_t*>(aChunk.mChannelData[i]); } InterleaveTrackData(array, aDuration, aOutputChannels, aOutput, aChunk.mVolume); break; } case AUDIO_FORMAT_FLOAT32: { AutoTArray<const float*, 2> array; array.SetLength(aOutputChannels); for (uint32_t i = 0; i < array.Length(); i++) { array[i] = static_cast<const float*>(aChunk.mChannelData[i]); } InterleaveTrackData(array, aDuration, aOutputChannels, aOutput, aChunk.mVolume); break; } case AUDIO_FORMAT_SILENCE: { MOZ_ASSERT(false, "To implement."); } }; }
void ProxyAccessible::TableSelectedCells(nsTArray<ProxyAccessible*>* aCellIDs) { AutoTArray<uint64_t, 30> cellIDs; Unused << mDoc->SendTableSelectedCells(mID, &cellIDs); aCellIDs->SetCapacity(cellIDs.Length()); for (uint32_t i = 0; i < cellIDs.Length(); ++i) { aCellIDs->AppendElement(mDoc->GetAccessible(cellIDs[i])); } }
void ProxyAccessible::SelectedItems( nsTArray<ProxyAccessible*>* aSelectedItems) { AutoTArray<uint64_t, 10> itemIDs; Unused << mDoc->SendSelectedItems(mID, &itemIDs); aSelectedItems->SetCapacity(itemIDs.Length()); for (size_t i = 0; i < itemIDs.Length(); ++i) { aSelectedItems->AppendElement(mDoc->GetAccessible(itemIDs[i])); } }
nsIRDFResource* RDFContentSinkImpl::GetContextElement(int32_t ancestor /* = 0 */) { if ((nullptr == mContextStack) || (uint32_t(ancestor) >= mContextStack->Length())) { return nullptr; } return mContextStack->ElementAt( mContextStack->Length()-ancestor-1).mResource; }
/* static */ void nsFontFaceUtils::MarkDirtyForFontChange(nsIFrame* aSubtreeRoot, const gfxUserFontEntry* aFont) { AutoTArray<nsIFrame*, 4> subtrees; subtrees.AppendElement(aSubtreeRoot); nsIPresShell* ps = aSubtreeRoot->PresContext()->PresShell(); // check descendants, iterating over subtrees that may include // additional subtrees associated with placeholders do { nsIFrame* subtreeRoot = subtrees.ElementAt(subtrees.Length() - 1); subtrees.RemoveElementAt(subtrees.Length() - 1); // Check all descendants to see if they use the font AutoTArray<nsIFrame*, 32> stack; stack.AppendElement(subtreeRoot); do { nsIFrame* f = stack.ElementAt(stack.Length() - 1); stack.RemoveElementAt(stack.Length() - 1); // if this frame uses the font, mark its descendants dirty // and skip checking its children if (FrameUsesFont(f, aFont)) { ScheduleReflow(ps, f); } else { if (f->GetType() == nsGkAtoms::placeholderFrame) { nsIFrame* oof = nsPlaceholderFrame::GetRealFrameForPlaceholder(f); if (!nsLayoutUtils::IsProperAncestorFrame(subtreeRoot, oof)) { // We have another distinct subtree we need to mark. subtrees.AppendElement(oof); } } nsIFrame::ChildListIterator lists(f); for (; !lists.IsDone(); lists.Next()) { nsFrameList::Enumerator childFrames(lists.CurrentList()); for (; !childFrames.AtEnd(); childFrames.Next()) { nsIFrame* kid = childFrames.get(); stack.AppendElement(kid); } } } } while (!stack.IsEmpty()); } while (!subtrees.IsEmpty()); }
NS_IMETHODIMP xpcAccessibleTable::GetSelectedCells(nsIArray** aSelectedCells) { NS_ENSURE_ARG_POINTER(aSelectedCells); *aSelectedCells = nullptr; if (!Intl()) return NS_ERROR_FAILURE; nsresult rv = NS_OK; nsCOMPtr<nsIMutableArray> selCells = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); AutoTArray<Accessible*, XPC_TABLE_DEFAULT_SIZE> cellsArray; Intl()->SelectedCells(&cellsArray); uint32_t totalCount = cellsArray.Length(); for (uint32_t idx = 0; idx < totalCount; idx++) { Accessible* cell = cellsArray.ElementAt(idx); selCells->AppendElement(static_cast<nsIAccessible*>(ToXPC(cell))); } NS_ADDREF(*aSelectedCells = selCells); return NS_OK; }
NS_IMETHODIMP xpcAccessible::GetAttributes(nsIPersistentProperties** aAttributes) { NS_ENSURE_ARG_POINTER(aAttributes); *aAttributes = nullptr; if (IntlGeneric().IsNull()) { return NS_ERROR_FAILURE; } if (Accessible* acc = Intl()) { nsCOMPtr<nsIPersistentProperties> attributes = acc->Attributes(); attributes.swap(*aAttributes); return NS_OK; } ProxyAccessible* proxy = IntlGeneric().AsProxy(); AutoTArray<Attribute, 10> attrs; proxy->Attributes(&attrs); nsCOMPtr<nsIPersistentProperties> props = do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID); uint32_t attrCount = attrs.Length(); nsAutoString unused; for (uint32_t i = 0; i < attrCount; i++) { props->SetStringProperty(attrs[i].Name(), attrs[i].Value(), unused); } props.forget(aAttributes); return NS_OK; }
// The text that should be displayed for this counter. void nsCounterUseNode::GetText(nsString& aResult) { aResult.Truncate(); AutoTArray<nsCounterNode*, 8> stack; stack.AppendElement(static_cast<nsCounterNode*>(this)); if (mAllCounters && mScopeStart) { for (nsCounterNode* n = mScopeStart; n->mScopePrev; n = n->mScopeStart) { stack.AppendElement(n->mScopePrev); } } WritingMode wm = mPseudoFrame ? mPseudoFrame->GetWritingMode() : WritingMode(); for (uint32_t i = stack.Length() - 1;; --i) { nsCounterNode* n = stack[i]; nsAutoString text; bool isTextRTL; mCounterStyle->GetCounterText(n->mValueAfter, wm, text, isTextRTL); aResult.Append(text); if (i == 0) { break; } aResult.Append(mSeparator); } }
void HTMLOptionsCollection::GetSupportedNames(nsTArray<nsString>& aNames) { AutoTArray<nsIAtom*, 8> atoms; for (uint32_t i = 0; i < mElements.Length(); ++i) { HTMLOptionElement* content = mElements.ElementAt(i); if (content) { // Note: HasName means the names is exposed on the document, // which is false for options, so we don't check it here. const nsAttrValue* val = content->GetParsedAttr(nsGkAtoms::name); if (val && val->Type() == nsAttrValue::eAtom) { nsIAtom* name = val->GetAtomValue(); if (!atoms.Contains(name)) { atoms.AppendElement(name); } } if (content->HasID()) { nsIAtom* id = content->GetID(); if (!atoms.Contains(id)) { atoms.AppendElement(id); } } } } uint32_t atomsLen = atoms.Length(); nsString* names = aNames.AppendElements(atomsLen); for (uint32_t i = 0; i < atomsLen; ++i) { atoms[i]->ToString(names[i]); } }
void AudioNodeStream::AccumulateInputChunk(uint32_t aInputIndex, const AudioBlock& aChunk, AudioBlock* aBlock, DownmixBufferType* aDownmixBuffer) { AutoTArray<const float*,GUESS_AUDIO_CHANNELS> channels; UpMixDownMixChunk(&aChunk, aBlock->ChannelCount(), channels, *aDownmixBuffer); for (uint32_t c = 0; c < channels.Length(); ++c) { const float* inputData = static_cast<const float*>(channels[c]); float* outputData = aBlock->ChannelFloatsForWrite(c); if (inputData) { if (aInputIndex == 0) { AudioBlockCopyChannelWithScale(inputData, aChunk.mVolume, outputData); } else { AudioBlockAddChannelWithScale(inputData, aChunk.mVolume, outputData); } } else { if (aInputIndex == 0) { PodZero(outputData, WEBAUDIO_BLOCK_SIZE); } } } }
void AudioStream::GetTimeStretched(AudioBufferWriter& aWriter) { mMonitor.AssertCurrentThreadOwns(); // We need to call the non-locking version, because we already have the lock. if (EnsureTimeStretcherInitializedUnlocked() != NS_OK) { return; } uint32_t toPopFrames = ceil(aWriter.Available() * mAudioClock.GetPlaybackRate()); while (mTimeStretcher->numSamples() < aWriter.Available()) { UniquePtr<Chunk> c = mDataSource.PopFrames(toPopFrames); if (c->Frames() == 0) { break; } MOZ_ASSERT(c->Frames() <= toPopFrames); if (IsValidAudioFormat(c.get())) { mTimeStretcher->putSamples(c->Data(), c->Frames()); } else { // Write silence if invalid format. AutoTArray<AudioDataValue, 1000> buf; buf.SetLength(mOutChannels * c->Frames()); memset(buf.Elements(), 0, buf.Length() * sizeof(AudioDataValue)); mTimeStretcher->putSamples(buf.Elements(), c->Frames()); } } auto timeStretcher = mTimeStretcher; aWriter.Write([timeStretcher] (AudioDataValue* aPtr, uint32_t aFrames) { return timeStretcher->receiveSamples(aPtr, aFrames); }, aWriter.Available()); }
NS_IMETHODIMP xpcAccessibleHyperText::GetDefaultTextAttributes(nsIPersistentProperties** aAttributes) { NS_ENSURE_ARG_POINTER(aAttributes); *aAttributes = nullptr; if (mIntl.IsNull()) return NS_ERROR_FAILURE; nsCOMPtr<nsIPersistentProperties> props; if (mIntl.IsAccessible()) { props = Intl()->DefaultTextAttributes(); } else { #if defined(XP_WIN) return NS_ERROR_NOT_IMPLEMENTED; #else AutoTArray<Attribute, 10> attrs; mIntl.AsProxy()->DefaultTextAttributes(&attrs); uint32_t attrCount = attrs.Length(); nsAutoString unused; for (uint32_t i = 0; i < attrCount; i++) { props->SetStringProperty(attrs[i].Name(), attrs[i].Value(), unused); } #endif } props.forget(aAttributes); return NS_OK; }
void FetchDriver::SetRequestHeaders(nsIHttpChannel* aChannel) const { MOZ_ASSERT(aChannel); AutoTArray<InternalHeaders::Entry, 5> headers; mRequest->Headers()->GetEntries(headers); bool hasAccept = false; for (uint32_t i = 0; i < headers.Length(); ++i) { if (!hasAccept && headers[i].mName.EqualsLiteral("accept")) { hasAccept = true; } if (headers[i].mValue.IsEmpty()) { aChannel->SetEmptyRequestHeader(headers[i].mName); } else { aChannel->SetRequestHeader(headers[i].mName, headers[i].mValue, false /* merge */); } } if (!hasAccept) { aChannel->SetRequestHeader(NS_LITERAL_CSTRING("accept"), NS_LITERAL_CSTRING("*/*"), false /* merge */); } if (mRequest->ForceOriginHeader()) { nsAutoString origin; if (NS_SUCCEEDED(nsContentUtils::GetUTFOrigin(mPrincipal, origin))) { aChannel->SetRequestHeader(NS_LITERAL_CSTRING("origin"), NS_ConvertUTF16toUTF8(origin), false /* merge */); } } }
void nsShmImage::Put(const mozilla::LayoutDeviceIntRegion& aRegion) { AutoTArray<xcb_rectangle_t, 32> xrects; xrects.SetCapacity(aRegion.GetNumRects()); for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) { const mozilla::LayoutDeviceIntRect &r = iter.Get(); xcb_rectangle_t xrect = { (short)r.x, (short)r.y, (unsigned short)r.width, (unsigned short)r.height }; xrects.AppendElement(xrect); } if (!mGC) { mGC = xcb_generate_id(mConnection); xcb_create_gc(mConnection, mGC, mWindow, 0, nullptr); } xcb_set_clip_rectangles(mConnection, XCB_CLIP_ORDERING_YX_BANDED, mGC, 0, 0, xrects.Length(), xrects.Elements()); if (mPixmap != XCB_NONE) { mLastRequest = xcb_copy_area_checked(mConnection, mPixmap, mWindow, mGC, 0, 0, 0, 0, mSize.width, mSize.height); } else { mLastRequest = xcb_shm_put_image_checked(mConnection, mWindow, mGC, mSize.width, mSize.height, 0, 0, mSize.width, mSize.height, 0, 0, mDepth, XCB_IMAGE_FORMAT_Z_PIXMAP, 0, mShmSeg, 0); } xcb_flush(mConnection); }
void VideoSink::RenderVideoFrames(int32_t aMaxFrames, int64_t aClockTime, const TimeStamp& aClockTimeStamp) { AssertOwnerThread(); AutoTArray<RefPtr<MediaData>,16> frames; VideoQueue().GetFirstElements(aMaxFrames, &frames); if (frames.IsEmpty() || !mContainer) { return; } AutoTArray<ImageContainer::NonOwningImage,16> images; TimeStamp lastFrameTime; MediaSink::PlaybackParams params = mAudioSink->GetPlaybackParams(); for (uint32_t i = 0; i < frames.Length(); ++i) { VideoData* frame = frames[i]->As<VideoData>(); frame->mSentToCompositor = true; if (!frame->mImage || !frame->mImage->IsValid() || !frame->mImage->GetSize().width || !frame->mImage->GetSize().height) { continue; } int64_t frameTime = frame->mTime; if (frameTime < 0) { // Frame times before the start time are invalid; drop such frames continue; } TimeStamp t; if (aMaxFrames > 1) { MOZ_ASSERT(!aClockTimeStamp.IsNull()); int64_t delta = frame->mTime - aClockTime; t = aClockTimeStamp + TimeDuration::FromMicroseconds(delta / params.mPlaybackRate); if (!lastFrameTime.IsNull() && t <= lastFrameTime) { // Timestamps out of order; drop the new frame. In theory we should // probably replace the previous frame with the new frame if the // timestamps are equal, but this is a corrupt video file already so // never mind. continue; } lastFrameTime = t; } ImageContainer::NonOwningImage* img = images.AppendElement(); img->mTimeStamp = t; img->mImage = frame->mImage; img->mFrameID = frame->mFrameID; img->mProducerID = mProducerID; VSINK_LOG_V("playing video frame %lld (id=%x) (vq-queued=%i)", frame->mTime, frame->mFrameID, VideoQueue().GetSize()); } mContainer->SetCurrentFrames(frames[0]->As<VideoData>()->mDisplay, images); }
STDMETHODIMP ia2Accessible::get_selectionRanges(IA2Range** aRanges, long *aNRanges) { if (!aRanges || !aNRanges) return E_INVALIDARG; *aNRanges = 0; AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); if (acc->IsDefunct()) return CO_E_OBJNOTCONNECTED; AutoTArray<TextRange, 1> ranges; acc->Document()->SelectionRanges(&ranges); uint32_t len = ranges.Length(); for (uint32_t idx = 0; idx < len; idx++) { if (!ranges[idx].Crop(acc)) { ranges.RemoveElementAt(idx); } } *aNRanges = ranges.Length(); *aRanges = static_cast<IA2Range*>( ::CoTaskMemAlloc(sizeof(IA2Range) * *aNRanges)); if (!*aRanges) return E_OUTOFMEMORY; for (uint32_t idx = 0; idx < static_cast<uint32_t>(*aNRanges); idx++) { AccessibleWrap* anchor = static_cast<AccessibleWrap*>(ranges[idx].StartContainer()); (*aRanges)[idx].anchor = static_cast<IAccessible2*>(anchor); anchor->AddRef(); (*aRanges)[idx].anchorOffset = ranges[idx].StartOffset(); AccessibleWrap* active = static_cast<AccessibleWrap*>(ranges[idx].EndContainer()); (*aRanges)[idx].active = static_cast<IAccessible2*>(active); active->AddRef(); (*aRanges)[idx].activeOffset = ranges[idx].EndOffset(); } return S_OK; }
void AudioNodeStream::ObtainInputBlock(AudioBlock& aTmpChunk, uint32_t aPortIndex) { uint32_t inputCount = mInputs.Length(); uint32_t outputChannelCount = 1; AutoTArray<const AudioBlock*,250> inputChunks; for (uint32_t i = 0; i < inputCount; ++i) { if (aPortIndex != mInputs[i]->InputNumber()) { // This input is connected to a different port continue; } MediaStream* s = mInputs[i]->GetSource(); AudioNodeStream* a = static_cast<AudioNodeStream*>(s); MOZ_ASSERT(a == s->AsAudioNodeStream()); if (a->IsAudioParamStream()) { continue; } const AudioBlock* chunk = &a->mLastChunks[mInputs[i]->OutputNumber()]; MOZ_ASSERT(chunk); if (chunk->IsNull() || chunk->mChannelData.IsEmpty()) { continue; } inputChunks.AppendElement(chunk); outputChannelCount = GetAudioChannelsSuperset(outputChannelCount, chunk->ChannelCount()); } outputChannelCount = ComputedNumberOfChannels(outputChannelCount); uint32_t inputChunkCount = inputChunks.Length(); if (inputChunkCount == 0 || (inputChunkCount == 1 && inputChunks[0]->ChannelCount() == 0)) { aTmpChunk.SetNull(WEBAUDIO_BLOCK_SIZE); return; } if (inputChunkCount == 1 && inputChunks[0]->ChannelCount() == outputChannelCount) { aTmpChunk = *inputChunks[0]; return; } if (outputChannelCount == 0) { aTmpChunk.SetNull(WEBAUDIO_BLOCK_SIZE); return; } aTmpChunk.AllocateChannels(outputChannelCount); DownmixBufferType downmixBuffer; ASSERT_ALIGNED16(downmixBuffer.Elements()); for (uint32_t i = 0; i < inputChunkCount; ++i) { AccumulateInputChunk(i, *inputChunks[i], &aTmpChunk, &downmixBuffer); } }
void nsViewManager::ProcessPendingUpdatesForView(nsView* aView, bool aFlushDirtyRegion) { NS_ASSERTION(IsRootVM(), "Updates will be missed"); if (!aView) { return; } nsCOMPtr<nsIPresShell> rootShell(mPresShell); AutoTArray<nsCOMPtr<nsIWidget>, 1> widgets; aView->GetViewManager()->ProcessPendingUpdatesRecurse(aView, widgets); for (uint32_t i = 0; i < widgets.Length(); ++i) { nsView* view = nsView::GetViewFor(widgets[i]); if (view) { if (view->mNeedsWindowPropertiesSync) { view->mNeedsWindowPropertiesSync = false; if (nsViewManager* vm = view->GetViewManager()) { if (nsIPresShell* ps = vm->GetPresShell()) { ps->SyncWindowProperties(view); } } } } view = nsView::GetViewFor(widgets[i]); if (view) { view->ResetWidgetBounds(false, true); } } if (rootShell->GetViewManager() != this) { return; // presentation might have been torn down } if (aFlushDirtyRegion) { nsAutoScriptBlocker scriptBlocker; SetPainting(true); for (uint32_t i = 0; i < widgets.Length(); ++i) { nsIWidget* widget = widgets[i]; nsView* view = nsView::GetViewFor(widget); if (view) { view->GetViewManager()->ProcessPendingUpdatesPaint(widget); } } SetPainting(false); } }
void NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, uint8_t* aBreakBefore) { NS_ASSERTION(aText, "aText shouldn't be null"); int outItems = 0; HRESULT result; AutoTArray<SCRIPT_ITEM, 64> items; char16ptr_t text = aText; memset(aBreakBefore, false, aLength); if (!items.AppendElements(64)) return; do { result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr, items.Elements(), &outItems); if (result == E_OUTOFMEMORY) { if (!items.AppendElements(items.Length())) return; } } while (result == E_OUTOFMEMORY); for (int iItem = 0; iItem < outItems; ++iItem) { uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos); uint32_t startOffset = items[iItem].iCharPos; AutoTArray<SCRIPT_LOGATTR, 64> sla; if (!sla.AppendElements(endOffset - startOffset)) return; if (ScriptBreak(text + startOffset, endOffset - startOffset, &items[iItem].a, sla.Elements()) < 0) return; for (uint32_t j=0; j+startOffset < endOffset; ++j) { aBreakBefore[j+startOffset] = sla[j].fSoftBreak; } } }
void ExtractEmail(const nsCOMArray<msgIAddressObject> &aHeader, nsACString &email) { AutoTArray<nsString, 1> names; AutoTArray<nsString, 1> emails; ExtractAllAddresses(aHeader, names, emails); if (emails.Length() > 0) CopyUTF16toUTF8(emails[0], email); else email.Truncate(); }
NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, uint32_t *aCount, char ***aChildArray) { char **outArray; int32_t numPrefs; int32_t dwIndex; AutoTArray<nsCString, 32> prefArray; NS_ENSURE_ARG(aStartingAt); NS_ENSURE_ARG_POINTER(aCount); NS_ENSURE_ARG_POINTER(aChildArray); *aChildArray = nullptr; *aCount = 0; // this will contain a list of all the pref name strings // allocate on the stack for speed const char* parent = getPrefName(aStartingAt); size_t parentLen = strlen(parent); for (auto iter = gHashTable->Iter(); !iter.Done(); iter.Next()) { auto entry = static_cast<PrefHashEntry*>(iter.Get()); if (strncmp(entry->key, parent, parentLen) == 0) { prefArray.AppendElement(entry->key); } } // now that we've built up the list, run the callback on // all the matching elements numPrefs = prefArray.Length(); if (numPrefs) { outArray = (char **)moz_xmalloc(numPrefs * sizeof(char *)); if (!outArray) return NS_ERROR_OUT_OF_MEMORY; for (dwIndex = 0; dwIndex < numPrefs; ++dwIndex) { // we need to lop off mPrefRoot in case the user is planning to pass this // back to us because if they do we are going to add mPrefRoot again. const nsCString& element = prefArray[dwIndex]; outArray[dwIndex] = (char *)nsMemory::Clone( element.get() + mPrefRootLength, element.Length() - mPrefRootLength + 1); if (!outArray[dwIndex]) { // we ran out of memory... this is annoying NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(dwIndex, outArray); return NS_ERROR_OUT_OF_MEMORY; } } *aChildArray = outArray; } *aCount = numPrefs; return NS_OK; }
int32_t RDFContentSinkImpl::PushContext(nsIRDFResource *aResource, RDFContentSinkState aState, RDFContentSinkParseMode aParseMode) { if (! mContextStack) { mContextStack = new AutoTArray<RDFContextStackElement, 8>(); if (! mContextStack) return 0; } RDFContextStackElement* e = mContextStack->AppendElement(); if (! e) return mContextStack->Length(); e->mResource = aResource; e->mState = aState; e->mParseMode = aParseMode; return mContextStack->Length(); }
/* static */ nsIFrame* nsFontInflationData::FindEdgeInflatableFrameIn(nsIFrame* aFrame, SearchDirection aDirection) { // NOTE: This function has a similar structure to ScanTextIn! // FIXME: Should probably only scan the text that's actually going to // be inflated! nsIFormControlFrame* fcf = do_QueryFrame(aFrame); if (fcf) { return aFrame; } // FIXME: aDirection! AutoTArray<FrameChildList, 4> lists; aFrame->GetChildLists(&lists); for (uint32_t i = 0, len = lists.Length(); i < len; ++i) { const nsFrameList& list = lists[(aDirection == eFromStart) ? i : len - i - 1].mList; for (nsIFrame *kid = (aDirection == eFromStart) ? list.FirstChild() : list.LastChild(); kid; kid = (aDirection == eFromStart) ? kid->GetNextSibling() : kid->GetPrevSibling()) { if (kid->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT) { // Goes in a different set of inflation data. continue; } if (kid->GetType() == nsGkAtoms::textFrame) { nsIContent *content = kid->GetContent(); if (content && kid == content->GetPrimaryFrame()) { uint32_t len = nsTextFrameUtils:: ComputeApproximateLengthWithWhitespaceCompression( content, kid->StyleText()); if (len != 0) { return kid; } } } else { nsIFrame *kidResult = FindEdgeInflatableFrameIn(kid, aDirection); if (kidResult) { return kidResult; } } } } return nullptr; }
void ExtractName(const nsCOMArray<msgIAddressObject> &aHeader, nsAString &name) { AutoTArray<nsString, 1> names; AutoTArray<nsString, 1> emails; ExtractAllAddresses(aHeader, names, emails); if (names.Length() > 0) { if (names[0].IsEmpty()) name = emails[0]; else name = names[0]; } else { name.Truncate(); } }
already_AddRefed<nsIPersistentProperties> ProxyAccessibleWrap::Attributes() { RefPtr<nsPersistentProperties> attributes = new nsPersistentProperties(); nsAutoString unused; AutoTArray<Attribute, 10> attrs; Proxy()->Attributes(&attrs); for (size_t i = 0; i < attrs.Length(); i++) { attributes->SetStringProperty( attrs.ElementAt(i).Name(), attrs.ElementAt(i).Value(), unused); } return attributes.forget(); }