bug 203069: Unable to search in page-source

sync'ing with seamonkey, use gBrowser instead of getBrowser()
This commit is contained in:
chanial%noos.fr 2003-04-27 05:02:28 +00:00
Родитель 735f25e3fc
Коммит 87d41981ad
4 изменённых файлов: 86 добавлений и 82 удалений

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

@ -56,7 +56,8 @@ const MARK_SELECTION_START = '\u200B\u200B\u200B\u200B\u200B';
const MARK_SELECTION_END = '\u200B\u200B\u200B\u200B\u200B';
function onLoadViewPartialSource()
{
{
gBrowser = document.getElementById("content");
// check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
if (gPrefs) {
try {
@ -66,6 +67,12 @@ function onLoadViewPartialSource()
gWrapLongLines = true;
}
} catch (e) { }
try {
document.getElementById("menu_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
} catch (e) {
}
} else {
document.getElementById("menu_highlightSyntax").setAttribute("hidden", "true");
}
// disable menu items that don't work since the selection is munged and
@ -101,12 +108,20 @@ function viewPartialSourceForSelection(selection)
ancestorContainer.nodeType == Node.CDATA_SECTION_NODE)
ancestorContainer = ancestorContainer.parentNode;
// for selectAll, let's use the entire document, including <html>...</html>
// @see DocumentViewerImpl::SelectAll() for how selectAll is implemented
try {
if (ancestorContainer == doc.body)
ancestorContainer = doc.documentElement;
} catch (e) { }
// each path is a "child sequence" (a.k.a. "tumbler") that
// descends from the ancestor down to the boundary point
var startPath = getPath(ancestorContainer, startContainer);
var endPath = getPath(ancestorContainer, endContainer);
// clone the fragment of interest and reset everything to be relative to it
// note: it is with the clone that we operate from now on
ancestorContainer = ancestorContainer.cloneNode(true);
startContainer = ancestorContainer;
endContainer = ancestorContainer;
@ -130,7 +145,7 @@ function viewPartialSourceForSelection(selection)
// To get a neat output, the idea here is to remap the end point from:
// 1. ...<tag>]... to ...]<tag>...
// 2. ...]</tag>... to ...</tag>]...
if ((endOffset > 0 && endOffset < endContainer.data.length-1) ||
if ((endOffset > 0 && endOffset < endContainer.data.length) ||
!endContainer.parentNode || !endContainer.parentNode.parentNode)
endContainer.insertData(endOffset, MARK_SELECTION_END);
else {
@ -154,8 +169,9 @@ function viewPartialSourceForSelection(selection)
// To get a neat output, the idea here is to remap the start point from:
// 1. ...<tag>[... to ...[<tag>...
// 2. ...[</tag>... to ...</tag>[...
if ((startOffset > 0 && startOffset < startContainer.data.length-1) ||
!startContainer.parentNode || !startContainer.parentNode.parentNode)
if ((startOffset > 0 && startOffset < startContainer.data.length) ||
!startContainer.parentNode || !startContainer.parentNode.parentNode ||
startContainer != startContainer.parentNode.lastChild)
startContainer.insertData(startOffset, MARK_SELECTION_START);
else {
tmpNode = doc.createTextNode(MARK_SELECTION_START);
@ -181,8 +197,8 @@ function viewPartialSourceForSelection(selection)
// all our content is held by the data:URI and URIs are internally stored as utf-8 (see nsIURI.idl)
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
getBrowser().webNavigation
.loadURI("view-source:data:text/html;charset=utf-8," + escape(tmpNode.innerHTML),
gBrowser.webNavigation
.loadURI("view-source:data:text/html;charset=utf-8," + escape(tmpNode.innerHTML),
loadFlags, null, null, null);
}
@ -213,7 +229,7 @@ function getPath(ancestor, node)
////////////////////////////////////////////////////////////////////////////////
// using special markers left in the serialized source, this helper makes the
// underlying markup of the selected fragement to automatically appear as selected
// underlying markup of the selected fragment to automatically appear as selected
// on the inflated view-source DOM
function drawSelection()
{
@ -237,10 +253,10 @@ function drawSelection()
var replaceString = findService.replaceString;
// setup our find instance
var findInst = getBrowser().webBrowserFind;
var findInst = gBrowser.webBrowserFind;
findInst.matchCase = true;
findInst.entireWord = false;
findInst.wrapFind = false;
findInst.wrapFind = true;
findInst.findBackwards = false;
// ...lookup the start mark
@ -248,7 +264,7 @@ function drawSelection()
var startLength = MARK_SELECTION_START.length;
findInst.findNext();
var contentWindow = getBrowser().contentDocument.defaultView;
var contentWindow = gBrowser.contentDocument.defaultView;
var selection = contentWindow.getSelection();
var range = selection.getRangeAt(0);
@ -279,11 +295,11 @@ function drawSelection()
// the selection, whereas in this situation, it is more user-friendly
// to scroll at the beginning. So we override the default behavior here
try {
getBrowser().docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController)
.scrollSelectionIntoView(Components.interfaces.nsISelectionController.SELECTION_NORMAL,
gBrowser.docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController)
.scrollSelectionIntoView(Components.interfaces.nsISelectionController.SELECTION_NORMAL,
Components.interfaces.nsISelectionController.SELECTION_ANCHOR_REGION,
true);
}
@ -343,7 +359,7 @@ function viewPartialSourceForFragment(node, context)
; // end
// display
var doc = getBrowser().contentDocument;
var doc = gBrowser.contentDocument;
doc.open("text/html", "replace");
doc.write(source);
doc.close();
@ -442,39 +458,44 @@ function getOuterMarkup(node, indent) {
////////////////////////////////////////////////////////////////////////////////
function unicodeTOentity(text)
{
const charTable = {
'&': '&amp;<span class="entity">amp;</span>',
'<': '&amp;<span class="entity">lt;</span>',
'>': '&amp;<span class="entity">gt;</span>',
'"': '&amp;<span class="entity">quot;</span>'
};
function charTableLookup(letter) {
return charTable[letter];
}
function convertEntity(letter) {
try {
var unichar = gEntityConverter.ConvertToEntity(letter, entityVersion);
var entity = unichar.substring(1); // extract '&'
return '&amp;<span class="entity">' + entity + '</span>';
} catch (ex) {
return letter;
}
}
if (!gEntityConverter) {
try {
gEntityConverter = Components.classes["@mozilla.org/intl/entityconverter;1"]
.createInstance(Components.interfaces.nsIEntityConverter);
gEntityConverter =
Components.classes["@mozilla.org/intl/entityconverter;1"]
.createInstance(Components.interfaces.nsIEntityConverter);
} catch(e) { }
}
var entityVersion = Components.interfaces.nsIEntityConverter.html40
+ Components.interfaces.nsIEntityConverter.mathml20;
var str = '';
for (var i = 0; i < text.length; i++) {
var c = text.charCodeAt(i);
if ((c <= 0x7F) || !gEntityConverter) {
if (text[i] == '<')
str += '&amp;<span class="entity">lt;</span>';
else if (text[i] == '>')
str += '&amp;<span class="entity">gt;</span>';
else if (text[i] == '&')
str += '&amp;<span class="entity">amp;</span>';
else
str += text[i];
}
else {
try {
var unichar = gEntityConverter.ConvertToEntity(text[i], entityVersion);
str += '&amp;<span class="entity">'
+ unichar.substring(1, unichar.length) // extract '&'
+ '</span>';
}
catch(e) {
str += text[i];
}
}
}
const entityVersion = Components.interfaces.nsIEntityConverter.entityW3C;
var str = text;
// replace chars in our charTable
str = str.replace(/[<>&"]/g, charTableLookup);
// replace chars > 0x7f via nsIEntityConverter
str = str.replace(/[^\0-\u007f]/g, convertEntity);
return str;
}

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

@ -23,7 +23,6 @@
const pageLoaderIface = Components.interfaces.nsIWebPageDescriptor;
var gBrowser = null;
var appCore = null;
var gPrefs = null;
try {
@ -35,15 +34,9 @@ try {
function onLoadViewSource()
{
gBrowser = document.getElementById("content");
viewSource(window.arguments[0]);
window._content.focus();
}
function getBrowser()
{
if (!gBrowser)
gBrowser = document.getElementById("content");
return gBrowser;
document.commandDispatcher.focusedWindow = content;
}
function viewSource(url)
@ -51,18 +44,6 @@ function viewSource(url)
if (!url)
return false; // throw Components.results.NS_ERROR_FAILURE;
try {
appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
.createInstance(Components.interfaces.nsIBrowserInstance);
// Initialize browser instance..
appCore.setWebShellWindow(window);
} catch(ex) {
// Give up.
window.close();
return false;
}
var loadFromURL = true;
//
// Parse the 'arguments' supplied with the dialog.
@ -99,7 +80,7 @@ function viewSource(url)
try {
if (typeof(arg) == "object" && arg != null) {
var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
//
// Load the page using the page descriptor rather than the URL.
@ -123,7 +104,7 @@ function viewSource(url)
//
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
var viewSrcUrl = "view-source:" + url;
getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
gBrowser.webNavigation.loadURI(viewSrcUrl, loadFlags, null, null, null);
}
//check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
@ -136,11 +117,11 @@ function viewSource(url)
} catch (ex) {
}
try {
document.getElementById("cmd_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
document.getElementById("menu_highlightSyntax").setAttribute("checked", gPrefs.getBoolPref("view_source.syntax_highlight"));
} catch (ex) {
}
} else {
document.getElementById("cmd_highlightSyntax").setAttribute("hidden", "true");
document.getElementById("menu_highlightSyntax").setAttribute("hidden", "true");
}
window._content.focus();
@ -200,20 +181,24 @@ function wrapLongLines()
//pref to persist the last state
function highlightSyntax()
{
var highlightSyntaxCmd = document.getElementById("cmd_highlightSyntax");
var highlightSyntax = highlightSyntaxCmd.getAttribute("checked") != "true";
highlightSyntaxCmd.setAttribute("checked", highlightSyntax);
var highlightSyntaxMenu = document.getElementById("menu_highlightSyntax");
var highlightSyntax = (highlightSyntaxMenu.getAttribute("checked") == "true");
gPrefs.setBoolPref("view_source.syntax_highlight", highlightSyntax);
var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
PageLoader.LoadPage(PageLoader.currentDescriptor, pageLoaderIface.DISPLAY_NORMAL);
}
function BrowserSetForcedCharacterSet(aCharset)
{
var docCharset = getBrowser().docShell.QueryInterface(
Components.interfaces.nsIDocCharset);
var docCharset = gBrowser.docShell
.QueryInterface(Components.interfaces.nsIDocCharset);
docCharset.charset = aCharset;
var PageLoader = getBrowser().webNavigation.QueryInterface(pageLoaderIface);
var PageLoader = gBrowser.webNavigation.QueryInterface(pageLoaderIface);
PageLoader.LoadPage(PageLoader.currentDescriptor, pageLoaderIface.DISPLAY_NORMAL);
}
function BrowserFind()
{
findInPage(gBrowser, window._content, window._content)
}

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

@ -57,7 +57,6 @@
screenX="10" screenY="10"
persist="screenX screenY width height sizemode">
<commandset id="commands"/>
<keyset id="viewSourceKeys"/>
<stringbundleset id="viewSource-stringbundleset"/>

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

@ -53,9 +53,8 @@
<script type="application/x-javascript" src="chrome://global/content/nsJSComponentManager.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaDD.js"/>
<script type="application/x-javascript" src="chrome://navigator/content/browser.js"/>
<script type="application/x-javascript" src="chrome://global/content/viewSource.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/findUtils.js"/>
<script type="application/x-javascript" src="chrome://global/content/findUtils.js"/>
<script type="application/x-javascript" src="chrome://browser/content/contentAreaUtils.js"/>
<commandset id="commands">
@ -144,9 +143,9 @@
<menu label="&viewMenu.label;" accesskey="&viewMenu.accesskey;">
<menupopup>
<menu id="charsetMenu"/>
<menuitem id="menu_wrapLongLines" type="checkbox" command="cmd_wrapLongLines"
<menuitem id="menu_wrapLongLines" type="checkbox" oncommand="wrapLongLines()"
label="&menu_wrapLongLines.title;" accesskey="&menu_wrapLongLines.accesskey;"/>
<menuitem type="checkbox" command="cmd_highlightSyntax"
<menuitem type="checkbox" id="menu_highlightSyntax" oncommand="highlightSyntax();"
label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
</menupopup>
</menu>