about summary refs log tree commit diff stats
path: root/src/layout
Commit message (Collapse)AuthorAgeFilesLines
* css: add reverse video extensionbptato2024-10-151-0/+2
| | | | | | | | | | | | Called -cha-reverse. Mostly to solve the problem that code tags are indistinguishable from regular text - on a graphical browser this is normally served by monospace font, but we always use monospace... So now the default ua.css adds reverse video to code and xmp. pre remains as it was, because it means "preformatted", not "monospaced". Also, it would mess with our whatever-to-HTML converter output.
* layout: fix float positioning in inline contextsbptato2024-10-151-60/+120
| | | | | | also fixes a bug in the previous commit where whitespacenum would be reset on absolute positioning + missing absolute margin handling without top/left/etc.
* layout: correct `position: absolute' (FINALLY)bptato2024-10-152-157/+229
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a) resolution of `position: absolute' percentage sizes with an indefinite containing block size (wait what?), and b) positioning of `position: absolute' inner block boxes inside inline boxes. a) is possible because `position: absolute' does not affect its parent's layout. I would love to have a long talk with whoever thought that specifying it like this is a good idea. You know, just because you can... anyways, shockingly enough, this was still the more straightforward part. b) forced me to change the box tree to allow blocks inside inlines, which is ugly, but no big deal. Two questions then remained: 1. *where* to put such boxes, and 2. *how large* these boxes should be; this is hardly obvious since an inline box does not have an unambiguous width or height. Of course the CSS standard, never too eager to fulfill my basic expectations, says nothing about this (other than "it's not defined"). So I first tried to reverse engineer what Gecko does, and after hours of pain and suffering I realized... that it's broken LOL https://bugzilla.mozilla.org/show_bug.cgi?id=489100 Therefore I ended up (partially) copying Blink behavior, which, while equally nonsensical as Gecko (and of course divergent), at least does not change after a partial layout. Thank you LayoutNG for saving my sanity. As for the practical benefits: this fixes the bug where Invidious [video] tags wouldn't show up. Hey, it's something! Still left to-do: `position: absolute' for `display: inline' boxes.
* layout, pager: preserve tabs on display, selection & outputbptato2024-10-101-6/+13
| | | | | | | | | | | | Substitute tabs with one of eight PUA characters based on their width, and convert them back in the pager: * TUI mode always prints spaces, but now handles tabs appropriately on cursor movement * dump mode tries to preserve hard tabs, but uses soft tabs when that is not possible (e.g. tabs after a margin, tab with background color, etc) * selection mode always outputs hard tabs.
* layout: small cleanupbptato2024-10-071-14/+11
| | | | the length check is not needed, we do that outside the loop already
* color: reduce CellColor size, misc color refactoringbptato2024-10-061-11/+19
| | | | | | * split out CSSColor from CellColor; now CellColor is just 4 bytes (which helps reduce FormatCell size) * unify color function naming (still not perfect)
* layout: fix floats overriding margin/paddingbptato2024-10-051-2/+3
|
* container: fix control char displaybptato2024-09-281-4/+4
| | | | | | Also, kill twidth and its friends; we haven't been using it for a while now. (In the future, a solution with PUA chars might be worth exploring.)
* layout: fix wrong padding offsetsbptato2024-09-272-54/+44
| | | | + some misc refactorings
* sixel: support transparencybptato2024-09-241-3/+1
| | | | | | | | | | | | | | | | | | Sixel can only represent transparency for fully transparent (alpha = 0) and fully opaque (alpha = 255) pixels, i.e. we would have to do blending ourselves to do this "properly". But what do you even blend? Background color? Images? Clearly you can't do text... So instead of going down the blending route, we now just approximate the 8-bit channel with Sixel's 1-bit channel and then patch it up with dither. It does look a bit weird, but it's not *that* bad, especially compared to the previous strategy of "blend with some color which hopefully happens to be the background color" (it rarely was). Note that this requires us to handle transparent images specially in term. That is, for opaque ones, we can leave out the "clear cells affected by image" part, but for transparent ones, we must clear the entire image every time.
* sixel: use inline background for blendingbptato2024-09-241-1/+3
| | | | still not really great, because inline background is a mess too
* layout: remove line-heightbptato2024-09-211-43/+13
| | | | | This was a bad idea that, despite my best efforts, never worked properly.
* Refactor img/*bptato2024-09-153-3/+3
| | | | | I've moved most image logic to adapter, so it doesn't really make sense to have this subdir anymore.
* renderdocument: fix image background coloringbptato2024-09-131-13/+16
| | | | special case it in paintBackground so that it doesn't look so ugly
* utils: add twtunibptato2024-09-082-30/+25
| | | | | | | | | | | | | | | | | | | std/unicode has the following issues: * Rune is an int32, which implies overflow checking. Also, it is distinct, so you have to convert it manually to do arithmetic. * QJS libunicode and Chagashi work with uint32, interfacing with these required pointless type conversions. * fastRuneAt is a template, meaning it's pasted into every call site. Also, it decodes to UCS-4, so it generates two branches that aren't even used. Overall this lead to quite some code bloat. * fastRuneAt and lastRune have frustratingly different interfaces. Writing code to handle both cases is error prone. * On older Nim versions which we still support, std/unicode takes strings, not openArray[char]'s. Replace it with "twtuni", which includes some improved versions of the few procedures from std/unicode that we actually use.
* canvas: move to separate CGI scriptbptato2024-09-013-4/+4
| | | | | | | | | | * stream: and passFd is now client-based, and accessible for buffers * Bitmap's width & height is now int, not uint64 * no more non-network Bitmap special case in the pager for canvas I just shoehorned it into the static image model, so it still doesn't render changes after page load. But at least now it doesn't crash the browser.
* layout: fix table height constraint typebptato2024-08-301-1/+9
| | | | | it's really min-height, not height; consistency is not CSS's strong suit...
* layout: fix whitespace weirdnessbptato2024-08-231-1/+3
| | | | | avoid adding whitespace to the previous atom if it's not on the current line
* winattrs: un-snakeifybptato2024-08-231-2/+2
|
* buffer, layout: small refactoringbptato2024-07-291-16/+15
|
* buffer, pager, config: add meta-refresh + misc fixesbptato2024-07-281-1/+1
| | | | | | | | | * buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
* layout: merge neighboring wordsbptato2024-07-283-32/+28
| | | | Great performance win on large documents.
* layout: inline table fixesbptato2024-07-271-54/+154
| | | | | | | * properly wrap inline internal table boxes in inline-table (instead of block-level table) * fix missing baseline in table wrapper boxes * fix wrong wrapping of misparented table/row/row group children
* layout: position: relative, absolute fixesbptato2024-07-261-34/+52
| | | | | | | | | | * support position: absolute on flex items * proper top/bottom/left/right calculation for position: relative * push positioned flex box sizes to positioned stack Still not perfect: position: absolute should always resolve percentage sizes and top/bottom/left/right, meaning absolute layout needs to be delayed until its containing box is fully layouted.
* layout: fix incorrect absolute positioningbptato2024-07-252-18/+26
| | | | It was broken for parent boxes with indefinite sizes.
* layout: min/max sizing fixesbptato2024-07-252-29/+58
| | | | | | | * fix max size trumping min size * respect min-width/max-width/min-height/max-height for images * fix xminwidth calculation for percentage-sized images with an indefinite containing size
* layout: fix various flex column sizing bugsbptato2024-07-221-24/+58
| | | | | | * fix flex column item width not being stretched * set minimum flex column height to the layouted item's height (to avoid overlap)
* renderdocument: fix clickable imagesbptato2024-07-121-0/+5
| | | | | | | | Paint the background with the current color, so that it gets associated with the owner styled node. (I didn't want to do this because it's slow, but otherwise image-mode gets very annoying to use.)
* renderdocument: clean up setTextbptato2024-07-061-100/+107
|
* layout: reduce copiesbptato2024-07-032-27/+35
| | | | | Text data is no longer stored separately in InlineFragments; instead, we now include refs to StyledNodes.
* layout: fix positioning bugbptato2024-07-021-4/+5
| | | | | top/left/right/bottom should only be used in renderdocument with position: absolute.
* renderdocument: avoid recursionbptato2024-06-301-9/+12
|
* layout: flex padding/margin fixesbptato2024-06-301-2/+8
|
* layout: clamp image size to available spacebptato2024-06-291-5/+14
| | | | reduces images spilling out of their containers
* layout: fix image baselinebptato2024-06-291-6/+5
| | | | I doubt this is correct, but at least it's less broken than previously
* layout: fix text-align + padding coloringbptato2024-06-291-1/+2
|
* img, loader: add image resizing, misc fixesbptato2024-06-282-9/+25
| | | | | | | | | | | | | | | * resize images with stb_image_resize * use tee for output handle redirection (redirectToFile blocks) * cache original image files * accept lseek in sandbox * misc stbi fixes For now, I just pulled in stb_image_resize v1. v2 is an extra 150K in size, not sure if it's worth the cost. (Either way, we can always switch later if needed, since the API is almost the same.) Next step: move sixel/kitty encoders to CGI, and cache their output in memory instead of the intermediate RGBA representation.
* layout: inline fixes & improvementsbptato2024-06-273-240/+201
| | | | | | | | | | | | | | | * fix text-align breaking down in the presence of floats * improve (and simplify) background color area painting This greatly simplifies inline layout by removing the additional text-align atom movement code and replacing it with a full re-layout when needed. That re-layout only occurs in (rare) cases where the text is likely to be relatively short anyway, so it's probably a win in any remotely realistic layout. This has also made it possible to at last merge the last three passes (horizontal/vertical alignment and background painting) and drop that weird synchronized tree + vector traversal.
* layout: simplifybptato2024-06-241-53/+44
|
* layout: avoid shrink-to-fit padding/margin overflowbptato2024-06-231-7/+12
|
* layout: get rid of incorrect hackbptato2024-06-231-1/+1
|
* layout: minor cleanupbptato2024-06-041-7/+4
|
* layout: track overflow sizebptato2024-06-042-48/+130
| | | | | | Not very useful yet; partial layouting and/or a new renderer is probably necessary to replace the current FormatCell-based node placement, otherwise it will be unbearably slow.
* renderdocument: handle overlapping double width charsbptato2024-06-021-1/+6
| | | | | See attached test case; previously, this would result in a missing space in visual mode and a crash in dump mode.
* layout: misc refactoringsbptato2024-06-021-209/+180
| | | | | * get rid of BlockGroup * unify BlockBox construction for flex, block, table
* layout: clean up inline tree constructionbptato2024-06-013-292/+309
| | | | | | | Much cleaner than the previous solution. Should also be somewhat less wasteful, as we no longer constantly rebuild the same tree with new branches.
* layout: dimSum -> sumbptato2024-06-011-22/+21
|
* layout: refactor resolveSizesbptato2024-06-011-140/+126
| | | | get rid of percHeight, unify min/max sizing, etc.
* layout: line box sizing fixesbptato2024-05-311-15/+11
| | | | | * do not use inline block computed values for wrapper fragment * fix minimum line box height calculation
* layout: fix a width sizing bugbptato2024-05-301-4/+1
| | | | | | | As expected, the mystery line was just hiding another bug. (In particular, indefinite containing size constraints were not denied in resolveContentWidth, so it only (accidentally) worked with stretched sizes.)