Work around XUL template builder regression on trunk and possibly marginally improve performance.

bug=336857
r=enndeakin
sr=ben
a=mconnor for checkin to 1.8 branch
This commit is contained in:
myk%mozilla.org 2006-05-22 19:23:57 +00:00
parent 2e77381faf
commit ba0803d3a8
4 changed files with 88 additions and 89 deletions

View File

@ -540,45 +540,15 @@
#endif
</toolbarbutton>
</rule>
<!-- A rule to match bookmarks with microsummary generated titles.
- We have to use the extended template syntax to specify the rule
- because the simplified syntax doesn't permit conditions that test
- for the mere presence of a property, and microsummarized bookmarks
- are identified by the mere presence of the GeneratedTitle property.
-->
<rule>
<conditions>
<content uri="?start" tag="hbox"/>
<member container="?start" child="?bookmark"/>
<triple subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#GeneratedTitle"
object="?GeneratedTitle"/>
</conditions>
<bindings>
<binding subject="?bookmark"
predicate="http://home.netscape.com/WEB-rdf#status"
object="?status"/>
<binding subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#Bookmark"
object="?xBookmark"/>
<binding subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#Icon"
object="?Icon"/>
<binding subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#URL"
object="?URL"/>
</bindings>
<action>
<toolbarbutton class="bookmark-item-microsummarized bookmark-item"
uri="?bookmark"
editable="true"
status="?status"
rdf:type="?xBookmark"
image="?Icon"
statustext="?URL"
tooltip="btTooltip"
label="?GeneratedTitle"/>
</action>
<rule parent="hbox" rdf:type="http://home.netscape.com/NC-rdf#MicsumBookmark">
<toolbarbutton class="bookmark-item-microsummarized bookmark-item"
uri="rdf:*" editable="true"
status="rdf:http://home.netscape.com/WEB-rdf#status"
rdf:type="http://home.netscape.com/NC-rdf#Bookmark"
image="rdf:http://home.netscape.com/NC-rdf#Icon"
statustext="rdf:http://home.netscape.com/NC-rdf#URL"
tooltip="btTooltip"
label="rdf:http://home.netscape.com/NC-rdf#GeneratedTitle"/>
</rule>
<rule parent="hbox">
<toolbarbutton class="bookmark-item" uri="rdf:*" editable="true"
@ -621,41 +591,14 @@
</menu>
</menupopup>
</rule>
<!-- A rule to match bookmarks with microsummary generated titles.
- We have to use the extended template syntax to specify the rule
- because the simplified syntax doesn't permit conditions that test
- for the mere presence of a property, and microsummarized bookmarks
- are identified by the mere presence of the GeneratedTitle property.
-->
<rule>
<conditions>
<content uri="?start"/>
<member container="?start" child="?bookmark"/>
<triple subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#GeneratedTitle"
object="?GeneratedTitle"/>
</conditions>
<bindings>
<binding subject="?bookmark"
predicate="http://home.netscape.com/WEB-rdf#status"
object="?status"/>
<binding subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#Icon"
object="?Icon"/>
<binding subject="?bookmark"
predicate="http://home.netscape.com/NC-rdf#URL"
object="?URL"/>
</bindings>
<action>
<menupopup>
<menuitem class="menuitem-iconic bookmark-item"
uri="?bookmark"
label="?GeneratedTitle"
image="?Icon"
status="?status"
statustext="?URL"/>
</menupopup>
</action>
<rule rdf:type="http://home.netscape.com/NC-rdf#MicsumBookmark">
<menupopup>
<menuitem class="menuitem-iconic bookmark-item" uri="rdf:*"
label="rdf:http://home.netscape.com/NC-rdf#GeneratedTitle"
image="rdf:http://home.netscape.com/NC-rdf#Icon"
status="rdf:http://home.netscape.com/WEB-rdf#status"
statustext="rdf:http://home.netscape.com/NC-rdf#URL"/>
</menupopup>
</rule>
<rule>
<menupopup>

View File

@ -1367,6 +1367,10 @@ var BookmarksUtils = {
if (aResource == BMSVC.getBookmarksToolbarFolder())
type = "PersonalToolbarFolder";
}
// Treat microsummary bookmarks like regular bookmarks, since they behave
// like regular bookmarks in almost every regard.
if (type == "MicsumBookmark")
type = "Bookmark";
if (type == "") {
// we're not sure what type it is. figure out if it's a container.

View File

@ -119,6 +119,7 @@ nsIRDFResource *kNC_PostData;
nsIRDFResource *kNC_Livemark;
nsIRDFResource *kNC_LivemarkLock;
nsIRDFResource *kNC_LivemarkExpiration;
nsIRDFResource *kNC_MicsumBookmark;
nsIRDFResource *kNC_MicsumGenURI;
nsIRDFResource *kNC_MicsumExpiration;
nsIRDFResource *kNC_GeneratedTitle;
@ -279,6 +280,8 @@ bm_AddRefGlobals()
&kNC_LivemarkLock);
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "LivemarkExpiration"),
&kNC_LivemarkExpiration);
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "MicsumBookmark"),
&kNC_MicsumBookmark);
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "MicsumGenURI"),
&kNC_MicsumGenURI);
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "MicsumExpiration"),
@ -402,6 +405,7 @@ bm_ReleaseGlobals()
NS_IF_RELEASE(kNC_Livemark);
NS_IF_RELEASE(kNC_LivemarkLock);
NS_IF_RELEASE(kNC_LivemarkExpiration);
NS_IF_RELEASE(kNC_MicsumBookmark);
NS_IF_RELEASE(kNC_MicsumGenURI);
NS_IF_RELEASE(kNC_MicsumExpiration);
NS_IF_RELEASE(kNC_GeneratedTitle);
@ -901,6 +905,10 @@ BookmarkParser::ProcessLine(nsIRDFContainer *container, nsIRDFResource *nodeType
{
rv = ParseBookmarkInfo(gBookmarkFieldTable, PR_TRUE, line, container, kNC_Livemark, bookmarkNode);
}
else if ((offset = line.Find(kMicsumGenURIEquals, PR_TRUE)) >= 0)
{
rv = ParseBookmarkInfo(gBookmarkFieldTable, PR_TRUE, line, container, kNC_MicsumBookmark, bookmarkNode);
}
else if ((offset = line.Find(kHREFEquals, PR_TRUE)) >= 0)
{
rv = ParseBookmarkInfo(gBookmarkFieldTable, PR_TRUE, line, container, nodeType, bookmarkNode);
@ -1319,7 +1327,8 @@ BookmarkParser::ParseBookmarkInfo(BookmarkField *fields, PRBool isBookmarkFlag,
else if (aNodeType == kNC_IEFavorite ||
aNodeType == kNC_IEFavoriteFolder ||
aNodeType == kNC_BookmarkSeparator ||
aNodeType == kNC_Livemark)
aNodeType == kNC_Livemark ||
aNodeType == kNC_MicsumBookmark)
{
rv = mDataSource->Assert(bookmark, kRDF_type, aNodeType, PR_TRUE);
if (aNodeType == kNC_Livemark) {
@ -3311,7 +3320,7 @@ nsBookmarksService::UpdateLastVisitedDate(const char *aURL,
nsCOMPtr<nsIRDFNode> nodeType;
GetSynthesizedType(bookmark, getter_AddRefs(nodeType));
if (nodeType == kNC_Bookmark) {
if (nodeType == kNC_Bookmark || nodeType == kNC_MicsumBookmark) {
nsCOMPtr<nsIRDFDate> now;
rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(now));
if (NS_FAILED(rv))
@ -3449,7 +3458,7 @@ nsBookmarksService::GetLastCharset(const nsACString &aURL, nsAString &aCharset)
nsCOMPtr<nsIRDFNode> nodeType;
GetSynthesizedType(bookmark, getter_AddRefs(nodeType));
if (nodeType == kNC_Bookmark) {
if (nodeType == kNC_Bookmark || nodeType == kNC_Bookmark) {
nsCOMPtr<nsIRDFNode> charsetNode;
rv = GetTarget(bookmark, kWEB_LastCharset, PR_TRUE,
getter_AddRefs(charsetNode));
@ -3917,7 +3926,12 @@ nsBookmarksService::Change(nsIRDFResource* aSource,
if (aNewTarget == kNC_Livemark) {
rv = gRDFC->MakeSeq(mInner, aSource, nsnull);
} else if (aNewTarget == kNC_Bookmark) {
rv = nsBMSVCUnmakeSeq(mInner, aSource);
// If the bookmark is a container (i.e. used to be a livemark),
// make it no longer be a container.
PRBool isContainer = PR_FALSE;
(void)gRDFC->IsSeq(mInner, aSource, &isContainer);
if (isContainer)
rv = nsBMSVCUnmakeSeq(mInner, aSource);
}
}
}
@ -4044,7 +4058,7 @@ nsBookmarksService::GetAllCmds(nsIRDFResource* source,
GetSynthesizedType(source, getter_AddRefs(nodeType));
PRBool isBookmark, isBookmarkFolder, isBookmarkSeparator, isLivemark;
isBookmark = (nodeType == kNC_Bookmark) ? PR_TRUE : PR_FALSE;
isBookmark = (nodeType == kNC_Bookmark || nodeType == kNC_MicsumBookmark) ? PR_TRUE : PR_FALSE;
isBookmarkFolder = (nodeType == kNC_Folder) ? PR_TRUE : PR_FALSE;
isBookmarkSeparator = (nodeType == kNC_BookmarkSeparator) ? PR_TRUE : PR_FALSE;
isLivemark = (nodeType == kNC_Livemark) ? PR_TRUE : PR_FALSE;

View File

@ -58,6 +58,10 @@ const FIELD_GENERATED_TITLE = "bookmarks/generatedTitle";
const FIELD_CONTENT_TYPE = "bookmarks/contentType";
#else
const NC_NS = "http://home.netscape.com/NC-rdf#";
const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
const FIELD_RDF_TYPE = RDF_NS + "type";
const VALUE_MICSUM_BOOKMARK = NC_NS + "MicsumBookmark";
const VALUE_NORMAL_BOOKMARK = NC_NS + "Bookmark";
const FIELD_MICSUM_GEN_URI = NC_NS + "MicsumGenURI";
const FIELD_MICSUM_EXPIRATION = NC_NS + "MicsumExpiration";
const FIELD_GENERATED_TITLE = NC_NS + "GeneratedTitle";
@ -238,12 +242,12 @@ MicrosummaryService.prototype = {
}
#else
var bookmarks = [];
var resources = this._bmds.GetAllResources();
while (resources.hasMoreElements()) {
var resource = resources.getNext().QueryInterface(Ci.nsIRDFResource);
if (this._bmds.hasArcOut(resource, this._resource(FIELD_MICSUM_GEN_URI)))
bookmarks.push(resource);
}
var resources = this._bmds.GetSources(this._resource(FIELD_RDF_TYPE),
this._resource(VALUE_MICSUM_BOOKMARK),
true);
while (resources.hasMoreElements())
bookmarks.push(resources.getNext().QueryInterface(Ci.nsIRDFResource));
#endif
var now = new Date().getTime();
@ -597,8 +601,12 @@ MicrosummaryService.prototype = {
var node = this._bmds.GetTarget(bookmarkResource,
this._resource(fieldName),
true);
if (node)
fieldValue = node.QueryInterface(Ci.nsIRDFLiteral).Value;
if (node) {
if (fieldName == FIELD_RDF_TYPE)
fieldValue = node.QueryInterface(Ci.nsIRDFResource).Value;
else
fieldValue = node.QueryInterface(Ci.nsIRDFLiteral).Value;
}
else
fieldValue = null;
@ -622,7 +630,29 @@ MicrosummaryService.prototype = {
true);
}
this._forceToolbarRebuild();
// If we're setting the generator URI field, make sure the bookmark's
// RDF type is set to the microsummary bookmark type.
if (fieldName == FIELD_MICSUM_GEN_URI &&
this._getField(bookmarkID, FIELD_RDF_TYPE) != VALUE_MICSUM_BOOKMARK) {
if (this._hasField(bookmarkID, FIELD_RDF_TYPE)) {
oldValue = this._getField(bookmarkID, FIELD_RDF_TYPE);
this._bmds.Change(bookmarkResource,
this._resource(FIELD_RDF_TYPE),
this._resource(oldValue),
this._resource(VALUE_MICSUM_BOOKMARK));
}
else {
this._bmds.Assert(bookmarkResource,
this._resource(FIELD_RDF_TYPE),
this._resource(VALUE_MICSUM_BOOKMARK),
true);
}
}
// If we're setting a field that could affect this bookmark's label
// in bookmarks toolbars, then force toolbars to rebuild from scratch.
if (fieldName == FIELD_MICSUM_GEN_URI || fieldName == FIELD_GENERATED_TITLE)
this._forceToolbarRebuild();
},
_clearField: function MSS__clearField(bookmarkID, fieldName) {
@ -635,8 +665,16 @@ MicrosummaryService.prototype = {
this._bmds.Unassert(bookmarkResource,
this._resource(fieldName),
node);
this._forceToolbarRebuild();
}
// If we're clearing the generator URI field, set the bookmark's RDF type
// back to the normal bookmark type.
if (fieldName == FIELD_MICSUM_GEN_URI &&
this._getField(bookmarkID, FIELD_RDF_TYPE) == VALUE_MICSUM_BOOKMARK)
this._bmds.Change(bookmarkResource,
this._resource(FIELD_RDF_TYPE),
this._resource(VALUE_MICSUM_BOOKMARK),
this._resource(VALUE_NORMAL_BOOKMARK));
},
_hasField: function MSS__hasField(bookmarkID, fieldName) {