SSL RadioGroupContainer.cpp
Interaktion und PortierbarkeitC
/* -*- 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/. */
/** * A struct that holds all the information about a radio group.
*/ struct nsRadioGroupStruct {
nsRadioGroupStruct()
: mRequiredRadioCount(0), mGroupSuffersFromValueMissing(false) {}
/** * A strong pointer to the currently selected radio button.
*/
RefPtr<HTMLInputElement> mSelectedRadioButton;
TreeOrderedArray<RefPtr<HTMLInputElement>> mRadioButtons;
uint32_t mRequiredRadioCount; bool mGroupSuffersFromValueMissing;
};
RadioGroupContainer::~RadioGroupContainer() { for (constauto& group : mRadioGroups) { for (constauto& button : group.GetData()->mRadioButtons.AsList()) { // When the radio group container is being cycle-collected, any remaining // connected buttons will also be in the process of being cycle-collected. // Here, we unset the button's reference to the container so that when it // is collected it does not attempt to remove itself from a potentially // already deleted radio group.
button->DisconnectRadioGroupContainer();
}
}
}
// Return the radio button relative to the focused radio button. // If no radio is focused, get the radio relative to the selected one.
RefPtr<HTMLInputElement> currentRadio; if (aFocusedRadio) {
currentRadio = aFocusedRadio;
} else {
currentRadio = radioGroup->mSelectedRadioButton; if (!currentRadio) { return NS_ERROR_FAILURE;
}
}
int32_t index = radioGroup->mRadioButtons->IndexOf(currentRadio); if (index < 0) { return NS_ERROR_FAILURE;
}
int32_t numRadios = static_cast<int32_t>(radioGroup->mRadioButtons->Length());
RefPtr<HTMLInputElement> radio; do { if (aPrevious) { if (--index < 0) {
index = numRadios - 1;
}
} elseif (++index >= numRadios) {
index = 0;
}
radio = radioGroup->mRadioButtons->ElementAt(index);
} while ((radio->Disabled() || !radio->GetPrimaryFrame() ||
!radio->GetPrimaryFrame()->IsVisibleConsideringAncestors()) &&
radio != currentRadio);
radio.forget(aRadioOut); return NS_OK;
}
HTMLInputElement* RadioGroupContainer::GetFirstRadioButton( const nsAString& aName) {
nsRadioGroupStruct* radioGroup = GetOrCreateRadioGroup(aName); for (HTMLInputElement* radio : radioGroup->mRadioButtons.AsList()) { if (!radio->Disabled() && radio->GetPrimaryFrame() &&
radio->GetPrimaryFrame()->IsVisibleConsideringAncestors()) { return radio;
}
} return nullptr;
}
void RadioGroupContainer::RemoveFromRadioGroup(const nsAString& aName,
HTMLInputElement* aRadio) {
nsRadioGroupStruct* radioGroup = GetOrCreateRadioGroup(aName);
MOZ_ASSERT(
radioGroup->mRadioButtons->Contains(aRadio), "Attempting to remove radio button from group it is not a part of!");
radioGroup->mRadioButtons.RemoveElement(*aRadio);
if (aRadio->IsRequired()) {
MOZ_ASSERT(radioGroup->mRequiredRadioCount != 0, "mRequiredRadioCount about to wrap below 0!");
radioGroup->mRequiredRadioCount--;
}
}
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.