summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/file_manager/js/tree.css.js
blob: d641d4cea267a6405e31fe30a03d8f5c66fad6ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';

/**
 * Custom version of chrome://resources/css/tree.css.js, adding support for
 * inverted arrow icons.
 */
(function() {
  /**
   * @type {number}
   * @const
   */
  var WIDTH = 14;

  /**
   * @type {number}
   * @const
   */
  var HEIGHT = WIDTH / 2 + 2;

  /**
   * @type {number}
   * @const
   */
  var MARGIN = 1;

  /**
   * @param {string} name CSS canvas identifier.
   * @param {string} backgroundColor Background color.
   * @param {string} strokeColor Outline color.
   */
  function prepareTriangle(name, backgroundColor, strokeColor) {
    var ctx = document.getCSSCanvasContext('2d',
                                           name,
                                           WIDTH + MARGIN * 2,
                                           HEIGHT + MARGIN * 2);

    ctx.fillStyle = backgroundColor;
    ctx.strokeStyle = strokeColor;
    ctx.translate(MARGIN, MARGIN);

    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(0, 2);
    ctx.lineTo(WIDTH / 2, HEIGHT);
    ctx.lineTo(WIDTH, 2);
    ctx.lineTo(WIDTH, 0);
    ctx.closePath();
    ctx.fill();
    ctx.stroke();
  }

  prepareTriangle(
      'tree-triangle', 'rgba(122, 122, 122, 0.6)', 'rgba(0, 0, 0, 0.6)');
  prepareTriangle('tree-triangle-inverted', '#ffffff', '#ffffff');
})();