mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add shell.background-color.rgba to prefs (#30488)
* Add shell.transparent-background.enabled to prefs * Rename config to background_color * Rename to background-color and.rgba add PrefValue::Array variant
This commit is contained in:
parent
ffac882f8f
commit
38a325cc1c
8 changed files with 108 additions and 37 deletions
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use std::sync::RwLock;
|
||||
|
@ -16,6 +17,7 @@ pub enum PrefValue {
|
|||
Int(i64),
|
||||
Str(String),
|
||||
Bool(bool),
|
||||
Array(Vec<PrefValue>),
|
||||
Missing,
|
||||
}
|
||||
|
||||
|
@ -149,6 +151,36 @@ impl_from_pref! {
|
|||
PrefValue::Bool => bool,
|
||||
}
|
||||
|
||||
impl From<[f64; 4]> for PrefValue {
|
||||
fn from(other: [f64; 4]) -> PrefValue {
|
||||
PrefValue::Array(IntoIterator::into_iter(other).map(|v| v.into()).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrefValue> for [f64; 4] {
|
||||
fn from(other: PrefValue) -> [f64; 4] {
|
||||
match other {
|
||||
PrefValue::Array(values) if values.len() == 4 => {
|
||||
let mut f = values.into_iter().map(|v| v.try_into());
|
||||
if f.all(|v| v.is_ok()) {
|
||||
let f = f.flatten().collect::<Vec<f64>>();
|
||||
return [f[0], f[1], f[2], f[3]];
|
||||
} else {
|
||||
panic!(
|
||||
"Cannot convert PrefValue to {:?}",
|
||||
std::any::type_name::<[f64; 4]>()
|
||||
)
|
||||
}
|
||||
},
|
||||
_ => panic!(
|
||||
"Cannot convert {:?} to {:?}",
|
||||
other,
|
||||
std::any::type_name::<[f64; 4]>()
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PrefError {
|
||||
NoSuchPref(String),
|
||||
|
|
|
@ -73,6 +73,17 @@ pub fn read_prefs_map(txt: &str) -> Result<HashMap<String, PrefValue>, PrefError
|
|||
Value::Number(n) if n.is_i64() => PrefValue::Int(n.as_i64().unwrap()),
|
||||
Value::Number(n) if n.is_f64() => PrefValue::Float(n.as_f64().unwrap()),
|
||||
Value::String(s) => PrefValue::Str(s.to_owned()),
|
||||
Value::Array(v) => {
|
||||
let mut array = v.iter().map(|v| PrefValue::from_json_value(v));
|
||||
if array.all(|v| v.is_some()) {
|
||||
PrefValue::Array(array.flatten().collect())
|
||||
} else {
|
||||
return Err(PrefError::InvalidValue(format!(
|
||||
"Invalid value: {}",
|
||||
pref_value
|
||||
)));
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return Err(PrefError::InvalidValue(format!(
|
||||
"Invalid value: {}",
|
||||
|
@ -478,6 +489,10 @@ mod gen {
|
|||
max_length: i64,
|
||||
},
|
||||
shell: {
|
||||
background_color: {
|
||||
#[serde(rename = "shell.background-color.rgba")]
|
||||
rgba: [f64; 4],
|
||||
},
|
||||
crash_reporter: {
|
||||
enabled: bool,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue