⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accessibilityrenderobject.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        return false;        // make a platform-specific decision    if (isAttachment())        return accessibilityIgnoreAttachment();        return !m_renderer->isListMarker() && !isWebArea();}bool AccessibilityRenderObject::isLoaded() const{    return !m_renderer->document()->tokenizer();}int AccessibilityRenderObject::layoutCount() const{    if (!m_renderer->isRenderView())        return 0;    return toRenderView(m_renderer)->frameView()->layoutCount();}String AccessibilityRenderObject::text() const{    if (!isTextControl() || isPasswordField())        return String();        if (isNativeTextControl())        return toRenderTextControl(m_renderer)->text();        Node* node = m_renderer->node();    if (!node)        return String();    if (!node->isElementNode())        return String();        return static_cast<Element*>(node)->innerText();}    int AccessibilityRenderObject::textLength() const{    ASSERT(isTextControl());        if (isPasswordField())        return -1; // need to return something distinct from 0        return text().length();}PassRefPtr<Range> AccessibilityRenderObject::ariaSelectedTextDOMRange() const{    Node* node = m_renderer->node();    if (!node)        return 0;        RefPtr<Range> currentSelectionRange = selection().toNormalizedRange();    if (!currentSelectionRange)        return 0;        ExceptionCode ec = 0;    if (!currentSelectionRange->intersectsNode(node, ec))        return Range::create(currentSelectionRange->ownerDocument());        RefPtr<Range> ariaRange = rangeOfContents(node);    Position startPosition, endPosition;        // Find intersection of currentSelectionRange and ariaRange    if (ariaRange->startOffset() > currentSelectionRange->startOffset())        startPosition = ariaRange->startPosition();    else        startPosition = currentSelectionRange->startPosition();        if (ariaRange->endOffset() < currentSelectionRange->endOffset())        endPosition = ariaRange->endPosition();    else        endPosition = currentSelectionRange->endPosition();        return Range::create(ariaRange->ownerDocument(), startPosition, endPosition);}String AccessibilityRenderObject::selectedText() const{    ASSERT(isTextControl());        if (isPasswordField())        return String(); // need to return something distinct from empty string        if (isNativeTextControl()) {        RenderTextControl* textControl = toRenderTextControl(m_renderer);        return textControl->text().substring(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());    }        if (ariaRoleAttribute() == UnknownRole)        return String();        RefPtr<Range> ariaRange = ariaSelectedTextDOMRange();    if (!ariaRange)        return String();    return ariaRange->text();}const AtomicString& AccessibilityRenderObject::accessKey() const{    Node* node = m_renderer->node();    if (!node)        return nullAtom;    if (!node->isElementNode())        return nullAtom;    return static_cast<Element*>(node)->getAttribute(accesskeyAttr);}VisibleSelection AccessibilityRenderObject::selection() const{    return m_renderer->document()->frame()->selection()->selection();}PlainTextRange AccessibilityRenderObject::selectedTextRange() const{    ASSERT(isTextControl());        if (isPasswordField())        return PlainTextRange();        AccessibilityRole ariaRole = ariaRoleAttribute();    if (isNativeTextControl() && ariaRole == UnknownRole) {        RenderTextControl* textControl = toRenderTextControl(m_renderer);        return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());    }        if (ariaRole == UnknownRole)        return PlainTextRange();        RefPtr<Range> ariaRange = ariaSelectedTextDOMRange();    if (!ariaRange)        return PlainTextRange();    return PlainTextRange(ariaRange->startOffset(), ariaRange->endOffset());}void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range){    if (isNativeTextControl()) {        RenderTextControl* textControl = toRenderTextControl(m_renderer);        textControl->setSelectionRange(range.start, range.start + range.length);        return;    }        Document* document = m_renderer->document();    if (!document)        return;    Frame* frame = document->frame();    if (!frame)        return;    Node* node = m_renderer->node();    frame->selection()->setSelection(VisibleSelection(Position(node, range.start),        Position(node, range.start + range.length), DOWNSTREAM));}KURL AccessibilityRenderObject::url() const{    if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {        if (HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(anchorElement()))            return anchor->href();    }        if (isWebArea())        return m_renderer->document()->url();        if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag))        return static_cast<HTMLImageElement*>(m_renderer->node())->src();        if (isInputImage())        return static_cast<HTMLInputElement*>(m_renderer->node())->src();        return KURL();}bool AccessibilityRenderObject::isVisited() const{    return m_renderer->style()->pseudoState() == PseudoVisited;}bool AccessibilityRenderObject::isSelected() const{    if (!m_renderer)        return false;        Node* node = m_renderer->node();    if (!node)        return false;        return false;}bool AccessibilityRenderObject::isFocused() const{    if (!m_renderer)        return false;        Document* document = m_renderer->document();    if (!document)        return false;        Node* focusedNode = document->focusedNode();    if (!focusedNode)        return false;        // A web area is represented by the Document node in the DOM tree, which isn't focusable.    // Check instead if the frame's selection controller is focused    if (focusedNode == m_renderer->node() ||         (roleValue() == WebAreaRole && document->frame()->selection()->isFocusedAndActive()))        return true;        return false;}void AccessibilityRenderObject::setFocused(bool on){    if (!canSetFocusAttribute())        return;        if (!on)        m_renderer->document()->setFocusedNode(0);    else {        if (m_renderer->node()->isElementNode())            static_cast<Element*>(m_renderer->node())->focus();        else            m_renderer->document()->setFocusedNode(m_renderer->node());    }}void AccessibilityRenderObject::setValue(const String& string){    // FIXME: Do we want to do anything here for ARIA textboxes?    if (m_renderer->isTextField()) {        HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());        input->setValue(string);    } else if (m_renderer->isTextArea()) {        HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(m_renderer->node());        textArea->setValue(string);    }}bool AccessibilityRenderObject::isEnabled() const{    ASSERT(m_renderer);    if (!m_renderer->node() || !m_renderer->node()->isElementNode())        return true;    FormControlElement* formControlElement = toFormControlElement(static_cast<Element*>(m_renderer->node()));    if (!formControlElement)        return true;    return formControlElement->isEnabled();    }RenderView* AccessibilityRenderObject::topRenderer() const{    return m_renderer->document()->topDocument()->renderView();}Document* AccessibilityRenderObject::document() const{    return m_renderer->document();}FrameView* AccessibilityRenderObject::topDocumentFrameView() const{    return topRenderer()->view()->frameView();}Widget* AccessibilityRenderObject::widget() const{    if (!m_renderer->isWidget())        return 0;        return static_cast<RenderWidget*>(m_renderer)->widget();}AXObjectCache* AccessibilityRenderObject::axObjectCache() const{    return m_renderer->document()->axObjectCache();}AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const{    // find an image that is using this map    if (!m_renderer || !map)        return 0;    RefPtr<HTMLCollection> coll = m_renderer->document()->images();    for (Node* curr = coll->firstItem(); curr; curr = coll->nextItem()) {        RenderObject* obj = curr->renderer();        if (!obj || !curr->hasTagName(imgTag))            continue;                // The HTMLImageElement's useMap() value includes the '#' symbol at the beginning,        // which has to be stripped off        if (static_cast<HTMLImageElement*>(curr)->useMap().substring(1) == map->getName())            return axObjectCache()->getOrCreate(obj);    }        return 0;}    void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result){    Document* document = m_renderer->document();    RefPtr<HTMLCollection> coll = document->links();    Node* curr = coll->firstItem();    while (curr) {        RenderObject* obj = curr->renderer();        if (obj) {            RefPtr<AccessibilityObject> axobj = document->axObjectCache()->getOrCreate(obj);            ASSERT(axobj);            ASSERT(axobj->roleValue() == WebCoreLinkRole);            if (!axobj->accessibilityIsIgnored())                result.append(axobj);        } else {            Node* parent = curr->parent();            if (parent && curr->hasTagName(areaTag) && parent->hasTagName(mapTag)) {                AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));                areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(curr));                areaObject->setHTMLMapElement(static_cast<HTMLMapElement*>(parent));                areaObject->setParent(accessibilityParentForImageMap(static_cast<HTMLMapElement*>(parent)));                result.append(areaObject);            }        }        curr = coll->nextItem();    }}FrameView* AccessibilityRenderObject::documentFrameView() const {     if (!m_renderer || !m_renderer->document())         return 0;     // this is the RenderObject's Document's Frame's FrameView     return m_renderer->document()->view();}Widget* AccessibilityRenderObject::widgetForAttachmentView() const{    if (!isAttachment())        return 0;    return static_cast<RenderWidget*>(m_renderer)->widget();}FrameView* AccessibilityRenderObject::frameViewIfRenderView() const{    if (!m_renderer->isRenderView())        return 0;    // this is the RenderObject's Document's renderer's FrameView    return m_renderer->view()->frameView();}// This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns// a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C fileVisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const{    if (!m_renderer)        return VisiblePositionRange();        // construct VisiblePositions for start and end    Node* node = m_renderer->node();    if (!node)        return VisiblePositionRange();        VisiblePosition startPos = VisiblePosition(node, 0, VP_DEFAULT_AFFINITY);    VisiblePosition endPos = VisiblePosition(node, maxDeepOffset(node), VP_DEFAULT_AFFINITY);        // the VisiblePositions are equal for nodes like buttons, so adjust for that    if (startPos == endPos) {        endPos = endPos.next();        if (endPos.isNull())            endPos = startPos;    }        return VisiblePositionRange(startPos, endPos);}VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const{    if (lineCount == 0 || !m_renderer)        return VisiblePositionRange();        // iterate over the lines    // FIXME: this is wrong when lineNumber is lineCount+1,  because nextLinePosition takes you to the    // last offset of the last line    VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForCoordinates(0, 0);    VisiblePosition savedVisiblePos;    while (--lineCount != 0) {        savedVisiblePos = visiblePos;        visiblePos = nextLinePosition(visiblePos, 0);        if (visiblePos.isNull() || visiblePos == savedVisiblePos)            return VisiblePositionRange();    }        // make a caret selection for the marker position, then extend it to the line    // NOTE: ignores results of sel.modify because it returns false when    // starting at an empty line.  The resulting selection in that case    // will be a caret at visiblePos.    SelectionController selection;    selection.setSelection(VisibleSelection(visiblePos));    selection.modify(SelectionController::EXTEND, SelectionController::RIGHT, LineBoundary);        return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());}    VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const{    if (!m_renderer)        return VisiblePosition();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -