SelectorCheckerTestFunctions.h [plain text]
#ifndef SelectorCheckerTestFunctions_h
#define SelectorCheckerTestFunctions_h
#include "HTMLInputElement.h"
#include "HTMLOptionElement.h"
#include <wtf/Compiler.h>
#if ENABLE(VIDEO_TRACK)
#include "WebVTTElement.h"
#endif
namespace WebCore {
ALWAYS_INLINE bool isAutofilled(const Element* element)
{
if (element->isFormControlElement()) {
if (const HTMLInputElement* inputElement = element->toInputElement())
return inputElement->isAutofilled();
}
return false;
}
ALWAYS_INLINE bool isDefaultButtonForForm(const Element* element)
{
return element->isDefaultButtonForForm();
}
ALWAYS_INLINE bool isDisabled(const Element* element)
{
if (element->isFormControlElement() || isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
return element->isDisabledFormControl();
return false;
}
ALWAYS_INLINE bool isEnabled(const Element* element)
{
if (element->isFormControlElement() || isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
return !element->isDisabledFormControl();
return false;
}
ALWAYS_INLINE bool isChecked(Element* element)
{
const HTMLInputElement* inputElement = element->toInputElement();
if (inputElement && inputElement->shouldAppearChecked() && !inputElement->shouldAppearIndeterminate())
return true;
if (isHTMLOptionElement(element) && toHTMLOptionElement(element)->selected())
return true;
return false;
}
ALWAYS_INLINE bool isInRange(Element* element)
{
element->document().setContainsValidityStyleRules();
return element->isInRange();
}
ALWAYS_INLINE bool isOutOfRange(Element* element)
{
element->document().setContainsValidityStyleRules();
return element->isOutOfRange();
}
ALWAYS_INLINE bool isInvalid(const Element* element)
{
element->document().setContainsValidityStyleRules();
return element->willValidate() && !element->isValidFormControlElement();
}
ALWAYS_INLINE bool isOptionalFormControl(const Element* element)
{
return element->isOptionalFormControl();
}
ALWAYS_INLINE bool isRequiredFormControl(const Element* element)
{
return element->isRequiredFormControl();
}
ALWAYS_INLINE bool isValid(const Element* element)
{
element->document().setContainsValidityStyleRules();
return element->willValidate() && element->isValidFormControlElement();
}
inline bool matchesLangPseudoClass(const Element* element, AtomicStringImpl* filter)
{
AtomicString value;
#if ENABLE(VIDEO_TRACK)
if (element->isWebVTTElement())
value = toWebVTTElement(element)->language();
else
#endif
value = element->computeInheritedLanguage();
if (value.isNull())
return false;
if (value.impl() == filter)
return true;
if (value.impl()->startsWith(filter, false)) {
if (value.length() == filter->length())
return true;
return value[filter->length()] == '-';
}
return false;
}
ALWAYS_INLINE bool matchesReadOnlyPseudoClass(const Element* element)
{
return element->matchesReadOnlyPseudoClass();
}
ALWAYS_INLINE bool matchesReadWritePseudoClass(const Element* element)
{
return element->matchesReadWritePseudoClass();
}
ALWAYS_INLINE bool shouldAppearIndeterminate(const Element* element)
{
return element->shouldAppearIndeterminate();
}
#if ENABLE(FULLSCREEN_API)
ALWAYS_INLINE bool matchesFullScreenPseudoClass(const Element* element)
{
if (element->isFrameElementBase() && element->containsFullScreenElement())
return true;
if (!element->document().webkitIsFullScreen())
return false;
return element == element->document().webkitCurrentFullScreenElement();
}
#endif
#if ENABLE(VIDEO_TRACK)
ALWAYS_INLINE bool matchesFutureCuePseudoClass(const Element* element)
{
return (element->isWebVTTElement() && !toWebVTTElement(element)->isPastNode());
}
ALWAYS_INLINE bool matchesPastCuePseudoClass(const Element* element)
{
return (element->isWebVTTElement() && toWebVTTElement(element)->isPastNode());
}
#endif
}
#endif // SelectorCheckerTestFunctions_h