Merge the last PGO-green inbound changeset to m-c.

This commit is contained in:
Ryan VanderMeulen 2012-07-22 15:42:39 -04:00
Родитель bb2d75376a 99aa02e215
Коммит 4a7a1fccac
29 изменённых файлов: 414 добавлений и 506 удалений

Просмотреть файл

@ -48,4 +48,3 @@ DEPRECATED_OPERATION(DOMExceptionCode)
DEPRECATED_OPERATION(NoExposedProps)
DEPRECATED_OPERATION(MutationEvent)
DEPRECATED_OPERATION(MozSlice)
DEPRECATED_OPERATION(Onuploadprogress)

Просмотреть файл

@ -395,22 +395,8 @@ interface nsIXHRSendable : nsISupports {
/**
* @deprecated
*/
[deprecated, scriptable, uuid(423fdd3d-41c9-4149-8fe5-b14a1d3912a0)]
[deprecated, scriptable, uuid(8ae70a39-edf1-40b4-a992-472d23421c25)]
interface nsIJSXMLHttpRequest : nsISupports {
/**
* Meant to be a script-only mechanism for setting an upload progress event
* listener.
* This attribute should not be used from native code!!
* This event listener may be called multiple times during the upload..
*
* After the initial response, all event listeners will be cleared.
* // XXXbz what does that mean, exactly?
*
* This event listener must be set BEFORE calling open().
*
* Mozilla only.
*/
attribute nsIDOMEventListener onuploadprogress;
};
%{ C++

Просмотреть файл

@ -90,7 +90,6 @@ using namespace mozilla::dom;
#define TIMEOUT_STR "timeout"
#define LOADSTART_STR "loadstart"
#define PROGRESS_STR "progress"
#define UPLOADPROGRESS_STR "uploadprogress"
#define READYSTATE_STR "readystatechange"
#define LOADEND_STR "loadend"
@ -619,7 +618,6 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsXMLHttpRequest)
NS_UNMARK_LISTENER_WRAPPER(LoadStart)
NS_UNMARK_LISTENER_WRAPPER(Progress)
NS_UNMARK_LISTENER_WRAPPER(Loadend)
NS_UNMARK_LISTENER_WRAPPER(UploadProgress)
NS_UNMARK_LISTENER_WRAPPER(Readystatechange)
}
if (!isBlack && tmp->PreservingWrapper()) {
@ -645,7 +643,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLHttpRequest,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mResponseXML)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCORSPreflightChannel)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnUploadProgressListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnReadystatechangeListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mXMLParserStreamListener)
@ -667,7 +664,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXMLHttpRequest,
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mResponseXML)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCORSPreflightChannel)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnUploadProgressListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnReadystatechangeListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mXMLParserStreamListener)
@ -708,7 +704,6 @@ void
nsXMLHttpRequest::DisconnectFromOwner()
{
nsXHREventTarget::DisconnectFromOwner();
NS_DISCONNECT_EVENT_HANDLER(UploadProgress)
NS_DISCONNECT_EVENT_HANDLER(Readystatechange)
Abort();
}
@ -730,23 +725,6 @@ nsXMLHttpRequest::SetOnreadystatechange(nsIDOMEventListener * aOnreadystatechang
aOnreadystatechange);
}
NS_IMETHODIMP
nsXMLHttpRequest::GetOnuploadprogress(nsIDOMEventListener * *aOnuploadprogress)
{
return
nsXHREventTarget::GetInnerEventListener(mOnUploadProgressListener,
aOnuploadprogress);
}
NS_IMETHODIMP
nsXMLHttpRequest::SetOnuploadprogress(nsIDOMEventListener * aOnuploadprogress)
{
return
nsXHREventTarget::RemoveAddEventListener(NS_LITERAL_STRING(UPLOADPROGRESS_STR),
mOnUploadProgressListener,
aOnuploadprogress);
}
/* readonly attribute nsIChannel channel; */
NS_IMETHODIMP
nsXMLHttpRequest::GetChannel(nsIChannel **aChannel)
@ -1655,8 +1633,7 @@ nsXMLHttpRequest::DispatchProgressEvent(nsDOMEventTargetHelper* aTarget,
NS_ASSERTION(!aType.IsEmpty(), "missing event type");
if (NS_FAILED(CheckInnerWindowCorrectness()) ||
(!AllowUploadProgress() &&
(aTarget == mUpload || aType.EqualsLiteral(UPLOADPROGRESS_STR)))) {
(!AllowUploadProgress() && aTarget == mUpload)) {
return;
}
@ -1752,7 +1729,6 @@ nsXMLHttpRequest::CheckChannelForCrossSiteRequest(nsIChannel* aChannel)
nsCAutoString method;
httpChannel->GetRequestMethod(method);
if (!mCORSUnsafeHeaders.IsEmpty() ||
HasListenersFor(NS_LITERAL_STRING(UPLOADPROGRESS_STR)) ||
(mUpload && mUpload->HasListeners()) ||
(!method.LowerCaseEqualsLiteral("get") &&
!method.LowerCaseEqualsLiteral("post") &&
@ -2820,7 +2796,6 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
// a progress event handler we must load with nsIRequest::LOAD_NORMAL or
// necko won't generate any progress notifications.
if (HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR)) ||
HasListenersFor(NS_LITERAL_STRING(UPLOADPROGRESS_STR)) ||
(mUpload && mUpload->HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR)))) {
nsLoadFlags loadFlags;
mChannel->GetLoadFlags(&loadFlags);
@ -3179,9 +3154,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
// can run script that would try to restart this request, and that could end
// up doing our AsyncOpen on a null channel if the reentered AsyncOpen fails.
ChangeState(XML_HTTP_REQUEST_SENT);
if ((!mUploadComplete &&
HasListenersFor(NS_LITERAL_STRING(UPLOADPROGRESS_STR))) ||
(mUpload && mUpload->HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR)))) {
if (mUpload && mUpload->HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR))) {
StartProgressEventTimer();
}
DispatchProgressEvent(this, NS_LITERAL_STRING(LOADSTART_STR), false,
@ -3722,10 +3695,6 @@ nsXMLHttpRequest::MaybeDispatchProgressEvents(bool aFinalProgress)
mUploadProgressMax = mUploadProgress;
mUploadLengthComputable = true;
}
DispatchProgressEvent(this, NS_LITERAL_STRING(UPLOADPROGRESS_STR),
true, mUploadLengthComputable, mUploadTransferred,
mUploadTotal, mUploadProgress,
mUploadProgressMax);
if (mUpload && !mUploadComplete) {
DispatchProgressEvent(mUpload, NS_LITERAL_STRING(PROGRESS_STR),
true, mUploadLengthComputable, mUploadTransferred,

Просмотреть файл

@ -217,10 +217,6 @@ public:
// nsIXMLHttpRequest
NS_DECL_NSIXMLHTTPREQUEST
// nsIJSXMLHttpRequest
NS_IMETHOD GetOnuploadprogress(nsIDOMEventListener** aOnuploadprogress);
NS_IMETHOD SetOnuploadprogress(nsIDOMEventListener* aOnuploadprogress);
NS_FORWARD_NSIXMLHTTPREQUESTEVENTTARGET(nsXHREventTarget::)
// nsIStreamListener
@ -253,24 +249,6 @@ public:
// event handler
IMPL_EVENT_HANDLER(readystatechange, Readystatechange)
JSObject* GetOnuploadprogress(JSContext* /* unused */)
{
nsIDocument* doc = GetOwner() ? GetOwner()->GetExtantDoc() : NULL;
if (doc) {
doc->WarnOnceAbout(nsIDocument::eOnuploadprogress);
}
return GetListenerAsJSObject(mOnUploadProgressListener);
}
void SetOnuploadprogress(JSContext* aCx, JSObject* aCallback,
ErrorResult& aRv)
{
nsIDocument* doc = GetOwner() ? GetOwner()->GetExtantDoc() : NULL;
if (doc) {
doc->WarnOnceAbout(nsIDocument::eOnuploadprogress);
}
aRv = SetJSObjectListener(aCx, NS_LITERAL_STRING("uploadprogress"),
mOnUploadProgressListener, aCallback);
}
// states
uint16_t GetReadyState();
@ -577,7 +555,6 @@ protected:
nsCOMPtr<nsIChannel> mCORSPreflightChannel;
nsTArray<nsCString> mCORSUnsafeHeaders;
nsRefPtr<nsDOMEventListenerWrapper> mOnUploadProgressListener;
nsRefPtr<nsDOMEventListenerWrapper> mOnReadystatechangeListener;
nsCOMPtr<nsIStreamListener> mXMLParserStreamListener;

Просмотреть файл

@ -37,16 +37,9 @@ window.addEventListener("message", function(e) {
res.progressEvents++;
}, false);
if (req.uploadProgress) {
if (req.uploadProgress == "uploadProgress") {
xhr.addEventListener("uploadProgress", function(e) {
res.progressEvents++;
}, false);
}
else {
xhr.upload.addEventListener(req.uploadProgress, function(e) {
res.progressEvents++;
}, false);
}
xhr.upload.addEventListener(req.uploadProgress, function(e) {
res.progressEvents++;
}, false);
}
xhr.onerror = function(e) {
res.didFail = true;

Просмотреть файл

@ -26,16 +26,9 @@ window.addEventListener("message", function(e) {\n\
res.progressEvents++;\n\
}, false);\n\
if (req.uploadProgress) {\n\
if (req.uploadProgress == "uploadProgress") {\n\
xhr.addEventListener("uploadProgress", function(e) {\n\
res.progressEvents++;\n\
}, false);\n\
}\n\
else {\n\
xhr.upload.addEventListener(req.uploadProgress, function(e) {\n\
res.progressEvents++;\n\
}, false);\n\
}\n\
xhr.upload.addEventListener(req.uploadProgress, function(e) {\n\
res.progressEvents++;\n\
}, false);\n\
}\n\
xhr.onerror = function(e) {\n\
res.didFail = true;\n\

Просмотреть файл

@ -449,25 +449,12 @@ function runTest() {
},
// Progress events
{ pass: 1,
method: "POST",
body: "hi there",
headers: { "Content-Type": "text/plain" },
uploadProgress: "uploadprogress",
},
{ pass: 1,
method: "POST",
body: "hi there",
headers: { "Content-Type": "text/plain" },
uploadProgress: "progress",
},
{ pass: 0,
method: "POST",
body: "hi there",
headers: { "Content-Type": "text/plain" },
uploadProgress: "uploadprogress",
noAllowPreflight: 1,
},
{ pass: 0,
method: "POST",
body: "hi there",

Просмотреть файл

@ -27,12 +27,12 @@ function uploadprogress()
}
var xhr = new XMLHttpRequest();
xhr.onuploadprogress = uploadprogress;
xhr.upload.onprogress = uploadprogress;
var event = document.createEvent("ProgressEvent");
event.initProgressEvent("uploadprogress", false, false, false, false, 0);
xhr.dispatchEvent(event);
event.initProgressEvent("progress", false, false, false, false, 0);
xhr.upload.dispatchEvent(event);
ok(called,
"XMLHttpRequest.onuploadprogress sets uploadprogress event listener");
"XMLHttpRequest.upload.onprogress sets upload progress event listener");
</script>

Просмотреть файл

@ -105,7 +105,7 @@ function test(trusted, type, removeAddedListener, removeSetListener, allowUntrus
}
var events =
["load", "error", "progress", "uploadprogress", "readystatechange", "foo"];
["load", "error", "progress", "readystatechange", "foo"];
do {
var e = events.shift();

Просмотреть файл

@ -104,10 +104,6 @@ function start(obj) {
function (evt) {
logEvent(evt);
}
xhr.onuploadprogress =
function (evt) {
logEvent(evt);
}
if ("upload" in xhr) {
xhr.upload.onloadstart =
@ -277,7 +273,6 @@ var tests =
{ method: "POST", withUpload: small, testAbort: false, testRedirectError: false, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: UPLOAD, type: "load", optional: false},
{target: UPLOAD, type: "loadend", optional: false},
@ -294,7 +289,6 @@ var tests =
{ method: "POST", withUpload: small, testAbort: false, testRedirectError: true, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},
@ -303,7 +297,6 @@ var tests =
{ method: "POST", withUpload: small, testAbort: false, testRedirectError: false, testNetworkError: true,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},
@ -313,7 +306,6 @@ var tests =
{ method: "POST", withUpload: mid, testAbort: false, testRedirectError: false, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: UPLOAD, type: "load", optional: false},
{target: UPLOAD, type: "loadend", optional: false},
@ -330,7 +322,6 @@ var tests =
{ method: "POST", withUpload: mid, testAbort: false, testRedirectError: true, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},
@ -339,7 +330,6 @@ var tests =
{ method: "POST", withUpload: mid, testAbort: false, testRedirectError: false, testNetworkError: true,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},
@ -349,7 +339,6 @@ var tests =
{ method: "POST", withUpload: large, testAbort: false, testRedirectError: false, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: UPLOAD, type: "load", optional: false},
{target: UPLOAD, type: "loadend", optional: false},
@ -366,7 +355,6 @@ var tests =
{ method: "POST", withUpload: large, testAbort: false, testRedirectError: true, testNetworkError: false,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},
@ -375,7 +363,6 @@ var tests =
{ method: "POST", withUpload: large, testAbort: false, testRedirectError: false, testNetworkError: true,
expectedEvents: [{target: XHR, type: "loadstart", optional: false},
{target: UPLOAD, type: "loadstart", optional: false},
{target: XHR, type: "uploadprogress", optional: true},
{target: UPLOAD, type: "progress", optional: true},
{target: XHR, type: "error", optional: false},
{target: XHR, type: "loadend", optional: false},

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsNetUtil.h"
#include "nsXPCOMCIDInternal.h"
#include "nsIXULRuntime.h"
#include "nsScriptLoader.h"
#include "xpcpublic.h"
@ -3866,7 +3867,7 @@ NS_DOMStructuredCloneError(JSContext* cx,
}
static nsresult
ReadSourceFromFilename(JSContext *cx, const char *filename, char **buf, PRUint32 *len)
ReadSourceFromFilename(JSContext *cx, const char *filename, jschar **src, PRUint32 *len)
{
nsresult rv;
@ -3893,40 +3894,48 @@ ReadSourceFromFilename(JSContext *cx, const char *filename, char **buf, PRUint32
rv = scriptChannel->Open(getter_AddRefs(scriptStream));
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptStream->Available(len);
PRUint32 rawLen;
rv = scriptStream->Available(&rawLen);
NS_ENSURE_SUCCESS(rv, rv);
if (!*len)
if (!rawLen)
return NS_ERROR_FAILURE;
// Allocate an internal buf the size of the file.
*buf = static_cast<char *>(JS_malloc(cx, *len + 1));
if (!*buf)
nsAutoArrayPtr<unsigned char> buf(new unsigned char[rawLen]);
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;
char *ptr = *buf, *end = ptr + *len;
unsigned char *ptr = buf, *end = ptr + rawLen;
while (ptr < end) {
PRUint32 bytesRead;
rv = scriptStream->Read(ptr, end - ptr, &bytesRead);
if (NS_FAILED(rv)) {
JS_free(cx, *buf);
rv = scriptStream->Read(reinterpret_cast<char *>(ptr), end - ptr, &bytesRead);
if (NS_FAILED(rv))
return rv;
}
NS_ASSERTION(bytesRead > 0, "stream promised more bytes before EOF");
ptr += bytesRead;
}
*end = '\0';
nsString decoded;
rv = nsScriptLoader::ConvertToUTF16(scriptChannel, buf, rawLen, EmptyString(), NULL, decoded);
NS_ENSURE_SUCCESS(rv, rv);
// Copy to JS engine.
*len = decoded.Length();
*src = static_cast<jschar *>(JS_malloc(cx, decoded.Length()*sizeof(jschar)));
if (!*src)
return NS_ERROR_FAILURE;
memcpy(*src, decoded.get(), decoded.Length()*sizeof(jschar));
return NS_OK;
}
/*
The JS engine calls this function when it needs the source for a chrome JS
function. See the comment in nsJSContext::nsJSContext about
JSOPTION_ONLY_CGN_SOURCE.
*/
static bool
SourceHook(JSContext *cx, JSScript *script, char **src, uint32_t *length)
SourceHook(JSContext *cx, JSScript *script, jschar **src, uint32_t *length)
{
*src = NULL;
*length = 0;

Просмотреть файл

@ -133,4 +133,3 @@ NoExposedPropsWarning=Exposing chrome JS objects to content without __exposedPro
MutationEventWarning=Use of Mutation Events is deprecated. Use MutationObserver instead.
# LOCALIZATION NOTE: Do not translate "Blob", "mozSlice", or "slice"
MozSliceWarning=Use of mozSlice on the Blob object is deprecated. Use slice instead.
OnuploadprogressWarning=Use of XMLHttpRequest's onuploadprogress attribute is deprecated.

Просмотреть файл

@ -127,9 +127,6 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
void sendAsBinary(DOMString body);
any getInterface(IID iid);
[TreatNonCallableAsNull, GetterInfallible=MainThread]
attribute Function? onuploadprogress;
[Infallible]
readonly attribute boolean mozAnon;

Просмотреть файл

@ -97,18 +97,6 @@ public:
#undef IMPL_GETTER_AND_SETTER
JSObject*
GetOnuploadprogress(JSContext* /* unused */, ErrorResult& aRv)
{
aRv = NS_ERROR_NOT_IMPLEMENTED;
return NULL;
}
void
SetOnuploadprogress(JSContext* /* unused */, JSObject* aListener, ErrorResult& aRv)
{
aRv = NS_ERROR_NOT_IMPLEMENTED;
}
uint16_t
GetReadyState() const
{

Просмотреть файл

@ -668,11 +668,10 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
// make sure we don't end up with selection collapsed after an invisible break node
nsWSRunObject wsRunObj(this, selNode, selOffset);
PRInt32 outVisOffset=0;
PRInt16 visType=0;
WSType visType;
wsRunObj.PriorVisibleNode(selNode, selOffset, address_of(visNode),
&outVisOffset, &visType);
if (visType == nsWSRunObject::eBreak)
{
if (visType == WSType::br) {
// we are after a break. Is it visible? Despite the name,
// PriorVisibleNode does not make that determination for breaks.
// It also may not return the break in visNode. We have to pull it
@ -686,14 +685,10 @@ nsHTMLEditor::DoInsertHTMLWithContext(const nsAString & aInputString,
nsWSRunObject wsRunObj(this, selNode, selOffset);
wsRunObj.PriorVisibleNode(selNode, selOffset, address_of(visNode),
&outVisOffset, &visType);
if (visType == nsWSRunObject::eText ||
visType == nsWSRunObject::eNormalWS)
{
if (visType == WSType::text || visType == WSType::normalWS) {
selNode = visNode;
selOffset = outVisOffset; // PriorVisibleNode already set offset to _after_ the text or ws
}
else if (visType == nsWSRunObject::eSpecial)
{
} else if (visType == WSType::special) {
// prior visible thing is an image or some other non-text thingy.
// We want to be right after it.
selNode = GetNodeLocation(wsRunObj.mStartReasonNode, &selOffset);

Просмотреть файл

@ -1598,15 +1598,15 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode* aNode, PRInt32 aOffset,
nsWSRunObject wsObj(mHTMLEditor, node, aOffset);
nsCOMPtr<nsIDOMNode> visNode, linkNode;
PRInt32 visOffset = 0, newOffset;
PRInt16 wsType;
WSType wsType;
wsObj.PriorVisibleNode(node, aOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType & nsWSRunObject::eBlock) {
if (wsType & WSType::block) {
bAfterBlock = true;
}
wsObj.NextVisibleNode(node, aOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType & nsWSRunObject::eBlock) {
if (wsType & WSType::block) {
bBeforeBlock = true;
}
if (mHTMLEditor->IsInLink(node, address_of(linkNode))) {
@ -1637,10 +1637,10 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode* aNode, PRInt32 aOffset,
nsWSRunObject wsObj(mHTMLEditor, node, aOffset+1);
nsCOMPtr<nsIDOMNode> secondBR;
PRInt32 visOffset = 0;
PRInt16 wsType;
WSType wsType;
wsObj.NextVisibleNode(node, aOffset+1, address_of(secondBR),
&visOffset, &wsType);
if (wsType == nsWSRunObject::eBreak) {
if (wsType == WSType::br) {
// the next thing after the break we inserted is another break. Move
// the 2nd break to be the first breaks sibling. This will prevent them
// from being in different inline nodes, which would break
@ -1704,11 +1704,10 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, bool aPlaintext, bool
nsWSRunObject wsObj(mHTMLEditor, selNode, selOffset);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset=0;
PRInt16 wsType;
WSType wsType;
wsObj.NextVisibleNode(selNode, selOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType==nsWSRunObject::eBreak)
{
if (wsType == WSType::br) {
// ok, we are just before a break. is it inside the mailquote?
PRInt32 unused;
if (nsEditorUtils::IsDescendantOf(visNode, citeNode, &unused))
@ -1740,20 +1739,16 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, bool aPlaintext, bool
nsWSRunObject wsObj(mHTMLEditor, selNode, newOffset);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset=0;
PRInt16 wsType;
WSType wsType;
wsObj.PriorVisibleNode(selNode, newOffset, address_of(visNode),
&visOffset, &wsType);
if ((wsType==nsWSRunObject::eNormalWS) ||
(wsType==nsWSRunObject::eText) ||
(wsType==nsWSRunObject::eSpecial))
{
if (wsType == WSType::normalWS || wsType == WSType::text ||
wsType == WSType::special) {
nsWSRunObject wsObjAfterBR(mHTMLEditor, selNode, newOffset+1);
wsObjAfterBR.NextVisibleNode(selNode, newOffset+1, address_of(visNode),
&visOffset, &wsType);
if ((wsType==nsWSRunObject::eNormalWS) ||
(wsType==nsWSRunObject::eText) ||
(wsType==nsWSRunObject::eSpecial))
{
if (wsType == WSType::normalWS || wsType == WSType::text ||
wsType == WSType::special) {
res = mHTMLEditor->CreateBR(selNode, newOffset, address_of(brNode));
NS_ENSURE_SUCCESS(res, res);
}
@ -1869,7 +1864,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
nsWSRunObject wsObj(mHTMLEditor, startNode, startOffset);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset;
PRInt16 wsType;
WSType wsType;
// find next visible node
if (aAction == nsIEditor::eNext)
@ -1885,8 +1880,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
return res;
}
if (wsType==nsWSRunObject::eNormalWS)
{
if (wsType == WSType::normalWS) {
// we found some visible ws to delete. Let ws code handle it.
if (aAction == nsIEditor::eNext)
res = wsObj.DeleteWSForward();
@ -1896,9 +1890,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
return res;
}
else if (wsType==nsWSRunObject::eText)
{
} else if (wsType == WSType::text) {
// found normal text to delete.
PRInt32 so = visOffset;
PRInt32 eo = visOffset+1;
@ -1939,11 +1931,8 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
return res;
}
else if ( (wsType==nsWSRunObject::eSpecial) ||
(wsType==nsWSRunObject::eBreak) ||
nsHTMLEditUtils::IsHR(visNode) )
{
} else if (wsType == WSType::special || wsType == WSType::br ||
nsHTMLEditUtils::IsHR(visNode)) {
// short circuit for invisible breaks. delete them and recurse.
if (nsTextEditUtils::IsBreak(visNode) && !mHTMLEditor->IsVisBreak(visNode))
{
@ -2005,15 +1994,14 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
// There is one exception to the move only case.
// If the <hr> is followed by a <br> we want to delete the <br>.
PRInt16 otherWSType;
WSType otherWSType;
nsCOMPtr<nsIDOMNode> otherNode;
PRInt32 otherOffset;
wsObj.NextVisibleNode(startNode, startOffset, address_of(otherNode),
&otherOffset, &otherWSType);
if (otherWSType == nsWSRunObject::eBreak)
{
if (otherWSType == WSType::br) {
// Delete the <br>
res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, otherNode);
@ -2056,9 +2044,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
return res;
}
else if (wsType==nsWSRunObject::eOtherBlock)
{
} else if (wsType == WSType::otherBlock) {
// make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
if (nsHTMLEditUtils::IsTableElement(visNode))
@ -2071,7 +2057,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
// want to delete the br. Else join content at selection to the block.
bool bDeletedBR = false;
PRInt16 otherWSType;
WSType otherWSType;
nsCOMPtr<nsIDOMNode> otherNode;
PRInt32 otherOffset;
@ -2154,9 +2140,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
}
aSelection->Collapse(selPointNode, selPointOffset);
return res;
}
else if (wsType==nsWSRunObject::eThisBlock)
{
} else if (wsType == WSType::thisBlock) {
// at edge of our block. Look beside it and see if we can join to an adjacent block
// make sure it's not a table element. If so, cancel the operation
@ -2480,9 +2464,9 @@ nsHTMLEditRules::InsertBRIfNeeded(nsISelection *aSelection)
// examine selection
nsWSRunObject wsObj(mHTMLEditor, node, offset);
if (((wsObj.mStartReason & nsWSRunObject::eBlock) || (wsObj.mStartReason & nsWSRunObject::eBreak))
&& (wsObj.mEndReason & nsWSRunObject::eBlock))
{
if (((wsObj.mStartReason & WSType::block) ||
(wsObj.mStartReason & WSType::br)) &&
(wsObj.mEndReason & WSType::block)) {
// if we are tucked between block boundaries then insert a br
// first check that we are allowed to
if (mHTMLEditor->CanContainTag(node, nsGkAtoms::br)) {
@ -2834,10 +2818,8 @@ nsHTMLEditRules::DeleteNonTableElements(nsINode* aNode)
return mHTMLEditor->DeleteNode(aNode->AsDOMNode());
}
for (nsCOMPtr<nsIContent> child = aNode->GetLastChild();
child;
child = child->GetPreviousSibling()) {
nsresult rv = DeleteNonTableElements(child);
for (PRInt32 i = aNode->GetChildCount() - 1; i >= 0; --i) {
nsresult rv = DeleteNonTableElements(aNode->GetChildAt(i));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
@ -4868,8 +4850,7 @@ nsHTMLEditRules::CheckForInvisibleBR(nsIDOMNode *aBlock,
if (runTest)
{
nsWSRunObject wsTester(mHTMLEditor, testNode, testOffset);
if (nsWSRunObject::eBreak == wsTester.mStartReason)
{
if (WSType::br == wsTester.mStartReason) {
*outBRNode = wsTester.mStartReasonNode;
}
}
@ -4965,7 +4946,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
bool stillLooking = true;
nsCOMPtr<nsIDOMNode> visNode, firstBRParent;
PRInt32 visOffset=0, firstBROffset=0;
PRInt16 wsType;
WSType wsType;
nsCOMPtr<nsIContent> rootContent = mHTMLEditor->GetActiveEditingHost();
nsCOMPtr<nsIDOMNode> rootElement = do_QueryInterface(rootContent);
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
@ -4978,8 +4959,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
nsWSRunObject wsObj(mHTMLEditor, selStartNode, selStartOffset);
wsObj.PriorVisibleNode(selStartNode, selStartOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType == nsWSRunObject::eThisBlock)
{
if (wsType == WSType::thisBlock) {
// we want to keep looking up. But stop if we are crossing table element
// boundaries, or if we hit the root.
if ( nsHTMLEditUtils::IsTableElement(wsObj.mStartReasonNode) ||
@ -5010,8 +4990,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
nsWSRunObject wsObj(mHTMLEditor, selEndNode, selEndOffset);
wsObj.NextVisibleNode(selEndNode, selEndOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType == nsWSRunObject::eBreak)
{
if (wsType == WSType::br) {
if (mHTMLEditor->IsVisBreak(wsObj.mEndReasonNode))
{
stillLooking = false;
@ -5026,9 +5005,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
selEndNode = nsEditor::GetNodeLocation(wsObj.mEndReasonNode, &selEndOffset);
++selEndOffset;
}
}
else if (wsType == nsWSRunObject::eThisBlock)
{
} else if (wsType == WSType::thisBlock) {
// we want to keep looking up. But stop if we are crossing table element
// boundaries, or if we hit the root.
if ( nsHTMLEditUtils::IsTableElement(wsObj.mEndReasonNode) ||
@ -5144,7 +5121,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
// some locals we need for whitespace code
nsCOMPtr<nsIDOMNode> someNode;
PRInt32 offset;
PRInt16 wsType;
WSType wsType;
// let the whitespace code do the heavy lifting
nsWSRunObject wsEndObj(mHTMLEditor, endNode, endOffset);
@ -5152,12 +5129,10 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
// it would visibly change maening of users selection
wsEndObj.PriorVisibleNode(endNode, endOffset, address_of(someNode),
&offset, &wsType);
if ((wsType != nsWSRunObject::eText) && (wsType != nsWSRunObject::eNormalWS))
{
if (wsType != WSType::text && wsType != WSType::normalWS) {
// eThisBlock and eOtherBlock conveniently distinquish cases
// of going "down" into a block and "up" out of a block.
if (wsEndObj.mStartReason == nsWSRunObject::eOtherBlock)
{
if (wsEndObj.mStartReason == WSType::otherBlock) {
// endpoint is just after the close of a block.
nsCOMPtr<nsIDOMNode> child = mHTMLEditor->GetRightmostChild(wsEndObj.mStartReasonNode, true);
if (child)
@ -5166,9 +5141,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
++newEndOffset; // offset *after* child
}
// else block is empty - we can leave selection alone here, i think.
}
else if (wsEndObj.mStartReason == nsWSRunObject::eThisBlock)
{
} else if (wsEndObj.mStartReason == WSType::thisBlock) {
// endpoint is just after start of this block
nsCOMPtr<nsIDOMNode> child;
res = mHTMLEditor->GetPriorHTMLNode(endNode, endOffset, address_of(child));
@ -5178,9 +5151,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
++newEndOffset; // offset *after* child
}
// else block is empty - we can leave selection alone here, i think.
}
else if (wsEndObj.mStartReason == nsWSRunObject::eBreak)
{
} else if (wsEndObj.mStartReason == WSType::br) {
// endpoint is just after break. lets adjust it to before it.
newEndNode = nsEditor::GetNodeLocation(wsEndObj.mStartReasonNode,
&newEndOffset);
@ -5194,12 +5165,10 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
// it would visibly change maening of users selection
wsStartObj.NextVisibleNode(startNode, startOffset, address_of(someNode),
&offset, &wsType);
if ((wsType != nsWSRunObject::eText) && (wsType != nsWSRunObject::eNormalWS))
{
if (wsType != WSType::text && wsType != WSType::normalWS) {
// eThisBlock and eOtherBlock conveniently distinquish cases
// of going "down" into a block and "up" out of a block.
if (wsStartObj.mEndReason == nsWSRunObject::eOtherBlock)
{
if (wsStartObj.mEndReason == WSType::otherBlock) {
// startpoint is just before the start of a block.
nsCOMPtr<nsIDOMNode> child = mHTMLEditor->GetLeftmostChild(wsStartObj.mEndReasonNode, true);
if (child)
@ -5207,9 +5176,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
newStartNode = nsEditor::GetNodeLocation(child, &newStartOffset);
}
// else block is empty - we can leave selection alone here, i think.
}
else if (wsStartObj.mEndReason == nsWSRunObject::eThisBlock)
{
} else if (wsStartObj.mEndReason == WSType::thisBlock) {
// startpoint is just before end of this block
nsCOMPtr<nsIDOMNode> child;
res = mHTMLEditor->GetNextHTMLNode(startNode, startOffset, address_of(child));
@ -5218,9 +5185,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
newStartNode = nsEditor::GetNodeLocation(child, &newStartOffset);
}
// else block is empty - we can leave selection alone here, i think.
}
else if (wsStartObj.mEndReason == nsWSRunObject::eBreak)
{
} else if (wsStartObj.mEndReason == WSType::br) {
// startpoint is just before a break. lets adjust it to after it.
newStartNode = nsEditor::GetNodeLocation(wsStartObj.mEndReasonNode,
&newStartOffset);
@ -6633,13 +6598,11 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
nsWSRunObject wsObj(mHTMLEditor, aListItem, 0);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset = 0;
PRInt16 wsType;
WSType wsType;
wsObj.NextVisibleNode(aListItem, 0, address_of(visNode),
&visOffset, &wsType);
if ( (wsType==nsWSRunObject::eSpecial) ||
(wsType==nsWSRunObject::eBreak) ||
nsHTMLEditUtils::IsHR(visNode) )
{
if (wsType == WSType::special || wsType == WSType::br ||
nsHTMLEditUtils::IsHR(visNode)) {
PRInt32 offset;
nsCOMPtr<nsIDOMNode> parent = nsEditor::GetNodeLocation(visNode, &offset);
return aSelection->Collapse(parent, offset);

Просмотреть файл

@ -516,23 +516,16 @@ nsHTMLEditor::BeginningOfDocument()
nsWSRunObject wsObj(this, curNode, curOffset);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset=0;
PRInt16 visType=0;
WSType visType;
wsObj.NextVisibleNode(curNode, curOffset, address_of(visNode), &visOffset, &visType);
if ((visType==nsWSRunObject::eNormalWS) ||
(visType==nsWSRunObject::eText))
{
if (visType == WSType::normalWS || visType == WSType::text) {
selNode = visNode;
selOffset = visOffset;
done = true;
}
else if ((visType==nsWSRunObject::eBreak) ||
(visType==nsWSRunObject::eSpecial))
{
} else if (visType == WSType::br || visType == WSType::special) {
selNode = GetNodeLocation(visNode, &selOffset);
done = true;
}
else if (visType==nsWSRunObject::eOtherBlock)
{
} else if (visType == WSType::otherBlock) {
// By definition of nsWSRunObject, a block element terminates
// a whitespace run. That is, although we are calling a method
// that is named "NextVisibleNode", the node returned
@ -950,10 +943,11 @@ bool nsHTMLEditor::IsVisBreak(nsIDOMNode *aNode)
nsWSRunObject wsObj(this, selNode, selOffset);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 visOffset=0;
PRInt16 visType=0;
WSType visType;
wsObj.NextVisibleNode(selNode, selOffset, address_of(visNode), &visOffset, &visType);
if (visType & nsWSRunObject::eBlock)
if (visType & WSType::block) {
return false;
}
return true;
}
@ -1451,26 +1445,29 @@ nsHTMLEditor::NormalizeEOLInsertPosition(nsIDOMNode *firstNodeToInsert,
nsCOMPtr<nsIDOMNode> nextVisNode;
nsCOMPtr<nsIDOMNode> prevVisNode;
PRInt32 nextVisOffset=0;
PRInt16 nextVisType=0;
WSType nextVisType;
PRInt32 prevVisOffset=0;
PRInt16 prevVisType=0;
WSType prevVisType;
wsObj.NextVisibleNode(*insertParentNode, *insertOffset, address_of(nextVisNode), &nextVisOffset, &nextVisType);
if (!nextVisNode)
return;
if (! (nextVisType & nsWSRunObject::eBreak))
if (!(nextVisType & WSType::br)) {
return;
}
wsObj.PriorVisibleNode(*insertParentNode, *insertOffset, address_of(prevVisNode), &prevVisOffset, &prevVisType);
if (!prevVisNode)
return;
if (prevVisType & nsWSRunObject::eBreak)
if (prevVisType & WSType::br) {
return;
}
if (prevVisType & nsWSRunObject::eThisBlock)
if (prevVisType & WSType::thisBlock) {
return;
}
PRInt32 brOffset=0;
nsCOMPtr<nsIDOMNode> brNode = GetNodeLocation(nextVisNode, &brOffset);
@ -4399,12 +4396,10 @@ nsHTMLEditor::IsVisTextNode(nsIContent* aNode,
nsWSRunObject wsRunObj(this, node, 0);
nsCOMPtr<nsIDOMNode> visNode;
PRInt32 outVisOffset=0;
PRInt16 visType=0;
WSType visType;
wsRunObj.NextVisibleNode(node, 0, address_of(visNode),
&outVisOffset, &visType);
if ( (visType == nsWSRunObject::eNormalWS) ||
(visType == nsWSRunObject::eText) )
{
if (visType == WSType::normalWS || visType == WSType::text) {
*outIsEmptyNode = (node != visNode);
}
}

Просмотреть файл

@ -41,11 +41,11 @@ mNode(aNode)
,mPRE(false)
,mStartNode()
,mStartOffset(0)
,mStartReason(0)
,mStartReason()
,mStartReasonNode()
,mEndNode()
,mEndOffset(0)
,mEndReason(0)
,mEndReason()
,mEndReasonNode()
,mFirstNBSPNode()
,mFirstNBSPOffset(0)
@ -175,25 +175,18 @@ nsWSRunObject::InsertBreak(nsCOMPtr<nsIDOMNode> *aInOutParent,
nsAutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater, aInOutParent, aInOutOffset);
// handle any changes needed to ws run after inserted br
if (!afterRun)
{
if (!afterRun) {
// don't need to do anything. just insert break. ws won't change.
}
else if (afterRun->mType & eTrailingWS)
{
} else if (afterRun->mType & WSType::trailingWS) {
// don't need to do anything. just insert break. ws won't change.
}
else if (afterRun->mType & eLeadingWS)
{
} else if (afterRun->mType & WSType::leadingWS) {
// delete the leading ws that is after insertion point. We don't
// have to (it would still not be significant after br), but it's
// just more aesthetically pleasing to.
res = DeleteChars(*aInOutParent, *aInOutOffset, afterRun->mEndNode, afterRun->mEndOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
else if (afterRun->mType == eNormalWS)
{
} else if (afterRun->mType == WSType::normalWS) {
// need to determine if break at front of non-nbsp run. if so
// convert run to nbsp.
WSPoint thePoint = GetCharAfter(*aInOutParent, *aInOutOffset);
@ -208,24 +201,17 @@ nsWSRunObject::InsertBreak(nsCOMPtr<nsIDOMNode> *aInOutParent,
}
// handle any changes needed to ws run before inserted br
if (!beforeRun)
{
if (!beforeRun) {
// don't need to do anything. just insert break. ws won't change.
}
else if (beforeRun->mType & eLeadingWS)
{
} else if (beforeRun->mType & WSType::leadingWS) {
// don't need to do anything. just insert break. ws won't change.
}
else if (beforeRun->mType & eTrailingWS)
{
} else if (beforeRun->mType & WSType::trailingWS) {
// need to delete the trailing ws that is before insertion point, because it
// would become significant after break inserted.
res = DeleteChars(beforeRun->mStartNode, beforeRun->mStartOffset, *aInOutParent, *aInOutOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
else if (beforeRun->mType == eNormalWS)
{
} else if (beforeRun->mType == WSType::normalWS) {
// try to change an nbsp to a space, if possible, just to prevent nbsp proliferation
res = CheckTrailingNBSP(beforeRun, *aInOutParent, *aInOutOffset);
NS_ENSURE_SUCCESS(res, res);
@ -267,48 +253,34 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert,
nsAutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater, aInOutParent, aInOutOffset);
// handle any changes needed to ws run after inserted text
if (!afterRun)
{
if (!afterRun) {
// don't need to do anything. just insert text. ws won't change.
}
else if (afterRun->mType & eTrailingWS)
{
} else if (afterRun->mType & WSType::trailingWS) {
// don't need to do anything. just insert text. ws won't change.
}
else if (afterRun->mType & eLeadingWS)
{
} else if (afterRun->mType & WSType::leadingWS) {
// delete the leading ws that is after insertion point, because it
// would become significant after text inserted.
res = DeleteChars(*aInOutParent, *aInOutOffset, afterRun->mEndNode, afterRun->mEndOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
else if (afterRun->mType == eNormalWS)
{
} else if (afterRun->mType == WSType::normalWS) {
// try to change an nbsp to a space, if possible, just to prevent nbsp proliferation
res = CheckLeadingNBSP(afterRun, *aInOutParent, *aInOutOffset);
NS_ENSURE_SUCCESS(res, res);
}
// handle any changes needed to ws run before inserted text
if (!beforeRun)
{
if (!beforeRun) {
// don't need to do anything. just insert text. ws won't change.
}
else if (beforeRun->mType & eLeadingWS)
{
} else if (beforeRun->mType & WSType::leadingWS) {
// don't need to do anything. just insert text. ws won't change.
}
else if (beforeRun->mType & eTrailingWS)
{
} else if (beforeRun->mType & WSType::trailingWS) {
// need to delete the trailing ws that is before insertion point, because it
// would become significant after text inserted.
res = DeleteChars(beforeRun->mStartNode, beforeRun->mStartOffset, *aInOutParent, *aInOutOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
else if (beforeRun->mType == eNormalWS)
{
} else if (beforeRun->mType == WSType::normalWS) {
// try to change an nbsp to a space, if possible, just to prevent nbsp proliferation
res = CheckTrailingNBSP(beforeRun, *aInOutParent, *aInOutOffset);
NS_ENSURE_SUCCESS(res, res);
@ -323,24 +295,17 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert,
if (nsCRT::IsAsciiSpace(theString[0]))
{
// we have a leading space
if (beforeRun)
{
if (beforeRun->mType & eLeadingWS)
{
if (beforeRun) {
if (beforeRun->mType & WSType::leadingWS) {
theString.SetCharAt(nbsp, 0);
}
else if (beforeRun->mType & eNormalWS)
{
} else if (beforeRun->mType & WSType::normalWS) {
WSPoint wspoint = GetCharBefore(*aInOutParent, *aInOutOffset);
if (wspoint.mTextNode && nsCRT::IsAsciiSpace(wspoint.mChar)) {
theString.SetCharAt(nbsp, 0);
}
}
}
else
{
if ((mStartReason & eBlock) || (mStartReason == eBreak))
{
} else {
if (mStartReason & WSType::block || mStartReason == WSType::br) {
theString.SetCharAt(nbsp, 0);
}
}
@ -354,12 +319,9 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert,
// we have a leading space
if (afterRun)
{
if (afterRun->mType & eTrailingWS)
{
if (afterRun->mType & WSType::trailingWS) {
theString.SetCharAt(nbsp, lastCharIndex);
}
else if (afterRun->mType & eNormalWS)
{
} else if (afterRun->mType & WSType::normalWS) {
WSPoint wspoint = GetCharAfter(*aInOutParent, *aInOutOffset);
if (wspoint.mTextNode && nsCRT::IsAsciiSpace(wspoint.mChar)) {
theString.SetCharAt(nbsp, lastCharIndex);
@ -368,8 +330,7 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert,
}
else
{
if ((mEndReason & eBlock))
{
if (mEndReason & WSType::block) {
theString.SetCharAt(nbsp, lastCharIndex);
}
}
@ -514,21 +475,20 @@ nsWSRunObject::PriorVisibleNode(nsIDOMNode *aNode,
PRInt32 aOffset,
nsCOMPtr<nsIDOMNode> *outVisNode,
PRInt32 *outVisOffset,
PRInt16 *outType)
WSType *outType)
{
// Find first visible thing before the point. position outVisNode/outVisOffset
// just _after_ that thing. If we don't find anything return start of ws.
MOZ_ASSERT(aNode && outVisNode && outVisOffset && outType);
*outType = eNone;
*outType = WSType::none;
WSFragment *run;
FindRun(aNode, aOffset, &run, false);
// is there a visible run there or earlier?
while (run)
{
if (run->mType == eNormalWS)
{
if (run->mType == WSType::normalWS) {
WSPoint point = GetCharBefore(aNode, aOffset);
if (point.mTextNode)
{
@ -536,16 +496,16 @@ nsWSRunObject::PriorVisibleNode(nsIDOMNode *aNode,
*outVisOffset = point.mOffset+1;
if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar==nbsp))
{
*outType = eNormalWS;
*outType = WSType::normalWS;
}
else if (!point.mChar)
{
// MOOSE: not possible?
*outType = eNone;
*outType = WSType::none;
}
else
{
*outType = eText;
*outType = WSType::text;
}
return;
}
@ -567,7 +527,7 @@ nsWSRunObject::NextVisibleNode (nsIDOMNode *aNode,
PRInt32 aOffset,
nsCOMPtr<nsIDOMNode> *outVisNode,
PRInt32 *outVisOffset,
PRInt16 *outType)
WSType *outType)
{
// Find first visible thing after the point. position outVisNode/outVisOffset
// just _before_ that thing. If we don't find anything return end of ws.
@ -579,8 +539,7 @@ nsWSRunObject::NextVisibleNode (nsIDOMNode *aNode,
// is there a visible run there or later?
while (run)
{
if (run->mType == eNormalWS)
{
if (run->mType == WSType::normalWS) {
WSPoint point = GetCharAfter(aNode, aOffset);
if (point.mTextNode)
{
@ -588,16 +547,16 @@ nsWSRunObject::NextVisibleNode (nsIDOMNode *aNode,
*outVisOffset = point.mOffset;
if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar==nbsp))
{
*outType = eNormalWS;
*outType = WSType::normalWS;
}
else if (!point.mChar)
{
// MOOSE: not possible?
*outType = eNone;
*outType = WSType::none;
}
else
{
*outType = eText;
*outType = WSType::text;
}
return;
}
@ -628,8 +587,7 @@ nsWSRunObject::AdjustWhitespace()
while (curRun)
{
// look for normal ws run
if (curRun->mType == eNormalWS)
{
if (curRun->mType == WSType::normalWS) {
res = CheckTrailingNBSPOfRun(curRun);
break;
}
@ -696,7 +654,7 @@ nsWSRunObject::GetWSNodes()
{
mStartNode = mNode;
mStartOffset = pos+1;
mStartReason = eText;
mStartReason = WSType::text;
mStartReasonNode = mNode;
break;
}
@ -726,7 +684,7 @@ nsWSRunObject::GetWSNodes()
if (IsBlockNode(priorNode))
{
start.GetPoint(mStartNode, mStartOffset);
mStartReason = eOtherBlock;
mStartReason = WSType::otherBlock;
mStartReasonNode = priorNode;
}
else if (mHTMLEditor->IsTextNode(priorNode))
@ -764,7 +722,7 @@ nsWSRunObject::GetWSNodes()
{
mStartNode = priorNode;
mStartOffset = pos+1;
mStartReason = eText;
mStartReason = WSType::text;
mStartReasonNode = priorNode;
break;
}
@ -788,9 +746,9 @@ nsWSRunObject::GetWSNodes()
// a break but still serves as a terminator to ws runs.
start.GetPoint(mStartNode, mStartOffset);
if (nsTextEditUtils::IsBreak(priorNode))
mStartReason = eBreak;
mStartReason = WSType::br;
else
mStartReason = eSpecial;
mStartReason = WSType::special;
mStartReasonNode = priorNode;
}
}
@ -798,7 +756,7 @@ nsWSRunObject::GetWSNodes()
{
// no prior node means we exhausted wsBoundingParent
start.GetPoint(mStartNode, mStartOffset);
mStartReason = eThisBlock;
mStartReason = WSType::thisBlock;
mStartReasonNode = wsBoundingParent;
}
}
@ -829,7 +787,7 @@ nsWSRunObject::GetWSNodes()
{
mEndNode = mNode;
mEndOffset = pos;
mEndReason = eText;
mEndReason = WSType::text;
mEndReasonNode = mNode;
break;
}
@ -860,7 +818,7 @@ nsWSRunObject::GetWSNodes()
{
// we encountered a new block. therefore no more ws.
end.GetPoint(mEndNode, mEndOffset);
mEndReason = eOtherBlock;
mEndReason = WSType::otherBlock;
mEndReasonNode = nextNode;
}
else if (mHTMLEditor->IsTextNode(nextNode))
@ -898,7 +856,7 @@ nsWSRunObject::GetWSNodes()
{
mEndNode = nextNode;
mEndOffset = pos;
mEndReason = eText;
mEndReason = WSType::text;
mEndReasonNode = nextNode;
break;
}
@ -923,9 +881,9 @@ nsWSRunObject::GetWSNodes()
// serves as a terminator to ws runs.
end.GetPoint(mEndNode, mEndOffset);
if (nsTextEditUtils::IsBreak(nextNode))
mEndReason = eBreak;
mEndReason = WSType::br;
else
mEndReason = eSpecial;
mEndReason = WSType::special;
mEndReasonNode = nextNode;
}
}
@ -933,7 +891,7 @@ nsWSRunObject::GetWSNodes()
{
// no next node means we exhausted wsBoundingParent
end.GetPoint(mEndNode, mEndOffset);
mEndReason = eThisBlock;
mEndReason = WSType::thisBlock;
mEndReasonNode = wsBoundingParent;
}
}
@ -950,23 +908,26 @@ nsWSRunObject::GetRuns()
mHTMLEditor->IsPreformatted(mNode, &mPRE);
// if it's preformatedd, or if we are surrounded by text or special, it's all one
// big normal ws run
if ( mPRE || (((mStartReason == eText) || (mStartReason == eSpecial)) &&
((mEndReason == eText) || (mEndReason == eSpecial) || (mEndReason == eBreak))) )
{
MakeSingleWSRun(eNormalWS);
if (mPRE ||
((mStartReason == WSType::text || mStartReason == WSType::special) &&
(mEndReason == WSType::text || mEndReason == WSType::special ||
mEndReason == WSType::br))) {
MakeSingleWSRun(WSType::normalWS);
return;
}
// if we are before or after a block (or after a break), and there are no nbsp's,
// then it's all non-rendering ws.
if ( !(mFirstNBSPNode || mLastNBSPNode) &&
( (mStartReason & eBlock) || (mStartReason == eBreak) || (mEndReason & eBlock) ) )
{
PRInt16 wstype = eNone;
if ((mStartReason & eBlock) || (mStartReason == eBreak))
wstype = eLeadingWS;
if (mEndReason & eBlock)
wstype |= eTrailingWS;
if (!mFirstNBSPNode && !mLastNBSPNode &&
((mStartReason & WSType::block) || mStartReason == WSType::br ||
(mEndReason & WSType::block))) {
WSType wstype;
if ((mStartReason & WSType::block) || mStartReason == WSType::br) {
wstype = WSType::leadingWS;
}
if (mEndReason & WSType::block) {
wstype |= WSType::trailingWS;
}
MakeSingleWSRun(wstype);
return;
}
@ -976,25 +937,23 @@ nsWSRunObject::GetRuns()
mStartRun->mStartNode = mStartNode;
mStartRun->mStartOffset = mStartOffset;
if ( (mStartReason & eBlock) || (mStartReason == eBreak) )
{
if (mStartReason & WSType::block || mStartReason == WSType::br) {
// set up mStartRun
mStartRun->mType = eLeadingWS;
mStartRun->mType = WSType::leadingWS;
mStartRun->mEndNode = mFirstNBSPNode;
mStartRun->mEndOffset = mFirstNBSPOffset;
mStartRun->mLeftType = mStartReason;
mStartRun->mRightType = eNormalWS;
mStartRun->mRightType = WSType::normalWS;
// set up next run
WSFragment *normalRun = new WSFragment();
mStartRun->mRight = normalRun;
normalRun->mType = eNormalWS;
normalRun->mType = WSType::normalWS;
normalRun->mStartNode = mFirstNBSPNode;
normalRun->mStartOffset = mFirstNBSPOffset;
normalRun->mLeftType = eLeadingWS;
normalRun->mLeftType = WSType::leadingWS;
normalRun->mLeft = mStartRun;
if (mEndReason != eBlock)
{
if (mEndReason != WSType::block) {
// then no trailing ws. this normal run ends the overall ws run.
normalRun->mRightType = mEndReason;
normalRun->mEndNode = mEndNode;
@ -1019,27 +978,25 @@ nsWSRunObject::GetRuns()
{
normalRun->mEndNode = mLastNBSPNode;
normalRun->mEndOffset = mLastNBSPOffset+1;
normalRun->mRightType = eTrailingWS;
normalRun->mRightType = WSType::trailingWS;
// set up next run
WSFragment *lastRun = new WSFragment();
lastRun->mType = eTrailingWS;
lastRun->mType = WSType::trailingWS;
lastRun->mStartNode = mLastNBSPNode;
lastRun->mStartOffset = mLastNBSPOffset+1;
lastRun->mEndNode = mEndNode;
lastRun->mEndOffset = mEndOffset;
lastRun->mLeftType = eNormalWS;
lastRun->mLeftType = WSType::normalWS;
lastRun->mLeft = normalRun;
lastRun->mRightType = mEndReason;
mEndRun = lastRun;
normalRun->mRight = lastRun;
}
}
}
else // mStartReason is not eBlock or eBreak
{
// set up mStartRun
mStartRun->mType = eNormalWS;
} else {
// mStartReason is not WSType::block or WSType::br; set up mStartRun
mStartRun->mType = WSType::normalWS;
mStartRun->mEndNode = mLastNBSPNode;
mStartRun->mEndOffset = mLastNBSPOffset+1;
mStartRun->mLeftType = mStartReason;
@ -1059,15 +1016,15 @@ nsWSRunObject::GetRuns()
{
// set up next run
WSFragment *lastRun = new WSFragment();
lastRun->mType = eTrailingWS;
lastRun->mType = WSType::trailingWS;
lastRun->mStartNode = mLastNBSPNode;
lastRun->mStartOffset = mLastNBSPOffset+1;
lastRun->mLeftType = eNormalWS;
lastRun->mLeftType = WSType::normalWS;
lastRun->mLeft = mStartRun;
lastRun->mRightType = mEndReason;
mEndRun = lastRun;
mStartRun->mRight = lastRun;
mStartRun->mRightType = eTrailingWS;
mStartRun->mRightType = WSType::trailingWS;
}
}
}
@ -1088,7 +1045,7 @@ nsWSRunObject::ClearRuns()
}
void
nsWSRunObject::MakeSingleWSRun(PRInt16 aType)
nsWSRunObject::MakeSingleWSRun(WSType aType)
{
mStartRun = new WSFragment();
@ -1352,18 +1309,16 @@ nsWSRunObject::PrepareToDeleteRangePriv(nsWSRunObject* aEndObject)
aEndObject->FindRun(aEndObject->mNode, aEndObject->mOffset, &afterRun, true);
// trim after run of any leading ws
if (afterRun && (afterRun->mType & eLeadingWS))
{
if (afterRun && (afterRun->mType & WSType::leadingWS)) {
res = aEndObject->DeleteChars(aEndObject->mNode, aEndObject->mOffset, afterRun->mEndNode, afterRun->mEndOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
// adjust normal ws in afterRun if needed
if (afterRun && (afterRun->mType == eNormalWS) && !aEndObject->mPRE)
{
if ( (beforeRun && (beforeRun->mType & eLeadingWS)) ||
(!beforeRun && ((mStartReason & eBlock) || (mStartReason == eBreak))) )
{
if (afterRun && afterRun->mType == WSType::normalWS && !aEndObject->mPRE) {
if ((beforeRun && (beforeRun->mType & WSType::leadingWS)) ||
(!beforeRun && ((mStartReason & WSType::block) ||
mStartReason == WSType::br))) {
// make sure leading char of following ws is an nbsp, so that it will show up
WSPoint point = aEndObject->GetCharAfter(aEndObject->mNode,
aEndObject->mOffset);
@ -1375,18 +1330,14 @@ nsWSRunObject::PrepareToDeleteRangePriv(nsWSRunObject* aEndObject)
}
}
// trim before run of any trailing ws
if (beforeRun && (beforeRun->mType & eTrailingWS))
{
if (beforeRun && (beforeRun->mType & WSType::trailingWS)) {
res = DeleteChars(beforeRun->mStartNode, beforeRun->mStartOffset, mNode, mOffset,
eOutsideUserSelectAll);
NS_ENSURE_SUCCESS(res, res);
}
else if (beforeRun && (beforeRun->mType == eNormalWS) && !mPRE)
{
if ( (afterRun && (afterRun->mType & eTrailingWS)) ||
(afterRun && (afterRun->mType == eNormalWS)) ||
(!afterRun && ((aEndObject->mEndReason & eBlock))) )
{
} else if (beforeRun && beforeRun->mType == WSType::normalWS && !mPRE) {
if ((afterRun && (afterRun->mType & WSType::trailingWS)) ||
(afterRun && afterRun->mType == WSType::normalWS) ||
(!afterRun && (aEndObject->mEndReason & WSType::block))) {
// make sure trailing char of starting ws is an nbsp, so that it will show up
WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
@ -1424,8 +1375,7 @@ nsWSRunObject::PrepareToSplitAcrossBlocksPriv()
FindRun(mNode, mOffset, &afterRun, true);
// adjust normal ws in afterRun if needed
if (afterRun && (afterRun->mType == eNormalWS))
{
if (afterRun && afterRun->mType == WSType::normalWS) {
// make sure leading char of following ws is an nbsp, so that it will show up
WSPoint point = GetCharAfter(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
@ -1436,8 +1386,7 @@ nsWSRunObject::PrepareToSplitAcrossBlocksPriv()
}
// adjust normal ws in beforeRun if needed
if (beforeRun && (beforeRun->mType == eNormalWS))
{
if (beforeRun && beforeRun->mType == WSType::normalWS) {
// make sure trailing char of starting ws is an nbsp, so that it will show up
WSPoint point = GetCharBefore(mNode, mOffset);
if (point.mTextNode && nsCRT::IsAsciiSpace(point.mChar))
@ -1982,7 +1931,9 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
bool rightCheck = false;
// confirm run is normalWS
if (aRun->mType != eNormalWS) return NS_ERROR_FAILURE;
if (aRun->mType != WSType::normalWS) {
return NS_ERROR_FAILURE;
}
// first check for trailing nbsp
WSPoint thePoint = GetCharBefore(aRun->mEndNode, aRun->mEndOffset);
@ -1992,18 +1943,25 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
if (prevPoint.mTextNode) {
if (!nsCRT::IsAsciiSpace(prevPoint.mChar)) leftCheck = true;
else spaceNBSP = true;
} else if (aRun->mLeftType == WSType::text) {
leftCheck = true;
} else if (aRun->mLeftType == WSType::special) {
leftCheck = true;
}
else if (aRun->mLeftType == eText) leftCheck = true;
else if (aRun->mLeftType == eSpecial) leftCheck = true;
if (leftCheck || spaceNBSP)
{
// now check that what is to the right of it is compatible with replacing nbsp with space
if (aRun->mRightType == eText) rightCheck = true;
if (aRun->mRightType == eSpecial) rightCheck = true;
if (aRun->mRightType == eBreak) rightCheck = true;
if ((aRun->mRightType & eBlock) &&
IsBlockNode(nsCOMPtr<nsIDOMNode>(GetWSBoundingParent())))
{
if (aRun->mRightType == WSType::text) {
rightCheck = true;
}
if (aRun->mRightType == WSType::special) {
rightCheck = true;
}
if (aRun->mRightType == WSType::br) {
rightCheck = true;
}
if ((aRun->mRightType & WSType::block) &&
IsBlockNode(nsCOMPtr<nsIDOMNode>(GetWSBoundingParent()))) {
// we are at a block boundary. Insert a <br>. Why? Well, first note that
// the br will have no visible effect since it is up against a block boundary.
// |foo<br><p>bar| renders like |foo<p>bar| and similarly
@ -2091,9 +2049,11 @@ nsWSRunObject::CheckTrailingNBSP(WSFragment *aRun, nsIDOMNode *aNode, PRInt32 aO
WSPoint prevPoint = GetCharBefore(thePoint);
if (prevPoint.mTextNode) {
if (!nsCRT::IsAsciiSpace(prevPoint.mChar)) canConvert = true;
} else if (aRun->mLeftType == WSType::text) {
canConvert = true;
} else if (aRun->mLeftType == WSType::special) {
canConvert = true;
}
else if (aRun->mLeftType == eText) canConvert = true;
else if (aRun->mLeftType == eSpecial) canConvert = true;
}
if (canConvert)
{
@ -2130,10 +2090,13 @@ nsWSRunObject::CheckLeadingNBSP(WSFragment *aRun, nsIDOMNode *aNode, PRInt32 aOf
WSPoint nextPoint = GetCharAfter(tmp);
if (nextPoint.mTextNode) {
if (!nsCRT::IsAsciiSpace(nextPoint.mChar)) canConvert = true;
} else if (aRun->mRightType == WSType::text) {
canConvert = true;
} else if (aRun->mRightType == WSType::special) {
canConvert = true;
} else if (aRun->mRightType == WSType::br) {
canConvert = true;
}
else if (aRun->mRightType == eText) canConvert = true;
else if (aRun->mRightType == eSpecial) canConvert = true;
else if (aRun->mRightType == eBreak) canConvert = true;
}
if (canConvert)
{
@ -2180,8 +2143,7 @@ nsWSRunObject::Scrub()
WSFragment *run = mStartRun;
while (run)
{
if (run->mType & (eLeadingWS|eTrailingWS) )
{
if (run->mType & (WSType::leadingWS | WSType::trailingWS)) {
nsresult res = DeleteChars(run->mStartNode, run->mStartOffset, run->mEndNode, run->mEndOffset);
NS_ENSURE_SUCCESS(res, res);
}

Просмотреть файл

@ -38,10 +38,109 @@ struct DOMPoint;
// will only render as one space (in non-preformatted stlye html), yet both
// spaces count as NormalWS. Together, they render as the one visible space.
/**
* A type-safe bitfield indicating various types of whitespace or other things.
* Used as a member variable in nsWSRunObject and WSFragment.
*
* XXX: If this idea is useful in other places, we should generalize it using a
* template.
*/
class WSType {
public:
enum Enum {
none = 0,
leadingWS = 1, // leading insignificant ws, ie, after block or br
trailingWS = 1 << 1, // trailing insignificant ws, ie, before block
normalWS = 1 << 2, // normal significant ws, ie, after text, image, ...
text = 1 << 3, // indicates regular (non-ws) text
special = 1 << 4, // indicates an inline non-container, like image
br = 1 << 5, // indicates a br node
otherBlock = 1 << 6, // indicates a block other than one ws run is in
thisBlock = 1 << 7, // indicates the block ws run is in
block = otherBlock | thisBlock // block found
};
/**
* Implicit constructor, because the enums are logically just WSTypes
* themselves, and are only a separate type because there's no other obvious
* way to name specific WSType values.
*/
WSType(const Enum& aEnum = none) : mEnum(aEnum) {}
// operator==, &, and | need to access mEnum
friend bool operator==(const WSType& aLeft, const WSType& aRight);
friend const WSType operator&(const WSType& aLeft, const WSType& aRight);
friend const WSType operator|(const WSType& aLeft, const WSType& aRight);
WSType& operator=(const WSType& aOther) {
// This handles self-assignment fine
mEnum = aOther.mEnum;
return *this;
}
WSType& operator&=(const WSType& aOther) {
mEnum &= aOther.mEnum;
return *this;
}
WSType& operator|=(const WSType& aOther) {
mEnum |= aOther.mEnum;
return *this;
}
private:
PRUint16 mEnum;
void bool_conversion_helper() {};
public:
// Allow boolean conversion with no numeric conversion
typedef void (WSType::*bool_type)();
operator bool_type() const
{
return mEnum ? &WSType::bool_conversion_helper : nsnull;
}
};
/**
* These are declared as global functions so "WSType::Enum == WSType" et al.
* will work using the implicit constructor.
*/
inline bool operator==(const WSType& aLeft, const WSType& aRight)
{
return aLeft.mEnum == aRight.mEnum;
}
inline bool operator!=(const WSType& aLeft, const WSType& aRight)
{
return !(aLeft == aRight);
}
inline const WSType operator&(const WSType& aLeft, const WSType& aRight)
{
WSType ret;
ret.mEnum = aLeft.mEnum & aRight.mEnum;
return ret;
}
inline const WSType operator|(const WSType& aLeft, const WSType& aRight)
{
WSType ret;
ret.mEnum = aLeft.mEnum | aRight.mEnum;
return ret;
}
/**
* Make sure that & and | of WSType::Enum creates a WSType instead of an int,
* because operators between WSType and int shouldn't work
*/
inline const WSType operator&(const WSType::Enum& aLeft,
const WSType::Enum& aRight)
{
return WSType(aLeft) & WSType(aRight);
}
inline const WSType operator|(const WSType::Enum& aLeft,
const WSType::Enum& aRight)
{
return WSType(aLeft) | WSType(aRight);
}
class NS_STACK_CLASS nsWSRunObject
{
public:
// public enums ---------------------------------------------------------
enum BlockBoundary
{
kBeforeBlock,
@ -50,6 +149,10 @@ class NS_STACK_CLASS nsWSRunObject
kAfterBlock
};
enum {eBefore = 1};
enum {eAfter = 1 << 1};
enum {eBoth = eBefore | eAfter};
// constructor / destructor -----------------------------------------------
nsWSRunObject(nsHTMLEditor *aEd, nsIDOMNode *aNode, PRInt32 aOffset);
~nsWSRunObject();
@ -139,7 +242,7 @@ class NS_STACK_CLASS nsWSRunObject
PRInt32 aOffset,
nsCOMPtr<nsIDOMNode> *outVisNode,
PRInt32 *outVisOffset,
PRInt16 *outType);
WSType *outType);
// NextVisibleNode returns the first piece of visible thing
// after {aNode,aOffset}. If there is no visible ws qualifying
@ -150,28 +253,12 @@ class NS_STACK_CLASS nsWSRunObject
PRInt32 aOffset,
nsCOMPtr<nsIDOMNode> *outVisNode,
PRInt32 *outVisOffset,
PRInt16 *outType);
WSType *outType);
// AdjustWhitespace examines the ws object for nbsp's that can
// be safely converted to regular ascii space and converts them.
nsresult AdjustWhitespace();
// public enums ---------------------------------------------------------
enum {eNone = 0};
enum {eLeadingWS = 1}; // leading insignificant ws, ie, after block or br
enum {eTrailingWS = 1 << 1}; // trailing insignificant ws, ie, before block
enum {eNormalWS = 1 << 2}; // normal significant ws, ie, after text, image, ...
enum {eText = 1 << 3}; // indicates regular (non-ws) text
enum {eSpecial = 1 << 4}; // indicates an inline non-container, like image
enum {eBreak = 1 << 5}; // indicates a br node
enum {eOtherBlock = 1 << 6}; // indicates a block other than one ws run is in
enum {eThisBlock = 1 << 7}; // indicates the block ws run is in
enum {eBlock = eOtherBlock | eThisBlock}; // block found
enum {eBefore = 1};
enum {eAfter = 1 << 1};
enum {eBoth = eBefore | eAfter};
protected:
// WSFragment struct ---------------------------------------------------------
@ -184,12 +271,17 @@ class NS_STACK_CLASS nsWSRunObject
nsCOMPtr<nsIDOMNode> mEndNode; // node where ws run ends
PRInt32 mStartOffset; // offset where ws run starts
PRInt32 mEndOffset; // offset where ws run ends
PRInt16 mType, mLeftType, mRightType; // type of ws, and what is to left and right of it
WSFragment *mLeft, *mRight; // other ws runs to left or right. may be null.
// type of ws, and what is to left and right of it
WSType mType, mLeftType, mRightType;
// other ws runs to left or right. may be null.
WSFragment *mLeft, *mRight;
WSFragment() : mStartNode(0),mEndNode(0),mStartOffset(0),
mEndOffset(0),mType(0),mLeftType(0),
mRightType(0),mLeft(0),mRight(0) {}
WSFragment() : mStartNode(0), mEndNode(0),
mStartOffset(0), mEndOffset(0),
mType(), mLeftType(), mRightType(),
mLeft(0), mRight(0)
{
}
};
// WSPoint struct ------------------------------------------------------------
@ -235,7 +327,7 @@ class NS_STACK_CLASS nsWSRunObject
nsresult GetWSNodes();
void GetRuns();
void ClearRuns();
void MakeSingleWSRun(PRInt16 aType);
void MakeSingleWSRun(WSType aType);
nsresult PrependNodeToList(nsIDOMNode *aNode);
nsresult AppendNodeToList(nsIDOMNode *aNode);
nsresult GetPreviousWSNode(nsIDOMNode *aStartNode,
@ -294,12 +386,12 @@ class NS_STACK_CLASS nsWSRunObject
bool mPRE; // true if we are in preformatted whitespace context
nsCOMPtr<nsIDOMNode> mStartNode; // node/offset where ws starts
PRInt32 mStartOffset; // ...
PRInt16 mStartReason; // reason why ws starts (eText, eOtherBlock, etc)
WSType mStartReason; // reason why ws starts (eText, eOtherBlock, etc)
nsCOMPtr<nsIDOMNode> mStartReasonNode;// the node that implicated by start reason
nsCOMPtr<nsIDOMNode> mEndNode; // node/offset where ws ends
PRInt32 mEndOffset; // ...
PRInt16 mEndReason; // reason why ws ends (eText, eOtherBlock, etc)
WSType mEndReason; // reason why ws ends (eText, eOtherBlock, etc)
nsCOMPtr<nsIDOMNode> mEndReasonNode; // the node that implicated by end reason
nsCOMPtr<nsIDOMNode> mFirstNBSPNode; // location of first nbsp in ws run, if any

Просмотреть файл

@ -37,4 +37,5 @@ include $(topsrcdir)/config/rules.mk
LOCAL_INCLUDES += \
-I$(topsrcdir)/xpcom/io \
-I$(topsrcdir)/content/base/src \
-I$(topsrcdir)/editor/libeditor/base \
$(NULL)

Просмотреть файл

@ -62,6 +62,7 @@
#include "nsGUIEvent.h"
#include "nsRange.h"
#include "nsContentUtils.h"
#include "nsEditor.h"
// Set to spew messages to the console about what is happening.
//#define DEBUG_INLINESPELL
@ -119,7 +120,7 @@ mozInlineSpellStatus::InitForEditorChange(
getter_AddRefs(mAnchorRange));
NS_ENSURE_SUCCESS(rv, rv);
if (aAction == mozInlineSpellChecker::kOpDeleteSelection) {
if (aAction == nsEditor::kOpDeleteSelection) {
// Deletes are easy, the range is just the current anchor. We set the range
// to check to be empty, FinishInitOnEvent will fill in the range to be
// the current word.
@ -152,7 +153,7 @@ mozInlineSpellStatus::InitForEditorChange(
// On insert save this range: DoSpellCheck optimizes things in this range.
// Otherwise, just leave this NULL.
if (aAction == mozInlineSpellChecker::kOpInsertText)
if (aAction == nsEditor::kOpInsertText)
mCreatedRange = mRange;
// if we were given a range, we need to expand our range to encompass it

Просмотреть файл

@ -157,46 +157,6 @@ private:
// the whole document.
bool mFullSpellCheckScheduled;
// TODO: these should be defined somewhere so that they don't have to be copied
// from editor!
enum OperationID
{
kOpIgnore = -1,
kOpNone = 0,
kOpUndo,
kOpRedo,
kOpInsertNode,
kOpCreateNode,
kOpDeleteNode,
kOpSplitNode,
kOpJoinNode,
kOpDeleteSelection,
kOpInsertBreak = 1000,
kOpInsertText = 1001,
kOpInsertIMEText = 1002,
kOpDeleteText = 1003,
kOpMakeList = 3001,
kOpIndent = 3002,
kOpOutdent = 3003,
kOpAlign = 3004,
kOpMakeBasicBlock = 3005,
kOpRemoveList = 3006,
kOpMakeDefListItem = 3007,
kOpInsertElement = 3008,
kOpInsertQuotation = 3009,
kOpSetTextProperty = 3010,
kOpRemoveTextProperty = 3011,
kOpHTMLPaste = 3012,
kOpLoadHTML = 3013,
kOpResetTextProperties = 3014,
kOpSetAbsolutePosition = 3015,
kOpRemoveAbsolutePosition = 3016,
kOpDecreaseZIndex = 3017,
kOpIncreaseZIndex = 3018
};
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS

Просмотреть файл

@ -64,6 +64,7 @@ CPPSRCS = \
testVersion.cpp \
testXDR.cpp \
testProfileStrings.cpp \
testJSEvaluateScript.cpp \
$(NULL)
CSRCS = \

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=99:
*/
#include "tests.h"
BEGIN_TEST(testJSEvaluateScript)
{
jsvalRoot proto(cx);
JSObject *obj = JS_NewObject(cx, NULL, NULL, global);
CHECK(obj);
uint32_t options = JS_GetOptions(cx);
CHECK(options & JSOPTION_VAROBJFIX);
static const char src[] = "var x = 5;";
JS::Value retval;
CHECK(JS_EvaluateScript(cx, obj, src, sizeof(src) - 1, __FILE__, __LINE__,
&retval));
JSBool hasProp = JS_TRUE;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
CHECK(!hasProp);
hasProp = JS_FALSE;
CHECK(JS_HasProperty(cx, global, "x", &hasProp));
CHECK(hasProp);
// Now do the same thing, but without JSOPTION_VAROBJFIX
JS_SetOptions(cx, options & ~JSOPTION_VAROBJFIX);
static const char src2[] = "var y = 5;";
CHECK(JS_EvaluateScript(cx, obj, src2, sizeof(src2) - 1, __FILE__, __LINE__,
&retval));
hasProp = JS_FALSE;
CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp));
CHECK(hasProp);
hasProp = JS_TRUE;
CHECK(JS_AlreadyHasOwnProperty(cx, global, "y", &hasProp));
CHECK(!hasProp);
return true;
}
END_TEST(testJSEvaluateScript)

Просмотреть файл

@ -175,7 +175,7 @@ JS_END_EXTERN_C
#ifdef __cplusplus
typedef bool (* JS_SourceHook)(JSContext *cx, JSScript *script, char **src, uint32_t *length);
typedef bool (* JS_SourceHook)(JSContext *cx, JSScript *script, jschar **src, uint32_t *length);
extern JS_FRIEND_API(void)
JS_SetSourceHook(JSRuntime *rt, JS_SourceHook hook);

Просмотреть файл

@ -1077,20 +1077,15 @@ JSScript::loadSource(JSContext *cx, bool *worked)
*worked = false;
if (!cx->runtime->sourceHook)
return true;
char *src = NULL;
jschar *src = NULL;
uint32_t length;
if (!cx->runtime->sourceHook(cx, this, &src, &length))
return false;
if (!src)
return true;
size_t newLength = length;
jschar *usrc = InflateString(cx, src, &newLength);
cx->free_(src);
if (!usrc)
return false;
ScriptSource *ss = ScriptSource::createFromSource(cx, usrc, length, false, NULL, true);
ScriptSource *ss = ScriptSource::createFromSource(cx, src, length, false, NULL, true);
if (!ss) {
cx->free_(usrc);
cx->free_(src);
return false;
}
source = ss;

Просмотреть файл

@ -54,7 +54,7 @@ js::TryCompressString(const unsigned char *inp, size_t inplen, unsigned char *ou
zs.avail_in = inplen;
zs.next_out = out;
zs.avail_out = inplen;
int ret = deflateInit(&zs, Z_DEFAULT_COMPRESSION);
int ret = deflateInit(&zs, Z_BEST_SPEED);
if (ret != Z_OK) {
JS_ASSERT(ret == Z_MEM_ERROR);
return false;

Просмотреть файл

@ -1,3 +1,6 @@
// Some unicode characters that must be decoded:
// ………………………………………………………………………………………………………………………………
function outoflinefunction() {
return 42;
}

Просмотреть файл

@ -22,8 +22,14 @@ function inlinefunction() {
return 42;
}
isnot(inlinefunction.toSource().indexOf("return 42"), -1, "inline XUL script should have source");
isnot(outoflinefunction.toSource().indexOf("return 42"), -1, "outofline XUL script should have source");
isnot(NetUtil.asyncFetch.toSource().indexOf("return"), -1, "JSM module should have source");
var src;
src = inlinefunction.toSource();
isnot(src.indexOf("return 42"), -1, "inline XUL script should have source");
is(src.charAt(src.length - 1), "}", "inline XUL source should end with '}'");
src = outoflinefunction.toSource();
isnot(src.indexOf("return 42"), -1, "out of line XUL script should have source")
is(src.charAt(src.length - 1), "}", "out of line XUL source should end with '}'");
src = NetUtil.asyncFetch.toSource()
isnot(src.indexOf("return"), -1, "JSM should have source");
]]></script>
</window>