mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
The inclusions were removed with the following very crude script and the
resulting breakage was fixed up by hand. The manual fixups did either
revert the changes done by the script, replace a generic header with a more
specific one or replace a header with a forward declaration.
find . -name "*.idl" | grep -v web-platform | grep -v third_party | while read path; do
interfaces=$(grep "^\(class\|interface\).*:.*" "$path" | cut -d' ' -f2)
if [ -n "$interfaces" ]; then
if [[ "$interfaces" == *$'\n'* ]]; then
regexp="\("
for i in $interfaces; do regexp="$regexp$i\|"; done
regexp="${regexp%%\\\|}\)"
else
regexp="$interfaces"
fi
interface=$(basename "$path")
rg -l "#include.*${interface%%.idl}.h" . | while read path2; do
hits=$(grep -v "#include.*${interface%%.idl}.h" "$path2" | grep -c "$regexp" )
if [ $hits -eq 0 ]; then
echo "Removing ${interface} from ${path2}"
grep -v "#include.*${interface%%.idl}.h" "$path2" > "$path2".tmp
mv -f "$path2".tmp "$path2"
fi
done
fi
done
Differential Revision: https://phabricator.services.mozilla.com/D55443
210 lines
6.5 KiB
C++
210 lines
6.5 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/EditorUtils.h"
|
|
|
|
#include "mozilla/ContentIterator.h"
|
|
#include "mozilla/EditorDOMPoint.h"
|
|
#include "mozilla/OwningNonNull.h"
|
|
#include "mozilla/TextEditor.h"
|
|
#include "mozilla/dom/Selection.h"
|
|
#include "mozilla/dom/Text.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "nsError.h"
|
|
#include "nsIContent.h"
|
|
#include "mozilla/dom/Document.h"
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
#include "nsINode.h"
|
|
|
|
class nsISupports;
|
|
class nsRange;
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace dom;
|
|
|
|
/******************************************************************************
|
|
* mozilla::EditActionResult
|
|
*****************************************************************************/
|
|
|
|
EditActionResult& EditActionResult::operator|=(
|
|
const MoveNodeResult& aMoveNodeResult) {
|
|
mHandled |= aMoveNodeResult.Handled();
|
|
// When both result are same, keep the result.
|
|
if (mRv == aMoveNodeResult.Rv()) {
|
|
return *this;
|
|
}
|
|
// If one of the result is NS_ERROR_EDITOR_DESTROYED, use it since it's
|
|
// the most important error code for editor.
|
|
if (EditorDestroyed() || aMoveNodeResult.EditorDestroyed()) {
|
|
mRv = NS_ERROR_EDITOR_DESTROYED;
|
|
return *this;
|
|
}
|
|
// If aMoveNodeResult hasn't been set explicit nsresult value, keep current
|
|
// result.
|
|
if (aMoveNodeResult.Rv() == NS_ERROR_NOT_INITIALIZED) {
|
|
return *this;
|
|
}
|
|
// If one of the results is error, use NS_ERROR_FAILURE.
|
|
if (Failed() || aMoveNodeResult.Failed()) {
|
|
mRv = NS_ERROR_FAILURE;
|
|
return *this;
|
|
}
|
|
// Otherwise, use generic success code, NS_OK.
|
|
mRv = NS_OK;
|
|
return *this;
|
|
}
|
|
|
|
/******************************************************************************
|
|
* some helper classes for iterating the dom tree
|
|
*****************************************************************************/
|
|
|
|
DOMIterator::DOMIterator(nsINode& aNode MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
|
: mIter(&mPostOrderIter) {
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
DebugOnly<nsresult> rv = mIter->Init(&aNode);
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
}
|
|
|
|
nsresult DOMIterator::Init(nsRange& aRange) { return mIter->Init(&aRange); }
|
|
|
|
nsresult DOMIterator::Init(const RawRangeBoundary& aStartRef,
|
|
const RawRangeBoundary& aEndRef) {
|
|
return mIter->Init(aStartRef, aEndRef);
|
|
}
|
|
|
|
DOMIterator::DOMIterator(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
|
|
: mIter(&mPostOrderIter) {
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
}
|
|
|
|
void DOMIterator::AppendList(
|
|
const BoolDomIterFunctor& functor,
|
|
nsTArray<OwningNonNull<nsINode>>& arrayOfNodes) const {
|
|
// Iterate through dom and build list
|
|
for (; !mIter->IsDone(); mIter->Next()) {
|
|
nsCOMPtr<nsINode> node = mIter->GetCurrentNode();
|
|
|
|
if (functor(node)) {
|
|
arrayOfNodes.AppendElement(*node);
|
|
}
|
|
}
|
|
}
|
|
|
|
DOMSubtreeIterator::DOMSubtreeIterator(
|
|
MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
|
|
: DOMIterator(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) {
|
|
mIter = &mSubtreeIter;
|
|
}
|
|
|
|
nsresult DOMSubtreeIterator::Init(nsRange& aRange) {
|
|
return mIter->Init(&aRange);
|
|
}
|
|
|
|
/******************************************************************************
|
|
* some general purpose editor utils
|
|
*****************************************************************************/
|
|
|
|
bool EditorUtils::IsDescendantOf(const nsINode& aNode, const nsINode& aParent,
|
|
EditorRawDOMPoint* aOutPoint /* = nullptr */) {
|
|
if (aOutPoint) {
|
|
aOutPoint->Clear();
|
|
}
|
|
|
|
if (&aNode == &aParent) {
|
|
return false;
|
|
}
|
|
|
|
for (const nsINode* node = &aNode; node; node = node->GetParentNode()) {
|
|
if (node->GetParentNode() == &aParent) {
|
|
if (aOutPoint) {
|
|
MOZ_ASSERT(node->IsContent());
|
|
aOutPoint->Set(node->AsContent());
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool EditorUtils::IsDescendantOf(const nsINode& aNode, const nsINode& aParent,
|
|
EditorDOMPoint* aOutPoint) {
|
|
MOZ_ASSERT(aOutPoint);
|
|
aOutPoint->Clear();
|
|
if (&aNode == &aParent) {
|
|
return false;
|
|
}
|
|
|
|
for (const nsINode* node = &aNode; node; node = node->GetParentNode()) {
|
|
if (node->GetParentNode() == &aParent) {
|
|
MOZ_ASSERT(node->IsContent());
|
|
aOutPoint->Set(node->AsContent());
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// static
|
|
void EditorUtils::MaskString(nsString& aString, Text* aText,
|
|
uint32_t aStartOffsetInString,
|
|
uint32_t aStartOffsetInText) {
|
|
MOZ_ASSERT(aText->HasFlag(NS_MAYBE_MASKED));
|
|
MOZ_ASSERT(aStartOffsetInString == 0 || aStartOffsetInText == 0);
|
|
|
|
uint32_t unmaskStart = UINT32_MAX, unmaskLength = 0;
|
|
TextEditor* textEditor =
|
|
nsContentUtils::GetTextEditorFromAnonymousNodeWithoutCreation(aText);
|
|
if (textEditor && textEditor->UnmaskedLength() > 0) {
|
|
unmaskStart = textEditor->UnmaskedStart();
|
|
unmaskLength = textEditor->UnmaskedLength();
|
|
// If text is copied from after unmasked range, we can treat this case
|
|
// as mask all.
|
|
if (aStartOffsetInText >= unmaskStart + unmaskLength) {
|
|
unmaskLength = 0;
|
|
unmaskStart = UINT32_MAX;
|
|
} else {
|
|
// If text is copied from middle of unmasked range, reduce the length
|
|
// and adjust start offset.
|
|
if (aStartOffsetInText > unmaskStart) {
|
|
unmaskLength = unmaskStart + unmaskLength - aStartOffsetInText;
|
|
unmaskStart = 0;
|
|
}
|
|
// If text is copied from before start of unmasked range, just adjust
|
|
// the start offset.
|
|
else {
|
|
unmaskStart -= aStartOffsetInText;
|
|
}
|
|
// Make the range is in the string.
|
|
unmaskStart += aStartOffsetInString;
|
|
}
|
|
}
|
|
|
|
const char16_t kPasswordMask = TextEditor::PasswordMask();
|
|
for (uint32_t i = aStartOffsetInString; i < aString.Length(); ++i) {
|
|
bool isSurrogatePair = NS_IS_HIGH_SURROGATE(aString.CharAt(i)) &&
|
|
i < aString.Length() - 1 &&
|
|
NS_IS_LOW_SURROGATE(aString.CharAt(i + 1));
|
|
if (i < unmaskStart || i >= unmaskStart + unmaskLength) {
|
|
if (isSurrogatePair) {
|
|
aString.SetCharAt(kPasswordMask, i);
|
|
aString.SetCharAt(kPasswordMask, i + 1);
|
|
} else {
|
|
aString.SetCharAt(kPasswordMask, i);
|
|
}
|
|
}
|
|
|
|
// Skip the following low surrogate.
|
|
if (isSurrogatePair) {
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace mozilla
|