Here's roughly how a bubble gets its size:

let doc  = LHDocument(html: msg.html, css: bubbleCSS)
let size = doc.layout(maxWidth: 480) // shrink-to-fit
bubble.frame.size = size + insets

(it's Objective-C++ really, but you get the idea)