Commit 3d06e2a4 authored by Hixie's avatar Hixie

Specs: hit testing (and some cleanup)

Review URL: https://codereview.chromium.org/727993002
parent f8340b77
......@@ -37,7 +37,7 @@ SKY MODULE
}
function getIntrinsicWidth() {
let width = this.node.getProperty('width');
if (typeof height != 'number') {
if (typeof width != 'number') {
// e.g. width: auto
width = 0;
let children = this.walkChildren();
......
......@@ -112,18 +112,48 @@
loop = children.next();
}
}
function inHex(topLeftX, topLeftY, width, height, hitX, hitY) {
let centerX = topLeftX - width/2;
let absCenteredHitX = Math.abs(hitX - centerX);
if (absCenteredHitX > width/2)
return false;
let centerY = topLeftY - height/2;
let absCenteredHitY = Math.abs(hitY - centerY);
if (absCenteredHitY > height/2)
return false;
if (absCenteredHitY < height * absCenteredHitX / (2 * width) + height / 2)
return true;
return false;
}
function hitTest(x, y) {
let cellCount = this.node.getProperty('beehive-count');
let cellDim = width / cellCount;
let children = this.walkChildren();
let loop = children.next();
while (!loop.done) {
let child = loop.value;
if (this.inHex(child.x, child.y, child.width, child.height, x, y))
return child.layoutManager.hitText(x, y);
loop = children.next();
}
return this.node;
}
}
sky.registerLayoutManager('beehive', BeehiveLayoutManager);
let BeehiveCountStyleValueType = new StyleValueType();
BeehiveCountStyleValueType.addParser((tokens) => {
let token = tokens.next();
if (token.done) throw new Error();
if (token.value.kind != 'number') throw new Error();
if (token.value.value <= 0) throw new Error();
if (Math.trunc(token.value.value) != token.value.value) throw new Error();
let result = token.value.value;
if (!token.next().done) throw new Error();
return result;
if (token.done)
throw new Error();
if (token.value.kind != 'number')
throw new Error();
if (token.value.value <= 0)
throw new Error();
if (Math.trunc(token.value.value) != token.value.value) // is integer
throw new Error();
return {
value: token.value.value;
}
});
sky.registerProperty({
name: 'beehive-count',
......
......@@ -10,9 +10,9 @@ SKY MODULE
sky.registerLayoutManager('spring', module.exports.SpringLayoutManager);
sky.registerProperty({
name: 'toolbar-spacing',
type: sky.LengthStyleValueType,
type: sky.PositiveLengthStyleValueType,
inherits: true,
initialValue: { value: 8, unit: 'px' },
initialValue: 8,
needsLayout: true,
});
module.exports.ToolbarLayoutManager = class ToolbarLayoutManager extends sky.LayoutManager {
......@@ -131,7 +131,7 @@ SKY MODULE
}
function getIntrinsicWidth() {
let width = this.node.getProperty('width');
if (typeof height != 'number') {
if (typeof width != 'number') {
let spacing = this.node.getProperty('toolbar-spacing');
if (typeof spacing != 'number')
spacing = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment