mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 04:03:47 +00:00
Bug 1387143 part 21. Remove nsISelection getters for anchor and focus points. r=mats
Instead of copying spec-duplicating comments from nsISelection.idl to Selection.webidl, this just points the latter to the right spec.
This commit is contained in:
parent
1ff99d888e
commit
f7d68d6078
@ -800,45 +800,6 @@ Selection::FocusRef()
|
||||
return mAnchorFocusRange->StartRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Selection::GetAnchorNode(nsIDOMNode** aAnchorNode)
|
||||
{
|
||||
nsINode* anchorNode = GetAnchorNode();
|
||||
if (anchorNode) {
|
||||
return CallQueryInterface(anchorNode, aAnchorNode);
|
||||
}
|
||||
|
||||
*aAnchorNode = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Selection::GetAnchorOffset(int32_t* aAnchorOffset)
|
||||
{
|
||||
*aAnchorOffset = static_cast<int32_t>(AnchorOffset());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// note: this can return a nil focus node
|
||||
NS_IMETHODIMP
|
||||
Selection::GetFocusNode(nsIDOMNode** aFocusNode)
|
||||
{
|
||||
nsINode* focusNode = GetFocusNode();
|
||||
if (focusNode) {
|
||||
return CallQueryInterface(focusNode, aFocusNode);
|
||||
}
|
||||
|
||||
*aFocusNode = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
Selection::GetFocusOffset(int32_t* aFocusOffset)
|
||||
{
|
||||
*aFocusOffset = static_cast<int32_t>(FocusOffset());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
Selection::SetAnchorFocusRange(int32_t indx)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ private:
|
||||
nsresult AddStringsToDataTransfer(nsIContent* aDragNode,
|
||||
DataTransfer* aDataTransfer);
|
||||
nsresult GetImageData(imgIContainer* aImage, imgIRequest* aRequest);
|
||||
static nsresult GetDraggableSelectionData(nsISelection* inSelection,
|
||||
static nsresult GetDraggableSelectionData(Selection* inSelection,
|
||||
nsIContent* inRealTargetNode,
|
||||
nsIContent **outImageOrLinkNode,
|
||||
bool* outDragSelectedText);
|
||||
@ -944,7 +944,7 @@ DragDataProducer::AddStringsToDataTransfer(nsIContent* aDragNode,
|
||||
// note that this can return NS_OK, but a null out param (by design)
|
||||
// static
|
||||
nsresult
|
||||
DragDataProducer::GetDraggableSelectionData(nsISelection* inSelection,
|
||||
DragDataProducer::GetDraggableSelectionData(Selection* inSelection,
|
||||
nsIContent* inRealTargetNode,
|
||||
nsIContent **outImageOrLinkNode,
|
||||
bool* outDragSelectedText)
|
||||
@ -967,25 +967,21 @@ DragDataProducer::GetDraggableSelectionData(nsISelection* inSelection,
|
||||
|
||||
if (selectionContainsTarget) {
|
||||
// track down the anchor node, if any, for the url
|
||||
nsCOMPtr<nsIDOMNode> selectionStart;
|
||||
inSelection->GetAnchorNode(getter_AddRefs(selectionStart));
|
||||
|
||||
nsCOMPtr<nsIDOMNode> selectionEnd;
|
||||
inSelection->GetFocusNode(getter_AddRefs(selectionEnd));
|
||||
nsINode* selectionStart = inSelection->GetAnchorNode();
|
||||
nsINode* selectionEnd = inSelection->GetFocusNode();
|
||||
|
||||
// look for a selection around a single node, like an image.
|
||||
// in this case, drag the image, rather than a serialization of the HTML
|
||||
// XXX generalize this to other draggable element types?
|
||||
if (selectionStart == selectionEnd) {
|
||||
nsCOMPtr<nsIContent> selStartContent = do_QueryInterface(selectionStart);
|
||||
nsCOMPtr<nsIContent> selStartContent = nsIContent::FromNodeOrNull(selectionStart);
|
||||
if (selStartContent && selStartContent->HasChildNodes()) {
|
||||
// see if just one node is selected
|
||||
int32_t anchorOffset, focusOffset;
|
||||
inSelection->GetAnchorOffset(&anchorOffset);
|
||||
inSelection->GetFocusOffset(&focusOffset);
|
||||
if (abs(anchorOffset - focusOffset) == 1) {
|
||||
int32_t childOffset =
|
||||
(anchorOffset < focusOffset) ? anchorOffset : focusOffset;
|
||||
uint32_t anchorOffset = inSelection->AnchorOffset();
|
||||
uint32_t focusOffset = inSelection->FocusOffset();
|
||||
if (anchorOffset == focusOffset + 1 ||
|
||||
focusOffset == anchorOffset + 1) {
|
||||
uint32_t childOffset = std::min(anchorOffset, focusOffset);
|
||||
nsIContent *childContent =
|
||||
selStartContent->GetChildAt_Deprecated(childOffset);
|
||||
// if we find an image, we'll fall into the node-dragging code,
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(nsIContent)
|
||||
|
||||
NS_IMPL_FROMNODE_HELPER(nsIContent, IsContent())
|
||||
|
||||
/**
|
||||
* Bind this content node to a tree. If this method throws, the caller must
|
||||
* call UnbindFromTree() on the node. In the typical case of a node being
|
||||
|
@ -28,26 +28,6 @@ class Selection;
|
||||
[shim(Selection), uuid(e0a4d4b3-f34e-44bd-b1f2-4e3bde9b6915)]
|
||||
interface nsISelection : nsISupports
|
||||
{
|
||||
/**
|
||||
* Returns the node in which the selection begins.
|
||||
*/
|
||||
readonly attribute nsIDOMNode anchorNode;
|
||||
|
||||
/**
|
||||
* The offset within the (text) node where the selection begins.
|
||||
*/
|
||||
readonly attribute long anchorOffset;
|
||||
|
||||
/**
|
||||
* Returns the node in which the selection ends.
|
||||
*/
|
||||
readonly attribute nsIDOMNode focusNode;
|
||||
|
||||
/**
|
||||
* The offset within the (text) node where the selection ends.
|
||||
*/
|
||||
readonly attribute long focusOffset;
|
||||
|
||||
/**
|
||||
* Indicates if the selection is collapsed or not.
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* The origin of this IDL file is
|
||||
* https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#concept-selection
|
||||
* https://w3c.github.io/selection-api/#selection-interface
|
||||
*
|
||||
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
|
@ -57,7 +57,6 @@
|
||||
#include "nsTArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsContainerFrame.h"
|
||||
#include "nsISelection.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
@ -2862,12 +2861,10 @@ nsIPresShell::GetSelectedContentForScrolling() const
|
||||
{
|
||||
nsCOMPtr<nsIContent> selectedContent;
|
||||
if (mSelection) {
|
||||
nsISelection* domSelection =
|
||||
Selection* domSelection =
|
||||
mSelection->GetSelection(SelectionType::eNormal);
|
||||
if (domSelection) {
|
||||
nsCOMPtr<nsIDOMNode> focusedNode;
|
||||
domSelection->GetFocusNode(getter_AddRefs(focusedNode));
|
||||
selectedContent = do_QueryInterface(focusedNode);
|
||||
selectedContent = nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
|
||||
}
|
||||
}
|
||||
return selectedContent.forget();
|
||||
@ -8263,18 +8260,16 @@ PresShell::PrepareToUseCaretPosition(nsIWidget* aEventWidget,
|
||||
|
||||
// caret selection, this is a temporary weak reference, so no refcounting is
|
||||
// needed
|
||||
nsISelection* domSelection = caret->GetSelection();
|
||||
Selection* domSelection = caret->GetSelection();
|
||||
NS_ENSURE_TRUE(domSelection, false);
|
||||
|
||||
// since the match could be an anonymous textnode inside a
|
||||
// <textarea> or text <input>, we need to get the outer frame
|
||||
// note: frames are not refcounted
|
||||
nsIFrame* frame = nullptr; // may be nullptr
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
rv = domSelection->GetFocusNode(getter_AddRefs(node));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
nsINode* node = domSelection->GetFocusNode();
|
||||
NS_ENSURE_TRUE(node, false);
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
||||
nsCOMPtr<nsIContent> content = nsIContent::FromNode(node);
|
||||
if (content) {
|
||||
nsIContent* nonNative = content->FindFirstNonChromeOnlyAccessContent();
|
||||
content = nonNative;
|
||||
|
@ -224,7 +224,7 @@ void nsCaret::Terminate()
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCaret, nsISelectionListener)
|
||||
|
||||
nsISelection* nsCaret::GetSelection()
|
||||
Selection* nsCaret::GetSelection()
|
||||
{
|
||||
return mDomSelectionWeak;
|
||||
}
|
||||
@ -391,7 +391,7 @@ nsCaret::GetFrameAndOffset(Selection* aSelection,
|
||||
focusOffset = aOverrideOffset;
|
||||
} else if (aSelection) {
|
||||
focusNode = aSelection->GetFocusNode();
|
||||
aSelection->GetFocusOffset(&focusOffset);
|
||||
focusOffset = aSelection->FocusOffset();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
@ -426,20 +426,13 @@ nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect)
|
||||
return frame;
|
||||
}
|
||||
|
||||
Selection*
|
||||
nsCaret::GetSelectionInternal()
|
||||
{
|
||||
nsISelection* domSelection = GetSelection();
|
||||
return domSelection ? domSelection->AsSelection() : nullptr;
|
||||
}
|
||||
|
||||
void nsCaret::SchedulePaint(nsISelection* aSelection)
|
||||
{
|
||||
Selection* selection;
|
||||
if (aSelection) {
|
||||
selection = aSelection->AsSelection();
|
||||
} else {
|
||||
selection = GetSelectionInternal();
|
||||
selection = GetSelection();
|
||||
}
|
||||
nsINode* focusNode;
|
||||
if (mOverrideContent) {
|
||||
@ -499,7 +492,7 @@ nsCaret::CheckSelectionLanguageChange()
|
||||
// Call SelectionLanguageChange on every paint. Mostly it will be a noop
|
||||
// but it should be fast anyway. This guarantees we never paint the caret
|
||||
// at the wrong place.
|
||||
Selection* selection = GetSelectionInternal();
|
||||
Selection* selection = GetSelection();
|
||||
if (selection) {
|
||||
selection->SelectionLanguageChange(isKeyboardRTL);
|
||||
}
|
||||
@ -518,7 +511,7 @@ nsCaret::GetPaintGeometry(nsRect* aRect)
|
||||
CheckSelectionLanguageChange();
|
||||
|
||||
int32_t frameOffset;
|
||||
nsIFrame* frame = GetFrameAndOffset(GetSelectionInternal(),
|
||||
nsIFrame* frame = GetFrameAndOffset(GetSelection(),
|
||||
mOverrideContent, mOverrideOffset, &frameOffset);
|
||||
if (!frame) {
|
||||
return nullptr;
|
||||
@ -550,7 +543,7 @@ nsCaret::GetPaintGeometry(nsRect* aRect)
|
||||
|
||||
nsIFrame*
|
||||
nsCaret::GetFrame(int32_t* aContentOffset) {
|
||||
return GetFrameAndOffset(GetSelectionInternal(),
|
||||
return GetFrameAndOffset(GetSelection(),
|
||||
mOverrideContent,
|
||||
mOverrideOffset,
|
||||
aContentOffset);
|
||||
@ -873,10 +866,8 @@ bool nsCaret::IsMenuPopupHidingCaret()
|
||||
if (!mDomSelectionWeak) {
|
||||
return true; // No selection/caret to draw.
|
||||
}
|
||||
mDomSelectionWeak->GetFocusNode(getter_AddRefs(node));
|
||||
if (!node)
|
||||
return true; // No selection/caret to draw.
|
||||
nsCOMPtr<nsIContent> caretContent = do_QueryInterface(node);
|
||||
nsCOMPtr<nsIContent> caretContent =
|
||||
nsIContent::FromNodeOrNull(mDomSelectionWeak->GetFocusNode());
|
||||
if (!caretContent)
|
||||
return true; // No selection/caret to draw.
|
||||
|
||||
|
@ -53,7 +53,7 @@ class nsCaret final : public nsISelectionListener
|
||||
void Terminate();
|
||||
|
||||
void SetSelection(mozilla::dom::Selection *aDOMSel);
|
||||
nsISelection* GetSelection();
|
||||
mozilla::dom::Selection* GetSelection();
|
||||
|
||||
/**
|
||||
* Sets whether the caret should only be visible in nodes that are not
|
||||
@ -86,7 +86,7 @@ class nsCaret final : public nsISelectionListener
|
||||
if (aSelection) {
|
||||
selection = static_cast<mozilla::dom::Selection*>(aSelection);
|
||||
} else {
|
||||
selection = GetSelectionInternal();
|
||||
selection = GetSelection();
|
||||
}
|
||||
if (!selection || !selection->IsCollapsed()) {
|
||||
return false;
|
||||
@ -213,8 +213,6 @@ protected:
|
||||
void ResetBlinking();
|
||||
void StopBlinking();
|
||||
|
||||
mozilla::dom::Selection* GetSelectionInternal();
|
||||
|
||||
struct Metrics {
|
||||
nscoord mBidiIndicatorSize; // width and height of bidi indicator
|
||||
nscoord mCaretWidth; // full caret width including bidi indicator
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "nsIFrameInlines.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "nsISelection.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "TextDrawTarget.h"
|
||||
|
||||
using mozilla::layout::TextDrawTarget;
|
||||
@ -828,11 +828,10 @@ TextOverflow::CanHaveTextOverflow(nsIFrame* aBlockFrame)
|
||||
// Inhibit the markers if a descendant content owns the caret.
|
||||
RefPtr<nsCaret> caret = aBlockFrame->PresShell()->GetCaret();
|
||||
if (caret && caret->IsVisible()) {
|
||||
nsCOMPtr<nsISelection> domSelection = caret->GetSelection();
|
||||
RefPtr<dom::Selection> domSelection = caret->GetSelection();
|
||||
if (domSelection) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
domSelection->GetFocusNode(getter_AddRefs(node));
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
||||
nsCOMPtr<nsIContent> content =
|
||||
nsIContent::FromNodeOrNull(domSelection->GetFocusNode());
|
||||
if (content && nsContentUtils::ContentIsDescendantOf(content,
|
||||
aBlockFrame->GetContent())) {
|
||||
return false;
|
||||
|
@ -449,29 +449,12 @@ nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree(nsIFrame* aFrame,
|
||||
// Get the frame and content for the selection's anchor point!
|
||||
//
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode> anchorNode;
|
||||
int32_t anchorOffset = 0;
|
||||
|
||||
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
|
||||
if (!mDomSelections[index])
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
result = mDomSelections[index]->GetAnchorNode(getter_AddRefs(anchorNode));
|
||||
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
if (!anchorNode)
|
||||
return NS_OK;
|
||||
|
||||
result = mDomSelections[index]->GetAnchorOffset(&anchorOffset);
|
||||
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIContent> anchorContent = do_QueryInterface(anchorNode);
|
||||
|
||||
nsCOMPtr<nsIContent> anchorContent =
|
||||
do_QueryInterface(mDomSelections[index]->GetAnchorNode());
|
||||
if (!anchorContent)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -25,11 +25,11 @@
|
||||
#include "nsCaret.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsQuickSort.h"
|
||||
#include "SVGObserverUtils.h"
|
||||
#include "nsSVGOuterSVGFrame.h"
|
||||
#include "nsSVGPaintServerFrame.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "mozilla/dom/SVGRect.h"
|
||||
#include "mozilla/dom/SVGTextContentElementBinding.h"
|
||||
#include "nsSVGIntegrationUtils.h"
|
||||
@ -3521,14 +3521,12 @@ SVGTextFrame::NotifySVGChanged(uint32_t aFlags)
|
||||
static int32_t
|
||||
GetCaretOffset(nsCaret* aCaret)
|
||||
{
|
||||
nsCOMPtr<nsISelection> selection = aCaret->GetSelection();
|
||||
RefPtr<Selection> selection = aCaret->GetSelection();
|
||||
if (!selection) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t offset = -1;
|
||||
selection->GetAnchorOffset(&offset);
|
||||
return offset;
|
||||
return selection->AnchorOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,8 +337,8 @@ nsBaseDragService::InvokeDragSessionWithSelection(Selection* aSelection,
|
||||
// just get the focused node from the selection
|
||||
// XXXndeakin this should actually be the deepest node that contains both
|
||||
// endpoints of the selection
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
aSelection->GetFocusNode(getter_AddRefs(node));
|
||||
nsCOMPtr<nsIDOMNode> node = aSelection->GetFocusNode() ?
|
||||
aSelection->GetFocusNode()->AsDOMNode() : nullptr;
|
||||
|
||||
nsresult rv = InvokeDragSession(node, aPrincipalURISpec,
|
||||
aTransferableArray,
|
||||
|
Loading…
x
Reference in New Issue
Block a user