Passed
Push — master ( f61779...efbe97 )
by John
31:43 queued 16:46
created
apps/theming/lib/Themes/DefaultTheme.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -33,206 +33,206 @@
 block discarded – undo
33 33
 use OCP\IURLGenerator;
34 34
 
35 35
 class DefaultTheme implements ITheme {
36
-	public Util $util;
37
-	public ThemingDefaults $themingDefaults;
38
-	public IURLGenerator $urlGenerator;
39
-	public ImageManager $imageManager;
40
-	public IConfig $config;
41
-	public IL10N $l;
42
-
43
-	public string $primaryColor;
44
-
45
-	public function __construct(Util $util,
46
-								ThemingDefaults $themingDefaults,
47
-								IURLGenerator $urlGenerator,
48
-								ImageManager $imageManager,
49
-								IConfig $config,
50
-								IL10N $l) {
51
-		$this->util = $util;
52
-		$this->themingDefaults = $themingDefaults;
53
-		$this->urlGenerator = $urlGenerator;
54
-		$this->imageManager = $imageManager;
55
-		$this->config = $config;
56
-		$this->l = $l;
57
-
58
-		$this->primaryColor = $this->themingDefaults->getColorPrimary();
59
-	}
60
-
61
-	public function getId(): string {
62
-		return 'default';
63
-	}
64
-
65
-	public function getType(): int {
66
-		return ITheme::TYPE_THEME;
67
-	}
68
-
69
-	public function getTitle(): string {
70
-		return $this->l->t('System default theme');
71
-	}
72
-
73
-	public function getEnableLabel(): string {
74
-		return $this->l->t('Enable the system default');
75
-	}
76
-
77
-	public function getDescription(): string {
78
-		return $this->l->t('Using the default system appearance.');
79
-	}
80
-
81
-	public function getMediaQuery(): string {
82
-		return '';
83
-	}
84
-
85
-	public function getCSSVariables(): array {
86
-		$colorMainText = '#222222';
87
-		$colorMainBackground = '#ffffff';
88
-		$colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
89
-		$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
90
-		$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
91
-		$colorPrimaryLight = $this->util->mix($this->primaryColor, $colorMainBackground, -80);
92
-
93
-		$colorPrimaryElement = $this->util->elementColor($this->primaryColor);
94
-		$colorPrimaryElementLight = $this->util->mix($colorPrimaryElement, $colorMainBackground, -80);
95
-
96
-		$hasCustomLogoHeader = $this->imageManager->hasImage('logo') ||  $this->imageManager->hasImage('logoheader');
97
-		$hasCustomPrimaryColour = !empty($this->config->getAppValue('theming', 'color'));
98
-
99
-		$variables = [
100
-			'--color-main-background' => $colorMainBackground,
101
-			'--color-main-background-rgb' => $colorMainBackgroundRGB,
102
-			'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
103
-			'--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
104
-			'--filter-background-blur' => 'blur(25px)',
105
-
106
-			// to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
107
-			'--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
108
-
109
-			// used for different active/hover/focus/disabled states
110
-			'--color-background-hover' => $this->util->darken($colorMainBackground, 4),
111
-			'--color-background-dark' => $this->util->darken($colorMainBackground, 7),
112
-			'--color-background-darker' => $this->util->darken($colorMainBackground, 14),
113
-
114
-			'--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
115
-			'--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
116
-
117
-			// primary related colours
118
-			'--color-primary' => $this->primaryColor,
119
-			'--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
120
-			'--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60),
121
-			'--color-primary-light' => $colorPrimaryLight,
122
-			'--color-primary-light-text' => $this->primaryColor,
123
-			'--color-primary-light-hover' => $this->util->mix($colorPrimaryLight, $colorMainText, 90),
124
-			'--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7),
125
-			// used for buttons, inputs...
126
-			'--color-primary-element' => $colorPrimaryElement,
127
-			'--color-primary-element-text' => $this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff',
128
-			'--color-primary-element-hover' => $this->util->mix($colorPrimaryElement, $colorMainBackground, 60),
129
-			'--color-primary-element-light' => $colorPrimaryElementLight,
130
-			'--color-primary-element-light-text' => $colorPrimaryElement,
131
-			'--color-primary-element-light-hover' => $this->util->mix($colorPrimaryElementLight, $colorMainText, 90),
132
-			'--color-primary-element-text-dark' => $this->util->darken($this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff', 7),
133
-			// to use like this: background-image: var(--gradient-primary-background);
134
-			'--gradient-primary-background' => 'linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%)',
135
-
136
-			// max contrast for WCAG compliance
137
-			'--color-main-text' => $colorMainText,
138
-			'--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33),
139
-			'--color-text-light' => $colorMainText,
140
-			'--color-text-lighter' => $this->util->lighten($colorMainText, 33),
141
-
142
-			// info/warning/success feedback colours
143
-			'--color-error' => '#e9322d',
144
-			'--color-error-rgb' => join(',', $this->util->hexToRGB('#e9322d')),
145
-			'--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60),
146
-			'--color-warning' => '#eca700',
147
-			'--color-warning-rgb' => join(',', $this->util->hexToRGB('#eca700')),
148
-			'--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60),
149
-			'--color-success' => '#46ba61',
150
-			'--color-success-rgb' => join(',', $this->util->hexToRGB('#46ba61')),
151
-			'--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60),
152
-
153
-			// used for the icon loading animation
154
-			'--color-loading-light' => '#cccccc',
155
-			'--color-loading-dark' => '#444444',
156
-
157
-			'--color-box-shadow-rgb' => $colorBoxShadowRGB,
158
-			'--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
159
-
160
-			'--color-border' => $this->util->darken($colorMainBackground, 7),
161
-			'--color-border-dark' => $this->util->darken($colorMainBackground, 14),
162
-
163
-			'--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
164
-			'--default-font-size' => '15px',
165
-
166
-			// TODO: support "(prefers-reduced-motion)"
167
-			'--animation-quick' => '100ms',
168
-			'--animation-slow' => '300ms',
169
-
170
-			// Default variables --------------------------------------------
171
-			'--border-radius' => '3px',
172
-			'--border-radius-large' => '10px',
173
-			// pill-style button, value is large so big buttons also have correct roundness
174
-			'--border-radius-pill' => '100px',
175
-
176
-			'--default-line-height' => '24px',
177
-
178
-			// various structure data
179
-			'--header-height' => '50px',
180
-			'--navigation-width' => '300px',
181
-			'--sidebar-min-width' => '300px',
182
-			'--sidebar-max-width' => '500px',
183
-			'--list-min-width' => '200px',
184
-			'--list-max-width' => '300px',
185
-			'--header-menu-item-height' => '44px',
186
-			'--header-menu-profile-item-height' => '66px',
187
-
188
-			// mobile. Keep in sync with core/js/js.js
189
-			'--breakpoint-mobile' => '1024px',
190
-
191
-			// invert filter if primary is too bright
192
-			// to be used for legacy reasons only. Use inline
193
-			// svg with proper css variable instead or material
194
-			// design icons.
195
-			// ⚠️ Using 'no' as a value to make sure we specify an
196
-			// invalid one with no fallback. 'unset' could here fallback to some
197
-			// other theme with media queries
198
-			'--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no',
199
-			'--background-invert-if-dark' => 'no',
200
-			'--background-invert-if-bright' => 'invert(100%)',
201
-
202
-			'--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
203
-		];
204
-
205
-		$backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor';
206
-		// If primary as background has been request or if we have a custom primary colour
207
-		// let's not define the background image
208
-		if ($backgroundDeleted || $hasCustomPrimaryColour) {
209
-			$variables["--image-background-plain"] = 'true';
210
-		}
211
-
212
-		// Register image variables only if custom-defined
213
-		foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) {
214
-			if ($this->imageManager->hasImage($image)) {
215
-				$imageUrl = $this->imageManager->getImageUrl($image);
216
-				if ($image === 'background') {
217
-					// If background deleted is set, ignoring variable
218
-					if ($backgroundDeleted) {
219
-						continue;
220
-					}
221
-					$variables['--image-background-size'] = 'cover';
222
-					$variables['--image-main-background'] = "url('" . $imageUrl . "')";
223
-				}
224
-				$variables["--image-$image"] = "url('" . $imageUrl . "')";
225
-			}
226
-		}
227
-
228
-		if ($hasCustomLogoHeader) {
229
-			$variables["--image-logoheader-custom"] = 'true';
230
-		}
231
-
232
-		return $variables;
233
-	}
234
-
235
-	public function getCustomCss(): string {
236
-		return '';
237
-	}
36
+    public Util $util;
37
+    public ThemingDefaults $themingDefaults;
38
+    public IURLGenerator $urlGenerator;
39
+    public ImageManager $imageManager;
40
+    public IConfig $config;
41
+    public IL10N $l;
42
+
43
+    public string $primaryColor;
44
+
45
+    public function __construct(Util $util,
46
+                                ThemingDefaults $themingDefaults,
47
+                                IURLGenerator $urlGenerator,
48
+                                ImageManager $imageManager,
49
+                                IConfig $config,
50
+                                IL10N $l) {
51
+        $this->util = $util;
52
+        $this->themingDefaults = $themingDefaults;
53
+        $this->urlGenerator = $urlGenerator;
54
+        $this->imageManager = $imageManager;
55
+        $this->config = $config;
56
+        $this->l = $l;
57
+
58
+        $this->primaryColor = $this->themingDefaults->getColorPrimary();
59
+    }
60
+
61
+    public function getId(): string {
62
+        return 'default';
63
+    }
64
+
65
+    public function getType(): int {
66
+        return ITheme::TYPE_THEME;
67
+    }
68
+
69
+    public function getTitle(): string {
70
+        return $this->l->t('System default theme');
71
+    }
72
+
73
+    public function getEnableLabel(): string {
74
+        return $this->l->t('Enable the system default');
75
+    }
76
+
77
+    public function getDescription(): string {
78
+        return $this->l->t('Using the default system appearance.');
79
+    }
80
+
81
+    public function getMediaQuery(): string {
82
+        return '';
83
+    }
84
+
85
+    public function getCSSVariables(): array {
86
+        $colorMainText = '#222222';
87
+        $colorMainBackground = '#ffffff';
88
+        $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
89
+        $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
90
+        $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
91
+        $colorPrimaryLight = $this->util->mix($this->primaryColor, $colorMainBackground, -80);
92
+
93
+        $colorPrimaryElement = $this->util->elementColor($this->primaryColor);
94
+        $colorPrimaryElementLight = $this->util->mix($colorPrimaryElement, $colorMainBackground, -80);
95
+
96
+        $hasCustomLogoHeader = $this->imageManager->hasImage('logo') ||  $this->imageManager->hasImage('logoheader');
97
+        $hasCustomPrimaryColour = !empty($this->config->getAppValue('theming', 'color'));
98
+
99
+        $variables = [
100
+            '--color-main-background' => $colorMainBackground,
101
+            '--color-main-background-rgb' => $colorMainBackgroundRGB,
102
+            '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
103
+            '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
104
+            '--filter-background-blur' => 'blur(25px)',
105
+
106
+            // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
107
+            '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
108
+
109
+            // used for different active/hover/focus/disabled states
110
+            '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
111
+            '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
112
+            '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
113
+
114
+            '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
115
+            '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
116
+
117
+            // primary related colours
118
+            '--color-primary' => $this->primaryColor,
119
+            '--color-primary-text' => $this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff',
120
+            '--color-primary-hover' => $this->util->mix($this->primaryColor, $colorMainBackground, 60),
121
+            '--color-primary-light' => $colorPrimaryLight,
122
+            '--color-primary-light-text' => $this->primaryColor,
123
+            '--color-primary-light-hover' => $this->util->mix($colorPrimaryLight, $colorMainText, 90),
124
+            '--color-primary-text-dark' => $this->util->darken($this->util->invertTextColor($this->primaryColor) ? '#000000' : '#ffffff', 7),
125
+            // used for buttons, inputs...
126
+            '--color-primary-element' => $colorPrimaryElement,
127
+            '--color-primary-element-text' => $this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff',
128
+            '--color-primary-element-hover' => $this->util->mix($colorPrimaryElement, $colorMainBackground, 60),
129
+            '--color-primary-element-light' => $colorPrimaryElementLight,
130
+            '--color-primary-element-light-text' => $colorPrimaryElement,
131
+            '--color-primary-element-light-hover' => $this->util->mix($colorPrimaryElementLight, $colorMainText, 90),
132
+            '--color-primary-element-text-dark' => $this->util->darken($this->util->invertTextColor($colorPrimaryElement) ? '#000000' : '#ffffff', 7),
133
+            // to use like this: background-image: var(--gradient-primary-background);
134
+            '--gradient-primary-background' => 'linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%)',
135
+
136
+            // max contrast for WCAG compliance
137
+            '--color-main-text' => $colorMainText,
138
+            '--color-text-maxcontrast' => $this->util->lighten($colorMainText, 33),
139
+            '--color-text-light' => $colorMainText,
140
+            '--color-text-lighter' => $this->util->lighten($colorMainText, 33),
141
+
142
+            // info/warning/success feedback colours
143
+            '--color-error' => '#e9322d',
144
+            '--color-error-rgb' => join(',', $this->util->hexToRGB('#e9322d')),
145
+            '--color-error-hover' => $this->util->mix('#e9322d', $colorMainBackground, 60),
146
+            '--color-warning' => '#eca700',
147
+            '--color-warning-rgb' => join(',', $this->util->hexToRGB('#eca700')),
148
+            '--color-warning-hover' => $this->util->mix('#eca700', $colorMainBackground, 60),
149
+            '--color-success' => '#46ba61',
150
+            '--color-success-rgb' => join(',', $this->util->hexToRGB('#46ba61')),
151
+            '--color-success-hover' => $this->util->mix('#46ba61', $colorMainBackground, 60),
152
+
153
+            // used for the icon loading animation
154
+            '--color-loading-light' => '#cccccc',
155
+            '--color-loading-dark' => '#444444',
156
+
157
+            '--color-box-shadow-rgb' => $colorBoxShadowRGB,
158
+            '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
159
+
160
+            '--color-border' => $this->util->darken($colorMainBackground, 7),
161
+            '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
162
+
163
+            '--font-face' => "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', Arial, sans-serif, 'Noto Color Emoji', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
164
+            '--default-font-size' => '15px',
165
+
166
+            // TODO: support "(prefers-reduced-motion)"
167
+            '--animation-quick' => '100ms',
168
+            '--animation-slow' => '300ms',
169
+
170
+            // Default variables --------------------------------------------
171
+            '--border-radius' => '3px',
172
+            '--border-radius-large' => '10px',
173
+            // pill-style button, value is large so big buttons also have correct roundness
174
+            '--border-radius-pill' => '100px',
175
+
176
+            '--default-line-height' => '24px',
177
+
178
+            // various structure data
179
+            '--header-height' => '50px',
180
+            '--navigation-width' => '300px',
181
+            '--sidebar-min-width' => '300px',
182
+            '--sidebar-max-width' => '500px',
183
+            '--list-min-width' => '200px',
184
+            '--list-max-width' => '300px',
185
+            '--header-menu-item-height' => '44px',
186
+            '--header-menu-profile-item-height' => '66px',
187
+
188
+            // mobile. Keep in sync with core/js/js.js
189
+            '--breakpoint-mobile' => '1024px',
190
+
191
+            // invert filter if primary is too bright
192
+            // to be used for legacy reasons only. Use inline
193
+            // svg with proper css variable instead or material
194
+            // design icons.
195
+            // ⚠️ Using 'no' as a value to make sure we specify an
196
+            // invalid one with no fallback. 'unset' could here fallback to some
197
+            // other theme with media queries
198
+            '--primary-invert-if-bright' => $this->util->invertTextColor($this->primaryColor) ? 'invert(100%)' : 'no',
199
+            '--background-invert-if-dark' => 'no',
200
+            '--background-invert-if-bright' => 'invert(100%)',
201
+
202
+            '--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
203
+        ];
204
+
205
+        $backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor';
206
+        // If primary as background has been request or if we have a custom primary colour
207
+        // let's not define the background image
208
+        if ($backgroundDeleted || $hasCustomPrimaryColour) {
209
+            $variables["--image-background-plain"] = 'true';
210
+        }
211
+
212
+        // Register image variables only if custom-defined
213
+        foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) {
214
+            if ($this->imageManager->hasImage($image)) {
215
+                $imageUrl = $this->imageManager->getImageUrl($image);
216
+                if ($image === 'background') {
217
+                    // If background deleted is set, ignoring variable
218
+                    if ($backgroundDeleted) {
219
+                        continue;
220
+                    }
221
+                    $variables['--image-background-size'] = 'cover';
222
+                    $variables['--image-main-background'] = "url('" . $imageUrl . "')";
223
+                }
224
+                $variables["--image-$image"] = "url('" . $imageUrl . "')";
225
+            }
226
+        }
227
+
228
+        if ($hasCustomLogoHeader) {
229
+            $variables["--image-logoheader-custom"] = 'true';
230
+        }
231
+
232
+        return $variables;
233
+    }
234
+
235
+    public function getCustomCss(): string {
236
+        return '';
237
+    }
238 238
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		$colorPrimaryElement = $this->util->elementColor($this->primaryColor);
94 94
 		$colorPrimaryElementLight = $this->util->mix($colorPrimaryElement, $colorMainBackground, -80);
95 95
 
96
-		$hasCustomLogoHeader = $this->imageManager->hasImage('logo') ||  $this->imageManager->hasImage('logoheader');
96
+		$hasCustomLogoHeader = $this->imageManager->hasImage('logo') || $this->imageManager->hasImage('logoheader');
97 97
 		$hasCustomPrimaryColour = !empty($this->config->getAppValue('theming', 'color'));
98 98
 
99 99
 		$variables = [
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 			'--background-invert-if-dark' => 'no',
200 200
 			'--background-invert-if-bright' => 'invert(100%)',
201 201
 
202
-			'--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
202
+			'--image-main-background' => "url('".$this->urlGenerator->imagePath('core', 'app-background.jpg')."')",
203 203
 		];
204 204
 
205 205
 		$backgroundDeleted = $this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor';
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 
212 212
 		// Register image variables only if custom-defined
213
-		foreach(['logo', 'logoheader', 'favicon', 'background'] as $image) {
213
+		foreach (['logo', 'logoheader', 'favicon', 'background'] as $image) {
214 214
 			if ($this->imageManager->hasImage($image)) {
215 215
 				$imageUrl = $this->imageManager->getImageUrl($image);
216 216
 				if ($image === 'background') {
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
 						continue;
220 220
 					}
221 221
 					$variables['--image-background-size'] = 'cover';
222
-					$variables['--image-main-background'] = "url('" . $imageUrl . "')";
222
+					$variables['--image-main-background'] = "url('".$imageUrl."')";
223 223
 				}
224
-				$variables["--image-$image"] = "url('" . $imageUrl . "')";
224
+				$variables["--image-$image"] = "url('".$imageUrl."')";
225 225
 			}
226 226
 		}
227 227
 
Please login to merge, or discard this patch.