Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1120316 - Part 1: Move SelectionBatcher to Selection.h. r=roc
Browse files Browse the repository at this point in the history
  • Loading branch information
mephisto41 committed Feb 4, 2015
1 parent cc0a8d7 commit 42761ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
25 changes: 4 additions & 21 deletions editor/libeditor/nsTableEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,6 @@ class MOZ_STACK_CLASS nsSetSelectionAfterTableEdit
void CancelSetCaret() {mEd = nullptr; mTable = nullptr;}
};

// Stack-class to turn on/off selection batching for table selection
class MOZ_STACK_CLASS nsSelectionBatcherForTable
{
private:
nsRefPtr<mozilla::dom::Selection> mSelection;
public:
explicit nsSelectionBatcherForTable(Selection* aSelection)
{
mSelection = aSelection;
if (mSelection) mSelection->StartBatchChanges();
}
virtual ~nsSelectionBatcherForTable()
{
if (mSelection) mSelection->EndBatchChanges();
}
};

// Table Editing helper utilities (not exposed in IDL)

NS_IMETHODIMP
Expand Down Expand Up @@ -1448,7 +1431,7 @@ nsHTMLEditor::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndC

// Suppress nsISelectionListener notification
// until all selection changes are finished
nsSelectionBatcherForTable selectionBatcher(selection);
SelectionBatcher selectionBatcher(selection);

// Examine all cell nodes in current selection and
// remove those outside the new block cell region
Expand Down Expand Up @@ -1529,7 +1512,7 @@ nsHTMLEditor::SelectAllTableCells()

// Suppress nsISelectionListener notification
// until all selection changes are finished
nsSelectionBatcherForTable selectionBatcher(selection);
SelectionBatcher selectionBatcher(selection);

// It is now safe to clear the selection
// BE SURE TO RESET IT BEFORE LEAVING!
Expand Down Expand Up @@ -1599,7 +1582,7 @@ nsHTMLEditor::SelectTableRow()

// Suppress nsISelectionListener notification
// until all selection changes are finished
nsSelectionBatcherForTable selectionBatcher(selection);
SelectionBatcher selectionBatcher(selection);

// It is now safe to clear the selection
// BE SURE TO RESET IT BEFORE LEAVING!
Expand Down Expand Up @@ -1662,7 +1645,7 @@ nsHTMLEditor::SelectTableColumn()

// Suppress nsISelectionListener notification
// until all selection changes are finished
nsSelectionBatcherForTable selectionBatcher(selection);
SelectionBatcher selectionBatcher(selection);

// It is now safe to clear the selection
// BE SURE TO RESET IT BEFORE LEAVING!
Expand Down
22 changes: 22 additions & 0 deletions layout/generic/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ class Selection MOZ_FINAL : public nsISelectionPrivate,
bool mApplyUserSelectStyle;
};

// Stack-class to turn on/off selection batching.
class MOZ_STACK_CLASS SelectionBatcher MOZ_FINAL
{
private:
nsRefPtr<Selection> mSelection;
public:
explicit SelectionBatcher(Selection* aSelection)
{
mSelection = aSelection;
if (mSelection) {
mSelection->StartBatchChanges();
}
}

~SelectionBatcher()
{
if (mSelection) {
mSelection->EndBatchChanges();
}
}
};

} // namespace dom
} // namespace mozilla

Expand Down
18 changes: 1 addition & 17 deletions layout/generic/nsSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@ struct CachedOffsetForFrame {
bool mCanCacheFrameOffset; // cached frame offset is valid?
};

// Stack-class to turn on/off selection batching for table selection
class MOZ_STACK_CLASS nsSelectionBatcher MOZ_FINAL
{
private:
nsCOMPtr<nsISelectionPrivate> mSelection;
public:
explicit nsSelectionBatcher(nsISelectionPrivate *aSelection) : mSelection(aSelection)
{
if (mSelection) mSelection->StartBatchChanges();
}
~nsSelectionBatcher()
{
if (mSelection) mSelection->EndBatchChanges();
}
};

class nsAutoScrollTimer MOZ_FINAL : public nsITimerCallback
{
public:
Expand Down Expand Up @@ -2175,7 +2159,7 @@ nsFrameSelection::HandleTableSelection(nsINode* aParentContent,

// Stack-class to wrap all table selection changes in
// BeginBatchChanges() / EndBatchChanges()
nsSelectionBatcher selectionBatcher(mDomSelections[index]);
SelectionBatcher selectionBatcher(mDomSelections[index]);

int32_t startRowIndex, startColIndex, curRowIndex, curColIndex;
if (mDragState && mDragSelectingCells)
Expand Down

0 comments on commit 42761ee

Please sign in to comment.