Primo commit del progetto: motore Rust con parser HTML, cascata CSS, layout, raster CPU, formulari, bidi, flex, tabelle, JavaScript (Boa) con eventi e costruzione di nodi, rete HTTP/HTTPS con TLS, sotto-risorse, invio dei formulari; guscio grafico per Sailfish (QML/Silica) e per desktop (minifb, distribuito come AppImage), con 11 documenti di specifica e 91 casi di reftest.
372 lines
15 KiB
QML
372 lines
15 KiB
QML
import QtQuick 2.2
|
|
import Sailfish.Silica 1.0
|
|
import Harbour.Mosaic 1.0
|
|
|
|
Page {
|
|
id: page
|
|
|
|
/* Lo zoom vive nelle impostazioni: il pinch lo cambia e il valore
|
|
* sopravvive alla chiusura. Default 2.0 perché a scala 1 un testo da 16px
|
|
* su uno schermo da 1080 px è illeggibile. */
|
|
property real zoom: appSettings ? appSettings.zoom : 2.0
|
|
property real pinchStartZoom: 2.0
|
|
/* Zoom mostrato durante il pinch: scala l'immagine già pronta, senza
|
|
* ri-rasterizzare a ogni evento (un render costa ~40 ms sul telefono). */
|
|
property real liveZoom: zoom
|
|
|
|
onZoomChanged: if (appSettings) appSettings.zoom = zoom
|
|
|
|
/* Documento di prova M0: è il contenuto che il motore sa impaginare oggi
|
|
* (blocchi, testo, elenchi, sfondi, bordi, colore inline). Documentazione
|
|
* completa del perimetro in docs/01-requisiti.md. */
|
|
property string demoHtml:
|
|
"<h1>NCSA Mosaic</h1>" +
|
|
"<p>Riedizione 2026 con un motore di rendering scritto da zero: nessun WebKit, nessun Blink.</p>" +
|
|
"<div style=\"width:200px;height:6px;background:#000080\"></div>" +
|
|
"<h2>Modulo di prova</h2>" +
|
|
"<p style=\"font-size:15px\">Nome: <input type=\"text\" value=\"Mosaic\"></p>" +
|
|
"<p style=\"font-size:15px\"><input type=\"checkbox\" checked> attivo" +
|
|
" <input type=\"radio\" checked> A <input type=\"radio\"> B</p>" +
|
|
"<p style=\"font-size:15px\">Modalità: <select><option>uno</option>" +
|
|
"<option selected>due</option></select> " +
|
|
"<input type=\"submit\" value=\"Invia\"></p>" +
|
|
"<p style=\"font-size:15px\">Note: <textarea style=\"width:100%;height:44px\">" +
|
|
"testo lungo</textarea></p>" +
|
|
"<h2>Tabella</h2>" +
|
|
"<table style=\"width:100%\">" +
|
|
"<tr><th style=\"width:40%\">funzione</th><th>stato</th></tr>" +
|
|
"<tr><td>tabelle</td><td>colspan e colonne automatiche</td></tr>" +
|
|
"<tr><td>flex</td><td>riga, colonna, grow, gap</td></tr>" +
|
|
"<tr><td colspan=\"2\">bidi: paragrafi da destra</td></tr>" +
|
|
"</table>" +
|
|
"<h2>Disposizione con flex</h2>" +
|
|
"<div style=\"display:flex;gap:8px;height:56px\">" +
|
|
"<div class=\"scheda\" style=\"flex:1\">uno</div>" +
|
|
"<div class=\"scheda\" style=\"flex:2\">due</div>" +
|
|
"<div class=\"scheda\" style=\"flex:1\">tre</div>" +
|
|
"</div>" +
|
|
"<h2>Testo da destra</h2>" +
|
|
"<p dir=\"rtl\">שלום עולם — paragrafo RTL</p>" +
|
|
"<h2>Che cosa sa fare il motore, oggi</h2>" +
|
|
"<ul>" +
|
|
"<li>parse HTML con recupero dagli errori</li>" +
|
|
"<li>cascata CSS con @media, var() e margini collassanti</li>" +
|
|
"<li>layout a blocchi e inline, testo con kerning e legature</li>" +
|
|
"<li>immagini PNG, JPEG e WebP</li>" +
|
|
"</ul>" +
|
|
"<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC\" width=\"48\" height=\"48\">" +
|
|
"<p>Colori ereditati: <span style=\"color:#800000\">questo testo è rosso scuro</span> e questo no.</p>" +
|
|
"<div style=\"width:120px;height:40px;border:2px solid #000000;background:#ffffcc\"></div>" +
|
|
"<p>Due colonne con float:</p>" +
|
|
"<div style=\"width:100%;font-size:15px\">" +
|
|
"<div style=\"float:left;width:80px;height:60px;background:#3f9b46\"></div>" +
|
|
"<p>Questo testo scorre accanto al riquadro verde, come in una pagina del 1994.</p></div>" +
|
|
"<p style=\"font-family:SerifMosaic\">Questo paragrafo usa un font caricato con "
|
|
+ "@font-face dal pacchetto.</p>" +
|
|
"<p>Ancora fuori ambito: grid, script, rete.</p>"
|
|
|
|
property string demoCss:
|
|
"@font-face { font-family: SerifMosaic; src: url(fonts/DejaVuSerif.ttf) }" +
|
|
"body { background: #dcdcdc; }" +
|
|
"h1 { color: #000080; }" +
|
|
"h2 { color: #000000; font-size: 20px; }" +
|
|
"p { color: #202020; font-size: 15px; }" +
|
|
"table { width: 100%; }" +
|
|
"th, td { border: 1px solid #808080; padding: 4px; font-size: 13px }" +
|
|
"th { background: #e8e8d8 }" +
|
|
".scheda { background: #f4f4e8; border: 1px solid #808080; padding: 4px; font-size: 13px }"
|
|
|
|
PageHeader {
|
|
id: header
|
|
title: qsTr("Mosaic")
|
|
}
|
|
|
|
/* Flickable semplice: con SilicaFlickable e un menu in pagina i tocchi non
|
|
* arrivavano ai controlli. Il percorso che funziona è questo. */
|
|
Flickable {
|
|
id: flick
|
|
anchors.top: avvisoRete.visible ? avvisoRete.bottom : header.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: statusBar.top
|
|
contentWidth: width
|
|
contentHeight: Math.max(view.contentHeight, height)
|
|
clip: true
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
Item {
|
|
id: content
|
|
width: flick.width
|
|
height: view.contentHeight > 0 ? view.contentHeight : flick.height
|
|
|
|
transform: Scale {
|
|
origin.x: 0
|
|
origin.y: 0
|
|
xScale: page.liveZoom / page.zoom
|
|
yScale: page.liveZoom / page.zoom
|
|
}
|
|
|
|
EngineView {
|
|
id: view
|
|
width: content.width
|
|
height: content.height
|
|
zoom: page.zoom
|
|
html: page.demoHtml
|
|
extraCss: page.demoCss
|
|
}
|
|
|
|
/* Editor multi-riga per le textarea: gli a capo restano. */
|
|
TextEdit {
|
|
id: editorMulti
|
|
width: 1
|
|
height: 1
|
|
opacity: 0
|
|
onTextChanged: {
|
|
if (activeFocus && view.focusedKey !== "") {
|
|
view.setValue(view.focusedKey, text)
|
|
view.setCaret(cursorPosition)
|
|
}
|
|
}
|
|
onCursorPositionChanged: if (activeFocus) view.setCaret(cursorPosition)
|
|
}
|
|
|
|
/* Editor invisibile: esiste solo per aprire la tastiera virtuale e
|
|
* consegnare il testo al controllo che ha il fuoco. */
|
|
TextInput {
|
|
id: editor
|
|
width: 1
|
|
height: 1
|
|
opacity: 0
|
|
onTextChanged: {
|
|
if (activeFocus && view.focusedKey !== "") {
|
|
view.setValue(view.focusedKey, text)
|
|
view.setCaret(cursorPosition)
|
|
}
|
|
}
|
|
/* cursore e selezione: il motore li disegna sul controllo che ha
|
|
* il fuoco, il TextInput fornisce solo la posizione */
|
|
onCursorPositionChanged: if (activeFocus) view.setCaret(cursorPosition)
|
|
onSelectionStartChanged: if (activeFocus && selectionStart >= 0)
|
|
view.setSelection(selectionStart, selectionEnd)
|
|
onSelectionEndChanged: if (activeFocus && selectionEnd >= 0)
|
|
view.setSelection(selectionStart, selectionEnd)
|
|
}
|
|
}
|
|
|
|
/* Pinch a due dita per lo zoom; con un dito resta lo scroll.
|
|
* Durante il gesto si scala l'immagine, al rilascio si ricalcola nitido. */
|
|
PinchArea {
|
|
anchors.fill: parent
|
|
pinch.minimumScale: 0.75
|
|
pinch.maximumScale: 4.0
|
|
|
|
onPinchStarted: {
|
|
page.pinchStartZoom = page.zoom
|
|
page.liveZoom = page.zoom
|
|
}
|
|
onPinchUpdated: {
|
|
var ratio = pinch.previousScale > 0 ? pinch.scale / pinch.previousScale : 1
|
|
page.liveZoom = Math.max(0.75, Math.min(4.0, page.liveZoom * ratio))
|
|
}
|
|
onPinchFinished: page.zoom = page.liveZoom
|
|
|
|
/* Tocco sui controlli di modulo. Il MouseArea sta DENTRO la PinchArea:
|
|
* fuori, la PinchArea copre la vista e si mangia i tocchi (era il
|
|
* motivo per cui caselle e campi non rispondevano sul telefono).
|
|
* Il rettangolo dei controlli lo fornisce il motore, quindi il guscio
|
|
* non duplica la geometria. */
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
var cx = (mouse.x + flick.contentX) / view.zoom
|
|
var cy = (mouse.y + flick.contentY) / view.zoom
|
|
|
|
/* 1) elenco aperto: il tocco su una voce la sceglie */
|
|
var controlli = view.controls
|
|
for (var i = 0; i < controlli.length; i++) {
|
|
var pop = controlli[i].popup
|
|
if (!pop) continue
|
|
if (cx >= pop.x && cx <= pop.x + pop.w &&
|
|
cy >= pop.y && cy <= pop.y + pop.h) {
|
|
var riga = Math.floor((cy - pop.y) / controlli[i].rowHeight)
|
|
view.chooseOption(controlli[i].key, riga)
|
|
return
|
|
}
|
|
/* tocco fuori dall'elenco: si chiude */
|
|
view.setOpenSelect("")
|
|
}
|
|
|
|
var key = view.controlAt(cx, cy)
|
|
console.log("mosaic: tocco css=" + cx.toFixed(1) + "," + cy.toFixed(1) +
|
|
" controllo=" + key + " tipo=" + view.kindOf(key))
|
|
if (key === "") {
|
|
view.setOpenSelect("")
|
|
view.setFocus("")
|
|
editor.focus = false
|
|
return
|
|
}
|
|
view.setFocus(key)
|
|
var tipo = view.kindOf(key)
|
|
if (tipo === "checkbox" || tipo === "radio") {
|
|
view.toggle(key)
|
|
} else if (tipo === "select") {
|
|
/* un solo posto tiene lo stato: il C++ */
|
|
view.toggleSelect(key)
|
|
} else if (tipo === "textarea") {
|
|
/* la textarea accetta gli a capo: serve un editor multi-riga */
|
|
editorMulti.text = view.hasValue(key) ? view.value(key)
|
|
: view.textOf(key)
|
|
editorMulti.cursorPosition = editorMulti.length
|
|
editorMulti.forceActiveFocus()
|
|
} else if (tipo === "text" || tipo === "password") {
|
|
editor.text = view.hasValue(key) ? view.value(key) : view.textOf(key)
|
|
editor.cursorPosition = editor.length
|
|
editor.forceActiveFocus()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
/* Errore del motore: banner esplicito, mai pagina bianca muta. */
|
|
Rectangle {
|
|
id: errorBanner
|
|
visible: view.lastError !== ""
|
|
anchors.top: header.bottom
|
|
width: parent.width
|
|
height: Theme.itemSizeSmall
|
|
color: Theme.rgba("#cc0000", 0.9)
|
|
|
|
Label {
|
|
anchors.centerIn: parent
|
|
width: parent.width - 2 * Theme.paddingMedium
|
|
text: view.lastError
|
|
color: "white"
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
wrapMode: Text.Wrap
|
|
horizontalAlignment: Text.AlignHCenter
|
|
}
|
|
}
|
|
|
|
Item {
|
|
id: statusBar
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
height: Theme.itemSizeExtraSmall
|
|
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
x: Theme.paddingMedium
|
|
text: qsTr("motore M1") + " · " + Math.round(page.zoom * 100) + "% · "
|
|
+ view.renderMs + qsTr(" ms")
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.right: parent.right
|
|
x: -Theme.paddingMedium
|
|
text: qsTr("pinch: zoom")
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
}
|
|
|
|
/* Rete (M2.6): l'indirizzo si apre dal menu a tendina della testata.
|
|
* Il caricamento gira su un thread del guscio: la finestra non si blocca. */
|
|
/* Ingresso all'indirizzo con un pulsante: nessun gesto da indovinare e
|
|
* nessun widget che possa intercettare i tocchi della pagina. */
|
|
Button {
|
|
id: pulsanteIndirizzo
|
|
anchors.top: header.bottom
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: Theme.paddingMedium
|
|
anchors.topMargin: Theme.paddingSmall
|
|
z: 20
|
|
text: qsTr("Indirizzo")
|
|
onClicked: pannelloIndirizzo.open = true
|
|
}
|
|
|
|
DockedPanel {
|
|
id: pannelloIndirizzo
|
|
width: parent.width
|
|
height: colonna.height + Theme.paddingLarge
|
|
|
|
Column {
|
|
id: colonna
|
|
width: parent.width
|
|
spacing: Theme.paddingSmall
|
|
|
|
/* Column in QtQuick 2.2 non ha topPadding: un errore del genere rende
|
|
* la Page indisponibile e lo schermo resta bianco. Si usa un distanziale. */
|
|
Item {
|
|
width: 1
|
|
height: Theme.paddingLarge
|
|
}
|
|
|
|
TextField {
|
|
id: campoIndirizzo
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
placeholderText: qsTr("https://esempio.it")
|
|
label: qsTr("Indirizzo")
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
|
|
EnterKey.onClicked: {
|
|
view.loadUrl(text)
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
Row {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
spacing: Theme.paddingMedium
|
|
|
|
Button {
|
|
text: qsTr("Apri")
|
|
onClicked: {
|
|
view.loadUrl(campoIndirizzo.text)
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
Button {
|
|
text: qsTr("Ricarica")
|
|
onClicked: {
|
|
if (view.url.length > 0)
|
|
view.loadUrl(view.url)
|
|
else
|
|
view.setHtml(page.demoHtml)
|
|
pannelloIndirizzo.close()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Avviso di rete: il caricamento e l'errore non devono essere invisibili. */
|
|
Rectangle {
|
|
id: avvisoRete
|
|
anchors.top: header.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
height: Theme.itemSizeExtraSmall
|
|
visible: view.loadState === 1 || view.loadState === 3
|
|
color: view.loadState === 3 ? "#b03030" : "#205080"
|
|
z: 10
|
|
|
|
Label {
|
|
anchors.centerIn: parent
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
horizontalAlignment: Text.AlignHCenter
|
|
truncationMode: TruncationMode.Fade
|
|
color: "white"
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: view.loadState === 1
|
|
? qsTr("Caricamento di %1…").arg(view.url)
|
|
: view.networkError
|
|
}
|
|
}
|
|
}
|