Mit der auf dem iPhone verwendeten Rendering-Engine WebKit steht der vielleicht leistungsfähigste Browser nun auch auf einem mobilen Gerät zur Verfügung. Gerade seine umfangreiche Unterstützung von HTML5 und CSS3 eignet sich perfekt um hochklassige und leistungsfähige Web-Applikationen zu entwickeln, die den nativen Applikationen oftmals um nichts nachstehen. Wir beleuchten sämtliche verfügbare Techniken an Hand zahlreicher Beispiele und wagen einen Ausblick auf die Zukunft von WebKit, die längst nicht beim iPhone aufhört, sondern bereits viele andere Hersteller wie Nokia, Palm, Google und Blackberry infiziert hat.
Webapplikationen der Zukunft - HTML5 und CSS3 auf dem iPhone
1. WEBAPPLIKATIONEN DER
ZUKUNFT
HTML5 und CSS3 auf dem iPhone
02.12.2009 | iPhone developer conference | Köln, Wasserturm
Patrick Lobacher (GF typofaktum)
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009
2. ÜBER TYPOFAKTUM
• Münchner Fullservice-Agentur für Unternehmenskommunikation
• Inhabergeführt: Patrick Lobacher / Christoph Laruelle
• Spezialisiert
auf Webapplikations-Entwicklung,
vorwiegend mit Hilfe von TYPO3
• Gründung vor 16 Jahren (net-o-graphic / Agentur Laruelle)
Zusammenschluss und Umbenennung am 02.01.2009
• Über 800 realisierte Projekte
• Kunden: Finanzscout 24, AGIP, Contraco, Arbeitsamt München,
Langenscheidt, Motorola, Seifert, Integralis, u.v.a.m
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 2
3. ÜBER TYPOFAKTUM
• GF Patrick Lobacher hat zahlreiche Publikationen über alle Aspekte der iPhone
Webapplikationsentwicklung geschrieben:
• Geschäftsbereiche
• TYPO3 Konzeption, Entwicklung, Programmierung, Integration
(inkl. Extbase / Fluid / FLOW3)
• Webapplikationsentwicklung (PHP, iPhone, ...)
• Consulting, Projektmanagement & Coaching
• Schulung (inkl. komplettes TYPO3-Curriculum von Anfäger bis Fortgeschrittene
und Spezialschulungen sowie Firmen- und Individualschulungen)
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 3
4. DAS BUCH ZUM VORTRAG
ACHTUNG!
Unverschämte
• Patrick Lobacher Eigenwerbung :-)
und Alexander Ebner
Broschiert: 324 Seiten
Verlag: Open Source Press;
Au age: 1 (Juni 2009)
• ISBN-10: 3937514864
ISBN-13: 978-3937514864
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 4
5. ÜBER TYPOFAKTUM
• Adresse:
typofaktum unternehmenskommunikation
belfortstr. 8
81667 münchen
tel 089 46 13 38 67
fax 089 46 13 38 68
email info@typofaktum.de
web http://www.typofaktum.de
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 X
6. WEBAPPS
Quo vadis
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 5
7. WO IST DAS SDK?
• iPhone seit
29. Juni 2007
• „Web-SDK“ am 11. Juni 2007
• SDK seit
06. März 2008
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 6
8. WO IST DAS SDK
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 7
11. WEBKIT
Mac OS X Windows
WebKit iPhone OS
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 10
12. WEBKIT
• freie HTML-Rendering-Bibliothek
• entwickelt von Apple aus KHTML und KJS
• Der Browser Safari basiert auf WebKit
• Safari ist für die folgenden Plattformen erhältlich
• Mac OS X
• Windows
• iPhone OS (iPhone & iPod)
• WebKit bietet die beste Unterstützung an Web-Standards
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 11
13. WEBKIT
• WebKit wird (dank OpenSource-Lizenz) in weiteren Anwendungen
integriert:
• Google Chrome
• Nokia Symbian OS (S60)
• Adobe AIR
• Google ANDROID
• PalmOS, Blackerry OS, Open Moko, ...
• iPhone OS enthält neueste WebKit Version
• Quelle: http://www.webkit.org
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 12
14. WEBKIT FEATURES
• HTML 4.01 / XHTML 1.0 & 1.1 / HTML5
• HTML 5 Of ine Webapps
• HTML 5 Audio und Video Element
• HTML 5 Geolocation API
• CSS 2.1 vollständig und CSS 3 teilweise
• JavaScript 1.4 (inkl. kompletter DOM-Unterstützung)
• JavaScript Multitouch & Gesture API
• Canvas
• AJAX (XMLHTTP-Request) / Web 2.0
• SVG
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 13
20. CSS-TRANSFORMS
• Jedes HTML-Element kann ein Objekt sein
• Ausgangspunkt ist die Mitte des Objekts
0
X-Achse
Y-Achse
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 19
21. CSS-TRANSFORMS
• Setzt den Ausgangspunkt neu
-webkit-transform-origin: posx
-webkit-transform-origin: posx posy
• Werte, prozentuale Angaben oder Konstanten
• Konstanten posx: left, center, right
• Konstanten posy: top, center, bottom
• Default ist: 50% 50%
• -webkit-transform-origin-x: posx
-webkit-transform-origin-y: posy
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 20
22. CSS-TRANSFORMS: TRANSLATE
• Bewegt das Objekt
• Angabe in Pixel oder Prozent
• Prozentangaben sind relativ zur Objekt-Box
• translate, translateX, translateY
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 21
25. CSS-TRANSFORMS: SCALE
• Wenn der Absolut-Wert größer als 1 ist, wird das Objekt
vergrößert
• Wenn der Absolut-Wert kleiner als 1 ist, wird das Objekt
verkleinert
• Negative Werte spiegeln das Objekt
• scale, scaleX, scaleY
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 24
29. CSS-TRANSFORMS: ROTATE
• Dreht das Objekt um den Ausgangspunkt
• Werte können als Grad oder Rad angegeben werden
• rotate
45°
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 28
32. CSS-TRANSFORMS: SKEW
• Verzerrt das Objekt um einen angegebenen Winkel
• Werte können als Grad oder Rad angegeben werden
• skew, skewX, skewY
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 31
38. CSS-TRANSFORMS 3D
• -webkit-transform:
• translate3d(x, y, z)
• translateZ(length
• rotateZ(angle)
• rotate3d(x, y, z, angle) (Rotation um den Vektor)
• matrix3d(m11, m12, …, m44) (4x4 Matrix)
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 37
39. CSS-TRANSFORMS 3D
• -webkit-transform-style:
• at / preserve-3d
• -webkit-perspective: <tiefe>
• Der Wert „tiefe“ gibt den
Abstand des Betrachters zur
Z-Ebene (z=0) an (Default: tiefe = 0)
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 38
40. CSS-TRANSITIONS
• Hardware beschleunigte Übergänge
• Animation von einem alten Zustand in einen
neuen innerhalb einer gewissen Zeit
• Wird eine CSS-Eigenschaft geändert, für die ein
Übergang de niert ist, so wird dieser ausgeführt
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 39
41. CSS-TRANSITIONS
• Tappen ändert
vier CSS-Werte:
• Breite
• Höhe
• Hintergrundfarbe
• Abstand von oben
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 40
48. CSS-ANIMATIONS
• Tappen startet die Animation
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 47
49. CSS-ANIMATIONS
• -webkit-animation-name
• Name der Animation,
dafür muss eine @rule de niert sein
• -webkit-animation-duration
• Dauer (Default 0 Sekunden)
• -webkit-animation-timing-function
• Geschwindigkeitskurve (Default „ease“)
• -webkit-animation-iteration-count
• Anzahl der Animationen (Default 1)
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 48
50. CSS-ANIMATIONS
• -webkit-animation-direction
• Richtung der Animation („normal“ für normale Richtung, „alternate“
für normale Richtung bei ungeraden Durchläufen und umgekehrte
Richtung bei geraden Durchläufen)
• -webkit-animation-play-state
• Zustand der Animation („running“ wenn die Animation läuft und
„paused“ wenn diese pausiert - Default „running“)
• -webkit-animation-delay
• Verzögerung am Anfang
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 49
57. HTML5: OFFLINE WEBAPPS
• Local und Session Storage
• HTML5 Database Storage
• HTML Application Cache
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 56
58. LOCAL / SESSION STORAGE
• Cookies haben einige Nachteile
• Nicht an ein Browserfenster gebunden sondern an die Session
• Cookie-Daten müssen bei jedem Request im Header übertragen
werden
• Zwei neue Speicher-Objekte:
• localStorage
(längere Vorhaltung der Daten über Browserfenster hinweg)
• sessionStorage
(kurze Vorhaltung der Daten - bis Schließen des Fensters)
• HTML 5 client-side storage speci cation
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 57
59. LOCAL / SESSION STORAGE
// Speichern des Wertepaares key => value im Session Storage
sessionStorage.setItem("key", value);
localStorage.setItem("key", value);
// Ermitteln des Wertes zum Schlüssel key
var value = sessionStorage.getItem("key");
// Und nun wird der Wert wieder gelöscht
sessionStorge.removeItem("key");
try {
sessionStorage.setItem("shirt_size", myShirtSize);
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert('Quota exceeded.');
}
}
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 58
60. HTML5: DATABASE STORAGE
• SQLite - Relationale Datenbank auf Dateibasis
• Asynchroner und Callback-Zugriff (per Query und per
Transaction) möglich
• Sicherheitsmodell: Same Origin Policy
• Features
• Indexes
• Triggers
• Transactions
• u.v.a.m.
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 59
61. HTML5: DATABASE STORAGE
try {
if (!window.openDatabase) {
alert('Kein HTML5 Database Storage möglich!');
} else {
var shortName = 'zeiterfassung';
var version = '1.0';
var displayName = 'Meine Zeiterfassung';
var expectedSize = 65536; // Angabe in Bytes
var mydb = openDatabase(shortName, version,
displayName, expectedSize);
}
} catch(e) {
if (e == INVALID_STATE_ERR) {
alert("Falsche Version!");
} else {
alert("Unbekannter Fehler "+e+".");
}
return;
}
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 60
62. HTML5: DATABASE STORAGE
db.transaction(
function (transaction) {
transaction.executeSql(
SQL,
[Werte-Array, die statt ‚?‘ ersetzt werden],
dataHandler,
errorHandler
);
},
transactionError,
transactionSuccess
);
var projekt = "iPhoneDevCon";
var stunden = "3.50";
transaction.executeSql(
"UPDATE zeiten SET stunden=? where projekt=?;",
[prokjekt,stunden], dataHandler, errorHandler);
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 61
63. HTML5: DATABASE STORAGE
function createTables(db) {
db.transaction(
function (transaction) {
transaction.executeSql(
'CREATE TABLE zeiten(
id INTEGER PRIMARY KEY AUTOINCREMENT,
projekt TEXT NOT NULL,
stunden REAL NOT NULL);',
[], dataHandler, errorHandler);
}
);
}
WICHTIG! SQL-Statement in eine Zeile!!
transaction.executeSql("DROP TABLE IF EXISTS zeiten",
[],dataHandler,errorHandler);
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 62
65. HTML5: DATABASE STORAGE
db.transaction(
function (transaction) {
transaction.executeSql(
"SELECT * from zeiten",
[], // Werte-Array für ?-Platzhalter
dataHandler, errorHandler);
}
)
function dataHandler(transaction, results) {
var ausgabe = "Zeiten:nn";
for (var i=0; i < results.rows.length; i++) {
var zeit = results.rows.item(i);
ausgabe += „Projekt: „ + zeit['projekt'] + 'n';
ausgabe += „Stunden: „ + zeit['stunden'] + 'n';
}
}
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 64
66. HTML5: DATABASE STORAGE
function errorHandler(transaction, error) {
// error.message ist eine
// ausführliche Fehlerbeschreibung
// error.code ist der interne Fehlercode
alert('Fehler ist '
+ error.message
+ ' (Code '
+ error.code
+ ')');
// Fatal Error - ja oder nein? (Rollback bei true)
fatalError = true;
return fatalError;
}
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 65
67. HTML5: DATABASE STORAGE
Eigenschaft Beschreibung
error.code interner Fehlercode
error.message ausführliche Fehlerbeschreibung
results.rows.length Anzahl der Ergebniszeilen
Ergebnis der Spalte 'name' der i-ten
results.rows.item(i)['name']
Ergebniszeile
Anzahl der Zeilen die bei einem DELETE oder
results.rowAffected
UPDATE Befehl betroffen waren
Eindeutige ID der letzten Einfüge-Aktion durch
results.insertId
INSERT
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 66
68. HTML5: APPLICATION CACHE
• Resource Manifest
• Textdatei mit Liste der URLs aller benötigten Assets
• Addressierung relativ oder absolut
• MimeType: text/cache-manifest
• Erste Zeile muss enthalten: CACHE MANIFEST
• Die HTML-Datei, in der das Cache Manifest referenziert wird,
muss nicht angegeben werden
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 67
69. HTML5: APPLICATION CACHE
• BeispielhafterInhalt
Datei mit Namen “demo.manifest“
CACHE MANIFEST
css/style.css
js/script.js
img/bild1.png
kontakt.html
http://www.iphonedevcon.de/images/header.gif
• Referenzierung im HTML
<html manifest=“demo.manifest“>
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 68
70. HTML5: APPLICATION CACHE
• Der Application Cache updated sich nur
wenn sich der Inhalt des Cache Manifest ändert
• Update via JavaScript möglich
• Objekt: window.applicationCache
window.applicationCache.status
/* UNCACHED = 0;
IDLE = 1;
CHECKING = 2;
DOWNLOADING = 3;
UPDATEREADY = 4;
OBSOLETE = 5; */
window.applicationCache.update()
window.applicationCache.swapCache()
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 69
71. AUDIO & VIDEO
HTML5
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 70
72. HTML5: VIDEO & AUDIO
• Einbettenvon Medien mittels HTML5
<audio> und <video> Tags
• Media-Events
• Abspiel-UI beliebig anpassbar
• Fallback wenn HTML5 nicht verfügbar
• Flash
• Java (Ogg, ...)
• http://www.youtube.com/html5
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 71
73. HTML5: VIDEO & AUDIO
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 72
74. HTML5: VIDEO & AUDIO
<video src=“sample.mov“ autoplay=“true“></video>
<script>
function playPause() {
var myVideo = document.getElementsByTagName('video')[0];
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
</script>
<input type=button onclick=”playPause()” value=”Play/Pause”>
myVideo.addEventListener('ended', function () {
alert('video playback finished')
} );
var audio = new Audio("song.mp3");
audio.play();
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 73
77. HTML5: VIDEO & AUDIO
• H.264 Simple baseline pro le video (main and extended video compatible) level 3 and Low-Complexity AAC audio in MP4
container
• H.264 Extended pro le video (baseline-compatible) level 3 and Low-Complexity AAC audio in MP4 container
• H.264 Main pro le video level 3 and Low-Complexity AAC audio in MP4 container
• H.264 "High" pro le video (incompatible with main, baseline, or extended pro les) level 3 and Low-Complexity AAC audio
in MP4 container
• MPEG-4 Visual Simple Pro le Level 0 video and Low-Complexity AAC audio in MP4 container
• MPEG-4 Advanced Simple Pro le Level 0 video and Low-Complexity AAC audio in MP4 container
• MPEG-4 Visual Simple Pro le Level 0 video and AMR audio in 3GPP container
• Theora video and Vorbis audio in Ogg container
• Theora video and Speex audio in Ogg container
• Vorbis audio alone in Ogg container
• Speex audio alone in Ogg container
• FLAC audio alone in Ogg container
• Dirac video and Vorbis audio in Ogg container
• Theora video and Vorbis audio in Matroska container
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 76
78. GEO LOCATION API
HTML5
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 77
79. HTML5: GEOLOCATION API
• Kapselung der Positionsermittlung
• GPS, WLAN, Bluetooth, o.ä.
• Ermittlung der aktuellen Position
• Nachfrage im Browser
• Tracking möglich
• Objekt: navigator.geolocation
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 78
80. HTML5: GEOLOCATION API
navigator.geolocation.getCurrentPosition(showMap);
function showMap(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
var trackId = navigator.geolocation.watchPosition(trackMap);
function trackMap(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
navigator.geolocation.clearWatch(trackId);
(c) 2009 - typofaktum unternehmenskommunikation | HTML5 & CSS3 | Patrick Lobacher | 02.12.2009 79