2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-07-30 14:15:38 +04:00
|
|
|
|
|
|
|
#include "nsHtml5Highlighter.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsHtml5Tokenizer.h"
|
|
|
|
#include "nsHtml5AttributeName.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2011-11-30 21:44:31 +04:00
|
|
|
#include "nsHtml5ViewSourceUtils.h"
|
2015-12-25 10:01:32 +03:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2010-07-30 14:15:38 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
// The old code had a limit of 16 tokens. 1300 is a number picked my measuring
|
|
|
|
// the size of 16 tokens on cnn.com.
|
|
|
|
#define NS_HTML5_HIGHLIGHTER_PRE_BREAK_THRESHOLD 1300
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sComment[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'c', 'o', 'm', 'm', 'e', 'n', 't', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sCdata[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'c', 'd', 'a', 't', 'a', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sEntity[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'e', 'n', 't', 'i', 't', 'y', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sEndTag[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'e', 'n', 'd', '-', 't', 'a', 'g', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sStartTag[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 's', 't', 'a', 'r', 't', '-', 't', 'a', 'g', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sAttributeName[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'a', 't', 't', 'r', 'i', 'b', 'u', 't', 'e', '-', 'n', 'a', 'm', 'e', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sAttributeValue[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'a', 't', 't', 'r', 'i', 'b', 'u', 't', 'e', '-',
|
|
|
|
'v', 'a', 'l', 'u', 'e', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sDoctype[] =
|
2010-07-30 14:15:38 +04:00
|
|
|
{ 'd', 'o', 'c', 't', 'y', 'p', 'e', 0 };
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t nsHtml5Highlighter::sPi[] =
|
2011-11-01 15:33:11 +04:00
|
|
|
{ 'p', 'i', 0 };
|
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
nsHtml5Highlighter::nsHtml5Highlighter(nsAHtml5TreeOpSink* aOpSink)
|
|
|
|
: mState(NS_HTML5TOKENIZER_DATA)
|
2012-09-28 10:57:33 +04:00
|
|
|
, mCStart(INT32_MAX)
|
2010-07-30 14:15:38 +04:00
|
|
|
, mPos(0)
|
2011-11-01 15:33:11 +04:00
|
|
|
, mLineNumber(1)
|
2010-07-30 14:15:38 +04:00
|
|
|
, mInlinesOpen(0)
|
2011-11-01 15:33:11 +04:00
|
|
|
, mInCharacters(false)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mBuffer(nullptr)
|
2010-07-30 14:15:38 +04:00
|
|
|
, mOpSink(aOpSink)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mCurrentRun(nullptr)
|
|
|
|
, mAmpersand(nullptr)
|
|
|
|
, mSlash(nullptr)
|
2015-11-20 04:19:57 +03:00
|
|
|
, mHandles(MakeUnique<nsIContent*[]>(NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH))
|
2010-07-30 14:15:38 +04:00
|
|
|
, mHandlesUsed(0)
|
2014-09-30 13:35:17 +04:00
|
|
|
, mSeenBase(false)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHtml5Highlighter::~nsHtml5Highlighter()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-30 21:44:31 +04:00
|
|
|
nsHtml5Highlighter::Start(const nsAutoString& aTitle)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
// Doctype
|
|
|
|
mOpQueue.AppendElement()->Init(nsGkAtoms::html, EmptyString(), EmptyString());
|
|
|
|
|
|
|
|
mOpQueue.AppendElement()->Init(STANDARDS_MODE);
|
|
|
|
|
2014-11-10 09:50:18 +03:00
|
|
|
nsIContent** root = CreateElement(nsHtml5Atoms::html, nullptr, nullptr);
|
2010-07-30 14:15:38 +04:00
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpAppendToDocument, root);
|
|
|
|
mStack.AppendElement(root);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::head, nullptr);
|
2010-07-30 14:15:38 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::title, nullptr);
|
2010-07-30 14:15:38 +04:00
|
|
|
// XUL will add the "Source of: " prefix.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length = aTitle.Length();
|
2012-09-28 10:57:33 +04:00
|
|
|
if (length > INT32_MAX) {
|
|
|
|
length = INT32_MAX;
|
2011-11-30 21:44:31 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
AppendCharacters(aTitle.get(), 0, (int32_t)length);
|
2010-07-30 14:15:38 +04:00
|
|
|
Pop(); // title
|
|
|
|
|
2011-11-30 21:44:31 +04:00
|
|
|
Push(nsGkAtoms::link, nsHtml5ViewSourceUtils::NewLinkAttributes());
|
2010-07-30 14:15:38 +04:00
|
|
|
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpUpdateStyleSheet, CurrentNode());
|
|
|
|
|
|
|
|
Pop(); // link
|
|
|
|
|
|
|
|
Pop(); // head
|
|
|
|
|
2011-11-30 21:44:31 +04:00
|
|
|
Push(nsGkAtoms::body, nsHtml5ViewSourceUtils::NewBodyAttributes());
|
2010-07-30 14:15:38 +04:00
|
|
|
|
|
|
|
nsHtml5HtmlAttributes* preAttrs = new nsHtml5HtmlAttributes(0);
|
|
|
|
nsString* preId = new nsString(NS_LITERAL_STRING("line1"));
|
|
|
|
preAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, preId);
|
|
|
|
Push(nsGkAtoms::pre, preAttrs);
|
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
StartCharacters();
|
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpStartLayout);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
nsHtml5Highlighter::Transition(int32_t aState, bool aReconsume, int32_t aPos)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
mPos = aPos;
|
|
|
|
switch (mState) {
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA:
|
|
|
|
case NS_HTML5TOKENIZER_RAWTEXT:
|
|
|
|
case NS_HTML5TOKENIZER_RCDATA:
|
|
|
|
case NS_HTML5TOKENIZER_DATA:
|
|
|
|
// We can transition on < and on &. Either way, we don't yet know the
|
|
|
|
// role of the token, so open a span without class.
|
2011-11-01 15:33:11 +04:00
|
|
|
if (aState == NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE) {
|
2011-11-01 15:33:11 +04:00
|
|
|
StartSpan();
|
2011-11-01 15:33:11 +04:00
|
|
|
// Start another span for highlighting the ampersand
|
|
|
|
StartSpan();
|
|
|
|
mAmpersand = CurrentNode();
|
|
|
|
} else {
|
2012-04-17 15:53:52 +04:00
|
|
|
EndCharactersAndStartMarkupRun();
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_TAG_OPEN:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_TAG_NAME:
|
|
|
|
StartSpan(sStartTag);
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_DATA:
|
2011-11-01 15:33:11 +04:00
|
|
|
FinishTag(); // DATA
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
2011-11-01 15:33:11 +04:00
|
|
|
case NS_HTML5TOKENIZER_PROCESSING_INSTRUCTION:
|
|
|
|
AddClass(sPi);
|
|
|
|
break;
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_TAG_NAME:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // NS_HTML5TOKENIZER_TAG_NAME
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // NS_HTML5TOKENIZER_TAG_NAME
|
2010-07-30 14:15:38 +04:00
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_NAME:
|
|
|
|
StartSpan(sAttributeName);
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_NAME:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME
|
2010-07-30 14:15:38 +04:00
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_SINGLE_QUOTED:
|
|
|
|
FlushCurrent();
|
|
|
|
StartA();
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_UNQUOTED:
|
|
|
|
StartA();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_SINGLE_QUOTED:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_VALUE_QUOTED:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE:
|
|
|
|
StartSpan();
|
2011-11-01 15:33:11 +04:00
|
|
|
StartSpan(); // for ampersand itself
|
|
|
|
mAmpersand = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Impossible transition.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_VALUE_QUOTED:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // end the slash highlight
|
2010-07-30 14:15:38 +04:00
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_UNQUOTED:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE:
|
|
|
|
StartSpan();
|
2011-11-01 15:33:11 +04:00
|
|
|
StartSpan(); // for ampersand itself
|
|
|
|
mAmpersand = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_NAME:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE:
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_ATTRIBUTE_NAME:
|
|
|
|
StartSpan(sAttributeName);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// most comment states are omitted, because they don't matter to
|
|
|
|
// highlighting
|
2011-11-29 10:55:09 +04:00
|
|
|
case NS_HTML5TOKENIZER_COMMENT_START:
|
2010-07-30 14:15:38 +04:00
|
|
|
case NS_HTML5TOKENIZER_COMMENT_END:
|
|
|
|
case NS_HTML5TOKENIZER_COMMENT_END_BANG:
|
|
|
|
case NS_HTML5TOKENIZER_COMMENT_START_DASH:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_COMMENT:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_COMMENT_HYPHEN:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_DATA) {
|
|
|
|
AddClass(sComment);
|
|
|
|
FinishTag();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// most cdata states are omitted, because they don't matter to
|
|
|
|
// highlighting
|
|
|
|
case NS_HTML5TOKENIZER_CDATA_RSQB_RSQB:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_DATA) {
|
|
|
|
AddClass(sCdata);
|
|
|
|
FinishTag();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE:
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // the span for the ampersand
|
2010-07-30 14:15:38 +04:00
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_CONSUME_NCR:
|
|
|
|
case NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// not actually a character reference
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_CHARACTER_REFERENCE_TAIL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// not actually a character reference
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CHARACTER_REFERENCE_TAIL:
|
|
|
|
if (!aReconsume) {
|
|
|
|
FlushCurrent();
|
|
|
|
}
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_DECIMAL_NRC_LOOP:
|
|
|
|
case NS_HTML5TOKENIZER_HEX_NCR_LOOP:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_HANDLE_NCR_VALUE:
|
|
|
|
AddClass(sEntity);
|
|
|
|
FlushCurrent();
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_HANDLE_NCR_VALUE_RECONSUME:
|
|
|
|
AddClass(sEntity);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CLOSE_TAG_OPEN:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_DATA:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_TAG_NAME:
|
|
|
|
StartSpan(sEndTag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_RAWTEXT_RCDATA_LESS_THAN_SIGN:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME) {
|
|
|
|
FlushCurrent();
|
|
|
|
StartSpan(); // don't know if it is "end-tag" yet :-(
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2011-11-01 15:33:11 +04:00
|
|
|
StartCharacters();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME:
|
|
|
|
switch (aState) {
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME:
|
|
|
|
AddClass(sEndTag);
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG:
|
|
|
|
AddClass(sEndTag);
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
StartSpan(); // for highlighting the slash
|
2011-11-01 15:33:11 +04:00
|
|
|
mSlash = CurrentNode();
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_DATA: // yes, as a result of emitting the token
|
|
|
|
AddClass(sEndTag);
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA_LESS_THAN_SIGN:
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_NON_DATA_END_TAG_NAME) {
|
2012-04-17 15:53:52 +04:00
|
|
|
FlushCurrent();
|
|
|
|
StartSpan(); // don't know if it is "end-tag" yet :-(
|
2010-07-30 14:15:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
FinishTag();
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH_DASH:
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED:
|
|
|
|
case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN) {
|
2012-04-17 15:53:52 +04:00
|
|
|
EndCharactersAndStartMarkupRun();
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// Lots of double escape states omitted, because they don't highlight.
|
|
|
|
// Likewise, only doctype states that can emit the doctype are of
|
|
|
|
// interest. Otherwise, the transition out of bogus comment deals.
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_KEYWORD:
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_DOCTYPE:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_KEYWORD:
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_DATA) {
|
|
|
|
AddClass(sDoctype);
|
|
|
|
FinishTag();
|
|
|
|
}
|
|
|
|
break;
|
2011-11-01 15:33:11 +04:00
|
|
|
case NS_HTML5TOKENIZER_PROCESSING_INSTRUCTION_QUESTION_MARK:
|
|
|
|
if (aState == NS_HTML5TOKENIZER_DATA) {
|
|
|
|
FinishTag();
|
|
|
|
}
|
|
|
|
break;
|
2010-07-30 14:15:38 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mState = aState;
|
|
|
|
return aState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::End()
|
|
|
|
{
|
|
|
|
switch (mState) {
|
|
|
|
case NS_HTML5TOKENIZER_COMMENT_END:
|
|
|
|
case NS_HTML5TOKENIZER_COMMENT_END_BANG:
|
|
|
|
case NS_HTML5TOKENIZER_COMMENT_START_DASH:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_COMMENT:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_COMMENT_HYPHEN:
|
|
|
|
AddClass(sComment);
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_CDATA_RSQB_RSQB:
|
|
|
|
AddClass(sCdata);
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_DECIMAL_NRC_LOOP:
|
|
|
|
case NS_HTML5TOKENIZER_HEX_NCR_LOOP:
|
|
|
|
// XXX need tokenizer help here
|
|
|
|
break;
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_NAME:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_KEYWORD:
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_PUBLIC_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_BOGUS_DOCTYPE:
|
|
|
|
case NS_HTML5TOKENIZER_AFTER_DOCTYPE_SYSTEM_KEYWORD:
|
|
|
|
case NS_HTML5TOKENIZER_BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:
|
|
|
|
case NS_HTML5TOKENIZER_DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:
|
|
|
|
AddClass(sDoctype);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 15:33:11 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(eTreeOpStreamEnded);
|
2010-07-30 14:15:38 +04:00
|
|
|
FlushOps();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::SetBuffer(nsHtml5UTF16Buffer* aBuffer)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mBuffer, "Old buffer still here!");
|
|
|
|
mBuffer = aBuffer;
|
|
|
|
mCStart = aBuffer->getStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHtml5Highlighter::DropBuffer(int32_t aPos)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mBuffer, "No buffer to drop!");
|
|
|
|
mPos = aPos;
|
|
|
|
FlushChars();
|
2012-07-30 18:20:58 +04:00
|
|
|
mBuffer = nullptr;
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::StartSpan()
|
|
|
|
{
|
|
|
|
FlushChars();
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::span, nullptr);
|
2010-07-30 14:15:38 +04:00
|
|
|
++mInlinesOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsHtml5Highlighter::StartSpan(const char16_t* aClass)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
StartSpan();
|
|
|
|
AddClass(aClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-01 15:33:11 +04:00
|
|
|
nsHtml5Highlighter::EndSpanOrA()
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
FlushChars();
|
|
|
|
Pop();
|
|
|
|
--mInlinesOpen;
|
|
|
|
}
|
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
void
|
|
|
|
nsHtml5Highlighter::StartCharacters()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mInCharacters, "Already in characters!");
|
|
|
|
FlushChars();
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::span, nullptr);
|
2011-11-01 15:33:11 +04:00
|
|
|
mCurrentRun = CurrentNode();
|
|
|
|
mInCharacters = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-17 15:53:52 +04:00
|
|
|
nsHtml5Highlighter::EndCharactersAndStartMarkupRun()
|
2011-11-01 15:33:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mInCharacters, "Not in characters!");
|
|
|
|
FlushChars();
|
|
|
|
Pop();
|
|
|
|
mInCharacters = false;
|
2012-04-17 15:53:52 +04:00
|
|
|
// Now start markup run
|
|
|
|
StartSpan();
|
|
|
|
mCurrentRun = CurrentNode();
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
2010-07-30 14:15:38 +04:00
|
|
|
void
|
|
|
|
nsHtml5Highlighter::StartA()
|
|
|
|
{
|
|
|
|
FlushChars();
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::a, nullptr);
|
2010-07-30 14:15:38 +04:00
|
|
|
AddClass(sAttributeValue);
|
|
|
|
++mInlinesOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::FinishTag()
|
|
|
|
{
|
|
|
|
while (mInlinesOpen > 1) {
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA();
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
FlushCurrent(); // >
|
2011-11-01 15:33:11 +04:00
|
|
|
EndSpanOrA(); // DATA
|
2010-07-30 14:15:38 +04:00
|
|
|
NS_ASSERTION(!mInlinesOpen, "mInlinesOpen got out of sync!");
|
2011-11-01 15:33:11 +04:00
|
|
|
StartCharacters();
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::FlushChars()
|
|
|
|
{
|
2011-11-01 15:33:11 +04:00
|
|
|
if (mCStart < mPos) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* buf = mBuffer->getBuffer();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = mCStart;
|
2011-11-01 15:33:11 +04:00
|
|
|
while (i < mPos) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t c = buf[i];
|
2011-11-01 15:33:11 +04:00
|
|
|
switch (c) {
|
|
|
|
case '\r':
|
|
|
|
// The input this code sees has been normalized so that there are
|
|
|
|
// CR breaks and LF breaks but no CRLF breaks. Overwrite CR with LF
|
|
|
|
// to show consistent LF line breaks to layout. It is OK to mutate
|
|
|
|
// the input data, because there are no reparses in the View Source
|
|
|
|
// case, so we won't need the original data in the buffer anymore.
|
|
|
|
buf[i] = '\n';
|
2015-12-25 10:01:32 +03:00
|
|
|
MOZ_FALLTHROUGH;
|
2011-11-01 15:33:11 +04:00
|
|
|
case '\n': {
|
|
|
|
++i;
|
|
|
|
if (mCStart < i) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = i - mCStart;
|
2011-11-01 15:33:11 +04:00
|
|
|
AppendCharacters(buf, mCStart, len);
|
2011-11-01 15:33:11 +04:00
|
|
|
mCStart = i;
|
|
|
|
}
|
|
|
|
++mLineNumber;
|
2012-07-30 18:20:58 +04:00
|
|
|
Push(nsGkAtoms::span, nullptr);
|
2011-11-01 15:33:11 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->InitAddLineNumberId(CurrentNode(), mLineNumber);
|
|
|
|
Pop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCStart < mPos) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = mPos - mCStart;
|
2011-11-01 15:33:11 +04:00
|
|
|
AppendCharacters(buf, mCStart, len);
|
2011-11-01 15:33:11 +04:00
|
|
|
mCStart = mPos;
|
|
|
|
}
|
2010-07-30 14:15:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::FlushCurrent()
|
|
|
|
{
|
|
|
|
mPos++;
|
|
|
|
FlushChars();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHtml5Highlighter::FlushOps()
|
|
|
|
{
|
|
|
|
bool hasOps = !mOpQueue.IsEmpty();
|
|
|
|
if (hasOps) {
|
|
|
|
mOpSink->MoveOpsFrom(mOpQueue);
|
|
|
|
}
|
|
|
|
return hasOps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::MaybeLinkifyAttributeValue(nsHtml5AttributeName* aName,
|
|
|
|
nsString* aValue)
|
|
|
|
{
|
2011-11-01 15:33:11 +04:00
|
|
|
if (!(nsHtml5AttributeName::ATTR_HREF == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_SRC == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_ACTION == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_CITE == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_BACKGROUND == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_LONGDESC == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_XLINK_HREF == aName ||
|
|
|
|
nsHtml5AttributeName::ATTR_DEFINITIONURL == aName)) {
|
2010-07-30 14:15:38 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddViewSourceHref(*aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::CompletedNamedCharacterReference()
|
|
|
|
{
|
|
|
|
AddClass(sEntity);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent**
|
|
|
|
nsHtml5Highlighter::AllocateContentHandle()
|
|
|
|
{
|
|
|
|
if (mHandlesUsed == NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH) {
|
2015-11-20 04:19:57 +03:00
|
|
|
mOldHandles.AppendElement(Move(mHandles));
|
|
|
|
mHandles = MakeUnique<nsIContent*[]>(NS_HTML5_HIGHLIGHTER_HANDLE_ARRAY_LENGTH);
|
2010-07-30 14:15:38 +04:00
|
|
|
mHandlesUsed = 0;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2016-03-17 19:27:56 +03:00
|
|
|
mHandles[mHandlesUsed] = reinterpret_cast<nsIContent*>(uintptr_t(0xC0DEDBAD));
|
2010-07-30 14:15:38 +04:00
|
|
|
#endif
|
|
|
|
return &mHandles[mHandlesUsed++];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent**
|
|
|
|
nsHtml5Highlighter::CreateElement(nsIAtom* aName,
|
2014-11-10 09:50:18 +03:00
|
|
|
nsHtml5HtmlAttributes* aAttributes,
|
|
|
|
nsIContent** aIntendedParent)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aName, "Got null name.");
|
|
|
|
nsIContent** content = AllocateContentHandle();
|
|
|
|
mOpQueue.AppendElement()->Init(kNameSpaceID_XHTML,
|
|
|
|
aName,
|
|
|
|
aAttributes,
|
|
|
|
content,
|
2014-11-10 09:50:18 +03:00
|
|
|
aIntendedParent,
|
2010-07-30 14:15:38 +04:00
|
|
|
true);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent**
|
|
|
|
nsHtml5Highlighter::CurrentNode()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mStack.Length() >= 1, "Must have something on stack.");
|
|
|
|
return mStack[mStack.Length() - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::Push(nsIAtom* aName,
|
|
|
|
nsHtml5HtmlAttributes* aAttributes)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mStack.Length() >= 1, "Pushing without root.");
|
2014-11-10 09:50:18 +03:00
|
|
|
nsIContent** elt = CreateElement(aName, aAttributes, CurrentNode()); // Don't inline below!
|
2010-07-30 14:15:38 +04:00
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpAppend, elt, CurrentNode());
|
|
|
|
mStack.AppendElement(elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::Pop()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mStack.Length() >= 2, "Popping when stack too short.");
|
|
|
|
mStack.RemoveElementAt(mStack.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsHtml5Highlighter::AppendCharacters(const char16_t* aBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStart,
|
|
|
|
int32_t aLength)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aBuffer, "Null buffer");
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* bufferCopy = new char16_t[aLength];
|
|
|
|
memcpy(bufferCopy, aBuffer + aStart, aLength * sizeof(char16_t));
|
2010-07-30 14:15:38 +04:00
|
|
|
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpAppendText,
|
|
|
|
bufferCopy,
|
|
|
|
aLength,
|
|
|
|
CurrentNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
nsHtml5Highlighter::AddClass(const char16_t* aClass)
|
2010-07-30 14:15:38 +04:00
|
|
|
{
|
|
|
|
mOpQueue.AppendElement()->InitAddClass(CurrentNode(), aClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddViewSourceHref(const nsString& aValue)
|
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* bufferCopy = new char16_t[aValue.Length() + 1];
|
|
|
|
memcpy(bufferCopy, aValue.get(), aValue.Length() * sizeof(char16_t));
|
2010-07-30 14:15:38 +04:00
|
|
|
bufferCopy[aValue.Length()] = 0;
|
|
|
|
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpAddViewSourceHref,
|
|
|
|
bufferCopy,
|
|
|
|
aValue.Length(),
|
|
|
|
CurrentNode());
|
|
|
|
}
|
2011-11-01 15:33:11 +04:00
|
|
|
|
2014-09-30 13:35:17 +04:00
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddBase(const nsString& aValue)
|
|
|
|
{
|
|
|
|
if(mSeenBase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mSeenBase = true;
|
|
|
|
char16_t* bufferCopy = new char16_t[aValue.Length() + 1];
|
|
|
|
memcpy(bufferCopy, aValue.get(), aValue.Length() * sizeof(char16_t));
|
|
|
|
bufferCopy[aValue.Length()] = 0;
|
|
|
|
|
|
|
|
mOpQueue.AppendElement()->Init(eTreeOpAddViewSourceBase,
|
|
|
|
bufferCopy,
|
|
|
|
aValue.Length());
|
|
|
|
}
|
|
|
|
|
2011-11-01 15:33:11 +04:00
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddErrorToCurrentNode(const char* aMsgId)
|
|
|
|
{
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(CurrentNode(), aMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-01 15:33:11 +04:00
|
|
|
nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(mCurrentRun, aMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId,
|
|
|
|
nsIAtom* aName)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2011-11-01 15:33:11 +04:00
|
|
|
treeOp->Init(mCurrentRun, aMsgId, aName);
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddErrorToCurrentRun(const char* aMsgId,
|
|
|
|
nsIAtom* aName,
|
|
|
|
nsIAtom* aOther)
|
2011-11-01 15:33:11 +04:00
|
|
|
{
|
2011-11-01 15:33:11 +04:00
|
|
|
NS_PRECONDITION(mCurrentRun, "Adding error to run without one!");
|
2011-11-01 15:33:11 +04:00
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
2011-11-01 15:33:11 +04:00
|
|
|
treeOp->Init(mCurrentRun, aMsgId, aName, aOther);
|
2011-11-01 15:33:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddErrorToCurrentAmpersand(const char* aMsgId)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mAmpersand, "Adding error to ampersand without one!");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(mAmpersand, aMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Highlighter::AddErrorToCurrentSlash(const char* aMsgId)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mSlash, "Adding error to slash without one!");
|
|
|
|
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
|
|
|
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
|
|
|
treeOp->Init(mSlash, aMsgId);
|
|
|
|
}
|