From b8e12fbe7bf4e17a82183345f4e9f934b7ddfc4f Mon Sep 17 00:00:00 2001 From: John Foerch Date: Sun, 7 Jun 2009 14:40:51 -0400 Subject: [PATCH] whitespace and style cleanup view_source_use_external_editor and view_source_function rewritten in define_variable forms with documentation. --- modules/content-buffer.js | 138 ++++++++++++++++++++++++---------------------- modules/element.js | 65 ++++++++++++---------- modules/save.js | 22 +++----- 3 files changed, 118 insertions(+), 107 deletions(-) diff --git a/modules/content-buffer.js b/modules/content-buffer.js index 357e485..3b8dd9f 100644 --- a/modules/content-buffer.js +++ b/modules/content-buffer.js @@ -32,12 +32,10 @@ define_current_buffer_hook("current_content_buffer_overlink_change_hook", "conte /* If browser is null, create a new browser */ define_keywords("$load"); -function content_buffer(window, element) -{ +function content_buffer (window, element) { keywords(arguments); this.constructor_begin(); try { - conkeror.buffer.call(this, window, element, forward_keywords(arguments)); this.browser.addProgressListener(this); @@ -119,7 +117,6 @@ content_buffer.prototype = { get scrollMaxX () { return this.top_frame.scrollMaxX; }, get scrollMaxY () { return this.top_frame.scrollMaxY; }, - /* Used to display the correct URI when the buffer opens initially * even before loading has progressed far enough for currentURI to * contain the correct URI. */ @@ -133,7 +130,7 @@ content_buffer.prototype = { return ""; }, - get title() { return this.browser.contentTitle; }, + get title () { return this.browser.contentTitle; }, get description () { return this.display_URI_string; }, load : function (load_spec) { @@ -148,7 +145,7 @@ content_buffer.prototype = { QueryInterface: generate_QI(Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference), // This method is called to indicate state changes. - onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) { + onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) { /* const WPL = Components.interfaces.nsIWebProgressListener; @@ -173,8 +170,7 @@ content_buffer.prototype = { if (aStateFlags & Ci.nsIWebProgressListener.STATE_START) { this._request_count++; - } - else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) { + } else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) { const NS_ERROR_UNKNOWN_HOST = 2152398878; if (--this._request_count > 0 && aStatus == NS_ERROR_UNKNOWN_HOST) { // to prevent bug 235825: wait for the request handled @@ -197,10 +193,9 @@ content_buffer.prototype = { this.loading = true; content_buffer_started_loading_hook.run(this); this.last_user_input_received = null; - } - else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) { - if (this.loading == true) { + } else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && + aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) { + if (this.loading == true) { //dumpln("*** finished loading"); this.loading = false; content_buffer_finished_loading_hook.run(this); @@ -216,14 +211,14 @@ content_buffer.prototype = { /* This method is called to indicate progress changes for the currently loading page. */ - onProgressChange: function(webProgress, request, curSelf, maxSelf, - curTotal, maxTotal) { + onProgressChange: function (webProgress, request, curSelf, maxSelf, + curTotal, maxTotal) { content_buffer_progress_change_hook.run(this, request, curSelf, maxSelf, curTotal, maxTotal); }, /* This method is called to indicate a change to the current location. The url can be gotten as location.spec. */ - onLocationChange : function(webProgress, request, location) { + onLocationChange : function (webProgress, request, location) { /* Attempt to ignore onLocationChange calls due to the initial * loading of about:blank by all xul:browser elements. */ if (location.spec == "about:blank" && this.ignore_initial_blank) @@ -242,13 +237,13 @@ content_buffer.prototype = { // This method is called to indicate a status changes for the currently // loading page. The message is already formatted for display. // Status messages could be displayed in the minibuffer output area. - onStatusChange: function(webProgress, request, status, msg) { + onStatusChange: function (webProgress, request, status, msg) { this.set_default_message(msg); content_buffer_status_change_hook.run(this, request, status, msg); }, // This method is called when the security state of the browser changes. - onSecurityChange: function(webProgress, request, state) { + onSecurityChange: function (webProgress, request, state) { /* FIXME: currently this isn't used */ /* @@ -299,42 +294,54 @@ define_variable("read_url_handler_list", [], "null. The result of the first function on the list that returns a " + "string is used in place of the input."); -/* read_url_make_default_webjump_handler returns a function that +/** + * read_url_make_default_webjump_handler returns a function that * transforms any input into the given webjump. It should be the last * handler on read_url_handler_list (because any input is - * accepted). */ -function read_url_make_default_webjump_handler(default_webjump) { - return function(input) { + * accepted). + */ +function read_url_make_default_webjump_handler (default_webjump) { + return function (input) { return default_webjump + " " + input; }; } -/* read_url_make_blank_url_handler returns a function that replaces a +/** + * read_url_make_blank_url_handler returns a function that replaces a * blank (empty) input with the given url (or webjump). The url may - * perform some function, eg. "javascript:location.reload()". */ -function read_url_make_blank_url_handler(url) { - return function(input) { + * perform some function, eg. "javascript:location.reload()". + */ +function read_url_make_blank_url_handler (url) { + return function (input) { if (input.length == 0) return url; return null; }; } -minibuffer.prototype.try_read_url_handlers = function(input) { +minibuffer.prototype.try_read_url_handlers = function (input) { var result; - for (var i = 0; i < read_url_handler_list.length; ++i) + for (var i = 0; i < read_url_handler_list.length; ++i) { if ((result = read_url_handler_list[i](input))) return result; + } return input; } -define_variable("url_completion_use_webjumps", true, "Specifies whether URL completion should complete webjumps."); -define_variable("url_completion_use_bookmarks", true, "Specifies whether URL completion should complete bookmarks."); +define_variable("url_completion_use_webjumps", true, + "Specifies whether URL completion should complete webjumps."); + +define_variable("url_completion_use_bookmarks", true, + "Specifies whether URL completion should complete bookmarks."); + define_variable("url_completion_use_history", false, - "Specifies whether URL completion should complete using browser history."); + "Specifies whether URL completion should complete using browser "+ + "history."); define_variable("minibuffer_read_url_select_initial", true, - "Specifies whether a URL presented in the minibuffer for editing should be selected. This affects find-alternate-url."); + "Specifies whether a URL presented in the minibuffer for editing "+ + "should be selected. This affects find-alternate-url."); + minibuffer_auto_complete_preferences["url"] = true; minibuffer.prototype.read_url = function () { @@ -342,7 +349,7 @@ minibuffer.prototype.read_url = function () { $use_webjumps = url_completion_use_webjumps, $use_history = url_completion_use_history, $use_bookmarks = url_completion_use_bookmarks); - var completer = url_completer ($use_webjumps = arguments.$use_webjumps, + var completer = url_completer($use_webjumps = arguments.$use_webjumps, $use_bookmarks = arguments.$use_bookmarks, $use_history = arguments.$use_history); var result = yield this.read( @@ -381,7 +388,7 @@ I.content_selection = interactive_method( return focusedWindow.getSelection (); }); */ -function overlink_update_status(buffer, text) { +function overlink_update_status (buffer, text) { if (text.length > 0) buffer.window.minibuffer.show("Link: " + text); else @@ -399,15 +406,13 @@ define_global_mode("overlink_mode", overlink_mode(true); -function go_back (b, prefix) -{ +function go_back (b, prefix) { if (prefix < 0) go_forward(b, -prefix); check_buffer(b, content_buffer); - if (b.web_navigation.canGoBack) - { + if (b.web_navigation.canGoBack) { var hist = b.web_navigation.sessionHistory; var idx = hist.index - prefix; if (idx < 0) @@ -416,20 +421,19 @@ function go_back (b, prefix) } else throw interactive_error("Can't go back"); } -interactive( - "go-back", + +interactive("go-back", "Go back in the session history for the current buffer.", function (I) {go_back(I.buffer, I.p);}); -function go_forward (b, prefix) -{ + +function go_forward (b, prefix) { if (prefix < 0) go_back(b, -prefix); check_buffer(b, content_buffer); - if (b.web_navigation.canGoForward) - { + if (b.web_navigation.canGoForward) { var hist = b.web_navigation.sessionHistory; var idx = hist.index + prefix; if (idx >= hist.count) idx = hist.count-1; @@ -437,21 +441,23 @@ function go_forward (b, prefix) } else throw interactive_error("Can't go forward"); } + interactive("go-forward", "Go back in the session history for the current buffer.", function (I) {go_forward(I.buffer, I.p);}); -function stop_loading (b) -{ + +function stop_loading (b) { check_buffer(b, content_buffer); b.web_navigation.stop(Ci.nsIWebNavigation.STOP_NETWORK); } + interactive("stop-loading", "Stop loading the current document.", function (I) {stop_loading(I.buffer);}); -function reload (b, bypass_cache, element, forced_charset) -{ + +function reload (b, bypass_cache, element, forced_charset) { check_buffer(b, content_buffer); if (element) { if (element instanceof Ci.nsIDOMHTMLImageElement) { @@ -482,40 +488,42 @@ function reload (b, bypass_cache, element, forced_charset) b.web_navigation.reload(flags); } } + interactive("reload", - "Reload the current document.\n" + - "If a prefix argument is specified, the cache is bypassed. If a "+ - "DOM node is supplied via browser object, that node will be "+ - "reloaded.", - function (I) { - check_buffer(I.buffer, content_buffer); - var element = yield read_browser_object(I); - reload(I.buffer, I.P, element); - }); + "Reload the current document.\n" + + "If a prefix argument is specified, the cache is bypassed. If a "+ + "DOM node is supplied via browser object, that node will be "+ + "reloaded.", + function (I) { + check_buffer(I.buffer, content_buffer); + var element = yield read_browser_object(I); + reload(I.buffer, I.P, element); + }); /** * browserDOMWindow: intercept window opening */ -function initialize_browser_dom_window(window) { +function initialize_browser_dom_window (window) { window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new browser_dom_window(window); } define_variable("browser_default_open_target", OPEN_NEW_BUFFER, - "Specifies how new window requests by content pages "+ - "(e.g. by window.open from JavaScript or by using the "+ - "target attribute of anchor and form elements) will be "+ - "handled. This will generally be `OPEN_NEW_BUFFER', "+ - "`OPEN_NEW_BUFFER_BACKGROUND', or `OPEN_NEW_WINDOW'."); + "Specifies how new window requests by content pages (e.g. by "+ + "window.open from JavaScript or by using the target attribute of "+ + "anchor and form elements) will be handled. This will generally "+ + "be `OPEN_NEW_BUFFER', `OPEN_NEW_BUFFER_BACKGROUND', or "+ + "`OPEN_NEW_WINDOW'."); + -function browser_dom_window(window) { +function browser_dom_window (window) { this.window = window; this.next_target = null; } browser_dom_window.prototype = { QueryInterface: generate_QI(Ci.nsIBrowserDOMWindow), - openURI : function(aURI, aOpener, aWhere, aContext) { + openURI : function (aURI, aOpener, aWhere, aContext) { // Reference: http://www.xulplanet.com/references/xpcomref/ifaces/nsIBrowserDOMWindow.html var target = this.next_target; @@ -599,7 +607,7 @@ ignore_function_for_get_caller_source_code_reference("define_page_mode"); define_variable("auto_mode_list", [], "A list of mappings from URI regular expressions to page modes."); -function page_mode_auto_update(buffer) { +function page_mode_auto_update (buffer) { var uri = buffer.current_URI.spec; var mode = predicate_alist_match(auto_mode_list, uri); if (mode) diff --git a/modules/element.js b/modules/element.js index bb21e20..2017e4b 100644 --- a/modules/element.js +++ b/modules/element.js @@ -82,7 +82,7 @@ define_browser_object_class( define_browser_object_class( "mathml", "MathML element", null, - xpath_browser_object_handler ("//m:math")); + xpath_browser_object_handler("//m:math")); define_browser_object_class( "top", null, null, @@ -109,7 +109,7 @@ define_browser_object_class( $prompt = prompt, $history = I.command.name+"/file", $initial_value = I.local.cwd.path); - yield co_return (result); + yield co_return(result); }); define_browser_object_class( @@ -119,7 +119,7 @@ define_browser_object_class( $buffer = I.buffer, $prompt = prompt, $hint_xpath_expression = "//img[@alt]"); - yield (co_return (result.alt)); + yield co_return(result.alt); }); define_browser_object_class( @@ -129,7 +129,7 @@ define_browser_object_class( $buffer = I.buffer, $prompt = prompt, $hint_xpath_expression = "//*[@title]"); - yield (co_return (result.title)); + yield co_return(result.title); }); define_browser_object_class( @@ -139,7 +139,7 @@ define_browser_object_class( $buffer = I.buffer, $prompt = prompt, $hint_xpath_expression = "//img[@alt] | //*[@title]"); - yield (co_return (result.title ? result.title : result.alt)); + yield co_return(result.title ? result.title : result.alt); }); define_browser_object_class( @@ -217,19 +217,19 @@ function browser_element_focus (buffer, elem) { if (!element_dom_node_or_window_p(elem)) return; - if (elem instanceof Ci.nsIDOMXULTextBoxElement) { - // Focus the input field instead - elem = elem.wrappedJSObject.inputField; - } + if (elem instanceof Ci.nsIDOMXULTextBoxElement) + elem = elem.wrappedJSObject.inputField; // focus the input field browser_set_element_focus(buffer, elem); - if (elem instanceof Ci.nsIDOMWindow) { + if (elem instanceof Ci.nsIDOMWindow) return; - } + // If it is not a window, it must be an HTML element var x = 0; var y = 0; - if (elem instanceof Ci.nsIDOMHTMLFrameElement || elem instanceof Ci.nsIDOMHTMLIFrameElement) { + if (elem instanceof Ci.nsIDOMHTMLFrameElement || + elem instanceof Ci.nsIDOMHTMLIFrameElement) + { elem.contentWindow.focus(); return; } @@ -246,8 +246,7 @@ function browser_element_focus (buffer, elem) { elem.dispatchEvent(evt); } -function browser_object_follow(buffer, target, elem) -{ +function browser_object_follow (buffer, target, elem) { // XXX: would be better to let nsILocalFile objects be load_specs if (elem instanceof Ci.nsILocalFile) elem = elem.path; @@ -342,7 +341,7 @@ function follow (I, target) { target = FOLLOW_DEFAULT; I.target = target; if (target == OPEN_CURRENT_BUFFER) - check_buffer (I.buffer, content_buffer); + check_buffer(I.buffer, content_buffer); var element = yield read_browser_object(I); try { element = load_spec(element); @@ -373,7 +372,7 @@ function follow_current_buffer (I) { } -function element_get_load_target_label(element) { +function element_get_load_target_label (element) { if (element instanceof Ci.nsIDOMWindow) return "page"; if (element instanceof Ci.nsIDOMHTMLFrameElement) @@ -383,7 +382,7 @@ function element_get_load_target_label(element) { return null; } -function element_get_operation_label(element, op_name, suffix) { +function element_get_operation_label (element, op_name, suffix) { var target_label = element_get_load_target_label(element); if (target_label != null) target_label = " " + target_label; @@ -399,8 +398,7 @@ function element_get_operation_label(element, op_name, suffix) { } -function browser_element_copy(buffer, elem) -{ +function browser_element_copy (buffer, elem) { var spec; try { spec = load_spec(elem); @@ -426,16 +424,25 @@ function browser_element_copy(buffer, elem) } } browser_set_element_focus(buffer, elem); - writeToClipboard (text); - buffer.window.minibuffer.message ("Copied: " + text); + writeToClipboard(text); + buffer.window.minibuffer.message("Copied: " + text); } -var view_source_use_external_editor = false, view_source_function = null; -function browser_object_view_source(buffer, target, elem) -{ - if (view_source_use_external_editor || view_source_function) - { +define_variable("view_source_use_external_editor", false, + "When true, the `view-source' command will send its document to "+ + "your external editor."); + +define_variable("view_source_function", null, + "May be set to a user-defined function for viewing source code. "+ + "The function should accept an nsILocalFile of the filename as "+ + "its one positional argument, and it will also be called with "+ + "the keyword `$temporary', whose value will be true if the file "+ + "is considered temporary, and therefore the function must take "+ + "responsibility for deleting it."); + +function browser_object_view_source (buffer, target, elem) { + if (view_source_use_external_editor || view_source_function) { var spec = load_spec(elem); let [file, temp] = yield download_as_temporary(spec, @@ -456,7 +463,7 @@ function browser_object_view_source(buffer, target, elem) win = elem.contentWindow; break; case "math": - view_mathml_source (window, charset, elem); + view_mathml_source(window, charset, elem); return; default: throw new Error("Invalid browser element"); @@ -477,8 +484,10 @@ function browser_object_view_source(buffer, target, elem) function view_source (I, target) { I.target = target; + if (target == null) + target = OPEN_CURRENT_BUFFER; var element = yield read_browser_object(I); - yield browser_object_view_source(I.buffer, (target == null ? OPEN_CURRENT_BUFFER : target), element); + yield browser_object_view_source(I.buffer, target, element); } function view_source_new_buffer (I) { diff --git a/modules/save.js b/modules/save.js index 9ed4794..f69ac2b 100644 --- a/modules/save.js +++ b/modules/save.js @@ -13,7 +13,7 @@ require("suggest-file-name.js"); /* buffer is used only to associate with the download */ define_keywords("$use_cache", "$buffer", "$prepare_download", "$temp_file"); -function save_uri(lspec, output_file) { +function save_uri (lspec, output_file) { keywords(arguments, $use_cache = true); var use_cache = arguments.$use_cache; @@ -90,7 +90,7 @@ const SAVEMODE_COMPLETE_DOM = 0x01; // We have a DOM which we can serialize as text. const SAVEMODE_COMPLETE_TEXT = 0x02; -function get_save_mode_from_content_type(content_type) { +function get_save_mode_from_content_type (content_type) { var mode = SAVEMODE_FILEONLY; switch (content_type) { case "text/html": @@ -106,8 +106,7 @@ function get_save_mode_from_content_type(content_type) { } define_keywords("$use_cache", "$buffer", "$wrap_column", "$prepare_download"); -function save_document_as_text(document, output_file) -{ +function save_document_as_text (document, output_file) { keywords(arguments, $use_cache = true, $wrap_column = 80); var mode = get_save_mode_from_content_type(document.contentType); @@ -137,14 +136,11 @@ function save_document_as_text(document, output_file) Ci.nsIWebBrowserPersist.ENCODE_FLAGS_ABSOLUTE_LINKS | Ci.nsIWebBrowserPersist.ENCODE_FLAGS_NOFRAMES_CONTENT; - if (use_cache) persist.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_FROM_CACHE; else persist.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_BYPASS_CACHE; - - var info = register_download(buffer, uri); if (prepare_download) prepare_download(info); @@ -163,7 +159,7 @@ function save_document_as_text(document, output_file) } define_keywords("$use_cache", "$buffer", "$prepare_download"); -function save_document_complete(document, output_file, output_dir) { +function save_document_complete (document, output_file, output_dir) { keywords(arguments); var mime_type = document.contentType; @@ -216,7 +212,7 @@ function save_document_complete(document, output_file, output_dir) { return info; } -function download_failed_error() { +function download_failed_error () { var e = new Error("Download failed"); e.__proto__ = download_failed_error.prototype; return e; @@ -229,7 +225,7 @@ download_failed_error.prototype.__proto__ = Error.prototype; * done with it. */ define_keywords("$action", "$shell_command", "$shell_command_cwd", "$buffer", "$use_cache"); -function download_as_temporary(lspec) { +function download_as_temporary (lspec) { keywords(arguments, $use_cache = true); var action_description = arguments.$action; @@ -238,19 +234,17 @@ function download_as_temporary(lspec) { var uri = load_spec_uri(lspec); // If it is local file, there is no need to download it - if (uri.scheme == "file") - { + if (uri.scheme == "file") { let file = uri.QueryInterface(Ci.nsIFileURL).file; yield co_return([file, false /* not temporary */]); } - var file = get_temporary_file(suggest_file_name(lspec)); var cc = yield CONTINUATION; - function handle_state_change(info) { + function handle_state_change (info) { var state = info.state; switch (state) { case DOWNLOAD_CANCELED: -- 2.11.4.GIT