/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if (!changedStates.IsEmpty()) {
ToggleStates(changedStates, aNotify);
}
}
void HTMLOptionElement::SetSelected(bool aValue) { // Note: The select content obj maintains all the PresState // so defer to it to get the answer
HTMLSelectElement* selectInt = GetSelect(); if (selectInt) {
int32_t index = Index();
HTMLSelectElement::OptionFlags mask{
HTMLSelectElement::OptionFlag::SetDisabled,
HTMLSelectElement::OptionFlag::Notify}; if (aValue) {
mask += HTMLSelectElement::OptionFlag::IsSelected;
}
// This should end up calling SetSelectedInternal
selectInt->SetOptionsSelectedByIndex(index, index, mask);
} else {
SetSelectedInternal(aValue, true);
}
}
// We just changed out selected state (since we look at the "selected" // attribute when mSelectedChanged is false). Let's tell our select about // it.
HTMLSelectElement* selectInt = GetSelect(); if (!selectInt) { // If option is a child of select, SetOptionsSelectedByIndex will set the // selected state if needed.
SetStates(ElementState::CHECKED, !!aValue, aNotify); return;
}
NS_ASSERTION(!mSelectedChanged, "Shouldn't be here");
int32_t index = Index();
HTMLSelectElement::OptionFlags mask =
HTMLSelectElement::OptionFlag::SetDisabled; if (aValue) {
mask += HTMLSelectElement::OptionFlag::IsSelected;
}
if (aNotify) {
mask += HTMLSelectElement::OptionFlag::Notify;
}
// This can end up calling SetSelectedInternal if our selected state needs to // change, which we will allow to take effect so that parts of // SetOptionsSelectedByIndex that might depend on it working don't get // confused.
selectInt->SetOptionsSelectedByIndex(index, index, mask);
// Now reset our members; when we finish the attr set we'll end up with the // rigt selected state.
mIsInSetDefaultSelected = inSetDefaultSelected; // the selected state might have been changed by SetOptionsSelectedByIndex, // possibly more than once; make sure our mSelectedChanged state is set back // correctly.
mSelectedChanged = false;
}
if (aName == nsGkAtoms::value && Selected()) { // Since this option is selected, changing value may have changed missing // validity state of the select element if (HTMLSelectElement* select = GetSelect()) {
select->UpdateValueMissingValidityState();
}
}
if (aName == nsGkAtoms::selected) {
SetStates(ElementState::DEFAULT, !!aValue, aNotify);
}
}
// Our previous parent could have been involved in :disabled/:enabled state.
UpdateDisabledState(false);
}
// Get the select content element that contains this option
HTMLSelectElement* HTMLOptionElement::GetSelect() {
nsIContent* parent = GetParent(); if (!parent) { return nullptr;
}
HTMLSelectElement* select = HTMLSelectElement::FromNode(parent); if (select) { return select;
}
if (!parent->IsHTMLElement(nsGkAtoms::optgroup)) { return nullptr;
}
auto* nim = nodeInfo->NodeInfoManager();
RefPtr<HTMLOptionElement> option = new (nim) HTMLOptionElement(nodeInfo.forget());
if (!aText.IsEmpty()) { // Create a new text node and append it to the option
RefPtr<nsTextNode> textContent = new (option->NodeInfo()->NodeInfoManager())
nsTextNode(option->NodeInfo()->NodeInfoManager());
textContent->SetText(aText, false);
option->AppendChildTo(textContent, false, aError); if (aError.Failed()) { return nullptr;
}
}
if (aValue.WasPassed()) { // Set the value attribute for this element. We're calling SetAttr // directly because we want to pass aNotify == false.
aError = option->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
aValue.Value(), false); if (aError.Failed()) { return nullptr;
}
}
if (aDefaultSelected) { // We're calling SetAttr directly because we want to pass // aNotify == false.
aError =
option->SetAttr(kNameSpaceID_None, nsGkAtoms::selected, u""_ns, false); if (aError.Failed()) { return nullptr;
}
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.