-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathhighlight_isolated_element.ts
62 lines (55 loc) · 2.24 KB
/
highlight_isolated_element.ts
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
60
61
62
// Copyright 2021 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.
import type {PathCommands} from './common.js';
import {buildPath, emptyBounds, fillPathWithBoxStyle} from './highlight_common.js';
export interface IsolatedElementHighlight {
widthResizerBorder: PathCommands;
heightResizerBorder: PathCommands;
bidirectionResizerBorder: PathCommands;
currentX: number;
currentY: number;
currentWidth: number;
currentHeight: number;
highlightIndex: number;
isolationModeHighlightConfig: {
resizerColor: string,
resizerHandleColor: string,
maskColor: string,
};
}
export function drawIsolatedElementHighlight(
highlight: IsolatedElementHighlight, context: CanvasRenderingContext2D, canvasWidth: number, canvasHeight: number,
emulationScaleFactor: number) {
const {currentX, currentY, currentWidth, currentHeight, highlightIndex} = highlight;
// Draw a mask covering other area of the canvas.
context.save();
context.fillStyle = highlight.isolationModeHighlightConfig.maskColor;
context.fillRect(0, 0, canvasWidth, canvasHeight);
context.clearRect(currentX, currentY, currentWidth, currentHeight);
context.restore();
// Draw the width resizer with handle bars.
const bounds = emptyBounds();
const widthPath = buildPath(highlight.widthResizerBorder, bounds, emulationScaleFactor);
fillPathWithBoxStyle(context, widthPath, bounds, 0 /* angle */, {
fillColor: highlight.isolationModeHighlightConfig.resizerColor,
});
// Draw the height resizer with handle bars.
const heightPath = buildPath(highlight.heightResizerBorder, bounds, emulationScaleFactor);
fillPathWithBoxStyle(context, heightPath, bounds, 0 /* angle */, {
fillColor: highlight.isolationModeHighlightConfig.resizerColor,
});
// Draw the bidirection resizer with handle bars.
const bidirectionPath = buildPath(highlight.bidirectionResizerBorder, bounds, emulationScaleFactor);
fillPathWithBoxStyle(context, bidirectionPath, bounds, 0 /* angle */, {
fillColor: highlight.isolationModeHighlightConfig.resizerColor,
});
return {
widthPath,
heightPath,
bidirectionPath,
currentWidth,
currentHeight,
highlightIndex,
};
}