void nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot) { mScrollEvent.Revoke(); EditorInitializer* initializer = (EditorInitializer*) Properties().Get(TextControlInitializer()); if (initializer) { initializer->Revoke(); Properties().Delete(TextControlInitializer()); } // Unbind the text editor state object from the frame. The editor will live // on, but things like controllers will be released. nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); txtCtrl->UnbindFromFrame(this); nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), PR_FALSE); nsBoxFrame::DestroyFrom(aDestructRoot); }
nsresult nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) { NS_ASSERTION(mContent, "We should have a content!"); mState |= NS_FRAME_INDEPENDENT_SELECTION; nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); // Bind the frame to its text control nsresult rv = txtCtrl->BindToFrame(this); NS_ENSURE_SUCCESS(rv, rv); nsIContent* rootNode = txtCtrl->GetRootEditorNode(); NS_ENSURE_TRUE(rootNode, NS_ERROR_OUT_OF_MEMORY); if (!aElements.AppendElement(rootNode)) return NS_ERROR_OUT_OF_MEMORY; // Do we need a placeholder node? nsAutoString placeholderTxt; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholderTxt); nsContentUtils::RemoveNewlines(placeholderTxt); mUsePlaceholder = !placeholderTxt.IsEmpty(); // Create the placeholder anonymous content if needed. if (mUsePlaceholder) { nsIContent* placeholderNode = txtCtrl->CreatePlaceholderNode(); NS_ENSURE_TRUE(placeholderNode, NS_ERROR_OUT_OF_MEMORY); if (!aElements.AppendElement(placeholderNode)) return NS_ERROR_OUT_OF_MEMORY; } rv = UpdateValueDisplay(PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // textareas are eagerly initialized PRBool initEagerly = !IsSingleLineTextControl(); if (!initEagerly) { nsCOMPtr<nsIDOMNSHTMLElement> element = do_QueryInterface(txtCtrl); if (element) { // so are input text controls with spellcheck=true element->GetSpellcheck(&initEagerly); } } if (initEagerly) { NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), "Someone forgot a script blocker?"); EditorInitializer* initializer = (EditorInitializer*) Properties().Get(TextControlInitializer()); if (initializer) { initializer->Revoke(); } initializer = new EditorInitializer(this); Properties().Set(TextControlInitializer(),initializer); if (!nsContentUtils::AddScriptRunner(initializer)) { initializer->Revoke(); // paranoia Properties().Delete(TextControlInitializer()); delete initializer; return NS_ERROR_OUT_OF_MEMORY; } } return NS_OK; }
nsresult nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) { NS_ASSERTION(mContent, "We should have a content!"); mState |= NS_FRAME_INDEPENDENT_SELECTION; nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); // Bind the frame to its text control nsresult rv = txtCtrl->BindToFrame(this); NS_ENSURE_SUCCESS(rv, rv); nsIContent* rootNode = txtCtrl->GetRootEditorNode(); NS_ENSURE_TRUE(rootNode, NS_ERROR_OUT_OF_MEMORY); if (!aElements.AppendElement(rootNode)) return NS_ERROR_OUT_OF_MEMORY; // Do we need a placeholder node? nsAutoString placeholderTxt; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholderTxt); nsContentUtils::RemoveNewlines(placeholderTxt); mUsePlaceholder = !placeholderTxt.IsEmpty(); // Create the placeholder anonymous content if needed. if (mUsePlaceholder) { nsIContent* placeholderNode = txtCtrl->CreatePlaceholderNode(); NS_ENSURE_TRUE(placeholderNode, NS_ERROR_OUT_OF_MEMORY); // Associate ::-moz-placeholder pseudo-element with the placeholder node. nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozPlaceholder; nsRefPtr<nsStyleContext> placeholderStyleContext = PresContext()->StyleSet()->ResolvePseudoElementStyle( mContent->AsElement(), pseudoType, StyleContext(), placeholderNode->AsElement()); if (!aElements.AppendElement(ContentInfo(placeholderNode, placeholderStyleContext))) { return NS_ERROR_OUT_OF_MEMORY; } } rv = UpdateValueDisplay(false); NS_ENSURE_SUCCESS(rv, rv); // textareas are eagerly initialized bool initEagerly = !IsSingleLineTextControl(); if (!initEagerly) { // Also, input elements which have a cached selection should get eager // editor initialization. nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); initEagerly = txtCtrl->HasCachedSelection(); } if (!initEagerly) { nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(txtCtrl); if (element) { // so are input text controls with spellcheck=true element->GetSpellcheck(&initEagerly); } } if (initEagerly) { NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), "Someone forgot a script blocker?"); EditorInitializer* initializer = (EditorInitializer*) Properties().Get(TextControlInitializer()); if (initializer) { initializer->Revoke(); } initializer = new EditorInitializer(this); Properties().Set(TextControlInitializer(),initializer); if (!nsContentUtils::AddScriptRunner(initializer)) { initializer->Revoke(); // paranoia Properties().Delete(TextControlInitializer()); delete initializer; return NS_ERROR_OUT_OF_MEMORY; } } return NS_OK; }
nsresult nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) { NS_ASSERTION(mContent, "We should have a content!"); mState |= NS_FRAME_INDEPENDENT_SELECTION; nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); // Bind the frame to its text control nsresult rv = txtCtrl->BindToFrame(this); NS_ENSURE_SUCCESS(rv, rv); nsIContent* rootNode = txtCtrl->GetRootEditorNode(); NS_ENSURE_TRUE(rootNode, NS_ERROR_OUT_OF_MEMORY); if (!aElements.AppendElement(rootNode)) return NS_ERROR_OUT_OF_MEMORY; // Do we need a placeholder node? nsAutoString placeholderTxt; mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholderTxt); nsContentUtils::RemoveNewlines(placeholderTxt); mUsePlaceholder = !placeholderTxt.IsEmpty(); // Create the placeholder anonymous content if needed. if (mUsePlaceholder) { nsIContent* placeholderNode = txtCtrl->CreatePlaceholderNode(); NS_ENSURE_TRUE(placeholderNode, NS_ERROR_OUT_OF_MEMORY); // Associate ::placeholder pseudo-element with the placeholder node. CSSPseudoElementType pseudoType = CSSPseudoElementType::placeholder; // If this is a text input inside a number input then we want to use the // main number input as the source of style for the placeholder frame. nsIFrame* mainInputFrame = this; if (StyleContext()->GetPseudoType() == CSSPseudoElementType::mozNumberText) { do { mainInputFrame = mainInputFrame->GetParent(); } while (mainInputFrame && mainInputFrame->GetType() != nsGkAtoms::numberControlFrame); MOZ_ASSERT(mainInputFrame); } RefPtr<nsStyleContext> placeholderStyleContext = PresContext()->StyleSet()->ResolvePseudoElementStyle( mainInputFrame->GetContent()->AsElement(), pseudoType, StyleContext(), placeholderNode->AsElement()); if (!aElements.AppendElement(ContentInfo(placeholderNode, placeholderStyleContext))) { return NS_ERROR_OUT_OF_MEMORY; } if (!IsSingleLineTextControl()) { // For textareas, UpdateValueDisplay doesn't initialize the visibility // status of the placeholder because it returns early, so we have to // do that manually here. txtCtrl->UpdatePlaceholderVisibility(true); } } rv = UpdateValueDisplay(false); NS_ENSURE_SUCCESS(rv, rv); // textareas are eagerly initialized bool initEagerly = !IsSingleLineTextControl(); if (!initEagerly) { // Also, input elements which have a cached selection should get eager // editor initialization. nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); NS_ASSERTION(txtCtrl, "Content not a text control element"); initEagerly = txtCtrl->HasCachedSelection(); } if (!initEagerly) { nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(txtCtrl); if (element) { // so are input text controls with spellcheck=true element->GetSpellcheck(&initEagerly); } } if (initEagerly) { NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), "Someone forgot a script blocker?"); EditorInitializer* initializer = Properties().Get(TextControlInitializer()); if (initializer) { initializer->Revoke(); } initializer = new EditorInitializer(this); Properties().Set(TextControlInitializer(),initializer); nsContentUtils::AddScriptRunner(initializer); } return NS_OK; }