Bug 1261299 - Update the selection cache on repaint to handle when a pre-existing selection becomes active aka the current selection. r=smaug

MozReview-Commit-ID: HrTQnHd12rg

--HG--
extra : rebase_source : bd727de70576a39da3cd3fab1754330c41add768
This commit is contained in:
Jimmy Wang 2016-07-27 16:05:37 -04:00
Родитель a7ba1f9d54
Коммит a2bf6b970a
2 изменённых файлов: 52 добавлений и 2 удалений

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

@ -373,7 +373,7 @@ public:
* specified by aSelectionType.
* @param aSelectionType The selection type what you want to repaint.
*/
nsresult RepaintSelection(mozilla::SelectionType aSelectionType) const;
nsresult RepaintSelection(mozilla::SelectionType aSelectionType);
/** GetFrameForNodeOffset given a node and its child offset, return the nsIFrame and
* the offset into that frame.
@ -681,6 +681,10 @@ private:
// nsFrameSelection may get deleted when calling this,
// so remember to use nsCOMPtr when needed.
nsresult NotifySelectionListeners(mozilla::SelectionType aSelectionType);
// Update the selection cache on repaint when the
// selection being repainted is not empty.
nsresult UpdateSelectionCacheOnRepaintSelection(mozilla::dom::
Selection* aSel);
RefPtr<mozilla::dom::Selection>
mDomSelections[mozilla::kPresentSelectionTypeCount];

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

@ -1964,7 +1964,7 @@ nsFrameSelection::ScrollSelectionIntoView(SelectionType aSelectionType,
}
nsresult
nsFrameSelection::RepaintSelection(SelectionType aSelectionType) const
nsFrameSelection::RepaintSelection(SelectionType aSelectionType)
{
int8_t index = GetIndexFromSelectionType(aSelectionType);
if (index < 0)
@ -1972,6 +1972,14 @@ nsFrameSelection::RepaintSelection(SelectionType aSelectionType) const
if (!mDomSelections[index])
return NS_ERROR_NULL_POINTER;
NS_ENSURE_STATE(mShell);
// On macOS, update the selection cache to the new active selection
// aka the current selection.
#ifdef XP_MACOSX
if (aSelectionType == SelectionType::eNormal) {
UpdateSelectionCacheOnRepaintSelection(mDomSelections[index]);
}
#endif
return mDomSelections[index]->Repaint(mShell->GetPresContext());
}
@ -6512,6 +6520,44 @@ nsAutoCopyListener::NotifySelectionChanged(nsIDOMDocument *aDoc,
mCachedClipboard, false);
}
/**
* See Bug 1288453.
*
* Update the selection cache on repaint to handle when a pre-existing
* selection becomes active aka the current selection.
*
* 1. Change the current selection by click n dragging another selection.
* - Make a selection on content page. Make a selection in a text editor.
* - You can click n drag the content selection to make it active again.
* 2. Change the current selection when switching to a tab with a selection.
* - Make selection in tab.
* - Switching tabs will make its respective selection active.
*
* Therefore, we only update the selection cache on a repaint
* if the current selection being repainted is not an empty selection.
*
* If the current selection is empty. The current selection cache
* would be cleared by nsAutoCopyListener::NotifySelectionChanged.
*/
nsresult
nsFrameSelection::UpdateSelectionCacheOnRepaintSelection(Selection* aSel)
{
nsIPresShell* ps = aSel->GetPresShell();
if (!ps) {
return NS_OK;
}
nsCOMPtr<nsIDocument> aDoc = ps->GetDocument();
bool collapsed;
if (aDoc && aSel &&
NS_SUCCEEDED(aSel->GetIsCollapsed(&collapsed)) && !collapsed) {
return nsCopySupport::HTMLCopy(aSel, aDoc,
nsIClipboard::kSelectionCache, false);
}
return NS_OK;
}
// SelectionChangeListener
SelectionChangeListener::RawRangeData::RawRangeData(const nsRange* aRange)