📄 accessibilityrenderobject.cpp
字号:
/** Copyright (C) 2008 Apple Inc. All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** 1. Redistributions of source code must retain the above copyright* notice, this list of conditions and the following disclaimer.* 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in the* documentation and/or other materials provided with the distribution.* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of* its contributors may be used to endorse or promote products derived* from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#include "config.h"#include "AccessibilityRenderObject.h"#include "AXObjectCache.h"#include "AccessibilityListBox.h"#include "AccessibilityImageMapLink.h"#include "CharacterNames.h"#include "EventNames.h"#include "FloatRect.h"#include "FocusController.h"#include "Frame.h"#include "FrameLoader.h"#include "HTMLAreaElement.h"#include "HTMLFrameElementBase.h"#include "HTMLImageElement.h"#include "HTMLInputElement.h"#include "HTMLLabelElement.h"#include "HTMLMapElement.h"#include "HTMLOptGroupElement.h"#include "HTMLOptionElement.h"#include "HTMLOptionsCollection.h"#include "HTMLSelectElement.h"#include "HTMLTextAreaElement.h"#include "HitTestRequest.h"#include "HitTestResult.h"#include "LocalizedStrings.h"#include "NodeList.h"#include "NotImplemented.h"#include "Page.h"#include "RenderFieldset.h"#include "RenderFileUploadControl.h"#include "RenderImage.h"#include "RenderInline.h"#include "RenderListBox.h"#include "RenderListMarker.h"#include "RenderMenuList.h"#include "RenderText.h"#include "RenderTextControl.h"#include "RenderTheme.h"#include "RenderView.h"#include "RenderWidget.h"#include "SelectionController.h"#include "Text.h"#include "TextIterator.h"#include "htmlediting.h"#include "visible_units.h"#include <wtf/StdLibExtras.h>using namespace std;namespace WebCore {using namespace HTMLNames;AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer) : m_renderer(renderer) , m_ariaRole(UnknownRole){ setAriaRole();#ifndef NDEBUG m_renderer->setHasAXObject(true);#endif}AccessibilityRenderObject::~AccessibilityRenderObject(){ ASSERT(isDetached());}PassRefPtr<AccessibilityRenderObject> AccessibilityRenderObject::create(RenderObject* renderer){ return adoptRef(new AccessibilityRenderObject(renderer));}void AccessibilityRenderObject::detach(){ clearChildren(); AccessibilityObject::detach(); #ifndef NDEBUG if (m_renderer) m_renderer->setHasAXObject(false);#endif m_renderer = 0; }AccessibilityObject* AccessibilityRenderObject::firstChild() const{ if (!m_renderer) return 0; RenderObject* firstChild = m_renderer->firstChild(); if (!firstChild) return 0; return m_renderer->document()->axObjectCache()->getOrCreate(firstChild);}AccessibilityObject* AccessibilityRenderObject::lastChild() const{ if (!m_renderer) return 0; RenderObject* lastChild = m_renderer->lastChild(); if (!lastChild) return 0; return m_renderer->document()->axObjectCache()->getOrCreate(lastChild);}AccessibilityObject* AccessibilityRenderObject::previousSibling() const{ if (!m_renderer) return 0; RenderObject* previousSibling = m_renderer->previousSibling(); if (!previousSibling) return 0; return m_renderer->document()->axObjectCache()->getOrCreate(previousSibling);}AccessibilityObject* AccessibilityRenderObject::nextSibling() const{ if (!m_renderer) return 0; RenderObject* nextSibling = m_renderer->nextSibling(); if (!nextSibling) return 0; return m_renderer->document()->axObjectCache()->getOrCreate(nextSibling);}AccessibilityObject* AccessibilityRenderObject::parentObjectIfExists() const{ if (!m_renderer) return 0; RenderObject *parent = m_renderer->parent(); if (!parent) return 0; return m_renderer->document()->axObjectCache()->get(parent);} AccessibilityObject* AccessibilityRenderObject::parentObject() const{ if (!m_renderer) return 0; RenderObject *parent = m_renderer->parent(); if (!parent) return 0; if (ariaRoleAttribute() == MenuBarRole) return m_renderer->document()->axObjectCache()->getOrCreate(parent); // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child if (ariaRoleAttribute() == MenuRole) { AccessibilityObject* parent = menuButtonForMenu(); if (parent) return parent; } return m_renderer->document()->axObjectCache()->getOrCreate(parent);}bool AccessibilityRenderObject::isWebArea() const{ return roleValue() == WebAreaRole;}bool AccessibilityRenderObject::isImageButton() const{ return isNativeImage() && roleValue() == ButtonRole;}bool AccessibilityRenderObject::isAnchor() const{ return !isNativeImage() && isLink();}bool AccessibilityRenderObject::isNativeTextControl() const{ return m_renderer->isTextControl();} bool AccessibilityRenderObject::isTextControl() const{ AccessibilityRole role = roleValue(); return role == TextAreaRole || role == TextFieldRole;}bool AccessibilityRenderObject::isNativeImage() const{ return m_renderer->isImage();} bool AccessibilityRenderObject::isImage() const{ return roleValue() == ImageRole;}bool AccessibilityRenderObject::isAttachment() const{ if (!m_renderer) return false; // Widgets are the replaced elements that we represent to AX as attachments bool isWidget = m_renderer && m_renderer->isWidget(); ASSERT(!isWidget || (m_renderer->isReplaced() && !isImage())); return isWidget && ariaRoleAttribute() == UnknownRole;}bool AccessibilityRenderObject::isPasswordField() const{ ASSERT(m_renderer); if (!m_renderer->node() || !m_renderer->node()->isHTMLElement()) return false; if (ariaRoleAttribute() != UnknownRole) return false; InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node())); if (!inputElement) return false; return inputElement->isPasswordField();}bool AccessibilityRenderObject::isCheckboxOrRadio() const{ AccessibilityRole role = roleValue(); return role == RadioButtonRole || role == CheckBoxRole;} bool AccessibilityRenderObject::isFileUploadButton() const{ if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) { HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node()); return input->inputType() == HTMLInputElement::FILE; } return false;} bool AccessibilityRenderObject::isInputImage() const{ if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) { HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node()); return input->inputType() == HTMLInputElement::IMAGE; } return false;}bool AccessibilityRenderObject::isProgressIndicator() const{ return roleValue() == ProgressIndicatorRole;}bool AccessibilityRenderObject::isSlider() const{ return roleValue() == SliderRole;} bool AccessibilityRenderObject::isMenuRelated() const{ AccessibilityRole role = roleValue(); return role == MenuRole || role == MenuBarRole || role == MenuButtonRole || role == MenuItemRole;} bool AccessibilityRenderObject::isMenu() const{ return roleValue() == MenuRole;}bool AccessibilityRenderObject::isMenuBar() const{ return roleValue() == MenuBarRole;}bool AccessibilityRenderObject::isMenuButton() const{ return roleValue() == MenuButtonRole;}bool AccessibilityRenderObject::isMenuItem() const{ return roleValue() == MenuItemRole;} bool AccessibilityRenderObject::isPressed() const{ ASSERT(m_renderer); if (roleValue() != ButtonRole) return false; Node* node = m_renderer->node(); if (!node) return false; // If this is an ARIA button, check the aria-pressed attribute rather than node()->active() if (ariaRoleAttribute() == ButtonRole) { if (equalIgnoringCase(getAttribute(aria_pressedAttr).string(), "true")) return true; return false; } return node->active();}bool AccessibilityRenderObject::isIndeterminate() const{ ASSERT(m_renderer); if (!m_renderer->node() || !m_renderer->node()->isElementNode()) return false; InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node())); if (!inputElement) return false; return inputElement->isIndeterminate();}bool AccessibilityRenderObject::isChecked() const{ ASSERT(m_renderer); if (!m_renderer->node() || !m_renderer->node()->isElementNode()) return false; InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node())); if (!inputElement) return false; return inputElement->isChecked();}bool AccessibilityRenderObject::isHovered() const{ ASSERT(m_renderer); return m_renderer->node() && m_renderer->node()->hovered();}bool AccessibilityRenderObject::isMultiSelect() const{ ASSERT(m_renderer); if (!m_renderer->isListBox()) return false; return m_renderer->node() && static_cast<HTMLSelectElement*>(m_renderer->node())->multiple();} bool AccessibilityRenderObject::isReadOnly() const{ ASSERT(m_renderer); if (isWebArea()) { Document* document = m_renderer->document(); if (!document) return true; HTMLElement* body = document->body(); if (body && body->isContentEditable()) return false; Frame* frame = document->frame(); if (!frame) return true; return !frame->isContentEditable(); } return !m_renderer->node() || !m_renderer->node()->isContentEditable();}bool AccessibilityRenderObject::isOffScreen() const{ ASSERT(m_renderer); IntRect contentRect = m_renderer->absoluteClippedOverflowRect(); FrameView* view = m_renderer->document()->frame()->view(); FloatRect viewRect = view->visibleContentRect();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -