responsivedesign.jsm 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. const Ci = Components.interfaces;
  6. const Cu = Components.utils;
  7. var {loader, require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
  8. var Telemetry = require("devtools/client/shared/telemetry");
  9. var {showDoorhanger} = require("devtools/client/shared/doorhanger");
  10. var {TouchEventSimulator} = require("devtools/shared/touch/simulator");
  11. var {Task} = require("devtools/shared/task");
  12. var promise = require("promise");
  13. var DevToolsUtils = require("devtools/shared/DevToolsUtils");
  14. var flags = require("devtools/shared/flags");
  15. var Services = require("Services");
  16. var EventEmitter = require("devtools/shared/event-emitter");
  17. var {ViewHelpers} = require("devtools/client/shared/widgets/view-helpers");
  18. var { LocalizationHelper } = require("devtools/shared/l10n");
  19. var { EmulationFront } = require("devtools/shared/fronts/emulation");
  20. loader.lazyImporter(this, "SystemAppProxy",
  21. "resource://gre/modules/SystemAppProxy.jsm");
  22. loader.lazyRequireGetter(this, "DebuggerClient",
  23. "devtools/shared/client/main", true);
  24. loader.lazyRequireGetter(this, "DebuggerServer",
  25. "devtools/server/main", true);
  26. this.EXPORTED_SYMBOLS = ["ResponsiveUIManager"];
  27. const MIN_WIDTH = 50;
  28. const MIN_HEIGHT = 50;
  29. const MAX_WIDTH = 10000;
  30. const MAX_HEIGHT = 10000;
  31. const SLOW_RATIO = 6;
  32. const ROUND_RATIO = 10;
  33. const INPUT_PARSER = /(\d+)[^\d]+(\d+)/;
  34. const SHARED_L10N = new LocalizationHelper("devtools/client/locales/shared.properties");
  35. function debug(msg) {
  36. // dump(`RDM UI: ${msg}\n`);
  37. }
  38. var ActiveTabs = new Map();
  39. var Manager = {
  40. /**
  41. * Check if the a tab is in a responsive mode.
  42. * Leave the responsive mode if active,
  43. * active the responsive mode if not active.
  44. *
  45. * @param aWindow the main window.
  46. * @param aTab the tab targeted.
  47. */
  48. toggle: function (aWindow, aTab) {
  49. if (this.isActiveForTab(aTab)) {
  50. ActiveTabs.get(aTab).close();
  51. } else {
  52. this.openIfNeeded(aWindow, aTab);
  53. }
  54. },
  55. /**
  56. * Launches the responsive mode.
  57. *
  58. * @param aWindow the main window.
  59. * @param aTab the tab targeted.
  60. * @returns {ResponsiveUI} the instance of ResponsiveUI for the current tab.
  61. */
  62. openIfNeeded: Task.async(function* (aWindow, aTab) {
  63. let ui;
  64. if (!this.isActiveForTab(aTab)) {
  65. ui = new ResponsiveUI(aWindow, aTab);
  66. yield ui.inited;
  67. } else {
  68. ui = this.getResponsiveUIForTab(aTab);
  69. }
  70. return ui;
  71. }),
  72. /**
  73. * Returns true if responsive view is active for the provided tab.
  74. *
  75. * @param aTab the tab targeted.
  76. */
  77. isActiveForTab: function (aTab) {
  78. return ActiveTabs.has(aTab);
  79. },
  80. /**
  81. * Return the responsive UI controller for a tab.
  82. */
  83. getResponsiveUIForTab: function (aTab) {
  84. return ActiveTabs.get(aTab);
  85. },
  86. /**
  87. * Handle gcli commands.
  88. *
  89. * @param aWindow the browser window.
  90. * @param aTab the tab targeted.
  91. * @param aCommand the command name.
  92. * @param aArgs command arguments.
  93. */
  94. handleGcliCommand: Task.async(function* (aWindow, aTab, aCommand, aArgs) {
  95. switch (aCommand) {
  96. case "resize to":
  97. let ui = yield this.openIfNeeded(aWindow, aTab);
  98. ui.setViewportSize(aArgs);
  99. break;
  100. case "resize on":
  101. this.openIfNeeded(aWindow, aTab);
  102. break;
  103. case "resize off":
  104. if (this.isActiveForTab(aTab)) {
  105. yield ActiveTabs.get(aTab).close();
  106. }
  107. break;
  108. case "resize toggle":
  109. this.toggle(aWindow, aTab);
  110. default:
  111. }
  112. })
  113. };
  114. EventEmitter.decorate(Manager);
  115. // If the new HTML RDM UI is enabled and e10s is enabled by default (e10s is required for
  116. // the new HTML RDM UI to function), delegate the ResponsiveUIManager API over to that
  117. // tool instead. Performing this delegation here allows us to contain the pref check to a
  118. // single place.
  119. if (Services.prefs.getBoolPref("devtools.responsive.html.enabled") &&
  120. Services.appinfo.browserTabsRemoteAutostart) {
  121. let { ResponsiveUIManager } =
  122. require("devtools/client/responsive.html/manager");
  123. this.ResponsiveUIManager = ResponsiveUIManager;
  124. } else {
  125. this.ResponsiveUIManager = Manager;
  126. }
  127. var defaultPresets = [
  128. // Phones
  129. {key: "320x480", width: 320, height: 480}, // iPhone, B2G, with <meta viewport>
  130. {key: "360x640", width: 360, height: 640}, // Android 4, phones, with <meta viewport>
  131. // Tablets
  132. {key: "768x1024", width: 768, height: 1024}, // iPad, with <meta viewport>
  133. {key: "800x1280", width: 800, height: 1280}, // Android 4, Tablet, with <meta viewport>
  134. // Default width for mobile browsers, no <meta viewport>
  135. {key: "980x1280", width: 980, height: 1280},
  136. // Computer
  137. {key: "1280x600", width: 1280, height: 600},
  138. {key: "1920x900", width: 1920, height: 900},
  139. ];
  140. function ResponsiveUI(aWindow, aTab)
  141. {
  142. this.mainWindow = aWindow;
  143. this.tab = aTab;
  144. this.mm = this.tab.linkedBrowser.messageManager;
  145. this.tabContainer = aWindow.gBrowser.tabContainer;
  146. this.browser = aTab.linkedBrowser;
  147. this.chromeDoc = aWindow.document;
  148. this.container = aWindow.gBrowser.getBrowserContainer(this.browser);
  149. this.stack = this.container.querySelector(".browserStack");
  150. this._telemetry = new Telemetry();
  151. // Let's bind some callbacks.
  152. this.bound_presetSelected = this.presetSelected.bind(this);
  153. this.bound_handleManualInput = this.handleManualInput.bind(this);
  154. this.bound_addPreset = this.addPreset.bind(this);
  155. this.bound_removePreset = this.removePreset.bind(this);
  156. this.bound_rotate = this.rotate.bind(this);
  157. this.bound_screenshot = () => this.screenshot();
  158. this.bound_touch = this.toggleTouch.bind(this);
  159. this.bound_close = this.close.bind(this);
  160. this.bound_startResizing = this.startResizing.bind(this);
  161. this.bound_stopResizing = this.stopResizing.bind(this);
  162. this.bound_onDrag = this.onDrag.bind(this);
  163. this.bound_changeUA = this.changeUA.bind(this);
  164. this.bound_onContentResize = this.onContentResize.bind(this);
  165. this.mm.addMessageListener("ResponsiveMode:OnContentResize",
  166. this.bound_onContentResize);
  167. // We must be ready to handle window or tab close now that we have saved
  168. // ourselves in ActiveTabs. Otherwise we risk leaking the window.
  169. this.mainWindow.addEventListener("unload", this);
  170. this.tab.addEventListener("TabClose", this);
  171. this.tabContainer.addEventListener("TabSelect", this);
  172. ActiveTabs.set(this.tab, this);
  173. this.inited = this.init();
  174. }
  175. ResponsiveUI.prototype = {
  176. _transitionsEnabled: true,
  177. get transitionsEnabled() {
  178. return this._transitionsEnabled;
  179. },
  180. set transitionsEnabled(aValue) {
  181. this._transitionsEnabled = aValue;
  182. if (aValue && !this._resizing && this.stack.hasAttribute("responsivemode")) {
  183. this.stack.removeAttribute("notransition");
  184. } else if (!aValue) {
  185. this.stack.setAttribute("notransition", "true");
  186. }
  187. },
  188. init: Task.async(function* () {
  189. debug("INIT BEGINS");
  190. let ready = this.waitForMessage("ResponsiveMode:ChildScriptReady");
  191. this.mm.loadFrameScript("resource://devtools/client/responsivedesign/responsivedesign-child.js", true);
  192. yield ready;
  193. let requiresFloatingScrollbars =
  194. !this.mainWindow.matchMedia("(-moz-overlay-scrollbars)").matches;
  195. let started = this.waitForMessage("ResponsiveMode:Start:Done");
  196. debug("SEND START");
  197. this.mm.sendAsyncMessage("ResponsiveMode:Start", {
  198. requiresFloatingScrollbars,
  199. // Tests expect events on resize to yield on various size changes
  200. notifyOnResize: flags.testing,
  201. });
  202. yield started;
  203. // Load Presets
  204. this.loadPresets();
  205. // Setup the UI
  206. this.container.setAttribute("responsivemode", "true");
  207. this.stack.setAttribute("responsivemode", "true");
  208. this.buildUI();
  209. this.checkMenus();
  210. // Rotate the responsive mode if needed
  211. try {
  212. if (Services.prefs.getBoolPref("devtools.responsiveUI.rotate")) {
  213. this.rotate();
  214. }
  215. } catch (e) {}
  216. // Touch events support
  217. this.touchEnableBefore = false;
  218. this.touchEventSimulator = new TouchEventSimulator(this.browser);
  219. yield this.connectToServer();
  220. this.userAgentInput.hidden = false;
  221. // Hook to display promotional Developer Edition doorhanger.
  222. // Only displayed once.
  223. showDoorhanger({
  224. window: this.mainWindow,
  225. type: "deveditionpromo",
  226. anchor: this.chromeDoc.querySelector("#content")
  227. });
  228. // Notify that responsive mode is on.
  229. this._telemetry.toolOpened("responsive");
  230. ResponsiveUIManager.emit("on", { tab: this.tab });
  231. }),
  232. connectToServer: Task.async(function* () {
  233. if (!DebuggerServer.initialized) {
  234. DebuggerServer.init();
  235. DebuggerServer.addBrowserActors();
  236. }
  237. this.client = new DebuggerClient(DebuggerServer.connectPipe());
  238. yield this.client.connect();
  239. let {tab} = yield this.client.getTab();
  240. yield this.client.attachTab(tab.actor);
  241. this.emulationFront = EmulationFront(this.client, tab);
  242. }),
  243. loadPresets: function () {
  244. // Try to load presets from prefs
  245. let presets = defaultPresets;
  246. if (Services.prefs.prefHasUserValue("devtools.responsiveUI.presets")) {
  247. try {
  248. presets = JSON.parse(Services.prefs.getCharPref("devtools.responsiveUI.presets"));
  249. } catch (e) {
  250. // User pref is malformated.
  251. console.error("Could not parse pref `devtools.responsiveUI.presets`: " + e);
  252. }
  253. }
  254. this.customPreset = {key: "custom", custom: true};
  255. if (Array.isArray(presets)) {
  256. this.presets = [this.customPreset].concat(presets);
  257. } else {
  258. console.error("Presets value (devtools.responsiveUI.presets) is malformated.");
  259. this.presets = [this.customPreset];
  260. }
  261. try {
  262. let width = Services.prefs.getIntPref("devtools.responsiveUI.customWidth");
  263. let height = Services.prefs.getIntPref("devtools.responsiveUI.customHeight");
  264. this.customPreset.width = Math.min(MAX_WIDTH, width);
  265. this.customPreset.height = Math.min(MAX_HEIGHT, height);
  266. this.currentPresetKey = Services.prefs.getCharPref("devtools.responsiveUI.currentPreset");
  267. } catch (e) {
  268. // Default size. The first preset (custom) is the one that will be used.
  269. let bbox = this.stack.getBoundingClientRect();
  270. this.customPreset.width = bbox.width - 40; // horizontal padding of the container
  271. this.customPreset.height = bbox.height - 80; // vertical padding + toolbar height
  272. this.currentPresetKey = this.presets[1].key; // most common preset
  273. }
  274. },
  275. /**
  276. * Destroy the nodes. Remove listeners. Reset the style.
  277. */
  278. close: Task.async(function* () {
  279. debug("CLOSE BEGINS");
  280. if (this.closing) {
  281. debug("ALREADY CLOSING, ABORT");
  282. return;
  283. }
  284. this.closing = true;
  285. // If we're closing very fast (in tests), ensure init has finished.
  286. debug("CLOSE: WAIT ON INITED");
  287. yield this.inited;
  288. debug("CLOSE: INITED DONE");
  289. this.unCheckMenus();
  290. // Reset style of the stack.
  291. debug(`CURRENT SIZE: ${this.stack.getAttribute("style")}`);
  292. let style = "max-width: none;" +
  293. "min-width: 0;" +
  294. "max-height: none;" +
  295. "min-height: 0;";
  296. debug("RESET STACK SIZE");
  297. this.stack.setAttribute("style", style);
  298. // Wait for resize message before stopping in the child when testing,
  299. // but only if we should expect to still get a message.
  300. if (flags.testing && this.tab.linkedBrowser.messageManager) {
  301. yield this.waitForMessage("ResponsiveMode:OnContentResize");
  302. }
  303. if (this.isResizing)
  304. this.stopResizing();
  305. // Remove listeners.
  306. this.menulist.removeEventListener("select", this.bound_presetSelected, true);
  307. this.menulist.removeEventListener("change", this.bound_handleManualInput, true);
  308. this.mainWindow.removeEventListener("unload", this);
  309. this.tab.removeEventListener("TabClose", this);
  310. this.tabContainer.removeEventListener("TabSelect", this);
  311. this.rotatebutton.removeEventListener("command", this.bound_rotate, true);
  312. this.screenshotbutton.removeEventListener("command", this.bound_screenshot, true);
  313. this.closebutton.removeEventListener("command", this.bound_close, true);
  314. this.addbutton.removeEventListener("command", this.bound_addPreset, true);
  315. this.removebutton.removeEventListener("command", this.bound_removePreset, true);
  316. this.touchbutton.removeEventListener("command", this.bound_touch, true);
  317. this.userAgentInput.removeEventListener("blur", this.bound_changeUA, true);
  318. // Removed elements.
  319. this.container.removeChild(this.toolbar);
  320. if (this.bottomToolbar) {
  321. this.bottomToolbar.remove();
  322. delete this.bottomToolbar;
  323. }
  324. this.stack.removeChild(this.resizer);
  325. this.stack.removeChild(this.resizeBarV);
  326. this.stack.removeChild(this.resizeBarH);
  327. this.stack.classList.remove("fxos-mode");
  328. // Unset the responsive mode.
  329. this.container.removeAttribute("responsivemode");
  330. this.stack.removeAttribute("responsivemode");
  331. ActiveTabs.delete(this.tab);
  332. if (this.touchEventSimulator) {
  333. this.touchEventSimulator.stop();
  334. }
  335. yield this.client.close();
  336. this.client = this.emulationFront = null;
  337. this._telemetry.toolClosed("responsive");
  338. if (this.tab.linkedBrowser.messageManager) {
  339. let stopped = this.waitForMessage("ResponsiveMode:Stop:Done");
  340. this.tab.linkedBrowser.messageManager.sendAsyncMessage("ResponsiveMode:Stop");
  341. yield stopped;
  342. }
  343. this.inited = null;
  344. ResponsiveUIManager.emit("off", { tab: this.tab });
  345. }),
  346. waitForMessage(message) {
  347. return new Promise(resolve => {
  348. let listener = () => {
  349. this.mm.removeMessageListener(message, listener);
  350. resolve();
  351. };
  352. this.mm.addMessageListener(message, listener);
  353. });
  354. },
  355. /**
  356. * Emit an event when the content has been resized. Only used in tests.
  357. */
  358. onContentResize: function (msg) {
  359. ResponsiveUIManager.emit("content-resize", {
  360. tab: this.tab,
  361. width: msg.data.width,
  362. height: msg.data.height,
  363. });
  364. },
  365. /**
  366. * Handle events
  367. */
  368. handleEvent: function (aEvent) {
  369. switch (aEvent.type) {
  370. case "TabClose":
  371. case "unload":
  372. this.close();
  373. break;
  374. case "TabSelect":
  375. if (this.tab.selected) {
  376. this.checkMenus();
  377. } else if (!this.mainWindow.gBrowser.selectedTab.responsiveUI) {
  378. this.unCheckMenus();
  379. }
  380. break;
  381. }
  382. },
  383. getViewportBrowser() {
  384. return this.browser;
  385. },
  386. /**
  387. * Check the menu items.
  388. */
  389. checkMenus: function RUI_checkMenus() {
  390. this.chromeDoc.getElementById("menu_responsiveUI").setAttribute("checked", "true");
  391. },
  392. /**
  393. * Uncheck the menu items.
  394. */
  395. unCheckMenus: function RUI_unCheckMenus() {
  396. let el = this.chromeDoc.getElementById("menu_responsiveUI");
  397. if (el) {
  398. el.setAttribute("checked", "false");
  399. }
  400. },
  401. /**
  402. * Build the toolbar and the resizers.
  403. *
  404. * <vbox class="browserContainer"> From tabbrowser.xml
  405. * <toolbar class="devtools-responsiveui-toolbar">
  406. * <menulist class="devtools-responsiveui-menulist"/> // presets
  407. * <toolbarbutton tabindex="0" class="devtools-responsiveui-toolbarbutton" tooltiptext="rotate"/> // rotate
  408. * <toolbarbutton tabindex="0" class="devtools-responsiveui-toolbarbutton" tooltiptext="screenshot"/> // screenshot
  409. * <toolbarbutton tabindex="0" class="devtools-responsiveui-toolbarbutton" tooltiptext="Leave Responsive Design Mode"/> // close
  410. * </toolbar>
  411. * <stack class="browserStack"> From tabbrowser.xml
  412. * <browser/>
  413. * <box class="devtools-responsiveui-resizehandle" bottom="0" right="0"/>
  414. * <box class="devtools-responsiveui-resizebarV" top="0" right="0"/>
  415. * <box class="devtools-responsiveui-resizebarH" bottom="0" left="0"/>
  416. * // Additional button in FxOS mode:
  417. * <button class="devtools-responsiveui-sleep-button" />
  418. * <vbox class="devtools-responsiveui-volume-buttons">
  419. * <button class="devtools-responsiveui-volume-up-button" />
  420. * <button class="devtools-responsiveui-volume-down-button" />
  421. * </vbox>
  422. * </stack>
  423. * <toolbar class="devtools-responsiveui-hardware-button">
  424. * <toolbarbutton class="devtools-responsiveui-home-button" />
  425. * </toolbar>
  426. * </vbox>
  427. */
  428. buildUI: function RUI_buildUI() {
  429. // Toolbar
  430. this.toolbar = this.chromeDoc.createElement("toolbar");
  431. this.toolbar.className = "devtools-responsiveui-toolbar";
  432. this.toolbar.setAttribute("fullscreentoolbar", "true");
  433. this.menulist = this.chromeDoc.createElement("menulist");
  434. this.menulist.className = "devtools-responsiveui-menulist";
  435. this.menulist.setAttribute("editable", "true");
  436. this.menulist.addEventListener("select", this.bound_presetSelected, true);
  437. this.menulist.addEventListener("change", this.bound_handleManualInput, true);
  438. this.menuitems = new Map();
  439. let menupopup = this.chromeDoc.createElement("menupopup");
  440. this.registerPresets(menupopup);
  441. this.menulist.appendChild(menupopup);
  442. this.addbutton = this.chromeDoc.createElement("menuitem");
  443. this.addbutton.setAttribute("label", this.strings.GetStringFromName("responsiveUI.addPreset"));
  444. this.addbutton.addEventListener("command", this.bound_addPreset, true);
  445. this.removebutton = this.chromeDoc.createElement("menuitem");
  446. this.removebutton.setAttribute("label", this.strings.GetStringFromName("responsiveUI.removePreset"));
  447. this.removebutton.addEventListener("command", this.bound_removePreset, true);
  448. menupopup.appendChild(this.chromeDoc.createElement("menuseparator"));
  449. menupopup.appendChild(this.addbutton);
  450. menupopup.appendChild(this.removebutton);
  451. this.rotatebutton = this.chromeDoc.createElement("toolbarbutton");
  452. this.rotatebutton.setAttribute("tabindex", "0");
  453. this.rotatebutton.setAttribute("tooltiptext", this.strings.GetStringFromName("responsiveUI.rotate2"));
  454. this.rotatebutton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-rotate";
  455. this.rotatebutton.addEventListener("command", this.bound_rotate, true);
  456. this.screenshotbutton = this.chromeDoc.createElement("toolbarbutton");
  457. this.screenshotbutton.setAttribute("tabindex", "0");
  458. this.screenshotbutton.setAttribute("tooltiptext", this.strings.GetStringFromName("responsiveUI.screenshot"));
  459. this.screenshotbutton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-screenshot";
  460. this.screenshotbutton.addEventListener("command", this.bound_screenshot, true);
  461. this.closebutton = this.chromeDoc.createElement("toolbarbutton");
  462. this.closebutton.setAttribute("tabindex", "0");
  463. this.closebutton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-close";
  464. this.closebutton.setAttribute("tooltiptext", this.strings.GetStringFromName("responsiveUI.close1"));
  465. this.closebutton.addEventListener("command", this.bound_close, true);
  466. this.toolbar.appendChild(this.closebutton);
  467. this.toolbar.appendChild(this.menulist);
  468. this.toolbar.appendChild(this.rotatebutton);
  469. this.touchbutton = this.chromeDoc.createElement("toolbarbutton");
  470. this.touchbutton.setAttribute("tabindex", "0");
  471. this.touchbutton.setAttribute("tooltiptext", this.strings.GetStringFromName("responsiveUI.touch"));
  472. this.touchbutton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-touch";
  473. this.touchbutton.addEventListener("command", this.bound_touch, true);
  474. this.toolbar.appendChild(this.touchbutton);
  475. this.toolbar.appendChild(this.screenshotbutton);
  476. this.userAgentInput = this.chromeDoc.createElement("textbox");
  477. this.userAgentInput.className = "devtools-responsiveui-textinput";
  478. this.userAgentInput.setAttribute("placeholder",
  479. this.strings.GetStringFromName("responsiveUI.userAgentPlaceholder"));
  480. this.userAgentInput.addEventListener("blur", this.bound_changeUA, true);
  481. this.userAgentInput.hidden = true;
  482. this.toolbar.appendChild(this.userAgentInput);
  483. // Resizers
  484. let resizerTooltip = this.strings.GetStringFromName("responsiveUI.resizerTooltip");
  485. this.resizer = this.chromeDoc.createElement("box");
  486. this.resizer.className = "devtools-responsiveui-resizehandle";
  487. this.resizer.setAttribute("right", "0");
  488. this.resizer.setAttribute("bottom", "0");
  489. this.resizer.setAttribute("tooltiptext", resizerTooltip);
  490. this.resizer.onmousedown = this.bound_startResizing;
  491. this.resizeBarV = this.chromeDoc.createElement("box");
  492. this.resizeBarV.className = "devtools-responsiveui-resizebarV";
  493. this.resizeBarV.setAttribute("top", "0");
  494. this.resizeBarV.setAttribute("right", "0");
  495. this.resizeBarV.setAttribute("tooltiptext", resizerTooltip);
  496. this.resizeBarV.onmousedown = this.bound_startResizing;
  497. this.resizeBarH = this.chromeDoc.createElement("box");
  498. this.resizeBarH.className = "devtools-responsiveui-resizebarH";
  499. this.resizeBarH.setAttribute("bottom", "0");
  500. this.resizeBarH.setAttribute("left", "0");
  501. this.resizeBarH.setAttribute("tooltiptext", resizerTooltip);
  502. this.resizeBarH.onmousedown = this.bound_startResizing;
  503. this.container.insertBefore(this.toolbar, this.stack);
  504. this.stack.appendChild(this.resizer);
  505. this.stack.appendChild(this.resizeBarV);
  506. this.stack.appendChild(this.resizeBarH);
  507. },
  508. // FxOS custom controls
  509. buildPhoneUI: function () {
  510. this.stack.classList.add("fxos-mode");
  511. let sleepButton = this.chromeDoc.createElement("button");
  512. sleepButton.className = "devtools-responsiveui-sleep-button";
  513. sleepButton.setAttribute("top", 0);
  514. sleepButton.setAttribute("right", 0);
  515. sleepButton.addEventListener("mousedown", () => {
  516. SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "Power"});
  517. });
  518. sleepButton.addEventListener("mouseup", () => {
  519. SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "Power"});
  520. });
  521. this.stack.appendChild(sleepButton);
  522. let volumeButtons = this.chromeDoc.createElement("vbox");
  523. volumeButtons.className = "devtools-responsiveui-volume-buttons";
  524. volumeButtons.setAttribute("top", 0);
  525. volumeButtons.setAttribute("left", 0);
  526. let volumeUp = this.chromeDoc.createElement("button");
  527. volumeUp.className = "devtools-responsiveui-volume-up-button";
  528. volumeUp.addEventListener("mousedown", () => {
  529. SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "AudioVolumeUp"});
  530. });
  531. volumeUp.addEventListener("mouseup", () => {
  532. SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "AudioVolumeUp"});
  533. });
  534. let volumeDown = this.chromeDoc.createElement("button");
  535. volumeDown.className = "devtools-responsiveui-volume-down-button";
  536. volumeDown.addEventListener("mousedown", () => {
  537. SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "AudioVolumeDown"});
  538. });
  539. volumeDown.addEventListener("mouseup", () => {
  540. SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "AudioVolumeDown"});
  541. });
  542. volumeButtons.appendChild(volumeUp);
  543. volumeButtons.appendChild(volumeDown);
  544. this.stack.appendChild(volumeButtons);
  545. let bottomToolbar = this.chromeDoc.createElement("toolbar");
  546. bottomToolbar.className = "devtools-responsiveui-hardware-buttons";
  547. bottomToolbar.setAttribute("align", "center");
  548. bottomToolbar.setAttribute("pack", "center");
  549. let homeButton = this.chromeDoc.createElement("toolbarbutton");
  550. homeButton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-home-button";
  551. homeButton.addEventListener("mousedown", () => {
  552. SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "Home"});
  553. });
  554. homeButton.addEventListener("mouseup", () => {
  555. SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "Home"});
  556. });
  557. bottomToolbar.appendChild(homeButton);
  558. this.bottomToolbar = bottomToolbar;
  559. this.container.appendChild(bottomToolbar);
  560. },
  561. /**
  562. * Validate and apply any user input on the editable menulist
  563. */
  564. handleManualInput: function RUI_handleManualInput() {
  565. let userInput = this.menulist.inputField.value;
  566. let value = INPUT_PARSER.exec(userInput);
  567. let selectedPreset = this.menuitems.get(this.selectedItem);
  568. // In case of an invalide value, we show back the last preset
  569. if (!value || value.length < 3) {
  570. this.setMenuLabel(this.selectedItem, selectedPreset);
  571. return;
  572. }
  573. this.rotateValue = false;
  574. if (!selectedPreset.custom) {
  575. let menuitem = this.customMenuitem;
  576. this.currentPresetKey = this.customPreset.key;
  577. this.menulist.selectedItem = menuitem;
  578. }
  579. let w = this.customPreset.width = parseInt(value[1], 10);
  580. let h = this.customPreset.height = parseInt(value[2], 10);
  581. this.saveCustomSize();
  582. this.setViewportSize({
  583. width: w,
  584. height: h,
  585. });
  586. },
  587. /**
  588. * Build the presets list and append it to the menupopup.
  589. *
  590. * @param aParent menupopup.
  591. */
  592. registerPresets: function RUI_registerPresets(aParent) {
  593. let fragment = this.chromeDoc.createDocumentFragment();
  594. let doc = this.chromeDoc;
  595. for (let preset of this.presets) {
  596. let menuitem = doc.createElement("menuitem");
  597. menuitem.setAttribute("ispreset", true);
  598. this.menuitems.set(menuitem, preset);
  599. if (preset.key === this.currentPresetKey) {
  600. menuitem.setAttribute("selected", "true");
  601. this.selectedItem = menuitem;
  602. }
  603. if (preset.custom) {
  604. this.customMenuitem = menuitem;
  605. }
  606. this.setMenuLabel(menuitem, preset);
  607. fragment.appendChild(menuitem);
  608. }
  609. aParent.appendChild(fragment);
  610. },
  611. /**
  612. * Set the menuitem label of a preset.
  613. *
  614. * @param aMenuitem menuitem to edit.
  615. * @param aPreset associated preset.
  616. */
  617. setMenuLabel: function RUI_setMenuLabel(aMenuitem, aPreset) {
  618. let size = SHARED_L10N.getFormatStr("dimensions",
  619. Math.round(aPreset.width), Math.round(aPreset.height));
  620. // .inputField might be not reachable yet (async XBL loading)
  621. if (this.menulist.inputField) {
  622. this.menulist.inputField.value = size;
  623. }
  624. if (aPreset.custom) {
  625. size = this.strings.formatStringFromName("responsiveUI.customResolution", [size], 1);
  626. } else if (aPreset.name != null && aPreset.name !== "") {
  627. size = this.strings.formatStringFromName("responsiveUI.namedResolution", [size, aPreset.name], 2);
  628. }
  629. aMenuitem.setAttribute("label", size);
  630. },
  631. /**
  632. * When a preset is selected, apply it.
  633. */
  634. presetSelected: function RUI_presetSelected() {
  635. if (this.menulist.selectedItem.getAttribute("ispreset") === "true") {
  636. this.selectedItem = this.menulist.selectedItem;
  637. this.rotateValue = false;
  638. let selectedPreset = this.menuitems.get(this.selectedItem);
  639. this.loadPreset(selectedPreset);
  640. this.currentPresetKey = selectedPreset.key;
  641. this.saveCurrentPreset();
  642. // Update the buttons hidden status according to the new selected preset
  643. if (selectedPreset == this.customPreset) {
  644. this.addbutton.hidden = false;
  645. this.removebutton.hidden = true;
  646. } else {
  647. this.addbutton.hidden = true;
  648. this.removebutton.hidden = false;
  649. }
  650. }
  651. },
  652. /**
  653. * Apply a preset.
  654. */
  655. loadPreset(preset) {
  656. this.setViewportSize(preset);
  657. },
  658. /**
  659. * Add a preset to the list and the memory
  660. */
  661. addPreset: function RUI_addPreset() {
  662. let w = this.customPreset.width;
  663. let h = this.customPreset.height;
  664. let newName = {};
  665. let title = this.strings.GetStringFromName("responsiveUI.customNamePromptTitle1");
  666. let message = this.strings.formatStringFromName("responsiveUI.customNamePromptMsg", [w, h], 2);
  667. let promptOk = Services.prompt.prompt(null, title, message, newName, null, {});
  668. if (!promptOk) {
  669. // Prompt has been cancelled
  670. this.menulist.selectedItem = this.selectedItem;
  671. return;
  672. }
  673. let newPreset = {
  674. key: w + "x" + h,
  675. name: newName.value,
  676. width: w,
  677. height: h
  678. };
  679. this.presets.push(newPreset);
  680. // Sort the presets according to width/height ascending order
  681. this.presets.sort(function RUI_sortPresets(aPresetA, aPresetB) {
  682. // We keep custom preset at first
  683. if (aPresetA.custom && !aPresetB.custom) {
  684. return 1;
  685. }
  686. if (!aPresetA.custom && aPresetB.custom) {
  687. return -1;
  688. }
  689. if (aPresetA.width === aPresetB.width) {
  690. if (aPresetA.height === aPresetB.height) {
  691. return 0;
  692. } else {
  693. return aPresetA.height > aPresetB.height;
  694. }
  695. } else {
  696. return aPresetA.width > aPresetB.width;
  697. }
  698. });
  699. this.savePresets();
  700. let newMenuitem = this.chromeDoc.createElement("menuitem");
  701. newMenuitem.setAttribute("ispreset", true);
  702. this.setMenuLabel(newMenuitem, newPreset);
  703. this.menuitems.set(newMenuitem, newPreset);
  704. let idx = this.presets.indexOf(newPreset);
  705. let beforeMenuitem = this.menulist.firstChild.childNodes[idx + 1];
  706. this.menulist.firstChild.insertBefore(newMenuitem, beforeMenuitem);
  707. this.menulist.selectedItem = newMenuitem;
  708. this.currentPresetKey = newPreset.key;
  709. this.saveCurrentPreset();
  710. },
  711. /**
  712. * remove a preset from the list and the memory
  713. */
  714. removePreset: function RUI_removePreset() {
  715. let selectedPreset = this.menuitems.get(this.selectedItem);
  716. let w = selectedPreset.width;
  717. let h = selectedPreset.height;
  718. this.presets.splice(this.presets.indexOf(selectedPreset), 1);
  719. this.menulist.firstChild.removeChild(this.selectedItem);
  720. this.menuitems.delete(this.selectedItem);
  721. this.customPreset.width = w;
  722. this.customPreset.height = h;
  723. let menuitem = this.customMenuitem;
  724. this.setMenuLabel(menuitem, this.customPreset);
  725. this.menulist.selectedItem = menuitem;
  726. this.currentPresetKey = this.customPreset.key;
  727. this.setViewportSize({
  728. width: w,
  729. height: h,
  730. });
  731. this.savePresets();
  732. },
  733. /**
  734. * Swap width and height.
  735. */
  736. rotate: function RUI_rotate() {
  737. let selectedPreset = this.menuitems.get(this.selectedItem);
  738. let width = this.rotateValue ? selectedPreset.height : selectedPreset.width;
  739. let height = this.rotateValue ? selectedPreset.width : selectedPreset.height;
  740. this.setViewportSize({
  741. width: height,
  742. height: width,
  743. });
  744. if (selectedPreset.custom) {
  745. this.saveCustomSize();
  746. } else {
  747. this.rotateValue = !this.rotateValue;
  748. this.saveCurrentPreset();
  749. }
  750. },
  751. /**
  752. * Take a screenshot of the page.
  753. *
  754. * @param aFileName name of the screenshot file (used for tests).
  755. */
  756. screenshot: function RUI_screenshot(aFileName) {
  757. let filename = aFileName;
  758. if (!filename) {
  759. let date = new Date();
  760. let month = ("0" + (date.getMonth() + 1)).substr(-2, 2);
  761. let day = ("0" + date.getDate()).substr(-2, 2);
  762. let dateString = [date.getFullYear(), month, day].join("-");
  763. let timeString = date.toTimeString().replace(/:/g, ".").split(" ")[0];
  764. filename = this.strings.formatStringFromName("responsiveUI.screenshotGeneratedFilename", [dateString, timeString], 2);
  765. }
  766. let mm = this.tab.linkedBrowser.messageManager;
  767. let chromeWindow = this.chromeDoc.defaultView;
  768. let doc = chromeWindow.document;
  769. function onScreenshot(aMessage) {
  770. mm.removeMessageListener("ResponsiveMode:RequestScreenshot:Done", onScreenshot);
  771. chromeWindow.saveURL(aMessage.data, filename + ".png", null, true, true, doc.documentURIObject, doc);
  772. }
  773. mm.addMessageListener("ResponsiveMode:RequestScreenshot:Done", onScreenshot);
  774. mm.sendAsyncMessage("ResponsiveMode:RequestScreenshot");
  775. },
  776. /**
  777. * Enable/Disable mouse -> touch events translation.
  778. */
  779. enableTouch: function RUI_enableTouch() {
  780. this.touchbutton.setAttribute("checked", "true");
  781. return this.touchEventSimulator.start();
  782. },
  783. disableTouch: function RUI_disableTouch() {
  784. this.touchbutton.removeAttribute("checked");
  785. return this.touchEventSimulator.stop();
  786. },
  787. hideTouchNotification: function RUI_hideTouchNotification() {
  788. let nbox = this.mainWindow.gBrowser.getNotificationBox(this.browser);
  789. let n = nbox.getNotificationWithValue("responsive-ui-need-reload");
  790. if (n) {
  791. n.close();
  792. }
  793. },
  794. toggleTouch: Task.async(function* () {
  795. this.hideTouchNotification();
  796. if (this.touchEventSimulator.enabled) {
  797. this.disableTouch();
  798. } else {
  799. let isReloadNeeded = yield this.enableTouch();
  800. if (isReloadNeeded) {
  801. if (Services.prefs.getBoolPref("devtools.responsiveUI.no-reload-notification")) {
  802. return;
  803. }
  804. let nbox = this.mainWindow.gBrowser.getNotificationBox(this.browser);
  805. var buttons = [{
  806. label: this.strings.GetStringFromName("responsiveUI.notificationReload"),
  807. callback: () => {
  808. this.browser.reload();
  809. },
  810. accessKey: this.strings.GetStringFromName("responsiveUI.notificationReload_accesskey"),
  811. }, {
  812. label: this.strings.GetStringFromName("responsiveUI.dontShowReloadNotification"),
  813. callback: function () {
  814. Services.prefs.setBoolPref("devtools.responsiveUI.no-reload-notification", true);
  815. },
  816. accessKey: this.strings.GetStringFromName("responsiveUI.dontShowReloadNotification_accesskey"),
  817. }];
  818. nbox.appendNotification(
  819. this.strings.GetStringFromName("responsiveUI.needReload"),
  820. "responsive-ui-need-reload",
  821. null,
  822. nbox.PRIORITY_INFO_LOW,
  823. buttons);
  824. }
  825. }
  826. }),
  827. waitForReload() {
  828. let navigatedDeferred = promise.defer();
  829. let onNavigated = (_, { state }) => {
  830. if (state != "stop") {
  831. return;
  832. }
  833. this.client.removeListener("tabNavigated", onNavigated);
  834. navigatedDeferred.resolve();
  835. };
  836. this.client.addListener("tabNavigated", onNavigated);
  837. return navigatedDeferred.promise;
  838. },
  839. /**
  840. * Change the user agent string
  841. */
  842. changeUA: Task.async(function* () {
  843. let value = this.userAgentInput.value;
  844. let changed;
  845. if (value) {
  846. changed = yield this.emulationFront.setUserAgentOverride(value);
  847. this.userAgentInput.setAttribute("attention", "true");
  848. } else {
  849. changed = yield this.emulationFront.clearUserAgentOverride();
  850. this.userAgentInput.removeAttribute("attention");
  851. }
  852. if (changed) {
  853. let reloaded = this.waitForReload();
  854. this.tab.linkedBrowser.reload();
  855. yield reloaded;
  856. }
  857. ResponsiveUIManager.emit("userAgentChanged", { tab: this.tab });
  858. }),
  859. /**
  860. * Get the current width and height.
  861. */
  862. getSize() {
  863. let width = Number(this.stack.style.minWidth.replace("px", ""));
  864. let height = Number(this.stack.style.minHeight.replace("px", ""));
  865. return {
  866. width,
  867. height,
  868. };
  869. },
  870. /**
  871. * Change the size of the viewport.
  872. */
  873. setViewportSize({ width, height }) {
  874. debug(`SET SIZE TO ${width} x ${height}`);
  875. if (width) {
  876. this.setWidth(width);
  877. }
  878. if (height) {
  879. this.setHeight(height);
  880. }
  881. },
  882. setWidth: function RUI_setWidth(aWidth) {
  883. aWidth = Math.min(Math.max(aWidth, MIN_WIDTH), MAX_WIDTH);
  884. this.stack.style.maxWidth = this.stack.style.minWidth = aWidth + "px";
  885. if (!this.ignoreX)
  886. this.resizeBarH.setAttribute("left", Math.round(aWidth / 2));
  887. let selectedPreset = this.menuitems.get(this.selectedItem);
  888. if (selectedPreset.custom) {
  889. selectedPreset.width = aWidth;
  890. this.setMenuLabel(this.selectedItem, selectedPreset);
  891. }
  892. },
  893. setHeight: function RUI_setHeight(aHeight) {
  894. aHeight = Math.min(Math.max(aHeight, MIN_HEIGHT), MAX_HEIGHT);
  895. this.stack.style.maxHeight = this.stack.style.minHeight = aHeight + "px";
  896. if (!this.ignoreY)
  897. this.resizeBarV.setAttribute("top", Math.round(aHeight / 2));
  898. let selectedPreset = this.menuitems.get(this.selectedItem);
  899. if (selectedPreset.custom) {
  900. selectedPreset.height = aHeight;
  901. this.setMenuLabel(this.selectedItem, selectedPreset);
  902. }
  903. },
  904. /**
  905. * Start the process of resizing the browser.
  906. *
  907. * @param aEvent
  908. */
  909. startResizing: function RUI_startResizing(aEvent) {
  910. let selectedPreset = this.menuitems.get(this.selectedItem);
  911. if (!selectedPreset.custom) {
  912. this.customPreset.width = this.rotateValue ? selectedPreset.height : selectedPreset.width;
  913. this.customPreset.height = this.rotateValue ? selectedPreset.width : selectedPreset.height;
  914. let menuitem = this.customMenuitem;
  915. this.setMenuLabel(menuitem, this.customPreset);
  916. this.currentPresetKey = this.customPreset.key;
  917. this.menulist.selectedItem = menuitem;
  918. }
  919. this.mainWindow.addEventListener("mouseup", this.bound_stopResizing, true);
  920. this.mainWindow.addEventListener("mousemove", this.bound_onDrag, true);
  921. this.container.style.pointerEvents = "none";
  922. this._resizing = true;
  923. this.stack.setAttribute("notransition", "true");
  924. this.lastScreenX = aEvent.screenX;
  925. this.lastScreenY = aEvent.screenY;
  926. this.ignoreY = (aEvent.target === this.resizeBarV);
  927. this.ignoreX = (aEvent.target === this.resizeBarH);
  928. this.isResizing = true;
  929. },
  930. /**
  931. * Resizing on mouse move.
  932. *
  933. * @param aEvent
  934. */
  935. onDrag: function RUI_onDrag(aEvent) {
  936. let shift = aEvent.shiftKey;
  937. let ctrl = !aEvent.shiftKey && aEvent.ctrlKey;
  938. let screenX = aEvent.screenX;
  939. let screenY = aEvent.screenY;
  940. let deltaX = screenX - this.lastScreenX;
  941. let deltaY = screenY - this.lastScreenY;
  942. if (this.ignoreY)
  943. deltaY = 0;
  944. if (this.ignoreX)
  945. deltaX = 0;
  946. if (ctrl) {
  947. deltaX /= SLOW_RATIO;
  948. deltaY /= SLOW_RATIO;
  949. }
  950. let width = this.customPreset.width + deltaX;
  951. let height = this.customPreset.height + deltaY;
  952. if (shift) {
  953. let roundedWidth, roundedHeight;
  954. roundedWidth = 10 * Math.floor(width / ROUND_RATIO);
  955. roundedHeight = 10 * Math.floor(height / ROUND_RATIO);
  956. screenX += roundedWidth - width;
  957. screenY += roundedHeight - height;
  958. width = roundedWidth;
  959. height = roundedHeight;
  960. }
  961. if (width < MIN_WIDTH) {
  962. width = MIN_WIDTH;
  963. } else {
  964. this.lastScreenX = screenX;
  965. }
  966. if (height < MIN_HEIGHT) {
  967. height = MIN_HEIGHT;
  968. } else {
  969. this.lastScreenY = screenY;
  970. }
  971. this.setViewportSize({ width, height });
  972. },
  973. /**
  974. * Stop End resizing
  975. */
  976. stopResizing: function RUI_stopResizing() {
  977. this.container.style.pointerEvents = "auto";
  978. this.mainWindow.removeEventListener("mouseup", this.bound_stopResizing, true);
  979. this.mainWindow.removeEventListener("mousemove", this.bound_onDrag, true);
  980. this.saveCustomSize();
  981. delete this._resizing;
  982. if (this.transitionsEnabled) {
  983. this.stack.removeAttribute("notransition");
  984. }
  985. this.ignoreY = false;
  986. this.ignoreX = false;
  987. this.isResizing = false;
  988. },
  989. /**
  990. * Store the custom size as a pref.
  991. */
  992. saveCustomSize: function RUI_saveCustomSize() {
  993. Services.prefs.setIntPref("devtools.responsiveUI.customWidth", this.customPreset.width);
  994. Services.prefs.setIntPref("devtools.responsiveUI.customHeight", this.customPreset.height);
  995. },
  996. /**
  997. * Store the current preset as a pref.
  998. */
  999. saveCurrentPreset: function RUI_saveCurrentPreset() {
  1000. Services.prefs.setCharPref("devtools.responsiveUI.currentPreset", this.currentPresetKey);
  1001. Services.prefs.setBoolPref("devtools.responsiveUI.rotate", this.rotateValue);
  1002. },
  1003. /**
  1004. * Store the list of all registered presets as a pref.
  1005. */
  1006. savePresets: function RUI_savePresets() {
  1007. // We exclude the custom one
  1008. let registeredPresets = this.presets.filter(function (aPreset) {
  1009. return !aPreset.custom;
  1010. });
  1011. Services.prefs.setCharPref("devtools.responsiveUI.presets", JSON.stringify(registeredPresets));
  1012. },
  1013. };
  1014. loader.lazyGetter(ResponsiveUI.prototype, "strings", function () {
  1015. return Services.strings.createBundle("chrome://devtools/locale/responsiveUI.properties");
  1016. });