diff --git a/com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecoratorTest.java b/com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecoratorTest.java index aed8d39..bb8f9db 100644 --- a/com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecoratorTest.java +++ b/com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecoratorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 EclipseSource and others. + * Copyright (c) 2013, 2021 EclipseSource and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -69,4 +69,32 @@ public void testSetsOverlay() { verify( shell ).setData( WhiteListEntry.OVERLAY_COLOR.getKey(), expectedColor ); } + @Test( expected = IllegalArgumentException.class ) + public void testSetTitlebarColor_FailsWithNegativeAlpha() { + Color color = new Color( display, 233, 244, 255 ); + + decorator.setTitlebarColor( color, -34 ); + } + + @Test( expected = IllegalArgumentException.class ) + public void testSetTitlebarColor_FailsWithToBigAlpha() { + Color color = new Color( display, 233, 244, 255 ); + + decorator.setTitlebarColor( color, 256 ); + } + + @Test( expected = IllegalArgumentException.class ) + public void testSetTitlebarColor_FailsWithNullColor() { + decorator.setTitlebarColor( null, 254 ); + } + + @Test + public void testSetTitlebarColor() { + Color color = new Color( display, 233, 244, 255 ); + decorator.setTitlebarColor( color, 34 ); + + JsonArray expectedColor = new JsonArray().add( 233 ).add( 244 ).add( 255 ).add( 34 ); + verify( shell ).setData( WhiteListEntry.TITLEBAR_COLOR.getKey(), expectedColor ); + } + } diff --git a/com.eclipsesource.tabris/src/com/eclipsesource/tabris/internal/DataWhitelist.java b/com.eclipsesource.tabris/src/com/eclipsesource/tabris/internal/DataWhitelist.java index 1f9bf84..93b70e6 100644 --- a/com.eclipsesource.tabris/src/com/eclipsesource/tabris/internal/DataWhitelist.java +++ b/com.eclipsesource.tabris/src/com/eclipsesource/tabris/internal/DataWhitelist.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 EclipseSource and others. + * Copyright (c) 2013, 2021 EclipseSource and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,6 +33,7 @@ public enum WhiteListEntry { SHOW_TOUCH( "showTouch" ), BADGE_VALUE( "badgeValue" ), OVERLAY_COLOR( "overlayColor" ), + TITLEBAR_COLOR( "titlebarColor" ), TEXT_REPLACEMENT( "textReplacement" ), AUTO_CAPITALIZE( "autoCapitalize" ), KEYBOARD_APPEARANCE_MODE( "keyboardAppearanceMode" ), diff --git a/com.eclipsesource.tabris/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecorator.java b/com.eclipsesource.tabris/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecorator.java index b943af9..e9dfc0f 100644 --- a/com.eclipsesource.tabris/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecorator.java +++ b/com.eclipsesource.tabris/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecorator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 EclipseSource and others. + * Copyright (c) 2013, 2021 EclipseSource and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ import static com.eclipsesource.tabris.internal.Clauses.when; import static com.eclipsesource.tabris.internal.Clauses.whenNull; import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.OVERLAY_COLOR; +import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.TITLEBAR_COLOR; import static com.eclipsesource.tabris.internal.WidgetsUtil.setData; import org.eclipse.rap.json.JsonArray; @@ -51,4 +52,23 @@ public ShellDecorator setOverlayColor( Color color, int alpha ) { setData( shell, OVERLAY_COLOR, overlay ); return this; } + + /** + *

+ * Specifies the titlebar color of modal shells. + *

+ * + * @param color the color to use for shell titlebar. Must not be null. + * @param alpha the alpha value of the color. + * + * @since 3.17 + */ + public ShellDecorator setTitlebarColor( Color color, int alpha ) { + whenNull( color ).throwIllegalArgument( "Color must not be null" ); + when( alpha < 0 || alpha > 255 ).throwIllegalArgument( "Alpha must be >= 0 and <= 255 but was " + alpha ); + RGB rgb = color.getRGB(); + JsonArray overlay = new JsonArray().add( rgb.red ).add( rgb.green ).add( rgb.blue ).add( alpha ); + setData( shell, TITLEBAR_COLOR, overlay ); + return this; + } }