From dff208a654ba290b5be7b4ab79a72dacdf62037a Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 23 Oct 2023 13:41:44 +1300 Subject: [PATCH] Upload missing files. --- app/Integration2.hs | 66 +++++++++++++++ app/useragent.css | 78 ++++++++++++++++++ test.html | 194 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 app/Integration2.hs create mode 100644 app/useragent.css create mode 100644 test.html diff --git a/app/Integration2.hs b/app/Integration2.hs new file mode 100644 index 0000000..d947d16 --- /dev/null +++ b/app/Integration2.hs @@ -0,0 +1,66 @@ +module Main where + +import Text.HTML.DOM as HTML +import Text.XML as X +import Data.HTML2CSS (html2css, el2stylist) +import Network.URI (nullURI) + +import Data.CSS.Preprocessor.Conditions as CSSCond +import qualified Data.CSS.Preprocessor.PsuedoClasses as CSSPseudo +import qualified Data.CSS.Style as Style +import Stylist.Tree (StyleTree(..), preorder, treeMap) +import qualified Data.CSS.Preprocessor.Text as CSSTxt +import Data.Maybe (fromMaybe) + +import Graphics.Layout.CSS.Font (placeholderFont) +import Graphics.Layout.CSS (finalizeCSS', CSSBox) +import Graphics.Layout (LayoutItem, boxLayout) +import Graphics.Layout.Box (Length, Size(..), PaddedBox(..), zeroBox) + +import Control.Exception (evaluate) +import qualified Graphics.Text.Font.Choose as FC + +import Control.Concurrent.MVar (putMVar, newEmptyMVar, readMVar) +import Control.Concurrent (forkIO) +import Control.DeepSeq (NFData(..), ($!!)) + +resolve' = CSSCond.resolve lowerVars lowerToks +lowerVars _ = CSSCond.B False +lowerToks _ = CSSCond.B False + +stylize' style = preorder inner + where + inner parent _ el = Style.cascade style el [] $ + Style.inherit $ fromMaybe Style.temp parent + +main :: IO () +main = do + FC.init + doc <- HTML.readFile "test.html" + let css' :: CSSCond.ConditionalStyles (Style.VarParser (CSSTxt.TextStyle + (CSSBox Nil))) + css' = html2css doc nullURI $ CSSCond.conditionalStyles nullURI "temp" + css' `seq` print "Parsed page with CSS!" + let pseudoFilter = CSSPseudo.htmlPsuedoFilter Style.queryableStyleSheet + let css = CSSPseudo.inner $ resolve' pseudoFilter css' + let styles = CSSTxt.resolve $ treeMap Style.innerParser $ + stylize' css $ el2stylist $ X.documentRoot doc + styles `seq` print "Styled page!" + let layout :: LayoutItem Length Length Nil + layout = finalizeCSS' placeholderFont styles + layout `seq` print "Laying out page!" + res <- forkCompute $ boxLayout zeroBox { size = Size 1280 480 } layout False + readMVar res + FC.fini + +data Nil = Nil deriving Eq +instance Style.PropertyParser Nil where + temp = Nil + inherit _ = Nil + longhand _ _ _ _ = Nothing +instance NFData Nil where rnf Nil = () + +forkCompute dat = do + ret <- newEmptyMVar + forkIO $ putMVar ret $!! dat + return ret diff --git a/app/useragent.css b/app/useragent.css new file mode 100644 index 0000000..451cb4a --- /dev/null +++ b/app/useragent.css @@ -0,0 +1,78 @@ +html, address, +blockquote, +body, dd, div, +dl, dt, fieldset, form, +frame, frameset, +h1, h2, h3, h4, +h5, h6, noframes, +ol, p, ul, center, +dir, hr, menu, pre { display: block; unicode-bidi: embed } +li { display: list-item } +head { display: none } +table { display: table } +tr { display: table-row } +thead { display: table-header-group } +tbody { display: table-row-group } +tfoot { display: table-footer-group } +col { display: table-column } +colgroup { display: table-column-group } +td, th { display: table-cell } +caption { display: table-caption } +th { font-weight: bolder; text-align: center } +caption { text-align: center } +body { margin: 8px } +h1 { font-size: 2em; margin: .67em 0 } +h2 { font-size: 1.5em; margin: .75em 0 } +h3 { font-size: 1.17em; margin: .83em 0 } +h4, p, +blockquote, ul, +fieldset, form, +ol, dl, dir, +menu { margin: 1.12em 0 } +h5 { font-size: .83em; margin: 1.5em 0 } +h6 { font-size: .75em; margin: 1.67em 0 } +h1, h2, h3, h4, +h5, h6, b, +strong { font-weight: bolder } +blockquote { margin-left: 40px; margin-right: 40px } +i, cite, em, +var, address { font-style: italic } +pre, tt, code, +kbd, samp { font-family: monospace } +pre { white-space: pre } +button, textarea, +input, select { display: inline-block } +big { font-size: 1.17em } +small, sub, sup { font-size: .83em } +sub { vertical-align: sub } +sup { vertical-align: super } +table { border-spacing: 2px; } +thead, tbody, +tfoot { vertical-align: middle } +td, th, tr { vertical-align: inherit } +s, strike, del { text-decoration: line-through } +hr { border: 1px inset } +ol, ul, dir, +menu, dd { margin-left: 40px } +ol { list-style-type: decimal } +ol ul, ul ol, +ul ul, ol ol { margin-top: 0; margin-bottom: 0 } +u, ins { text-decoration: underline } +br:before { content: "\A"; white-space: pre-line } +center { text-align: center } +:link, :visited { text-decoration: underline } +:focus { outline: thin dotted invert } + +/* Begin bidirectionality settings (do not change) */ +BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override } +BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override } + +*[DIR="ltr"] { direction: ltr; unicode-bidi: embed } +*[DIR="rtl"] { direction: rtl; unicode-bidi: embed } + +@media print { + h1 { page-break-before: always } + h1, h2, h3, + h4, h5, h6 { page-break-after: avoid } + ul, ol, dl { page-break-before: avoid } +} diff --git a/test.html b/test.html new file mode 100644 index 0000000..2abbc6e --- /dev/null +++ b/test.html @@ -0,0 +1,194 @@ + + + + + + +~alcinnz/CatTrap - Argonaut Constellation git + + + + + + + + + + + + + + + + +
+
+

+~alcinnz/CatTrap +

+ +
+
+
+
+
+
+ Lays out the CSS Box Model, this being the internet some of these boxes will contain cats! +
+
+ +
+
+
+
+
+
+
+
+
+
+9478d630 + + — + + + Adrian Cochrane + + +6 days ago + +
+
Performance optimizations: Concurrency, & move download/styling/layout to out-of-thread.
+
+
+
+6db35caa + + — + + + Adrian Cochrane + + +2 months ago + +
+
Fix for Balkon update.
+
+
+
+590ef319 + + — + + + Adrian Cochrane + + +3 months ago + +
+
Fix inline sizing, handle length units for callers.
+
+
+
+
+
+
+

refs

+
+
main
+
+browse  +log  +
+
+
+
+

clone

+
+
read-only
+
https://git.argonaut-constellation.org/~alcinnz/CatTrap
+
read/write
+
git@git.argonaut-constellation.org:~alcinnz/CatTrap
+
+
+
+
+
+
+ + + + + + +

+ + You can also use your local clone with + git send-email. + +

+
+
+
+
+
+
+
+

#CatTrap

+

Repository | Issue Tracker

+

Lays out boxes according to the CSS Box Model, computing where to place e.g. images, paragraphs, containers, tables, etc onscreen given desired amounts of whitespace.

+

It is a layout engine for The Argonaut Stack browser engine, and as such this being the internet some of these boxes will inevitably contain cats.

+

TODO: Say more about how to use this once its implemented.

+

#Contributing

+

Please send patches to our issue tracker by either:

+ +

Whichever you find most convenient.

+

If you'd prefer to not make your email address public please contact alcinnz@argonaut-constellation.org !

+
+
+
+
+ + \ No newline at end of file -- 2.30.2