Commit 7fc7f149 authored by Dão Gottwald's avatar Dão Gottwald
Browse files

Bug 1497814 - Clean up UrlbarInput getters and setters. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D8188

--HG--
extra : moz-landing-system : lando
parent e61cc054
......@@ -50,11 +50,12 @@ class UrlbarInput {
this.userInitiatedFocus = false;
this.isPrivate = PrivateBrowsingUtils.isWindowPrivate(this.window);
// Forward textbox methods and properties.
const METHODS = ["addEventListener", "removeEventListener",
"setAttribute", "hasAttribute", "removeAttribute", "getAttribute",
"focus", "blur", "select"];
const READ_ONLY_PROPERTIES = ["focused", "inputField", "editor"];
const READ_WRITE_PROPERTIES = ["value", "placeholder", "readOnly",
const READ_ONLY_PROPERTIES = ["inputField", "editor"];
const READ_WRITE_PROPERTIES = ["placeholder", "readOnly",
"selectionStart", "selectionEnd"];
for (let method of METHODS) {
......@@ -67,10 +68,6 @@ class UrlbarInput {
Object.defineProperty(this, property, {
enumerable: true,
get() {
let getter = "_get_" + property;
if (getter in this) {
return this[getter]();
}
return this.textbox[property];
},
});
......@@ -80,17 +77,9 @@ class UrlbarInput {
Object.defineProperty(this, property, {
enumerable: true,
get() {
let getter = "_get_" + property;
if (getter in this) {
return this[getter]();
}
return this.textbox[property];
},
set(val) {
let setter = "_set_" + property;
if (setter in this) {
return this[setter](val);
}
return this.textbox[property] = val;
},
});
......@@ -113,12 +102,15 @@ class UrlbarInput {
this.inputField.controllers.insertControllerAt(0, new CopyCutController(this));
}
/* Shortens the given value, usually by removing http:// and trailing slashes,
/**
* Shortens the given value, usually by removing http:// and trailing slashes,
* such that calling nsIURIFixup::createFixupURI with the result will produce
* the same URI.
*
* @param {string} val
* The string to be trimmed if it appears to be URI
* @returns {string}
* The trimmed string
*/
trimValue(val) {
return UrlbarPrefs.get("trimURLs") ? this.window.trimURL(val) : val;
......@@ -179,11 +171,15 @@ class UrlbarInput {
// Getters and Setters below.
_get_focused() {
return this.inputField.getAttribute("focused") == "true";
get focused() {
return this.textbox.getAttribute("focused") == "true";
}
get value() {
return this.inputField.value;
}
_set_value(val) {
set value(val) {
val = this.trimValue(val);
this.valueIsTyped = false;
......
Supports Markdown
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