void nsListBoxBodyFrame::GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, PRInt32& aSiblingIndex) { *aContent = nsnull; aSiblingIndex = -1; nsIContent* listboxContent = mContent->GetBindingParent(); ENSURE_TRUE(listboxContent); PRUint32 childCount = listboxContent->GetChildCount(); nsIContent *prevKid = nsnull; for (PRUint32 i = 0; i < childCount; ++i) { nsIContent *kid = listboxContent->GetChildAt(i); if (kid->Tag() == nsGkAtoms::listitem) { ++aSiblingIndex; if (prevKid == aListItem) { *aContent = kid; NS_IF_ADDREF(*aContent); return; } } prevKid = kid; } aSiblingIndex = -1; // no match, so there is no next sibling }
void nsMenuFrame::UpdateMenuType(nsPresContext* aPresContext) { static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::checkbox, &nsGkAtoms::radio, nsnull}; switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type, strings, eCaseMatters)) { case 0: mType = eMenuType_Checkbox; break; case 1: mType = eMenuType_Radio; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, mGroupName); break; default: if (mType != eMenuType_Normal) { nsWeakFrame weakFrame(this); mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::checked, PR_TRUE); ENSURE_TRUE(weakFrame.IsAlive()); } mType = eMenuType_Normal; break; } UpdateMenuSpecialState(aPresContext); }
void nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot) { ENSURE_TRUE(mContent); // Remove the drag events if (mContent) { mContent->RemoveSystemEventListener(NS_LITERAL_STRING("drop"), mMouseListener, false); mContent->RemoveSystemEventListener(NS_LITERAL_STRING("dragover"), mMouseListener, false); } // remove mMouseListener as a mouse event listener (bug 40533, bug 355931) nsContentUtils::DestroyAnonymousContent(&mCapture); if (mBrowse) { mBrowse->RemoveSystemEventListener(NS_LITERAL_STRING("click"), mMouseListener, false); } nsContentUtils::DestroyAnonymousContent(&mBrowse); if (mTextContent) { mTextContent->RemoveSystemEventListener(NS_LITERAL_STRING("click"), mMouseListener, false); } nsContentUtils::DestroyAnonymousContent(&mTextContent); mCaptureMouseListener->ForgetFrame(); mMouseListener->ForgetFrame(); nsBlockFrame::DestroyFrom(aDestructRoot); }
/** \brief Construct the BDD that represent all hitting sets from a ZDD. * \param f ZDD * \return The contructed BDD * \see hit_z2b_rec */ bddp hit_z2b(zddp f) { my_hash *h = ht_create(0); ENSURE_TRUE_MSG(h != NULL, "hash table creation failed"); #ifdef SIZE_LOG char str[BUFSIZ]; snprintf(str, BUFSIZ, "%s-hit.log", g_basename); sizelog = fopen(str, "w"); ENSURE_TRUE_MSG(sizelog != NULL, "file open failed"); maxsize = 0; #endif /*SIZE_LOG*/ assert(recdepth == 0); bddp r = hit_z2b_rec(f, h); ENSURE_TRUE(r != BDD_NULL); assert(recdepth == 0); #ifdef SIZE_LOG fclose(sizelog); printf("max|bdd|\t%ju\n", maxsize); #endif /*SIZE_LOG*/ ht_destroy(h); return r; }
void nsFileControlFrame::Destroy() { mTextFrame = nsnull; ENSURE_TRUE(mContent); // remove mMouseListener as a mouse event listener (bug 40533, bug 355931) NS_NAMED_LITERAL_STRING(click, "click"); nsCOMPtr<nsIDOMEventGroup> systemGroup; mContent->GetSystemEventGroup(getter_AddRefs(systemGroup)); nsCOMPtr<nsIDOM3EventTarget> dom3Browse = do_QueryInterface(mBrowse); if (dom3Browse) { dom3Browse->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, systemGroup); nsContentUtils::DestroyAnonymousContent(&mBrowse); } nsCOMPtr<nsIDOM3EventTarget> dom3TextContent = do_QueryInterface(mTextContent); if (dom3TextContent) { dom3TextContent->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, systemGroup); nsContentUtils::DestroyAnonymousContent(&mTextContent); } mMouseListener->ForgetFrame(); nsAreaFrame::Destroy(); }
uint64_t GenNewUniqueTaskId() { TraceInfo* info = GetOrCreateTraceInfo(); ENSURE_TRUE(info, 0); pid_t tid = gettid(); uint64_t taskid = ((uint64_t)tid << 32) | ++info->mLastUniqueTaskId; return taskid; }
TraceInfo* GetOrCreateTraceInfo() { ENSURE_TRUE(sTraceInfoTLS.initialized(), nullptr); ENSURE_TRUE(IsStartLogging(), nullptr); TraceInfo* info = sTraceInfoTLS.get(); if (info && info->mObsolete) { // TraceInfo is obsolete: remove it. FreeTraceInfo(info); info = nullptr; } if (!info) { info = AllocTraceInfo(gettid()); sTraceInfoTLS.set(info); } return info; }
void nsSplitterFrameInner::RemoveListener() { ENSURE_TRUE(mOuter); mOuter->GetContent()-> RemoveEventListenerByIID(static_cast<nsIDOMMouseListener*>(this), NS_GET_IID(nsIDOMMouseListener)); mOuter->GetContent()-> RemoveEventListenerByIID(static_cast<nsIDOMMouseMotionListener*>(this), NS_GET_IID(nsIDOMMouseMotionListener)); }
void nsSplitterFrameInner::SetPreferredSize(nsBoxLayoutState& aState, nsIBox* aChildBox, nscoord aOnePixel, PRBool aIsHorizontal, nscoord* aSize) { //printf("current=%d, pref=%d", current/onePixel, pref/onePixel); nscoord current = 0; nsRect rect(aChildBox->GetRect()); if (aIsHorizontal) current = rect.width; else current = rect.height; nscoord pref = 0; if (!aSize) { if (aIsHorizontal) pref = rect.width; else pref = rect.height; } else { pref = *aSize; } nsMargin margin(0,0,0,0); aChildBox->GetMargin(margin); nsCOMPtr<nsIAtom> attribute; if (aIsHorizontal) { pref -= (margin.left + margin.right); attribute = nsGkAtoms::width; } else { pref -= (margin.top + margin.bottom); attribute = nsGkAtoms::height; } nsIContent* content = aChildBox->GetContent(); // set its preferred size. nsAutoString prefValue; prefValue.AppendInt(pref/aOnePixel); if (content->AttrValueIs(kNameSpaceID_None, attribute, prefValue, eCaseMatters)) return; nsWeakFrame weakBox(aChildBox); content->SetAttr(kNameSpaceID_None, attribute, prefValue, PR_TRUE); ENSURE_TRUE(weakBox.IsAlive()); aState.PresShell()->FrameNeedsReflow(aChildBox, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY); }
void nsSplitterFrameInner::RemoveListener() { ENSURE_TRUE(mOuter); mOuter->GetContent()-> RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, false); mOuter->GetContent()-> RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, false); mOuter->GetContent()-> RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, false); mOuter->GetContent()-> RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, false); }
/** \brief Construct the ZDD that represents all minimal hitting sets for a ZDD. * \param f ZDD * \return The contructed ZDD * \see minhit_nonsup_rec, nonsup * \note pp.669-670 in "The Art of Computer Programming, Volume 4a (2011)" by Knuth */ zddp minhit_nonsup(zddp f) { my_hash *h = ht_create(0); ENSURE_TRUE_MSG(h != NULL, "hash table creation failed"); assert(recdepth == 0); zddp r = minhit_nonsup_rec(f, h); ENSURE_TRUE(r != BDD_NULL); assert(recdepth == 0); ht_destroy(h); return r; }
void nsListBoxBodyFrame::ComputeTotalRowCount() { mRowCount = 0; nsIContent* listbox = mContent->GetBindingParent(); ENSURE_TRUE(listbox); PRUint32 childCount = listbox->GetChildCount(); for (PRUint32 i = 0; i < childCount; i++) { if (listbox->GetChildAt(i)->Tag() == nsGkAtoms::listitem) ++mRowCount; } }
void nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot) { mTextFrame = nsnull; ENSURE_TRUE(mContent); // Remove the drag events nsCOMPtr<nsIDOMEventTarget> dragTarget = do_QueryInterface(mContent); if (dragTarget) { dragTarget->RemoveEventListener(NS_LITERAL_STRING("drop"), mMouseListener, PR_FALSE); dragTarget->RemoveEventListener(NS_LITERAL_STRING("dragover"), mMouseListener, PR_FALSE); } // remove mMouseListener as a mouse event listener (bug 40533, bug 355931) NS_NAMED_LITERAL_STRING(click, "click"); nsCOMPtr<nsIDOMEventGroup> systemGroup; mContent->GetSystemEventGroup(getter_AddRefs(systemGroup)); nsCOMPtr<nsIDOM3EventTarget> dom3Capture = do_QueryInterface(mCapture); if (dom3Capture) { nsContentUtils::DestroyAnonymousContent(&mCapture); } nsCOMPtr<nsIDOM3EventTarget> dom3Browse = do_QueryInterface(mBrowse); if (dom3Browse) { dom3Browse->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, systemGroup); nsContentUtils::DestroyAnonymousContent(&mBrowse); } nsCOMPtr<nsIDOM3EventTarget> dom3TextContent = do_QueryInterface(mTextContent); if (dom3TextContent) { dom3TextContent->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE, systemGroup); nsContentUtils::DestroyAnonymousContent(&mTextContent); } mCaptureMouseListener->ForgetFrame(); mMouseListener->ForgetFrame(); nsBlockFrame::DestroyFrom(aDestructRoot); }
void nsListBoxBodyFrame::GetListItemContentAt(PRInt32 aIndex, nsIContent** aContent) { *aContent = nsnull; nsIContent* listboxContent = mContent->GetBindingParent(); ENSURE_TRUE(listboxContent); PRUint32 childCount = listboxContent->GetChildCount(); PRInt32 itemsFound = 0; for (PRUint32 i = 0; i < childCount; ++i) { nsIContent *kid = listboxContent->GetChildAt(i); if (kid->Tag() == nsGkAtoms::listitem) { ++itemsFound; if (itemsFound-1 == aIndex) { *aContent = kid; NS_IF_ADDREF(*aContent); return; } } } }
void nsMenuFrame::BuildAcceleratorText() { nsAutoString accelText; if ((GetStateBits() & NS_STATE_ACCELTEXT_IS_DERIVED) == 0) { mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accelText); if (!accelText.IsEmpty()) return; } // accelText is definitely empty here. // Now we're going to compute the accelerator text, so remember that we did. AddStateBits(NS_STATE_ACCELTEXT_IS_DERIVED); // If anything below fails, just leave the accelerator text blank. nsWeakFrame weakFrame(this); mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, PR_FALSE); ENSURE_TRUE(weakFrame.IsAlive()); // See if we have a key node and use that instead. nsAutoString keyValue; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyValue); if (keyValue.IsEmpty()) return; // Turn the document into a DOM document so we can use getElementById nsIDocument *document = mContent->GetDocument(); if (!document) return; nsIContent *keyElement = document->GetElementById(keyValue); if (!keyElement) { #ifdef DEBUG nsAutoString label; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, label); nsAutoString msg = NS_LITERAL_STRING("Key '") + keyValue + NS_LITERAL_STRING("' of menu item '") + label + NS_LITERAL_STRING("' could not be found"); NS_WARNING(NS_ConvertUTF16toUTF8(msg).get()); #endif return; } // get the string to display as accelerator text // check the key element's attributes in this order: // |keytext|, |key|, |keycode| nsAutoString accelString; keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::keytext, accelString); if (accelString.IsEmpty()) { keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::key, accelString); if (!accelString.IsEmpty()) { ToUpperCase(accelString); } else { nsAutoString keyCode; keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, keyCode); ToUpperCase(keyCode); nsresult rv; nsCOMPtr<nsIStringBundleService> bundleService = mozilla::services::GetStringBundleService(); if (bundleService) { nsCOMPtr<nsIStringBundle> bundle; rv = bundleService->CreateBundle("chrome://global/locale/keys.properties", getter_AddRefs(bundle)); if (NS_SUCCEEDED(rv) && bundle) { nsXPIDLString keyName; rv = bundle->GetStringFromName(keyCode.get(), getter_Copies(keyName)); if (keyName) accelString = keyName; } } // nothing usable found, bail if (accelString.IsEmpty()) return; } } static PRInt32 accelKey = 0; if (!accelKey) { // Compiled-in defaults, in case we can't get LookAndFeel -- // command for mac, control for all other platforms. #ifdef XP_MACOSX accelKey = nsIDOMKeyEvent::DOM_VK_META; #else accelKey = nsIDOMKeyEvent::DOM_VK_CONTROL; #endif // Get the accelerator key value from prefs, overriding the default: accelKey = nsContentUtils::GetIntPref("ui.key.accelKey", accelKey); } nsAutoString modifiers; keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiers); char* str = ToNewCString(modifiers); char* newStr; char* token = nsCRT::strtok(str, ", \t", &newStr); while (token) { if (PL_strcmp(token, "shift") == 0) accelText += *gShiftText; else if (PL_strcmp(token, "alt") == 0) accelText += *gAltText; else if (PL_strcmp(token, "meta") == 0) accelText += *gMetaText; else if (PL_strcmp(token, "control") == 0) accelText += *gControlText; else if (PL_strcmp(token, "accel") == 0) { switch (accelKey) { case nsIDOMKeyEvent::DOM_VK_META: accelText += *gMetaText; break; case nsIDOMKeyEvent::DOM_VK_ALT: accelText += *gAltText; break; case nsIDOMKeyEvent::DOM_VK_CONTROL: default: accelText += *gControlText; break; } } accelText += *gModifierSeparator; token = nsCRT::strtok(newStr, ", \t", &newStr); } nsMemory::Free(str); accelText += accelString; mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accelText, PR_FALSE); }
// Special handing is needed around ReturnOutput as it spins the IPC message // queue when creating an empty frame and can end up with reentrant calls into // the class methods. bool WidevineVideoDecoder::ReturnOutput(WidevineVideoFrame& aCDMFrame) { MOZ_ASSERT(mReturnOutputCallDepth >= 0); CounterHelper counterHelper(mReturnOutputCallDepth); mFrameAllocationQueue.push_back(Move(aCDMFrame)); if (mReturnOutputCallDepth > 1) { // In a reentrant call. return true; } while (!mFrameAllocationQueue.empty()) { MOZ_ASSERT(mReturnOutputCallDepth == 1); // If we're at call level 1 a reset should not have been started. A // reset may be received during CreateEmptyFrame below, but we should not // be in a reset at this stage -- this would indicate receiving decode // messages before completing our reset, which we should not. MOZ_ASSERT(!mResetInProgress); WidevineVideoFrame currentCDMFrame = Move(mFrameAllocationQueue.front()); mFrameAllocationQueue.pop_front(); GMPVideoFrame* f = nullptr; auto err = mVideoHost->CreateFrame(kGMPI420VideoFrame, &f); if (GMP_FAILED(err) || !f) { Log("Failed to create i420 frame!\n"); return false; } auto gmpFrame = static_cast<GMPVideoi420Frame*>(f); FrameDestroyerHelper frameDestroyerHelper(gmpFrame); Size size = currentCDMFrame.Size(); const int32_t yStride = currentCDMFrame.Stride(VideoFrame::kYPlane); const int32_t uStride = currentCDMFrame.Stride(VideoFrame::kUPlane); const int32_t vStride = currentCDMFrame.Stride(VideoFrame::kVPlane); const int32_t halfHeight = size.height / 2; // This call can cause a shmem alloc, during this alloc other calls // may be made to this class and placed on the stack. ***WARNING***: // other IPC calls can happen during this call, resulting in calls // being made to the CDM. After this call state can have changed, // and should be reevaluated. err = gmpFrame->CreateEmptyFrame(size.width, size.height, yStride, uStride, vStride); // Assert possible reentrant calls or resets haven't altered level unexpectedly. MOZ_ASSERT(mReturnOutputCallDepth == 1); ENSURE_GMP_SUCCESS(err, false); // If a reset started we need to dump the current frame and complete the reset. if (mResetInProgress) { MOZ_ASSERT(mCDMWrapper); MOZ_ASSERT(mFrameAllocationQueue.empty()); CompleteReset(); return true; } err = gmpFrame->SetWidth(size.width); ENSURE_GMP_SUCCESS(err, false); err = gmpFrame->SetHeight(size.height); ENSURE_GMP_SUCCESS(err, false); Buffer* buffer = currentCDMFrame.FrameBuffer(); uint8_t* outBuffer = gmpFrame->Buffer(kGMPYPlane); ENSURE_TRUE(outBuffer != nullptr, false); MOZ_ASSERT(gmpFrame->AllocatedSize(kGMPYPlane) >= yStride*size.height); memcpy(outBuffer, buffer->Data() + currentCDMFrame.PlaneOffset(VideoFrame::kYPlane), yStride * size.height); outBuffer = gmpFrame->Buffer(kGMPUPlane); ENSURE_TRUE(outBuffer != nullptr, false); MOZ_ASSERT(gmpFrame->AllocatedSize(kGMPUPlane) >= uStride * halfHeight); memcpy(outBuffer, buffer->Data() + currentCDMFrame.PlaneOffset(VideoFrame::kUPlane), uStride * halfHeight); outBuffer = gmpFrame->Buffer(kGMPVPlane); ENSURE_TRUE(outBuffer != nullptr, false); MOZ_ASSERT(gmpFrame->AllocatedSize(kGMPVPlane) >= vStride * halfHeight); memcpy(outBuffer, buffer->Data() + currentCDMFrame.PlaneOffset(VideoFrame::kVPlane), vStride * halfHeight); gmpFrame->SetTimestamp(currentCDMFrame.Timestamp()); auto d = mFrameDurations.find(currentCDMFrame.Timestamp()); if (d != mFrameDurations.end()) { gmpFrame->SetDuration(d->second); mFrameDurations.erase(d); } // Forget frame so it's not deleted, call back taking ownership. frameDestroyerHelper.ForgetFrame(); mCallback->Decoded(gmpFrame); } return true; }