2001-09-25 04:48:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-04-18 03:06:38 +04:00
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
#include "HTMLFormControlAccessible.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-07-28 08:21:40 +04:00
|
|
|
#include "nsEventShell.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsTextEquivUtils.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Relation.h"
|
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2012-05-30 17:34:33 +04:00
|
|
|
#include "nsContentList.h"
|
2013-03-28 23:41:32 +04:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2017-10-31 02:14:51 +03:00
|
|
|
#include "mozilla/dom/HTMLTextAreaElement.h"
|
2007-08-14 20:25:24 +04:00
|
|
|
#include "nsIEditor.h"
|
2012-05-30 17:34:33 +04:00
|
|
|
#include "nsIFormControl.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2003-04-15 12:45:55 +04:00
|
|
|
#include "nsISelectionController.h"
|
2007-07-25 10:24:00 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2006-07-12 17:14:53 +04:00
|
|
|
#include "nsITextControlFrame.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-12-12 05:51:58 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2001-04-18 03:06:38 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-11-20 01:01:15 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2012-05-08 09:10:31 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-11-24 08:38:02 +03:00
|
|
|
#include "mozilla/TextControlElement.h"
|
2017-08-07 11:42:50 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2012-05-08 09:10:31 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-28 23:41:32 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2018-11-02 04:06:56 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLFormAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
role HTMLFormAccessible::NativeRole() const {
|
|
|
|
nsAutoString name;
|
|
|
|
const_cast<HTMLFormAccessible*>(this)->Name(name);
|
|
|
|
return name.IsEmpty() ? roles::FORM : roles::FORM_LANDMARK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtom* HTMLFormAccessible::LandmarkRole() const {
|
|
|
|
if (!HasOwnContent()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only return xml-roles "form" if the form has an accessible name.
|
|
|
|
nsAutoString name;
|
|
|
|
const_cast<HTMLFormAccessible*>(this)->Name(name);
|
|
|
|
return name.IsEmpty() ? nullptr : nsGkAtoms::form;
|
|
|
|
}
|
|
|
|
|
2010-01-06 13:36:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLRadioButtonAccessible
|
2010-01-06 13:36:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-04-18 03:06:38 +04:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HTMLRadioButtonAccessible::NativeState() const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t state = AccessibleWrap::NativeState();
|
2007-04-02 19:56:24 +04:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
state |= states::CHECKABLE;
|
2001-09-18 07:09:01 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* input = HTMLInputElement::FromNode(mContent);
|
2012-06-03 15:36:51 +04:00
|
|
|
if (input && input->Checked()) state |= states::CHECKED;
|
2001-09-18 07:09:01 +04:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
return state;
|
2001-09-18 07:09:01 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void HTMLRadioButtonAccessible::GetPositionAndSizeInternal(int32_t* aPosInSet,
|
|
|
|
int32_t* aSetSize) {
|
|
|
|
int32_t namespaceId = mContent->NodeInfo()->NamespaceID();
|
2007-03-27 16:17:11 +04:00
|
|
|
nsAutoString tagName;
|
2010-06-11 12:23:18 +04:00
|
|
|
mContent->NodeInfo()->GetName(tagName);
|
2007-04-03 12:27:43 +04:00
|
|
|
|
|
|
|
nsAutoString type;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type);
|
2007-04-03 12:27:43 +04:00
|
|
|
nsAutoString name;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
|
2007-04-03 12:27:43 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsContentList> inputElms;
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2012-05-30 17:34:33 +04:00
|
|
|
nsCOMPtr<nsIFormControl> formControlNode(do_QueryInterface(mContent));
|
|
|
|
dom::Element* formElm = formControlNode->GetFormElement();
|
|
|
|
if (formElm)
|
|
|
|
inputElms = NS_GetContentList(formElm, namespaceId, tagName);
|
|
|
|
else
|
|
|
|
inputElms = NS_GetContentList(mContent->OwnerDoc(), namespaceId, tagName);
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(inputElms);
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t inputCount = inputElms->Length(false);
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2010-01-06 13:36:50 +03:00
|
|
|
// Compute posinset and setsize.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t indexOf = 0;
|
|
|
|
int32_t count = 0;
|
2007-04-03 12:27:43 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < inputCount; index++) {
|
2012-05-30 17:34:33 +04:00
|
|
|
nsIContent* inputElm = inputElms->Item(index, false);
|
2017-12-07 21:13:50 +03:00
|
|
|
if (inputElm->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
type, eCaseMatters) &&
|
|
|
|
inputElm->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
name, eCaseMatters) &&
|
|
|
|
mDoc->HasAccessible(inputElm)) {
|
2013-02-21 20:31:40 +04:00
|
|
|
count++;
|
2012-05-30 17:34:33 +04:00
|
|
|
if (inputElm == mContent) indexOf = count;
|
2007-03-27 16:17:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 13:36:50 +03:00
|
|
|
*aPosInSet = indexOf;
|
|
|
|
*aSetSize = count;
|
2007-03-27 16:17:11 +04:00
|
|
|
}
|
|
|
|
|
2010-01-06 13:36:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLButtonAccessible
|
2010-01-06 13:36:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-04-18 03:06:38 +04:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLButtonAccessible::HTMLButtonAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {
|
2014-04-04 12:01:19 +04:00
|
|
|
mGenericTypes |= eButton;
|
2001-04-18 03:06:38 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
uint8_t HTMLButtonAccessible::ActionCount() const { return 1; }
|
2001-05-12 01:11:38 +04:00
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
void HTMLButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
|
|
|
|
if (aIndex == eAction_Click) aName.AssignLiteral("press");
|
2001-04-18 03:06:38 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
bool HTMLButtonAccessible::DoAction(uint8_t aIndex) const {
|
2010-01-25 18:09:25 +03:00
|
|
|
if (aIndex != eAction_Click) return false;
|
|
|
|
|
|
|
|
DoCommand();
|
2014-09-16 21:30:23 +04:00
|
|
|
return true;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
uint64_t HTMLButtonAccessible::State() {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::State();
|
2011-11-30 16:36:20 +04:00
|
|
|
if (state == states::DEFUNCT) return state;
|
|
|
|
|
|
|
|
// Inherit states from input@type="file" suitable for the button. Note,
|
|
|
|
// no special processing for unavailable state since inheritance is supplied
|
|
|
|
// other code paths.
|
|
|
|
if (mParent && mParent->IsHTMLFileInput()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t parentState = mParent->State();
|
2011-11-30 16:36:20 +04:00
|
|
|
state |= parentState & (states::BUSY | states::REQUIRED | states::HASPOPUP |
|
|
|
|
states::INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HTMLButtonAccessible::NativeState() const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeState();
|
2008-02-11 15:12:17 +03:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates elmState = mContent->AsElement()->State();
|
2011-10-03 18:26:18 +04:00
|
|
|
if (elmState.HasState(NS_EVENT_STATE_DEFAULT)) state |= states::DEFAULT;
|
2002-03-10 08:14:24 +03:00
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
return state;
|
2002-03-10 08:14:24 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLButtonAccessible::NativeRole() const { return roles::PUSHBUTTON; }
|
2001-04-18 03:06:38 +04:00
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLButtonAccessible::NativeName(nsString& aName) const {
|
2013-02-03 08:49:18 +04:00
|
|
|
// No need to check @value attribute for buttons since this attribute results
|
|
|
|
// in native anonymous text node and the name is calculated from subtree.
|
|
|
|
// The same magic works for @alt and @value attributes in case of type="image"
|
|
|
|
// element that has no valid @src (note if input@type="image" has an image
|
|
|
|
// then neither @alt nor @value attributes are used to generate a visual label
|
|
|
|
// and thus we need to obtain the accessible name directly from attribute
|
|
|
|
// value). Also the same algorithm works in case of default labels for
|
|
|
|
// type="submit"/"reset"/"image" elements.
|
|
|
|
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!aName.IsEmpty() || !mContent->IsHTMLElement(nsGkAtoms::input) ||
|
2017-12-07 21:13:50 +03:00
|
|
|
!mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::image, eCaseMatters))
|
2012-10-17 10:38:16 +04:00
|
|
|
return nameFlag;
|
2008-10-14 12:27:02 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName))
|
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
|
2008-10-14 12:27:02 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
aName.CompressWhitespace();
|
|
|
|
return eNameOK;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 07:13:08 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLButtonAccessible: Widgets
|
2011-09-29 07:13:08 +04:00
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
bool HTMLButtonAccessible::IsWidget() const { return true; }
|
2001-05-12 01:11:38 +04:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLTextFieldAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLTextFieldAccessible::HTMLTextFieldAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {
|
2018-03-16 14:02:00 +03:00
|
|
|
mType = mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::password, eIgnoreCase)
|
|
|
|
? eHTMLTextPasswordFieldType
|
|
|
|
: eHTMLTextFieldType;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLTextFieldAccessible::NativeRole() const {
|
2018-03-16 14:02:00 +03:00
|
|
|
if (mType == eHTMLTextPasswordFieldType) {
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::PASSWORD_TEXT;
|
2006-06-16 21:13:37 +04:00
|
|
|
}
|
2013-12-11 07:19:26 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::ENTRY;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 07:21:24 +04:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
HTMLTextFieldAccessible::NativeAttributes() {
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
HyperTextAccessibleWrap::NativeAttributes();
|
|
|
|
|
|
|
|
// Expose type for text input elements as it gives some useful context,
|
|
|
|
// especially for mobile.
|
|
|
|
nsAutoString type;
|
2018-08-31 15:11:00 +03:00
|
|
|
// In the case of this element being part of a binding, the binding's
|
|
|
|
// parent's type should have precedence. For example an input[type=number]
|
|
|
|
// has an embedded anonymous input[type=text] (along with spinner buttons).
|
|
|
|
// In that case, we would want to take the input type from the parent
|
|
|
|
// and not the anonymous content.
|
2019-05-08 16:43:58 +03:00
|
|
|
nsIContent* widgetElm = BindingOrWidgetParent();
|
2018-08-31 15:11:00 +03:00
|
|
|
if ((widgetElm && widgetElm->AsElement()->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::type, type)) ||
|
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
type)) {
|
2013-10-25 07:21:24 +04:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::textInputType, type);
|
2016-07-12 22:34:13 +03:00
|
|
|
if (!ARIARoleMap() && type.EqualsLiteral("search")) {
|
2015-02-27 17:41:57 +03:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles,
|
|
|
|
NS_LITERAL_STRING("searchbox"));
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 07:21:24 +04:00
|
|
|
|
2019-02-18 12:21:32 +03:00
|
|
|
// If this element has the placeholder attribute set,
|
|
|
|
// and if that is not identical to the name, expose it as an object attribute.
|
|
|
|
nsAutoString placeholderText;
|
|
|
|
if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder,
|
|
|
|
placeholderText)) {
|
|
|
|
nsAutoString name;
|
|
|
|
const_cast<HTMLTextFieldAccessible*>(this)->Name(name);
|
|
|
|
if (!name.Equals(placeholderText)) {
|
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::placeholder,
|
|
|
|
placeholderText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 07:21:24 +04:00
|
|
|
return attributes.forget();
|
|
|
|
}
|
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLTextFieldAccessible::NativeName(nsString& aName) const {
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2008-10-10 16:26:55 +04:00
|
|
|
if (!aName.IsEmpty()) return nameFlag;
|
|
|
|
|
2013-12-08 01:37:04 +04:00
|
|
|
// If part of compound of XUL widget then grab a name from XUL widget element.
|
2019-05-08 16:43:58 +03:00
|
|
|
nsIContent* widgetElm = BindingOrWidgetParent();
|
2013-12-08 01:37:04 +04:00
|
|
|
if (widgetElm) XULElmName(mDoc, widgetElm, aName);
|
2010-11-08 16:33:25 +03:00
|
|
|
|
|
|
|
if (!aName.IsEmpty()) return eNameOK;
|
2007-06-15 05:50:37 +04:00
|
|
|
|
2010-11-08 16:33:25 +03:00
|
|
|
// text inputs and textareas might have useful placeholder text
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder,
|
|
|
|
aName);
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2007-06-15 05:50:37 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:55:28 +03:00
|
|
|
void HTMLTextFieldAccessible::Value(nsString& aValue) const {
|
2012-04-09 13:48:41 +04:00
|
|
|
aValue.Truncate();
|
2011-04-10 03:38:06 +04:00
|
|
|
if (NativeState() & states::PROTECTED) // Don't return password text!
|
2012-04-09 13:48:41 +04:00
|
|
|
return;
|
2001-09-18 07:09:01 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent);
|
2001-05-12 01:11:38 +04:00
|
|
|
if (textArea) {
|
2012-04-09 13:48:41 +04:00
|
|
|
textArea->GetValue(aValue);
|
|
|
|
return;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
2012-12-23 04:54:13 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* input = HTMLInputElement::FromNode(mContent);
|
2016-11-15 20:46:32 +03:00
|
|
|
if (input) {
|
|
|
|
// Pass NonSystem as the caller type, to be safe. We don't expect to have a
|
|
|
|
// file input here.
|
|
|
|
input->GetValue(aValue, CallerType::NonSystem);
|
|
|
|
}
|
2001-04-18 03:06:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void HTMLTextFieldAccessible::ApplyARIAState(uint64_t* aState) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessibleWrap::ApplyARIAState(aState);
|
2012-04-05 20:23:30 +04:00
|
|
|
aria::MapToState(aria::eARIAAutoComplete, mContent->AsElement(), aState);
|
2013-12-08 01:37:04 +04:00
|
|
|
|
|
|
|
// If part of compound of XUL widget then pick up ARIA stuff from XUL widget
|
|
|
|
// element.
|
2019-05-08 16:43:58 +03:00
|
|
|
nsIContent* widgetElm = BindingOrWidgetParent();
|
2013-12-08 01:37:04 +04:00
|
|
|
if (widgetElm)
|
|
|
|
aria::MapToState(aria::eARIAAutoComplete, widgetElm->AsElement(), aState);
|
2011-11-30 16:36:20 +04:00
|
|
|
}
|
2011-09-01 19:37:24 +04:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HTMLTextFieldAccessible::NativeState() const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeState();
|
2006-06-16 21:13:37 +04:00
|
|
|
|
2014-01-21 20:24:23 +04:00
|
|
|
// Text fields are always editable, even if they are also read only or
|
|
|
|
// disabled.
|
|
|
|
state |= states::EDITABLE;
|
|
|
|
|
2005-03-15 02:10:53 +03:00
|
|
|
// can be focusable, focused, protected. readonly, unavailable, selected
|
2017-12-07 21:13:50 +03:00
|
|
|
if (mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::password, eIgnoreCase)) {
|
2011-04-10 03:38:06 +04:00
|
|
|
state |= states::PROTECTED;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
2006-06-16 21:13:37 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly)) {
|
2011-04-10 03:38:06 +04:00
|
|
|
state |= states::READONLY;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
2006-06-16 21:13:37 +04:00
|
|
|
// Is it an <input> or a <textarea> ?
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement* input = HTMLInputElement::FromNode(mContent);
|
2012-06-03 15:36:51 +04:00
|
|
|
state |= input && input->IsSingleLineTextControl() ? states::SINGLE_LINE
|
|
|
|
: states::MULTI_LINE;
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2014-01-21 20:24:23 +04:00
|
|
|
if (state & (states::PROTECTED | states::MULTI_LINE | states::READONLY |
|
|
|
|
states::UNAVAILABLE))
|
2011-09-28 05:46:11 +04:00
|
|
|
return state;
|
2006-06-16 21:13:37 +04:00
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
// Expose autocomplete states if this input is part of autocomplete widget.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* widget = ContainerWidget();
|
2011-09-28 05:46:11 +04:00
|
|
|
if (widget && widget - IsAutoComplete()) {
|
|
|
|
state |= states::HASPOPUP | states::SUPPORTS_AUTOCOMPLETION;
|
2011-04-10 03:38:06 +04:00
|
|
|
return state;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
2008-07-02 12:42:58 +04:00
|
|
|
|
2011-10-07 10:02:18 +04:00
|
|
|
// Expose autocomplete state if it has associated autocomplete list.
|
2018-03-14 02:27:25 +03:00
|
|
|
if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::list_))
|
2013-06-04 10:52:39 +04:00
|
|
|
return state | states::SUPPORTS_AUTOCOMPLETION | states::HASPOPUP;
|
2011-10-07 10:02:18 +04:00
|
|
|
|
2013-12-08 01:37:04 +04:00
|
|
|
// Ordinal XUL textboxes don't support autocomplete.
|
2019-05-25 20:46:15 +03:00
|
|
|
if (!BindingOrWidgetParent() &&
|
|
|
|
Preferences::GetBool("browser.formfill.enable")) {
|
2007-04-06 02:14:08 +04:00
|
|
|
// Check to see if autocompletion is allowed on this input. We don't expose
|
|
|
|
// it for password fields even though the entire password can be remembered
|
|
|
|
// for a page if the user asks it to be. However, the kind of autocomplete
|
|
|
|
// we're talking here is based on what the user types, where a popup of
|
|
|
|
// possible choices comes up.
|
|
|
|
nsAutoString autocomplete;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::autocomplete,
|
|
|
|
autocomplete);
|
2007-04-06 02:14:08 +04:00
|
|
|
|
|
|
|
if (!autocomplete.LowerCaseEqualsLiteral("off")) {
|
2017-12-07 21:13:50 +03:00
|
|
|
Element* formElement = input->GetFormElement();
|
|
|
|
if (formElement) {
|
|
|
|
formElement->GetAttr(kNameSpaceID_None, nsGkAtoms::autocomplete,
|
2011-06-04 01:35:17 +04:00
|
|
|
autocomplete);
|
2007-04-06 01:52:03 +04:00
|
|
|
}
|
2007-04-06 02:14:08 +04:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!formElement || !autocomplete.LowerCaseEqualsLiteral("off"))
|
2011-04-10 03:38:06 +04:00
|
|
|
state |= states::SUPPORTS_AUTOCOMPLETION;
|
2007-03-13 06:22:44 +03:00
|
|
|
}
|
2006-06-16 21:13:37 +04:00
|
|
|
}
|
|
|
|
|
2011-04-10 03:38:06 +04:00
|
|
|
return state;
|
2005-03-15 02:10:53 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
uint8_t HTMLTextFieldAccessible::ActionCount() const { return 1; }
|
2004-06-01 09:25:00 +04:00
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
void HTMLTextFieldAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
|
2007-02-25 06:43:20 +03:00
|
|
|
if (aIndex == eAction_Click) aName.AssignLiteral("activate");
|
2004-06-01 09:25:00 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
bool HTMLTextFieldAccessible::DoAction(uint8_t aIndex) const {
|
2014-09-16 21:30:23 +04:00
|
|
|
if (aIndex != 0) return false;
|
2012-04-12 15:11:40 +04:00
|
|
|
|
2019-11-21 13:42:36 +03:00
|
|
|
if (FocusMgr()->IsFocused(this)) {
|
|
|
|
// This already has focus, so TakeFocus()will do nothing. However, the user
|
|
|
|
// might be activating this element because they dismissed a touch keyboard
|
|
|
|
// and want to bring it back.
|
|
|
|
DoCommand();
|
|
|
|
} else {
|
|
|
|
TakeFocus();
|
|
|
|
}
|
2014-09-16 21:30:23 +04:00
|
|
|
return true;
|
2004-06-01 09:25:00 +04:00
|
|
|
}
|
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
already_AddRefed<TextEditor> HTMLTextFieldAccessible::GetEditor() const {
|
2019-11-24 08:38:02 +03:00
|
|
|
RefPtr<TextControlElement> textControlElement =
|
|
|
|
TextControlElement::FromNodeOrNull(mContent);
|
2017-08-07 11:42:50 +03:00
|
|
|
if (!textControlElement) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2017-08-07 11:42:50 +03:00
|
|
|
}
|
|
|
|
RefPtr<TextEditor> textEditor = textControlElement->GetTextEditor();
|
|
|
|
return textEditor.forget();
|
2006-07-12 17:14:53 +04:00
|
|
|
}
|
|
|
|
|
2011-09-28 05:46:11 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLTextFieldAccessible: Widgets
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
bool HTMLTextFieldAccessible::IsWidget() const { return true; }
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
Accessible* HTMLTextFieldAccessible::ContainerWidget() const {
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!mParent || mParent->Role() != roles::AUTOCOMPLETE) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mParent;
|
2011-09-28 05:46:11 +04:00
|
|
|
}
|
|
|
|
|
2011-11-30 16:36:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLFileInputAccessible
|
2011-11-30 16:36:20 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLFileInputAccessible::HTMLFileInputAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {
|
2012-12-18 09:22:26 +04:00
|
|
|
mType = eHTMLFileInputType;
|
2011-11-30 16:36:20 +04:00
|
|
|
}
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLFileInputAccessible::NativeRole() const {
|
2019-09-19 07:39:21 +03:00
|
|
|
// No specific role in AT APIs. We use GROUPING so that the label will be
|
|
|
|
// reported by screen readers when focus enters this control .
|
|
|
|
return roles::GROUPING;
|
2011-11-30 16:36:20 +04:00
|
|
|
}
|
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
nsresult HTMLFileInputAccessible::HandleAccEvent(AccEvent* aEvent) {
|
2012-05-31 12:04:41 +04:00
|
|
|
nsresult rv = HyperTextAccessibleWrap::HandleAccEvent(aEvent);
|
2011-11-30 16:36:20 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Redirect state change events for inherited states to child controls. Note,
|
|
|
|
// unavailable state is not redirected. That's a standard for unavailable
|
|
|
|
// state handling.
|
|
|
|
AccStateChangeEvent* event = downcast_accEvent(aEvent);
|
|
|
|
if (event && (event->GetState() == states::BUSY ||
|
|
|
|
event->GetState() == states::REQUIRED ||
|
|
|
|
event->GetState() == states::HASPOPUP ||
|
|
|
|
event->GetState() == states::INVALID)) {
|
2013-03-27 15:35:22 +04:00
|
|
|
Accessible* button = GetChildAt(0);
|
2012-01-12 07:07:35 +04:00
|
|
|
if (button && button->Role() == roles::PUSHBUTTON) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccStateChangeEvent> childEvent = new AccStateChangeEvent(
|
2011-11-30 16:36:20 +04:00
|
|
|
button, event->GetState(), event->IsStateEnabled(),
|
2013-10-26 18:58:53 +04:00
|
|
|
event->FromUserInput());
|
2011-11-30 16:36:20 +04:00
|
|
|
nsEventShell::FireEvent(childEvent);
|
|
|
|
}
|
|
|
|
}
|
2013-03-27 15:35:22 +04:00
|
|
|
|
2011-11-30 16:36:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-19 07:34:29 +03:00
|
|
|
Accessible* HTMLFileInputAccessible::CurrentItem() const {
|
|
|
|
// Allow aria-activedescendant to override.
|
|
|
|
if (Accessible* item = HyperTextAccessibleWrap::CurrentItem()) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The HTML file input itself gets DOM focus, not the button inside it.
|
|
|
|
// For a11y, we want the button to get focus.
|
|
|
|
Accessible* button = FirstChild();
|
|
|
|
if (!button) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("File input doesn't contain a button");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(button->IsButton());
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2013-12-11 07:19:26 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLSpinnerAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLSpinnerAccessible::NativeRole() const { return roles::SPINBUTTON; }
|
2013-12-11 07:19:26 +04:00
|
|
|
|
2018-05-15 19:55:28 +03:00
|
|
|
void HTMLSpinnerAccessible::Value(nsString& aValue) const {
|
2013-12-11 07:19:26 +04:00
|
|
|
AccessibleWrap::Value(aValue);
|
|
|
|
if (!aValue.IsEmpty()) return;
|
|
|
|
|
2016-11-15 20:46:32 +03:00
|
|
|
// Pass NonSystem as the caller type, to be safe. We don't expect to have a
|
|
|
|
// file input here.
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement::FromNode(mContent)->GetValue(aValue, CallerType::NonSystem);
|
2013-12-11 07:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLSpinnerAccessible::MaxValue() const {
|
|
|
|
double value = AccessibleWrap::MaxValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetMaximum().toDouble();
|
2013-12-11 07:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLSpinnerAccessible::MinValue() const {
|
|
|
|
double value = AccessibleWrap::MinValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetMinimum().toDouble();
|
2013-12-11 07:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLSpinnerAccessible::Step() const {
|
|
|
|
double value = AccessibleWrap::Step();
|
|
|
|
if (!IsNaN(value)) return value;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetStep().toDouble();
|
2013-12-11 07:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLSpinnerAccessible::CurValue() const {
|
|
|
|
double value = AccessibleWrap::CurValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetValueAsDecimal().toDouble();
|
2013-12-11 07:19:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLSpinnerAccessible::SetCurValue(double aValue) {
|
|
|
|
ErrorResult er;
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement::FromNode(mContent)->SetValueAsNumber(aValue, er);
|
2013-12-11 07:19:26 +04:00
|
|
|
return !er.Failed();
|
|
|
|
}
|
|
|
|
|
2013-04-28 04:54:54 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLRangeAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLRangeAccessible::NativeRole() const { return roles::SLIDER; }
|
2013-04-28 04:54:54 +04:00
|
|
|
|
|
|
|
bool HTMLRangeAccessible::IsWidget() const { return true; }
|
|
|
|
|
2018-05-15 19:55:28 +03:00
|
|
|
void HTMLRangeAccessible::Value(nsString& aValue) const {
|
2013-04-28 04:54:54 +04:00
|
|
|
LeafAccessible::Value(aValue);
|
|
|
|
if (!aValue.IsEmpty()) return;
|
|
|
|
|
2016-11-15 20:46:32 +03:00
|
|
|
// Pass NonSystem as the caller type, to be safe. We don't expect to have a
|
|
|
|
// file input here.
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement::FromNode(mContent)->GetValue(aValue, CallerType::NonSystem);
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 01:01:15 +04:00
|
|
|
double HTMLRangeAccessible::MaxValue() const {
|
|
|
|
double value = LeafAccessible::MaxValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
2013-04-28 04:54:54 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetMaximum().toDouble();
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 01:01:15 +04:00
|
|
|
double HTMLRangeAccessible::MinValue() const {
|
|
|
|
double value = LeafAccessible::MinValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
2013-04-28 04:54:54 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetMinimum().toDouble();
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 01:01:15 +04:00
|
|
|
double HTMLRangeAccessible::Step() const {
|
|
|
|
double value = LeafAccessible::Step();
|
|
|
|
if (!IsNaN(value)) return value;
|
2013-04-28 04:54:54 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetStep().toDouble();
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 01:01:15 +04:00
|
|
|
double HTMLRangeAccessible::CurValue() const {
|
|
|
|
double value = LeafAccessible::CurValue();
|
|
|
|
if (!IsNaN(value)) return value;
|
2013-04-28 04:54:54 +04:00
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
return HTMLInputElement::FromNode(mContent)->GetValueAsDecimal().toDouble();
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 01:01:15 +04:00
|
|
|
bool HTMLRangeAccessible::SetCurValue(double aValue) {
|
2013-04-28 04:54:54 +04:00
|
|
|
ErrorResult er;
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLInputElement::FromNode(mContent)->SetValueAsNumber(aValue, er);
|
2013-11-20 01:01:15 +04:00
|
|
|
return !er.Failed();
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLGroupboxAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2002-02-16 04:34:42 +03:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLGroupboxAccessible::HTMLGroupboxAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {}
|
2002-02-16 04:34:42 +03:00
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLGroupboxAccessible::NativeRole() const { return roles::GROUPING; }
|
2002-02-16 04:34:42 +03:00
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
nsIContent* HTMLGroupboxAccessible::GetLegend() const {
|
2011-12-07 11:20:17 +04:00
|
|
|
for (nsIContent* legendContent = mContent->GetFirstChild(); legendContent;
|
|
|
|
legendContent = legendContent->GetNextSibling()) {
|
2011-06-04 01:35:17 +04:00
|
|
|
if (legendContent->NodeInfo()->Equals(nsGkAtoms::legend,
|
2010-06-11 12:23:18 +04:00
|
|
|
mContent->GetNameSpaceID())) {
|
2007-07-01 00:06:13 +04:00
|
|
|
// Either XHTML namespace or no namespace
|
2010-06-11 12:23:18 +04:00
|
|
|
return legendContent;
|
2007-07-01 00:06:13 +04:00
|
|
|
}
|
|
|
|
}
|
2002-02-16 04:34:42 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-02-16 04:34:42 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLGroupboxAccessible::NativeName(nsString& aName) const {
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2008-10-10 16:26:55 +04:00
|
|
|
if (!aName.IsEmpty()) return nameFlag;
|
2005-06-01 18:03:38 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
nsIContent* legendContent = GetLegend();
|
|
|
|
if (legendContent)
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, legendContent, &aName);
|
2007-07-01 00:06:13 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2007-07-01 00:06:13 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLGroupboxAccessible::RelationByType(RelationType aType) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2007-07-01 00:06:13 +04:00
|
|
|
// No override for label, so use <legend> for this <fieldset>
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABELLED_BY) rel.AppendTarget(mDoc, GetLegend());
|
2007-07-01 00:06:13 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2002-02-16 04:34:42 +03:00
|
|
|
}
|
2004-05-26 17:01:13 +04:00
|
|
|
|
2009-03-07 18:38:58 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLLegendAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-03-07 18:38:58 +03:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLLegendAccessible::HTMLLegendAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {}
|
2007-07-01 00:06:13 +04:00
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLLegendAccessible::RelationByType(RelationType aType) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType != RelationType::LABEL_FOR) return rel;
|
2004-05-26 17:01:13 +04:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* groupbox = Parent();
|
2012-01-12 07:07:35 +04:00
|
|
|
if (groupbox && groupbox->Role() == roles::GROUPING)
|
2011-08-10 05:44:00 +04:00
|
|
|
rel.AppendTarget(groupbox);
|
2007-07-01 00:06:13 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2004-05-26 17:01:13 +04:00
|
|
|
}
|
2009-03-07 18:38:58 +03:00
|
|
|
|
2011-12-05 10:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLFigureAccessible
|
2011-12-05 10:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLFigureAccessible::HTMLFigureAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {}
|
2011-12-05 10:04:06 +04:00
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLFigureAccessible::NativeName(nsString& aName) const {
|
2012-10-17 10:38:16 +04:00
|
|
|
ENameValueFlag nameFlag = HyperTextAccessibleWrap::NativeName(aName);
|
2011-12-05 10:04:06 +04:00
|
|
|
if (!aName.IsEmpty()) return nameFlag;
|
|
|
|
|
|
|
|
nsIContent* captionContent = Caption();
|
2012-10-14 08:18:39 +04:00
|
|
|
if (captionContent)
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName);
|
2011-12-05 10:04:06 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2011-12-05 10:04:06 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLFigureAccessible::RelationByType(RelationType aType) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABELLED_BY) rel.AppendTarget(mDoc, Caption());
|
2011-12-05 10:04:06 +04:00
|
|
|
|
|
|
|
return rel;
|
|
|
|
}
|
|
|
|
|
2012-04-12 15:11:40 +04:00
|
|
|
nsIContent* HTMLFigureAccessible::Caption() const {
|
2011-12-05 10:04:06 +04:00
|
|
|
for (nsIContent* childContent = mContent->GetFirstChild(); childContent;
|
|
|
|
childContent = childContent->GetNextSibling()) {
|
|
|
|
if (childContent->NodeInfo()->Equals(nsGkAtoms::figcaption,
|
|
|
|
mContent->GetNameSpaceID())) {
|
|
|
|
return childContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-05 10:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-12 15:11:40 +04:00
|
|
|
// HTMLFigcaptionAccessible
|
2011-12-05 10:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLFigcaptionAccessible::HTMLFigcaptionAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-05-31 12:04:41 +04:00
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {}
|
2011-12-05 10:04:06 +04:00
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLFigcaptionAccessible::RelationByType(RelationType aType) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType != RelationType::LABEL_FOR) return rel;
|
2011-12-05 10:04:06 +04:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* figure = Parent();
|
2011-12-05 10:04:06 +04:00
|
|
|
if (figure && figure->GetContent()->NodeInfo()->Equals(
|
|
|
|
nsGkAtoms::figure, mContent->GetNameSpaceID())) {
|
|
|
|
rel.AppendTarget(figure);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rel;
|
|
|
|
}
|
2018-11-20 17:10:38 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLProgressAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
role HTMLProgressAccessible::NativeRole() const { return roles::PROGRESSBAR; }
|
|
|
|
|
|
|
|
uint64_t HTMLProgressAccessible::NativeState() const {
|
|
|
|
uint64_t state = LeafAccessible::NativeState();
|
|
|
|
|
|
|
|
// An undetermined progressbar (i.e. without a value) has a mixed state.
|
|
|
|
nsAutoString attrValue;
|
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
|
|
|
attrValue);
|
|
|
|
if (attrValue.IsEmpty()) {
|
|
|
|
state |= states::MIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLProgressAccessible::IsWidget() const { return true; }
|
|
|
|
|
|
|
|
void HTMLProgressAccessible::Value(nsString& aValue) const {
|
|
|
|
LeafAccessible::Value(aValue);
|
|
|
|
if (!aValue.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double maxValue = MaxValue();
|
|
|
|
if (IsNaN(maxValue) || maxValue == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double curValue = CurValue();
|
|
|
|
if (IsNaN(curValue)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Treat the current value bigger than maximum as 100%.
|
|
|
|
double percentValue =
|
|
|
|
(curValue < maxValue) ? (curValue / maxValue) * 100 : 100;
|
|
|
|
|
|
|
|
aValue.AppendFloat(percentValue);
|
|
|
|
aValue.Append('%');
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLProgressAccessible::MaxValue() const {
|
|
|
|
double value = LeafAccessible::MaxValue();
|
|
|
|
if (!IsNaN(value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString strValue;
|
|
|
|
if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::max,
|
|
|
|
strValue)) {
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
value = strValue.ToDouble(&result);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLProgressAccessible::MinValue() const {
|
|
|
|
double value = LeafAccessible::MinValue();
|
|
|
|
return IsNaN(value) ? 0 : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLProgressAccessible::Step() const {
|
|
|
|
double value = LeafAccessible::Step();
|
|
|
|
return IsNaN(value) ? 0 : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HTMLProgressAccessible::CurValue() const {
|
|
|
|
double value = LeafAccessible::CurValue();
|
|
|
|
if (!IsNaN(value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString attrValue;
|
|
|
|
if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
|
|
|
attrValue)) {
|
|
|
|
return UnspecifiedNaN<double>();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult error = NS_OK;
|
|
|
|
value = attrValue.ToDouble(&error);
|
|
|
|
return NS_FAILED(error) ? UnspecifiedNaN<double>() : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTMLProgressAccessible::SetCurValue(double aValue) {
|
|
|
|
return false; // progress meters are readonly.
|
|
|
|
}
|