本文整理汇总了C++中OptionElement::setSelectedState方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionElement::setSelectedState方法的具体用法?C++ OptionElement::setSelectedState怎么用?C++ OptionElement::setSelectedState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionElement
的用法示例。
在下文中一共展示了OptionElement::setSelectedState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset
void SelectElement::reset(SelectElementData& data, Element* element)
{
bool optionSelected = false;
OptionElement* firstOption = 0;
const Vector<Element*>& items = data.listItems(element);
for (unsigned i = 0; i < items.size(); ++i) {
OptionElement* optionElement = toOptionElement(items[i]);
if (!optionElement)
continue;
if (!items[i]->getAttribute(HTMLNames::selectedAttr).isNull()) {
optionElement->setSelectedState(true);
optionSelected = true;
} else
optionElement->setSelectedState(false);
if (!firstOption)
firstOption = optionElement;
}
if (!optionSelected && firstOption && data.usesMenuList())
firstOption->setSelectedState(true);
element->setNeedsStyleRecalc();
}
示例2: updateListBoxSelection
void SelectElement::updateListBoxSelection(SelectElementData& data, Element* element, bool deselectOtherOptions)
{
ASSERT(element->renderer() && element->renderer()->isListBox());
ASSERT(data.activeSelectionAnchorIndex() >= 0);
unsigned start = min(data.activeSelectionAnchorIndex(), data.activeSelectionEndIndex());
unsigned end = max(data.activeSelectionAnchorIndex(), data.activeSelectionEndIndex());
Vector<bool>& cachedStateForActiveSelection = data.cachedStateForActiveSelection();
const Vector<Element*>& items = data.listItems(element);
for (unsigned i = 0; i < items.size(); ++i) {
OptionElement* optionElement = toOptionElement(items[i]);
if (!optionElement || items[i]->disabled())
continue;
if (i >= start && i <= end)
optionElement->setSelectedState(data.activeSelectionState());
else if (deselectOtherOptions || i >= cachedStateForActiveSelection.size())
optionElement->setSelectedState(false);
else
optionElement->setSelectedState(cachedStateForActiveSelection[i]);
}
scrollToSelection(data, element);
}
示例3: recalcListItems
void SelectElement::recalcListItems(SelectElementData& data, const Element* element, bool updateSelectedStates)
{
Vector<Element*>& listItems = data.rawListItems();
listItems.clear();
OptionElement* foundSelected = 0;
for (Node* currentNode = element->firstChild(); currentNode;) {
if (!currentNode->isElementNode()) {
currentNode = currentNode->traverseNextSibling(element);
continue;
}
Element* current = static_cast<Element*>(currentNode);
// optgroup tags may not nest. However, both FireFox and IE will
// flatten the tree automatically, so we follow suit.
// (http://www.w3.org/TR/html401/interact/forms.html#h-17.6)
if (isOptionGroupElement(current)) {
listItems.append(current);
if (current->firstChild()) {
currentNode = current->firstChild();
continue;
}
}
if (OptionElement* optionElement = toOptionElement(current)) {
listItems.append(current);
if (updateSelectedStates) {
if (!foundSelected && (data.usesMenuList() || (!data.multiple() && optionElement->selected()))) {
foundSelected = optionElement;
foundSelected->setSelectedState(true);
} else if (foundSelected && !data.multiple() && optionElement->selected()) {
foundSelected->setSelectedState(false);
foundSelected = optionElement;
}
}
}
if (current->hasTagName(HTMLNames::hrTag))
listItems.append(current);
// In conforming HTML code, only <optgroup> and <option> will be found
// within a <select>. We call traverseNextSibling so that we only step
// into those tags that we choose to. For web-compat, we should cope
// with the case where odd tags like a <div> have been added but we
// handle this because such tags have already been removed from the
// <select>'s subtree at this point.
currentNode = currentNode->traverseNextSibling(element);
}
data.setShouldRecalcListItems(false);
}
示例4: listBoxDefaultEventHandler
void SelectElement::listBoxDefaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm)
{
const Vector<Element*>& listItems = data.listItems(element);
if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
element->focus();
// Convert to coords relative to the list box if needed.
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
IntPoint localOffset = roundedIntPoint(element->renderer()->absoluteToLocal(mouseEvent->absoluteLocation(), false, true));
int listIndex = static_cast<RenderListBox*>(element->renderer())->listIndexAtOffset(localOffset.x(), localOffset.y());
if (listIndex >= 0) {
// Save the selection so it can be compared to the new selection when dispatching change events during mouseup, or after autoscroll finishes.
saveLastSelection(data, element);
data.setActiveSelectionState(true);
bool multiSelectKeyPressed = false;
#if PLATFORM(MAC)
multiSelectKeyPressed = mouseEvent->metaKey();
#else
multiSelectKeyPressed = mouseEvent->ctrlKey();
#endif
bool shiftSelect = data.multiple() && mouseEvent->shiftKey();
bool multiSelect = data.multiple() && multiSelectKeyPressed && !mouseEvent->shiftKey();
Element* clickedElement = listItems[listIndex];
OptionElement* option = toOptionElement(clickedElement);
if (option) {
// Keep track of whether an active selection (like during drag selection), should select or deselect
if (option->selected() && multiSelectKeyPressed)
data.setActiveSelectionState(false);
if (!data.activeSelectionState())
option->setSelectedState(false);
}
// If we're not in any special multiple selection mode, then deselect all other items, excluding the clicked option.
// If no option was clicked, then this will deselect all items in the list.
if (!shiftSelect && !multiSelect)
deselectItems(data, element, clickedElement);
// If the anchor hasn't been set, and we're doing a single selection or a shift selection, then initialize the anchor to the first selected index.
if (data.activeSelectionAnchorIndex() < 0 && !multiSelect)
setActiveSelectionAnchorIndex(data, element, selectedIndex(data, element));
// Set the selection state of the clicked option
if (option && !clickedElement->disabled())
option->setSelectedState(true);
// If there was no selectedIndex() for the previous initialization, or
// If we're doing a single selection, or a multiple selection (using cmd or ctrl), then initialize the anchor index to the listIndex that just got clicked.
if (listIndex >= 0 && (data.activeSelectionAnchorIndex() < 0 || !shiftSelect))
setActiveSelectionAnchorIndex(data, element, listIndex);
setActiveSelectionEndIndex(data, listIndex);
updateListBoxSelection(data, element, !multiSelect);
if (Frame* frame = element->document()->frame())
frame->eventHandler()->setMouseDownMayStartAutoscroll();
event->setDefaultHandled();
}
} else if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton && element->document()->frame()->eventHandler()->autoscrollRenderer() != element->renderer())
// This makes sure we fire dispatchFormControlChangeEvent for a single click. For drag selection, onChange will fire when the autoscroll timer stops.
listBoxOnChange(data, element);
else if (event->type() == eventNames().keydownEvent) {
if (!event->isKeyboardEvent())
return;
String keyIdentifier = static_cast<KeyboardEvent*>(event)->keyIdentifier();
int endIndex = 0;
if (data.activeSelectionEndIndex() < 0) {
// Initialize the end index
if (keyIdentifier == "Down")
endIndex = nextSelectableListIndex(data, element, lastSelectedListIndex(data, element));
else if (keyIdentifier == "Up")
endIndex = previousSelectableListIndex(data, element, optionToListIndex(data, element, selectedIndex(data, element)));
} else {
// Set the end index based on the current end index
if (keyIdentifier == "Down")
endIndex = nextSelectableListIndex(data, element, data.activeSelectionEndIndex());
else if (keyIdentifier == "Up")
endIndex = previousSelectableListIndex(data, element, data.activeSelectionEndIndex());
}
if (keyIdentifier == "Down" || keyIdentifier == "Up") {
// Save the selection so it can be compared to the new selection when dispatching change events immediately after making the new selection.
saveLastSelection(data, element);
ASSERT(endIndex >= 0 && (unsigned) endIndex < listItems.size());
setActiveSelectionEndIndex(data, endIndex);
// If the anchor is unitialized, or if we're going to deselect all other options, then set the anchor index equal to the end index.
bool deselectOthers = !data.multiple() || !static_cast<KeyboardEvent*>(event)->shiftKey();
if (data.activeSelectionAnchorIndex() < 0 || deselectOthers) {
data.setActiveSelectionState(true);
if (deselectOthers)
deselectItems(data, element);
//.........这里部分代码省略.........