nsresult nsColorControlFrame::UpdateColor() { // Get the color from the "value" property of our content; it will return the // default color (through the sanitization algorithm) if the value is empty. nsAutoString color; HTMLInputElement* elt = HTMLInputElement::FromContent(mContent); elt->GetValue(color, CallerType::System); if (color.IsEmpty()) { // OK, there is one case the color string might be empty -- if our content // is still being created, i.e. if it has mDoneCreating==false. In that // case, we simply do nothing, because we'll be called again with a complete // content node before we ever reflow or paint. Specifically: we can expect // that HTMLInputElement::DoneCreatingElement() will set mDoneCreating to // true (which enables sanitization) and then it'll call SetValueInternal(), // which produces a nonempty color (via sanitization), and then it'll call // this function here, and we'll get the nonempty default color. MOZ_ASSERT(HasAnyStateBits(NS_FRAME_FIRST_REFLOW), "Content node's GetValue() should return a valid color string " "by the time we've been reflowed (the default color, in case " "no valid color is set)"); return NS_OK; } // Set the background-color CSS property of the swatch element to this color. return mColorContent->SetAttr(kNameSpaceID_None, nsGkAtoms::style, NS_LITERAL_STRING("background-color:") + color, /* aNotify */ true); }
void HTMLTextFieldAccessible::Value(nsString& aValue) { aValue.Truncate(); if (NativeState() & states::PROTECTED) // Don't return password text! return; nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea(do_QueryInterface(mContent)); if (textArea) { textArea->GetValue(aValue); return; } HTMLInputElement* input = HTMLInputElement::FromContent(mContent); if (input) input->GetValue(aValue); }
void HTMLTextFieldAccessible::Value(nsString& aValue) const { aValue.Truncate(); if (NativeState() & states::PROTECTED) // Don't return password text! return; HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent); if (textArea) { textArea->GetValue(aValue); return; } HTMLInputElement* input = HTMLInputElement::FromNode(mContent); if (input) { // Pass NonSystem as the caller type, to be safe. We don't expect to have a // file input here. input->GetValue(aValue, CallerType::NonSystem); } }
nsresult nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) { nsresult rv; // We create an anonymous tree for our input element that is structured as // follows: // // input // div - outer wrapper with "display:flex" by default // input - text input field // div - spin box wrapping up/down arrow buttons // div - spin up (up arrow button) // div - spin down (down arrow button) // // If you change this, be careful to change the destruction order in // nsNumberControlFrame::DestroyFrom. // Create the anonymous outer wrapper: rv = MakeAnonymousElement(getter_AddRefs(mOuterWrapper), aElements, nsGkAtoms::div, nsCSSPseudoElements::ePseudo_mozNumberWrapper, mStyleContext); NS_ENSURE_SUCCESS(rv, rv); ContentInfo& outerWrapperCI = aElements.LastElement(); // Create the ::-moz-number-text pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mTextField), outerWrapperCI.mChildren, nsGkAtoms::input, nsCSSPseudoElements::ePseudo_mozNumberText, outerWrapperCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE); HTMLInputElement* content = HTMLInputElement::FromContent(mContent); HTMLInputElement* textField = HTMLInputElement::FromContent(mTextField); // Initialize the text field value: nsAutoString value; content->GetValue(value); mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::value, value, false); // If we're readonly, make sure our anonymous text control is too: nsAutoString readonly; if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly)) { mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly, false); } // Propogate our tabindex: int32_t tabIndex; content->GetTabIndex(&tabIndex); textField->SetTabIndex(tabIndex); // Initialize the text field's placeholder, if ours is set: nsAutoString placeholder; if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholder)) { mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholder, false); } if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS)) { // We don't want to focus the frame but the text field. nsIFocusManager* fm = nsFocusManager::GetFocusManager(); nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mTextField); NS_ASSERTION(element, "Really, this should be a nsIDOMElement!"); fm->SetFocus(element, 0); } // Create the ::-moz-number-spin-box pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinBox), outerWrapperCI.mChildren, nsGkAtoms::div, nsCSSPseudoElements::ePseudo_mozNumberSpinBox, outerWrapperCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); ContentInfo& spinBoxCI = outerWrapperCI.mChildren.LastElement(); // Create the ::-moz-number-spin-up pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinUp), spinBoxCI.mChildren, nsGkAtoms::div, nsCSSPseudoElements::ePseudo_mozNumberSpinUp, spinBoxCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); // Create the ::-moz-number-spin-down pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinDown), spinBoxCI.mChildren, nsGkAtoms::div, nsCSSPseudoElements::ePseudo_mozNumberSpinDown, spinBoxCI.mStyleContext); return rv; }
nsresult nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) { nsresult rv; // We create an anonymous tree for our input element that is structured as // follows: // // input // div - outer wrapper with "display:flex" by default // input - text input field // div - spin box wrapping up/down arrow buttons // div - spin up (up arrow button) // div - spin down (down arrow button) // // If you change this, be careful to change the destruction order in // nsNumberControlFrame::DestroyFrom. // Create the anonymous outer wrapper: rv = MakeAnonymousElement(getter_AddRefs(mOuterWrapper), aElements, nsGkAtoms::div, CSSPseudoElementType::mozNumberWrapper, mStyleContext); NS_ENSURE_SUCCESS(rv, rv); ContentInfo& outerWrapperCI = aElements.LastElement(); // Create the ::-moz-number-text pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mTextField), outerWrapperCI.mChildren, nsGkAtoms::input, CSSPseudoElementType::mozNumberText, outerWrapperCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE); HTMLInputElement* content = HTMLInputElement::FromContent(mContent); HTMLInputElement* textField = HTMLInputElement::FromContent(mTextField); // Initialize the text field value: nsAutoString value; content->GetValue(value); SetValueOfAnonTextControl(value); // If we're readonly, make sure our anonymous text control is too: nsAutoString readonly; if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly)) { mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly, false); } // Propogate our tabindex: int32_t tabIndex; content->GetTabIndex(&tabIndex); textField->SetTabIndex(tabIndex); // Initialize the text field's placeholder, if ours is set: nsAutoString placeholder; if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholder)) { mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, placeholder, false); } if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS)) { // We don't want to focus the frame but the text field. RefPtr<FocusTextField> focusJob = new FocusTextField(mContent, mTextField); nsContentUtils::AddScriptRunner(focusJob); } if (StyleDisplay()->mAppearance == NS_THEME_TEXTFIELD) { // The author has elected to hide the spinner by setting this // -moz-appearance. We will reframe if it changes. return rv; } // Create the ::-moz-number-spin-box pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinBox), outerWrapperCI.mChildren, nsGkAtoms::div, CSSPseudoElementType::mozNumberSpinBox, outerWrapperCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); ContentInfo& spinBoxCI = outerWrapperCI.mChildren.LastElement(); // Create the ::-moz-number-spin-up pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinUp), spinBoxCI.mChildren, nsGkAtoms::div, CSSPseudoElementType::mozNumberSpinUp, spinBoxCI.mStyleContext); NS_ENSURE_SUCCESS(rv, rv); // Create the ::-moz-number-spin-down pseudo-element: rv = MakeAnonymousElement(getter_AddRefs(mSpinDown), spinBoxCI.mChildren, nsGkAtoms::div, CSSPseudoElementType::mozNumberSpinDown, spinBoxCI.mStyleContext); SyncDisabledState(); return rv; }