Skip to content

Commit

Permalink
Draw borders inside the bounds of landmarks
Browse files Browse the repository at this point in the history
* Ensure that the border and label are drawn within landmarks@ bounding
  boxes.
* Resultant minor code tidy-ups.
* Switch the border and label to border-box sizing.
* Fixes #167.
  • Loading branch information
matatk committed Jun 8, 2018
1 parent 1962f84 commit 827e041
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/static/content.focusing.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ function ElementFocuser() {
const contrastChecker = new ContrastChecker()

const momentaryBorderTime = 2000
const borderWidthPx = 2
const outlineWidthPx = 2
const borderWidthPx = 4

const settings = {} // caches options locally (simpler drawing code)
let labelFontColour = null // computed based on border colour
Expand Down Expand Up @@ -161,8 +160,8 @@ function ElementFocuser() {

const borderDiv = document.createElement('div')
borderDiv.style.border = borderWidthPx + 'px solid ' + colour
borderDiv.style.boxSizing = 'border-box'
borderDiv.style.margin = '0'
borderDiv.style.outline = outlineWidthPx + 'px solid ' + colour
borderDiv.style.padding = '0'
// Pass events through - https://stackoverflow.com/a/6441884/1485308
borderDiv.style.pointerEvents = 'none'
Expand All @@ -172,13 +171,13 @@ function ElementFocuser() {
const labelDiv = document.createElement('div')
labelDiv.style.backgroundColor = colour
labelDiv.style.border = 'none'
labelDiv.style.boxSizing = 'border-box'
labelDiv.style.color = fontColour
labelDiv.style.display = 'inline-block'
labelDiv.style.fontFamily = 'sans-serif'
labelDiv.style.fontSize = fontSize + 'px'
labelDiv.style.fontWeight = 'bold'
labelDiv.style.margin = '0'
labelDiv.style.outline = 'none'
labelDiv.style.paddingBottom = '0.25em'
labelDiv.style.paddingLeft = '0.75em'
labelDiv.style.paddingRight = '0.75em'
Expand Down Expand Up @@ -207,15 +206,13 @@ function ElementFocuser() {
// element
function sizeBorderAndLabel(element, border, label) {
const elementBounds = element.getBoundingClientRect()
const elementTopEdgePx = window.scrollY + elementBounds.top
const elementTopEdgeStyle = window.scrollY + elementBounds.top + 'px'
const elementLeftEdgeStyle = window.scrollX + elementBounds.left + 'px'
const elementRightEdgeStyle =
window.innerWidth
- (window.scrollX + elementBounds.right + 2 * borderWidthPx)
+ 'px'
window.innerWidth - (window.scrollX + elementBounds.right) + 'px'

border.style.left = elementLeftEdgeStyle
border.style.top = elementTopEdgePx + 'px'
border.style.top = elementTopEdgeStyle
border.style.width = elementBounds.width + 'px'
border.style.height = elementBounds.height + 'px'

Expand All @@ -227,7 +224,7 @@ function ElementFocuser() {

label.style.removeProperty('left') // in case this was set before

label.style.top = elementTopEdgePx - borderWidthPx + 'px'
label.style.top = elementTopEdgeStyle
label.style.right = elementRightEdgeStyle

// Is part of the label off-screen?
Expand Down

0 comments on commit 827e041

Please sign in to comment.