Bug 1447889 part 1. Change nsCopySupport to work with Selection a bit more. r=mystor

MozReview-Commit-ID: B8HePBcalWU
This commit is contained in:
Boris Zbarsky 2018-03-27 00:35:20 -04:00
Родитель 17509bc9da
Коммит 0245595d7e
3 изменённых файлов: 21 добавлений и 16 удалений

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

@ -688,7 +688,7 @@ static nsresult AppendImagePromise(nsITransferable* aTransferable,
#endif // XP_WIN
nsIContent*
nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, nsISelection** aSelection)
nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, Selection** aSelection)
{
*aSelection = nullptr;
@ -704,8 +704,9 @@ nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, nsISelection** aSelec
return nullptr;
}
selectionController->GetSelection(nsISelectionController::SELECTION_NORMAL,
aSelection);
RefPtr<Selection> sel =
selectionController->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
sel.forget(aSelection);
return focusedContent;
}
@ -715,13 +716,11 @@ nsCopySupport::CanCopy(nsIDocument* aDocument)
if (!aDocument)
return false;
nsCOMPtr<nsISelection> sel;
RefPtr<Selection> sel;
GetSelectionForCopy(aDocument, getter_AddRefs(sel));
NS_ENSURE_TRUE(sel, false);
bool isCollapsed;
sel->GetIsCollapsed(&isCollapsed);
return !isCollapsed;
return !sel->IsCollapsed();
}
static bool
@ -760,7 +759,7 @@ bool
nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
int32_t aClipboardType,
nsIPresShell* aPresShell,
nsISelection* aSelection,
Selection* aSelection,
bool* aActionTaken)
{
if (aActionTaken) {
@ -790,9 +789,10 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
// if a selection was not supplied, try to find it
nsCOMPtr<nsIContent> content;
nsCOMPtr<nsISelection> sel = aSelection;
if (!sel)
RefPtr<Selection> sel = aSelection;
if (!sel) {
content = GetSelectionForCopy(doc, getter_AddRefs(sel));
}
// retrieve the event target node from the start of the selection
nsresult rv;

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

@ -20,6 +20,12 @@ class nsITransferable;
class nsIPresShell;
class nsILoadContext;
namespace mozilla {
namespace dom {
class Selection;
} // namespace dom
} // namespace mozilla
class nsCopySupport
{
// class of static helper functions for copy support
@ -56,7 +62,7 @@ class nsCopySupport
* set to the document's selection and null will be returned.
*/
static nsIContent* GetSelectionForCopy(nsIDocument* aDocument,
nsISelection** aSelection);
mozilla::dom::Selection** aSelection);
/**
* Returns true if a copy operation is currently permitted based on the
@ -93,7 +99,7 @@ class nsCopySupport
static bool FireClipboardEvent(mozilla::EventMessage aEventMessage,
int32_t aClipboardType,
nsIPresShell* aPresShell,
nsISelection* aSelection,
mozilla::dom::Selection* aSelection,
bool* aActionTaken = nullptr);
};

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

@ -2798,15 +2798,14 @@ NS_IMETHODIMP nsDocumentViewer::GetContents(const char *mimeType, bool selection
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED);
// Now we have the selection. Make sure it's nonzero:
nsCOMPtr<nsISelection> sel;
RefPtr<Selection> sel;
if (selectionOnly) {
nsCopySupport::GetSelectionForCopy(mDocument, getter_AddRefs(sel));
NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);
bool isCollapsed;
sel->GetIsCollapsed(&isCollapsed);
if (isCollapsed)
if (sel->IsCollapsed()) {
return NS_OK;
}
}
// call the copy code