//------------------------------------------------------------------------------------------------------------------ ///virtual tree out class ouputs hierarchial data of class void pMolElement::treeOut(QTreeWidgetItem *tree) { pMolXMLbase::treeOut(tree); treeItem(tree,"index",index); treeItem(tree,"length", length); //output annotations and their subsequent children for (int i = 0; i < pMolElements.size(); ++i) //recursively paint { QTreeWidgetItem* branch = treeItem(tree,"annotation"); pMolElements.at(i)->treeOut(branch); }; }
nsIntPoint nsCoreUtils::GetScreenCoordsForWindow(nsINode *aNode) { nsIntPoint coords(0, 0); nsCOMPtr<nsIDocShellTreeItem> treeItem(GetDocShellTreeItemFor(aNode)); if (!treeItem) return coords; nsCOMPtr<nsIDocShellTreeItem> rootTreeItem; treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem)); nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(rootTreeItem); nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(domDoc)); if (!docView) return coords; nsCOMPtr<nsIDOMAbstractView> abstractView; docView->GetDefaultView(getter_AddRefs(abstractView)); nsCOMPtr<nsIDOMWindowInternal> windowInter(do_QueryInterface(abstractView)); if (!windowInter) return coords; windowInter->GetScreenX(&coords.x); windowInter->GetScreenY(&coords.y); return coords; }
/* readonly attribute nsIXULWindow xulWindow */ NS_IMETHODIMP nsWindowUtil::GetXulWindow(nsIXULWindow **_retval) { NS_ENSURE_STATE(mDOMWindow); nsresult rv; nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mDOMWindow, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIWebNavigation> nav; rv = requestor->GetInterface(NS_GET_IID(nsIWebNavigation), getter_AddRefs(nav)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(nav, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDocShellTreeOwner> treeOwner; rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); NS_ENSURE_SUCCESS(rv, rv); requestor = do_QueryInterface(treeOwner, &rv); NS_ENSURE_SUCCESS(rv, rv); return requestor->GetInterface(NS_GET_IID(nsIXULWindow), (void **) _retval); }
bool nsWinUtils::IsTabDocument(nsIDocument* aDocumentNode) { nsCOMPtr<nsISupports> container = aDocumentNode->GetContainer(); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container)); nsCOMPtr<nsIDocShellTreeItem> parentTreeItem; treeItem->GetParent(getter_AddRefs(parentTreeItem)); nsCOMPtr<nsIDocShellTreeItem> rootTreeItem; treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem)); return parentTreeItem == rootTreeItem; }
bool nsCoreUtils::IsTabDocument(nsIDocument* aDocumentNode) { nsCOMPtr<nsISupports> container = aDocumentNode->GetContainer(); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container)); nsCOMPtr<nsIDocShellTreeItem> parentTreeItem; treeItem->GetParent(getter_AddRefs(parentTreeItem)); // Tab document running in own process doesn't have parent. if (XRE_GetProcessType() == GeckoProcessType_Content) return !parentTreeItem; // Parent of docshell for tab document running in chrome process is root. nsCOMPtr<nsIDocShellTreeItem> rootTreeItem; treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem)); return parentTreeItem == rootTreeItem; }
nsIntPoint nsCoreUtils::GetScreenCoordsForWindow(nsINode *aNode) { nsIntPoint coords(0, 0); nsCOMPtr<nsIDocShellTreeItem> treeItem(GetDocShellFor(aNode)); if (!treeItem) return coords; nsCOMPtr<nsIDocShellTreeOwner> treeOwner; treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); if (!treeOwner) return coords; nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(treeOwner); if (baseWindow) baseWindow->GetPosition(&coords.x, &coords.y); // in device pixels return coords; }
nsresult nsDOMMenuBar::GetChromeDocument(nsIDOMDocument** _retval) { NS_ENSURE_STATE(mWindow); nsresult rv; nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(mWindow, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(webNav, &rv)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDocShellTreeItem> rootItem; rv = treeItem->GetRootTreeItem(getter_AddRefs(rootItem)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDOMWindow> chromeWindow(do_GetInterface(rootItem, &rv)); NS_ENSURE_SUCCESS(rv, rv); return chromeWindow->GetDocument(_retval); }
void pMolStackError :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolStackError",error); };
void pMolCmdString :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolCmd::STRING",string); };
void pMolCmdList :: treeOut(QTreeWidgetItem *tree) { QTreeWidgetItem* branch = treeItem(tree,"pMolCmd::LIST","----"); foreach (pMolCmd* cmd, list) cmd->treeOut(branch); };
void pMolCmdChild :: treeOut(QTreeWidgetItem *tree) { QTreeWidgetItem* branch = treeItem(tree,"pMolCmd::CHILD",name); if (child!=NULL) child->treeOut(branch); };
void pMolStackList :: treeOut(QTreeWidgetItem *tree) { QTreeWidgetItem* branch = treeItem(tree,"pMolCmd::LIST"); foreach (pMolStackObject* object, list) object->treeOut(branch); };
void pMolStackDouble :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolStack::DOUBLE",n); };
void pMolStackNumber :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolCmd::NUMBER",n); };
nsresult nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, PRBool aIsLinksOnly, PRBool aIsFirstVisiblePreferred, PRBool aFindPrev, PRUint16* aResult) { *aResult = FIND_NOTFOUND; mFoundLink = nsnull; mFoundEditable = nsnull; mCurrentWindow = nsnull; nsCOMPtr<nsIPresShell> startingPresShell (GetPresShell()); if (!startingPresShell) { nsCOMPtr<nsIDocShell> ds = do_QueryReferent(mDocShell); NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE); ds->GetPresShell(getter_AddRefs(startingPresShell)); mPresShell = do_GetWeakReference(startingPresShell); } nsCOMPtr<nsIPresShell> presShell(aPresShell); if (!presShell) { presShell = startingPresShell; // this is the current document if (!presShell) return NS_ERROR_FAILURE; } nsRefPtr<nsPresContext> presContext = presShell->GetPresContext(); if (!presContext) return NS_ERROR_FAILURE; nsCOMPtr<nsISelection> selection; nsCOMPtr<nsISelectionController> selectionController = do_QueryReferent(mSelectionController); if (!selectionController) { GetSelection(presShell, getter_AddRefs(selectionController), getter_AddRefs(selection)); // cache for reuse mSelectionController = do_GetWeakReference(selectionController); } else { selectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); } nsCOMPtr<nsISupports> startingContainer = presContext->GetContainer(); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(startingContainer)); NS_ASSERTION(treeItem, "Bug 175321 Crashes with Type Ahead Find [@ nsTypeAheadFind::FindItNow]"); if (!treeItem) return NS_ERROR_FAILURE; nsCOMPtr<nsIDocShellTreeItem> rootContentTreeItem; nsCOMPtr<nsIDocShell> currentDocShell; nsCOMPtr<nsIDocShell> startingDocShell(do_QueryInterface(startingContainer)); treeItem->GetSameTypeRootTreeItem(getter_AddRefs(rootContentTreeItem)); nsCOMPtr<nsIDocShell> rootContentDocShell = do_QueryInterface(rootContentTreeItem); if (!rootContentDocShell) return NS_ERROR_FAILURE; nsCOMPtr<nsISimpleEnumerator> docShellEnumerator; rootContentDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent, nsIDocShell::ENUMERATE_FORWARDS, getter_AddRefs(docShellEnumerator)); // Default: can start at the current document nsCOMPtr<nsISupports> currentContainer = startingContainer = do_QueryInterface(rootContentDocShell); // Iterate up to current shell, if there's more than 1 that we're // dealing with PRBool hasMoreDocShells; while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) && hasMoreDocShells) { docShellEnumerator->GetNext(getter_AddRefs(currentContainer)); currentDocShell = do_QueryInterface(currentContainer); if (!currentDocShell || currentDocShell == startingDocShell || aIsFirstVisiblePreferred) break; } // ------------ Get ranges ready ---------------- nsCOMPtr<nsIDOMRange> returnRange; nsCOMPtr<nsIPresShell> focusedPS; if (NS_FAILED(GetSearchContainers(currentContainer, (!aIsFirstVisiblePreferred || mStartFindRange) ? selectionController.get() : nsnull, aIsFirstVisiblePreferred, aFindPrev, getter_AddRefs(presShell), getter_AddRefs(presContext)))) { return NS_ERROR_FAILURE; } PRInt16 rangeCompareResult = 0; mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, mSearchRange, &rangeCompareResult); // No need to wrap find in doc if starting at beginning PRBool hasWrapped = (rangeCompareResult < 0); if (mTypeAheadBuffer.IsEmpty()) return NS_ERROR_FAILURE; mFind->SetFindBackwards(aFindPrev); while (PR_TRUE) { // ----- Outer while loop: go through all docs ----- while (PR_TRUE) { // === Inner while loop: go through a single doc === mFind->Find(mTypeAheadBuffer.get(), mSearchRange, mStartPointRange, mEndPointRange, getter_AddRefs(returnRange)); if (!returnRange) break; // Nothing found in this doc, go to outer loop (try next doc) // ------- Test resulting found range for success conditions ------ PRBool isInsideLink = PR_FALSE, isStartingLink = PR_FALSE; if (aIsLinksOnly) { // Don't check if inside link when searching all text RangeStartsInsideLink(returnRange, presShell, &isInsideLink, &isStartingLink); } PRBool usesIndependentSelection; if (!IsRangeVisible(presShell, presContext, returnRange, aIsFirstVisiblePreferred, PR_FALSE, getter_AddRefs(mStartPointRange), &usesIndependentSelection) || (aIsLinksOnly && !isInsideLink) || (mStartLinksOnlyPref && aIsLinksOnly && !isStartingLink)) { // ------ Failure ------ // Start find again from here returnRange->CloneRange(getter_AddRefs(mStartPointRange)); // Collapse to end mStartPointRange->Collapse(aFindPrev); continue; } // ------ Success! ------- // Hide old selection (new one may be on a different controller) if (selection) { selection->CollapseToStart(); SetSelectionModeAndRepaint(nsISelectionController::SELECTION_ON); } // Make sure new document is selected if (presShell != startingPresShell) { // We are in a new document (because of frames/iframes) mPresShell = do_GetWeakReference(presShell); } nsCOMPtr<nsIDocument> document = do_QueryInterface(presShell->GetDocument()); NS_ASSERTION(document, "Wow, presShell doesn't have document!"); if (!document) return NS_ERROR_UNEXPECTED; nsCOMPtr<nsPIDOMWindow> window = document->GetWindow(); NS_ASSERTION(window, "document has no window"); if (!window) return NS_ERROR_UNEXPECTED; nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); if (usesIndependentSelection) { /* If a search result is found inside an editable element, we'll focus * the element only if focus is in our content window, i.e. * |if (focusedWindow.top == ourWindow.top)| */ PRBool shouldFocusEditableElement = false; if (fm) { nsCOMPtr<nsIDOMWindow> focusedWindow; nsresult rv = fm->GetFocusedWindow(getter_AddRefs(focusedWindow)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsPIDOMWindow> fwPI(do_QueryInterface(focusedWindow, &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIDocShellTreeItem> fwTreeItem (do_QueryInterface(fwPI->GetDocShell(), &rv)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIDocShellTreeItem> fwRootTreeItem; rv = fwTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(fwRootTreeItem)); if (NS_SUCCEEDED(rv) && fwRootTreeItem == rootContentTreeItem) shouldFocusEditableElement = PR_TRUE; } } } } // We may be inside an editable element, and therefore the selection // may be controlled by a different selection controller. Walk up the // chain of parent nodes to see if we find one. nsCOMPtr<nsIDOMNode> node; returnRange->GetStartContainer(getter_AddRefs(node)); while (node) { nsCOMPtr<nsIDOMNSEditableElement> editable = do_QueryInterface(node); if (editable) { // Inside an editable element. Get the correct selection // controller and selection. nsCOMPtr<nsIEditor> editor; editable->GetEditor(getter_AddRefs(editor)); NS_ASSERTION(editor, "Editable element has no editor!"); if (!editor) { break; } editor->GetSelectionController( getter_AddRefs(selectionController)); if (selectionController) { selectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); } mFoundEditable = do_QueryInterface(node); if (!shouldFocusEditableElement) break; // Otherwise move focus/caret to editable element if (fm) fm->SetFocus(mFoundEditable, 0); break; } nsIDOMNode* tmp = node; tmp->GetParentNode(getter_AddRefs(node)); } // If we reach here without setting mFoundEditable, then something // besides editable elements can cause us to have an independent // selection controller. I don't know whether this is possible. // Currently, we simply fall back to grabbing the document's selection // controller in this case. Perhaps we should reject this find match // and search again. NS_ASSERTION(mFoundEditable, "Independent selection controller on " "non-editable element!"); } if (!mFoundEditable) { // Not using a separate selection controller, so just get the // document's controller and selection. GetSelection(presShell, getter_AddRefs(selectionController), getter_AddRefs(selection)); } mSelectionController = do_GetWeakReference(selectionController); // Select the found text if (selection) { selection->RemoveAllRanges(); selection->AddRange(returnRange); } if (!mFoundEditable && fm) { nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(window); fm->MoveFocus(win, nsnull, nsIFocusManager::MOVEFOCUS_CARET, nsIFocusManager::FLAG_NOSCROLL | nsIFocusManager::FLAG_NOSWITCHFRAME, getter_AddRefs(mFoundLink)); } // Change selection color to ATTENTION and scroll to it. Careful: we // must wait until after we goof with focus above before changing to // ATTENTION, or when we MoveFocus() and the selection is not on a // link, we'll blur, which will lose the ATTENTION. if (selectionController) { // Beware! This may flush notifications via synchronous // ScrollSelectionIntoView. SetSelectionModeAndRepaint(nsISelectionController::SELECTION_ATTENTION); selectionController->ScrollSelectionIntoView( nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_WHOLE_SELECTION, nsISelectionController::SCROLL_SYNCHRONOUS); } mCurrentWindow = window; *aResult = hasWrapped ? FIND_WRAPPED : FIND_FOUND; return NS_OK; } // ======= end-inner-while (go through a single document) ========== // ---------- Nothing found yet, try next document ------------- PRBool hasTriedFirstDoc = PR_FALSE; do { // ==== Second inner loop - get another while ==== if (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) && hasMoreDocShells) { docShellEnumerator->GetNext(getter_AddRefs(currentContainer)); NS_ASSERTION(currentContainer, "HasMoreElements lied to us!"); currentDocShell = do_QueryInterface(currentContainer); if (currentDocShell) break; } else if (hasTriedFirstDoc) // Avoid potential infinite loop return NS_ERROR_FAILURE; // No content doc shells // Reached last doc shell, loop around back to first doc shell rootContentDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent, nsIDocShell::ENUMERATE_FORWARDS, getter_AddRefs(docShellEnumerator)); hasTriedFirstDoc = PR_TRUE; } while (docShellEnumerator); // ==== end second inner while === PRBool continueLoop = PR_FALSE; if (currentDocShell != startingDocShell) continueLoop = PR_TRUE; // Try next document else if (!hasWrapped || aIsFirstVisiblePreferred) { // Finished searching through docshells: // If aFirstVisiblePreferred == PR_TRUE, we may need to go through all // docshells twice -once to look for visible matches, the second time // for any match aIsFirstVisiblePreferred = PR_FALSE; hasWrapped = PR_TRUE; continueLoop = PR_TRUE; // Go through all docs again } if (continueLoop) { if (NS_FAILED(GetSearchContainers(currentContainer, nsnull, aIsFirstVisiblePreferred, aFindPrev, getter_AddRefs(presShell), getter_AddRefs(presContext)))) { continue; } if (aFindPrev) { // Reverse mode: swap start and end points, so that we start // at end of document and go to beginning nsCOMPtr<nsIDOMRange> tempRange; mStartPointRange->CloneRange(getter_AddRefs(tempRange)); mStartPointRange = mEndPointRange; mEndPointRange = tempRange; } continue; } // ------------- Failed -------------- break; } // end-outer-while: go through all docs return NS_ERROR_FAILURE; }
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; }
void pMolCmdNumber :: treeOut(QTreeWidgetItem *tree) { QString str; treeItem(tree,"pMolCmd::NUMBER",str.setNum(n)); };
void pMolCmdError :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolCmd::ERROR",error); };
void pMolStackString :: treeOut(QTreeWidgetItem *tree) { treeItem(tree,"pMolStackString",string); };