mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
bug 828138 - GetCurrentSelection() should return Selection* r=smaug
This commit is contained in:
parent
df3d973915
commit
0e12472abd
@ -45,6 +45,7 @@
|
||||
#include "nsContentCID.h"
|
||||
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/Selection.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
|
@ -195,6 +195,7 @@
|
||||
|
||||
#include "nsIDragService.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/Selection.h"
|
||||
#include "nsFrameLoader.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
|
@ -89,6 +89,8 @@ typedef short SelectionType;
|
||||
typedef uint64_t nsFrameState;
|
||||
|
||||
namespace mozilla {
|
||||
class Selection;
|
||||
|
||||
namespace dom {
|
||||
class Element;
|
||||
} // namespace dom
|
||||
@ -120,8 +122,8 @@ typedef struct CapturingContentInfo {
|
||||
|
||||
// a43e26cd-9573-44c7-8fe5-859549eff814
|
||||
#define NS_IPRESSHELL_IID \
|
||||
{ 0x13b031cb, 0x738a, 0x4e97, \
|
||||
{ 0xb0, 0xca, 0x8b, 0x4b, 0x6c, 0xbb, 0xea, 0xa9 } }
|
||||
{0xb0f585b5, 0x199b, 0x4cd7, \
|
||||
{0x9c, 0xee, 0xea, 0xfd, 0x40, 0xc4, 0x88, 0x6f}}
|
||||
|
||||
// debug VerifyReflow flags
|
||||
#define VERIFY_REFLOW_ON 0x01
|
||||
@ -749,7 +751,7 @@ public:
|
||||
*/
|
||||
int16_t GetSelectionFlags() const { return mSelectionFlags; }
|
||||
|
||||
virtual nsISelection* GetCurrentSelection(SelectionType aType) = 0;
|
||||
virtual mozilla::Selection* GetCurrentSelection(SelectionType aType) = 0;
|
||||
|
||||
/**
|
||||
* Interface to dispatch events via the presshell
|
||||
|
@ -1582,7 +1582,7 @@ PresShell::GetSelection(SelectionType aType, nsISelection **aSelection)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsISelection*
|
||||
Selection*
|
||||
PresShell::GetCurrentSelection(SelectionType aType)
|
||||
{
|
||||
if (!mSelection)
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
virtual NS_HIDDEN_(nsresult) SetPreferenceStyleRules(bool aForceReflow);
|
||||
|
||||
NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection);
|
||||
virtual nsISelection* GetCurrentSelection(SelectionType aType);
|
||||
virtual mozilla::Selection* GetCurrentSelection(SelectionType aType);
|
||||
|
||||
NS_IMETHOD SetDisplaySelection(int16_t aToggle);
|
||||
NS_IMETHOD GetDisplaySelection(int16_t *aToggle);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsISelection.h"
|
||||
#include "mozilla/Selection.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
@ -1078,23 +1078,23 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
|
||||
|
||||
// check here to see if there is a range selection
|
||||
// so we know whether to turn on the "Selection" radio button
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
selection = presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (selection) {
|
||||
int32_t count;
|
||||
selection->GetRangeCount(&count);
|
||||
if (count == 1) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
if (NS_SUCCEEDED(selection->GetRangeAt(0, getter_AddRefs(range)))) {
|
||||
// check to make sure it isn't an insertion selection
|
||||
bool isCollapsed;
|
||||
selection->GetIsCollapsed(&isCollapsed);
|
||||
return !isCollapsed;
|
||||
}
|
||||
}
|
||||
if (count > 1) return true;
|
||||
Selection* selection =
|
||||
presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (!selection) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
int32_t rangeCount = selection->GetRangeCount();
|
||||
if (!rangeCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rangeCount > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check to make sure it isn't an insertion selection
|
||||
return selection->GetRangeAt(0) && !selection->IsCollapsed();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
@ -2031,7 +2031,7 @@ nsPrintEngine::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> displayShell = aPO->mDocShell->GetPresShell();
|
||||
// Transfer Selection Ranges to the new Print PresShell
|
||||
nsCOMPtr<nsISelection> selection, selectionPS;
|
||||
nsRefPtr<Selection> selection, selectionPS;
|
||||
// It's okay if there is no display shell, just skip copying the selection
|
||||
if (displayShell) {
|
||||
selection = displayShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
@ -2044,13 +2044,10 @@ nsPrintEngine::UpdateSelectionAndShrinkPrintObject(nsPrintObject* aPO,
|
||||
selectionPS->RemoveAllRanges();
|
||||
}
|
||||
if (selection && selectionPS) {
|
||||
int32_t cnt;
|
||||
selection->GetRangeCount(&cnt);
|
||||
int32_t cnt = selection->GetRangeCount();
|
||||
int32_t inx;
|
||||
for (inx = 0; inx < cnt; ++inx) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
if (NS_SUCCEEDED(selection->GetRangeAt(inx, getter_AddRefs(range))))
|
||||
selectionPS->AddRange(range);
|
||||
selectionPS->AddRange(selection->GetRangeAt(inx));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2408,35 +2405,32 @@ GetEqualNodeInCloneTree(nsIDOMNode* aNode, nsIDocument* aDoc)
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
static nsresult CloneRangeToSelection(nsIDOMRange* aRange,
|
||||
nsIDocument* aDoc,
|
||||
nsISelection* aSelection)
|
||||
static void
|
||||
CloneRangeToSelection(nsRange* aRange, nsIDocument* aDoc,
|
||||
Selection* aSelection)
|
||||
{
|
||||
bool collapsed = false;
|
||||
aRange->GetCollapsed(&collapsed);
|
||||
if (collapsed) {
|
||||
return NS_OK;
|
||||
if (aRange->Collapsed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> startContainer, endContainer;
|
||||
int32_t startOffset = -1, endOffset = -1;
|
||||
aRange->GetStartContainer(getter_AddRefs(startContainer));
|
||||
aRange->GetStartOffset(&startOffset);
|
||||
int32_t startOffset = aRange->StartOffset();
|
||||
aRange->GetEndContainer(getter_AddRefs(endContainer));
|
||||
aRange->GetEndOffset(&endOffset);
|
||||
NS_ENSURE_STATE(startContainer && endContainer);
|
||||
int32_t endOffset = aRange->EndOffset();
|
||||
NS_ENSURE_TRUE_VOID(startContainer && endContainer);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newStart = GetEqualNodeInCloneTree(startContainer, aDoc);
|
||||
nsCOMPtr<nsIDOMNode> newEnd = GetEqualNodeInCloneTree(endContainer, aDoc);
|
||||
NS_ENSURE_STATE(newStart && newEnd);
|
||||
NS_ENSURE_TRUE_VOID(newStart && newEnd);
|
||||
|
||||
nsRefPtr<nsRange> range = new nsRange();
|
||||
nsresult rv = range->SetStart(newStart, startOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
rv = range->SetEnd(newEnd, endOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
return aSelection->AddRange(range);
|
||||
aSelection->AddRange(range);
|
||||
}
|
||||
|
||||
static nsresult CloneSelection(nsIDocument* aOrigDoc, nsIDocument* aDoc)
|
||||
@ -2445,20 +2439,15 @@ static nsresult CloneSelection(nsIDocument* aOrigDoc, nsIDocument* aDoc)
|
||||
nsIPresShell* shell = aDoc->GetShell();
|
||||
NS_ENSURE_STATE(origShell && shell);
|
||||
|
||||
nsCOMPtr<nsISelection> origSelection =
|
||||
nsRefPtr<Selection> origSelection =
|
||||
origShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
nsCOMPtr<nsISelection> selection =
|
||||
nsRefPtr<Selection> selection =
|
||||
shell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
NS_ENSURE_STATE(origSelection && selection);
|
||||
|
||||
int32_t rangeCount = 0;
|
||||
origSelection->GetRangeCount(&rangeCount);
|
||||
int32_t rangeCount = origSelection->GetRangeCount();
|
||||
for (int32_t i = 0; i < rangeCount; ++i) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
origSelection->GetRangeAt(i, getter_AddRefs(range));
|
||||
if (range) {
|
||||
CloneRangeToSelection(range, aDoc, selection);
|
||||
}
|
||||
CloneRangeToSelection(origSelection->GetRangeAt(i), aDoc, selection);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2547,8 +2536,8 @@ nsPrintEngine::DoPrint(nsPrintObject * aPO)
|
||||
nsRect startRect;
|
||||
nsRect endRect;
|
||||
|
||||
nsCOMPtr<nsISelection> selectionPS;
|
||||
selectionPS = poPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
nsRefPtr<Selection> selectionPS =
|
||||
poPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
|
||||
rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence,
|
||||
&startFrame, startPageNum, startRect,
|
||||
|
Loading…
Reference in New Issue
Block a user