nsIFrame* nsSubDocumentFrame::ObtainIntrinsicSizeFrame() { nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(GetContent()); if (olc) { // We are an HTML <object>, <embed> or <applet> (a replaced element). // Try to get an nsIFrame for our sub-document's document element nsIFrame* subDocRoot = nsnull; nsCOMPtr<nsIDocShell> docShell; GetDocShell(getter_AddRefs(docShell)); if (docShell) { nsCOMPtr<nsIPresShell> presShell; docShell->GetPresShell(getter_AddRefs(presShell)); if (presShell) { nsIScrollableFrame* scrollable = presShell->GetRootScrollFrameAsScrollable(); if (scrollable) { nsIFrame* scrolled = scrollable->GetScrolledFrame(); if (scrolled) { subDocRoot = scrolled->GetFirstChild(nsnull); } } } } #ifdef MOZ_SVG if (subDocRoot && subDocRoot->GetContent() && subDocRoot->GetContent()->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) { return subDocRoot; // SVG documents have an intrinsic size } #endif } return nsnull; }
nsresult Location::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL) { *sourceURL = nullptr; nsIDocument* doc = GetEntryDocument(); // If there's no entry document, we either have no Script Entry Point or one // that isn't a DOM Window. This doesn't generally happen with the DOM, but // can sometimes happen with extension code in certain IPC configurations. If // this happens, try falling back on the current document associated with the // docshell. If that fails, just return null and hope that the caller passed // an absolute URI. if (!doc && GetDocShell()) { nsCOMPtr<nsPIDOMWindowOuter> docShellWin = do_QueryInterface(GetDocShell()->GetScriptGlobalObject()); if (docShellWin) { doc = docShellWin->GetDoc(); } } NS_ENSURE_TRUE(doc, NS_OK); *sourceURL = doc->GetBaseURI().take(); return NS_OK; }
PRBool nsSubDocumentFrame::ReflowFinished() { nsCOMPtr<nsIDocShell> docShell; GetDocShell(getter_AddRefs(docShell)); nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell)); // resize the sub document if (baseWindow) { PRInt32 x = 0; PRInt32 y = 0; nsWeakFrame weakFrame(this); nsPresContext* presContext = PresContext(); baseWindow->GetPositionAndSize(&x, &y, nsnull, nsnull); if (!weakFrame.IsAlive()) { // GetPositionAndSize() killed us return PR_FALSE; } // GetPositionAndSize might have resized us. So now is the time to // get our size. mPostedReflowCallback = PR_FALSE; nsSize innerSize(GetSize()); if (IsInline()) { nsMargin usedBorderPadding = GetUsedBorderAndPadding(); // Sadly, XUL smacks the frame size without changing the used // border and padding, so we can't trust those. Subtracting // them might make things negative. innerSize.width -= usedBorderPadding.LeftRight(); innerSize.width = PR_MAX(innerSize.width, 0); innerSize.height -= usedBorderPadding.TopBottom(); innerSize.height = PR_MAX(innerSize.height, 0); } PRInt32 cx = presContext->AppUnitsToDevPixels(innerSize.width); PRInt32 cy = presContext->AppUnitsToDevPixels(innerSize.height); baseWindow->SetPositionAndSize(x, y, cx, cy, PR_FALSE); } else { // Make sure that we can post a reflow callback in the future. mPostedReflowCallback = PR_FALSE; } return PR_FALSE; }
nsresult nsLocation::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL) { *sourceURL = nullptr; nsCOMPtr<nsIScriptGlobalObject> sgo = nsJSUtils::GetDynamicScriptGlobal(cx); // If this JS context doesn't have an associated DOM window, we effectively // have no script entry point stack. This doesn't generally happen with the DOM, // but can sometimes happen with extension code in certain IPC configurations. // If this happens, try falling back on the current document associated with // the docshell. If that fails, just return null and hope that the caller passed // an absolute URI. if (!sgo && GetDocShell()) { sgo = do_GetInterface(GetDocShell()); } NS_ENSURE_TRUE(sgo, NS_OK); nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(sgo); NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED); nsIDocument* doc = window->GetDoc(); NS_ENSURE_TRUE(doc, NS_OK); *sourceURL = doc->GetBaseURI().get(); return NS_OK; }
/* void init (in nsIDOMWindow win); */ NS_IMETHODIMP nsWindowUtil::Init(nsIDOMWindow *win) { nsresult rv; mDOMWindow = win; nsCOMPtr<nsIDocShell> docShell; rv = GetDocShell(getter_AddRefs(docShell)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell, &rv)); NS_ENSURE_SUCCESS(rv, rv); nativeWindow theNativeWindow; rv = baseWindow->GetParentNativeWindow( &theNativeWindow ); NS_ENSURE_SUCCESS(rv, rv); mWnd = reinterpret_cast<HWND>(theNativeWindow); NS_ENSURE_TRUE(mWnd, NS_ERROR_UNEXPECTED); return NS_OK; }
nsresult nsSubDocumentFrame::ShowDocShell() { nsCOMPtr<nsIDocShell> docShell; nsresult rv = GetDocShell(getter_AddRefs(docShell)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPresShell> presShell; docShell->GetPresShell(getter_AddRefs(presShell)); if (presShell) { // The docshell is already showing, nothing left to do... NS_ASSERTION(mInnerView, "What's going on?"); return NS_OK; } // pass along marginwidth, marginheight, scrolling so sub document // can use it nsIntSize margin = GetMarginAttributes(); docShell->SetMarginWidth(margin.width); docShell->SetMarginHeight(margin.height); // Current and initial scrolling is set so that all succeeding docs // will use the scrolling value set here, regardless if scrolling is // set by viewing a particular document (e.g. XUL turns off scrolling) nsCOMPtr<nsIScrollable> sc(do_QueryInterface(docShell)); if (sc) { const nsStyleDisplay *disp = GetStyleDisplay(); sc->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X, ConvertOverflow(disp->mOverflowX)); sc->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, ConvertOverflow(disp->mOverflowY)); } PRInt32 itemType = nsIDocShellTreeItem::typeContent; nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell)); if (treeItem) { treeItem->GetItemType(&itemType); } nsContentType contentType; if (itemType == nsIDocShellTreeItem::typeChrome) { contentType = eContentTypeUI; } else { nsCOMPtr<nsIDocShellTreeItem> sameTypeParent; treeItem->GetSameTypeParent(getter_AddRefs(sameTypeParent)); contentType = sameTypeParent ? eContentTypeContentFrame : eContentTypeContent; } rv = CreateViewAndWidget(contentType); if (NS_FAILED(rv)) { return rv; } nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell)); if (baseWindow) { baseWindow->InitWindow(nsnull, mInnerView->GetWidget(), 0, 0, 10, 10); // This is kinda whacky, this "Create()" call doesn't really // create anything, one starts to wonder why this was named // "Create"... baseWindow->Create(); baseWindow->SetVisibility(PR_TRUE); } // Trigger editor re-initialization if midas is turned on in the // sub-document. This shouldn't be necessary, but given the way our // editor works, it is. See // https://bugzilla.mozilla.org/show_bug.cgi?id=284245 docShell->GetPresShell(getter_AddRefs(presShell)); if (presShell) { nsCOMPtr<nsIDOMNSHTMLDocument> doc = do_QueryInterface(presShell->GetDocument()); if (doc) { nsAutoString designMode; doc->GetDesignMode(designMode); if (designMode.EqualsLiteral("on")) { doc->SetDesignMode(NS_LITERAL_STRING("off")); doc->SetDesignMode(NS_LITERAL_STRING("on")); } } } return NS_OK; }