/* -*- 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"ChangeStyleTransaction.h"
#include"HTMLEditUtils.h" #include"mozilla/Logging.h" #include"mozilla/ToString.h" #include"mozilla/dom/Element.h"// for Element #include"nsAString.h"// for nsAString::Append, etc. #include"nsCRT.h"// for nsCRT::IsAsciiSpace #include"nsDebug.h"// for NS_WARNING, etc. #include"nsError.h"// for NS_ERROR_NULL_POINTER, etc. #include"nsGkAtoms.h"// for nsGkAtoms, etc. #include"nsICSSDeclaration.h"// for nsICSSDeclaration. #include"nsLiteralString.h"// for NS_LITERAL_STRING, etc. #include"nsReadableUtils.h"// for ToNewUnicode #include"nsString.h"// for nsAutoString, nsString, etc. #include"nsStyledElement.h"// for nsStyledElement. #include"nsUnicharUtils.h"// for nsCaseInsensitiveStringComparator
// Answers true if aValue is in the string list of white-space separated values // aValueList. bool ChangeStyleTransaction::ValueIncludes(const nsACString& aValueList, const nsACString& aValue) {
nsAutoCString valueList(aValueList); bool result = false;
// put an extra null at the end
valueList.Append(kNullCh);
char* start = valueList.BeginWriting(); char* end = start;
while (kNullCh != *start) { while (kNullCh != *start && nsCRT::IsAsciiSpace(*start)) { // skip leading space
start++;
}
end = start;
while (kNullCh != *end && !nsCRT::IsAsciiSpace(*end)) { // look for space or end
end++;
} // end string here
*end = kNullCh;
if (start < end) { if (aValue.Equals(nsDependentCString(start),
nsCaseInsensitiveCStringComparator)) {
result = true; break;
}
}
start = ++end;
} return result;
}
// FIXME(bug 1606994): Using atoms forces a string copy here which is not // great.
nsAutoCString propertyNameString;
mProperty->ToUTF8String(propertyNameString);
ErrorResult error; if (aValue.IsEmpty()) { // An empty value means we have to remove the property
nsAutoCString returnString;
cssDecl->RemoveProperty(propertyNameString, returnString, error); if (MOZ_UNLIKELY(error.Failed())) {
NS_WARNING("nsICSSDeclaration::RemoveProperty() failed"); return error.StealNSResult();
}
} // Let's recreate the declaration as it was
nsAutoCString priority;
cssDecl->GetPropertyPriority(propertyNameString, priority);
cssDecl->SetProperty(propertyNameString, aValue, priority, error);
NS_WARNING_ASSERTION(!error.Failed(), "nsICSSDeclaration::SetProperty() failed"); return error.StealNSResult();
}
void ChangeStyleTransaction::BuildTextDecorationValue(bool aUnderline, bool aOverline, bool aLineThrough,
nsACString& aOutValues) { // We should build text-decoration(-line) value as same as Blink for // compatibility. Blink sets text-decoration-line to the values in the // following order. Blink drops `blink` and other styles like color and // style. For keeping the code simple, let's use the lossy behavior.
aOutValues.Truncate(); if (aUnderline) {
aOutValues.AssignLiteral("underline");
} if (aOverline) { if (!aOutValues.IsEmpty()) {
aOutValues.Append(HTMLEditUtils::kSpace);
}
aOutValues.AppendLiteral("overline");
} if (aLineThrough) { if (!aOutValues.IsEmpty()) {
aOutValues.Append(HTMLEditUtils::kSpace);
}
aOutValues.AppendLiteral("line-through");
}
}
} // namespace mozilla
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.