Bug 1386411 - Part 7: Inline EditorBase::GetSelection(); r=masayuki

This commit is contained in:
Ehsan Akhgari 2017-08-01 19:51:25 -04:00
Родитель dd8fbce0c9
Коммит cf4e6a817c
6 изменённых файлов: 24 добавлений и 31 удалений

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

@ -20,6 +20,8 @@ interface nsIDOMNode;
interface nsISelection;
interface nsISelectionDisplay;
[ptr] native SelectionPtr(mozilla::dom::Selection);
[scriptable, uuid(3801c9d4-8e69-4bfc-9edb-b58278621f8f)]
interface nsISelectionController : nsISelectionDisplay
{
@ -69,6 +71,11 @@ interface nsISelectionController : nsISelectionDisplay
*/
nsISelection getSelection(in short type);
/**
* Return the selection object corresponding to a selection type.
*/
[noscript,nostdcall,notxpcom] SelectionPtr getDOMSelection(in short aType);
const short SCROLL_SYNCHRONOUS = 1<<1;
const short SCROLL_FIRST_ANCESTOR_ONLY = 1<<2;
const short SCROLL_CENTER_VERTICALLY = 1<<4;
@ -278,13 +285,6 @@ interface nsISelectionController : nsISelectionDisplay
*/
boolean checkVisibility(in nsIDOMNode node, in short startOffset, in short endOffset);
[noscript,nostdcall] boolean checkVisibilityContent(in nsIContent node, in short startOffset, in short endOffset);
%{C++
/**
* Return the selection object corresponding to a selection type.
*/
NS_IMETHOD_(mozilla::dom::Selection*) GetSelection(int16_t aType) = 0;
%}
};
%{ C++
#define NS_ISELECTIONCONTROLLER_CID \

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

@ -296,7 +296,7 @@ public:
NS_IMETHOD GetSelectionFlags(int16_t *aOutEnable) override;
NS_IMETHOD GetSelection(RawSelectionType aRawSelectionType,
nsISelection** aSelection) override;
NS_IMETHODIMP_(Selection*) GetSelection(RawSelectionType aRawSelectionType) override;
Selection* GetDOMSelection(RawSelectionType aRawSelectionType) override;
NS_IMETHOD ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
int16_t aRegion, int16_t aFlags) override;
NS_IMETHOD RepaintSelection(RawSelectionType aRawSelectionType) override;
@ -433,8 +433,8 @@ nsTextInputSelectionImpl::GetSelection(RawSelectionType aRawSelectionType,
return NS_OK;
}
NS_IMETHODIMP_(Selection*)
nsTextInputSelectionImpl::GetSelection(RawSelectionType aRawSelectionType)
Selection*
nsTextInputSelectionImpl::GetDOMSelection(RawSelectionType aRawSelectionType)
{
return GetSelection(ToSelectionType(aRawSelectionType));
}

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

@ -663,18 +663,6 @@ EditorBase::GetSelection(SelectionType aSelectionType,
return selcon->GetSelection(ToRawSelectionType(aSelectionType), aSelection);
}
Selection*
EditorBase::GetSelection(SelectionType aSelectionType)
{
nsCOMPtr<nsISelection> sel;
nsresult rv = GetSelection(aSelectionType, getter_AddRefs(sel));
if (NS_WARN_IF(NS_FAILED(rv)) || NS_WARN_IF(!sel)) {
return nullptr;
}
return sel->AsSelection();
}
NS_IMETHODIMP
EditorBase::DoTransaction(nsITransaction* aTxn)
{

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

@ -13,6 +13,7 @@
#include "mozilla/SelectionState.h" // for RangeUpdater, etc.
#include "mozilla/StyleSheet.h" // for StyleSheet
#include "mozilla/WeakPtr.h" // for WeakPtr
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Text.h"
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsCycleCollectionParticipant.h"
@ -129,7 +130,6 @@ namespace dom {
class DataTransfer;
class Element;
class EventTarget;
class Selection;
class Text;
} // namespace dom
@ -834,7 +834,15 @@ public:
static void DumpNode(nsIDOMNode* aNode, int32_t indent = 0);
#endif
Selection* GetSelection(SelectionType aSelectionType =
SelectionType::eNormal);
SelectionType::eNormal)
{
nsISelectionController* sc = GetSelectionController();
if (!sc) {
return nullptr;
}
Selection* selection = sc->GetDOMSelection(ToRawSelectionType(aSelectionType));
return selection;
}
/**
* Helpers to add a node to the selection.

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

@ -1601,18 +1601,15 @@ PresShell::GetSelection(RawSelectionType aRawSelectionType,
return NS_OK;
}
NS_IMETHODIMP_(Selection*)
PresShell::GetSelection(RawSelectionType aRawSelectionType)
Selection*
PresShell::GetDOMSelection(RawSelectionType aRawSelectionType)
{
if (!mSelection) {
return nullptr;
}
RefPtr<nsFrameSelection> frameSelection = mSelection;
nsISelection* selection =
frameSelection->GetSelection(ToSelectionType(aRawSelectionType));
return static_cast<Selection*>(selection);
return frameSelection->GetSelection(ToSelectionType(aRawSelectionType));
}
Selection*

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

@ -106,7 +106,7 @@ public:
NS_IMETHOD GetSelection(RawSelectionType aRawSelectionType,
nsISelection** aSelection) override;
NS_IMETHODIMP_(dom::Selection*) GetSelection(RawSelectionType aRawSelectionType) override;
dom::Selection* GetDOMSelection(RawSelectionType aRawSelectionType) override;
virtual mozilla::dom::Selection*
GetCurrentSelection(SelectionType aSelectionType) override;
virtual already_AddRefed<nsISelectionController>