decomtaminate Is Column / Row / Cell Selected() on accessible tables

RESOLVED FIXED in mozilla16

Status

()

Core
Disability Access APIs
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: tbsaunde, Assigned: capella)

Tracking

unspecified
mozilla16
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [good first bug][mentor=trev.saunders@gmail.com][lang=c++])

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

5 years ago
similar approach to bug 757504
(Assignee)

Updated

5 years ago
Assignee: nobody → markcapella
Status: NEW → ASSIGNED
(Assignee)

Comment 1

5 years ago
Created attachment 632045 [details] [diff] [review]
Patch (v1)

Review request for the next one ... 

Also, I went ahead and fixed two alignment nits I forgot in bug 760881 re: HTMLTableAccessible::SelectRow() and UnselectRow().
Attachment #632045 - Flags: review?(trev.saunders)
(Reporter)

Comment 2

5 years ago
Comment on attachment 632045 [details] [diff] [review]
Patch (v1)

>   do {
>     if (!nsAccUtils::IsARIASelected(row)) {
>-      Accessible* cell = GetCellInRowAt(row, aColumn);
>+      Accessible* cell = GetCellInRowAt(row, aColIdx);
>       if (!cell) // Do not fail due to wrong markup
>-        return NS_OK;
>+        return false;
>       
>       if (!nsAccUtils::IsARIASelected(cell))
>-        return NS_OK;
>+        return false;

nit, you could put these in one if.

>+  Accessible* row = GetRowAt(aRowIdx);
>   NS_ENSURE_ARG(row);

that'll return an nsresult which you shouldn't do.
It would also tend to indicate bad markup not bad argument so you should probably fail peacefully.


>   if (!nsAccUtils::IsARIASelected(row)) {
>-    Accessible* cell = GetCellInRowAt(row, aColumn);
>+    Accessible* cell = GetCellInRowAt(row, aColIdx);
>     NS_ENSURE_ARG(cell);

same

>-HTMLTableAccessible::IsColumnSelected(PRInt32 aColumn, bool* aIsSelected)
>+bool
>+HTMLTableAccessible::IsColSelected(PRUint32 aColIdx)
> {
>-  NS_ENSURE_ARG_POINTER(aIsSelected);
>-  *aIsSelected = false;
>-
>   PRInt32 colCount = 0;
>   nsresult rv = GetColumnCount(&colCount);
>-  NS_ENSURE_SUCCESS(rv, rv);
>+  NS_ASSERTION(rv, "GetColumnCount() Shouldn't fail!");

just use RowCount() / ColCount() here and below

> 
>-  if (aColumn < 0 || aColumn >= colCount)
>-    return NS_ERROR_INVALID_ARG;
>+  if (aColIdx < 0 || aColIdx >= colCount)
>+    return false;

caller should check this similar to all other methods on TableAccessible

>+  bool isSelected = false;
>   for (PRInt32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
>-    bool isSelected = false;
>-    rv = IsCellSelected(rowIdx, aColumn, &isSelected);
>+    bool isCellSelected = false;
>+    rv = IsCellSelected(rowIdx, aColIdx, &isCellSelected);

you could use the new version you add.

>+xpcAccessibleTable::IsColumnSelected(PRInt32 aColIdx, bool* aIsSelected)
>+{
>+  NS_ENSURE_ARG_POINTER(aIsSelected);
>+  *aIsSelected = FALSE;
>+
>+  if (!mTable)
>+    return NS_ERROR_FAILURE;
>+
>+  *aIsSelected = mTable->IsColSelected(aColIdx);

all three of these methods should check the indexs are valid.

>+XULListboxAccessible::IsColSelected(PRUint32 aColIdx)
> {
>-  NS_ENSURE_ARG_POINTER(aIsSelected);
>-  *aIsSelected = false;
>-
>-  if (IsDefunct())
>-    return NS_ERROR_FAILURE;
>-
>   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
>     do_QueryInterface(mContent);
>   NS_ASSERTION(control,
>                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
> 
>   PRInt32 selectedrowCount = 0;
>   nsresult rv = control->GetSelectedCount(&selectedrowCount);
>-  NS_ENSURE_SUCCESS(rv, rv);
>+  NS_ASSERTION(rv, "GetSelectedCount() Shouldn't fail!");

you can just do NS_ENSURE_SUCCESS(rv, false)  which is better since it prints the error.

> 
>   PRInt32 rowCount = 0;
>   rv = GetRowCount(&rowCount);
>-  NS_ENSURE_SUCCESS(rv, rv);
>+  NS_ASSERTION(rv, "GetRowCount() Shouldn't fail!");

same, use RowCount()

>   nsCOMPtr<nsIDOMXULSelectControlElement> control =
>     do_QueryInterface(mContent);
>   NS_ASSERTION(control,
>                "Doesn't implement nsIDOMXULSelectControlElement.");
> 
>   nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
>-  control->GetItemAtIndex(aRow, getter_AddRefs(item));
>-  NS_ENSURE_TRUE(item, NS_ERROR_INVALID_ARG);
>+  control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
>+  NS_ASSERTION(item, "GetItemAtIndex() Shouldn't fail!");

you can use NS_ENSURE_SUCCESS here too

>+XULListboxAccessible::IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx)
> {
>-  return IsRowSelected(aRowIndex, aIsSelected);
>+  bool isSelected = false;
>+  IsRowSelected(aRowIdx, &isSelected);
>+  return isSelected;

you could use the version you add

>   PRInt32 selectedrowCount = 0;
>   rv = GetSelectionCount(&selectedrowCount);
>-  NS_ENSURE_SUCCESS(rv, rv);
>+  NS_ASSERTION(rv, "GetSelectionCount() Shouldn't fail!");

don't change from NS_ENSURE_SUCCESS

>+XULTreeGridAccessible::IsRowSelected(PRUint32 aRowIdx)
> {
>-  NS_ENSURE_ARG_POINTER(aIsSelected);
>-  *aIsSelected = false;
>-
>-  if (IsDefunct())
>-    return NS_ERROR_FAILURE;
>-
>   if (!mTreeView)
>-    return NS_ERROR_INVALID_ARG;
>+    return false;

really this should never happen since a tree with no view has no rows, but we might have cahce issues related to updating mTreeView sync and the cache async, so I guess its ok.

>   nsCOMPtr<nsITreeSelection> selection;
>   nsresult rv = mTreeView->GetSelection(getter_AddRefs(selection));
>-  NS_ENSURE_SUCCESS(rv, rv);
>+  NS_ASSERTION(rv, "GetSelection() Shouldn't fail!");

leave just change second arg to false
Attachment #632045 - Flags: review?(trev.saunders)
(Assignee)

Comment 3

5 years ago
FYI... in XULListboxAccessible::IsRowSelected()

>   nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
>-  control->GetItemAtIndex(aRow, getter_AddRefs(item));
>-  NS_ENSURE_TRUE(item, NS_ERROR_INVALID_ARG);
>+  control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
>+  NS_ASSERTION(item, "GetItemAtIndex() Shouldn't fail!");
you can use NS_ENSURE_SUCCESS here too

Errors out, so I switched it to fail gracefully like in existing code in method XULListboxAccessible::CellAt().
(Assignee)

Comment 4

5 years ago
Created attachment 632215 [details] [diff] [review]
Patch (v2)

With nits addressed .... for further review.
Attachment #632045 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Blocks: 760878
(Assignee)

Comment 5

5 years ago
Comment on attachment 632215 [details] [diff] [review]
Patch (v2)

(forgot to set the review flag)
Attachment #632215 - Flags: review?(trev.saunders)
(Reporter)

Comment 6

5 years ago
(In reply to Mark Capella [:capella] from comment #3)
> FYI... in XULListboxAccessible::IsRowSelected()
> 
> >   nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
> >-  control->GetItemAtIndex(aRow, getter_AddRefs(item));
> >-  NS_ENSURE_TRUE(item, NS_ERROR_INVALID_ARG);
> >+  control->GetItemAtIndex(aRowIdx, getter_AddRefs(item));
> >+  NS_ASSERTION(item, "GetItemAtIndex() Shouldn't fail!");
> you can use NS_ENSURE_SUCCESS here too
> 
> Errors out, so I switched it to fail gracefully like in existing code in
> method XULListboxAccessible::CellAt().

err, I should have said NS_ENSURE_TRUE
(Assignee)

Comment 7

5 years ago
Created attachment 633271 [details] [diff] [review]
Patch (v3)

Looking at it now, I must have done something wrong last night because using NS_ENSURE_SUCCESS(rv, false); does indeed work.
Attachment #632215 - Attachment is obsolete: true
Attachment #632215 - Flags: review?(trev.saunders)
(Reporter)

Comment 8

5 years ago
Comment on attachment 632215 [details] [diff] [review]
Patch (v2)

>+  for (PRInt32 rowIdx = 0; rowIdx < RowCount(); rowIdx++) {

don't call RowCount() every time through the loop, use a local var instead.

>+    bool isCellSelected = IsCellSelected(rowIdx, aColIdx);
>+    isSelected = isCellSelected;
>+    if (!isCellSelected)
>+      break;

the other cleanup seems to make the temporary bool pointless, it would be nice if you got rid of it.

btw also instead of breaking you could just return false.

>+  for (PRInt32 colIdx = 0; colIdx < ColCount(); colIdx++) {

same as RowCount()

>+    bool isCellSelected = IsCellSelected(aRowIdx, colIdx);
>+    isSelected = isCellSelected;
>+    if (!isCellSelected)
>+      break;

also the same, it seems you could get rid of the temporary and return false

>+HTMLTableAccessible::IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx)
> {
>-  NS_ENSURE_ARG_POINTER(aIsSelected);
>-  *aIsSelected = false;
>-
>   nsITableLayout *tableLayout = GetTableLayout();
>   NS_ENSURE_STATE(tableLayout);

just return false, NS_ENSURE_STATE doesn't return a bool.
Attachment #632215 - Attachment is obsolete: false
(Reporter)

Comment 9

5 years ago
Comment on attachment 633271 [details] [diff] [review]
Patch (v3)

r=me with comment 8 fixed
Attachment #633271 - Flags: review+
(Assignee)

Comment 10

5 years ago
Thanks! I think the local bool in the for loop is to ensure that at least one "selected == true" condition is met in addition to no "selected == false" conditions. Other wise, it could loop zero times, and report back a selected == true erroneously.
(Assignee)

Comment 11

5 years ago
https://tbpl.mozilla.org/?tree=Try&rev=77f704ba95f8
(Assignee)

Comment 12

5 years ago
https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=eb67e4c9f7df
Target Milestone: --- → mozilla16
https://hg.mozilla.org/mozilla-central/rev/21ab04d13974
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED

Updated

5 years ago
Duplicate of this bug: 739885
You need to log in before you can comment on or make changes to this bug.