Skip to content

Commit

Permalink
Bug 1387143 part 7. Move the TABLESELECTION_* constants from nsISelec…
Browse files Browse the repository at this point in the history
…tionPrivate to a TableSelection enum. r=mats
  • Loading branch information
bzbarsky committed May 8, 2018
1 parent d319e32 commit 84a3c84
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 120 deletions.
28 changes: 10 additions & 18 deletions accessible/html/HTMLTableAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,48 +734,40 @@ void
HTMLTableAccessible::SelectRow(uint32_t aRowIdx)
{
DebugOnly<nsresult> rv =
RemoveRowsOrColumnsFromSelection(aRowIdx,
nsISelectionPrivate::TABLESELECTION_ROW,
true);
RemoveRowsOrColumnsFromSelection(aRowIdx, TableSelection::Row, true);
NS_ASSERTION(NS_SUCCEEDED(rv),
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");

AddRowOrColumnToSelection(aRowIdx, nsISelectionPrivate::TABLESELECTION_ROW);
AddRowOrColumnToSelection(aRowIdx, TableSelection::Row);
}

void
HTMLTableAccessible::SelectCol(uint32_t aColIdx)
{
DebugOnly<nsresult> rv =
RemoveRowsOrColumnsFromSelection(aColIdx,
nsISelectionPrivate::TABLESELECTION_COLUMN,
true);
RemoveRowsOrColumnsFromSelection(aColIdx, TableSelection::Column, true);
NS_ASSERTION(NS_SUCCEEDED(rv),
"RemoveRowsOrColumnsFromSelection() Shouldn't fail!");

AddRowOrColumnToSelection(aColIdx, nsISelectionPrivate::TABLESELECTION_COLUMN);
AddRowOrColumnToSelection(aColIdx, TableSelection::Column);
}

void
HTMLTableAccessible::UnselectRow(uint32_t aRowIdx)
{
RemoveRowsOrColumnsFromSelection(aRowIdx,
nsISelectionPrivate::TABLESELECTION_ROW,
false);
RemoveRowsOrColumnsFromSelection(aRowIdx, TableSelection::Row, false);
}

void
HTMLTableAccessible::UnselectCol(uint32_t aColIdx)
{
RemoveRowsOrColumnsFromSelection(aColIdx,
nsISelectionPrivate::TABLESELECTION_COLUMN,
false);
RemoveRowsOrColumnsFromSelection(aColIdx, TableSelection::Column, false);
}

nsresult
HTMLTableAccessible::AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget)
HTMLTableAccessible::AddRowOrColumnToSelection(int32_t aIndex, TableSelection aTarget)
{
bool doSelectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
bool doSelectRow = (aTarget == TableSelection::Row);

nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
if (!tableFrame)
Expand Down Expand Up @@ -806,7 +798,7 @@ HTMLTableAccessible::AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget)

nsresult
HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(int32_t aIndex,
uint32_t aTarget,
TableSelection aTarget,
bool aIsOuter)
{
nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame());
Expand All @@ -817,7 +809,7 @@ HTMLTableAccessible::RemoveRowsOrColumnsFromSelection(int32_t aIndex,
RefPtr<nsFrameSelection> tableSelection =
const_cast<nsFrameSelection*>(presShell->ConstFrameSelection());

bool doUnselectRow = (aTarget == nsISelectionPrivate::TABLESELECTION_ROW);
bool doUnselectRow = (aTarget == TableSelection::Row);
uint32_t count = doUnselectRow ? ColCount() : RowCount();

int32_t startRowIdx = doUnselectRow ? aIndex : 0;
Expand Down
7 changes: 5 additions & 2 deletions accessible/html/HTMLTableAccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class nsITableCellLayout;
class nsTableCellFrame;

namespace mozilla {

enum class TableSelection : uint32_t;

namespace a11y {

/**
Expand Down Expand Up @@ -181,7 +184,7 @@ class HTMLTableAccessible : public AccessibleWrap,
* @param aTarget [in] indicates what should be selected, either row or column
* (see nsISelectionPrivate)
*/
nsresult AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget);
nsresult AddRowOrColumnToSelection(int32_t aIndex, TableSelection aTarget);

/**
* Removes rows or columns at the given index or outside it from selection.
Expand All @@ -193,7 +196,7 @@ class HTMLTableAccessible : public AccessibleWrap,
* should be unselected only
*/
nsresult RemoveRowsOrColumnsFromSelection(int32_t aIndex,
uint32_t aTarget,
TableSelection aTarget,
bool aIsOuter);

/**
Expand Down
39 changes: 20 additions & 19 deletions dom/base/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ Selection::SetCaretBidiLevel(const Nullable<int16_t>& aCaretBidiLevel, mozilla::

nsresult
Selection::GetTableCellLocationFromRange(nsRange* aRange,
int32_t* aSelectionType,
TableSelection* aSelectionType,
int32_t* aRow, int32_t* aCol)
{
if (!aRange || !aSelectionType || !aRow || !aCol)
return NS_ERROR_NULL_POINTER;

*aSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
*aSelectionType = TableSelection::None;
*aRow = 0;
*aCol = 0;

Expand All @@ -581,8 +581,9 @@ Selection::GetTableCellLocationFromRange(nsRange* aRange,

// Don't fail if range does not point to a single table cell,
// let aSelectionType tell user if we don't have a cell
if (*aSelectionType != nsISelectionPrivate::TABLESELECTION_CELL)
if (*aSelectionType != TableSelection::Cell) {
return NS_OK;
}

// Get the child content (the cell) pointed to by starting node of range
// We do minimal checking since GetTableSelectionType assures
Expand Down Expand Up @@ -630,12 +631,13 @@ Selection::AddTableCellRange(nsRange* aRange, bool* aDidAddRange,
nsresult result;

// Get if we are adding a cell selection and the row, col of cell if we are
int32_t newRow, newCol, tableMode;
int32_t newRow, newCol;
TableSelection tableMode;
result = GetTableCellLocationFromRange(aRange, &tableMode, &newRow, &newCol);
if (NS_FAILED(result)) return result;

// If not adding a cell range, we are done here
if (tableMode != nsISelectionPrivate::TABLESELECTION_CELL)
if (tableMode != TableSelection::Cell)
{
mFrameSelection->mSelectingTableCellMode = tableMode;
// Don't fail if range isn't a selected cell, aDidAddRange tells caller if we didn't proceed
Expand All @@ -644,40 +646,39 @@ Selection::AddTableCellRange(nsRange* aRange, bool* aDidAddRange,

// Set frame selection mode only if not already set to a table mode
// so we don't lose the select row and column flags (not detected by getTableCellLocation)
if (mFrameSelection->mSelectingTableCellMode == TABLESELECTION_NONE)
if (mFrameSelection->mSelectingTableCellMode == TableSelection::None)
mFrameSelection->mSelectingTableCellMode = tableMode;

*aDidAddRange = true;
return AddItem(aRange, aOutIndex);
}

//TODO: Figure out TABLESELECTION_COLUMN and TABLESELECTION_ALLCELLS
//TODO: Figure out TableSelection::Column and TableSelection::AllCells
nsresult
Selection::GetTableSelectionType(nsIDOMRange* aDOMRange,
int32_t* aTableSelectionType)
Selection::GetTableSelectionType(nsRange* aRange,
TableSelection* aTableSelectionType)
{
if (!aDOMRange || !aTableSelectionType)
if (!aRange || !aTableSelectionType)
return NS_ERROR_NULL_POINTER;
nsRange* range = static_cast<nsRange*>(aDOMRange);

*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
*aTableSelectionType = TableSelection::None;

// Must have access to frame selection to get cell info
if(!mFrameSelection) return NS_OK;

nsINode* startNode = range->GetStartContainer();
nsINode* startNode = aRange->GetStartContainer();
if (!startNode) return NS_ERROR_FAILURE;

nsINode* endNode = range->GetEndContainer();
nsINode* endNode = aRange->GetEndContainer();
if (!endNode) return NS_ERROR_FAILURE;

// Not a single selected node
if (startNode != endNode) return NS_OK;

nsIContent* child = range->GetChildAtStartOffset();
nsIContent* child = aRange->GetChildAtStartOffset();

// Not a single selected node
if (!child || child->GetNextSibling() != range->GetChildAtEndOffset()) {
if (!child || child->GetNextSibling() != aRange->GetChildAtEndOffset()) {
return NS_OK;
}

Expand All @@ -690,14 +691,14 @@ Selection::GetTableSelectionType(nsIDOMRange* aDOMRange,

if (startContent->IsHTMLElement(nsGkAtoms::tr))
{
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_CELL;
*aTableSelectionType = TableSelection::Cell;
}
else //check to see if we are selecting a table or row (column and all cells not done yet)
{
if (child->IsHTMLElement(nsGkAtoms::table))
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_TABLE;
*aTableSelectionType = TableSelection::Table;
else if (child->IsHTMLElement(nsGkAtoms::tr))
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_ROW;
*aTableSelectionType = TableSelection::Row;
}

return NS_OK;
Expand Down
17 changes: 13 additions & 4 deletions dom/base/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class nsHTMLCopyEncoder;
namespace mozilla {
class ErrorResult;
class HTMLEditor;
enum class TableSelection : uint32_t;
struct AutoPrepareFocusRange;
namespace dom {
class DocGroup;
Expand All @@ -52,14 +53,14 @@ struct RangeData
mozilla::TextRangeStyle mTextRangeStyle;
};

namespace mozilla {
namespace dom {

// Note, the ownership of mozilla::dom::Selection depends on which way the
// object is created. When nsFrameSelection has created Selection,
// addreffing/releasing the Selection object is aggregated to nsFrameSelection.
// Otherwise normal addref/release is used. This ensures that nsFrameSelection
// is never deleted before its Selections.
namespace mozilla {
namespace dom {

class Selection final : public nsISelection,
public nsWrapperCache,
public nsISelectionPrivate,
Expand Down Expand Up @@ -456,8 +457,16 @@ class Selection final : public nsISelection,
nsresult SelectFrames(nsPresContext* aPresContext,
nsRange* aRange,
bool aSelect);

/**
* Test whether the supplied range points to a single table element.
* Result is one of the TableSelection constants. "None" means
* a table element isn't selected.
*/
nsresult GetTableSelectionType(nsRange* aRange,
TableSelection* aTableSelectionType);
nsresult GetTableCellLocationFromRange(nsRange* aRange,
int32_t* aSelectionType,
TableSelection* aSelectionType,
int32_t* aRow,
int32_t* aCol);
nsresult AddTableCellRange(nsRange* aRange,
Expand Down
18 changes: 0 additions & 18 deletions dom/base/nsISelectionPrivate.idl
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ interface nsISelectionPrivate : nsISupports
void addSelectionListener(in nsISelectionListener newListener);
void removeSelectionListener(in nsISelectionListener listenerToRemove);

/* Table selection stuff
We should probably move this and table-related
items in nsFrameSelection to a
new nsITableSelection interface
*/
const long TABLESELECTION_NONE = 0;
const long TABLESELECTION_CELL = 1;
const long TABLESELECTION_ROW = 2;
const long TABLESELECTION_COLUMN = 3;
const long TABLESELECTION_TABLE = 4;
const long TABLESELECTION_ALLCELLS = 5;

/** Test if supplied range points to a single table element:
* Result is one of above constants. "None" means
* a table element isn't selected.
*/
[noscript] long getTableSelectionType(in nsIDOMRange range);

/* canCacheFrameOffset
* Frame Offset cache can be used just during calling nsEditor::EndPlaceHolderTransaction.
* EndPlaceHolderTransaction will give rise to reflow/refreshing view/scroll, and call times
Expand Down
7 changes: 4 additions & 3 deletions editor/libeditor/HTMLTableEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsFrameSelection.h"
#include "nsGkAtoms.h"
#include "nsAtom.h"
#include "nsIContent.h"
Expand Down Expand Up @@ -3207,7 +3208,7 @@ HTMLEditor::GetSelectedCellsType(Element* aElement,
}

// We have at least one selected cell, so set return value
*aSelectionType = nsISelectionPrivate::TABLESELECTION_CELL;
*aSelectionType = static_cast<uint32_t>(TableSelection::Cell);

// Store indexes of each row/col to avoid duplication of searches
nsTArray<int32_t> indexArray;
Expand All @@ -3234,7 +3235,7 @@ HTMLEditor::GetSelectedCellsType(Element* aElement,
}

if (allCellsInRowAreSelected) {
*aSelectionType = nsISelectionPrivate::TABLESELECTION_ROW;
*aSelectionType = static_cast<uint32_t>(TableSelection::Row);
return NS_OK;
}
// Test for columns
Expand Down Expand Up @@ -3263,7 +3264,7 @@ HTMLEditor::GetSelectedCellsType(Element* aElement,
rv = GetNextSelectedCell(nullptr, getter_AddRefs(selectedCell));
}
if (allCellsInColAreSelected) {
*aSelectionType = nsISelectionPrivate::TABLESELECTION_COLUMN;
*aSelectionType = static_cast<uint32_t>(TableSelection::Column);
}

return NS_OK;
Expand Down
6 changes: 3 additions & 3 deletions editor/nsITableEditor.idl
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ interface nsITableEditor : nsISupports
* @return
* 0 aCellElement was not a cell
* (returned result = NS_ERROR_FAILURE)
* TABLESELECTION_CELL There are 1 or more cells selected but
* TableSelection::Cell There are 1 or more cells selected but
* complete rows or columns are not selected
* TABLESELECTION_ROW All cells are in 1 or more rows
* TableSelection::Row All cells are in 1 or more rows
* and in each row, all cells selected
* Note: This is the value if all rows
* (thus all cells) are selected
* TABLESELECTION_COLUMN All cells are in 1 or more columns
* TableSelection::Column All cells are in 1 or more columns
* and in each column, all cells are selected
*/
uint32_t getSelectedCellsType(in Element aElement);
Expand Down
Loading

0 comments on commit 84a3c84

Please sign in to comment.