Exemple #1
0
bool HTMLSelectElement::appendFormData(FormDataList& list, bool)
{
    bool successful = false;
    const Vector<HTMLElement*>& items = listItems();

    unsigned i;
    for (i = 0; i < items.size(); i++) {
        if (items[i]->hasLocalName(optionTag)) {
            HTMLOptionElement *option = static_cast<HTMLOptionElement*>(items[i]);
            if (option->selected()) {
                list.appendData(name(), option->value());
                successful = true;
            }
        }
    }

    // ### this case should not happen. make sure that we select the first option
    // in any case. otherwise we have no consistency with the DOM interface. FIXME!
    // we return the first one if it was a combobox select
    if (!successful && !m_multiple && m_size <= 1 && items.size() &&
        (items[0]->hasLocalName(optionTag))) {
        HTMLOptionElement *option = static_cast<HTMLOptionElement*>(items[0]);
        if (option->value().isNull())
            list.appendData(name(), option->text().stripWhiteSpace());
        else
            list.appendData(name(), option->value());
        successful = true;
    }

    return successful;
}
void PopupMenuImpl::addOption(HTMLOptionElement& element, bool enableExtraStyling, SharedBuffer* data)
{
    PagePopupClient::addString("{\n", data);
    PagePopupClient::addString("type: \"option\",\n", data);
    addProperty("label", element.text(), data);
    addProperty("title", element.title(), data);
    addProperty("value", element.listIndex(), data);
    addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr), data);
    addProperty("disabled", element.isDisabledFormControl(), data);
    addElementStyle(element, enableExtraStyling, data);
    PagePopupClient::addString("},\n", data);
}
HRESULT STDMETHODCALLTYPE DOMHTMLOptionElement::text( 
        /* [retval][out] */ BSTR* result)
{
    if (!result)
        return E_POINTER;

    *result = 0;

    ASSERT(m_element);
    ASSERT(m_element->hasTagName(optionTag));
    HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(m_element);

    *result = BString(optionElement->text()).release();
    return S_OK;
}
Exemple #4
0
HRESULT STDMETHODCALLTYPE DOMHTMLOptionElement::text( 
        /* [retval][out] */ BSTR* result)
{
    if (!result)
        return E_POINTER;

    *result = 0;

    ASSERT(m_element);
    ASSERT(isHTMLOptionElement(m_element));
    HTMLOptionElement* optionElement = toHTMLOptionElement(m_element);

    *result = BString(optionElement->text()).release();
    return S_OK;
}
void PopupMenuImpl::addOption(ItemIterationContext& context, HTMLOptionElement& element)
{
    SharedBuffer* data = context.m_buffer;
    PagePopupClient::addString("{", data);
    addProperty("label", element.text(), data);
    ASSERT(context.m_listIndex == element.listIndex());
    addProperty("value", context.m_listIndex++, data);
    if (!element.title().isEmpty())
        addProperty("title", element.title(), data);
    const AtomicString& ariaLabel = element.fastGetAttribute(HTMLNames::aria_labelAttr);
    if (!ariaLabel.isEmpty())
        addProperty("ariaLabel", ariaLabel, data);
    if (element.isDisabledFormControl())
        addProperty("disabled", true, data);
    addElementStyle(context, element);
    PagePopupClient::addString("},", data);
}
void DeprecatedRenderSelect::updateFromElement()
{
    m_ignoreSelectEvents = true;

    // change widget type
    bool oldMultiple = m_multiple;
    m_multiple = static_cast<HTMLSelectElement*>(node())->multiple();

    if (oldMultiple != m_multiple) {
        static_cast<ListBox*>(m_widget)->setSelectionMode(m_multiple ? ListBox::Extended : ListBox::Single);
        m_selectionChanged = true;
        m_optionsChanged = true;
    }

    // update contents listbox/combobox based on options in m_element
    if (m_optionsChanged) {
        static_cast<HTMLSelectElement*>(node())->recalcListItems();
        const Vector<HTMLElement*>& listItems = static_cast<HTMLSelectElement*>(node())->listItems();
        int listIndex;

        static_cast<ListBox*>(m_widget)->clear();
        
        bool groupEnabled = true;
        for (listIndex = 0; listIndex < int(listItems.size()); listIndex++) {
            if (listItems[listIndex]->hasTagName(optgroupTag)) {
                HTMLOptGroupElement* optgroupElement = static_cast<HTMLOptGroupElement*>(listItems[listIndex]);
                DeprecatedString label = optgroupElement->getAttribute(labelAttr).deprecatedString();
                label.replace('\\', backslashAsCurrencySymbol());
                
                // In WinIE, an optgroup can't start or end with whitespace (other than the indent
                // we give it).  We match this behavior.
                label = label.stripWhiteSpace();
                // We want to collapse our whitespace too.  This will match other browsers.
                label = label.simplifyWhiteSpace();

                groupEnabled = optgroupElement->isEnabled();
                
                static_cast<ListBox*>(m_widget)->appendGroupLabel(label, groupEnabled);

            } else if (listItems[listIndex]->hasTagName(optionTag)) {
                HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(listItems[listIndex]);
                DeprecatedString itemText = optionElement->text().deprecatedString();
                if (itemText.isEmpty())
                    itemText = optionElement->getAttribute(labelAttr).deprecatedString();
                
                itemText.replace('\\', backslashAsCurrencySymbol());

                // In WinIE, leading and trailing whitespace is ignored in options. We match this behavior.
                itemText = itemText.stripWhiteSpace();
                // We want to collapse our whitespace too.  This will match other browsers.
                itemText = itemText.simplifyWhiteSpace();
                
                if (listItems[listIndex]->parentNode()->hasTagName(optgroupTag))
                    itemText.prepend("    ");

                static_cast<ListBox*>(m_widget)->appendItem(itemText, groupEnabled && optionElement->isEnabled());
            } else
                ASSERT(false);
            m_selectionChanged = true;
        }
        static_cast<ListBox*>(m_widget)->doneAppendingItems();
        setNeedsLayoutAndMinMaxRecalc();
        m_optionsChanged = false;
    }

    // update selection
    if (m_selectionChanged)
        updateSelection();

    m_ignoreSelectEvents = false;

    RenderFormElement::updateFromElement();
}
static v8::Handle<v8::Value> textAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    HTMLOptionElement* imp = V8HTMLOptionElement::toNative(info.Holder());
    return v8String(imp->text(), info.GetIsolate());
}
Exemple #8
0
static v8::Handle<v8::Value> textAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
    INC_STATS("DOM.HTMLOptionElement.text._get");
    HTMLOptionElement* imp = V8HTMLOptionElement::toNative(info.Holder());
    return v8String(imp->text());
}