/** * HPI function saHpiSensorEventMasksSet() * * See also the description of the function inside the specification or header file. * Copying the internal reading values (if a read is allowed). * * @param act address of variable which includes the action to be done * @param AssertEventMask address of variable which include new assertion mask data * @param DeassertEventMask address of variable which include new deassertion mask data * * @return HPI return code **/ SaErrorT NewSimulatorSensor::SetEventMasks( const SaHpiSensorEventMaskActionT &act, SaHpiEventStateT &AssertEventMask, SaHpiEventStateT &DeassertEventMask ) { if ( EventCtrl() != SAHPI_SEC_PER_EVENT ) return SA_ERR_HPI_READ_ONLY; if ( AssertEventMask == SAHPI_ALL_EVENT_STATES ) AssertEventMask = EventStates(); if ( DeassertEventMask == SAHPI_ALL_EVENT_STATES ) DeassertEventMask = EventStates(); if ( act == SAHPI_SENS_ADD_EVENTS_TO_MASKS ) { if ((( AssertEventMask & ~EventStates() ) != 0 ) || (( DeassertEventMask & ~EventStates() ) != 0 )) return SA_ERR_HPI_INVALID_DATA; } SaHpiEventStateT save_assert_mask = m_assert_mask; SaHpiEventStateT save_deassert_mask = m_deassert_mask; if ( act == SAHPI_SENS_ADD_EVENTS_TO_MASKS ) { m_assert_mask |= AssertEventMask; m_deassert_mask |= DeassertEventMask; } else if ( act == SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS ) { m_assert_mask &= (AssertEventMask ^ SAHPI_ALL_EVENT_STATES); m_deassert_mask &= (DeassertEventMask ^ SAHPI_ALL_EVENT_STATES); } else return SA_ERR_HPI_INVALID_PARAMS; stdlog << "SetEventMasks sensor " << m_sensor_record.Num << " assert " << m_assert_mask << " deassert " << m_deassert_mask << "\n"; if (( save_assert_mask == m_assert_mask ) && ( save_deassert_mask == m_deassert_mask )) return SA_OK; CreateEnableChangeEvent(); return SA_OK; }
static nsIFrame* GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame, const nsRect& aTargetRect, const EventRadiusPrefs* aPrefs, nsIFrame* aRestrictToDescendants, nsTArray<nsIFrame*>& aCandidates) { nsIFrame* bestTarget = nullptr; // Lower is better; distance is in appunits float bestDistance = 1e6f; nsRegion exposedRegion(aTargetRect); for (uint32_t i = 0; i < aCandidates.Length(); ++i) { nsIFrame* f = aCandidates[i]; bool preservesAxisAlignedRectangles = false; nsRect borderBox = nsLayoutUtils::TransformFrameRectToAncestor(f, nsRect(nsPoint(0, 0), f->GetSize()), aRoot, &preservesAxisAlignedRectangles); nsRegion region; region.And(exposedRegion, borderBox); if (region.IsEmpty()) { continue; } if (preservesAxisAlignedRectangles) { // Subtract from the exposed region if we have a transform that won't make // the bounds include a bunch of area that we don't actually cover. SubtractFromExposedRegion(&exposedRegion, region); } if (!IsElementClickable(f)) { continue; } // If our current closest frame is a descendant of 'f', skip 'f' (prefer // the nested frame). if (bestTarget && nsLayoutUtils::IsProperAncestorFrameCrossDoc(f, bestTarget, aRoot)) { continue; } if (!nsLayoutUtils::IsAncestorFrameCrossDoc(aRestrictToDescendants, f, aRoot)) { continue; } // distance is in appunits float distance = ComputeDistanceFromRegion(aPointRelativeToRootFrame, region); nsIContent* content = f->GetContent(); if (content && content->IsElement() && content->AsElement()->State().HasState( EventStates(NS_EVENT_STATE_VISITED))) { distance *= aPrefs->mVisitedWeight / 100.0f; } if (distance < bestDistance) { bestDistance = distance; bestTarget = f; } } return bestTarget; }
void Link::ResetLinkState(bool aNotify, bool aHasHref) { nsLinkState defaultState; // The default state for links with an href is unvisited. if (aHasHref) { defaultState = eLinkState_Unvisited; } else { defaultState = eLinkState_NotLink; } // If !mNeedsRegstration, then either we've never registered, or we're // currently registered; in either case, we should remove ourself // from the doc and the history. if (!mNeedsRegistration && mLinkState != eLinkState_NotLink) { nsIDocument *doc = mElement->GetComposedDoc(); if (doc && (mRegistered || mLinkState == eLinkState_Visited)) { // Tell the document to forget about this link if we've registered // with it before. doc->ForgetLink(this); } UnregisterFromHistory(); } // If we have an href, we should register with the history. mNeedsRegistration = aHasHref; // If we've cached the URI, reset always invalidates it. mCachedURI = nullptr; UpdateURLSearchParams(); // Update our state back to the default. mLinkState = defaultState; // We have to be very careful here: if aNotify is false we do NOT // want to call UpdateState, because that will call into LinkState() // and try to start off loads, etc. But ResetLinkState is called // with aNotify false when things are in inconsistent states, so // we'll get confused in that situation. Instead, just silently // update the link state on mElement. Since we might have set the // link state to unvisited, make sure to update with that state if // required. if (aNotify) { mElement->UpdateState(aNotify); } else { if (mLinkState == eLinkState_Unvisited) { mElement->UpdateLinkState(NS_EVENT_STATE_UNVISITED); } else { mElement->UpdateLinkState(EventStates()); } } }
EventStates Link::LinkState() const { // We are a constant method, but we are just lazily doing things and have to // track that state. Cast away that constness! Link *self = const_cast<Link *>(this); Element *element = self->mElement; // If we have not yet registered for notifications and need to, // due to our href changing, register now! if (!mRegistered && mNeedsRegistration && element->IsInComposedDoc()) { // Only try and register once. self->mNeedsRegistration = false; nsCOMPtr<nsIURI> hrefURI(GetURI()); // Assume that we are not visited until we are told otherwise. self->mLinkState = eLinkState_Unvisited; // Make sure the href attribute has a valid link (bug 23209). // If we have a good href, register with History if available. if (mHistory && hrefURI) { nsresult rv = mHistory->RegisterVisitedCallback(hrefURI, self); if (NS_SUCCEEDED(rv)) { self->mRegistered = true; // And make sure we are in the document's link map. element->GetComposedDoc()->AddStyleRelevantLink(self); } } } // Otherwise, return our known state. if (mLinkState == eLinkState_Visited) { return NS_EVENT_STATE_VISITED; } if (mLinkState == eLinkState_Unvisited) { return NS_EVENT_STATE_UNVISITED; } return EventStates(); }
static nsIFrame* GetClosest(nsIFrame* aRoot, const nsPoint& aPointRelativeToRootFrame, const nsRect& aTargetRect, const EventRadiusPrefs* aPrefs, nsIFrame* aRestrictToDescendants, nsIContent* aClickableAncestor, nsTArray<nsIFrame*>& aCandidates, int32_t* aElementsInCluster) { std::vector<nsIContent*> mContentsInCluster; // List of content elements in the cluster without duplicate nsIFrame* bestTarget = nullptr; // Lower is better; distance is in appunits float bestDistance = 1e6f; nsRegion exposedRegion(aTargetRect); for (uint32_t i = 0; i < aCandidates.Length(); ++i) { nsIFrame* f = aCandidates[i]; PET_LOG("Checking candidate %p\n", f); bool preservesAxisAlignedRectangles = false; nsRect borderBox = nsLayoutUtils::TransformFrameRectToAncestor(f, nsRect(nsPoint(0, 0), f->GetSize()), aRoot, &preservesAxisAlignedRectangles); nsRegion region; region.And(exposedRegion, borderBox); if (region.IsEmpty()) { PET_LOG(" candidate %p had empty hit region\n", f); continue; } if (preservesAxisAlignedRectangles) { // Subtract from the exposed region if we have a transform that won't make // the bounds include a bunch of area that we don't actually cover. SubtractFromExposedRegion(&exposedRegion, region); } nsAutoString labelTargetId; if (aClickableAncestor && !IsDescendant(f, aClickableAncestor, &labelTargetId)) { PET_LOG(" candidate %p is not a descendant of required ancestor\n", f); continue; } nsIContent* clickableContent = GetClickableAncestor(f, nsGkAtoms::body, &labelTargetId); if (!aClickableAncestor && !clickableContent) { PET_LOG(" candidate %p was not clickable\n", f); continue; } // If our current closest frame is a descendant of 'f', skip 'f' (prefer // the nested frame). if (bestTarget && nsLayoutUtils::IsProperAncestorFrameCrossDoc(f, bestTarget, aRoot)) { PET_LOG(" candidate %p was ancestor for bestTarget %p\n", f, bestTarget); continue; } if (!aClickableAncestor && !nsLayoutUtils::IsAncestorFrameCrossDoc(aRestrictToDescendants, f, aRoot)) { PET_LOG(" candidate %p was not descendant of restrictroot %p\n", f, aRestrictToDescendants); continue; } // If the first clickable ancestor of f is a label element // and "for" attribute is present in label element, search the frame list for the "for" element // If this element is present in the current list, do not count the frame in // the cluster elements counter if ((labelTargetId.IsEmpty() || !IsElementPresent(aCandidates, labelTargetId)) && !IsLargeElement(f, aPrefs)) { if (std::find(mContentsInCluster.begin(), mContentsInCluster.end(), clickableContent) == mContentsInCluster.end()) { mContentsInCluster.push_back(clickableContent); } } // distance is in appunits float distance = ComputeDistanceFromRegion(aPointRelativeToRootFrame, region); nsIContent* content = f->GetContent(); if (content && content->IsElement() && content->AsElement()->State().HasState( EventStates(NS_EVENT_STATE_VISITED))) { distance *= aPrefs->mVisitedWeight / 100.0f; } if (distance < bestDistance) { PET_LOG(" candidate %p is the new best\n", f); bestDistance = distance; bestTarget = f; } } *aElementsInCluster = mContentsInCluster.size(); return bestTarget; }