Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be consistent about how the algorithm we use to modulate colors. #3010

Merged
merged 4 commits into from Sep 4, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Cleanup the way we compute the darker / lighter colors for inset / ou…

…tset borders.

Just so we have a single way to define the coefficients that we use to darken /
enlighten a color for these kinds of borders.
  • Loading branch information
emilio committed Sep 3, 2018
commit ec5710b66cfe1ab3e3ed56569df349973f343594
@@ -201,40 +201,31 @@ impl<'a> DisplayListFlattener<'a> {
}

pub trait BorderSideHelpers {
fn border_color(
&self,
scale_factor_0: f32,
scale_factor_1: f32,
black_color_0: f32,
black_color_1: f32,
) -> ColorF;
fn border_color(&self, is_inner_border: bool) -> ColorF;
}

impl BorderSideHelpers for BorderSide {
fn border_color(
&self,
scale_factor_0: f32,
scale_factor_1: f32,
black_color_0: f32,
black_color_1: f32,
) -> ColorF {
match self.style {
BorderStyle::Inset => {
if self.color.r != 0.0 || self.color.g != 0.0 || self.color.b != 0.0 {
self.color.scale_rgb(scale_factor_1)
} else {
ColorF::new(black_color_0, black_color_0, black_color_0, self.color.a)
}
}
BorderStyle::Outset => {
if self.color.r != 0.0 || self.color.g != 0.0 || self.color.b != 0.0 {
self.color.scale_rgb(scale_factor_0)
} else {
ColorF::new(black_color_1, black_color_1, black_color_1, self.color.a)
}
}
_ => self.color,
fn border_color(&self, is_inner_border: bool) -> ColorF {
let lighter = match self.style {
BorderStyle::Inset => is_inner_border,
BorderStyle::Outset => !is_inner_border,
_ => return self.color,
};

// The modulate colors below are not part of the specification. They are
// derived from the Gecko source code and experimentation, and used to
// modulate the colors in order to generate colors for the inset/outset
// and groove/ridge border styles.
//
// NOTE(emilio): Gecko at least takes the background color into
// account, should we do the same? Looks a bit annoying for this.
if self.color.r != 0.0 || self.color.g != 0.0 || self.color.b != 0.0 {
let scale = if lighter { 1.0 } else { 2.0 / 3.0 };
return self.color.scale_rgb(scale)
}

let black = if lighter { 0.7 } else { 0.3 };
ColorF::new(black, black, black, self.color.a)
}
}

@@ -912,21 +903,8 @@ impl BorderRenderTaskInfo {
side1.style
};

// These modulate colors are not part of the specification. They
// are derived from the Gecko source code and experimentation, and
// used to modulate the colors in order to generate colors for
// the inset/outset and groove/ridge border styles.
let color0 = if flip0 {
side0.border_color(2.0 / 3.0, 1.0, 0.7, 0.3)
} else {
side0.border_color(1.0, 2.0 / 3.0, 0.3, 0.7)
};

let color1 = if flip1 {
side1.border_color(2.0 / 3.0, 1.0, 0.7, 0.3)
} else {
side1.border_color(1.0, 2.0 / 3.0, 0.3, 0.7)
};
let color0 = side0.border_color(flip0);
let color1 = side1.border_color(flip1);

add_segment(
info.task_rect,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.