From 68af0d86c3a941e185b34926fdbc57c457466e28 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 31 Aug 2019 11:51:31 -0400 Subject: Improve popup position for vertical text --- ext/fg/js/source.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'ext/fg/js/source.js') diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index a360b331..a5421934 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -61,6 +61,10 @@ class TextSourceRange { return this.range.getBoundingClientRect(); } + getWritingMode() { + return TextSourceRange.getElementWritingMode(TextSourceRange.getParentElement(this.range.startContainer)); + } + getPaddedRect() { const range = this.range.cloneRange(); const startOffset = range.startOffset; @@ -204,6 +208,23 @@ class TextSourceRange { return state.remainder > 0; } + + static getParentElement(node) { + while (node !== null && node.nodeType !== Node.ELEMENT_NODE) { + node = node.parentNode; + } + return node; + } + + static getElementWritingMode(element) { + if (element === null) { + return 'horizontal-tb'; + } + + const style = window.getComputedStyle(element); + const writingMode = style.writingMode; + return typeof writingMode === 'string' ? writingMode : 'horizontal-tb'; + } } @@ -267,6 +288,10 @@ class TextSourceElement { return this.element.getBoundingClientRect(); } + getWritingMode() { + return 'horizontal-tb'; + } + select() { // NOP } -- cgit v1.2.3