UNPKG

2.3 kBPlain TextView Raw
1// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import type {PathCommands} from './common.js';
6import {buildPath, emptyBounds, fillPathWithBoxStyle} from './highlight_common.js';
7
8export interface IsolatedElementHighlight {
9 widthResizerBorder: PathCommands;
10 heightResizerBorder: PathCommands;
11 bidirectionResizerBorder: PathCommands;
12 currentX: number;
13 currentY: number;
14 currentWidth: number;
15 currentHeight: number;
16 highlightIndex: number;
17 isolationModeHighlightConfig: {
18 resizerColor: string,
19 resizerHandleColor: string,
20 maskColor: string,
21 };
22}
23
24export function drawIsolatedElementHighlight(
25 highlight: IsolatedElementHighlight, context: CanvasRenderingContext2D, canvasWidth: number, canvasHeight: number,
26 emulationScaleFactor: number) {
27 const {currentX, currentY, currentWidth, currentHeight, highlightIndex} = highlight;
28 // Draw a mask covering other area of the canvas.
29 context.save();
30 context.fillStyle = highlight.isolationModeHighlightConfig.maskColor;
31 context.fillRect(0, 0, canvasWidth, canvasHeight);
32 context.clearRect(currentX, currentY, currentWidth, currentHeight);
33 context.restore();
34
35 // Draw the width resizer with handle bars.
36 const bounds = emptyBounds();
37 const widthPath = buildPath(highlight.widthResizerBorder, bounds, emulationScaleFactor);
38 fillPathWithBoxStyle(context, widthPath, bounds, 0 /* angle */, {
39 fillColor: highlight.isolationModeHighlightConfig.resizerColor,
40 });
41
42 // Draw the height resizer with handle bars.
43 const heightPath = buildPath(highlight.heightResizerBorder, bounds, emulationScaleFactor);
44 fillPathWithBoxStyle(context, heightPath, bounds, 0 /* angle */, {
45 fillColor: highlight.isolationModeHighlightConfig.resizerColor,
46 });
47
48 // Draw the bidirection resizer with handle bars.
49 const bidirectionPath = buildPath(highlight.bidirectionResizerBorder, bounds, emulationScaleFactor);
50 fillPathWithBoxStyle(context, bidirectionPath, bounds, 0 /* angle */, {
51 fillColor: highlight.isolationModeHighlightConfig.resizerColor,
52 });
53
54 return {
55 widthPath,
56 heightPath,
57 bidirectionPath,
58 currentWidth,
59 currentHeight,
60 highlightIndex,
61 };
62}