tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FontOrigin.js (1838B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  PureComponent,
      9 } = require("resource://devtools/client/shared/vendor/react.mjs");
     10 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
     11 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs");
     12 
     13 loader.lazyRequireGetter(
     14  this,
     15  "clipboardHelper",
     16  "resource://devtools/shared/platform/clipboard.js"
     17 );
     18 
     19 const {
     20  getStr,
     21 } = require("resource://devtools/client/inspector/fonts/utils/l10n.js");
     22 const Types = require("resource://devtools/client/inspector/fonts/types.js");
     23 
     24 class FontOrigin extends PureComponent {
     25  static get propTypes() {
     26    return {
     27      font: PropTypes.shape(Types.font).isRequired,
     28    };
     29  }
     30 
     31  constructor(props) {
     32    super(props);
     33    this.onCopyURL = this.onCopyURL.bind(this);
     34  }
     35 
     36  clipTitle(title, maxLength = 512) {
     37    if (title.length > maxLength) {
     38      return title.substring(0, maxLength - 2) + "…";
     39    }
     40    return title;
     41  }
     42 
     43  onCopyURL() {
     44    clipboardHelper.copyString(this.props.font.URI);
     45  }
     46 
     47  render() {
     48    const url = this.props.font.URI;
     49 
     50    if (!url) {
     51      return dom.p(
     52        {
     53          className: "font-origin system",
     54        },
     55        getStr("fontinspector.system")
     56      );
     57    }
     58 
     59    return dom.p(
     60      {
     61        className: "font-origin remote",
     62      },
     63      dom.span(
     64        {
     65          className: "url",
     66          title: this.clipTitle(url),
     67        },
     68        url
     69      ),
     70      dom.button({
     71        className: "copy-icon",
     72        onClick: this.onCopyURL,
     73        title: getStr("fontinspector.copyURL"),
     74      })
     75    );
     76  }
     77 }
     78 
     79 module.exports = FontOrigin;