bool canScrollInDirection(const Node* container, FocusDirection direction)
{
    ASSERT(container);

    if (isHTMLSelectElement(container))
        return false;

    if (container->isDocumentNode())
        return canScrollInDirection(toDocument(container)->frame(), direction);

    if (!isScrollableNode(container))
        return false;

    switch (direction) {
    case FocusDirectionLeft:
        return (container->renderer()->style().overflowX() != OHIDDEN && container->renderBox()->scrollLeft() > 0);
    case FocusDirectionUp:
        return (container->renderer()->style().overflowY() != OHIDDEN && container->renderBox()->scrollTop() > 0);
    case FocusDirectionRight:
        return (container->renderer()->style().overflowX() != OHIDDEN && container->renderBox()->scrollLeft() + container->renderBox()->clientWidth() < container->renderBox()->scrollWidth());
    case FocusDirectionDown:
        return (container->renderer()->style().overflowY() != OHIDDEN && container->renderBox()->scrollTop() + container->renderBox()->clientHeight() < container->renderBox()->scrollHeight());
    default:
        ASSERT_NOT_REACHED();
        return false;
    }
}
void WebFormControlElement::setAutofillValue(const WebString& value) {
  // The input and change events will be sent in setValue.
  if (isHTMLInputElement(*m_private) || isHTMLTextAreaElement(*m_private)) {
    if (!focused())
      unwrap<Element>()->dispatchFocusEvent(nullptr, WebFocusTypeForward,
                                            nullptr);
    unwrap<Element>()->dispatchScopedEvent(
        Event::createBubble(EventTypeNames::keydown));
    unwrap<HTMLTextFormControlElement>()->setValue(value,
                                                   DispatchInputAndChangeEvent);
    unwrap<Element>()->dispatchScopedEvent(
        Event::createBubble(EventTypeNames::keyup));
    if (!focused())
      unwrap<Element>()->dispatchBlurEvent(nullptr, WebFocusTypeForward,
                                           nullptr);
  } else if (isHTMLSelectElement(*m_private)) {
    if (!focused())
      unwrap<Element>()->dispatchFocusEvent(nullptr, WebFocusTypeForward,
                                            nullptr);
    unwrap<HTMLSelectElement>()->setValue(value, true);
    if (!focused())
      unwrap<Element>()->dispatchBlurEvent(nullptr, WebFocusTypeForward,
                                           nullptr);
  }
}
void WebFormControlElement::setSuggestedValue(const WebString& value) {
  if (isHTMLInputElement(*m_private))
    unwrap<HTMLInputElement>()->setSuggestedValue(value);
  else if (isHTMLTextAreaElement(*m_private))
    unwrap<HTMLTextAreaElement>()->setSuggestedValue(value);
  else if (isHTMLSelectElement(*m_private))
    unwrap<HTMLSelectElement>()->setSuggestedValue(value);
}
void WebFormControlElement::setValue(const WebString& value, bool sendEvents)
{
    if (isHTMLInputElement(*m_private))
        unwrap<HTMLInputElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
    else if (isHTMLTextAreaElement(*m_private))
        unwrap<HTMLTextAreaElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
    else if (isHTMLSelectElement(*m_private))
        unwrap<HTMLSelectElement>()->setValue(value, sendEvents);
}
bool WebFormControlElement::autoComplete() const {
  if (isHTMLInputElement(*m_private))
    return constUnwrap<HTMLInputElement>()->shouldAutocomplete();
  if (isHTMLTextAreaElement(*m_private))
    return constUnwrap<HTMLTextAreaElement>()->shouldAutocomplete();
  if (isHTMLSelectElement(*m_private))
    return constUnwrap<HTMLSelectElement>()->shouldAutocomplete();
  return false;
}
WebString WebFormControlElement::suggestedValue() const {
  if (isHTMLInputElement(*m_private))
    return constUnwrap<HTMLInputElement>()->suggestedValue();
  if (isHTMLTextAreaElement(*m_private))
    return constUnwrap<HTMLTextAreaElement>()->suggestedValue();
  if (isHTMLSelectElement(*m_private))
    return constUnwrap<HTMLSelectElement>()->suggestedValue();
  return WebString();
}
Example #7
0
// We don't make child style information if the popup will have a lot of items
// because of a performance problem.
// TODO(tkent): This is a workaround.  We should do a performance optimization.
bool PopupMenuImpl::hasTooManyItemsForStyling()
{
    // 300 is enough for world-wide countries.
    const unsigned styledChildrenLimit = 300;

    if (!isHTMLSelectElement(ownerElement()))
        return false;
    return toHTMLSelectElement(ownerElement()).listItems().size() > styledChildrenLimit;
}
Example #8
0
LayoutMenuList::LayoutMenuList(Element* element)
    : LayoutFlexibleBox(element),
      m_buttonText(nullptr),
      m_innerBlock(nullptr),
      m_isEmpty(false),
      m_hasUpdatedActiveOption(false),
      m_innerBlockHeight(LayoutUnit()),
      m_optionsWidth(0),
      m_lastActiveIndex(-1) {
  ASSERT(isHTMLSelectElement(element));
}
Example #9
0
bool WebFrame::containsAnyFormControls() const
{
    if (!m_coreFrame)
        return false;
    
    Document* document = m_coreFrame->document();
    if (!document)
        return false;

    for (Node* node = document->documentElement(); node; node = NodeTraversal::next(node)) {
        if (!node->isElementNode())
            continue;
        if (isHTMLInputElement(node) || isHTMLSelectElement(node) || isHTMLTextAreaElement(node))
            return true;
    }
    return false;
}
Example #10
0
HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode& select)
    : HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter)
{
    ASSERT(isHTMLSelectElement(select));
    ScriptWrappable::init(this);
}
HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode& select)
    : HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter)
{
    ASSERT(isHTMLSelectElement(select));
}
Example #12
0
LayoutListBox::LayoutListBox(Element* element) : LayoutBlockFlow(element) {
  ASSERT(element);
  ASSERT(element->isHTMLElement());
  ASSERT(isHTMLSelectElement(element));
}
Example #13
0
static void notifyChildrenSelectionChange(AccessibilityObject* object)
{
    // This static variables are needed to keep track of the old
    // focused object and its associated list object, as per previous
    // calls to this function, in order to properly decide whether to
    // emit some signals or not.
    static NeverDestroyed<RefPtr<AccessibilityObject>> oldListObject;
    static NeverDestroyed<RefPtr<AccessibilityObject>> oldFocusedObject;

    // Only list boxes and menu lists supported so far.
    if (!object || !(object->isListBox() || object->isMenuList()))
        return;

    // Only support HTML select elements so far (ARIA selectors not supported).
    Node* node = object->node();
    if (!node || !isHTMLSelectElement(node))
        return;

    // Emit signal from the listbox's point of view first.
    g_signal_emit_by_name(object->wrapper(), "selection-changed");

    // Find the item where the selection change was triggered from.
    HTMLSelectElement* select = toHTMLSelectElement(node);
    if (!select)
        return;
    int changedItemIndex = select->activeSelectionStartListIndex();

    AccessibilityObject* listObject = getListObject(object);
    if (!listObject) {
        oldListObject.get() = 0;
        return;
    }

    const AccessibilityObject::AccessibilityChildrenVector& items = listObject->children();
    if (changedItemIndex < 0 || changedItemIndex >= static_cast<int>(items.size()))
        return;
    AccessibilityObject* item = items.at(changedItemIndex).get();

    // Ensure the current list object is the same than the old one so
    // further comparisons make sense. Otherwise, just reset
    // oldFocusedObject so it won't be taken into account.
    if (oldListObject.get() != listObject)
        oldFocusedObject.get() = 0;

    AtkObject* axItem = item ? item->wrapper() : 0;
    AtkObject* axOldFocusedObject = oldFocusedObject.get() ? oldFocusedObject.get()->wrapper() : 0;

    // Old focused object just lost focus, so emit the events.
    if (axOldFocusedObject && axItem != axOldFocusedObject) {
        g_signal_emit_by_name(axOldFocusedObject, "focus-event", false);
        atk_object_notify_state_change(axOldFocusedObject, ATK_STATE_FOCUSED, false);
    }

    // Emit needed events for the currently (un)selected item.
    if (axItem) {
        bool isSelected = item->isSelected();
        atk_object_notify_state_change(axItem, ATK_STATE_SELECTED, isSelected);
        g_signal_emit_by_name(axItem, "focus-event", isSelected);
        atk_object_notify_state_change(axItem, ATK_STATE_FOCUSED, isSelected);
    }

    // Update pointers to the previously involved objects.
    oldListObject.get() = listObject;
    oldFocusedObject.get() = item;
}