SlideShare a Scribd company logo
1 of 47
Download to read offline
CSS3 meets GWT with GSS
Closure-stylesheets in GWT
Daniel Kurka
Software Engineer

Julien Dramaix
Software Engineer

Developers
!2
!3
What is this about?
• Introduction to Closure-stylesheets (GSS)
- Variables
- Functions
- Mixins
- Conditionals
- Linting
- RTL flipping

• Integration with GWT
• Timeline
• Demo

!4
DRY
http://farm3.staticflickr.com/2663/4241456606_be6fcc8b4e_o.jpg

!5
http://upload.wikimedia.org/wikipedia/commons/1/19/Lego_mess.jpg

!6
CSS is missing things
• variables
- repeating tokens in CSS files

• functions
- no way to express derived parameters

• macros
- duplicating code common code blocks

!7
Closure-stylesheets
• are an extension to CSS
• write GSS, compile to CSS
• adding variables, conditionals, mixing
• support minification, linting, RTL flipping, renaming

!8
Examples

!9
Variables
@def BG_COLOR

rgb(235, 239, 249);	

!
@def DIALOG_BORDER_COLOR
@def DIALOG_BG_COLOR

rgb(107, 144, 218);	
BG_COLOR;	

!
body {	
background-color: BG_COLOR;	
}	

!
.dialog {	
background-color: DIALOG_BG_COLOR;	
border: 1px solid DIALOG_BORDER_COLOR;	
}

!10
compiles to
body {	
background-color: #ebeff9;	
}	
.dialog {	
background-color: #ebeff9;	
border: 1px solid #6b90da;	
}

!11
Functions
• Several arithmetic functions
- add()
- sub()
- mult()
- divide()
- min()
- max()

• Variable number of arguments
• Arguments may be purely numeric or need to have the same CSS unit
• multiply and divide only allow a CSS unit for the first parameter
• not as flexible as CSS calc, but yields more maintainable stylesheets

!12
Functions
@def LEFT_HAND_NAV_WIDTH
@def LEFT_HAND_NAV_PADDING

180px;	
3px;	

!
.left_hand_nav {	
position: absolute;	
width: LEFT_HAND_NAV_WIDTH;	
padding: LEFT_HAND_NAV_PADDING;	
}	

!
.content {	
position: absolute;	
margin-left: add(LEFT_HAND_NAV_PADDING, /* padding left */	
LEFT_HAND_NAV_WIDTH,	
LEFT_HAND_NAV_PADDING); /* padding right */	
}

!13
compiles to
.left_hand_nav {	
position: absolute;	
width: 180px;	
padding: 3px;	
}	

!
.content {	
position: absolute;	
margin-left: 186px;	
}

!14
Functions
• blendColorsHsb(startColor, endColor) blends using HSB values
• blendColorsRgb(startColor, endColor) blends using RGB values
• makeMutedColor(backgroundColor, foregroundColor [, saturationLoss])
• addHsbToCssColor(baseColor, hueToAdd, saturationToAdd,
brightnessToAdd)
• makeContrastingColor(color, similarityIndex)
• adjustBrightness(color, brightness)
• ….

!15
Functions - selectFrom
/* Implies MYDEF = FOO ? BAR : BAZ; */	
@def MYDEF selectFrom(FOO, BAR, BAZ);	

!
/* @def FOO true; to have the effect of @def MYDEF = BAR. */

!16
Providing your own functions
• Implement GssFunctionMapProvider
• pass “--gss-function-map-provider” to the compiler

!17
Mixins
• reuse a list of parameterized declarations
• declaration
• a mixing can be used anywhere instead of a declaration

!18
Mixins
@defmixin size(WIDTH, HEIGHT) {	
width: WIDTH;	
height: HEIGHT;	
}	

!
.logo {	
@mixin size(150px, 55px);	
background-image: url('http://www.google.com/images/logo_sm.gif');	
}

!19
compiles to
.logo {	
width: 150px;	
height: 55px;	
background-image: url('http://www.google.com/images/logo_sm.gif');	
}

!20
Mixins - for browser specific code
@defmixin gradient(POS, HSL1, HSL2, HSL3, COLOR, FALLBACK_COLOR) {	
background-color: FALLBACK_COLOR; /* fallback color if gradients are not supported */	
background-image: -webkit-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR);
/* Chrome 10+,Safari 5.1+ */	
/* @alternate */ 	
background-image: -moz-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); 	
/* FF3.6+ */	
/* @alternate */ 	
background-image: -ms-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); /* IE10 */	
/* @alternate */ 	
background-image: -o-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR);
	
/* Opera 11.10+ */	
}	

!

.header {	
@mixin gradient(top, 0%, 50%, 70%, #cc0000, #f07575);	
}

!21
Mixins - for browser specific code
.header {	
background-color:
background-image:
background-image:
background-image:
background-image:
}

#f07575;	
-webkit-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000);	
-moz-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000);	
-ms-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000);	
-o-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000);	

!22
Conditionals
• defining variables in conditionals

!23
Conditionals
@if (BROWSER_IE) {	
@if (BROWSER_IE6) {	
@def GOOG_INLINE_BLOCK_DISPLAY
} @elseif (BROWSER_IE7) {	
@def GOOG_INLINE_BLOCK_DISPLAY
} @else {	
@def GOOG_INLINE_BLOCK_DISPLAY
}	
} @elseif (BROWSER_FF2) {	
@def GOOG_INLINE_BLOCK_DISPLAY
} @else {	
@def GOOG_INLINE_BLOCK_DISPLAY
}	

inline;	
inline;	
inline-block;	

-moz-inline-box;	
inline-block;	

!
.goog-inline-block {	
position: relative;	
display: GOOG_INLINE_BLOCK_DISPLAY;	
}

!24
Conditionals
• “java -jar closure-stylesheets.jar --define BROWSER_FF2 --pretty-print
conditionals-example.gss”
	
.goog-inline-block {	
position: relative;	
display: -moz-inline-box;	
}	

• “java -jar closure-stylesheets.jar --pretty-print conditionals-example.gss”
	
.goog-inline-block {	
position: relative;	
display: inline-box;	
}	

!25
Linting
• check your CSS for errors
• will fail the compile with an error message

!26
Linting
.logo {	
width: 150px;	
height: 55px;	
background-image: urel('http://www.google.com/images/logo_sm.gif');	
border-color: #DCDCDC;	
border-color: rgba(0, 0, 0, 0.1);	
}

!27
Linting
.logo {	
width: 150px;	
height: 55px;	
background-image: urel('http://www.google.com/images/logo_sm.gif');	
border-color: #DCDCDC;	
border-color: rgba(0, 0, 0, 0.1);	
}	

!
Unknown function "urel" in linting-example.gss at line 4 column 21:	
background-image: urel('http://www.google.com/images/logo_sm.gif');	
^	
Detected multiple identical, non-alternate declarations in the same
ruleset.	
If this is intentional please use the /* @alternate */ annotation.	
border-color:[rgba(0,0,0,0.1)] in linting-example.gss at line 7 column 1:	
}	
^	
2 error(s)

!28
RTL flipping
.logo {	
margin-left: 10px;	
}	

!
.shortcut_accelerator {	
/* Keyboard shortcuts are untranslated; always left-to-right. */	
/* @noflip */ direction: ltr;	
border-right: 2px solid #ccc;	
padding: 0 2px 0 4px;	
}	

!29
RTL flipping
.logo {	
margin-right: 10px;	
}	

!
.shortcut_accelerator {	
direction: ltr;	
border-left: 2px solid #ccc;	
padding: 0 4px 0 2px;	
}	

!30
GSS

!31
Integration with GWT
• Why ?
- Closure-stylesheets are powerful
- easier to maintain CSS
- GWT needs better CSS3 support

• What does it look like?
- A new GSSResource
- similar to CSSResource

!32
CSS: application.gss
@def PADDING_RIGHT 50px;	
@def PADDING_LEFT 50px;	

!
@defmixin size(WIDTH, HEIGHT) {	
width: WIDTH;	
height: HEIGHT;	
}	

!
.header, span[data-role^="header"] {	
display: block;	
@mixin size(150px, 50px);	
}	

!
.header-with-padding {	
@mixin size(add(PADDING_RIGHT, 150px, PADDING_LEFT), 50px);	
padding-right: PADDING_RIGHT;	
}

!33
Java: define GssResource
public interface ApplicationResources extends ClientBundle {	

!
public interface ApplicationGss extends GssResource {	
int paddingRight();	
	
String header();	

!
@ClassName("header-with-padding")	
String headerWithPadding();	
}	

!
@Source("application.gss")	
public ApplicationGss style();	
}

!34
Usage:
ApplicationResources resources = GWT.create(ApplicationResources.class);	
ApplicationGss style = resources.style();	
style.ensureInjected();	

!
// ...	
myWidget.addStyleName(style.header());

!35
CssResource features
• @sprite
• @eval
• value function

!36
Image sprite (@sprite)
.addIcon {	
gwt-sprite: 'addIcon';	
}

!37
Runtime substitution (@eval)
@def BLACK eval(‘mypackage.GssSampleApplication.black()’);	

!
.black {	
color: eval('mypackage.GssSampleApplication.black()');	
}

!38
Value function
@def ICON_WIDTH value('addIcon.getWidth', 'px');	

!39
How far is this done?
• supports all Closure-stylesheet features
• supported CssResource features
- image sprites
- runtime substitution
- value function
- RTL support

!40
What is missing?
• conditionals based on permutations
!
@if user.agent safari {	
/* ... */ 	
}	

!
@if locale en { 	
/* ... */ 	
}

!41
Roadmap
• Ready to use, but there might still be issues
• please test & report issues at: https://github.com/jDramaix/gss.gwt/
issues
• Expect missing user agent conditionals in Q1
• Unclear: How will CssResource transition look like
• If everything goes smoothly, expect GssResource in GWT 3.0, but you can
use it right now!

!42
Demo

!43
Summary
• simple and maintainable CSS with Closure-stylesheets
- many exciting features
- widely used inside of Google

• GssResource
- brings Closure-stylesheets to GWT, aka CssResource for CSS
- brings all CSS3 features to GWT
- thanks to Julien Dramaix for this big contribution

• Roadmap
- Test and report bugs!

!44
Questions?

!45
Julien Dramaix
gplus: https://plus.google.com/+JulienDramaix
twitter: @jDramaix
Daniel Kurka
www.m-gwt.com

!

gplus: daniel-kurka.de/+

!

twitter: @dankurka

More Related Content

What's hot

Keep calm and let's play CSS3
Keep calm and let's play CSS3Keep calm and let's play CSS3
Keep calm and let's play CSS3A2 Comunicação
 
Css week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandourCss week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Tahmina Khatoon
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockMarco Pinheiro
 
HTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersHTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersJason Hando
 

What's hot (7)

Keep calm and let's play CSS3
Keep calm and let's play CSS3Keep calm and let's play CSS3
Keep calm and let's play CSS3
 
Css week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandourCss week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandour
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, Greensock
 
SASS - CSS with Superpower
SASS - CSS with SuperpowerSASS - CSS with Superpower
SASS - CSS with Superpower
 
HTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersHTML5 and CSS3 for Teachers
HTML5 and CSS3 for Teachers
 

Similar to CSS3 meets GWT with GSS

CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid PrototypingEven Wu
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageKatsunori Tanaka
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrMichael Enslow
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3Jamshid Hashimi
 
[WebVisions 2010] CSS3 Workshop (Afternoon)
[WebVisions 2010] CSS3 Workshop (Afternoon)[WebVisions 2010] CSS3 Workshop (Afternoon)
[WebVisions 2010] CSS3 Workshop (Afternoon)Christopher Schmitt
 
Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan Stefan Bauer
 
CSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlCSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlChristian Heilmann
 
From CSS to Sass in WordPress
From CSS to Sass in WordPressFrom CSS to Sass in WordPress
From CSS to Sass in WordPressJames Steinbach
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewDiacode
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
 
Create SASSy web parts in SPFx
Create SASSy web parts in SPFxCreate SASSy web parts in SPFx
Create SASSy web parts in SPFxStefan Bauer
 
LESS is More
LESS is MoreLESS is More
LESS is Morejsmith92
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopShoshi Roberts
 

Similar to CSS3 meets GWT with GSS (20)

CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
CSS3 3D Workshop
CSS3 3D WorkshopCSS3 3D Workshop
CSS3 3D Workshop
 
CSS3
CSS3CSS3
CSS3
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet language
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking Modernizr
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3
 
[WebVisions 2010] CSS3 Workshop (Afternoon)
[WebVisions 2010] CSS3 Workshop (Afternoon)[WebVisions 2010] CSS3 Workshop (Afternoon)
[WebVisions 2010] CSS3 Workshop (Afternoon)
 
Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan
 
CSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. ControlCSS vs. JavaScript - Trust vs. Control
CSS vs. JavaScript - Trust vs. Control
 
From CSS to Sass in WordPress
From CSS to Sass in WordPressFrom CSS to Sass in WordPress
From CSS to Sass in WordPress
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
Css animation
Css animationCss animation
Css animation
 
Create SASSy web parts in SPFx
Create SASSy web parts in SPFxCreate SASSy web parts in SPFx
Create SASSy web parts in SPFx
 
[Bauer] SASSy web parts with SPFX
[Bauer] SASSy web parts with SPFX[Bauer] SASSy web parts with SPFX
[Bauer] SASSy web parts with SPFX
 
[heweb11] CSS3 Makeover
[heweb11] CSS3 Makeover[heweb11] CSS3 Makeover
[heweb11] CSS3 Makeover
 
LESS is More
LESS is MoreLESS is More
LESS is More
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 Workshop
 

Recently uploaded

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 

CSS3 meets GWT with GSS

  • 1. CSS3 meets GWT with GSS Closure-stylesheets in GWT Daniel Kurka Software Engineer Julien Dramaix Software Engineer Developers
  • 2. !2
  • 3. !3
  • 4. What is this about? • Introduction to Closure-stylesheets (GSS) - Variables - Functions - Mixins - Conditionals - Linting - RTL flipping • Integration with GWT • Timeline • Demo !4
  • 7. CSS is missing things • variables - repeating tokens in CSS files • functions - no way to express derived parameters • macros - duplicating code common code blocks !7
  • 8. Closure-stylesheets • are an extension to CSS • write GSS, compile to CSS • adding variables, conditionals, mixing • support minification, linting, RTL flipping, renaming !8
  • 10. Variables @def BG_COLOR rgb(235, 239, 249); ! @def DIALOG_BORDER_COLOR @def DIALOG_BG_COLOR rgb(107, 144, 218); BG_COLOR; ! body { background-color: BG_COLOR; } ! .dialog { background-color: DIALOG_BG_COLOR; border: 1px solid DIALOG_BORDER_COLOR; } !10
  • 11. compiles to body { background-color: #ebeff9; } .dialog { background-color: #ebeff9; border: 1px solid #6b90da; } !11
  • 12. Functions • Several arithmetic functions - add() - sub() - mult() - divide() - min() - max() • Variable number of arguments • Arguments may be purely numeric or need to have the same CSS unit • multiply and divide only allow a CSS unit for the first parameter • not as flexible as CSS calc, but yields more maintainable stylesheets !12
  • 13. Functions @def LEFT_HAND_NAV_WIDTH @def LEFT_HAND_NAV_PADDING 180px; 3px; ! .left_hand_nav { position: absolute; width: LEFT_HAND_NAV_WIDTH; padding: LEFT_HAND_NAV_PADDING; } ! .content { position: absolute; margin-left: add(LEFT_HAND_NAV_PADDING, /* padding left */ LEFT_HAND_NAV_WIDTH, LEFT_HAND_NAV_PADDING); /* padding right */ } !13
  • 14. compiles to .left_hand_nav { position: absolute; width: 180px; padding: 3px; } ! .content { position: absolute; margin-left: 186px; } !14
  • 15. Functions • blendColorsHsb(startColor, endColor) blends using HSB values • blendColorsRgb(startColor, endColor) blends using RGB values • makeMutedColor(backgroundColor, foregroundColor [, saturationLoss]) • addHsbToCssColor(baseColor, hueToAdd, saturationToAdd, brightnessToAdd) • makeContrastingColor(color, similarityIndex) • adjustBrightness(color, brightness) • …. !15
  • 16. Functions - selectFrom /* Implies MYDEF = FOO ? BAR : BAZ; */ @def MYDEF selectFrom(FOO, BAR, BAZ); ! /* @def FOO true; to have the effect of @def MYDEF = BAR. */ !16
  • 17. Providing your own functions • Implement GssFunctionMapProvider • pass “--gss-function-map-provider” to the compiler !17
  • 18. Mixins • reuse a list of parameterized declarations • declaration • a mixing can be used anywhere instead of a declaration !18
  • 19. Mixins @defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT; } ! .logo { @mixin size(150px, 55px); background-image: url('http://www.google.com/images/logo_sm.gif'); } !19
  • 20. compiles to .logo { width: 150px; height: 55px; background-image: url('http://www.google.com/images/logo_sm.gif'); } !20
  • 21. Mixins - for browser specific code @defmixin gradient(POS, HSL1, HSL2, HSL3, COLOR, FALLBACK_COLOR) { background-color: FALLBACK_COLOR; /* fallback color if gradients are not supported */ background-image: -webkit-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); /* Chrome 10+,Safari 5.1+ */ /* @alternate */ background-image: -moz-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); /* FF3.6+ */ /* @alternate */ background-image: -ms-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); /* IE10 */ /* @alternate */ background-image: -o-linear-gradient(POS, hsl(HSL1, HSL2, HSL3), COLOR); /* Opera 11.10+ */ } ! .header { @mixin gradient(top, 0%, 50%, 70%, #cc0000, #f07575); } !21
  • 22. Mixins - for browser specific code .header { background-color: background-image: background-image: background-image: background-image: } #f07575; -webkit-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000); -moz-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000); -ms-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000); -o-linear-gradient(top,hsl(0%,50%,70%) ,#cc0000); !22
  • 24. Conditionals @if (BROWSER_IE) { @if (BROWSER_IE6) { @def GOOG_INLINE_BLOCK_DISPLAY } @elseif (BROWSER_IE7) { @def GOOG_INLINE_BLOCK_DISPLAY } @else { @def GOOG_INLINE_BLOCK_DISPLAY } } @elseif (BROWSER_FF2) { @def GOOG_INLINE_BLOCK_DISPLAY } @else { @def GOOG_INLINE_BLOCK_DISPLAY } inline; inline; inline-block; -moz-inline-box; inline-block; ! .goog-inline-block { position: relative; display: GOOG_INLINE_BLOCK_DISPLAY; } !24
  • 25. Conditionals • “java -jar closure-stylesheets.jar --define BROWSER_FF2 --pretty-print conditionals-example.gss” .goog-inline-block { position: relative; display: -moz-inline-box; } • “java -jar closure-stylesheets.jar --pretty-print conditionals-example.gss” .goog-inline-block { position: relative; display: inline-box; } !25
  • 26. Linting • check your CSS for errors • will fail the compile with an error message !26
  • 27. Linting .logo { width: 150px; height: 55px; background-image: urel('http://www.google.com/images/logo_sm.gif'); border-color: #DCDCDC; border-color: rgba(0, 0, 0, 0.1); } !27
  • 28. Linting .logo { width: 150px; height: 55px; background-image: urel('http://www.google.com/images/logo_sm.gif'); border-color: #DCDCDC; border-color: rgba(0, 0, 0, 0.1); } ! Unknown function "urel" in linting-example.gss at line 4 column 21: background-image: urel('http://www.google.com/images/logo_sm.gif'); ^ Detected multiple identical, non-alternate declarations in the same ruleset. If this is intentional please use the /* @alternate */ annotation. border-color:[rgba(0,0,0,0.1)] in linting-example.gss at line 7 column 1: } ^ 2 error(s) !28
  • 29. RTL flipping .logo { margin-left: 10px; } ! .shortcut_accelerator { /* Keyboard shortcuts are untranslated; always left-to-right. */ /* @noflip */ direction: ltr; border-right: 2px solid #ccc; padding: 0 2px 0 4px; } !29
  • 30. RTL flipping .logo { margin-right: 10px; } ! .shortcut_accelerator { direction: ltr; border-left: 2px solid #ccc; padding: 0 4px 0 2px; } !30
  • 32. Integration with GWT • Why ? - Closure-stylesheets are powerful - easier to maintain CSS - GWT needs better CSS3 support • What does it look like? - A new GSSResource - similar to CSSResource !32
  • 33. CSS: application.gss @def PADDING_RIGHT 50px; @def PADDING_LEFT 50px; ! @defmixin size(WIDTH, HEIGHT) { width: WIDTH; height: HEIGHT; } ! .header, span[data-role^="header"] { display: block; @mixin size(150px, 50px); } ! .header-with-padding { @mixin size(add(PADDING_RIGHT, 150px, PADDING_LEFT), 50px); padding-right: PADDING_RIGHT; } !33
  • 34. Java: define GssResource public interface ApplicationResources extends ClientBundle { ! public interface ApplicationGss extends GssResource { int paddingRight(); String header(); ! @ClassName("header-with-padding") String headerWithPadding(); } ! @Source("application.gss") public ApplicationGss style(); } !34
  • 35. Usage: ApplicationResources resources = GWT.create(ApplicationResources.class); ApplicationGss style = resources.style(); style.ensureInjected(); ! // ... myWidget.addStyleName(style.header()); !35
  • 36. CssResource features • @sprite • @eval • value function !36
  • 37. Image sprite (@sprite) .addIcon { gwt-sprite: 'addIcon'; } !37
  • 38. Runtime substitution (@eval) @def BLACK eval(‘mypackage.GssSampleApplication.black()’); ! .black { color: eval('mypackage.GssSampleApplication.black()'); } !38
  • 39. Value function @def ICON_WIDTH value('addIcon.getWidth', 'px'); !39
  • 40. How far is this done? • supports all Closure-stylesheet features • supported CssResource features - image sprites - runtime substitution - value function - RTL support !40
  • 41. What is missing? • conditionals based on permutations ! @if user.agent safari { /* ... */ } ! @if locale en { /* ... */ } !41
  • 42. Roadmap • Ready to use, but there might still be issues • please test & report issues at: https://github.com/jDramaix/gss.gwt/ issues • Expect missing user agent conditionals in Q1 • Unclear: How will CssResource transition look like • If everything goes smoothly, expect GssResource in GWT 3.0, but you can use it right now! !42
  • 44. Summary • simple and maintainable CSS with Closure-stylesheets - many exciting features - widely used inside of Google • GssResource - brings Closure-stylesheets to GWT, aka CssResource for CSS - brings all CSS3 features to GWT - thanks to Julien Dramaix for this big contribution • Roadmap - Test and report bugs! !44