//
// IsInternetShortcut
//
// A file is an Internet Shortcut if it ends with .URL
//
PRBool
nsClipboard :: IsInternetShortcut ( const nsAString& inFileName )
{
return StringEndsWith(inFileName, NS_LITERAL_STRING(".url"), nsCaseInsensitiveStringComparator());
} // IsInternetShortcut
NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
nsIDOMElement *aOriginalElement,
nsAString& aStr)
{
NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) return NS_ERROR_FAILURE;
// The _moz_dirty attribute is emitted by the editor to
// indicate that this element should be pretty printed
// even if we're not in pretty printing mode
PRBool hasDirtyAttr = content->HasAttr(kNameSpaceID_None,
nsGkAtoms::mozdirty);
nsIAtom *name = content->Tag();
if (name == nsGkAtoms::br && mPreLevel > 0
&& (mFlags & nsIDocumentEncoder::OutputNoFormattingInPre)) {
AppendToString(mLineBreak, aStr);
mMayIgnoreLineBreakSequence = PR_TRUE;
mColPos = 0;
return NS_OK;
}
if (name == nsGkAtoms::body) {
mInBody = PR_TRUE;
}
if (LineBreakBeforeOpen(name, hasDirtyAttr)) {
AppendToString(mLineBreak, aStr);
mMayIgnoreLineBreakSequence = PR_TRUE;
mColPos = 0;
mAddSpace = PR_FALSE;
}
else if (mAddSpace) {
AppendToString(PRUnichar(' '), aStr);
mAddSpace = PR_FALSE;
}
else {
MaybeAddNewline(aStr);
}
// Always reset to avoid false newlines in case MaybeAddNewline wasn't
// called
mAddNewline = PR_FALSE;
StartIndentation(name, hasDirtyAttr, aStr);
if (name == nsGkAtoms::pre ||
name == nsGkAtoms::script ||
name == nsGkAtoms::style) {
mPreLevel++;
}
AppendToString(kLessThan, aStr);
nsAutoString nameStr;
name->ToString(nameStr);
AppendToString(nameStr.get(), -1, aStr);
// Need to keep track of OL and LI elements in order to get ordinal number
// for the LI.
if (mIsCopying && name == nsGkAtoms::ol) {
// We are copying and current node is an OL;
// Store it's start attribute value in olState->startVal.
nsAutoString start;
PRInt32 startAttrVal = 0;
aElement->GetAttribute(NS_LITERAL_STRING("start"), start);
if (!start.IsEmpty()) {
PRInt32 rv = 0;
startAttrVal = start.ToInteger(&rv);
//If OL has "start" attribute, first LI element has to start with that value
//Therefore subtracting 1 as all the LI elements are incrementing it before using it;
//In failure of ToInteger(), default StartAttrValue to 0.
if (NS_SUCCEEDED(rv))
startAttrVal--;
else
startAttrVal = 0;
}
olState* state = new olState(startAttrVal, PR_TRUE);
if (state)
mOLStateStack.AppendElement(state);
}
if (mIsCopying && name == nsGkAtoms::li) {
mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement);
if (mIsFirstChildOfOL) {
// If OL is parent of this LI, serialize attributes in different manner.
SerializeLIValueAttribute(aElement, aStr);
}
}
// Even LI passed above have to go through this
// for serializing attributes other than "value".
SerializeAttributes(content, name, aStr);
AppendToString(kGreaterThan, aStr);
if (LineBreakAfterOpen(name, hasDirtyAttr)) {
//.........这里部分代码省略.........
NS_IMETHODIMP nsPop3IncomingServer::SetDeferredToAccount(const nsACString& aAccountKey)
{
nsCString deferredToAccount;
GetDeferredToAccount(deferredToAccount);
m_rootMsgFolder = nullptr; // clear this so we'll recalculate it on demand.
//Notify listeners who listen to every folder
nsresult rv = SetCharValue("deferred_to_account", aAccountKey);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFolderListener> folderListenerManager =
do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIMsgFolder> rootFolder;
// use GetRootFolder, because that returns the real
// root, not the deferred to root.
rv = GetRootFolder(getter_AddRefs(rootFolder));
if (rootFolder)
{
// if isDeferred state has changed, send notification
if (aAccountKey.IsEmpty() != deferredToAccount.IsEmpty())
{
nsCOMPtr <nsIAtom> deferAtom = MsgGetAtom("isDeferred");
nsCOMPtr <nsIAtom> canFileAtom = MsgGetAtom("CanFileMessages");
folderListenerManager->OnItemBoolPropertyChanged(rootFolder, deferAtom,
!deferredToAccount.IsEmpty(), deferredToAccount.IsEmpty());
folderListenerManager->OnItemBoolPropertyChanged(rootFolder, canFileAtom,
deferredToAccount.IsEmpty(), !deferredToAccount.IsEmpty());
// this hack causes the account manager ds to send notifications to the
// xul content builder that make the changed acct appear or disappear
// from the folder pane and related menus.
nsCOMPtr<nsIMsgAccountManager> acctMgr =
do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID);
if (acctMgr)
{
acctMgr->NotifyServerUnloaded(this);
acctMgr->NotifyServerLoaded(this);
// check if this newly deferred to account is the local folders account
// and needs to have a newly created INBOX.
if (!aAccountKey.IsEmpty())
{
nsCOMPtr <nsIMsgAccount> account;
acctMgr->GetAccount(aAccountKey, getter_AddRefs(account));
if (account)
{
nsCOMPtr <nsIMsgIncomingServer> server;
account->GetIncomingServer(getter_AddRefs(server));
if (server)
{
nsCOMPtr <nsILocalMailIncomingServer> incomingLocalServer = do_QueryInterface(server);
if (incomingLocalServer)
{
nsCOMPtr <nsIMsgFolder> rootFolder;
rv = server->GetRootFolder(getter_AddRefs(rootFolder));
NS_ENSURE_SUCCESS(rv, rv);
// this will fail if it already exists, which is fine.
rootFolder->CreateSubfolder(NS_LITERAL_STRING("Inbox"), nullptr);
}
}
}
}
}
}
}
}
return rv;
}
nsresult
nsNNTPNewsgroupList::GetRangeOfArtsToDownload(nsIMsgWindow *aMsgWindow,
int32_t first_possible,
int32_t last_possible,
int32_t maxextra,
int32_t *first,
int32_t *last,
int32_t *status)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(first);
NS_ENSURE_ARG_POINTER(last);
NS_ENSURE_ARG_POINTER(status);
*first = 0;
*last = 0;
nsCOMPtr <nsIMsgFolder> folder = do_QueryInterface(m_newsFolder, &rv);
NS_ENSURE_SUCCESS(rv,rv);
m_msgWindow = aMsgWindow;
nsCOMPtr<nsINewsDatabase> db(do_QueryInterface(m_newsDB, &rv));
NS_ENSURE_SUCCESS(rv,rv);
rv = db->GetReadSet(&m_set);
if (NS_FAILED(rv) || !m_set)
return rv;
m_set->SetLastMember(last_possible); // make sure highwater mark is valid.
nsCOMPtr <nsIDBFolderInfo> newsGroupInfo;
rv = m_newsDB->GetDBFolderInfo(getter_AddRefs(newsGroupInfo));
if (NS_SUCCEEDED(rv) && newsGroupInfo) {
nsCString knownArtsString;
nsMsgKey mark;
newsGroupInfo->GetKnownArtsSet(getter_Copies(knownArtsString));
rv = newsGroupInfo->GetHighWater(&mark);
NS_ENSURE_SUCCESS(rv,rv);
if (last_possible < ((int32_t)mark))
newsGroupInfo->SetHighWater(last_possible);
if (m_knownArts.set)
delete m_knownArts.set;
m_knownArts.set = nsMsgKeySet::Create(knownArtsString.get());
}
else
{
if (m_knownArts.set)
delete m_knownArts.set;
m_knownArts.set = nsMsgKeySet::Create();
nsMsgKey low, high;
rv = m_newsDB->GetLowWaterArticleNum(&low);
NS_ENSURE_SUCCESS(rv,rv);
rv = m_newsDB->GetHighWaterArticleNum(&high);
NS_ENSURE_SUCCESS(rv,rv);
m_knownArts.set->AddRange(low,high);
}
if (m_knownArts.set->IsMember(last_possible)) {
nsString statusString;
nsCOMPtr<nsIStringBundleService> bundleService =
mozilla::services::GetStringBundleService();
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
rv = bundle->GetStringFromName(NS_LITERAL_STRING("noNewMessages").get(), getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
SetProgressStatus(statusString.get());
}
if (maxextra <= 0 || last_possible < first_possible || last_possible < 1)
{
*status=0;
return NS_OK;
}
m_knownArts.first_possible = first_possible;
m_knownArts.last_possible = last_possible;
nsCOMPtr <nsIMsgIncomingServer> server;
rv = folder->GetServer(getter_AddRefs(server));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsINntpIncomingServer> nntpServer = do_QueryInterface(server, &rv);
NS_ENSURE_SUCCESS(rv,rv);
/* Determine if we only want to get just new articles or more messages.
If there are new articles at the end we haven't seen, we always want to get those first.
Otherwise, we get the newest articles we haven't gotten, if we're getting more.
My thought for now is that opening a newsgroup should only try to get new articles.
Selecting "More Messages" will first try to get unseen messages, then old messages. */
if (m_getOldMessages || !m_knownArts.set->IsMember(last_possible))
{
bool notifyMaxExceededOn = true;
//.........这里部分代码省略.........
void
nsHTMLContentSerializer::SerializeLIValueAttribute(nsIDOMElement* aElement,
nsAString& aStr)
{
// We are copying and we are at the "first" LI node of OL in selected range.
// It may not be the first LI child of OL but it's first in the selected range.
// Note that we get into this condition only once per a OL.
PRBool found = PR_FALSE;
nsCOMPtr<nsIDOMNode> currNode = do_QueryInterface(aElement);
nsAutoString valueStr;
PRInt32 offset = 0;
olState defaultOLState(0, PR_FALSE);
olState* state = nsnull;
if (mOLStateStack.Count() > 0)
state = (olState*)mOLStateStack.ElementAt(mOLStateStack.Count()-1);
/* Though we should never reach to a "state" as null or mOLStateStack.Count() == 0
at this point as all LI are supposed to be inside some OL and OL tag should have
pushed a state to the olStateStack.*/
if (!state || mOLStateStack.Count() == 0)
state = &defaultOLState;
PRInt32 startVal = state->startVal;
state->isFirstListItem = PR_FALSE;
// Traverse previous siblings until we find one with "value" attribute.
// offset keeps track of how many previous siblings we had tocurrNode traverse.
while (currNode && !found) {
nsCOMPtr<nsIDOMElement> currElement = do_QueryInterface(currNode);
// currElement may be null if it were a text node.
if (currElement) {
nsAutoString tagName;
currElement->GetTagName(tagName);
if (tagName.LowerCaseEqualsLiteral("li")) {
currElement->GetAttribute(NS_LITERAL_STRING("value"), valueStr);
if (valueStr.IsEmpty())
offset++;
else {
found = PR_TRUE;
PRInt32 rv = 0;
startVal = valueStr.ToInteger(&rv);
}
}
}
nsCOMPtr<nsIDOMNode> tmp;
currNode->GetPreviousSibling(getter_AddRefs(tmp));
currNode.swap(tmp);
}
// If LI was not having "value", Set the "value" attribute for it.
// Note that We are at the first LI in the selected range of OL.
if (offset == 0 && found) {
// offset = 0 => LI itself has the value attribute and we did not need to traverse back.
// Just serialize value attribute like other tags.
SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"), valueStr, aStr, PR_FALSE);
}
else if (offset == 1 && !found) {
/*(offset = 1 && !found) means either LI is the first child node of OL
and LI is not having "value" attribute.
In that case we would not like to set "value" attribute to reduce the changes.
*/
//do nothing...
}
else if (offset > 0) {
// Set value attribute.
nsAutoString valueStr;
//As serializer needs to use this valueAttr we are creating here,
valueStr.AppendInt(startVal + offset);
SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"), valueStr, aStr, PR_FALSE);
}
}
NS_IMETHODIMP
nsXFormsItemSetElement::Refresh()
{
// We need to create item elements for each element referenced by the
// nodeset. Each of these items will create an anonymous HTML option element
// which will return from GetAnonymousNodes. We then clone our template
// content and insert the cloned content as children of the HTML option.
if (!nsXFormsUtils::IsDocumentReadyForBind(mElement)) {
// not ready to bind yet, defer
nsXFormsModelElement::DeferElementBind(this);
return NS_OK;
}
nsCOMPtr<nsIModelElementPrivate> model;
nsCOMPtr<nsIDOMXPathResult> result;
nsresult rv = ProcessNodeBinding(NS_LITERAL_STRING("nodeset"),
nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
getter_AddRefs(result),
getter_AddRefs(model));
if (NS_FAILED(rv) | !result | !model)
return rv;
nsCOMPtr<nsIDOMNode> node, templateNode, cloneNode, tmpNode;
nsCOMPtr<nsIDOMElement> itemNode, itemWrapperNode, contextContainer;
nsCOMPtr<nsIDOMNodeList> templateNodes;
mElement->GetChildNodes(getter_AddRefs(templateNodes));
PRUint32 templateNodeCount = 0;
if (templateNodes)
templateNodes->GetLength(&templateNodeCount);
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
NS_ENSURE_STATE(content);
nsCOMPtr<nsIDocument> doc = content->GetCurrentDoc();
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
NS_ENSURE_STATE(domDoc);
PRUint32 nodeCount;
result->GetSnapshotLength(&nodeCount);
nsCOMPtr<nsIDOMNode> parent, tmp;
mElement->GetParentNode(getter_AddRefs(parent));
while (parent) {
if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select1")) ||
nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select"))) {
break;
}
tmp.swap(parent);
tmp->GetParentNode(getter_AddRefs(parent));
}
nsCOMPtr<nsIXFormsItemSetUIElement> uiItemSet(do_QueryInterface(mElement));
nsCOMPtr<nsIDOMElement> anonContent;
if (uiItemSet) {
uiItemSet->GetAnonymousItemSetContent(getter_AddRefs(anonContent));
}
NS_ENSURE_STATE(anonContent);
nsCOMPtr<nsIDOMNode> childNode, nodeReturn;
while (NS_SUCCEEDED(anonContent->GetFirstChild(getter_AddRefs(childNode))) &&
childNode) {
anonContent->RemoveChild(childNode, getter_AddRefs(nodeReturn));
}
for (PRUint32 i = 0; i < nodeCount; ++i) {
result->SnapshotItem(i, getter_AddRefs(node));
NS_ASSERTION(node, "incorrect snapshot length");
rv = domDoc->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
NS_LITERAL_STRING("item"),
getter_AddRefs(itemNode));
NS_ENSURE_SUCCESS(rv, rv);
anonContent->AppendChild(itemNode, getter_AddRefs(tmpNode));
nsCOMPtr<nsIXFormsContextControl> ctx(do_QueryInterface(itemNode));
if (ctx) {
ctx->SetContext(node, i + 1, nodeCount);
}
// Clone the template content under the item
for (PRUint32 j = 0; j < templateNodeCount; ++j) {
templateNodes->Item(j, getter_AddRefs(templateNode));
templateNode->CloneNode(PR_TRUE, getter_AddRefs(cloneNode));
itemNode->AppendChild(cloneNode, getter_AddRefs(templateNode));
}
}
// refresh parent so that it has a chance to reflect the changes we just made
if (parent) {
nsCOMPtr<nsIXFormsControlBase> control = do_QueryInterface(parent);
if (control) {
control->Refresh();
}
}
//.........这里部分代码省略.........
nsresult
nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
{
nsresult rv;
if (NS_FAILED(ensure_libgnomeui()) || NS_FAILED(ensure_libgnome()) || NS_FAILED(ensure_libgnomevfs())) {
gTriedToLoadGnomeLibs = true;
return NS_ERROR_NOT_AVAILABLE;
}
gTriedToLoadGnomeLibs = true;
if (!_gnome_program_get()) {
// Get the brandShortName from the string bundle to pass to GNOME
// as the application name. This may be used for things such as
// the title of grouped windows in the panel.
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
NS_ASSERTION(bundleService, "String bundle service must be present!");
nsCOMPtr<nsIStringBundle> bundle;
bundleService->CreateBundle("chrome://branding/locale/brand.properties",
getter_AddRefs(bundle));
nsAutoString appName;
if (bundle) {
bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(),
getter_Copies(appName));
} else {
NS_WARNING("brand.properties not present, using default application name");
appName.Assign(NS_LITERAL_STRING("Gecko"));
}
char* empty[] = { "" };
_gnome_init(NS_ConvertUTF16toUTF8(appName).get(), "1.0", 1, empty, NULL, 0, NULL);
}
uint32_t iconSize = GetIconSize(aIconURI);
nsCAutoString type;
aIconURI->GetContentType(type);
GnomeVFSFileInfo fileInfo = {0};
fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it
nsCAutoString spec;
nsCOMPtr<nsIURL> url;
rv = aIconURI->GetIconURL(getter_AddRefs(url));
if (url) {
url->GetAsciiSpec(spec);
// Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a
// network request
bool isFile;
if (NS_SUCCEEDED(url->SchemeIs("file", &isFile)) && isFile) {
_gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT);
}
else {
// The filename we get is UTF-8-compatible, which matches gnome expectations.
// See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html
// "Whenever we can detect the charset used for the URI type we try to
// convert it to/from utf8 automatically inside gnome-vfs."
// I'll interpret that as "otherwise, this field is random junk".
nsCAutoString name;
url->GetFileName(name);
fileInfo.name = g_strdup(name.get());
if (!type.IsEmpty()) {
fileInfo.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
fileInfo.mime_type = g_strdup(type.get());
}
}
}
if (type.IsEmpty()) {
nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1"));
if (ms) {
nsCAutoString fileExt;
aIconURI->GetFileExtension(fileExt);
if (!fileExt.IsEmpty()) {
ms->GetTypeFromExtension(fileExt, type);
}
}
}
// Get the icon theme
if (!gIconTheme) {
gIconTheme = _gnome_icon_theme_new();
if (!gIconTheme) {
_gnome_vfs_file_info_clear(&fileInfo);
return NS_ERROR_NOT_AVAILABLE;
}
}
char* name = _gnome_icon_lookup(gIconTheme, NULL, spec.get(), NULL, &fileInfo,
type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE,
NULL);
_gnome_vfs_file_info_clear(&fileInfo);
if (!name)
return NS_ERROR_NOT_AVAILABLE;
//.........这里部分代码省略.........
nsresult
nsNNTPNewsgroupList::FinishXOVERLINE(int status, int *newstatus)
{
nsresult rv;
struct MSG_NewsKnown* k;
/* If any XOVER lines from the last time failed to come in, mark those
messages as read. */
if (status >= 0 && m_lastProcessedNumber < m_lastMsgNumber) {
m_set->AddRange(m_lastProcessedNumber + 1, m_lastMsgNumber);
}
if (m_lastProcessedNumber)
AddToKnownArticles(m_firstMsgNumber, m_lastProcessedNumber);
k = &m_knownArts;
if (k && k->set)
{
int32_t n = k->set->FirstNonMember();
if (n < k->first_possible || n > k->last_possible)
{
/* We know we've gotten all there is to know.
Take advantage of that to update our counts... */
// ### dmb
}
}
if (!m_finishingXover)
{
// turn on m_finishingXover - this is a horrible hack to avoid recursive
// calls which happen when the fe selects a message as a result of getting EndingUpdate,
// which interrupts this url right before it was going to finish and causes FinishXOver
// to get called again.
m_finishingXover = true;
// XXX is this correct?
m_runningURL = nullptr;
if (m_lastMsgNumber > 0) {
nsAutoString firstStr;
firstStr.AppendInt(m_lastProcessedNumber - m_firstMsgNumber + 1);
nsAutoString lastStr;
lastStr.AppendInt(m_lastMsgNumber - m_firstMsgNumber + 1);
nsString statusString;
nsCOMPtr<nsIStringBundleService> bundleService =
mozilla::services::GetStringBundleService();
NS_ENSURE_TRUE(bundleService, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(NEWS_MSGS_URL, getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
const PRUnichar *formatStrings[2] = { firstStr.get(), lastStr.get() };
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("downloadingArticles").get(), formatStrings, 2, getter_Copies(statusString));
NS_ENSURE_SUCCESS(rv, rv);
SetProgressStatus(statusString.get());
}
}
if (newstatus)
*newstatus=0;
return NS_OK;
}
void
nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsIAtom* aTagName,
nsAString& aStr)
{
nsresult rv;
PRUint32 index, count;
nsAutoString nameStr, valueStr;
count = aContent->GetAttrCount();
NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
// 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 is unsigned, hence index >= 0 is always true.
for (index = count; index > 0; ) {
--index;
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(attrName, 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(tempURI, valueStr)))
valueStr = tempURI;
}
if (mIsWholeDocument && 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);
if (header.LowerCaseEqualsLiteral("content-type")) {
valueStr = NS_LITERAL_STRING("text/html; charset=") +
NS_ConvertASCIItoUTF16(mCharset);
}
}
attrName->ToString(nameStr);
/*If we already crossed the MaxColumn limit or
* if this attr name-value pair(including a space,=,opening and closing quotes) is greater than MaxColumn limit
* then start the attribute from a new line.
*/
if (mDoFormat
&& (mColPos >= mMaxColumn
|| ((PRInt32)(mColPos + nameStr.Length() +
valueStr.Length() + 4) > mMaxColumn))) {
aStr.Append(mLineBreak);
mColPos = 0;
}
// Expand shorthand attribute.
if (IsShorthandAttr(attrName, aTagName) && valueStr.IsEmpty()) {
valueStr = nameStr;
//.........这里部分代码省略.........
void
TelephonyCall::ChangeStateInternal(uint16_t aCallState, bool aFireEvents)
{
nsRefPtr<TelephonyCall> kungFuDeathGrip(this);
nsString stateString;
switch (aCallState) {
case nsIRadioInterfaceLayer::CALL_STATE_DIALING:
stateString.AssignLiteral("dialing");
break;
case nsIRadioInterfaceLayer::CALL_STATE_ALERTING:
stateString.AssignLiteral("alerting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_BUSY:
stateString.AssignLiteral("busy");
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTING:
stateString.AssignLiteral("connecting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_CONNECTED:
stateString.AssignLiteral("connected");
break;
case nsIRadioInterfaceLayer::CALL_STATE_HOLDING:
stateString.AssignLiteral("holding");
break;
case nsIRadioInterfaceLayer::CALL_STATE_HELD:
stateString.AssignLiteral("held");
break;
case nsIRadioInterfaceLayer::CALL_STATE_RESUMING:
stateString.AssignLiteral("resuming");
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTING:
stateString.AssignLiteral("disconnecting");
break;
case nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED:
stateString.AssignLiteral("disconnected");
break;
case nsIRadioInterfaceLayer::CALL_STATE_INCOMING:
stateString.AssignLiteral("incoming");
break;
default:
NS_NOTREACHED("Unknown state!");
}
mState = stateString;
mCallState = aCallState;
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DIALING) {
mOutgoing = true;
}
if (aCallState == nsIRadioInterfaceLayer::CALL_STATE_DISCONNECTED) {
NS_ASSERTION(mLive, "Should be live!");
mTelephony->RemoveCall(this);
mLive = false;
} else if (!mLive) {
mTelephony->AddCall(this);
mLive = true;
}
if (aFireEvents) {
nsRefPtr<CallEvent> event = CallEvent::Create(this);
NS_ASSERTION(event, "This should never fail!");
if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(),
NS_LITERAL_STRING("statechange")))) {
NS_WARNING("Failed to dispatch statechange event!");
}
// This can change if the statechange handler called back here... Need to
// figure out something smarter.
if (mCallState == aCallState) {
event = CallEvent::Create(this);
NS_ASSERTION(event, "This should never fail!");
if (NS_FAILED(event->Dispatch(ToIDOMEventTarget(), stateString))) {
NS_WARNING("Failed to dispatch specific event!");
}
}
}
}
NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
PRBool aHasChildren,
nsAString& aStr)
{
NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) return NS_ERROR_FAILURE;
// The _moz_dirty attribute is emitted by the editor to
// indicate that this element should be pretty printed
// even if we're not in pretty printing mode
PRBool hasDirtyAttr = content->HasAttr(kNameSpaceID_None,
nsLayoutAtoms::mozdirty);
nsIAtom *name = content->Tag();
if (name == nsHTMLAtoms::br && mPreLevel > 0
&& (mFlags & nsIDocumentEncoder::OutputNoFormattingInPre)) {
AppendToString(mLineBreak, aStr);
mMayIgnoreLineBreakSequence = PR_TRUE;
mColPos = 0;
return NS_OK;
}
if (name == nsHTMLAtoms::body) {
mInBody = PR_TRUE;
}
if (LineBreakBeforeOpen(name, hasDirtyAttr)) {
AppendToString(mLineBreak, aStr);
mMayIgnoreLineBreakSequence = PR_TRUE;
mColPos = 0;
mAddSpace = PR_FALSE;
}
else if (mAddSpace) {
AppendToString(PRUnichar(' '), aStr);
mAddSpace = PR_FALSE;
}
else {
MaybeAddNewline(aStr);
}
// Always reset to avoid false newlines in case MaybeAddNewline wasn't
// called
mAddNewline = PR_FALSE;
StartIndentation(name, hasDirtyAttr, aStr);
if (name == nsHTMLAtoms::pre ||
name == nsHTMLAtoms::script ||
name == nsHTMLAtoms::style) {
mPreLevel++;
}
AppendToString(kLessThan, aStr);
nsAutoString nameStr;
name->ToString(nameStr);
AppendToString(nameStr.get(), -1, aStr);
// Need to keep track of OL and LI elements in order to get ordinal number
// for the LI.
if (mIsCopying && name == nsHTMLAtoms::ol){
// We are copying and current node is an OL;
// Store it's start attribute value in olState->startVal.
nsAutoString start;
PRInt32 startAttrVal = 0;
aElement->GetAttribute(NS_LITERAL_STRING("start"), start);
if (!start.IsEmpty()){
PRInt32 rv = 0;
startAttrVal = start.ToInteger(&rv);
//If OL has "start" attribute, first LI element has to start with that value
//Therefore subtracting 1 as all the LI elements are incrementing it before using it;
//In failure of ToInteger(), default StartAttrValue to 0.
if (NS_SUCCEEDED(rv))
startAttrVal--;
else
startAttrVal = 0;
}
olState* state = new olState(startAttrVal, PR_TRUE);
if (state)
mOLStateStack.AppendElement(state);
}
if (mIsCopying && name == nsHTMLAtoms::li) {
mIsFirstChildOfOL = IsFirstChildOfOL(aElement);
if (mIsFirstChildOfOL){
// If OL is parent of this LI, serialize attributes in different manner.
SerializeLIValueAttribute(aElement, aStr);
}
}
// Even LI passed above have to go through this
// for serializing attributes other than "value".
SerializeAttributes(content, name, aStr);
AppendToString(kGreaterThan, aStr);
if (LineBreakAfterOpen(name, hasDirtyAttr)) {
//.........这里部分代码省略.........
请发表评论