本文整理汇总了C++中NS_NAMED_LITERAL_STRING函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_NAMED_LITERAL_STRING函数的具体用法?C++ NS_NAMED_LITERAL_STRING怎么用?C++ NS_NAMED_LITERAL_STRING使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_NAMED_LITERAL_STRING函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: NS_NAMED_LITERAL_STRING
void
nsPageFrame::ProcessSpecialCodes(const nsString& aStr, nsString& aNewStr)
{
aNewStr = aStr;
// Search to see if the &D code is in the string
// then subst in the current date/time
NS_NAMED_LITERAL_STRING(kDate, "&D");
if (aStr.Find(kDate) != kNotFound) {
if (mPD->mDateTimeStr != nsnull) {
aNewStr.ReplaceSubstring(kDate.get(), mPD->mDateTimeStr);
} else {
aNewStr.ReplaceSubstring(kDate.get(), EmptyString().get());
}
}
// NOTE: Must search for &PT before searching for &P
//
// Search to see if the "page number and page" total code are in the string
// and replace the page number and page total code with the actual
// values
NS_NAMED_LITERAL_STRING(kPageAndTotal, "&PT");
if (aStr.Find(kPageAndTotal) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumAndTotalsFormat, mPageNum, mTotNumPages);
aNewStr.ReplaceSubstring(kPageAndTotal.get(), uStr);
nsMemory::Free(uStr);
}
// Search to see if the page number code is in the string
// and replace the page number code with the actual value
NS_NAMED_LITERAL_STRING(kPage, "&P");
if (aStr.Find(kPage) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mPageNum);
aNewStr.ReplaceSubstring(kPage.get(), uStr);
nsMemory::Free(uStr);
}
NS_NAMED_LITERAL_STRING(kTitle, "&T");
if (aStr.Find(kTitle) != kNotFound) {
if (mPD->mDocTitle != nsnull) {
aNewStr.ReplaceSubstring(kTitle.get(), mPD->mDocTitle);
} else {
aNewStr.ReplaceSubstring(kTitle.get(), EmptyString().get());
}
}
NS_NAMED_LITERAL_STRING(kDocURL, "&U");
if (aStr.Find(kDocURL) != kNotFound) {
if (mPD->mDocURL != nsnull) {
aNewStr.ReplaceSubstring(kDocURL.get(), mPD->mDocURL);
} else {
aNewStr.ReplaceSubstring(kDocURL.get(), EmptyString().get());
}
}
NS_NAMED_LITERAL_STRING(kPageTotal, "&L");
if (aStr.Find(kPageTotal) != kNotFound) {
PRUnichar * uStr = nsTextFormatter::smprintf(mPD->mPageNumFormat, mTotNumPages);
aNewStr.ReplaceSubstring(kPageTotal.get(), uStr);
nsMemory::Free(uStr);
}
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:63,代码来源:nsPageFrame.cpp
示例2: GetFileName
void
MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
const char* const* aFormatNames,
int32_t aWidth, int32_t aHeight,
const nsAString& aStatus)
{
nsXPIDLString fileStr;
GetFileName(fileStr);
NS_ConvertASCIItoUTF16 typeStr(aTypeStr);
nsXPIDLString title;
if (mStringBundle) {
// if we got a valid size (not all media have a size)
if (aWidth != 0 && aHeight != 0) {
nsAutoString widthStr;
nsAutoString heightStr;
widthStr.AppendInt(aWidth);
heightStr.AppendInt(aHeight);
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const char16_t *formatStrings[4] = {fileStr.get(), typeStr.get(),
widthStr.get(), heightStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDimAndFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
getter_Copies(title));
}
else {
const char16_t *formatStrings[3] = {typeStr.get(), widthStr.get(),
heightStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithDim]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
getter_Copies(title));
}
}
else {
// If we got a filename, display it
if (!fileStr.IsEmpty()) {
const char16_t *formatStrings[2] = {fileStr.get(), typeStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithFile]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
getter_Copies(title));
}
else {
const char16_t *formatStrings[1] = {typeStr.get()};
NS_ConvertASCIItoUTF16 fmtName(aFormatNames[eWithNoInfo]);
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
getter_Copies(title));
}
}
}
// set it on the document
if (aStatus.IsEmpty()) {
SetTitle(title);
}
else {
nsXPIDLString titleWithStatus;
const nsPromiseFlatString& status = PromiseFlatString(aStatus);
const char16_t *formatStrings[2] = {title.get(), status.get()};
NS_NAMED_LITERAL_STRING(fmtName, "TitleWithStatus");
mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
getter_Copies(titleWithStatus));
SetTitle(titleWithStatus);
}
}
开发者ID:ConradIrwin,项目名称:gecko-dev,代码行数:66,代码来源:MediaDocument.cpp
示例3: MakeScopeExit
Maybe<bool>
Compatibility::OnUIAMessage(WPARAM aWParam, LPARAM aLParam)
{
auto clearUiaRemotePid = MakeScopeExit([]() {
sUiaRemotePid = Nothing();
});
Telemetry::AutoTimer<Telemetry::A11Y_UIA_DETECTION_TIMING_MS> timer;
// UIA creates a section containing the substring "HOOK_SHMEM_"
NS_NAMED_LITERAL_STRING(kStrHookShmem, "HOOK_SHMEM_");
// The section name always ends with this suffix, which is derived from the
// current thread id and the UIA message's WPARAM and LPARAM.
nsAutoString partialSectionSuffix;
partialSectionSuffix.AppendPrintf("_%08x_%08x_%08x", ::GetCurrentThreadId(),
static_cast<DWORD>(aLParam), aWParam);
// Find any named Section that matches the naming convention of the UIA shared
// memory.
nsAutoHandle section;
auto comparator = [&](const nsDependentSubstring& aName,
const nsDependentSubstring& aType) -> bool {
if (aType.Equals(NS_LITERAL_STRING("Section")) &&
FindInReadable(kStrHookShmem, aName) &&
StringEndsWith(aName, partialSectionSuffix)) {
section.own(::OpenFileMapping(GENERIC_READ, FALSE,
PromiseFlatString(aName).get()));
return false;
}
return true;
};
if (!FindNamedObject(comparator) || !section) {
return Nothing();
}
NTSTATUS ntStatus;
// First we must query for a list of all the open handles in the system.
UniquePtr<char[]> handleInfoBuf;
ULONG handleInfoBufLen = sizeof(SYSTEM_HANDLE_INFORMATION_EX) +
1024 * sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX);
// We must query for handle information in a loop, since we are effectively
// asking the kernel to take a snapshot of all the handles on the system;
// the size of the required buffer may fluctuate between successive calls.
while (true) {
// These allocations can be hundreds of megabytes on some computers, so
// we should use fallible new here.
handleInfoBuf = MakeUniqueFallible<char[]>(handleInfoBufLen);
if (!handleInfoBuf) {
return Nothing();
}
ntStatus = ::NtQuerySystemInformation(
(SYSTEM_INFORMATION_CLASS) SystemExtendedHandleInformation,
handleInfoBuf.get(), handleInfoBufLen, &handleInfoBufLen);
if (ntStatus == STATUS_INFO_LENGTH_MISMATCH) {
continue;
}
if (!NT_SUCCESS(ntStatus)) {
return Nothing();
}
break;
}
const DWORD ourPid = ::GetCurrentProcessId();
Maybe<PVOID> kernelObject;
static Maybe<USHORT> sectionObjTypeIndex;
nsTHashtable<nsUint32HashKey> nonSectionObjTypes;
nsDataHashtable<nsVoidPtrHashKey, DWORD> objMap;
auto handleInfo = reinterpret_cast<SYSTEM_HANDLE_INFORMATION_EX*>(handleInfoBuf.get());
for (ULONG index = 0; index < handleInfo->mHandleCount; ++index) {
SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX& curHandle = handleInfo->mHandles[index];
HANDLE handle = reinterpret_cast<HANDLE>(curHandle.mHandle);
// The mapping of the curHandle.mObjectTypeIndex field depends on the
// underlying OS kernel. As we scan through the handle list, we record the
// type indices such that we may use those values to skip over handles that
// refer to non-section objects.
if (sectionObjTypeIndex) {
// If we know the type index for Sections, that's the fastest check...
if (sectionObjTypeIndex.value() != curHandle.mObjectTypeIndex) {
// Not a section
continue;
}
} else if (nonSectionObjTypes.Contains(static_cast<uint32_t>(
curHandle.mObjectTypeIndex))) {
// Otherwise we check whether or not the object type is definitely _not_
// a Section...
continue;
} else if (ourPid == curHandle.mPid) {
// Otherwise we need to issue some system calls to find out the object
//.........这里部分代码省略.........
开发者ID:nils-ohlmeier,项目名称:gecko-dev,代码行数:101,代码来源:CompatibilityUIA.cpp
示例4: NS_ASSERTION
nsresult nsCollationUnix::Initialize(nsILocale* locale)
{
#define kPlatformLocaleLength 64
NS_ASSERTION(mCollation == NULL, "Should only be initialized once");
nsresult res;
mCollation = new nsCollation;
if (mCollation == NULL) {
NS_ASSERTION(0, "mCollation creation failed");
return NS_ERROR_OUT_OF_MEMORY;
}
// default platform locale
mLocale.Assign('C');
nsAutoString localeStr;
NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_COLLATE##PLATFORM");
// get locale string, use app default if no locale specified
if (locale == nsnull) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsCOMPtr<nsILocale> appLocale;
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_SUCCEEDED(res)) {
res = appLocale->GetCategory(aCategory, localeStr);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info");
}
}
}
else {
res = locale->GetCategory(aCategory, localeStr);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info");
}
// Get platform locale and charset name from locale, if available
if (NS_SUCCEEDED(res)) {
// keep the same behavior as 4.x as well as avoiding Linux collation key problem
if (localeStr.LowerCaseEqualsLiteral("en_us")) { // note: locale is in platform format
localeStr.AssignLiteral("C");
}
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = posixLocale->GetPlatformLocale(localeStr, mLocale);
}
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsCAutoString mappedCharset;
res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
if (NS_SUCCEEDED(res)) {
mCollation->SetCharset(mappedCharset.get());
}
}
}
return NS_OK;
}
开发者ID:EdgarChen,项目名称:mozilla-cvs-history,代码行数:61,代码来源:nsCollationUnix.cpp
示例5: test_comparisons
static bool test_comparisons()
{
bool result;
// nsString
NS_NAMED_LITERAL_STRING(shortString1, "Foo");
NS_NAMED_LITERAL_STRING(shortString2, "Bar");
NS_NAMED_LITERAL_STRING(shortString3, "Bar");
NS_NAMED_LITERAL_STRING(shortString4, "bar");
NS_NAMED_LITERAL_STRING(longString, "FooBar");
// ==
result = (shortString1 == shortString2);
if (result)
return false;
result = (shortString2 == shortString3);
if (!result)
return false;
result = (shortString3 == shortString4);
if (result)
return false;
result = (shortString1 == longString);
if (result)
return false;
result = (longString == shortString1);
if (result)
return false;
// !=
result = (shortString1 != shortString2);
if (!result)
return false;
result = (shortString2 != shortString3);
if (result)
return false;
result = (shortString3 != shortString4);
if (!result)
return false;
result = (shortString1 != longString);
if (!result)
return false;
result = (longString != shortString1);
if (!result)
return false;
// <
result = (shortString1 < shortString2);
if (result)
return false;
result = (shortString2 < shortString1);
if (!result)
return false;
result = (shortString1 < longString);
if (!result)
return false;
result = (longString < shortString1);
if (result)
return false;
result = (shortString2 < shortString3);
if (result)
return false;
result = (shortString3 < shortString4);
if (!result)
return false;
result = (shortString4 < shortString3);
if (result)
return false;
// <=
result = (shortString1 <= shortString2);
if (result)
return false;
result = (shortString2 <= shortString1);
if (!result)
return false;
result = (shortString1 <= longString);
if (!result)
return false;
//.........这里部分代码省略.........
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:101,代码来源:TestMinStringAPI.cpp
示例6: NS_ABORT_IF_FALSE
//.........这里部分代码省略.........
NS_STYLE_UNICODE_BIDI_PLAINTEXT,
aResult);
}
}
else {
const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, GetIntValue());
AppendASCIItoUTF16(name, aResult);
}
}
else if (eCSSUnit_EnumColor == unit) {
// we can lookup the property in the ColorTable and then
// get a string mapping the name
nsCAutoString str;
if (nsCSSProps::GetColorName(GetIntValue(), str)){
AppendASCIItoUTF16(str, aResult);
} else {
NS_ABORT_IF_FALSE(false, "bad color value");
}
}
else if (eCSSUnit_Color == unit) {
nscolor color = GetColorValue();
if (color == NS_RGBA(0, 0, 0, 0)) {
// Use the strictest match for 'transparent' so we do correct
// round-tripping of all other rgba() values.
aResult.AppendLiteral("transparent");
} else {
PRUint8 a = NS_GET_A(color);
if (a < 255) {
aResult.AppendLiteral("rgba(");
} else {
aResult.AppendLiteral("rgb(");
}
NS_NAMED_LITERAL_STRING(comma, ", ");
aResult.AppendInt(NS_GET_R(color), 10);
aResult.Append(comma);
aResult.AppendInt(NS_GET_G(color), 10);
aResult.Append(comma);
aResult.AppendInt(NS_GET_B(color), 10);
if (a < 255) {
aResult.Append(comma);
aResult.AppendFloat(nsStyleUtil::ColorComponentToFloat(a));
}
aResult.Append(PRUnichar(')'));
}
}
else if (eCSSUnit_URL == unit || eCSSUnit_Image == unit) {
aResult.Append(NS_LITERAL_STRING("url("));
nsStyleUtil::AppendEscapedCSSString(
nsDependentString(GetOriginalURLValue()), aResult);
aResult.Append(NS_LITERAL_STRING(")"));
}
else if (eCSSUnit_Element == unit) {
aResult.Append(NS_LITERAL_STRING("-moz-element(#"));
nsAutoString tmpStr;
GetStringValue(tmpStr);
nsStyleUtil::AppendEscapedCSSIdent(tmpStr, aResult);
aResult.Append(NS_LITERAL_STRING(")"));
}
else if (eCSSUnit_Percent == unit) {
aResult.AppendFloat(GetPercentValue() * 100.0f);
}
else if (eCSSUnit_Percent < unit) { // length unit
aResult.AppendFloat(GetFloatValue());
}
开发者ID:krellian,项目名称:mozilla-central,代码行数:67,代码来源:nsCSSValue.cpp
示例7: switch
NS_INTERFACE_MAP_END
// nsIDOMCSSValue
NS_IMETHODIMP
nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText)
{
nsAutoString tmpStr;
aCssText.Truncate();
nsresult result = NS_OK;
switch (mType) {
case CSS_PX :
{
float val = nsPresContext::AppUnitsToFloatCSSPixels(mValue.mAppUnits);
tmpStr.AppendFloat(val);
tmpStr.AppendLiteral("px");
break;
}
case CSS_IDENT :
{
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(mValue.mKeyword),
tmpStr);
break;
}
case CSS_STRING :
case CSS_COUNTER : /* FIXME: COUNTER should use an object */
{
tmpStr.Append(mValue.mString);
break;
}
case CSS_URI :
{
if (mValue.mURI) {
nsCAutoString specUTF8;
mValue.mURI->GetSpec(specUTF8);
tmpStr.AssignLiteral("url(");
nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(specUTF8),
tmpStr);
tmpStr.AppendLiteral(")");
} else {
// XXXldb Any better ideas? It's good to have something that
// doesn't parse so that things round-trip "correctly".
tmpStr.Assign(NS_LITERAL_STRING("url(invalid-url:)"));
}
break;
}
case CSS_ATTR :
{
tmpStr.AppendLiteral("attr(");
tmpStr.Append(mValue.mString);
tmpStr.Append(PRUnichar(')'));
break;
}
case CSS_PERCENTAGE :
{
tmpStr.AppendFloat(mValue.mFloat * 100);
tmpStr.Append(PRUnichar('%'));
break;
}
case CSS_NUMBER :
{
tmpStr.AppendFloat(mValue.mFloat);
break;
}
case CSS_RECT :
{
NS_ASSERTION(mValue.mRect, "mValue.mRect should never be null");
NS_NAMED_LITERAL_STRING(comma, ", ");
nsCOMPtr<nsIDOMCSSPrimitiveValue> sideCSSValue;
nsAutoString sideValue;
tmpStr.AssignLiteral("rect(");
// get the top
result = mValue.mRect->GetTop(getter_AddRefs(sideCSSValue));
if (NS_FAILED(result))
break;
result = sideCSSValue->GetCssText(sideValue);
if (NS_FAILED(result))
break;
tmpStr.Append(sideValue + comma);
// get the right
result = mValue.mRect->GetRight(getter_AddRefs(sideCSSValue));
if (NS_FAILED(result))
break;
result = sideCSSValue->GetCssText(sideValue);
if (NS_FAILED(result))
break;
tmpStr.Append(sideValue + comma);
// get the bottom
result = mValue.mRect->GetBottom(getter_AddRefs(sideCSSValue));
if (NS_FAILED(result))
break;
result = sideCSSValue->GetCssText(sideValue);
if (NS_FAILED(result))
break;
tmpStr.Append(sideValue + comma);
// get the left
//.........这里部分代码省略.........
开发者ID:FunkyVerb,项目名称:devtools-window,代码行数:101,代码来源:nsROCSSPrimitiveValue.cpp
示例8: NS_ASSERTION
NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
{
NS_ASSERTION(mEditor && mElement, "bad state");
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(mElement);
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
nsresult result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(cssDecl, NS_ERROR_NULL_POINTER);
nsAutoString propertyNameString;
mProperty->ToString(propertyNameString);
NS_NAMED_LITERAL_STRING(styleAttr, "style");
result = mElement->HasAttribute(styleAttr, &mUndoAttributeWasSet);
NS_ENSURE_SUCCESS(result, result);
nsAutoString values;
result = cssDecl->GetPropertyValue(propertyNameString, values);
NS_ENSURE_SUCCESS(result, result);
mUndoValue.Assign(values);
// does this property accept more than 1 value ?
// we need to know that because of bug 62682
bool multiple = AcceptsMoreThanOneValue(mProperty);
if (mRemoveProperty) {
nsAutoString returnString;
if (multiple) {
// the property can have more than one value, let's remove only
// the value we have to remove and not the others
// the 2 lines below are a workaround because nsDOMCSSDeclaration::GetPropertyCSSValue
// is not yet implemented (bug 62682)
RemoveValueFromListOfValues(values, NS_LITERAL_STRING("none"));
RemoveValueFromListOfValues(values, mValue);
if (values.IsEmpty()) {
result = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(result, result);
}
else {
nsAutoString priority;
result = cssDecl->GetPropertyPriority(propertyNameString, priority);
NS_ENSURE_SUCCESS(result, result);
result = cssDecl->SetProperty(propertyNameString, values,
priority);
NS_ENSURE_SUCCESS(result, result);
}
}
else {
result = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(result, result);
}
}
else {
nsAutoString priority;
result = cssDecl->GetPropertyPriority(propertyNameString, priority);
NS_ENSURE_SUCCESS(result, result);
if (multiple) {
// the property can have more than one value, let's add
// the value we have to add to the others
// the line below is a workaround because nsDOMCSSDeclaration::GetPropertyCSSValue
// is not yet implemented (bug 62682)
AddValueToMultivalueProperty(values, mValue);
}
else
values.Assign(mValue);
result = cssDecl->SetProperty(propertyNameString, values,
priority);
NS_ENSURE_SUCCESS(result, result);
}
// let's be sure we don't keep an empty style attribute
PRUint32 length;
result = cssDecl->GetLength(&length);
NS_ENSURE_SUCCESS(result, result);
if (!length) {
result = mElement->RemoveAttribute(styleAttr);
NS_ENSURE_SUCCESS(result, result);
}
else
mRedoAttributeWasSet = true;
return cssDecl->GetPropertyValue(propertyNameString, mRedoValue);
}
开发者ID:PriceTseng,项目名称:mozilla-central,代码行数:89,代码来源:ChangeCSSInlineStyleTxn.cpp
示例9: GetEntryDocument
already_AddRefed<Promise>
ServiceWorkerContainer::Register(const nsAString& aScriptURL,
const RegistrationOptions& aOptions,
ErrorResult& aRv)
{
nsCOMPtr<nsISupports> promise;
nsCOMPtr<nsIServiceWorkerManager> swm = mozilla::services::GetServiceWorkerManager();
if (!swm) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIURI> baseURI;
nsIDocument* doc = GetEntryDocument();
if (doc) {
baseURI = doc->GetBaseURI();
} else {
// XXXnsm. One of our devtools browser test calls register() from a content
// script where there is no valid entry document. Use the window to resolve
// the uri in that case.
nsCOMPtr<nsPIDOMWindow> window = GetOwner();
nsCOMPtr<nsPIDOMWindow> outerWindow;
if (window && (outerWindow = window->GetOuterWindow()) &&
outerWindow->GetServiceWorkersTestingEnabled()) {
baseURI = window->GetDocBaseURI();
}
}
nsresult rv;
nsCOMPtr<nsIURI> scriptURI;
rv = NS_NewURI(getter_AddRefs(scriptURI), aScriptURL, nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(&aScriptURL);
return nullptr;
}
aRv = CheckForSlashEscapedCharsInPath(scriptURI);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// In ServiceWorkerContainer.register() the scope argument is parsed against
// different base URLs depending on whether it was passed or not.
nsCOMPtr<nsIURI> scopeURI;
// Step 4. If none passed, parse against script's URL
if (!aOptions.mScope.WasPassed()) {
NS_NAMED_LITERAL_STRING(defaultScope, "./");
rv = NS_NewURI(getter_AddRefs(scopeURI), defaultScope,
nullptr, scriptURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
nsAutoCString spec;
scriptURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 wSpec(spec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(&defaultScope, &wSpec);
return nullptr;
}
} else {
// Step 5. Parse against entry settings object's base URL.
rv = NS_NewURI(getter_AddRefs(scopeURI), aOptions.mScope.Value(),
nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
nsAutoCString spec;
baseURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 wSpec(spec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(&aOptions.mScope.Value(), &wSpec);
return nullptr;
}
aRv = CheckForSlashEscapedCharsInPath(scopeURI);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
}
// The spec says that the "client" passed to Register() must be the global
// where the ServiceWorkerContainer was retrieved from.
aRv = swm->Register(GetOwner(), scopeURI, scriptURI, getter_AddRefs(promise));
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<Promise> ret = static_cast<Promise*>(promise.get());
MOZ_ASSERT(ret);
return ret.forget();
}
开发者ID:70599,项目名称:Waterfox,代码行数:88,代码来源:ServiceWorkerContainer.cpp
示例10: NS_NAMED_LITERAL_STRING
void nsScriptPaginator::AdjustNextPageBreak () {
NS_NAMED_LITERAL_STRING(kClassStr, "class");
NS_NAMED_LITERAL_STRING(kSoftBreakStr, "softbreak");
NS_NAMED_LITERAL_STRING(kHardBreakStr, "hardbreak");
NS_NAMED_LITERAL_STRING(kActStr, "act");
NS_NAMED_LITERAL_STRING(kDivStr, "div");
// Allow an extra line per page to accommodate bottom margins
const PRInt32 kPageHeight = PRInt32(mLineHeight * (mLinesPerPage + 1));
nsCOMPtr<nsIDOMNode> node = mNextPageStartsAt;
if (! node) {
nsCOMPtr<nsIDOMHTMLDocument> hdoc(do_QueryInterface(mScript));
nsCOMPtr<nsIDOMHTMLElement> body;
hdoc->GetBody(getter_AddRefs(body));
if (! body) {
return;
}
body->GetFirstChild(getter_AddRefs(node));
mCurPageBreakNum = 0;
if (! node) {
return;
}
}
nsCOMPtr<nsIDOMNSHTMLElement> element(do_QueryInterface(node));
if (! element)
return;
PRInt32 offset = 0;
element->GetOffsetTop(&offset);
PRUint32 pageEnd = PRUint32(offset + kPageHeight);
nsCOMPtr<nsIDOMNSHTMLElement> innerBreak(nsnull);
// Adjust for height of page break if we start at one
nsString className;
{
nsCOMPtr<nsIDOMElement> elemnode(do_QueryInterface(node));
elemnode->GetAttribute(kClassStr, className);
if (className.Equals(kSoftBreakStr) || className.Equals(kHardBreakStr)) {
PRInt32 height;
element->GetClientHeight(&height);
pageEnd += height;
}
}
// Basic strategy:
// 1. Get the next node
// 2. If the next node is undefined
// 2.1. If the page break cache extends further
// 2.1.1. Splice the remaining page breaks
// 2.2. Exit
// 3. Else if the next node is a hard break (or act)
// 3.1. Advance the page cursor
// 3.2. Exit
// 4. Else if the next node is a soft break
// 4.1. If a soft break is cached as |innerBreak|
// 4.1.1. Remove |innerBreak|
// 4.2. Cache the node as |innerBreak|
// 5. Else if the node does not fit the page
// 5.1. Find the last node (inclusive) that allows a break before it
// 5.2. If a soft break is cached as |innerBreak|
// 5.2.1. If |innerBreak| occurs as the previous sibling to the last node
// 5.2.1.1. Advance the page cursor
// 5.2.1.2. Exit
// 5.2.2. Else
// 5.2.2.1. Remove |innerBreak|
// 5.2.2.2. Insert a new soft page break
// 5.2.2.3. Advance the page cursor
// 5.2.2.4. Exit
// 5.3. Else
// 5.3.1. Insert a new soft page break
// 5.3.2. Advance the page cursor
// 5.3.3. Exit
// 6. Else
// 6.1. Continue
nsCOMPtr<nsIDOMNode> tmpnode;
PRUint16 nodeType = 0;
nsCOMPtr<nsIDOMNode> elemnode(do_QueryInterface(element));
elemnode->GetNextSibling(getter_AddRefs(tmpnode));
if (tmpnode)
tmpnode->GetNodeType(&nodeType);
while (tmpnode && nodeType != nsIDOMNode::ELEMENT_NODE) {
nsCOMPtr<nsIDOMNode> tmpnode2;
tmpnode->GetNextSibling(getter_AddRefs(tmpnode2));
tmpnode = tmpnode2;
if (tmpnode)
tmpnode->GetNodeType(&nodeType);
}
if (tmpnode)
element = do_QueryInterface(tmpnode);
else
element = nsnull;
while (element) {
nsCOMPtr<nsIDOMElement> elemnode(do_QueryInterface(element));
elemnode->GetAttribute(kClassStr, className);
element->GetOffsetTop(&offset);
//.........这里部分代码省略.........
开发者ID:SecareLupus,项目名称:Drood,代码行数:101,代码来源:nsScriptPaginator.cpp
示例11: NS_ASSERTION
nsresult
PluginDocument::CreateSyntheticPluginDocument()
{
NS_ASSERTION(!GetShell() || !GetShell()->DidInitialReflow(),
"Creating synthetic plugin document content too late");
// make our generic document
nsresult rv = MediaDocument::CreateSyntheticDocument();
NS_ENSURE_SUCCESS(rv, rv);
// then attach our plugin
Element* body = GetBodyElement();
if (!body) {
NS_WARNING("no body on plugin document!");
return NS_ERROR_FAILURE;
}
// remove margins from body
NS_NAMED_LITERAL_STRING(zero, "0");
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginwidth, zero, PR_FALSE);
body->SetAttr(kNameSpaceID_None, nsGkAtoms::marginheight, zero, PR_FALSE);
// make plugin content
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::embed, nsnull,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
rv = NS_NewHTMLElement(getter_AddRefs(mPluginContent), nodeInfo.forget(),
NOT_FROM_PARSER);
NS_ENSURE_SUCCESS(rv, rv);
// make it a named element
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::name,
NS_LITERAL_STRING("plugin"), PR_FALSE);
// fill viewport and auto-resize
NS_NAMED_LITERAL_STRING(percent100, "100%");
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::width, percent100,
PR_FALSE);
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::height, percent100,
PR_FALSE);
// set URL
nsCAutoString src;
mDocumentURI->GetSpec(src);
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
NS_ConvertUTF8toUTF16(src), PR_FALSE);
// set mime type
mPluginContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_ConvertUTF8toUTF16(mMimeType), PR_FALSE);
// This will not start the load because nsObjectLoadingContent checks whether
// its document is an nsIPluginDocument
body->AppendChildTo(mPluginContent, PR_FALSE);
return NS_OK;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:62,代码来源:PluginDocument.cpp
示例12: NS_NAMED_LITERAL_STRING
// init this interface to a specified locale
nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
{
nsAutoString localeStr;
NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_TIME##PLATFORM");
nsresult res = NS_OK;
// use cached info if match with stored locale
if (!locale) {
if (!mLocale.IsEmpty() &&
mLocale.Equals(mAppLocale, nsCaseInsensitiveStringComparator())) {
return NS_OK;
}
}
else {
res = locale->GetCategory(aCategory, localeStr);
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
if (!mLocale.IsEmpty() &&
mLocale.Equals(localeStr,
nsCaseInsensitiveStringComparator())) {
return NS_OK;
}
}
}
mCharset.AssignLiteral("ISO-8859-1");
mPlatformLocale.Assign("en_US");
// get locale name string, use app default if no locale specified
if (!locale) {
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsCOMPtr<nsILocale> appLocale;
res = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_SUCCEEDED(res)) {
res = appLocale->GetCategory(aCategory, localeStr);
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info");
mAppLocale = localeStr; // cache app locale name
}
}
}
}
else {
res = locale->GetCategory(aCategory, localeStr);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info");
}
if (NS_SUCCEEDED(res) && !localeStr.IsEmpty()) {
mLocale = localeStr; // cache locale name
nsPosixLocale::GetPlatformLocale(mLocale, mPlatformLocale);
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
nsAutoCString mappedCharset;
res = platformCharset->GetDefaultCharsetForLocale(mLocale, mappedCharset);
if (NS_SUCCEEDED(res)) {
mCharset = mappedCharset;
}
}
}
// Initialize unicode decoder
nsCOMPtr <nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = charsetConverterManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
}
LocalePreferred24hour();
return res;
}
开发者ID:BrunoReX,项目名称:palemoon,代码行数:75,代码来源:nsDateTimeFormatUnix.cpp
示例13: lc_name
/* wstring getAcceptLangFromLocale (in wstring aLocale); */
NS_IMETHODIMP
nsAcceptLang::GetAcceptLangFromLocale(const PRUnichar *aLocale, PRUnichar **_retval)
{
nsDependentString lc_name(aLocale);
if (lc_name.Length() <=0) {
#ifdef DEBUG
printf("nsAcceptLang::GetAcceptLangFromLocale: aLocale is empty!");
#endif
// TODO: don't return; instead, use system locale: lc_name=...
return NS_ERROR_FAILURE;
}
nsresult res;
nsCOMPtr<nsIStringBundleService> sBundleService =
do_GetService(kStringBundleServiceCID, &res);
if (NS_FAILED(res) || (nsnull == sBundleService)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIStringBundle> bundle;
#if 1
res = sBundleService->CreateBundle("resource://gre/res/language.properties",
getter_AddRefs(bundle));
#else
res = sBundleService->CreateBundle("chrome://global/locale/languageNames.properties",
getter_AddRefs(bundle));
#endif
PRUnichar *ptrv = nsnull;
nsAutoString lc_tmp(aLocale);
NS_NAMED_LITERAL_STRING(sAccept, ".accept");
NS_NAMED_LITERAL_STRING(sTrue, "true");
ToLowerCase(lc_tmp);
lc_tmp.Append(sAccept);
if (NS_OK == (res = bundle->GetStringFromName(lc_tmp.get(), &ptrv))) {
if (sTrue.Equals(ptrv)) {
// valid name already
*_retval = ToNewUnicode(lc_name);
return res;
}
}
/* not in languageNames.properties; lang only?
*/
PRInt32 dash = lc_tmp.FindChar('-');
nsAutoString lang;
nsAutoString country;
if (dash > 0) {
/* lang-country
*/
PRInt32 count = 0;
count = lc_tmp.Left(lang, dash);
count = lc_tmp.Right(country, (lc_tmp.Length()-dash-1));
/* ja-JP -> ja*/
}
else {
/* ja ?? en-JP
en-JP ->ja (how about product locale or syste, locale ???)
ja-EN ->ja
*/
lang = lc_name;
}
// lang always in lower case; don't convert
*_retval = ToNewUnicode(lang);
lang.Append(sAccept);
if (NS_OK == (res = bundle->GetStringFromName(lang.get(), &ptrv))) {
if (sTrue.Equals(ptrv)) {
/* lang is accepted */
return res;
}
}
/* unsupported lang */
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:80,代码来源:nsAcceptLang.cpp
示例14: NS_NAMED_LITERAL_STRING
void
nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement,
nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI,
nsIAtom* aTagName,
nsAString& aStr)
{
PRInt32 count = aContent->GetAttrCount();
if (!count)
return;
nsresult rv;
nsAutoString nameStr, valueStr;
NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
// HTML5 parser stored them in the order they were parsed so we want to
// loop forward in that case.
nsIDocument* doc = aContent->GetOwnerDocument();
PRBool caseSensitive = doc && doc->IsCaseSensitive();
PRBool loopForward = PR_FALSE;
if (!caseSensitive) {
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
if (htmlDoc) {
loopForward = nsHtml5Module::sEnabled;
}
}
PRInt32 index, limit, step;
if (loopForward) {
index = 0;
limit = count;
step = 1;
}
else {
// Loop backward over the attributes, since the order they are stored in is
// the opposite of the order they were parsed in (see bug 213347 for reason).
index = count - 1;
limit = -1;
step = -1;
}
for (; index != limit; index += step) {
const nsAttrName* name = aContent->GetAttrNameAt(index);
PRInt32 namespaceID = name->NamespaceID();
nsIAtom* attrName = name->LocalName();
// Filter out any attribute starting with [-|_]moz
const char* sharedName;
attrName->GetUTF8String(&sharedName);
if ((('_' == *sharedName) || ('-' == *sharedName)) &&
!nsCRT::strncmp(sharedName+1, kMozStr, PRUint32(sizeof(kMozStr)-1))) {
continue;
}
aContent->GetAttr(namespaceID, attrName, valueStr);
//
// Filter out special case of <br type="_moz"> or <br _moz*>,
// used by the editor. Bug 16988. Yuck.
//
if (aTagName == nsGkAtoms::br && attrName == nsGkAtoms::type &&
StringBeginsWith(valueStr, _mozStr)) {
continue;
}
if (mIsCopying && mIsFirstChildOfOL && (aTagName == nsGkAtoms::li) &&
(attrName == nsGkAtoms::value)){
// This is handled separately in SerializeLIValueAttribute()
continue;
}
PRBool isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
if (((attrName == nsGkAtoms::href) ||
(attrName == nsGkAtoms::src))) {
// Make all links absolute when converting only the selection:
if (mFlags & nsIDocumentEncoder::OutputAbsoluteLinks) {
// Would be nice to handle OBJECT and APPLET tags,
// but that gets more complicated since we have to
// search the tag list for CODEBASE as well.
// For now, just leave them relative.
nsCOMPtr<nsIURI> uri = aContent->GetBaseURI();
if (uri) {
nsAutoString absURI;
rv = NS_MakeAbsoluteURI(absURI, valueStr, uri);
if (NS_SUCCEEDED(rv)) {
valueStr = absURI;
}
}
}
// Need to escape URI.
nsAutoString tempURI(valueStr);
if (!isJS && NS_FAILED(EscapeURI(aContent, tempURI, valueStr)))
valueStr = tempURI;
}
if (mRewriteEncodingDeclaration && aTagName == nsGkAtoms::meta &&
attrName == nsGkAtoms::content) {
// If we're serializing a <meta http-equiv="content-type">,
// use the proper value, rather than what's in the document.
nsAutoString header;
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header);
//.........这里部分代码省略.........
开发者ID:AllenDou,项目名称:firefox,代码行数:101,代码来源:nsHTMLContentSerializer.cpp
示例15: printf
//.........这里部分代码省略.........
QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
#ifdef DEBUG_thebes
printf("WindowText ");
#endif
break;
default:
NS_WARNING("None of the listed font types, using WarpSans");
if (!IsDBCS()) {
strcpy(szFontNameSize, "9.WarpSans");
} else {
strcpy(szFontNameSize, "9.WarpSans Combined");
}
} // switch
#ifdef DEBUG_thebes
printf(" (%s)\n", szFontNameSize);
#endif
char *szFacename = strchr(szFontNameSize, '.');
if (!szFacename || (*(szFacename++) == '\0'))
return NS_ERROR_FAILURE;
// local DPI for size will be taken into account below
aFontStyle->size = atof(szFontNameSize);
// determine DPI resolution of screen device to compare compute
// font size in pixels
HPS ps = WinGetScreenPS(HWND_DESKTOP);
HDC dc = GpiQueryDevice(ps);
// effective vertical resolution in DPI
LONG vertScreenRes = 120; // assume 120 dpi as default
DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes);
WinReleasePS(ps);
// now scale to make pixels from points (1 pt = 1/72in)
aFontStyle->size *= vertScreenRes / 72.0;
NS_ConvertUTF8toUTF16 fontFace(szFacename);
int pos = 0;
// this is a system font in any case
aFontStyle->systemFont = true;
// bold fonts should have " Bold" in their names, at least we hope that they
// do, otherwise it's bad luck
NS_NAMED_LITERAL_CSTRING(spcBold, " Bold");
if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) {
aFontStyle->weight = FONT_WEIGHT_BOLD;
// strip the attribute, now that we have set it in the gfxFontStyle
fontFace.Cut(pos, spcBold.Length());
} else {
aFontStyle->weight = FONT_WEIGHT_NORMAL;
}
// FIXME: Set aFontStyle->stretch correctly!
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
// similar hopes for italic and oblique fonts...
NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic");
NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique");
NS_NAMED_LITERAL_CSTRING(spcObli, " Obli");
if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) {
aFontStyle->style = FONT_STYLE_ITALIC;
fontFace.Cut(pos, spcItalic.Length());
} else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) {
// oblique fonts are rare on OS/2 and not specially supported by
// the GPI system, but at least we are trying...
aFontStyle->style = FONT_STYLE_OBLIQUE;
fontFace.Cut(pos, spcOblique.Length());
} else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) {
// especially oblique often gets cut by the 32 char limit to "Obli",
// so search for that, too (anything shorter would be ambiguous)
aFontStyle->style = FONT_STYLE_OBLIQUE;
// In this case, assume that this is the last property in the line
// and cut off everything else, too
// This is needed in case it was really Obliq or Obliqu...
fontFace.Cut(pos, fontFace.Length());
} else {
aFontStyle->style = FONT_STYLE_NORMAL;
}
// just throw away any modifiers that are separated by dots (which are either
// .Strikeout, .Underline, or .Outline, none of which have a corresponding
// gfxFont property)
if ((pos = fontFace.Find(".", false, 0, -1)) > -1) {
fontFace.Cut(pos, fontFace.Length());
}
#ifdef DEBUG_thebes
printf(" after=%s\n", NS_LossyConvertUTF16toASCII(fontFace).get());
printf(" style: %s %s %s\n",
(aFontStyle->weight == FONT_WEIGHT_BOLD) ? "BOLD" : "",
(aFontStyle->style == FONT_STYLE_ITALIC) ? "ITALIC" : "",
(aFontStyl
|
请发表评论