From 49ef99474f47bce9ac0f9a5242290286f75f2ad7 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Tue, 19 Jul 2016 14:00:33 +0200 Subject: [PATCH] Theming: Colorize checkboxes depending on luminance --- apps/theming/lib/controller/themingcontroller.php | 9 +++++++++ apps/theming/lib/util.php | 15 +++++++++++++++ apps/theming/tests/lib/UtilTest.php | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/apps/theming/lib/controller/themingcontroller.php b/apps/theming/lib/controller/themingcontroller.php index 3e5d6f3e0d..32d96203d6 100644 --- a/apps/theming/lib/controller/themingcontroller.php +++ b/apps/theming/lib/controller/themingcontroller.php @@ -214,11 +214,20 @@ class ThemingController extends Controller { $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); $responseCss = ''; $color = $this->config->getAppValue($this->appName, 'color'); + $elementColor = Util::elementColor($color); if($color !== '') { $responseCss .= sprintf( '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}', $color ); + $responseCss .= sprintf(' + input[type="checkbox"].checkbox:checked + label:before { + background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\'); + background-color: %s; background-position: center center; background-size:contain; + width:12px; height:12px; padding:0; margin:1px 6px 7px 2px; + }', + $elementColor + ); } $logo = $this->config->getAppValue($this->appName, 'logoMime'); if($logo !== '') { diff --git a/apps/theming/lib/util.php b/apps/theming/lib/util.php index 2088650b19..d342073d83 100644 --- a/apps/theming/lib/util.php +++ b/apps/theming/lib/util.php @@ -38,6 +38,21 @@ class Util { } } + /** + * get color for on-page elements: + * theme color by default, grey if theme color is to bright + * @param $color + * @return string + */ + public static function elementColor($color) { + $l = self::calculateLuminance($color); + if($l>0.8) { + return '#969696'; + } else { + return $color; + } + } + /** * @param string $color rgb color value * @return float diff --git a/apps/theming/tests/lib/UtilTest.php b/apps/theming/tests/lib/UtilTest.php index 9ebb11d628..6451b65d02 100644 --- a/apps/theming/tests/lib/UtilTest.php +++ b/apps/theming/tests/lib/UtilTest.php @@ -65,4 +65,14 @@ class UtilTest extends TestCase { $invert = Util::invertTextColor(''); $this->assertEquals(false, $invert); } + + public function testElementColorDefault() { + $elementColor = Util::elementColor("#000000"); + $this->assertEquals('#000000', $elementColor); + } + + public function testElementColorOnBrightBackground() { + $elementColor = Util::elementColor('#ffffff'); + $this->assertEquals('#969696', $elementColor); + } }