Backed out changeset aa61db1f8f83 (bug 1191356)

This commit is contained in:
Sebastian Hengst 2016-05-01 16:27:29 +02:00
Родитель 0526cdbd22
Коммит ce0ea5ad03
3 изменённых файлов: 69 добавлений и 51 удалений

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

@ -83,14 +83,17 @@ nsHTMLEditor::AbsolutePositionSelection(bool aEnabled)
NS_IMETHODIMP
nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
{
nsCOMPtr<nsIDOMElement> element;
nsresult res = GetSelectionContainer(getter_AddRefs(element));
NS_ENSURE_SUCCESS(res, res);
nsAutoString positionStr;
nsCOMPtr<nsINode> node = GetSelectionContainer();
nsCOMPtr<nsINode> node = do_QueryInterface(element);
nsCOMPtr<nsIDOMNode> resultNode;
while (!resultNode && node && !node->IsHTMLElement(nsGkAtoms::html)) {
nsresult res =
mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
NS_ENSURE_SUCCESS(res, res);
if (positionStr.EqualsLiteral("absolute"))
resultNode = GetAsDOMNode(node);
@ -99,8 +102,9 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
}
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(resultNode);
element.forget(_retval);
element = do_QueryInterface(resultNode );
*_retval = element;
NS_IF_ADDREF(*_retval);
return NS_OK;
}

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

@ -4807,74 +4807,89 @@ nsHTMLEditor::EndUpdateViewBatch()
}
NS_IMETHODIMP
nsHTMLEditor::GetSelectionContainer(nsIDOMElement** aReturn)
nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn)
{
nsCOMPtr<nsIDOMElement> container =
static_cast<nsIDOMElement*>(GetAsDOMNode(GetSelectionContainer()));
NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
container.forget(aReturn);
return NS_OK;
}
RefPtr<Selection> selection = GetSelection();
// if we don't get the selection, just skip this
if (!selection) {
return NS_ERROR_FAILURE;
}
Element*
nsHTMLEditor::GetSelectionContainer()
{
// If we don't get the selection, just skip this
NS_ENSURE_TRUE(GetSelection(), nullptr);
OwningNonNull<Selection> selection = *GetSelection();
nsCOMPtr<nsINode> focusNode;
nsCOMPtr<nsIDOMNode> focusNode;
nsresult res;
if (selection->Collapsed()) {
focusNode = selection->GetFocusNode();
res = selection->GetFocusNode(getter_AddRefs(focusNode));
NS_ENSURE_SUCCESS(res, res);
} else {
int32_t rangeCount = selection->RangeCount();
int32_t rangeCount;
res = selection->GetRangeCount(&rangeCount);
NS_ENSURE_SUCCESS(res, res);
if (rangeCount == 1) {
RefPtr<nsRange> range = selection->GetRangeAt(0);
NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> startContainer = range->GetStartParent();
int32_t startOffset = range->StartOffset();
nsCOMPtr<nsINode> endContainer = range->GetEndParent();
int32_t endOffset = range->EndOffset();
nsCOMPtr<nsIDOMNode> startContainer, endContainer;
res = range->GetStartContainer(getter_AddRefs(startContainer));
NS_ENSURE_SUCCESS(res, res);
res = range->GetEndContainer(getter_AddRefs(endContainer));
NS_ENSURE_SUCCESS(res, res);
int32_t startOffset, endOffset;
res = range->GetStartOffset(&startOffset);
NS_ENSURE_SUCCESS(res, res);
res = range->GetEndOffset(&endOffset);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMElement> focusElement;
if (startContainer == endContainer && startOffset + 1 == endOffset) {
nsCOMPtr<nsIDOMElement> focusElement;
nsresult res = GetSelectedElement(EmptyString(),
getter_AddRefs(focusElement));
NS_ENSURE_SUCCESS(res, nullptr);
if (focusElement) {
res = GetSelectedElement(EmptyString(), getter_AddRefs(focusElement));
NS_ENSURE_SUCCESS(res, res);
if (focusElement)
focusNode = do_QueryInterface(focusElement);
}
}
if (!focusNode) {
focusNode = range->GetCommonAncestor();
res = range->GetCommonAncestorContainer(getter_AddRefs(focusNode));
NS_ENSURE_SUCCESS(res, res);
}
} else {
for (int32_t i = 0; i < rangeCount; i++) {
RefPtr<nsRange> range = selection->GetRangeAt(i);
nsCOMPtr<nsINode> startContainer = range->GetStartParent();
if (!focusNode) {
}
else {
int32_t i;
RefPtr<nsRange> range;
for (i = 0; i < rangeCount; i++)
{
range = selection->GetRangeAt(i);
NS_ENSURE_STATE(range);
nsCOMPtr<nsIDOMNode> startContainer;
res = range->GetStartContainer(getter_AddRefs(startContainer));
if (NS_FAILED(res)) continue;
if (!focusNode)
focusNode = startContainer;
} else if (focusNode != startContainer) {
focusNode = startContainer->GetParentNode();
else if (focusNode != startContainer) {
res = startContainer->GetParentNode(getter_AddRefs(focusNode));
NS_ENSURE_SUCCESS(res, res);
break;
}
}
}
}
if (focusNode && focusNode->GetAsText()) {
focusNode = focusNode->GetParentNode();
if (focusNode) {
uint16_t nodeType;
focusNode->GetNodeType(&nodeType);
if (nsIDOMNode::TEXT_NODE == nodeType) {
nsCOMPtr<nsIDOMNode> parent;
res = focusNode->GetParentNode(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(res, res);
focusNode = parent;
}
}
if (focusNode && focusNode->IsElement()) {
return focusNode->AsElement();
}
return nullptr;
nsCOMPtr<nsIDOMElement> focusElement = do_QueryInterface(focusNode);
focusElement.forget(aReturn);
return NS_OK;
}
NS_IMETHODIMP

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

@ -101,7 +101,6 @@ public:
nsHTMLEditor();
bool GetReturnInParagraphCreatesNewParagraph();
Element* GetSelectionContainer();
/* ------------ nsPlaintextEditor overrides -------------- */
NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable) override;