Bug 1486671 - stop using nsIDOMXULCheckboxElement, r=jamie

This commit is contained in:
Alexander Surkov 2018-08-29 15:42:31 +08:00
parent 39a3091a37
commit e36505da67
9 changed files with 119 additions and 194 deletions

View File

@ -4,7 +4,7 @@
XULMAP_TYPE(browser, OuterDocAccessible)
XULMAP_TYPE(button, XULButtonAccessible)
XULMAP_TYPE(checkbox, XULCheckboxAccessible)
XULMAP_TYPE(checkbox, CheckboxAccessible)
XULMAP_TYPE(description, XULLabelAccessible)
XULMAP_TYPE(dropMarker, XULDropmarkerAccessible)
XULMAP_TYPE(editor, OuterDocAccessible)

View File

@ -243,7 +243,7 @@ static Accessible* New_HTMLInput(Element* aElement, Accessible* aContext)
{
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::checkbox, eIgnoreCase)) {
return new HTMLCheckboxAccessible(aElement, aContext->Document());
return new CheckboxAccessible(aElement, aContext->Document());
}
if (aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
nsGkAtoms::radio, eIgnoreCase)) {
@ -1492,7 +1492,7 @@ nsAccessibilityService::CreateAccessibleByFrameType(nsIFrame* aFrame,
}
break;
case eHTMLCheckboxType:
newAcc = new HTMLCheckboxAccessible(aContent, document);
newAcc = new CheckboxAccessible(aContent, document);
break;
case eHTMLComboboxType:
newAcc = new HTMLComboboxAccessible(aContent, document);

View File

@ -909,9 +909,10 @@ public:
/**
* Return true if the accessible state change is processed by handling proper
* DOM UI event, if otherwise then false. For example, HTMLCheckboxAccessible
* process nsIDocumentObserver::ContentStateChanged instead
* 'CheckboxStateChange' event.
* DOM UI event, if otherwise then false. For example, CheckboxAccessible
* created for HTML:input@type="checkbox" will process
* nsIDocumentObserver::ContentStateChanged instead of 'CheckboxStateChange'
* event.
*/
bool NeedsDOMUIEvent() const
{ return !(mStateFlags & eIgnoreDOMUIEvent); }

View File

@ -6,10 +6,10 @@
// NOTE: alphabetically ordered
#include "FormControlAccessible.h"
#include "Role.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/FloatingPoint.h"
#include "nsIDOMXULControlElement.h"
#include "Role.h"
using namespace mozilla::a11y;
@ -142,6 +142,84 @@ ProgressMeterAccessible<Max>::SetCurValue(double aValue)
return false; // progress meters are readonly.
}
////////////////////////////////////////////////////////////////////////////////
// CheckboxAccessible
////////////////////////////////////////////////////////////////////////////////
role
CheckboxAccessible::NativeRole() const
{
return roles::CHECKBUTTON;
}
uint8_t
CheckboxAccessible::ActionCount() const
{
return 1;
}
void
CheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
{
if (aIndex == eAction_Click) {
uint64_t state = NativeState();
if (state & states::CHECKED) {
aName.AssignLiteral("uncheck");
} else if (state & states::MIXED) {
aName.AssignLiteral("cycle");
} else {
aName.AssignLiteral("check");
}
}
}
bool
CheckboxAccessible::DoAction(uint8_t aIndex) const
{
if (aIndex != eAction_Click) {
return false;
}
DoCommand();
return true;
}
uint64_t
CheckboxAccessible::NativeState() const
{
uint64_t state = LeafAccessible::NativeState();
state |= states::CHECKABLE;
dom::HTMLInputElement* input = dom::HTMLInputElement::FromNode(mContent);
if (input) { // HTML:input@type="checkbox"
if (input->Indeterminate()) {
return state | states::MIXED;
}
if (input->Checked()) {
return state | states::CHECKED;
}
} else if (mContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::checked,
nsGkAtoms::_true,
eCaseMatters)) { // XUL checkbox
return state | states::CHECKED;
}
return state;
}
////////////////////////////////////////////////////////////////////////////////
// CheckboxAccessible: Widgets
bool
CheckboxAccessible::IsWidget() const
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
// RadioButtonAccessible
////////////////////////////////////////////////////////////////////////////////

View File

@ -46,6 +46,38 @@ protected:
virtual ~ProgressMeterAccessible() {}
};
/**
* Checkbox accessible.
*/
class CheckboxAccessible : public LeafAccessible
{
public:
enum { eAction_Click = 0 };
CheckboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
LeafAccessible(aContent, aDoc)
{
// Ignore "CheckboxStateChange" DOM event in lieu of document observer
// state change notification.
if (aContent->IsHTMLElement()) {
mStateFlags |= eIgnoreDOMUIEvent;
}
}
// Accessible
virtual mozilla::a11y::role NativeRole() const override;
virtual uint64_t NativeState() const override;
// ActionAccessible
virtual uint8_t ActionCount() const override;
virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
virtual bool DoAction(uint8_t aIndex) const override;
// Widgets
virtual bool IsWidget() const override;
};
/**
* Generic class used for radio buttons.
*/

View File

@ -35,75 +35,6 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// HTMLCheckboxAccessible
////////////////////////////////////////////////////////////////////////////////
role
HTMLCheckboxAccessible::NativeRole() const
{
return roles::CHECKBUTTON;
}
uint8_t
HTMLCheckboxAccessible::ActionCount() const
{
return 1;
}
void
HTMLCheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
{
if (aIndex == eAction_Click) { // 0 is the magic value for default action
uint64_t state = NativeState();
if (state & states::CHECKED)
aName.AssignLiteral("uncheck");
else if (state & states::MIXED)
aName.AssignLiteral("cycle");
else
aName.AssignLiteral("check");
}
}
bool
HTMLCheckboxAccessible::DoAction(uint8_t aIndex) const
{
if (aIndex != 0)
return false;
DoCommand();
return true;
}
uint64_t
HTMLCheckboxAccessible::NativeState() const
{
uint64_t state = LeafAccessible::NativeState();
state |= states::CHECKABLE;
HTMLInputElement* input = HTMLInputElement::FromNode(mContent);
if (!input)
return state;
if (input->Indeterminate())
return state | states::MIXED;
if (input->Checked())
return state | states::CHECKED;
return state;
}
////////////////////////////////////////////////////////////////////////////////
// HTMLCheckboxAccessible: Widgets
bool
HTMLCheckboxAccessible::IsWidget() const
{
return true;
}
////////////////////////////////////////////////////////////////////////////////
// HTMLRadioButtonAccessible
////////////////////////////////////////////////////////////////////////////////

View File

@ -18,37 +18,6 @@ namespace a11y {
*/
typedef ProgressMeterAccessible<1> HTMLProgressMeterAccessible;
/**
* Accessible for HTML input@type="checkbox".
*/
class HTMLCheckboxAccessible : public LeafAccessible
{
public:
enum { eAction_Click = 0 };
HTMLCheckboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
LeafAccessible(aContent, aDoc)
{
// Ignore "CheckboxStateChange" DOM event in lieu of document observer
// state change notification.
mStateFlags |= eIgnoreDOMUIEvent;
}
// Accessible
virtual mozilla::a11y::role NativeRole() const override;
virtual uint64_t NativeState() const override;
// ActionAccessible
virtual uint8_t ActionCount() const override;
virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
virtual bool DoAction(uint8_t aIndex) const override;
// Widgets
virtual bool IsWidget() const override;
};
/**
* Accessible for HTML input@type="radio" element.
*/

View File

@ -17,7 +17,6 @@
#include "XULMenuAccessible.h"
#include "nsIDOMXULButtonElement.h"
#include "nsIDOMXULCheckboxElement.h"
#include "nsIDOMXULMenuListElement.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIEditor.h"
@ -274,71 +273,6 @@ XULDropmarkerAccessible::NativeState() const
return DropmarkerOpen(false) ? states::PRESSED : 0;
}
////////////////////////////////////////////////////////////////////////////////
// XULCheckboxAccessible
////////////////////////////////////////////////////////////////////////////////
XULCheckboxAccessible::
XULCheckboxAccessible(nsIContent* aContent, DocAccessible* aDoc) :
LeafAccessible(aContent, aDoc)
{
}
role
XULCheckboxAccessible::NativeRole() const
{
return roles::CHECKBUTTON;
}
uint8_t
XULCheckboxAccessible::ActionCount() const
{
return 1;
}
void
XULCheckboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
{
if (aIndex == eAction_Click) {
if (NativeState() & states::CHECKED)
aName.AssignLiteral("uncheck");
else
aName.AssignLiteral("check");
}
}
bool
XULCheckboxAccessible::DoAction(uint8_t aIndex) const
{
if (aIndex != eAction_Click)
return false;
DoCommand();
return true;
}
uint64_t
XULCheckboxAccessible::NativeState() const
{
// Possible states: focused, focusable, unavailable(disabled), checked
// Get focus and disable status from base class
uint64_t state = LeafAccessible::NativeState();
state |= states::CHECKABLE;
// Determine Checked state
nsCOMPtr<nsIDOMXULCheckboxElement> xulCheckboxElement =
do_QueryInterface(mContent);
if (xulCheckboxElement) {
bool checked = false;
xulCheckboxElement->GetChecked(&checked);
if (checked) {
state |= states::CHECKED;
}
}
return state;
}
////////////////////////////////////////////////////////////////////////////////
// XULGroupboxAccessible

View File

@ -59,26 +59,6 @@ protected:
bool ContainsMenu() const;
};
/**
* Used for XUL checkbox element.
*/
class XULCheckboxAccessible : public LeafAccessible
{
public:
enum { eAction_Click = 0 };
XULCheckboxAccessible(nsIContent* aContent, DocAccessible* aDoc);
// Accessible
virtual mozilla::a11y::role NativeRole() const override;
virtual uint64_t NativeState() const override;
// ActionAccessible
virtual uint8_t ActionCount() const override;
virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
virtual bool DoAction(uint8_t aIndex) const override;
};
/**
* Used for XUL dropmarker element.
*/