aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/canvas_state.rs172
-rw-r--r--components/script/dom/bindings/trace.rs8
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs47
-rw-r--r--components/script/dom/offscreencanvasrenderingcontext2d.rs57
-rw-r--r--components/script/dom/webidls/CanvasRenderingContext2D.webidl8
-rw-r--r--components/script/dom/window.rs17
6 files changed, 291 insertions, 18 deletions
diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs
index 2376d6f8d85..0a6fba842e4 100644
--- a/components/script/canvas_state.rs
+++ b/components/script/canvas_state.rs
@@ -3,10 +3,13 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasDirection;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasImageSource;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineCap;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineJoin;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextAlign;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextBaseline;
use crate::dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
use crate::dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
@@ -22,12 +25,12 @@ use crate::dom::element::Element;
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement};
use crate::dom::imagedata::ImageData;
-use crate::dom::node::{Node, NodeDamage};
+use crate::dom::node::{window_from_node, Node, NodeDamage};
use crate::dom::offscreencanvas::{OffscreenCanvas, OffscreenCanvasContext};
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
use crate::dom::textmetrics::TextMetrics;
use crate::unpremultiplytable::UNPREMULTIPLY_TABLE;
-use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg};
+use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg, Direction, TextAlign, TextBaseline};
use canvas_traits::canvas::{CompositionOrBlending, FillOrStrokeStyle, FillRule};
use canvas_traits::canvas::{LineCapStyle, LineJoinStyle, LinearGradientStyle};
use canvas_traits::canvas::{RadialGradientStyle, RepetitionStyle};
@@ -49,6 +52,10 @@ use std::cell::Cell;
use std::fmt;
use std::str::FromStr;
use std::sync::Arc;
+use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
+use style::properties::style_structs::Font;
+use style::values::computed::font::FontStyle;
+use style_traits::values::ToCss;
#[unrooted_must_root_lint::must_root]
#[derive(Clone, JSTraceable, MallocSizeOf)]
@@ -86,9 +93,15 @@ pub(crate) struct CanvasContextState {
shadow_offset_y: f64,
shadow_blur: f64,
shadow_color: RGBA,
+ font_style: Option<Font>,
+ text_align: TextAlign,
+ text_baseline: TextBaseline,
+ direction: Direction,
}
impl CanvasContextState {
+ const DEFAULT_FONT_STYLE: &'static str = "10px sans-serif";
+
pub(crate) fn new() -> CanvasContextState {
let black = RGBA::new(0, 0, 0, 255);
CanvasContextState {
@@ -106,6 +119,10 @@ impl CanvasContextState {
shadow_offset_y: 0.0,
shadow_blur: 0.0,
shadow_color: RGBA::transparent(),
+ font_style: None,
+ text_align: Default::default(),
+ text_baseline: Default::default(),
+ direction: Default::default(),
}
}
}
@@ -987,10 +1004,39 @@ impl CanvasState {
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
- pub fn fill_text(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
- let parsed_text: String = text.into();
+ pub fn fill_text(
+ &self,
+ canvas: Option<&HTMLCanvasElement>,
+ text: DOMString,
+ x: f64,
+ y: f64,
+ max_width: Option<f64>,
+ ) {
+ if !x.is_finite() || !y.is_finite() {
+ return;
+ }
+ if max_width.map_or(false, |max_width| !max_width.is_finite() || max_width <= 0.) {
+ return;
+ }
+ if self.state.borrow().font_style.is_none() {
+ self.set_font(canvas, CanvasContextState::DEFAULT_FONT_STYLE.into())
+ }
+
+ let is_rtl = match self.state.borrow().direction {
+ Direction::Ltr => false,
+ Direction::Rtl => true,
+ Direction::Inherit => false, // TODO: resolve direction wrt to canvas element
+ };
+
let style = self.state.borrow().fill_style.to_fill_or_stroke_style();
- self.send_canvas_2d_msg(Canvas2dMsg::FillText(parsed_text, x, y, max_width, style));
+ self.send_canvas_2d_msg(Canvas2dMsg::FillText(
+ text.into(),
+ x,
+ y,
+ max_width,
+ style,
+ is_rtl,
+ ));
}
// https://html.spec.whatwg.org/multipage/#textmetrics
@@ -1002,6 +1048,101 @@ impl CanvasState {
)
}
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ pub fn set_font(&self, canvas: Option<&HTMLCanvasElement>, value: DOMString) {
+ let canvas = match canvas {
+ Some(element) => element,
+ None => return, // offscreen canvas doesn't have a placeholder canvas
+ };
+ let node = canvas.upcast::<Node>();
+ let window = window_from_node(&*canvas);
+ let resolved_font_style = match window.resolved_font_style_query(&node, value.to_string()) {
+ Some(value) => value,
+ None => return, // syntax error
+ };
+ self.state.borrow_mut().font_style = Some((*resolved_font_style).clone());
+ self.send_canvas_2d_msg(Canvas2dMsg::SetFont((*resolved_font_style).clone()));
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ pub fn font(&self) -> DOMString {
+ self.state.borrow().font_style.as_ref().map_or_else(
+ || CanvasContextState::DEFAULT_FONT_STYLE.into(),
+ |style| {
+ let mut result = String::new();
+ serialize_font(style, &mut result).unwrap();
+ DOMString::from(result)
+ },
+ )
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ pub fn text_align(&self) -> CanvasTextAlign {
+ match self.state.borrow().text_align {
+ TextAlign::Start => CanvasTextAlign::Start,
+ TextAlign::End => CanvasTextAlign::End,
+ TextAlign::Left => CanvasTextAlign::Left,
+ TextAlign::Right => CanvasTextAlign::Right,
+ TextAlign::Center => CanvasTextAlign::Center,
+ }
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ pub fn set_text_align(&self, value: CanvasTextAlign) {
+ let text_align = match value {
+ CanvasTextAlign::Start => TextAlign::Start,
+ CanvasTextAlign::End => TextAlign::End,
+ CanvasTextAlign::Left => TextAlign::Left,
+ CanvasTextAlign::Right => TextAlign::Right,
+ CanvasTextAlign::Center => TextAlign::Center,
+ };
+ self.state.borrow_mut().text_align = text_align;
+ self.send_canvas_2d_msg(Canvas2dMsg::SetTextAlign(text_align));
+ }
+
+ pub fn text_baseline(&self) -> CanvasTextBaseline {
+ match self.state.borrow().text_baseline {
+ TextBaseline::Top => CanvasTextBaseline::Top,
+ TextBaseline::Hanging => CanvasTextBaseline::Hanging,
+ TextBaseline::Middle => CanvasTextBaseline::Middle,
+ TextBaseline::Alphabetic => CanvasTextBaseline::Alphabetic,
+ TextBaseline::Ideographic => CanvasTextBaseline::Ideographic,
+ TextBaseline::Bottom => CanvasTextBaseline::Bottom,
+ }
+ }
+
+ pub fn set_text_baseline(&self, value: CanvasTextBaseline) {
+ let text_baseline = match value {
+ CanvasTextBaseline::Top => TextBaseline::Top,
+ CanvasTextBaseline::Hanging => TextBaseline::Hanging,
+ CanvasTextBaseline::Middle => TextBaseline::Middle,
+ CanvasTextBaseline::Alphabetic => TextBaseline::Alphabetic,
+ CanvasTextBaseline::Ideographic => TextBaseline::Ideographic,
+ CanvasTextBaseline::Bottom => TextBaseline::Bottom,
+ };
+ self.state.borrow_mut().text_baseline = text_baseline;
+ self.send_canvas_2d_msg(Canvas2dMsg::SetTextBaseline(text_baseline));
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ pub fn direction(&self) -> CanvasDirection {
+ match self.state.borrow().direction {
+ Direction::Ltr => CanvasDirection::Ltr,
+ Direction::Rtl => CanvasDirection::Rtl,
+ Direction::Inherit => CanvasDirection::Inherit,
+ }
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ pub fn set_direction(&self, value: CanvasDirection) {
+ let direction = match value {
+ CanvasDirection::Ltr => Direction::Ltr,
+ CanvasDirection::Rtl => Direction::Rtl,
+ CanvasDirection::Inherit => Direction::Inherit,
+ };
+ self.state.borrow_mut().direction = direction;
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
pub fn line_width(&self) -> f64 {
self.state.borrow().line_width
@@ -1627,3 +1768,24 @@ pub fn adjust_size_sign(
}
(origin, size.to_u32())
}
+
+fn serialize_font<W>(style: &Font, dest: &mut W) -> fmt::Result
+where
+ W: fmt::Write,
+{
+ if style.font_style == FontStyle::Italic {
+ write!(dest, "{} ", style.font_style.to_css_string())?;
+ }
+ if style.font_weight.is_bold() {
+ write!(dest, "{} ", style.font_weight.to_css_string())?;
+ }
+ if style.font_variant_caps == FontVariantCaps::SmallCaps {
+ write!(dest, "{} ", style.font_variant_caps.to_css_string())?;
+ }
+ write!(
+ dest,
+ "{} {}",
+ style.font_size.to_css_string(),
+ style.font_family.to_css_string()
+ )
+}
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 1f6d15a191a..9518a2c0989 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -47,7 +47,10 @@ use app_units::Au;
use canvas_traits::canvas::{
CanvasGradientStop, CanvasId, LinearGradientStyle, RadialGradientStyle,
};
-use canvas_traits::canvas::{CompositionOrBlending, LineCapStyle, LineJoinStyle, RepetitionStyle};
+use canvas_traits::canvas::{
+ CompositionOrBlending, Direction, LineCapStyle, LineJoinStyle, RepetitionStyle, TextAlign,
+ TextBaseline,
+};
use canvas_traits::webgl::WebGLVertexArrayId;
use canvas_traits::webgl::{
ActiveAttribInfo, ActiveUniformBlockInfo, ActiveUniformInfo, GlType, TexDataType, TexFormat,
@@ -144,6 +147,7 @@ use style::context::QuirksMode;
use style::dom::OpaqueNode;
use style::element_state::*;
use style::media_queries::MediaList;
+use style::properties::style_structs::Font;
use style::properties::PropertyDeclarationBlock;
use style::selector_parser::{PseudoElement, Snapshot};
use style::shared_lock::{Locked as StyleLocked, SharedRwLock as StyleSharedRwLock};
@@ -479,6 +483,7 @@ unsafe_no_jsmanaged_fields!(NetworkError);
unsafe_no_jsmanaged_fields!(Atom, Prefix, LocalName, Namespace, QualName);
unsafe_no_jsmanaged_fields!(TrustedPromise);
unsafe_no_jsmanaged_fields!(PropertyDeclarationBlock);
+unsafe_no_jsmanaged_fields!(Font);
// These three are interdependent, if you plan to put jsmanaged data
// in one of these make sure it is propagated properly to containing structs
unsafe_no_jsmanaged_fields!(DocumentActivity, WindowSizeData, WindowSizeType);
@@ -501,6 +506,7 @@ unsafe_no_jsmanaged_fields!(RGBA);
unsafe_no_jsmanaged_fields!(StorageType);
unsafe_no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyle);
unsafe_no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
+unsafe_no_jsmanaged_fields!(TextAlign, TextBaseline, Direction);
unsafe_no_jsmanaged_fields!(RepetitionStyle);
unsafe_no_jsmanaged_fields!(WebGLError, GLLimits, GlType);
unsafe_no_jsmanaged_fields!(TimeProfilerChan);
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index 4820a3bbfd7..3ebf8f130d9 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -3,11 +3,14 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::canvas_state::CanvasState;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasDirection;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasImageSource;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineCap;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineJoin;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextAlign;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextBaseline;
use crate::dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
use crate::dom::bindings::error::{ErrorResult, Fallible};
use crate::dom::bindings::num::Finite;
@@ -288,7 +291,8 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
- self.canvas_state.fill_text(text, x, y, max_width);
+ self.canvas_state
+ .fill_text(self.canvas.as_ref().map(|c| &**c), text, x, y, max_width);
self.mark_as_dirty();
}
@@ -297,6 +301,47 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
self.canvas_state.measure_text(&self.global(), text)
}
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn Font(&self) -> DOMString {
+ self.canvas_state.font()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn SetFont(&self, value: DOMString) {
+ self.canvas_state
+ .set_font(self.canvas.as_ref().map(|c| &**c), value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn TextAlign(&self) -> CanvasTextAlign {
+ self.canvas_state.text_align()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn SetTextAlign(&self, value: CanvasTextAlign) {
+ self.canvas_state.set_text_align(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn TextBaseline(&self) -> CanvasTextBaseline {
+ self.canvas_state.text_baseline()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn SetTextBaseline(&self, value: CanvasTextBaseline) {
+ self.canvas_state.set_text_baseline(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn Direction(&self) -> CanvasDirection {
+ self.canvas_state.direction()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn SetDirection(&self, value: CanvasDirection) {
+ self.canvas_state.set_direction(value)
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult {
self.canvas_state
diff --git a/components/script/dom/offscreencanvasrenderingcontext2d.rs b/components/script/dom/offscreencanvasrenderingcontext2d.rs
index a3a873250f1..8c3deb001f4 100644
--- a/components/script/dom/offscreencanvasrenderingcontext2d.rs
+++ b/components/script/dom/offscreencanvasrenderingcontext2d.rs
@@ -3,10 +3,13 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::canvas_state::CanvasState;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasDirection;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasImageSource;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineCap;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineJoin;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextAlign;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextBaseline;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding::OffscreenCanvasRenderingContext2DMethods;
use crate::dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
use crate::dom::bindings::error::ErrorResult;
@@ -60,11 +63,6 @@ impl OffscreenCanvasRenderingContext2D {
));
reflect_dom_object(boxed, global)
}
- /*
- pub fn get_canvas_state(&self) -> Ref<CanvasState> {
- self.canvas_state.borrow()
- }
- */
pub fn set_canvas_bitmap_dimensions(&self, size: Size2D<u64>) {
self.canvas_state.set_bitmap_dimensions(size);
@@ -249,7 +247,13 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
- self.canvas_state.fill_text(text, x, y, max_width)
+ self.canvas_state.fill_text(
+ self.htmlcanvas.as_ref().map(|c| &**c),
+ text,
+ x,
+ y,
+ max_width,
+ )
}
// https://html.spec.whatwg.org/multipage/#textmetrics
@@ -257,6 +261,47 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
self.canvas_state.measure_text(&self.global(), text)
}
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn Font(&self) -> DOMString {
+ self.canvas_state.font()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn SetFont(&self, value: DOMString) {
+ self.canvas_state
+ .set_font(self.htmlcanvas.as_ref().map(|c| &**c), value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn TextAlign(&self) -> CanvasTextAlign {
+ self.canvas_state.text_align()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn SetTextAlign(&self, value: CanvasTextAlign) {
+ self.canvas_state.set_text_align(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn TextBaseline(&self) -> CanvasTextBaseline {
+ self.canvas_state.text_baseline()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn SetTextBaseline(&self, value: CanvasTextBaseline) {
+ self.canvas_state.set_text_baseline(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn Direction(&self) -> CanvasDirection {
+ self.canvas_state.direction()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn SetDirection(&self, value: CanvasDirection) {
+ self.canvas_state.set_direction(value)
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
fn LineWidth(&self) -> f64 {
self.canvas_state.line_width()
diff --git a/components/script/dom/webidls/CanvasRenderingContext2D.webidl b/components/script/dom/webidls/CanvasRenderingContext2D.webidl
index af88cfe9281..62669f4c2ba 100644
--- a/components/script/dom/webidls/CanvasRenderingContext2D.webidl
+++ b/components/script/dom/webidls/CanvasRenderingContext2D.webidl
@@ -211,11 +211,11 @@ interface mixin CanvasPathDrawingStyles {
[Exposed=(PaintWorklet, Window, Worker)]
interface mixin CanvasTextDrawingStyles {
// text
- //attribute DOMString font; // (default 10px sans-serif)
- //attribute CanvasTextAlign textAlign; // "start", "end", "left", "right", "center" (default: "start")
- //attribute CanvasTextBaseline textBaseline; // "top", "hanging", "middle", "alphabetic",
+ attribute DOMString font; // (default 10px sans-serif)
+ attribute CanvasTextAlign textAlign; // "start", "end", "left", "right", "center" (default: "start")
+ attribute CanvasTextBaseline textBaseline; // "top", "hanging", "middle", "alphabetic",
// "ideographic", "bottom" (default: "alphabetic")
- //attribute CanvasDirection direction; // "ltr", "rtl", "inherit" (default: "inherit")
+ attribute CanvasDirection direction; // "ltr", "rtl", "inherit" (default: "inherit")
};
[Exposed=(PaintWorklet, Window, Worker)]
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index c050579918e..d7fde4f27d5 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -118,6 +118,7 @@ use script_traits::{
};
use script_traits::{TimerSchedulerMsg, WebrenderIpcSender, WindowSizeData, WindowSizeType};
use selectors::attr::CaseSensitivity;
+use servo_arc::Arc as ServoArc;
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::borrow::Cow;
@@ -136,7 +137,8 @@ use style::dom::OpaqueNode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::media_queries;
use style::parser::ParserContext as CssParserContext;
-use style::properties::PropertyId;
+use style::properties::style_structs::Font;
+use style::properties::{PropertyId, ShorthandId};
use style::selector_parser::PseudoElement;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::CssRuleType;
@@ -1847,6 +1849,18 @@ impl Window {
)
}
+ pub fn resolved_font_style_query(&self, node: &Node, value: String) -> Option<ServoArc<Font>> {
+ let id = PropertyId::Shorthand(ShorthandId::Font);
+ if !self.layout_reflow(QueryMsg::ResolvedFontStyleQuery(
+ node.to_trusted_node_address(),
+ id,
+ value,
+ )) {
+ return None;
+ }
+ self.layout_rpc.resolved_font_style()
+ }
+
pub fn layout(&self) -> &dyn LayoutRPC {
&*self.layout_rpc
}
@@ -2500,6 +2514,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
&QueryMsg::NodeScrollGeometryQuery(_n) => "\tNodeScrollGeometryQuery",
&QueryMsg::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery",
&QueryMsg::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
+ &QueryMsg::ResolvedFontStyleQuery(..) => "\nResolvedFontStyleQuery",
&QueryMsg::OffsetParentQuery(_n) => "\tOffsetParentQuery",
&QueryMsg::StyleQuery => "\tStyleQuery",
&QueryMsg::TextIndexQuery(..) => "\tTextIndexQuery",