summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-08-28 12:01:32 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-10-02 08:37:54 +0200
commit92049c3ceb4121c6e424e8ba902cc6ebc663c690 (patch)
treeeb8a283e260e2b0918d13087c29af96d494fde58 /apps
parent7526971c95250807ac1ec485297919a27ee0dcfc (diff)
downloadnextcloud-server-92049c3ceb4121c6e424e8ba902cc6ebc663c690.tar.gz
nextcloud-server-92049c3ceb4121c6e424e8ba902cc6ebc663c690.zip
Switches the default logo color depending on the primary color
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/css/theming.scss11
-rw-r--r--apps/theming/lib/ImageManager.php2
-rw-r--r--apps/theming/lib/ThemingDefaults.php20
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php67
4 files changed, 92 insertions, 8 deletions
diff --git a/apps/theming/css/theming.scss b/apps/theming/css/theming.scss
index f12ce4d907f..b1b8896d0c1 100644
--- a/apps/theming/css/theming.scss
+++ b/apps/theming/css/theming.scss
@@ -98,20 +98,21 @@
background-image: url(./img/core/filetypes/folder-drag-accept.svg?v=#{$theming-cachebuster}) !important;
}
+#theming-preview-logo,
+#header .logo {
+ background-image: $image-logo;
+}
+
/* override styles for login screen in guest.css */
@if variable_exists('theming-logo-mime') and $theming-logo-mime != '' {
#theming-preview-logo,
#header .logo {
- background-image: $image-logo;
background-size: contain;
}
+
#body-login #header .logo {
margin-bottom: 22px;
}
-} @else {
- #theming-preview-logo {
- background-image: $image-logo;
- }
}
@if variable_exists('theming-background-mime') and $theming-background-mime != '' {
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php
index dfbdb582da6..6a42c22aba5 100644
--- a/apps/theming/lib/ImageManager.php
+++ b/apps/theming/lib/ImageManager.php
@@ -84,6 +84,8 @@ class ImageManager {
case 'logoheader':
case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo.png') . '?v=' . $cacheBusterCounter;
+ case 'logo-blue':
+ return $this->urlGenerator->imagePath('core', 'logo-blue.png') . '?v=' . $cacheBusterCounter;
case 'background':
return $this->urlGenerator->imagePath('core', 'background.png') . '?v=' . $cacheBusterCounter;
}
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php
index 1df7a9f17bb..5a14e8a7903 100644
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -275,7 +275,7 @@ class ThemingDefaults extends \OC_Defaults {
'theming-favicon-mime' => "'" . $this->config->getAppValue('theming', 'faviconMime') . "'"
];
- $variables['image-logo'] = "url('".$this->imageManager->getImageUrl('logo')."')";
+ $variables['image-logo'] = "url('". $this->getLogoUrl() ."')";
$variables['image-logoheader'] = "'".$this->imageManager->getImageUrl('logoheader')."'";
$variables['image-favicon'] = "'".$this->imageManager->getImageUrl('favicon')."'";
$variables['image-login-background'] = "url('".$this->imageManager->getImageUrl('background')."')";
@@ -301,6 +301,24 @@ class ThemingDefaults extends \OC_Defaults {
}
/**
+ * Returns the logo url.
+ * If there is a custom logo, it just returns it.
+ * For the default logo it returns the white or blue one depending on the color luminance.
+ *
+ * @return string
+ */
+ private function getLogoUrl() {
+ $logoMime = $this->config->getAppValue('theming', 'logoMime');
+ $primaryColor = $this->getColorPrimary();
+ $luminance = $this->util->calculateLuminance($primaryColor);
+ if ($logoMime === '' & $luminance > 0.8) {
+ return $this->imageManager->getImageUrl('logo-blue');
+ } else {
+ return $this->imageManager->getImageUrl('logo');
+ }
+ }
+
+ /**
* Check if the image should be replaced by the theming app
* and return the new image location then
*
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index 5d075709dc5..fc3a737c3c8 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -632,6 +632,66 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals(['foo'=>'bar'], $this->template->getScssVariables());
}
+ /**
+ * Provides test data for the get logo scss variable test.
+ *
+ * @return array
+ */
+ public function provideTestGetImageLogoScssVariableTestData(): array {
+ return [
+ // default logo
+ ['', '#000000', 0.0, 'logo'],
+ ['', '#cccccc', 0.8, 'logo'],
+ ['', '#dddddd', 0.81, 'logo-blue'],
+ ['', '#ffffff', 1.0, 'logo-blue'],
+
+ // custom logo
+ ['image/png', '#000000', 0.0, 'logo'],
+ ['image/png', '#cccccc', 0.8, 'logo'],
+ ['image/png', '#dddddd', 0.81, 'logo'],
+ ['image/png', '#ffffff', 1.0, 'logo'],
+ ];
+ }
+
+ /**
+ * Tests chat the logo url scss variable has the expected value
+ * depending on color and custom logo presence.
+ *
+ * @dataProvider provideTestGetImageLogoScssVariableTestData
+ * @param string $themingLogoMime The custom logo mime type
+ * @param string $primaryColor The primary theme color
+ * @param float $luminance The calculated luminance
+ * @param string $expected The expected requested logo
+ * @return void
+ */
+ public function testGetImageLogoScssVariable(
+ string $themingLogoMime,
+ string $primaryColor,
+ float $luminance,
+ string $expected
+ ) {
+ $this->config->expects($this->at(5))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime')
+ ->willReturn($themingLogoMime);
+ $this->config->expects($this->at(6))
+ ->method('getAppValue')
+ ->with('theming', 'color', $this->defaults->getColorPrimary())
+ ->willReturn($primaryColor);
+
+ $this->util
+ ->method('calculateLuminance')
+ ->with($primaryColor)
+ ->willReturn($luminance);
+
+ $this->imageManager->expects($this->at(0))
+ ->method('getImageUrl')
+ ->with($expected)
+ ->willReturn('custom-logo?v=0');
+
+ $this->template->getScssVariables();
+ }
+
public function testGetScssVariables() {
$this->config->expects($this->at(0))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0');
$this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
@@ -639,10 +699,13 @@ class ThemingDefaultsTest extends TestCase {
$this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg');
$this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg');
- $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
+ $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
$this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
- $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
+
+ $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
+ $this->config->expects($this->at(9))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
+ $this->config->expects($this->at(10))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
$this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
$this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa');