Bug 1369586 - Add a border around the grid area name overlay. r=gl

MozReview-Commit-ID: 3aUiVU3gKpq
This commit is contained in:
Micah Tigley 2017-06-02 22:05:55 -06:00
Родитель d2ac9519c1
Коммит c671140c63
2 изменённых файлов: 33 добавлений и 12 удалений

Просмотреть файл

@ -168,9 +168,8 @@ module.exports = createClass({
},
/**
* Displays a message text "Cannot show outline for this grid".
*
*/
* Displays a message text "Cannot show outline for this grid".
*/
renderCannotShowOutlineText() {
return dom.div(
{
@ -187,11 +186,11 @@ module.exports = createClass({
},
/**
* Renders the grid outline for the given grid container object.
*
* @param {Object} grid
* A single grid container in the document.
*/
* Renders the grid outline for the given grid container object.
*
* @param {Object} grid
* A single grid container in the document.
*/
renderGrid(grid) {
// TODO: We are drawing the first fragment since only one is currently being stored.
// In the future we will need to iterate over all fragments of a grid.

Просмотреть файл

@ -1166,9 +1166,8 @@ CssGridHighlighter.prototype = extend(AutoRefreshHighlighter.prototype, {
let canvasY = Math.round(this._canvasPosition.y * devicePixelRatio);
this.ctx.translate(offset - canvasX, offset - canvasY);
this.ctx.font = (fontSize * currentZoom) + "px " + GRID_FONT_FAMILY;
this.ctx.font = fontSize + "px " + GRID_FONT_FAMILY;
this.ctx.strokeStyle = this.color;
this.ctx.fillStyle = this.color;
this.ctx.textAlign = "center";
this.ctx.textBaseline = "middle";
@ -1181,15 +1180,38 @@ CssGridHighlighter.prototype = extend(AutoRefreshHighlighter.prototype, {
// Check if the font size is exceeds the bounds of the containing grid cell.
if (fontSize > column.breadth || fontSize > row.breadth) {
fontSize = (column.breadth + row.breadth) / 2;
this.ctx.font = (fontSize * currentZoom) + "px " + GRID_FONT_FAMILY;
this.ctx.font = fontSize + "px " + GRID_FONT_FAMILY;
}
let textWidth = this.ctx.measureText(area.name).width;
// The width of the character 'm' approximates the height of the text.
let textHeight = this.ctx.measureText("m").width;
// Padding in pixels for the line number text inside of the line number container.
let padding = 3 * displayPixelRatio;
let boxWidth = textWidth + 2 * padding;
let boxHeight = textHeight + 2 * padding;
let x = column.start + column.breadth / 2;
let y = row.start + row.breadth / 2;
[x, y] = apply(this.currentMatrix, [x, y]);
this.ctx.fillText(area.name, x, y);
let rectXPos = x - boxWidth / 2;
let rectYPos = y - boxHeight / 2;
// Draw a rounded rectangle with a border width of 1 pixel,
// a border color matching the grid color, and a white background
this.ctx.lineWidth = 1 * displayPixelRatio;
this.ctx.strokeStyle = this.color;
this.ctx.fillStyle = "white";
let radius = 2 * displayPixelRatio;
drawRoundedRect(this.ctx, rectXPos, rectYPos, boxWidth, boxHeight, radius);
this.ctx.fillStyle = this.color;
this.ctx.fillText(area.name, x, y + padding);
}
}