Commit 38fa0002 authored by Dong Hwi Lee's avatar Dong Hwi Lee Committed by Commit Bot

Adjust indentation two spaces for DocumentXMLTreeViewer.js.

Change-Id: I3e30b0c29dea6dd6db8657c7236505968dd22274
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084726
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746556}
parent 4819ce58
...@@ -8,54 +8,55 @@ var tree; ...@@ -8,54 +8,55 @@ var tree;
function prepareWebKitXMLViewer() function prepareWebKitXMLViewer()
{ {
var html = createHTMLElement('html'); var html = createHTMLElement('html');
var head = createHTMLElement('head'); var head = createHTMLElement('head');
html.appendChild(head); html.appendChild(head);
var style = createHTMLElement('style'); var style = createHTMLElement('style');
style.id = 'xml-viewer-style'; style.id = 'xml-viewer-style';
head.appendChild(style); head.appendChild(style);
var body = createHTMLElement('body'); var body = createHTMLElement('body');
html.appendChild(body); html.appendChild(body);
var sourceXML = createHTMLElement('div'); var sourceXML = createHTMLElement('div');
sourceXML.id = 'webkit-xml-viewer-source-xml'; sourceXML.id = 'webkit-xml-viewer-source-xml';
body.appendChild(sourceXML); body.appendChild(sourceXML);
var child; var child;
while (child = document.firstChild) { while (child = document.firstChild) {
document.removeChild(child); document.removeChild(child);
if (child.nodeType != Node.DOCUMENT_TYPE_NODE) if (child.nodeType != Node.DOCUMENT_TYPE_NODE)
sourceXML.appendChild(child); sourceXML.appendChild(child);
} }
document.appendChild(html); document.appendChild(html);
var header = createHTMLElement('div'); var header = createHTMLElement('div');
body.appendChild(header); body.appendChild(header);
header.classList.add('header'); header.classList.add('header');
var headerSpan = createHTMLElement('span'); var headerSpan = createHTMLElement('span');
header.appendChild(headerSpan); header.appendChild(headerSpan);
headerSpan.textContent = headerSpan.textContent =
'This XML file does not appear to have any style information ' + 'This XML file does not appear to have any style information ' +
'associated with it. The document tree is shown below.'; 'associated with it. The document tree is shown below.';
header.appendChild(createHTMLElement('br')); header.appendChild(createHTMLElement('br'));
tree = createHTMLElement('div'); tree = createHTMLElement('div');
body.appendChild(tree); body.appendChild(tree);
tree.classList.add('pretty-print'); tree.classList.add('pretty-print');
window.onload = sourceXMLLoaded; window.onload = sourceXMLLoaded;
} }
function sourceXMLLoaded() function sourceXMLLoaded()
{ {
var sourceXML = document.getElementById('webkit-xml-viewer-source-xml'); var sourceXML = document.getElementById('webkit-xml-viewer-source-xml');
if (!sourceXML) if (!sourceXML)
return; // Stop if some XML tree extension is already processing this document return; // Stop if some XML tree extension is already processing this
// document
for (var child = sourceXML.firstChild; child; child = child.nextSibling) for (var child = sourceXML.firstChild; child; child = child.nextSibling)
processNode(tree, child); processNode(tree, child);
initButtons(); initButtons();
return false; return false;
} }
// Tree processing. // Tree processing.
...@@ -85,232 +86,230 @@ function processNode(parentElement, node) ...@@ -85,232 +86,230 @@ function processNode(parentElement, node)
function processElement(parentElement, node) function processElement(parentElement, node)
{ {
if (!node.firstChild) if (!node.firstChild)
processEmptyElement(parentElement, node); processEmptyElement(parentElement, node);
else { else {
var child = node.firstChild; var child = node.firstChild;
if (child.nodeType == Node.TEXT_NODE && !child.nextSibling) if (child.nodeType == Node.TEXT_NODE && !child.nextSibling)
processShortTextOnlyElement(parentElement, node); processShortTextOnlyElement(parentElement, node);
else else
processComplexElement(parentElement, node); processComplexElement(parentElement, node);
} }
} }
function processEmptyElement(parentElement, node) function processEmptyElement(parentElement, node)
{ {
var line = createLine(); var line = createLine();
line.appendChild(createTag(node, false, true)); line.appendChild(createTag(node, false, true));
parentElement.appendChild(line); parentElement.appendChild(line);
} }
function processShortTextOnlyElement(parentElement, node) function processShortTextOnlyElement(parentElement, node)
{ {
var line = createLine(); var line = createLine();
line.appendChild(createTag(node, false, false)); line.appendChild(createTag(node, false, false));
for (var child = node.firstChild; child; child = child.nextSibling) for (var child = node.firstChild; child; child = child.nextSibling)
line.appendChild(createText(child.nodeValue)); line.appendChild(createText(child.nodeValue));
line.appendChild(createTag(node, true, false)); line.appendChild(createTag(node, true, false));
parentElement.appendChild(line); parentElement.appendChild(line);
} }
function processComplexElement(parentElement, node) function processComplexElement(parentElement, node)
{ {
var folder = createFolder(); var folder = createFolder();
folder.start.appendChild(createTag(node, false, false)); folder.start.appendChild(createTag(node, false, false));
for (var child = node.firstChild; child; child = child.nextSibling) for (var child = node.firstChild; child; child = child.nextSibling)
processNode(folder.openedContent, child); processNode(folder.openedContent, child);
folder.end.appendChild(createTag(node, true, false)); folder.end.appendChild(createTag(node, true, false));
parentElement.appendChild(folder); parentElement.appendChild(folder);
} }
function processComment(parentElement, node) function processComment(parentElement, node)
{ {
var line = createLine(); var line = createLine();
line.appendChild(createComment('<!-- ' + node.nodeValue + ' -->')); line.appendChild(createComment('<!-- ' + node.nodeValue + ' -->'));
parentElement.appendChild(line); parentElement.appendChild(line);
} }
function processCDATA(parentElement, node) function processCDATA(parentElement, node)
{ {
var line = createLine(); var line = createLine();
line.appendChild(createText('<![CDATA[ ' + node.nodeValue + ' ]]>')); line.appendChild(createText('<![CDATA[ ' + node.nodeValue + ' ]]>'));
parentElement.appendChild(line); parentElement.appendChild(line);
} }
function processProcessingInstruction(parentElement, node) function processProcessingInstruction(parentElement, node)
{ {
var line = createLine(); var line = createLine();
line.appendChild( line.appendChild(
createComment('<?' + node.nodeName + ' ' + node.nodeValue + '?>')); createComment('<?' + node.nodeName + ' ' + node.nodeValue + '?>'));
parentElement.appendChild(line); parentElement.appendChild(line);
} }
function processText(parentElement, node) function processText(parentElement, node)
{ {
parentElement.appendChild(createText(node.nodeValue)); parentElement.appendChild(createText(node.nodeValue));
} }
// Tree rendering. // Tree rendering.
function createHTMLElement(elementName) function createHTMLElement(elementName)
{ {
return document.createElementNS('http://www.w3.org/1999/xhtml', elementName) return document.createElementNS('http://www.w3.org/1999/xhtml', elementName)
} }
function createFolder() function createFolder()
{ {
var folder = createHTMLElement('div'); var folder = createHTMLElement('div');
folder.classList.add('folder'); folder.classList.add('folder');
folder.start = createLine(); folder.start = createLine();
folder.start.appendChild(createFolderButton()); folder.start.appendChild(createFolderButton());
folder.appendChild(folder.start); folder.appendChild(folder.start);
folder.openedContent = createHTMLElement('div'); folder.openedContent = createHTMLElement('div');
folder.openedContent.classList.add('opened'); folder.openedContent.classList.add('opened');
folder.appendChild(folder.openedContent); folder.appendChild(folder.openedContent);
// Folded content. // Folded content.
folder.foldedContent = createText('...'); folder.foldedContent = createText('...');
folder.foldedContent.classList.add('folded'); folder.foldedContent.classList.add('folded');
folder.foldedContent.classList.add('hidden'); folder.foldedContent.classList.add('hidden');
folder.appendChild(folder.foldedContent); folder.appendChild(folder.foldedContent);
folder.end = createLine(); folder.end = createLine();
folder.appendChild(folder.end); folder.appendChild(folder.end);
return folder; return folder;
} }
function createFolderButton(str) { function createFolderButton(str) {
var button = createHTMLElement('span'); var button = createHTMLElement('span');
button.classList.add('folder-button'); button.classList.add('folder-button');
button.classList.add('fold'); button.classList.add('fold');
return button; return button;
} }
function createComment(commentString) function createComment(commentString)
{ {
var comment = createHTMLElement('span'); var comment = createHTMLElement('span');
comment.classList.add('comment'); comment.classList.add('comment');
comment.classList.add('html-comment'); comment.classList.add('html-comment');
comment.textContent = commentString; comment.textContent = commentString;
return comment; return comment;
} }
function createText(value) function createText(value)
{ {
var text = createHTMLElement('span'); var text = createHTMLElement('span');
text.textContent = value; text.textContent = value;
return text; return text;
} }
function createLine() function createLine()
{ {
var line = createHTMLElement('div'); var line = createHTMLElement('div');
line.classList.add('line'); line.classList.add('line');
return line; return line;
} }
function createTag(node, isClosing, isEmpty) function createTag(node, isClosing, isEmpty)
{ {
var tag = createHTMLElement('span'); var tag = createHTMLElement('span');
tag.classList.add('html-tag'); tag.classList.add('html-tag');
var stringBeforeAttrs = '<'; var stringBeforeAttrs = '<';
if (isClosing) if (isClosing)
stringBeforeAttrs += '/'; stringBeforeAttrs += '/';
stringBeforeAttrs += node.nodeName; stringBeforeAttrs += node.nodeName;
var textBeforeAttrs = document.createTextNode(stringBeforeAttrs); var textBeforeAttrs = document.createTextNode(stringBeforeAttrs);
tag.appendChild(textBeforeAttrs); tag.appendChild(textBeforeAttrs);
if (!isClosing) { if (!isClosing) {
for (var i = 0; i < node.attributes.length; i++) for (var i = 0; i < node.attributes.length; i++)
tag.appendChild(createAttribute(node.attributes[i])); tag.appendChild(createAttribute(node.attributes[i]));
} }
var stringAfterAttrs = ''; var stringAfterAttrs = '';
if (isEmpty) if (isEmpty)
stringAfterAttrs += '/'; stringAfterAttrs += '/';
stringAfterAttrs += '>'; stringAfterAttrs += '>';
var textAfterAttrs = document.createTextNode(stringAfterAttrs); var textAfterAttrs = document.createTextNode(stringAfterAttrs);
tag.appendChild(textAfterAttrs); tag.appendChild(textAfterAttrs);
return tag; return tag;
} }
function createAttribute(attributeNode) function createAttribute(attributeNode)
{ {
var attribute = createHTMLElement('span'); var attribute = createHTMLElement('span');
attribute.classList.add('html-attribute'); attribute.classList.add('html-attribute');
var attributeName = createHTMLElement('span'); var attributeName = createHTMLElement('span');
attributeName.classList.add('html-attribute-name'); attributeName.classList.add('html-attribute-name');
attributeName.textContent = attributeNode.name; attributeName.textContent = attributeNode.name;
var textBefore = document.createTextNode(' '); var textBefore = document.createTextNode(' ');
var textBetween = document.createTextNode('="'); var textBetween = document.createTextNode('="');
var attributeValue = createHTMLElement('span'); var attributeValue = createHTMLElement('span');
attributeValue.classList.add('html-attribute-value'); attributeValue.classList.add('html-attribute-value');
attributeValue.textContent = attributeNode.value; attributeValue.textContent = attributeNode.value;
var textAfter = document.createTextNode('"'); var textAfter = document.createTextNode('"');
attribute.appendChild(textBefore); attribute.appendChild(textBefore);
attribute.appendChild(attributeName); attribute.appendChild(attributeName);
attribute.appendChild(textBetween); attribute.appendChild(textBetween);
attribute.appendChild(attributeValue); attribute.appendChild(attributeValue);
attribute.appendChild(textAfter); attribute.appendChild(textAfter);
return attribute; return attribute;
} }
function toggleFunction(sectionId) { function toggleFunction(sectionId) {
return function() { return function() {
var foldedContent = var foldedContent = document.querySelector('#' + sectionId + ' > .folded');
document.querySelector('#' + sectionId + ' > .folded'); var openedContent = document.querySelector('#' + sectionId + ' > .opened');
var openedContent = var folderButton =
document.querySelector('#' + sectionId + ' > .opened'); document.querySelector('#' + sectionId + ' > .line > .folder-button');
var folderButton = document.querySelector(
'#' + sectionId + ' > .line > .folder-button'); if (foldedContent) {
if (foldedContent.className.includes('hidden'))
if (foldedContent) { foldedContent.className = 'folded';
if (foldedContent.className.includes('hidden')) else
foldedContent.className = 'folded'; foldedContent.className = 'folded hidden';
else }
foldedContent.className = 'folded hidden';
} if (openedContent) {
if (openedContent.className.includes('hidden'))
if (openedContent) { openedContent.className = 'opened';
if (openedContent.className.includes('hidden')) else
openedContent.className = 'opened'; openedContent.className = 'opened hidden';
else }
openedContent.className = 'opened hidden';
} if (folderButton) {
if (folderButton.className.includes('open'))
if (folderButton) { folderButton.className = 'folder-button fold';
if (folderButton.className.includes('open')) else
folderButton.className = 'folder-button fold'; folderButton.className = 'folder-button open';
else }
folderButton.className = 'folder-button open'; };
}
};
} }
function initButtons() function initButtons()
{ {
var sections = document.querySelectorAll('.folder'); var sections = document.querySelectorAll('.folder');
for (var i = 0; i < sections.length; i++) { for (var i = 0; i < sections.length; i++) {
var sectionId = 'folder' + i; var sectionId = 'folder' + i;
sections[i].id = sectionId; sections[i].id = sectionId;
var folderButton = sections[i].querySelector('.folder-button'); var folderButton = sections[i].querySelector('.folder-button');
folderButton.onclick = toggleFunction(sectionId); folderButton.onclick = toggleFunction(sectionId);
folderButton.onmousedown = handleButtonMouseDown; folderButton.onmousedown = handleButtonMouseDown;
} }
} }
function handleButtonMouseDown(e) function handleButtonMouseDown(e)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment