Maybe<int32_t> SVGTextContentElement::GetNonLayoutDependentNumberOfChars() { SVGTextFrame* frame = GetSVGTextFrameForNonLayoutDependentQuery(); if (!frame || frame != GetPrimaryFrame()) { // Only support this fast path on <text>, not child <tspan>s, etc. return Some(0); } uint32_t num = 0; for (nsINode* n = Element::GetFirstChild(); n; n = n->GetNextSibling()) { if (!n->IsNodeOfType(nsINode::eTEXT)) { return Nothing(); } const nsTextFragment* text = static_cast<nsTextNode*>(n)->GetText(); uint32_t length = text->GetLength(); if (text->Is2b()) { if (FragmentHasSkippableCharacter(text->Get2b(), length)) { return Nothing(); } } else { auto buffer = reinterpret_cast<const uint8_t*>(text->Get1b()); if (FragmentHasSkippableCharacter(buffer, length)) { return Nothing(); } } num += length; } return Some(num); }
void ImageDocument::UpdateSizeFromLayout() { // Pull an updated size from the content frame to account for any size // change due to CSS properties like |image-orientation|. if (!mImageContent) { return; } nsIFrame* contentFrame = mImageContent->GetPrimaryFrame(FlushType::Frames); if (!contentFrame) { return; } nsIntSize oldSize(mImageWidth, mImageHeight); IntrinsicSize newSize = contentFrame->GetIntrinsicSize(); if (newSize.width.GetUnit() == eStyleUnit_Coord) { mImageWidth = nsPresContext::AppUnitsToFloatCSSPixels(newSize.width.GetCoordValue()); } if (newSize.height.GetUnit() == eStyleUnit_Coord) { mImageHeight = nsPresContext::AppUnitsToFloatCSSPixels(newSize.height.GetCoordValue()); } // Ensure that our information about overflow is up-to-date if needed. if (mImageWidth != oldSize.width || mImageHeight != oldSize.height) { CheckOverflowing(false); } }
NS_IMETHODIMP HTMLObjectElement::SubmitNamesValues(nsFormSubmission *aFormSubmission) { nsAutoString name; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::name, name)) { // No name, don't submit. return NS_OK; } nsIFrame* frame = GetPrimaryFrame(); nsIObjectFrame *objFrame = do_QueryFrame(frame); if (!objFrame) { // No frame, nothing to submit. return NS_OK; } nsRefPtr<nsNPAPIPluginInstance> pi; objFrame->GetPluginInstance(getter_AddRefs(pi)); if (!pi) return NS_OK; nsAutoString value; nsresult rv = pi->GetFormValue(value); NS_ENSURE_SUCCESS(rv, rv); return aFormSubmission->AddNameValuePair(name, value); }
void HTMLLegendElement::Focus(ErrorResult& aError) { nsIFrame* frame = GetPrimaryFrame(); if (!frame) { return; } int32_t tabIndex; if (frame->IsFocusable(&tabIndex, false)) { nsGenericHTMLElement::Focus(aError); return; } // If the legend isn't focusable, focus whatever is focusable following // the legend instead, bug 81481. nsIFocusManager* fm = nsFocusManager::GetFocusManager(); if (!fm) { return; } nsCOMPtr<nsIDOMElement> result; aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD, nsIFocusManager::FLAG_NOPARENTFRAME, getter_AddRefs(result)); }
void nsHTMLTextAreaElement::GetValueInternal(nsAString& aValue, PRBool aIgnoreWrap) { // Get the frame. // No need to flush here, if there is no frame yet for this textarea // there won't be a value in it we don't already have even if we // force the frame to be created. nsIFrame* primaryFrame = GetPrimaryFrame(); nsITextControlFrame* textControlFrame = nsnull; if (primaryFrame) { textControlFrame = do_QueryFrame(primaryFrame); } // If the frame exists and owns the value, get it from the frame. Otherwise // get it from content. PRBool frameOwnsValue = PR_FALSE; if (textControlFrame) { textControlFrame->OwnsValue(&frameOwnsValue); } if (frameOwnsValue) { textControlFrame->GetValue(aValue, aIgnoreWrap); } else { if (!mValueChanged || !mValue) { GetDefaultValue(aValue); } else { CopyUTF8toUTF16(mValue, aValue); } } }
SVGTextFrame* SVGTextContentElement::GetSVGTextFrameForNonLayoutDependentQuery() { nsIFrame* frame = GetPrimaryFrame(FlushType::Frames); nsIFrame* textFrame = nsLayoutUtils::GetClosestFrameOfType(frame, nsGkAtoms::svgTextFrame); return static_cast<SVGTextFrame*>(textFrame); }
nsresult nsHTMLTextAreaElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) { // Do not process any DOM events if the element is disabled aVisitor.mCanHandle = PR_FALSE; PRBool disabled; nsresult rv = GetDisabled(&disabled); if (NS_FAILED(rv) || disabled) { return rv; } nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE); nsIFrame* formFrame = nsnull; if (formControlFrame && (formFrame = do_QueryFrame(formControlFrame))) { const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface(); if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) { return NS_OK; } } // Don't dispatch a second select event if we are already handling // one. if (aVisitor.mEvent->message == NS_FORM_SELECTED) { if (mHandlingSelect) { return NS_OK; } mHandlingSelect = PR_TRUE; } // If NS_EVENT_FLAG_NO_CONTENT_DISPATCH is set we will not allow content to handle // this event. But to allow middle mouse button paste to work we must allow // middle clicks to go to text fields anyway. if (aVisitor.mEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH) aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH; if (aVisitor.mEvent->message == NS_MOUSE_CLICK && aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && static_cast<nsMouseEvent*>(aVisitor.mEvent)->button == nsMouseEvent::eMiddleButton) { aVisitor.mEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH; } // Fire onchange (if necessary), before we do the blur, bug 370521. if (aVisitor.mEvent->message == NS_BLUR_CONTENT) { nsIFrame* primaryFrame = GetPrimaryFrame(); if (primaryFrame) { nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame); if (textFrame) { textFrame->CheckFireOnChange(); } } } return nsGenericHTMLFormElement::PreHandleEvent(aVisitor); }
void nsSVGFilterElement::DidAnimateEnum(PRUint8 aAttrEnum) { // nsSVGFilterFrame does not implement a useful AttributeChanged nsIFrame* frame = GetPrimaryFrame(); if (frame) { nsSVGEffects::InvalidateRenderingObservers(frame); } }
CSSIntPoint HTMLImageElement::GetXY() { nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame) { return CSSIntPoint(0, 0); } nsIFrame* layer = nsLayoutUtils::GetClosestLayer(frame->GetParent()); return CSSIntPoint::FromAppUnitsRounded(frame->GetOffsetTo(layer)); }
void nsSVGGradientElement::DidAnimateTransform() { nsIFrame* frame = GetPrimaryFrame(); if (frame) { frame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::gradientTransform, nsIDOMMutationEvent::MODIFICATION); } }
void nsSVGElement::DidAnimateLength(PRUint8 aAttrEnum) { nsIFrame* frame = GetPrimaryFrame(); if (frame) { LengthAttributesInfo info = GetLengthInfo(); frame->AttributeChanged(kNameSpaceID_None, *info.mLengthInfo[aAttrEnum].mName, nsIDOMMutationEvent::MODIFICATION); } }
nsresult SVGFEImageElement::Filter(nsSVGFilterInstance *instance, const nsTArray<const Image*>& aSources, const Image* aTarget, const nsIntRect& rect) { nsIFrame* frame = GetPrimaryFrame(); if (!frame) return NS_ERROR_FAILURE; nsCOMPtr<imgIRequest> currentRequest; GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, getter_AddRefs(currentRequest)); nsCOMPtr<imgIContainer> imageContainer; if (currentRequest) currentRequest->GetImage(getter_AddRefs(imageContainer)); nsRefPtr<gfxASurface> currentFrame; if (imageContainer) imageContainer->GetFrame(imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE, getter_AddRefs(currentFrame)); // We need to wrap the surface in a pattern to have somewhere to set the // graphics filter. nsRefPtr<gfxPattern> thebesPattern; if (currentFrame) thebesPattern = new gfxPattern(currentFrame); if (thebesPattern) { thebesPattern->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(frame)); int32_t nativeWidth, nativeHeight; imageContainer->GetWidth(&nativeWidth); imageContainer->GetHeight(&nativeHeight); const gfxRect& filterSubregion = aTarget->mFilterPrimitiveSubregion; gfxMatrix viewBoxTM = SVGContentUtils::GetViewBoxTransform(filterSubregion.Width(), filterSubregion.Height(), 0,0, nativeWidth, nativeHeight, mPreserveAspectRatio); gfxMatrix xyTM = gfxMatrix().Translate(gfxPoint(filterSubregion.X(), filterSubregion.Y())); gfxMatrix TM = viewBoxTM * xyTM; nsRefPtr<gfxContext> ctx = new gfxContext(aTarget->mImage); nsSVGUtils::CompositePatternMatrix(ctx, thebesPattern, TM, nativeWidth, nativeHeight, 1.0); } return NS_OK; }
already_AddRefed<nsISVGTextContentMetrics> nsSVGTextPathElement::GetTextContentMetrics() { nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame) { return nsnull; } nsISVGTextContentMetrics* metrics; CallQueryInterface(frame, &metrics); return metrics; }
nsSVGTextFrame2* SVGTextContentElement::GetSVGTextFrame() { nsIFrame* frame = GetPrimaryFrame(Flush_Layout); while (frame) { nsSVGTextFrame2* textFrame = do_QueryFrame(frame); if (textFrame) { return textFrame; } frame = frame->GetParent(); } return nullptr; }
void nsSVGPatternElement::PushUpdate() { nsIFrame *frame = GetPrimaryFrame(); if (frame) { nsISVGValue *value = nsnull; CallQueryInterface(frame, &value); if (value) { value->BeginBatchUpdate(); value->EndBatchUpdate(); } } }
void TextTrackManager::UpdateCueDisplay() { WEBVTT_LOG("UpdateCueDisplay"); mUpdateCueDisplayDispatched = false; if (!mMediaElement || !mTextTracks) { return; } nsIFrame* frame = mMediaElement->GetPrimaryFrame(); nsVideoFrame* videoFrame = do_QueryFrame(frame); if (!videoFrame) { return; } nsCOMPtr<nsIContent> overlay = videoFrame->GetCaptionOverlay(); nsCOMPtr<nsIContent> controls = videoFrame->GetVideoControls(); if (!overlay) { return; } nsTArray<RefPtr<TextTrackCue> > activeCues; mTextTracks->GetShowingCues(activeCues); if (activeCues.Length() > 0) { WEBVTT_LOG("UpdateCueDisplay ProcessCues"); WEBVTT_LOGV("UpdateCueDisplay activeCues.Length() %d",activeCues.Length()); RefPtr<nsVariantCC> jsCues = new nsVariantCC(); jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE, &NS_GET_IID(nsIDOMEventTarget), activeCues.Length(), static_cast<void*>(activeCues.Elements())); nsPIDOMWindowInner* window = mMediaElement->OwnerDoc()->GetInnerWindow(); if (window) { sParserWrapper->ProcessCues(window, jsCues, overlay, controls); } } else if (overlay->Length() > 0) { WEBVTT_LOG("UpdateCueDisplay EmptyString"); nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true); } }
nsIntPoint HTMLImageElement::GetXY() { nsIntPoint point(0, 0); nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame) { return point; } nsIFrame* layer = nsLayoutUtils::GetClosestLayer(frame->GetParent()); nsPoint origin(frame->GetOffsetTo(layer)); // Convert to pixels using that scale point.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x); point.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y); return point; }
void nsSVGSwitchElement::MaybeInvalidate() { // We don't reuse UpdateActiveChild() and check if mActiveChild has changed // to determine if we should call nsSVGUtils::UpdateGraphic. If we did that, // nsSVGUtils::UpdateGraphic would not invalidate the old mActiveChild area! if (FindActiveChild() == mActiveChild) { return; } nsIFrame *frame = GetPrimaryFrame(); if (frame) { nsISVGChildFrame* svgFrame = do_QueryFrame(frame); if (svgFrame) { nsSVGUtils::UpdateGraphic(svgFrame); } } }
already_AddRefed<nsIDOMSVGRect> SVGLocatableElement::GetBBox(ErrorResult& rv) { nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame || (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) { rv.Throw(NS_ERROR_FAILURE); return nullptr; } nsISVGChildFrame* svgframe = do_QueryFrame(frame); if (!svgframe) { rv.Throw(NS_ERROR_NOT_IMPLEMENTED); // XXX: outer svg return nullptr; } nsCOMPtr<nsIDOMSVGRect> rect; rv = NS_NewSVGRect(getter_AddRefs(rect), nsSVGUtils::GetBBox(frame)); return rect.forget(); }
NS_IMETHODIMP nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission *aFormSubmission, nsIContent *aSubmitElement) { nsAutoString name; if (!GetAttr(kNameSpaceID_None, nsGkAtoms::name, name)) { // No name, don't submit. return NS_OK; } nsIFrame* frame = GetPrimaryFrame(); nsIObjectFrame *objFrame = nsnull; if (frame) { CallQueryInterface(frame, &objFrame); } if (!objFrame) { // No frame, nothing to submit. return NS_OK; } nsCOMPtr<nsIPluginInstance> pi; objFrame->GetPluginInstance(*getter_AddRefs(pi)); nsCOMPtr<nsIPluginInstanceInternal> pi_internal(do_QueryInterface(pi)); if (!pi_internal) { // No plugin, nothing to submit. return NS_OK; } nsAutoString value; nsresult rv = pi_internal->GetFormValue(value); NS_ENSURE_SUCCESS(rv, rv); return aFormSubmission->AddNameValuePair(this, name, value); }
NS_IMETHODIMP nsHTMLLegendElement::Focus() { nsIFrame* frame = GetPrimaryFrame(); if (!frame) return NS_OK; PRInt32 tabIndex; if (frame->IsFocusable(&tabIndex, false)) return nsGenericHTMLElement::Focus(); // If the legend isn't focusable, focus whatever is focusable following // the legend instead, bug 81481. nsIFocusManager* fm = nsFocusManager::GetFocusManager(); if (!fm) return NS_OK; nsCOMPtr<nsIDOMElement> result; return fm->MoveFocus(nsnull, this, nsIFocusManager::MOVEFOCUS_FORWARD, 0, getter_AddRefs(result)); }
void TextTrackManager::UpdateCueDisplay() { if (!mMediaElement || !mTextTracks) { return; } nsIFrame* frame = mMediaElement->GetPrimaryFrame(); nsVideoFrame* videoFrame = do_QueryFrame(frame); if (!videoFrame) { return; } nsCOMPtr<nsIContent> overlay = videoFrame->GetCaptionOverlay(); if (!overlay) { return; } nsTArray<nsRefPtr<TextTrackCue> > activeCues; mTextTracks->UpdateAndGetShowingCues(activeCues); if (activeCues.Length() > 0) { nsCOMPtr<nsIWritableVariant> jsCues = do_CreateInstance("@mozilla.org/variant;1"); jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE, &NS_GET_IID(nsIDOMEventTarget), activeCues.Length(), static_cast<void*>(activeCues.Elements())); nsPIDOMWindow* window = mMediaElement->OwnerDoc()->GetWindow(); if (window) { sParserWrapper->ProcessCues(window, jsCues, overlay); } } else if (overlay->Length() > 0) { nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true); } }
NS_IMETHODIMP PluginDocument::Print() { NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE); nsIObjectFrame* objectFrame = do_QueryFrame(mPluginContent->GetPrimaryFrame()); if (objectFrame) { RefPtr<nsNPAPIPluginInstance> pi; objectFrame->GetPluginInstance(getter_AddRefs(pi)); if (pi) { NPPrint npprint; npprint.mode = NP_FULL; npprint.print.fullPrint.pluginPrinted = false; npprint.print.fullPrint.printOne = false; npprint.print.fullPrint.platformPrint = nullptr; pi->Print(&npprint); } } return NS_OK; }
/* nsIDOMSVGRect getBBox (); */ NS_IMETHODIMP nsSVGGraphicElement::GetBBox(nsIDOMSVGRect **_retval) { *_retval = nsnull; nsIFrame* frame = GetPrimaryFrame(Flush_Layout); if (!frame || (frame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) return NS_ERROR_FAILURE; nsISVGChildFrame* svgframe; CallQueryInterface(frame, &svgframe); NS_ASSERTION(svgframe, "wrong frame type"); if (svgframe) { svgframe->SetMatrixPropagation(PR_FALSE); svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION | nsISVGChildFrame::TRANSFORM_CHANGED); nsresult rv = svgframe->GetBBox(_retval); svgframe->SetMatrixPropagation(PR_TRUE); svgframe->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION | nsISVGChildFrame::TRANSFORM_CHANGED); return rv; } return NS_ERROR_FAILURE; }
bool SVGTextContentElement::FrameIsSVGText() { nsIFrame* frame = GetPrimaryFrame(Flush_Layout); return frame && frame->IsSVGText(); }
nsSVGTextContainerFrame* SVGTextContentElement::GetTextContainerFrame() { return do_QueryFrame(GetPrimaryFrame(Flush_Layout)); }
nsIFrame* nsAccessNode::GetFrame() const { return mContent ? mContent->GetPrimaryFrame() : nsnull; }