Bug 1492326, change methods of nsIDOMXUL* interfaces so that they return Elements to reduce usages as most callers want the return values as elements, r=peterv

This commit is contained in:
Neil Deakin 2018-12-04 11:25:41 -05:00
Родитель 1d355fa505
Коммит d2ed932b7c
11 изменённых файлов: 79 добавлений и 75 удалений

Просмотреть файл

@ -95,8 +95,10 @@ int32_t nsAccUtils::GetLevelForXULContainerItem(nsIContent* aContent) {
nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
if (!item) return 0;
nsCOMPtr<nsIDOMXULContainerElement> container;
item->GetParentContainer(getter_AddRefs(container));
nsCOMPtr<Element> containerElement;
item->GetParentContainer(getter_AddRefs(containerElement));
nsCOMPtr<nsIDOMXULContainerElement> container =
do_QueryInterface(containerElement);
if (!container) return 0;
// Get level of the item.
@ -104,9 +106,8 @@ int32_t nsAccUtils::GetLevelForXULContainerItem(nsIContent* aContent) {
while (container) {
level++;
nsCOMPtr<nsIDOMXULContainerElement> parentContainer;
container->GetParentContainer(getter_AddRefs(parentContainer));
parentContainer.swap(container);
container->GetParentContainer(getter_AddRefs(containerElement));
container = do_QueryInterface(containerElement);
}
return level;

Просмотреть файл

@ -73,12 +73,10 @@ void XULComboboxAccessible::Description(nsString& aDescription) {
nsCOMPtr<nsIDOMXULMenuListElement> menuListElm(do_QueryInterface(mContent));
if (!menuListElm) return;
nsCOMPtr<nsIDOMXULSelectControlItemElement> focusedOptionItem;
nsCOMPtr<Element> focusedOptionItem;
menuListElm->GetSelectedItem(getter_AddRefs(focusedOptionItem));
nsCOMPtr<nsIContent> focusedOptionContent =
do_QueryInterface(focusedOptionItem);
if (focusedOptionContent && mDoc) {
Accessible* focusedOptionAcc = mDoc->GetAccessible(focusedOptionContent);
if (focusedOptionItem && mDoc) {
Accessible* focusedOptionAcc = mDoc->GetAccessible(focusedOptionItem);
if (focusedOptionAcc) focusedOptionAcc->Description(aDescription);
}
}

Просмотреть файл

@ -108,8 +108,11 @@ void XULListboxAccessible::Value(nsString& aValue) const {
nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mContent));
if (select) {
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
select->GetSelectedItem(getter_AddRefs(selectedItem));
RefPtr<Element> element;
select->GetSelectedItem(getter_AddRefs(element));
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem =
do_QueryInterface(element);
if (selectedItem) selectedItem->GetLabel(aValue);
}
}
@ -143,14 +146,11 @@ Accessible* XULListboxAccessible::CellAt(uint32_t aRowIndex,
nsCOMPtr<nsIDOMXULSelectControlElement> control = do_QueryInterface(mContent);
NS_ENSURE_TRUE(control, nullptr);
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
control->GetItemAtIndex(aRowIndex, getter_AddRefs(item));
if (!item) return nullptr;
RefPtr<Element> element;
control->GetItemAtIndex(aRowIndex, getter_AddRefs(element));
if (!element) return nullptr;
nsCOMPtr<nsIContent> itemContent(do_QueryInterface(item));
if (!itemContent) return nullptr;
Accessible* row = mDoc->GetAccessible(itemContent);
Accessible* row = mDoc->GetAccessible(element);
NS_ENSURE_TRUE(row, nullptr);
return row->GetChildAt(aColumnIndex);
@ -173,10 +173,12 @@ bool XULListboxAccessible::IsRowSelected(uint32_t aRowIdx) {
nsCOMPtr<nsIDOMXULSelectControlElement> control = do_QueryInterface(mContent);
NS_ASSERTION(control, "Doesn't implement nsIDOMXULSelectControlElement.");
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
nsresult rv = control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
RefPtr<Element> element;
nsresult rv = control->GetItemAtIndex(aRowIdx, getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, false);
nsCOMPtr<nsIDOMXULSelectControlItemElement> item = do_QueryInterface(element);
bool isSelected = false;
item->GetSelected(&isSelected);
return isSelected;
@ -332,9 +334,11 @@ void XULListboxAccessible::SelectRow(uint32_t aRowIdx) {
NS_ASSERTION(control,
"Doesn't implement nsIDOMXULMultiSelectControlElement.");
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
RefPtr<Element> item;
control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
control->SelectItem(item);
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm = do_QueryInterface(item);
control->SelectItem(itemElm);
}
void XULListboxAccessible::UnselectRow(uint32_t aRowIdx) {
@ -343,9 +347,11 @@ void XULListboxAccessible::UnselectRow(uint32_t aRowIdx) {
NS_ASSERTION(control,
"Doesn't implement nsIDOMXULMultiSelectControlElement.");
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
RefPtr<Element> item;
control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
control->RemoveItemFromSelection(item);
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm = do_QueryInterface(item);
control->RemoveItemFromSelection(itemElm);
}
////////////////////////////////////////////////////////////////////////////////
@ -426,13 +432,11 @@ Accessible* XULListitemAccessible::GetListAccessible() const {
do_QueryInterface(mContent);
if (!listItem) return nullptr;
nsCOMPtr<nsIDOMXULSelectControlElement> list;
listItem->GetControl(getter_AddRefs(list));
RefPtr<Element> listElement;
listItem->GetControl(getter_AddRefs(listElement));
if (!listElement) return nullptr;
nsCOMPtr<nsIContent> listContent(do_QueryInterface(list));
if (!listContent) return nullptr;
return mDoc->GetAccessible(listContent);
return mDoc->GetAccessible(listElement);
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -51,18 +51,16 @@ void XULSelectControlAccessible::SelectedItems(nsTArray<Accessible*>* aItems) {
int32_t length = 0;
xulMultiSelect->GetSelectedCount(&length);
for (int32_t index = 0; index < length; index++) {
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
xulMultiSelect->MultiGetSelectedItem(index, getter_AddRefs(itemElm));
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
Accessible* item = mDoc->GetAccessible(itemNode);
RefPtr<Element> element;
xulMultiSelect->MultiGetSelectedItem(index, getter_AddRefs(element));
Accessible* item = mDoc->GetAccessible(element);
if (item) aItems->AppendElement(item);
}
} else { // Single select?
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
if (itemNode) {
Accessible* item = mDoc->GetAccessible(itemNode);
RefPtr<Element> element;
mSelectControl->GetSelectedItem(getter_AddRefs(element));
if (element) {
Accessible* item = mDoc->GetAccessible(element);
if (item) aItems->AppendElement(item);
}
}
@ -72,14 +70,14 @@ Accessible* XULSelectControlAccessible::GetSelectedItem(uint32_t aIndex) {
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
do_QueryInterface(mSelectControl);
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm;
if (multiSelectControl)
multiSelectControl->MultiGetSelectedItem(aIndex, getter_AddRefs(itemElm));
else if (aIndex == 0)
mSelectControl->GetSelectedItem(getter_AddRefs(itemElm));
RefPtr<Element> element;
if (multiSelectControl) {
multiSelectControl->MultiGetSelectedItem(aIndex, getter_AddRefs(element));
} else if (aIndex == 0) {
mSelectControl->GetSelectedItem(getter_AddRefs(element));
}
nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemElm));
return itemNode && mDoc ? mDoc->GetAccessible(itemNode) : nullptr;
return element && mDoc ? mDoc->GetAccessible(element) : nullptr;
}
uint32_t XULSelectControlAccessible::SelectedItemCount() {
@ -113,10 +111,11 @@ bool XULSelectControlAccessible::AddItemToSelection(uint32_t aIndex) {
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
do_QueryInterface(mSelectControl);
if (multiSelectControl)
if (multiSelectControl) {
multiSelectControl->AddItemToSelection(itemElm);
else
mSelectControl->SetSelectedItem(itemElm);
} else {
mSelectControl->SetSelectedItem(item->Elm());
}
return true;
}
@ -184,20 +183,18 @@ bool XULSelectControlAccessible::SelectAll() {
Accessible* XULSelectControlAccessible::CurrentItem() const {
if (!mSelectControl) return nullptr;
nsCOMPtr<nsIDOMXULSelectControlItemElement> currentItemElm;
RefPtr<Element> currentItemElm;
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
do_QueryInterface(mSelectControl);
if (multiSelectControl)
if (multiSelectControl) {
multiSelectControl->GetCurrentItem(getter_AddRefs(currentItemElm));
else
} else {
mSelectControl->GetSelectedItem(getter_AddRefs(currentItemElm));
}
nsCOMPtr<nsINode> DOMNode;
if (currentItemElm) DOMNode = do_QueryInterface(currentItemElm);
if (DOMNode) {
if (currentItemElm) {
DocAccessible* document = Document();
if (document) return document->GetAccessible(DOMNode);
if (document) return document->GetAccessible(currentItemElm);
}
return nullptr;
@ -206,8 +203,7 @@ Accessible* XULSelectControlAccessible::CurrentItem() const {
void XULSelectControlAccessible::SetCurrentItem(const Accessible* aItem) {
if (!mSelectControl) return;
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemElm =
do_QueryInterface(aItem->GetContent());
nsCOMPtr<Element> itemElm = aItem->Elm();
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelectControl =
do_QueryInterface(mSelectControl);
if (multiSelectControl)

Просмотреть файл

@ -6,13 +6,15 @@
#include "nsISupports.idl"
interface nsIDOMXULContainerElement;
webidl Element;
[scriptable, uuid(800a68c7-b854-4597-a436-3055ce5c5c96)]
interface nsIDOMXULContainerItemElement : nsISupports
{
/**
* Returns the parent container if any.
*/
readonly attribute nsIDOMXULContainerElement parentContainer;
readonly attribute Element parentContainer;
};
[scriptable, uuid(b2bc96b8-31fc-42f4-937a-bd27291af40b)]

Просмотреть файл

@ -5,6 +5,7 @@
#include "nsIDOMXULSelectCntrlEl.idl"
webidl Element;
webidl NodeList;
[scriptable, uuid(40654a10-8204-4f06-9f21-7baa31c7b1dd)]
@ -12,7 +13,7 @@ interface nsIDOMXULMultiSelectControlElement : nsIDOMXULSelectControlElement
{
attribute AString selType;
attribute nsIDOMXULSelectControlItemElement currentItem;
attribute Element currentItem;
attribute long currentIndex;
readonly attribute NodeList selectedItems;
@ -32,5 +33,5 @@ interface nsIDOMXULMultiSelectControlElement : nsIDOMXULSelectControlElement
// mutable NodeList for selectedItems
readonly attribute long selectedCount;
[binaryname(MultiGetSelectedItem)]
nsIDOMXULSelectControlItemElement getSelectedItem(in long index);
Element getSelectedItem(in long index);
};

Просмотреть файл

@ -6,15 +6,17 @@
#include "nsIDOMXULControlElement.idl"
interface nsIDOMXULSelectControlItemElement;
webidl Element;
[scriptable, uuid(9bf188a7-d6f9-431b-b5c7-118013998e8b)]
interface nsIDOMXULSelectControlElement : nsIDOMXULControlElement {
attribute nsIDOMXULSelectControlItemElement selectedItem;
attribute Element selectedItem;
attribute long selectedIndex;
attribute AString value;
readonly attribute unsigned long itemCount;
long getIndexOfItem(in nsIDOMXULSelectControlItemElement item);
nsIDOMXULSelectControlItemElement getItemAtIndex(in long index);
Element getItemAtIndex(in long index);
};

Просмотреть файл

@ -6,6 +6,8 @@
#include "nsISupports.idl"
interface nsIDOMXULSelectControlElement;
webidl Element;
[scriptable, uuid(5c6be58f-17df-4750-88a5-4a59ac28adc9)]
interface nsIDOMXULSelectControlItemElement : nsISupports {
attribute boolean disabled;
@ -19,7 +21,7 @@ interface nsIDOMXULSelectControlItemElement : nsISupports {
readonly attribute boolean selected;
readonly attribute nsIDOMXULSelectControlElement control;
readonly attribute Element control;
// XXX defined in XULElement, but should be defined here
// void doCommand();

Просмотреть файл

@ -549,9 +549,7 @@ bool nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
bool disabled;
controlItem->GetDisabled(&disabled);
if (!disabled) {
nsCOMPtr<nsIDOMXULSelectControlElement> selectControl;
controlItem->GetControl(getter_AddRefs(selectControl));
elementToFocus = do_QueryInterface(selectControl);
controlItem->GetControl(getter_AddRefs(elementToFocus));
}
}
} else {

Просмотреть файл

@ -7897,7 +7897,7 @@ void PresShell::GetCurrentItemAndPositionForElement(
// lists or just underneath the selected item for single-select lists. If
// the element is not a list, or there is no selection, leave the position
// as is.
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
nsCOMPtr<Element> item;
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
do_QueryInterface(aFocusedElement);
if (multiSelect) {
@ -7957,7 +7957,9 @@ void PresShell::GetCurrentItemAndPositionForElement(
}
}
if (item) focusedContent = do_QueryInterface(item);
if (item) {
focusedContent = item;
}
#endif
nsIFrame* frame = focusedContent->GetPrimaryFrame();

Просмотреть файл

@ -1117,10 +1117,8 @@ nsIFrame* nsMenuPopupFrame::GetSelectedItemForAlignment() {
}
}
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
select->GetSelectedItem(getter_AddRefs(item));
nsCOMPtr<nsIContent> selectedElement = do_QueryInterface(item);
nsCOMPtr<Element> selectedElement;
select->GetSelectedItem(getter_AddRefs(selectedElement));
return selectedElement ? selectedElement->GetPrimaryFrame() : nullptr;
}