Bug 1387143 part 2. Stop using nsISelection in nsIDocumentEncoder. r=mats

This commit is contained in:
Boris Zbarsky 2018-05-08 13:52:36 -04:00
parent b23f25078d
commit 3463812125
11 changed files with 43 additions and 40 deletions

View File

@ -14,7 +14,6 @@
// Interfaces needed to be included
#include "nsCopySupport.h"
#include "nsISelection.h"
#include "nsISelectionController.h"
#include "nsIDOMNode.h"
#include "nsPIDOMWindow.h"
@ -53,6 +52,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLAreaElement.h"
#include "mozilla/dom/HTMLAnchorElement.h"
#include "mozilla/dom/Selection.h"
#include "nsVariant.h"
using namespace mozilla::dom;
@ -67,7 +67,7 @@ public:
bool aIsAltKeyPressed);
nsresult Produce(DataTransfer* aDataTransfer,
bool* aCanDrag,
nsISelection** aSelection,
Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec);
@ -120,7 +120,7 @@ nsContentAreaDragDrop::GetDragData(nsPIDOMWindowOuter* aWindow,
bool aIsAltKeyPressed,
DataTransfer* aDataTransfer,
bool* aCanDrag,
nsISelection** aSelection,
Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec)
{
@ -538,7 +538,7 @@ DragDataProducer::GetImageData(imgIContainer* aImage, imgIRequest* aRequest)
nsresult
DragDataProducer::Produce(DataTransfer* aDataTransfer,
bool* aCanDrag,
nsISelection** aSelection,
Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec)
{
@ -556,7 +556,7 @@ DragDataProducer::Produce(DataTransfer* aDataTransfer,
// Find the selection to see what we could be dragging and if what we're
// dragging is in what is selected. If this is an editable textbox, use
// the textbox's selection, otherwise use the window's selection.
nsCOMPtr<nsISelection> selection;
RefPtr<Selection> selection;
nsIContent* editingElement = mSelectionTargetNode->IsEditable() ?
mSelectionTargetNode->GetEditingHost() : nullptr;
nsCOMPtr<nsITextControlElement> textControl =
@ -564,7 +564,7 @@ DragDataProducer::Produce(DataTransfer* aDataTransfer,
if (textControl) {
nsISelectionController* selcon = textControl->GetSelectionController();
if (selcon) {
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
selection = selcon->GetDOMSelection(nsISelectionController::SELECTION_NORMAL);
}
if (!selection)

View File

@ -15,7 +15,6 @@
#include "nsITransferable.h"
class nsPIDOMWindowOuter;
class nsISelection;
class nsITransferable;
class nsIContent;
class nsIFile;
@ -23,6 +22,7 @@ class nsIFile;
namespace mozilla {
namespace dom {
class DataTransfer;
class Selection;
} // namespace dom
} // namespace mozilla
@ -60,7 +60,7 @@ public:
bool aIsAltKeyPressed,
mozilla::dom::DataTransfer* aDataTransfer,
bool* aCanDrag,
nsISelection** aSelection,
mozilla::dom::Selection** aSelection,
nsIContent** aDragNode,
nsACString& aPrincipalURISpec);
};

View File

@ -12,7 +12,6 @@
#include "nsIServiceManager.h"
#include "nsIClipboard.h"
#include "nsIFormControl.h"
#include "nsISelection.h"
#include "nsWidgetsCID.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
@ -89,7 +88,7 @@ static nsresult AppendImagePromise(nsITransferable* aTransferable,
// Helper used for HTMLCopy and GetTransferableForSelection since both routines
// share common code.
static nsresult
SelectionCopyHelper(nsISelection *aSel, nsIDocument *aDoc,
SelectionCopyHelper(Selection *aSel, nsIDocument *aDoc,
bool doPutOnClipboard, int16_t aClipboardID,
uint32_t aFlags, nsITransferable ** aTransferable)
{
@ -290,7 +289,7 @@ SelectionCopyHelper(nsISelection *aSel, nsIDocument *aDoc,
}
nsresult
nsCopySupport::HTMLCopy(nsISelection* aSel, nsIDocument* aDoc,
nsCopySupport::HTMLCopy(Selection* aSel, nsIDocument* aDoc,
int16_t aClipboardID, bool aWithRubyAnnotation)
{
uint32_t flags = nsIDocumentEncoder::SkipInvisibleContent;
@ -310,7 +309,7 @@ nsCopySupport::ClearSelectionCache()
}
nsresult
nsCopySupport::GetTransferableForSelection(nsISelection* aSel,
nsCopySupport::GetTransferableForSelection(Selection* aSel,
nsIDocument* aDoc,
nsITransferable** aTransferable)
{
@ -327,7 +326,7 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
// Make a temporary selection with aNode in a single range.
// XXX We should try to get rid of the Selection object here.
// XXX bug 1245883
nsCOMPtr<nsISelection> selection = new Selection();
RefPtr<Selection> selection = new Selection();
RefPtr<nsRange> range = new nsRange(aNode);
ErrorResult result;
range->SelectNode(*aNode, result);
@ -345,7 +344,7 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
}
nsresult
nsCopySupport::GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata)
nsCopySupport::GetContents(const nsACString& aMimeType, uint32_t aFlags, Selection *aSel, nsIDocument *aDoc, nsAString& outdata)
{
nsresult rv = NS_OK;

View File

@ -31,13 +31,15 @@ class nsCopySupport
// class of static helper functions for copy support
public:
static nsresult ClearSelectionCache();
static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
int16_t aClipboardID, bool aWithRubyAnnotation);
static nsresult HTMLCopy(mozilla::dom::Selection* aSel, nsIDocument* aDoc,
int16_t aClipboardID, bool aWithRubyAnnotation);
// Get the selection, or entire document, in the format specified by the mime type
// (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire
// doc.
static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata);
static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags,
mozilla::dom::Selection* aSel,
nsIDocument *aDoc, nsAString& outdata);
static nsresult ImageCopy(nsIImageLoadingContent* aImageElement,
nsILoadContext* aLoadContext,
@ -45,9 +47,9 @@ class nsCopySupport
// Get the selection as a transferable. Similar to HTMLCopy except does
// not deal with the clipboard.
static nsresult GetTransferableForSelection(nsISelection* aSelection,
nsIDocument* aDocument,
nsITransferable** aTransferable);
static nsresult GetTransferableForSelection(mozilla::dom::Selection* aSelection,
nsIDocument* aDocument,
nsITransferable** aTransferable);
// Same as GetTransferableForSelection, but doesn't skip invisible content.
static nsresult GetTransferableForNode(nsINode* aNode,

View File

@ -288,9 +288,9 @@ nsDocumentEncoder::SetWrapColumn(uint32_t aWC)
}
NS_IMETHODIMP
nsDocumentEncoder::SetSelection(nsISelection* aSelection)
nsDocumentEncoder::SetSelection(Selection* aSelection)
{
mSelection = aSelection->AsSelection();
mSelection = aSelection;
return NS_OK;
}
@ -1156,7 +1156,7 @@ public:
NS_IMETHOD Init(nsIDOMDocument* aDocument, const nsAString& aMimeType, uint32_t aFlags) override;
// overridden methods from nsDocumentEncoder
NS_IMETHOD SetSelection(nsISelection* aSelection) override;
NS_IMETHOD SetSelection(Selection* aSelection) override;
NS_IMETHOD EncodeToStringWithContext(nsAString& aContextString,
nsAString& aInfoString,
nsAString& aEncodedString) override;
@ -1236,7 +1236,7 @@ nsHTMLCopyEncoder::Init(nsIDOMDocument* aDocument,
}
NS_IMETHODIMP
nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
nsHTMLCopyEncoder::SetSelection(Selection* aSelection)
{
// check for text widgets: we need to recognize these so that
// we don't tweak the selection to be outside of the magic
@ -1245,8 +1245,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
if (!aSelection)
return NS_ERROR_NULL_POINTER;
Selection* selection = aSelection->AsSelection();
uint32_t rangeCount = selection->RangeCount();
uint32_t rangeCount = aSelection->RangeCount();
// if selection is uninitialized return
if (!rangeCount) {
@ -1263,7 +1262,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
// We should be able to write this as "Find the common ancestor of the
// selection, then go through the flattened tree and serialize the selected
// nodes", effectively serializing the composed tree.
RefPtr<nsRange> range = selection->GetRangeAt(0);
RefPtr<nsRange> range = aSelection->GetRangeAt(0);
nsINode* commonParent = range->GetCommonAncestor();
for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
@ -1322,7 +1321,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
// normalize selection if we are not in a widget
if (mIsTextWidget)
{
mSelection = selection;
mSelection = aSelection;
mMimeType.AssignLiteral("text/plain");
return NS_OK;
}
@ -1334,7 +1333,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
if (!(htmlDoc && mDocument->IsHTMLDocument())) {
mIsTextWidget = true;
mSelection = selection;
mSelection = aSelection;
// mMimeType is set to text/plain when encoding starts.
return NS_OK;
}
@ -1346,7 +1345,7 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
// loop thru the ranges in the selection
for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
range = selection->GetRangeAt(rangeIdx);
range = aSelection->GetRangeAt(rangeIdx);
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
RefPtr<nsRange> myRange = range->CloneRange();
MOZ_ASSERT(myRange);

View File

@ -6329,10 +6329,10 @@ nsGlobalWindowOuter::GetSelectionOuter()
return domSelection ? domSelection->AsSelection() : nullptr;
}
already_AddRefed<nsISelection>
already_AddRefed<Selection>
nsGlobalWindowOuter::GetSelection()
{
nsCOMPtr<nsISelection> selection = GetSelectionOuter();
RefPtr<Selection> selection = GetSelectionOuter();
return selection.forget();
}

View File

@ -638,7 +638,7 @@ public:
mozilla::ErrorResult& aError);
void PrintOuter(mozilla::ErrorResult& aError);
mozilla::dom::Selection* GetSelectionOuter();
already_AddRefed<nsISelection> GetSelection() override;
already_AddRefed<mozilla::dom::Selection> GetSelection() override;
already_AddRefed<mozilla::dom::MediaQueryList> MatchMediaOuter(
const nsAString& aQuery,
mozilla::dom::CallerType aCallerType);

View File

@ -7,10 +7,11 @@
interface nsIDOMDocument;
interface nsIDOMRange;
interface nsISelection;
interface nsIDOMNode;
interface nsIOutputStream;
webidl Selection;
%{ C++
class nsINode;
class nsIDocument;
@ -248,7 +249,7 @@ interface nsIDocumentEncoder : nsISupports
* document is encoded.
* @param aSelection The selection to encode.
*/
void setSelection(in nsISelection aSelection);
void setSelection(in Selection aSelection);
/**
* If the range is set to a non-null value, then the

View File

@ -53,6 +53,7 @@ class TabGroup;
class Element;
class Navigator;
class Performance;
class Selection;
class ServiceWorker;
class ServiceWorkerDescriptor;
class Timeout;
@ -1086,7 +1087,7 @@ public:
virtual nsresult GetPrompter(nsIPrompt** aPrompt) = 0;
virtual nsresult GetControllers(nsIControllers** aControllers) = 0;
virtual already_AddRefed<nsISelection> GetSelection() = 0;
virtual already_AddRefed<mozilla::dom::Selection> GetSelection() = 0;
virtual already_AddRefed<nsPIDOMWindowOuter> GetOpener() = 0;
virtual already_AddRefed<nsIDOMWindowCollection> GetFrames() = 0;

View File

@ -48,7 +48,6 @@
#include "nsIDOMXULControlElement.h"
#include "nsNameSpaceManager.h"
#include "nsIBaseWindow.h"
#include "nsISelection.h"
#include "nsFrameSelection.h"
#include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h"
@ -88,6 +87,7 @@
#include "mozilla/Services.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/HTMLLabelElement.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
@ -1937,7 +1937,7 @@ EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
}
});
nsCOMPtr<nsISelection> selection;
RefPtr<Selection> selection;
nsCOMPtr<nsIContent> eventContent, targetContent;
nsCString principalURISpec;
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(eventContent));
@ -2030,7 +2030,7 @@ void
EventStateManager::DetermineDragTargetAndDefaultData(nsPIDOMWindowOuter* aWindow,
nsIContent* aSelectionTarget,
DataTransfer* aDataTransfer,
nsISelection** aSelection,
Selection** aSelection,
nsIContent** aTargetNode,
nsACString& aPrincipalURISpec)
{

View File

@ -44,6 +44,7 @@ class WheelTransaction;
namespace dom {
class DataTransfer;
class Element;
class Selection;
class TabParent;
} // namespace dom
@ -1024,7 +1025,7 @@ protected:
void DetermineDragTargetAndDefaultData(nsPIDOMWindowOuter* aWindow,
nsIContent* aSelectionTarget,
dom::DataTransfer* aDataTransfer,
nsISelection** aSelection,
dom::Selection** aSelection,
nsIContent** aTargetNode,
nsACString& aPrincipalURISpec);