diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj
index a75cb6907..a9ef953d7 100644
--- a/CrossPlatformModules.csproj
+++ b/CrossPlatformModules.csproj
@@ -214,6 +214,9 @@
+
+ background.xml
+
@@ -241,6 +244,7 @@
image-source.d.ts
+
platform.d.ts
@@ -454,6 +458,16 @@
wrap-layout.d.ts
+
+ background.d.ts
+
+
+ background.d.ts
+
+
+
+ background.d.ts
+
css-selector.d.ts
@@ -646,7 +660,12 @@
-
+
+ fonts-test.xml
+
+
+ background-test.xml
+
Designer
@@ -655,7 +674,9 @@
+
+
@@ -683,6 +704,7 @@
+
@@ -692,11 +714,13 @@
+
+
PreserveNewest
@@ -1586,6 +1610,9 @@
PreserveNewest
+
+
+
@@ -1648,7 +1675,7 @@
False
-
+
\ No newline at end of file
diff --git a/apps/tests/pages/background-test.ts b/apps/tests/pages/background-test.ts
new file mode 100644
index 000000000..d3fc95ba5
--- /dev/null
+++ b/apps/tests/pages/background-test.ts
@@ -0,0 +1,10 @@
+import view = require("ui/core/view");
+export function applyTap(args) {
+ var el = view.getViewById(view.getAncestor(args.object, "Page"), "test-element");
+ (el).style = args.object.tag;
+}
+
+export function resetTap(args) {
+ var el = view.getViewById(view.getAncestor(args.object, "Page"), "test-element");
+ (el).style = "";
+}
\ No newline at end of file
diff --git a/apps/tests/pages/background-test.xml b/apps/tests/pages/background-test.xml
new file mode 100644
index 000000000..5699dc180
--- /dev/null
+++ b/apps/tests/pages/background-test.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/apps/tests/pages/test2.png b/apps/tests/pages/test2.png
new file mode 100644
index 000000000..fa059ba75
Binary files /dev/null and b/apps/tests/pages/test2.png differ
diff --git a/apps/tests/ui/button/button-tests-native.android.ts b/apps/tests/ui/button/button-tests-native.android.ts
index 39e0d705d..c88e28441 100644
--- a/apps/tests/ui/button/button-tests-native.android.ts
+++ b/apps/tests/ui/button/button-tests-native.android.ts
@@ -2,6 +2,7 @@
import colorModule = require("color");
import utilsModule = require("utils/utils");
import enums = require("ui/enums");
+import background = require("ui/styling/background");
export function getNativeText(button: buttonModule.Button): string {
return button.android.getText();
@@ -17,7 +18,13 @@ export function getNativeColor(button: buttonModule.Button): colorModule.Color {
}
export function getNativeBackgroundColor(button: buttonModule.Button): colorModule.Color {
- return new colorModule.Color((button.android.getBackground()).backgroundColor);
+ var bkg = button.android.getBackground();
+ if (bkg instanceof background.ad.BorderDrawable) {
+ return (bkg).background.color;
+ }
+ else {
+ return new colorModule.Color(bkg.backgroundColor)
+ }
}
export function getNativeTextAlignment(button: buttonModule.Button): string {
diff --git a/apps/tests/ui/label/label-tests.ts b/apps/tests/ui/label/label-tests.ts
index d7d26526d..c134855b0 100644
--- a/apps/tests/ui/label/label-tests.ts
+++ b/apps/tests/ui/label/label-tests.ts
@@ -25,6 +25,7 @@ import textBase = require("ui/text-base");
import enums = require("ui/enums");
import labelTestsNative = require("./label-tests-native");
import fs = require("file-system");
+import background = require("ui/styling/background");
export class LabelTest extends testModule.UITest {
@@ -32,30 +33,30 @@ export class LabelTest extends testModule.UITest {
var label = new LabelModule.Label();
label.text = "Label";
return label;
-}
+ }
public test_Label_Members() {
- var label = new LabelModule.Label();
- TKUnit.assert(types.isDefined(label.text), "Label.text is not defined");
- TKUnit.assert(types.isDefined(label.textWrap), "Label.textWrap is not defined");
-}
+ var label = new LabelModule.Label();
+ TKUnit.assert(types.isDefined(label.text), "Label.text is not defined");
+ TKUnit.assert(types.isDefined(label.textWrap), "Label.textWrap is not defined");
+ }
public snippet_Set_Text_TNS() {
- //
- // ### How to set label text content
- // ``` JavaScript
- var label = new LabelModule.Label();
- var expectedValue = "Expected Value";
- label.text = expectedValue;
- // ```
- //
-}
+ //
+ // ### How to set label text content
+ // ``` JavaScript
+ var label = new LabelModule.Label();
+ var expectedValue = "Expected Value";
+ label.text = expectedValue;
+ // ```
+ //
+ }
public snippet_Set_TextWrap_TNS() {
//
// ### How to turn on text wrapping for a label
// ``` JavaScript
- var label = new LabelModule.Label();
+ var label = new LabelModule.Label();
label.textWrap = true;
// ```
//
@@ -85,15 +86,15 @@ export class LabelTest extends testModule.UITest {
}
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
-}
+ }
public test_measuredWidth_is_not_clipped() {
var label = this.testView;
- label.horizontalAlignment = "left";
- label.text = "i";
- label.fontSize = 9;
+ label.horizontalAlignment = "left";
+ label.text = "i";
+ label.fontSize = 9;
- if (label.ios) {
+ if (label.ios) {
this.waitUntilTestElementLayoutIsValid();
@@ -105,11 +106,11 @@ export class LabelTest extends testModule.UITest {
public test_Set_TextWrap_TNS() {
var label = this.testView;
- label.textWrap = true;
+ label.textWrap = true;
- var actual = label._getValue(LabelModule.Label.textWrapProperty);
+ var actual = label._getValue(LabelModule.Label.textWrapProperty);
TKUnit.assertEqual(actual, true);
-}
+ }
public test_Set_TextWrap_Native() {
var testLabel = this.testView;
@@ -178,40 +179,40 @@ export class LabelTest extends testModule.UITest {
}
TKUnit.assertEqual(actualLinesNumber, expectedLinesNumber, "LinesNumber");
-}
+ }
public test_SetStyleProperties_via_css_class_Native() {
var label = this.testView;
- var fontSize = 14;
- var color = "#ffff0000";
- var backgroundColor = "#ff00ff00";
- var testCss = [".title {background-color: ", backgroundColor, "; ",
- "color: ", color, "; ",
- "font-size: ", fontSize, ";}"].join("");
+ var fontSize = 14;
+ var color = "#ffff0000";
+ var backgroundColor = "#ff00ff00";
+ var testCss = [".title {background-color: ", backgroundColor, "; ",
+ "color: ", color, "; ",
+ "font-size: ", fontSize, ";}"].join("");
- //
- // ### How to style a label via css class
- // ``` JavaScript
- label.text = "The quick brown fox jumps over the lazy dog.";
- label.cssClass = "title";
- //// after that all we have to do is to set a similar css entry within parent page css property
- //// label.parentPage.css = ".title {background-color: #C6C6C6; color: #10C2B0; font-size: 14;}";
- // ```
- //
+ //
+ // ### How to style a label via css class
+ // ``` JavaScript
+ label.text = "The quick brown fox jumps over the lazy dog.";
+ label.cssClass = "title";
+ //// after that all we have to do is to set a similar css entry within parent page css property
+ //// label.parentPage.css = ".title {background-color: #C6C6C6; color: #10C2B0; font-size: 14;}";
+ // ```
+ //
- var actualTextSize;
- var expSize;
- var actualColors;
- var expColor;
- var normalColor;
- var actualBackgroundColor;
- var expBackgroundColor;
+ var actualTextSize;
+ var expSize;
+ var actualColors;
+ var expColor;
+ var normalColor;
+ var actualBackgroundColor;
+ var expBackgroundColor;
this.testPage.css = testCss;
this.waitUntilTestElementIsLoaded();
var testLabel = label;
-
+
if (testLabel.android) {
actualTextSize = testLabel.android.getTextSize();
var density = utils.layout.getDisplayDensity();
@@ -223,7 +224,8 @@ export class LabelTest extends testModule.UITest {
normalColor = actualColors.getDefaultColor()
TKUnit.assert(normalColor, "Expected: " + expColor + ", Actual: " + normalColor);
- actualBackgroundColor = (testLabel.android.getBackground()).backgroundColor;
+ var bkg = (testLabel.android.getBackground());
+ actualBackgroundColor = bkg.background.color.android;
expBackgroundColor = android.graphics.Color.parseColor(backgroundColor);
TKUnit.assertEqual(actualBackgroundColor, expBackgroundColor);
}
@@ -244,12 +246,12 @@ export class LabelTest extends testModule.UITest {
public test_SetStyleProperties_via_css_type_TNS() {
var label = this.testView;
- var fontSize = 14;
- var color = "#10C2B0";
- var backgroundColor = "#C6C6C6";
- var testCss = ["label {background-color: ", backgroundColor, "; ",
- "color: ", color, "; ",
- "font-size: ", fontSize, ";}"].join("");
+ var fontSize = 14;
+ var color = "#10C2B0";
+ var backgroundColor = "#C6C6C6";
+ var testCss = ["label {background-color: ", backgroundColor, "; ",
+ "color: ", color, "; ",
+ "font-size: ", fontSize, ";}"].join("");
this.testPage.css = testCss;
this.waitUntilTestElementIsLoaded();
@@ -277,25 +279,25 @@ export class LabelTest extends testModule.UITest {
public test_SetStyleProperties_via_css_id() {
var label = this.testView;
- var fontSize = 14;
- var color = "#10C2B0";
- var backgroundColor = "#C6C6C6";
- var testCss = ["#testLabel {background-color: ", backgroundColor, "; ",
- "color: ", color, "; ",
- "font-size: ", fontSize, ";}"].join("");
+ var fontSize = 14;
+ var color = "#10C2B0";
+ var backgroundColor = "#C6C6C6";
+ var testCss = ["#testLabel {background-color: ", backgroundColor, "; ",
+ "color: ", color, "; ",
+ "font-size: ", fontSize, ";}"].join("");
this.testPage.css = testCss;
this.waitUntilTestElementIsLoaded();
- //
- // ### How to style a label via css control identifier
- // ``` JavaScript
- label.text = "The quick brown fox jumps over the lazy dog.";
- label.id = "testLabel";
- //// after that all we have to do is to set a similar css entry within parent page css property
- //// label.parentPage.css = "#testLabel {background-color: #C6C6C6; color: #10C2B0; font-size: 14;}";
- // ```
- //
+ //
+ // ### How to style a label via css control identifier
+ // ``` JavaScript
+ label.text = "The quick brown fox jumps over the lazy dog.";
+ label.id = "testLabel";
+ //// after that all we have to do is to set a similar css entry within parent page css property
+ //// label.parentPage.css = "#testLabel {background-color: #C6C6C6; color: #10C2B0; font-size: 14;}";
+ // ```
+ //
var expectedBackgroundColor = new colorModule.Color(backgroundColor);
var actualBackgroundColor = label.style.backgroundColor;
@@ -307,27 +309,27 @@ export class LabelTest extends testModule.UITest {
var actualFontSize = label.style.fontSize;
TKUnit.assertEqual(fontSize, actualFontSize);
-}
+ }
public test_BindingToText() {
- //
- // ### How to bind text property of a label to an observable model
- // ``` JavaScript
- var label = new LabelModule.Label();
- var expValue = "Expected Value";
- var sourceModel = new observableModule.Observable();
- var bindingOptions: bindable.BindingOptions = {
- sourceProperty: "sourceProperty",
- targetProperty: "text"
- };
- label.bind(bindingOptions, sourceModel);
- sourceModel.set("sourceProperty", expValue);
- //// console.log(label.text); --> prints: "Expected Value"
- // ```
- //
+ //
+ // ### How to bind text property of a label to an observable model
+ // ``` JavaScript
+ var label = new LabelModule.Label();
+ var expValue = "Expected Value";
+ var sourceModel = new observableModule.Observable();
+ var bindingOptions: bindable.BindingOptions = {
+ sourceProperty: "sourceProperty",
+ targetProperty: "text"
+ };
+ label.bind(bindingOptions, sourceModel);
+ sourceModel.set("sourceProperty", expValue);
+ //// console.log(label.text); --> prints: "Expected Value"
+ // ```
+ //
TKUnit.assertEqual(label.text, expValue);
-}
+ }
public test_BindingToText_Native() {
var label = this.testView;
@@ -348,10 +350,10 @@ export class LabelTest extends testModule.UITest {
}
else if (label.ios) {
actualNative = label.ios.text;
- }
+ }
TKUnit.assertEqual(actualNative, expValue);
-}
+ }
public test_BindingToText_WithBindingContext() {
var label = this.testView;
@@ -375,7 +377,7 @@ export class LabelTest extends testModule.UITest {
this.testPage.bindingContext = secondSourceObject;
TKUnit.assertEqual(label.text, secondExpValue);
-}
+ }
public test_BindingToText_BindingContext_SetingLocalValue() {
var label = this.testView;
@@ -400,7 +402,7 @@ export class LabelTest extends testModule.UITest {
firstSourceObject.set("sourceProperty", "some value");
// after setting a value one way binding should be gone.
TKUnit.assertEqual(label.text, secondExpValue);
-}
+ }
private expectedTextAlignment = enums.TextAlignment.right;
public testLocalTextAlignmentFromCss() {
@@ -408,7 +410,7 @@ export class LabelTest extends testModule.UITest {
this.testPage.css = "label { text-align: " + this.expectedTextAlignment + "; }";
this.waitUntilTestElementIsLoaded();
TKUnit.assertEqual(label.style.textAlignment, this.expectedTextAlignment);
-}
+ }
public testLocalTextAlignmentFromCssWhenAddingCss() {
var view = this.testView;
@@ -421,7 +423,7 @@ export class LabelTest extends testModule.UITest {
page.addCss("label { text-align: " + enums.TextAlignment.left + "; }");
TKUnit.assertEqual(view.style.textAlignment, view.style.textAlignment);
-}
+ }
public testLocalTextAlignmentFromCssWhenAddingCssAllSelectorsAreApplied() {
var view = this.testView;
@@ -435,7 +437,7 @@ export class LabelTest extends testModule.UITest {
var actualResult = view.style.textAlignment;
// actual result is taken from #testLabel tag, because it has a greater priority (id vs type).
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
-}
+ }
public testLocalTextAlignmentFromCssWhenAddingCssFileAllSelectorsAreApplied() {
var view = this.testView;
@@ -450,7 +452,7 @@ export class LabelTest extends testModule.UITest {
// actual result is taken from #testLabel tag, because it has a greater priority (id vs type).
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
TKUnit.assertEqual(view.style.backgroundColor.hex, "#FF0000");
-}
+ }
public testNativeTextAlignmentFromCss() {
var view = this.testView;
@@ -460,7 +462,7 @@ export class LabelTest extends testModule.UITest {
page.css = "label { text-align: " + this.expectedTextAlignment + "; }";
var actualResult = labelTestsNative.getNativeTextAlignment(view);
TKUnit.assert(actualResult, this.expectedTextAlignment);
-}
+ }
public testNativeTextAlignmentFromLocal() {
var view = this.testView;
@@ -470,7 +472,7 @@ export class LabelTest extends testModule.UITest {
var actualResult = labelTestsNative.getNativeTextAlignment(view);
TKUnit.assertEqual(actualResult, this.expectedTextAlignment);
-}
+ }
public testErrorMessageWhenWrongCssIsAddedWithFile() {
var view = this.testView;
@@ -481,7 +483,7 @@ export class LabelTest extends testModule.UITest {
page.addCssFile(fs.path.join(__dirname, "label-tests-wrong.css"));
TKUnit.assertNotEqual(this.errorMessage, undefined);
}
-
+
public testErrorMessageWhenWrongCssIsAdded() {
var view = this.testView;
var page = this.testPage;
diff --git a/apps/tests/ui/style/style-properties-tests.ts b/apps/tests/ui/style/style-properties-tests.ts
index 7f0e81653..729dc2051 100644
--- a/apps/tests/ui/style/style-properties-tests.ts
+++ b/apps/tests/ui/style/style-properties-tests.ts
@@ -39,8 +39,32 @@ export function test_setting_backgroundColor_property_from_CSS_is_applied_to_Sty
test_property_from_CSS_is_applied_to_style("backgroundColor", "background-color", new color.Color("#FF0000"), "#FF0000");
}
-export function test_setting_fontSize_property_from_CSS_is_applied_to_Style() {
- test_property_from_CSS_is_applied_to_style("fontSize", "font-size", 32);
+export function test_setting_backgroundRepeat_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("backgroundRepeat", "background-repeat", "repeat-x");
+}
+
+export function test_setting_backgroundSize_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("backgroundSize", "background-size", "10% 20%");
+}
+
+export function test_setting_backgroundPosition_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("backgroundPosition", "background-position", "left center");
+}
+
+export function test_setting_backgroundImage_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("backgroundImage", "background-image", "url('~/pages/test2.png')");
+}
+
+export function test_setting_borderWidth_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("borderWidth", "border-width", 5);
+}
+
+export function test_setting_borderColor_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("borderColor", "border-color", new color.Color("#FF0000"), "#FF0000");
+}
+
+export function test_setting_borderRadius_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("borderRadius", "border-radius", 20);
}
export function test_setting_textAlignment_property_from_CSS_is_applied_to_Style() {
@@ -81,6 +105,10 @@ export function test_setting_opacity_property_from_CSS_is_applied_to_Style() {
test_property_from_CSS_is_applied_to_style("opacity", "opacity", 0.5);
}
+export function test_setting_fontSize_property_from_CSS_is_applied_to_Style() {
+ test_property_from_CSS_is_applied_to_style("fontSize", "font-size", 32);
+}
+
export function test_setting_fontFamily_property_from_CSS_is_applied_to_Style() {
test_property_from_CSS_is_applied_to_style("fontFamily", "font-family", "Helvetica");
}
diff --git a/apps/tests/ui/style/style-tests.ts b/apps/tests/ui/style/style-tests.ts
index 23c26253b..e022d9efd 100644
--- a/apps/tests/ui/style/style-tests.ts
+++ b/apps/tests/ui/style/style-tests.ts
@@ -22,9 +22,10 @@ export function test_css_dataURI_is_applied_to_backgroundImageSource() {
var page = views[1];
page.css = "StackLayout { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC;') }";
- var value = stack.style._getValue(styleModule.backgroundImageSourceProperty);
+ var value = stack.style._getValue(styleModule.backgroundInternalProperty);
- TKUnit.assert(value !== undefined, "Style background-image not loaded correctly from data URI.");
+ TKUnit.assert(types.isDefined(value), "Style background-image not loaded correctly from data URI.");
+ TKUnit.assert(types.isDefined(value.image), "Style background-image not loaded correctly from data URI.");
});
}
@@ -747,6 +748,21 @@ export function test_setInlineStyle_setsLocalValues() {
});
}
+export function test_setInlineStyle_resetsLocalValues() {
+ var testButton = new buttonModule.Button();
+ testButton.text = "Test";
+ testButton.style.fontSize = 10;
+ var stack = new stackModule.StackLayout();
+ stack.addChild(testButton);
+
+ helper.buildUIAndRunTest(stack, function (views: Array) {
+ (testButton)._applyInlineStyle("color: red;");
+ helper.assertViewColor(testButton, "#FF0000", dependencyObservableModule.ValueSource.Local);
+ TKUnit.assert(types.isUndefined(testButton.style.fontSize), "Setting inline style should reset font size");
+ TKUnit.assertEqual(testButton.style._getValueSource(styling.properties.fontSizeProperty), dependencyObservableModule.ValueSource.Default, "valueSource");
+ });
+}
+
export var test_CSS_isAppliedOnPage = function () {
var testButton = new buttonModule.Button();
testButton.text = "Test";
diff --git a/apps/tests/ui/text-field/text-field-tests-native.android.ts b/apps/tests/ui/text-field/text-field-tests-native.android.ts
index d90197585..235d83a19 100644
--- a/apps/tests/ui/text-field/text-field-tests-native.android.ts
+++ b/apps/tests/ui/text-field/text-field-tests-native.android.ts
@@ -2,6 +2,7 @@
import colorModule = require("color");
import utilsModule = require("utils/utils");
import enums = require("ui/enums");
+import background = require("ui/styling/background");
export function getNativeText(textField: textFieldModule.TextField): string {
return textField.android.getText().toString();
@@ -26,7 +27,13 @@ export function getNativeColor(textField: textFieldModule.TextField): colorModul
}
export function getNativeBackgroundColor(textField: textFieldModule.TextField): colorModule.Color {
- return new colorModule.Color((textField.android.getBackground()).backgroundColor);
+ var bkg = textField.android.getBackground();
+ if (bkg instanceof background.ad.BorderDrawable) {
+ return (bkg).background.color;
+ }
+ else {
+ return new colorModule.Color(bkg.backgroundColor)
+ }
}
export function getNativeTextAlignment(textField: textFieldModule.TextField): string {
diff --git a/apps/tests/ui/text-view/text-view-tests-native.android.ts b/apps/tests/ui/text-view/text-view-tests-native.android.ts
index f0e989a52..f5ea9a7e9 100644
--- a/apps/tests/ui/text-view/text-view-tests-native.android.ts
+++ b/apps/tests/ui/text-view/text-view-tests-native.android.ts
@@ -2,6 +2,7 @@
import colorModule = require("color");
import utilsModule = require("utils/utils");
import enums = require("ui/enums");
+import background = require("ui/styling/background");
export function getNativeText(textView: textViewModule.TextView): string {
return textView.android.getText().toString();
@@ -30,7 +31,13 @@ export function getNativeColor(textView: textViewModule.TextView): colorModule.C
}
export function getNativeBackgroundColor(textView: textViewModule.TextView): colorModule.Color {
- return new colorModule.Color((textView.android.getBackground()).backgroundColor);
+ var bkg = textView.android.getBackground();
+ if (bkg instanceof background.ad.BorderDrawable) {
+ return (bkg).background.color;
+ }
+ else {
+ return new colorModule.Color(bkg.backgroundColor)
+ }
}
export function getNativeTextAlignment(textView: textViewModule.TextView): string {
diff --git a/apps/tests/ui/view/view-tests.android.ts b/apps/tests/ui/view/view-tests.android.ts
index c4bdbe121..396b1d31a 100644
--- a/apps/tests/ui/view/view-tests.android.ts
+++ b/apps/tests/ui/view/view-tests.android.ts
@@ -6,6 +6,7 @@ import button = require("ui/button");
import types = require("utils/types");
import stack = require("ui/layouts/stack-layout");
import labelModule = require("ui/label");
+import background = require("ui/styling/background");
import trace = require("trace");
// enable the trace, it is disabled by default
@@ -268,19 +269,19 @@ export function getNativeCornerRadius(v: view.View): number {
}
export function checkNativeBorderColor(v: view.View): boolean {
- var bkg = (v.android).getBackground();
+ var bkg = (v.android).getBackground();
return v.borderColor && bkg && bkg.borderColor === v.borderColor.android;
}
export function checkNativeBackgroundColor(v: view.View): boolean {
- var bkg = (v.android).getBackground();
+ var bkg = (v.android).getBackground();
- return v.backgroundColor && bkg && bkg.backgroundColor === v.backgroundColor.android;
+ return v.backgroundColor && bkg && bkg.background && bkg.background.color.equals(v.backgroundColor);
}
export function checkNativeBackgroundImage(v: view.View): boolean {
- var bkg = (v.android).getBackground();
+ var bkg = (v.android).getBackground();
- return bkg && bkg.bitmap !== undefined;
+ return bkg && bkg.background && !types.isNullOrUndefined(bkg.background.image);
}
\ No newline at end of file
diff --git a/apps/ui-tests-app/pages/background.ts b/apps/ui-tests-app/pages/background.ts
new file mode 100644
index 000000000..d3fc95ba5
--- /dev/null
+++ b/apps/ui-tests-app/pages/background.ts
@@ -0,0 +1,10 @@
+import view = require("ui/core/view");
+export function applyTap(args) {
+ var el = view.getViewById(view.getAncestor(args.object, "Page"), "test-element");
+ (el).style = args.object.tag;
+}
+
+export function resetTap(args) {
+ var el = view.getViewById(view.getAncestor(args.object, "Page"), "test-element");
+ (el).style = "";
+}
\ No newline at end of file
diff --git a/apps/ui-tests-app/pages/background.xml b/apps/ui-tests-app/pages/background.xml
new file mode 100644
index 000000000..5699dc180
--- /dev/null
+++ b/apps/ui-tests-app/pages/background.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/apps/ui-tests-app/pages/test2.png b/apps/ui-tests-app/pages/test2.png
new file mode 100644
index 000000000..fa059ba75
Binary files /dev/null and b/apps/ui-tests-app/pages/test2.png differ
diff --git a/js-libs/reworkcss-value/LICENSE b/js-libs/reworkcss-value/LICENSE
new file mode 100644
index 000000000..0c331f11a
--- /dev/null
+++ b/js-libs/reworkcss-value/LICENSE
@@ -0,0 +1,9 @@
+(The MIT License)
+
+Copyright (c) 2013 TJ Holowaychuk
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/js-libs/reworkcss-value/Readme.md b/js-libs/reworkcss-value/Readme.md
new file mode 100644
index 000000000..e31493542
--- /dev/null
+++ b/js-libs/reworkcss-value/Readme.md
@@ -0,0 +1,45 @@
+
+# css-value
+
+ WIP CSS value parser
+
+## Example
+
+The CSS value string "1px 0 0 5% .5px .10 1.5" yields:
+
+```js
+[
+ { type: 'number', string: '1px', unit: 'px', value: 1 },
+ { type: 'number', string: '0', unit: '', value: 0 },
+ { type: 'number', string: '0', unit: '', value: 0 },
+ { type: 'number', string: '5%', unit: '%', value: 5 },
+ { type: 'number', string: '.5px', unit: 'px', value: .5 },
+ { type: 'number', string: '.10', unit: '', value: .1 },
+ { type: 'number', string: '1.5', unit: '', value: 1.5 }
+]
+```
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2013 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/js-libs/reworkcss-value/package.json b/js-libs/reworkcss-value/package.json
new file mode 100644
index 000000000..2c1199986
--- /dev/null
+++ b/js-libs/reworkcss-value/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "reworkcss-value.js",
+ "version": "0.0.1",
+ "description": "CSS value parser",
+ "keywords": ["css", "parser", "value"],
+ "author": "TJ Holowaychuk ",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/visionmedia/css-value.git"
+ },
+ "main": "reworkcss-value.js"
+}
diff --git a/js-libs/reworkcss-value/reworkcss-value.d.ts b/js-libs/reworkcss-value/reworkcss-value.d.ts
new file mode 100644
index 000000000..3b2d7e3cd
--- /dev/null
+++ b/js-libs/reworkcss-value/reworkcss-value.d.ts
@@ -0,0 +1,10 @@
+declare module "js-libs/reworkcss-value" {
+ export interface CSSValue {
+ type: string;
+ string: string;
+ unit: string;
+ value: number;
+ }
+
+ export function parse(cssValue: string): Array;
+}
diff --git a/js-libs/reworkcss-value/reworkcss-value.js b/js-libs/reworkcss-value/reworkcss-value.js
new file mode 100644
index 000000000..3aca66f11
--- /dev/null
+++ b/js-libs/reworkcss-value/reworkcss-value.js
@@ -0,0 +1,113 @@
+
+module.exports.parse = parse;
+
+function parse(str) {
+ return new Parser(str).parse();
+}
+
+function Parser(str) {
+ this.str = str;
+}
+
+Parser.prototype.skip = function(m){
+ this.str = this.str.slice(m[0].length);
+};
+
+Parser.prototype.comma = function(){
+ var m = /^, */.exec(this.str);
+ if (!m) return;
+ this.skip(m);
+ return { type: 'comma', string: ',' };
+};
+
+Parser.prototype.ident = function(){
+ var m = /^([\w-]+) */.exec(this.str);
+ if (!m) return;
+ this.skip(m);
+ return {
+ type: 'ident',
+ string: m[1]
+ }
+};
+
+Parser.prototype.int = function(){
+ var m = /^((\d+)(\S+)?) */.exec(this.str);
+ if (!m) return;
+ this.skip(m);
+ var n = ~~m[2];
+ var u = m[3];
+
+ return {
+ type: 'number',
+ string: m[1],
+ unit: u || '',
+ value: n
+ }
+};
+
+Parser.prototype.float = function(){
+ var m = /^(((?:\d+)?\.\d+)(\S+)?) */.exec(this.str);
+ if (!m) return;
+ this.skip(m);
+ var n = parseFloat(m[2]);
+ var u = m[3];
+
+ return {
+ type: 'number',
+ string: m[1],
+ unit: u || '',
+ value: n
+ }
+};
+
+Parser.prototype.number = function(){
+ return this.float() || this.int();
+};
+
+Parser.prototype.double = function(){
+ var m = /^"([^"]*)" */.exec(this.str);
+ if (!m) return m;
+ this.skip(m);
+ return {
+ type: 'string',
+ quote: '"',
+ string: '"' + m[1] + '"',
+ value: m[1]
+ }
+};
+
+Parser.prototype.single = function(){
+ var m = /^'([^']*)' */.exec(this.str);
+ if (!m) return m;
+ this.skip(m);
+ return {
+ type: 'string',
+ quote: "'",
+ string: "'" + m[1] + "'",
+ value: m[1]
+ }
+};
+
+Parser.prototype.string = function(){
+ return this.single() || this.double();
+};
+
+
+Parser.prototype.value = function(){
+ return this.number()
+ || this.ident()
+ || this.string()
+ || this.comma();
+};
+
+Parser.prototype.parse = function(){
+ var vals = [];
+
+ while (this.str.length) {
+ var obj = this.value();
+ if (!obj) throw new Error('failed to parse near `' + this.str.slice(0, 10) + '...`');
+ vals.push(obj);
+ }
+
+ return vals;
+};
diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts
index ddf9d84a8..c3b6f3f9a 100644
--- a/ui/core/view-common.ts
+++ b/ui/core/view-common.ts
@@ -761,7 +761,13 @@ export class View extends proxy.ProxyObject implements definition.View {
private _applyInlineStyle(inlineStyle) {
if (types.isString(inlineStyle)) {
- styleScope.applyInlineSyle(this, inlineStyle);
+ try {
+ this.style._beginUpdate();
+ this.style._resetLocalValues();
+ styleScope.applyInlineSyle(this, inlineStyle);
+ } finally {
+ this.style._endUpdate();
+ }
}
}
diff --git a/ui/core/view.ios.ts b/ui/core/view.ios.ts
index 240ef0e6c..2b36260ce 100644
--- a/ui/core/view.ios.ts
+++ b/ui/core/view.ios.ts
@@ -3,6 +3,7 @@ import trace = require("trace");
import utils = require("utils/utils");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
+import background = require("ui/styling/background");
// merge the exports of the common file with the exports of this file
declare var exports;
@@ -124,6 +125,7 @@ export class View extends viewCommon.View {
if (changed || (this._privateFlags & PFLAG_LAYOUT_REQUIRED) === PFLAG_LAYOUT_REQUIRED) {
this.onLayout(left, top, right, bottom);
this._privateFlags &= ~PFLAG_LAYOUT_REQUIRED;
+ this._onBoundsChanged();
}
this._privateFlags &= ~PFLAG_FORCE_LAYOUT;
}
@@ -203,6 +205,13 @@ export class View extends viewCommon.View {
return false;
}
+
+ private _onBoundsChanged() {
+ var bgColor = background.ios.createBackgroundUIColor(this);
+ if (bgColor) {
+ this._nativeView.backgroundColor = bgColor;
+ }
+ }
}
export class CustomLayoutView extends View {
diff --git a/ui/enums/enums.d.ts b/ui/enums/enums.d.ts
index f5bc4f01a..ef08a32cc 100644
--- a/ui/enums/enums.d.ts
+++ b/ui/enums/enums.d.ts
@@ -402,4 +402,14 @@
export var bold: string;
}
+
+ /**
+ * Specifies nackground repeat.
+ */
+ export module BackgroundRepeat {
+ export var repeat: string;
+ export var repeatX: string;
+ export var repeatY: string;
+ export var noRepeat: string;
+ }
}
\ No newline at end of file
diff --git a/ui/enums/enums.ts b/ui/enums/enums.ts
index 273ef9858..bc3429fa3 100644
--- a/ui/enums/enums.ts
+++ b/ui/enums/enums.ts
@@ -113,3 +113,10 @@ export module FontWeight {
export var normal: string = "normal";
export var bold: string = "bold";
}
+
+export module BackgroundRepeat {
+ export var repeat: string = "repeat";
+ export var repeatX: string = "repeat-x";
+ export var repeatY: string = "repeat-y";
+ export var noRepeat: string = "no-repeat";
+}
\ No newline at end of file
diff --git a/ui/styling/background-common.ts b/ui/styling/background-common.ts
new file mode 100644
index 000000000..7521526b2
--- /dev/null
+++ b/ui/styling/background-common.ts
@@ -0,0 +1,188 @@
+import imageSource = require("image-source");
+import colorModule = require("color");
+import types = require("utils/types");
+import enums = require("ui/enums");
+import dts = require("ui/styling/background");
+import cssValue = require("js-libs/reworkcss-value");
+
+export class Background implements dts.Background {
+ public static default = new Background(undefined, undefined, undefined, undefined, undefined);
+
+ color: colorModule.Color;
+ image: imageSource.ImageSource;
+ repeat: string;
+ position: string;
+ size: string;
+
+ constructor(
+ color: colorModule.Color,
+ image: imageSource.ImageSource,
+ repeat: string,
+ position: string,
+ size: string) {
+
+ this.color = color;
+ this.image = image;
+ this.repeat = repeat;
+ this.position = position;
+ this.size = size;
+ }
+
+ public withColor(value: colorModule.Color): Background {
+ return new Background(value, this.image, this.repeat, this.position, this.size);
+ }
+
+ public withImage(value: imageSource.ImageSource): Background {
+ return new Background(this.color, value, this.repeat, this.position, this.size);
+ }
+
+ public withRepeat(value: string): Background {
+ return new Background(this.color, this.image, value, this.position, this.size);
+ }
+
+ public withPosition(value: string): Background {
+ return new Background(this.color, this.image, this.repeat, value, this.size);
+ }
+
+ public withSize(value: string): Background {
+ return new Background(this.color, this.image, this.repeat, this.position, value);
+ }
+
+ public getDrawParams(width: number, height: number): dts.BackgroundDrawParams {
+ if (!this.image) {
+ return null;
+ }
+
+ var res: dts.BackgroundDrawParams = {
+ repeatX: true,
+ repeatY: true,
+ posX: 0,
+ posY: 0,
+ }
+
+ // repeat
+ if (this.repeat) {
+ switch (this.repeat.toLowerCase()) {
+ case enums.BackgroundRepeat.noRepeat:
+ res.repeatX = false;
+ res.repeatY = false;
+ break;
+
+ case enums.BackgroundRepeat.repeatX:
+ res.repeatY = false;
+ break;
+
+ case enums.BackgroundRepeat.repeatY:
+ res.repeatX = false;
+ break;
+ }
+ }
+
+ var imageWidth = this.image.width;
+ var imageHeight = this.image.height;
+
+ // size
+ if (this.size) {
+ let values = cssValue.parse(this.size);
+
+ if (values.length === 2) {
+ let vx = values[0];
+ let vy = values[1];
+ if (vx.unit === "%" && vy.unit === "%") {
+ imageWidth = width * vx.value / 100;
+ imageHeight = height * vy.value / 100;
+
+ res.sizeX = imageWidth;
+ res.sizeY = imageHeight;
+ }
+ else if (vx.type === "number" && vy.type === "number" &&
+ ((vx.unit === "px" && vy.unit === "px") || (vx.unit === "" && vy.unit === ""))) {
+ imageWidth = vx.value;
+ imageHeight = vy.value;
+
+ res.sizeX = imageWidth;
+ res.sizeY = imageHeight;
+ }
+ }
+ else if (values.length === 1 && values[0].type === "ident") {
+ let scale = 0;
+
+ if (values[0].string === "cover") {
+ scale = Math.max(width / imageWidth, height / imageHeight);
+ }
+ else if (values[0].string === "contain") {
+ scale = Math.min(width / imageWidth, height / imageHeight);
+ }
+
+ if(scale > 0){
+ imageWidth *= scale;
+ imageHeight *= scale;
+
+ res.sizeX = imageWidth;
+ res.sizeY = imageHeight;
+ }
+ }
+ }
+
+ // position
+ if (this.position) {
+ let values = cssValue.parse(this.position);
+ let spaceX = width - imageWidth;
+ let spaceY = height - imageHeight;
+
+ if (values.length === 2) {
+ let vx = values[0];
+ let vy = values[1];
+
+ if (vx.unit === "%" && vy.unit === "%") {
+ res.posX = spaceX * vx.value / 100;
+ res.posY = spaceY * vy.value / 100;
+ }
+ else if (vx.type === "number" && vy.type === "number" &&
+ ((vx.unit === "px" && vy.unit === "px") || (vx.unit === "" && vy.unit === ""))) {
+ res.posX = vx.value;
+ res.posY = vy.value;
+ }
+ else if (vx.type === "ident" && vy.type === "ident") {
+ if (vx.string.toLowerCase() === "center") {
+ res.posX = spaceX / 2;
+ }
+ else if (vx.string.toLowerCase() === "right") {
+ res.posX = spaceX;
+ }
+
+ if (vy.string.toLowerCase() === "center") {
+ res.posY = spaceY / 2;
+ }
+ else if (vy.string.toLowerCase() === "bottom") {
+ res.posY = spaceY;
+ }
+ }
+ }
+ }
+
+ return res;
+ }
+
+ public isEmpty(): boolean {
+ return types.isUndefined(this.image) && types.isUndefined(this.color);
+ }
+
+ public static equals(value1: Background, value2: Background): boolean {
+ // both values are falsy
+ if (!value1 && !value2) {
+ return true;
+ }
+
+ // only one is falsy
+ if (!value1 || !value2) {
+ return false;
+ }
+
+ return value1.image === value2.image &&
+ value1.position === value2.position &&
+ value1.repeat === value2.repeat &&
+ value1.size === value2.size &&
+ colorModule.Color.equals(value1.color, value2.color);
+ }
+}
diff --git a/ui/styling/background.android.ts b/ui/styling/background.android.ts
new file mode 100644
index 000000000..6c4a2f3f2
--- /dev/null
+++ b/ui/styling/background.android.ts
@@ -0,0 +1,132 @@
+import utils = require("utils/utils");
+import common = require("ui/styling/background-common");
+import dts = require("ui/styling/background");
+
+declare var exports;
+require("utils/module-merge").merge(common, exports);
+
+// We are using "ad" here to avoid namespace collision with the global android object
+export module ad {
+ export class BorderDrawable extends android.graphics.drawable.ColorDrawable implements dts.ad.BorderDrawable {
+ private _density = utils.layout.getDisplayDensity();
+ private _borderWidth: number;
+ private _cornerRadius: number;
+ private _borderColor: number;
+
+ constructor() {
+ super();
+ return global.__native(this);
+ }
+
+ get borderWidth(): number {
+ return this._borderWidth;
+ }
+ set borderWidth(value: number) {
+ if (this._borderWidth !== value) {
+ this._borderWidth = value;
+ this.invalidateSelf();
+ }
+ }
+
+ get cornerRadius(): number {
+ return this._cornerRadius;
+ }
+ set cornerRadius(value: number) {
+ if (this._cornerRadius !== value) {
+ this._cornerRadius = value;
+ this.invalidateSelf();
+ }
+ }
+
+ get borderColor(): number {
+ return this._borderColor;
+ }
+ set borderColor(value: number) {
+ if (this._borderColor !== value) {
+ this._borderColor = value;
+ this.invalidateSelf();
+ }
+ }
+
+ private _background: common.Background
+ get background(): common.Background {
+ return this._background;
+ }
+ set background(value: common.Background) {
+ if (this._background !== value) {
+ this._background = value;
+ this.invalidateSelf();
+ }
+ }
+
+ public draw(canvas: android.graphics.Canvas): void {
+ var bounds = this.getBounds();
+ var boundsF = new android.graphics.RectF(bounds);
+ var boundsWidth = bounds.width();
+ var boundsHeight = bounds.height();
+
+ var radius = this._cornerRadius * this._density;
+ var stroke = this._borderWidth * this._density;
+
+ // set clip first
+ if (radius > 0) {
+ var path = new android.graphics.Path();
+ path.addRoundRect(boundsF, radius, radius, android.graphics.Path.Direction.CW);
+ canvas.clipPath(path);
+ }
+
+ // draw background
+ if (this.background.color && this.background.color.android) {
+ let c = this.background.color;
+ canvas.drawARGB(c.a, c.r, c.g, c.b);
+ }
+
+ // draw image
+ if (this.background.image) {
+ let bitmap = this.background.image.android;
+ let params = this.background.getDrawParams(boundsWidth, boundsHeight);
+
+ var matrix = new android.graphics.Matrix();
+ if (params.sizeX > 0 && params.sizeY > 0) {
+ var scaleX = params.sizeX / bitmap.getWidth();
+ var scaleY = params.sizeY / bitmap.getHeight();
+ matrix.setScale(scaleX, scaleY, 0, 0);
+ }
+ else {
+ params.sizeX = bitmap.getWidth();
+ params.sizeY = bitmap.getHeight();
+ }
+ matrix.postTranslate(params.posX, params.posY);
+
+ if (!params.repeatX && !params.repeatY) {
+ canvas.drawBitmap(bitmap, matrix, undefined);
+ }
+ else {
+ var shader = new android.graphics.BitmapShader(bitmap, android.graphics.Shader.TileMode.REPEAT, android.graphics.Shader.TileMode.REPEAT);
+ shader.setLocalMatrix(matrix);
+ var paint = new android.graphics.Paint();
+ paint.setShader(shader);
+
+ var w = params.repeatX ? bounds.width() : params.sizeX;
+ var h = params.repeatY ? bounds.height() : params.sizeY;
+
+ params.posX = params.repeatX ? 0 : params.posX;
+ params.posY = params.repeatY ? 0 : params.posY;
+
+ canvas.drawRect(params.posX, params.posY, params.posX + w, params.posY + h, paint);
+ }
+ }
+
+ // draw border (topmost)
+ if (stroke > 0 && this._borderColor && this._borderColor) {
+ let borderPaint = new android.graphics.Paint();
+ borderPaint.setStyle(android.graphics.Paint.Style.STROKE);
+ borderPaint.setColor(this._borderColor);
+
+ // Note: Double the stroke as the outer part will be clipped.
+ borderPaint.setStrokeWidth(stroke * 2);
+ canvas.drawRoundRect(boundsF, radius, radius, borderPaint)
+ }
+ }
+ }
+}
diff --git a/ui/styling/background.d.ts b/ui/styling/background.d.ts
new file mode 100644
index 000000000..e4d96daed
--- /dev/null
+++ b/ui/styling/background.d.ts
@@ -0,0 +1,59 @@
+declare module "ui/styling/background" {
+ import imageSource = require("image-source");
+ import colorModule = require("color");
+ import viewModule = require("ui/core/view");
+
+ export interface BackgroundDrawParams {
+ repeatX: boolean;
+ repeatY: boolean;
+ posX: number;
+ posY: number;
+ sizeX?: number;
+ sizeY?: number;
+ }
+
+ export class Background {
+ static default: Background;
+ color: colorModule.Color;
+ image: imageSource.ImageSource;
+ repeat: string;
+ position: string;
+ size: string;
+
+ constructor(
+ color: colorModule.Color,
+ image: imageSource.ImageSource,
+ repeat: string,
+ position: string,
+ size: string);
+
+ public withColor(value: colorModule.Color): Background;
+ public withImage(value: imageSource.ImageSource): Background;
+
+ public withRepeat(value: string): Background;
+
+ public withPosition(value: string): Background;
+
+ public withSize(value: string): Background;;
+
+ public getDrawParams(width: number, height: number): BackgroundDrawParams;
+
+ public isEmpty(): boolean;
+
+ public static equals(value1: Background, value2: Background): boolean;
+ }
+
+ export module ios {
+ export function createBackgroundUIColor(view: viewModule.View): UIColor;
+ }
+
+ // We are using "ad" here to avoid namespace collision with the global android object
+ export module ad {
+ export class BorderDrawable extends android.graphics.drawable.ColorDrawable {
+ borderWidth: number;
+ cornerRadius: number;
+ borderColor: number;
+ background: Background;
+ }
+ }
+}
diff --git a/ui/styling/background.ios.ts b/ui/styling/background.ios.ts
new file mode 100644
index 000000000..dc973e620
--- /dev/null
+++ b/ui/styling/background.ios.ts
@@ -0,0 +1,63 @@
+import viewModule = require("ui/core/view");
+import style = require("ui/styling/style");
+import common = require("ui/styling/background-common");
+
+declare var exports;
+require("utils/module-merge").merge(common, exports);
+
+export module ios {
+ export function createBackgroundUIColor(view: viewModule.View): UIColor {
+ var background = view.style._getValue(style.backgroundInternalProperty);
+ var frame = (view._nativeView).frame;
+ var boundsWidth = frame.size.width;
+ var boundsHeight = frame.size.height;
+ var result: UIColor;
+
+ if (background && !background.isEmpty() && boundsWidth > 0 && boundsHeight) {
+ if (!background.image) {
+ result = background.color.ios;
+ }
+ else {
+ var img = background.image.ios;
+ var params = background.getDrawParams(boundsWidth, boundsHeight);
+
+ if (params.sizeX > 0 && params.sizeY > 0) {
+ var resizeRect = CGRectMake(0, 0, params.sizeX, params.sizeY);
+ UIGraphicsBeginImageContext(resizeRect.size);
+ img.drawInRect(resizeRect);
+ img = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ }
+
+ UIGraphicsBeginImageContextWithOptions(frame.size, false, 1.0);
+ var context = UIGraphicsGetCurrentContext();
+
+ if (background.color && background.color.ios) {
+ CGContextSetFillColorWithColor(context, background.color.ios.CGColor);
+ CGContextFillRect(context, CGRectMake(0, 0, boundsWidth, boundsHeight));
+ }
+
+ if (!params.repeatX && !params.repeatY) {
+ img.drawAtPoint(CGPointMake(params.posX, params.posY));
+ }
+ else {
+ var w = params.repeatX ? boundsWidth : img.size.width;
+ var h = params.repeatY ? boundsHeight : img.size.height;
+
+ CGContextSetPatternPhase(context, CGSizeMake(params.posX, params.posY));
+
+ params.posX = params.repeatX ? 0 : params.posX;
+ params.posY = params.repeatY ? 0 : params.posY;
+
+ var patternRect = CGRectMake(params.posX, params.posY, w, h);
+
+ img.drawAsPatternInRect(patternRect);
+ }
+ var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ result = UIColor.alloc().initWithPatternImage(bkgImage);
+ }
+ return result;
+ }
+ }
+}
diff --git a/ui/styling/font.ios.ts b/ui/styling/font.ios.ts
index 022ba4648..26f45bd07 100644
--- a/ui/styling/font.ios.ts
+++ b/ui/styling/font.ios.ts
@@ -96,9 +96,6 @@ function resolveFontDescriptor(fontFamilyValue: string, symbolicTraits: number):
// This is an actual font - don't apply symbolic traits
result = UIFontDescriptor.fontDescriptorWithNameSize(fontFamily, 0);
}
- else {
- // TODO: Handle custom fonts when they are supported.
- }
if (result) {
return result;
diff --git a/ui/styling/style.ts b/ui/styling/style.ts
index bcecc442a..6040fb794 100644
--- a/ui/styling/style.ts
+++ b/ui/styling/style.ts
@@ -12,6 +12,7 @@ import enums = require("ui/enums");
import imageSource = require("image-source");
import utils = require("utils/utils");
import font = require("ui/styling/font");
+import background = require("ui/styling/background");
// key is the property id and value is Dictionary;
var _registeredHandlers = Array