mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 18:51:28 +00:00
Bug 739396, part 0 - Make nsDocumentViewer use mozilla::dom::Selection internally instead of nsISelection.
This commit is contained in:
parent
7f42e3826b
commit
63eddaffcd
@ -28,7 +28,7 @@
|
||||
#include "nsILinkHandler.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsISelectionListener.h"
|
||||
#include "nsISelectionPrivate.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsContentUtils.h"
|
||||
@ -316,7 +316,7 @@ private:
|
||||
|
||||
nsresult SyncParentSubDocMap();
|
||||
|
||||
nsresult GetDocumentSelection(nsISelection **aSelection);
|
||||
mozilla::dom::Selection* GetDocumentSelection();
|
||||
|
||||
void DestroyPresShell();
|
||||
void DestroyPresContext();
|
||||
@ -704,12 +704,12 @@ nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow)
|
||||
mSelectionListener = selectionListener;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = GetDocumentSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsRefPtr<mozilla::dom::Selection> selection = GetDocumentSelection();
|
||||
if (!selection) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));
|
||||
rv = selPrivate->AddSelectionListener(mSelectionListener);
|
||||
rv = selection->AddSelectionListener(mSelectionListener);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
@ -2562,19 +2562,14 @@ nsDocumentViewer::CreateDeviceContext(nsView* aContainerView)
|
||||
|
||||
// Return the selection for the document. Note that text fields have their
|
||||
// own selection, which cannot be accessed with this method.
|
||||
nsresult nsDocumentViewer::GetDocumentSelection(nsISelection **aSelection)
|
||||
mozilla::dom::Selection*
|
||||
nsDocumentViewer::GetDocumentSelection()
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aSelection);
|
||||
if (!mPresShell) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelectionController> selcon;
|
||||
selcon = do_QueryInterface(mPresShell);
|
||||
if (selcon)
|
||||
return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
aSelection);
|
||||
return NS_ERROR_FAILURE;
|
||||
return mPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
}
|
||||
|
||||
/* ========================================================================================
|
||||
@ -2583,12 +2578,11 @@ nsresult nsDocumentViewer::GetDocumentSelection(nsISelection **aSelection)
|
||||
|
||||
NS_IMETHODIMP nsDocumentViewer::ClearSelection()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
|
||||
// use nsCopySupport::GetSelectionForCopy() ?
|
||||
rv = GetDocumentSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsRefPtr<mozilla::dom::Selection> selection = GetDocumentSelection();
|
||||
if (!selection) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return selection->CollapseToStart();
|
||||
}
|
||||
@ -2598,16 +2592,17 @@ NS_IMETHODIMP nsDocumentViewer::SelectAll()
|
||||
// XXX this is a temporary implementation copied from nsWebShell
|
||||
// for now. I think nsDocument and friends should have some helper
|
||||
// functions to make this easier.
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult rv;
|
||||
|
||||
// use nsCopySupport::GetSelectionForCopy() ?
|
||||
rv = GetDocumentSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsRefPtr<mozilla::dom::Selection> selection = GetDocumentSelection();
|
||||
if (!selection) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLDocument> htmldoc = do_QueryInterface(mDocument);
|
||||
nsCOMPtr<nsIDOMNode> bodyNode;
|
||||
|
||||
nsresult rv;
|
||||
if (htmldoc)
|
||||
{
|
||||
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
|
||||
@ -3548,9 +3543,10 @@ NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocumen
|
||||
NS_ASSERTION(mDocViewer, "Should have doc viewer!");
|
||||
|
||||
// get the selection state
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult rv = mDocViewer->GetDocumentSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsRefPtr<mozilla::dom::Selection> selection = mDocViewer->GetDocumentSelection();
|
||||
if (!selection) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsIDocument* theDoc = mDocViewer->GetDocument();
|
||||
if (!theDoc) return NS_ERROR_FAILURE;
|
||||
@ -4432,11 +4428,9 @@ nsDocumentViewer::DestroyPresShell()
|
||||
// Break circular reference (or something)
|
||||
mPresShell->EndObservingDocument();
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
GetDocumentSelection(getter_AddRefs(selection));
|
||||
nsCOMPtr<nsISelectionPrivate> selPrivate = do_QueryInterface(selection);
|
||||
if (selPrivate && mSelectionListener)
|
||||
selPrivate->RemoveSelectionListener(mSelectionListener);
|
||||
nsRefPtr<mozilla::dom::Selection> selection = GetDocumentSelection();
|
||||
if (selection && mSelectionListener)
|
||||
selection->RemoveSelectionListener(mSelectionListener);
|
||||
|
||||
nsRefPtr<SelectionCarets> selectionCaret = mPresShell->GetSelectionCarets();
|
||||
if (selectionCaret) {
|
||||
|
Loading…
Reference in New Issue
Block a user