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:
Ngo Iok Ui (Wu Yu Wei) 2023-10-04 22:16:16 +09:00 committed by GitHub
parent ffac882f8f
commit 38a325cc1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 37 deletions

1
Cargo.lock generated
View file

@ -915,6 +915,7 @@ dependencies = [
"profile_traits", "profile_traits",
"script_traits", "script_traits",
"servo-media", "servo-media",
"servo_config",
"servo_geometry", "servo_geometry",
"servo_url", "servo_url",
"style_traits", "style_traits",

View file

@ -35,6 +35,7 @@ num-traits = { workspace = true }
pixels = { path = "../pixels", optional = true } pixels = { path = "../pixels", optional = true }
profile_traits = { path = "../profile_traits" } profile_traits = { path = "../profile_traits" }
script_traits = { path = "../script_traits" } script_traits = { path = "../script_traits" }
servo_config = { path = "../config" }
servo-media = { git = "https://github.com/servo/media" } servo-media = { git = "https://github.com/servo/media" }
servo_geometry = { path = "../geometry" } servo_geometry = { path = "../geometry" }
servo_url = { path = "../url" } servo_url = { path = "../url" }

View file

@ -1873,7 +1873,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.assert_gl_framebuffer_complete(); self.assert_gl_framebuffer_complete();
} }
// Make the viewport white. // Set the viewport background based on prefs.
let viewport = self.embedder_coordinates.get_flipped_viewport(); let viewport = self.embedder_coordinates.get_flipped_viewport();
gl.scissor( gl.scissor(
viewport.origin.x, viewport.origin.x,
@ -1881,7 +1881,14 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
viewport.size.width, viewport.size.width,
viewport.size.height, viewport.size.height,
); );
gl.clear_color(1.0, 1.0, 1.0, 1.0);
let color = servo_config::pref!(shell.background_color.rgba);
gl.clear_color(
color[0] as f32,
color[1] as f32,
color[2] as f32,
color[3] as f32,
);
gl.enable(gleam::gl::SCISSOR_TEST); gl.enable(gleam::gl::SCISSOR_TEST);
gl.clear(gleam::gl::COLOR_BUFFER_BIT); gl.clear(gleam::gl::COLOR_BUFFER_BIT);
gl.disable(gleam::gl::SCISSOR_TEST); gl.disable(gleam::gl::SCISSOR_TEST);

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto;
use std::fmt; use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use std::sync::RwLock; use std::sync::RwLock;
@ -16,6 +17,7 @@ pub enum PrefValue {
Int(i64), Int(i64),
Str(String), Str(String),
Bool(bool), Bool(bool),
Array(Vec<PrefValue>),
Missing, Missing,
} }
@ -149,6 +151,36 @@ impl_from_pref! {
PrefValue::Bool => bool, 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)] #[derive(Debug)]
pub enum PrefError { pub enum PrefError {
NoSuchPref(String), NoSuchPref(String),

View file

@ -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_i64() => PrefValue::Int(n.as_i64().unwrap()),
Value::Number(n) if n.is_f64() => PrefValue::Float(n.as_f64().unwrap()), Value::Number(n) if n.is_f64() => PrefValue::Float(n.as_f64().unwrap()),
Value::String(s) => PrefValue::Str(s.to_owned()), 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!( return Err(PrefError::InvalidValue(format!(
"Invalid value: {}", "Invalid value: {}",
@ -478,6 +489,10 @@ mod gen {
max_length: i64, max_length: i64,
}, },
shell: { shell: {
background_color: {
#[serde(rename = "shell.background-color.rgba")]
rgba: [f64; 4],
},
crash_reporter: { crash_reporter: {
enabled: bool, enabled: bool,
}, },

View file

@ -37,41 +37,50 @@ impl Actor for PreferenceActor {
_id: StreamId, _id: StreamId,
) -> Result<ActorMessageStatus, ()> { ) -> Result<ActorMessageStatus, ()> {
let pref_value = pref_map().get(msg_type); let pref_value = pref_map().get(msg_type);
Ok(match pref_value { Ok(handle_preference_value(
PrefValue::Float(value) => { pref_value,
let reply = FloatReply { self.name(),
from: self.name(), msg_type,
value: value, stream,
}; ))
let _ = stream.write_json_packet(&reply); }
ActorMessageStatus::Processed }
},
PrefValue::Int(value) => { fn handle_preference_value(
let reply = IntReply { pref_value: PrefValue,
from: self.name(), name: String,
value: value, msg_type: &str,
}; stream: &mut TcpStream,
let _ = stream.write_json_packet(&reply); ) -> ActorMessageStatus {
ActorMessageStatus::Processed match pref_value {
}, PrefValue::Float(value) => {
PrefValue::Str(value) => { let reply = FloatReply { from: name, value };
let reply = CharReply { let _ = stream.write_json_packet(&reply);
from: self.name(), ActorMessageStatus::Processed
value: value, },
}; PrefValue::Int(value) => {
let _ = stream.write_json_packet(&reply); let reply = IntReply { from: name, value };
ActorMessageStatus::Processed let _ = stream.write_json_packet(&reply);
}, ActorMessageStatus::Processed
PrefValue::Bool(value) => { },
let reply = BoolReply { PrefValue::Str(value) => {
from: self.name(), let reply = CharReply { from: name, value };
value: value, let _ = stream.write_json_packet(&reply);
}; ActorMessageStatus::Processed
let _ = stream.write_json_packet(&reply); },
ActorMessageStatus::Processed PrefValue::Bool(value) => {
}, let reply = BoolReply { from: name, value };
PrefValue::Missing => handle_missing_preference(self.name(), msg_type, stream), let _ = stream.write_json_packet(&reply);
}) ActorMessageStatus::Processed
},
PrefValue::Array(values) => {
let mut result = ActorMessageStatus::Processed;
for value in values {
result = handle_preference_value(value, name.clone(), msg_type, stream);
}
result
},
PrefValue::Missing => handle_missing_preference(name, msg_type, stream),
} }
} }

View file

@ -283,6 +283,11 @@ impl Serialize for WebDriverPrefValue {
PrefValue::Float(f) => serializer.serialize_f64(f), PrefValue::Float(f) => serializer.serialize_f64(f),
PrefValue::Int(i) => serializer.serialize_i64(i), PrefValue::Int(i) => serializer.serialize_i64(i),
PrefValue::Missing => serializer.serialize_unit(), PrefValue::Missing => serializer.serialize_unit(),
PrefValue::Array(ref v) => v
.iter()
.map(|value| WebDriverPrefValue(value.clone()))
.collect::<Vec<WebDriverPrefValue>>()
.serialize(serializer),
} }
} }
} }

View file

@ -110,6 +110,7 @@
"network.http-cache.disabled": false, "network.http-cache.disabled": false,
"network.mime.sniff": false, "network.mime.sniff": false,
"session-history.max-length": 20, "session-history.max-length": 20,
"shell.background-color.rgba": [1.0, 1.0, 1.0, 1.0],
"shell.crash_reporter.enabled": false, "shell.crash_reporter.enabled": false,
"shell.homepage": "https://servo.org", "shell.homepage": "https://servo.org",
"shell.keep_screen_on.enabled": false, "shell.keep_screen_on.enabled": false,