NS_IMETHODIMP nsARIAGridAccessible::GetSelectedCells(nsIArray **aCells) { NS_ENSURE_ARG_POINTER(aCells); *aCells = nsnull; if (IsDefunct()) return NS_ERROR_FAILURE; nsresult rv = NS_OK; nsCOMPtr<nsIMutableArray> selCells = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAccessible> row; while (row = GetNextRow(row)) { if (nsAccUtils::IsARIASelected(row)) { nsCOMPtr<nsIAccessible> cell; while (cell = GetNextCellInRow(row, cell)) selCells->AppendElement(cell, PR_FALSE); continue; } nsCOMPtr<nsIAccessible> cell; while (cell = GetNextCellInRow(row, cell)) { if (nsAccUtils::IsARIASelected(cell)) selCells->AppendElement(cell, PR_FALSE); } } NS_ADDREF(*aCells = selCells); return NS_OK; }
NS_IMETHODIMP nsARIAGridAccessible::GetSelectedRowCount(PRUint32* aCount) { NS_ENSURE_ARG_POINTER(aCount); *aCount = 0; if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr<nsIAccessible> row; while ((row = GetNextRow(row))) { if (nsAccUtils::IsARIASelected(row)) { (*aCount)++; continue; } nsCOMPtr<nsIAccessible> cell = GetNextCellInRow(row); if (!cell) continue; PRBool isRowSelected = PR_TRUE; do { if (!nsAccUtils::IsARIASelected(cell)) { isRowSelected = PR_FALSE; break; } } while ((cell = GetNextCellInRow(row, cell))); if (isRowSelected) (*aCount)++; } return NS_OK; }
already_AddRefed<nsIAccessible> nsARIAGridAccessible::GetCellInRowAt(nsIAccessible *aRow, PRInt32 aColumn) { PRInt32 colIdx = aColumn; nsCOMPtr<nsIAccessible> cell(GetNextCellInRow(aRow)); while (colIdx != 0 && (cell = GetNextCellInRow(aRow, cell))) colIdx--; return cell.forget(); }
NS_IMETHODIMP nsARIAGridAccessible::GetSelectedRowIndices(PRUint32 *arowCount, PRInt32 **aRows) { NS_ENSURE_ARG_POINTER(arowCount); *arowCount = 0; NS_ENSURE_ARG_POINTER(aRows); *aRows = nsnull; if (IsDefunct()) return NS_ERROR_FAILURE; PRInt32 rowCount = 0; GetRowCount(&rowCount); if (!rowCount) return NS_OK; nsTArray<PRInt32> selRows(rowCount); nsCOMPtr<nsIAccessible> row; for (PRInt32 rowIdx = 0; row = GetNextRow(row); rowIdx++) { if (nsAccUtils::IsARIASelected(row)) { selRows.AppendElement(rowIdx); continue; } nsCOMPtr<nsIAccessible> cell = GetNextCellInRow(row); if (!cell) continue; PRBool isRowSelected = PR_TRUE; do { if (!nsAccUtils::IsARIASelected(cell)) { isRowSelected = PR_FALSE; break; } } while ((cell = GetNextCellInRow(row, cell))); if (isRowSelected) selRows.AppendElement(rowIdx); } PRUint32 selrowCount = selRows.Length(); if (!selrowCount) return NS_OK; *aRows = static_cast<PRInt32*>( nsMemory::Clone(selRows.Elements(), selrowCount * sizeof(PRInt32))); NS_ENSURE_TRUE(*aRows, NS_ERROR_OUT_OF_MEMORY); *arowCount = selrowCount; return NS_OK; }
NS_IMETHODIMP nsARIAGridAccessible::GetSelectedCellCount(PRUint32* aCount) { NS_ENSURE_ARG_POINTER(aCount); *aCount = 0; if (IsDefunct()) return NS_ERROR_FAILURE; PRInt32 colCount = 0; GetColumnCount(&colCount); nsCOMPtr<nsIAccessible> row; while ((row = GetNextRow(row))) { if (nsAccUtils::IsARIASelected(row)) { (*aCount) += colCount; continue; } nsCOMPtr<nsIAccessible> cell; while ((cell = GetNextCellInRow(row, cell))) { if (nsAccUtils::IsARIASelected(cell)) (*aCount)++; } } return NS_OK; }
NS_IMETHODIMP nsARIAGridAccessible::GetColumnCount(PRInt32 *acolumnCount) { NS_ENSURE_ARG_POINTER(acolumnCount); *acolumnCount = 0; if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr<nsIAccessible> row = GetNextRow(); nsCOMPtr<nsIAccessible> cell; while ((cell = GetNextCellInRow(row, cell))) (*acolumnCount)++; return NS_OK; }
NS_IMETHODIMP nsARIAGridAccessible::GetSelectedCellIndices(PRUint32 *aCellsCount, PRInt32 **aCells) { NS_ENSURE_ARG_POINTER(aCellsCount); *aCellsCount = 0; NS_ENSURE_ARG_POINTER(aCells); *aCells = nsnull; if (IsDefunct()) return NS_ERROR_FAILURE; PRInt32 rowCount = 0; GetRowCount(&rowCount); PRInt32 colCount = 0; GetColumnCount(&colCount); nsTArray<PRInt32> selCells(rowCount * colCount); nsCOMPtr<nsIAccessible> row; for (PRInt32 rowIdx = 0; row = GetNextRow(row); rowIdx++) { if (nsAccUtils::IsARIASelected(row)) { for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++) selCells.AppendElement(rowIdx * colCount + colIdx); continue; } nsCOMPtr<nsIAccessible> cell; for (PRInt32 colIdx = 0; cell = GetNextCellInRow(row, cell); colIdx++) { if (nsAccUtils::IsARIASelected(cell)) selCells.AppendElement(rowIdx * colCount + colIdx); } } PRUint32 selCellsCount = selCells.Length(); if (!selCellsCount) return NS_OK; *aCells = static_cast<PRInt32*>( nsMemory::Clone(selCells.Elements(), selCellsCount * sizeof(PRInt32))); NS_ENSURE_TRUE(*aCells, NS_ERROR_OUT_OF_MEMORY); *aCellsCount = selCellsCount; return NS_OK; }
NS_IMETHODIMP nsARIAGridAccessible::IsRowSelected(PRInt32 aRow, PRBool *aIsSelected) { NS_ENSURE_ARG_POINTER(aIsSelected); *aIsSelected = PR_FALSE; if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr<nsIAccessible> row = GetRowAt(aRow); NS_ENSURE_ARG(row); if (!nsAccUtils::IsARIASelected(row)) { nsCOMPtr<nsIAccessible> cell; while ((cell = GetNextCellInRow(row, cell))) { if (!nsAccUtils::IsARIASelected(cell)) return NS_OK; } } *aIsSelected = PR_TRUE; return NS_OK; }
nsresult nsARIAGridAccessible::GetSelectedColumnsArray(PRUint32 *acolumnCount, PRInt32 **aColumns) { NS_ENSURE_ARG_POINTER(acolumnCount); *acolumnCount = 0; if (aColumns) *aColumns = nsnull; if (IsDefunct()) return NS_ERROR_FAILURE; nsCOMPtr<nsIAccessible> row = GetNextRow(); if (!row) return NS_OK; PRInt32 colCount = 0; GetColumnCount(&colCount); if (!colCount) return NS_OK; PRInt32 selColCount = colCount; nsTArray<PRBool> isColSelArray(selColCount); isColSelArray.AppendElements(selColCount); for (PRInt32 i = 0; i < selColCount; i++) isColSelArray[i] = PR_TRUE; do { if (nsAccUtils::IsARIASelected(row)) continue; PRInt32 colIdx = 0; nsCOMPtr<nsIAccessible> cell; for (colIdx = 0; cell = GetNextCellInRow(row, cell); colIdx++) { if (isColSelArray.SafeElementAt(colIdx, PR_FALSE) && !nsAccUtils::IsARIASelected(cell)) { isColSelArray[colIdx] = PR_FALSE; selColCount--; } } } while ((row = GetNextRow(row))); if (!selColCount) return NS_OK; if (!aColumns) { *acolumnCount = selColCount; return NS_OK; } *aColumns = static_cast<PRInt32*>( nsMemory::Alloc(selColCount * sizeof(PRInt32))); NS_ENSURE_TRUE(*aColumns, NS_ERROR_OUT_OF_MEMORY); *acolumnCount = selColCount; for (PRInt32 colIdx = 0, idx = 0; colIdx < colCount; colIdx++) { if (isColSelArray[colIdx]) (*aColumns)[idx++] = colIdx; } return NS_OK; }
nsresult nsARIAGridAccessible::SetARIASelected(nsIAccessible *aAccessible, PRBool aIsSelected, PRBool aNotify) { nsRefPtr<nsAccessible> acc = nsAccUtils::QueryAccessible(aAccessible); nsCOMPtr<nsIDOMNode> node; acc->GetDOMNode(getter_AddRefs(node)); NS_ENSURE_STATE(node); nsCOMPtr<nsIContent> content(do_QueryInterface(node)); nsresult rv = NS_OK; if (aIsSelected) rv = content->SetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected, NS_LITERAL_STRING("true"), aNotify); else rv = content->UnsetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected, aNotify); NS_ENSURE_SUCCESS(rv, rv); // No "smart" select/unselect for internal call. if (!aNotify) return NS_OK; // If row or cell accessible was selected then we're able to not bother about // selection of its cells or its row because our algorithm is row oriented, // i.e. we check selection on row firstly and then on cells. if (aIsSelected) return NS_OK; PRUint32 role = nsAccUtils::Role(aAccessible); // If the given accessible is row that was unselected then remove // aria-selected from cell accessible. if (role == nsIAccessibleRole::ROLE_ROW) { nsCOMPtr<nsIAccessible> cell; while ((cell = GetNextCellInRow(aAccessible, cell))) { rv = SetARIASelected(cell, PR_FALSE, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } // If the given accessible is cell that was unselected and its row is selected // then remove aria-selected from row and put aria-selected on // siblings cells. if (role == nsIAccessibleRole::ROLE_GRID_CELL || role == nsIAccessibleRole::ROLE_ROWHEADER || role == nsIAccessibleRole::ROLE_COLUMNHEADER) { nsCOMPtr<nsIAccessible> row; aAccessible->GetParent(getter_AddRefs(row)); if (nsAccUtils::Role(row) == nsIAccessibleRole::ROLE_ROW && nsAccUtils::IsARIASelected(row)) { rv = SetARIASelected(row, PR_FALSE, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIAccessible> cell; while ((cell = GetNextCellInRow(row, cell))) { if (cell != aAccessible) { rv = SetARIASelected(cell, PR_TRUE, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); } } } } return NS_OK; }
void FPropertyTable::PasteTextAtCell( const FString& Text, const TSharedRef< IPropertyTableCell >& Cell ) { if ( !SelectedCells.Contains( Cell ) ) { return; } int32 CurrentRowIdx = 0; int32 CurrentColumnIdx = 0; TSharedPtr< IPropertyTableCell > FirstCellInRow = Cell; TSharedPtr< IPropertyTableCell > TargetCell = Cell; // Parse into row strings TArray<FString> RowStrings; Text.ParseIntoArray(RowStrings, TEXT("\n"), true); // Parse row strings into individual cell strings TArray<FString> CellStrings; RowStrings[CurrentRowIdx++].ParseIntoArray(CellStrings, TEXT("\t"), false); // Get the maximum paste operations before displaying the slow task int32 NumPasteOperationsBeforeWarning = GetDefault<UEditorPerProjectUserSettings>()->PropertyMatrix_NumberOfPasteOperationsBeforeWarning; const bool bShowCancelButton = false; const bool bShowProgressDialog = SelectedCells.Num() > NumPasteOperationsBeforeWarning; GWarn->BeginSlowTask(LOCTEXT("UpdatingPropertiesSlowTaskLabel", "Updating properties..."), bShowProgressDialog, bShowCancelButton); if ( RowStrings.Num() == 1 && CellStrings.Num() == 1 ) { int32 CurrentCellIndex = 0; for( auto CellIter = SelectedCells.CreateIterator(); CellIter; ++CellIter ) { SetCellValue( *CellIter, CellStrings[0] ); if ( bShowProgressDialog ) { GWarn->UpdateProgress(CurrentCellIndex, SelectedCells.Num()); CurrentCellIndex++; } } } else if ( StartingCellSelectionRange.IsValid() && EndingCellSelectionRange.IsValid() ) { // Paste values into cells while ( TargetCell.IsValid() && SelectedCells.Contains( TargetCell.ToSharedRef() ) && CurrentColumnIdx < CellStrings.Num() ) { SetCellValue( TargetCell.ToSharedRef(), CellStrings[CurrentColumnIdx++] ); // Move to next column TargetCell = GetNextCellInRow(TargetCell.ToSharedRef()); if ( ( !TargetCell.IsValid() || !SelectedCells.Contains( TargetCell.ToSharedRef() ) || CurrentColumnIdx == CellStrings.Num() ) && CurrentRowIdx < RowStrings.Num() ) { // Move to next row TargetCell = GetNextCellInColumn(FirstCellInRow.ToSharedRef()); if ( TargetCell.IsValid() && SelectedCells.Contains( TargetCell.ToSharedRef() ) ) { // Prepare data to operate on next row CurrentColumnIdx = 0; FirstCellInRow = TargetCell; RowStrings[CurrentRowIdx++].ParseIntoArray(CellStrings, TEXT("\t"), false); if ( bShowProgressDialog ) { GWarn->UpdateProgress(CurrentRowIdx, RowStrings.Num()); } } } } } GWarn->EndSlowTask(); }