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

Implement CanvasRenderingContext2D.font property #26176

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -90,6 +90,9 @@ pub struct LayoutThreadData {

/// A queued response for the viewport dimensions for a given browsing context.
pub inner_window_dimensions_response: Option<TypedSize2D<f32, CSSPixel>>,

/// A queued response for the resolved font property of a canvas element.
pub canvas_font_response: String,
}

pub struct LayoutRPCImpl(pub Arc<Mutex<LayoutThreadData>>);
@@ -1095,3 +1098,11 @@ fn is_last_table_row() -> bool {
// FIXME(ferjm) Implement this.
false
}

pub fn process_canvas_font_request<'dom>(
_node: impl LayoutNode<'dom>,
_font: &str,
_layout_root: &mut dyn Flow,
) -> String {
unimplemented!()
}
@@ -50,12 +50,14 @@ use layout::flow_ref::FlowRef;
use layout::incremental::{RelayoutMode, SpecialRestyleDamage};
use layout::layout_debug;
use layout::parallel;
use layout::query::{
process_canvas_font_request, process_offset_parent_query, process_resolved_style_request,
};
use layout::query::{process_client_rect_query, process_element_inner_text_query};
use layout::query::{
process_content_box_request, process_content_boxes_request, LayoutRPCImpl, LayoutThreadData,
};
use layout::query::{process_node_scroll_area_request, process_node_scroll_id_request};
use layout::query::{process_offset_parent_query, process_resolved_style_request};
use layout::sequential;
use layout::traversal::{
ComputeStackingRelativePositions, PreorderFlowTraversal, RecalcStyleAndConstructFlows,
@@ -575,6 +577,7 @@ impl LayoutThread {
nodes_from_point_response: vec![],
element_inner_text_response: String::new(),
inner_window_dimensions_response: None,
canvas_font_response: String::new(),
})),
webrender_image_cache: Arc::new(RwLock::new(FnvHashMap::default())),
paint_time_metrics: paint_time_metrics,
@@ -1255,6 +1258,9 @@ impl LayoutThread {
&QueryMsg::InnerWindowDimensionsQuery(_) => {
rw_data.inner_window_dimensions_response = None;
},
&QueryMsg::CanvasFontQuery(..) => {
unimplemented!();
},
},
ReflowGoal::Full | ReflowGoal::TickAnimations => {},
}
@@ -1597,6 +1603,11 @@ impl LayoutThread {
.get(&browsing_context_id)
.cloned();
},
&QueryMsg::CanvasFontQuery(node, ref font) => {
let node = unsafe { ServoLayoutNode::new(&node) };
rw_data.canvas_font_response =
process_canvas_font_request(node, font, root_flow);
},
},
ReflowGoal::Full | ReflowGoal::TickAnimations => {},
}
@@ -49,6 +49,12 @@ use std::cell::Cell;
use std::fmt;
use std::str::FromStr;
use std::sync::Arc;
use style::context::QuirksMode;
use style::parser::ParserContext;
use style::properties::shorthands::font;
use style::stylesheets::origin::Origin;
use style::stylesheets::CssRuleType;
use style_traits::ParsingMode;

#[unrooted_must_root_lint::must_root]
#[derive(Clone, JSTraceable, MallocSizeOf)]
@@ -1558,6 +1564,30 @@ impl CanvasState {
));
Ok(())
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-font
pub fn font(&self) -> DOMString {
unimplemented!()
}

// https://html.spec.whatwg.org/multipage/#dom-context-2d-font
pub fn set_font(&self, value: DOMString) {
let mut input = ParserInput::new(&value);
let mut parser = Parser::new(&mut input);
let context = ParserContext::new(
Origin::Author,
&self.base_url,
Some(CssRuleType::Style),
ParsingMode::DEFAULT,
QuirksMode::NoQuirks,
None,
None,
);
match font::parse_value(&context, &mut parser) {
Ok(_longhands) => unimplemented!("TODO: handle parsed values"),
Err(_err) => unimplemented!("TODO: handle parse errors"),
}
}
}

pub fn parse_color(string: &str) -> Result<RGBA, ()> {
@@ -606,6 +606,16 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
fn SetShadowColor(&self, value: DOMString) {
self.canvas_state.set_shadow_color(value)
}

// 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(value)
}
}

impl Drop for CanvasRenderingContext2D {
@@ -513,4 +513,14 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
self.canvas_state
.ellipse(x, y, rx, ry, rotation, start, end, ccw)
}

// 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(value)
}
}
@@ -211,7 +211,7 @@ interface mixin CanvasPathDrawingStyles {
[Exposed=(PaintWorklet, Window, Worker)]
interface mixin CanvasTextDrawingStyles {
// text
//attribute DOMString font; // (default 10px sans-serif)
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")
@@ -2460,6 +2460,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
&QueryMsg::TextIndexQuery(..) => "\tTextIndexQuery",
&QueryMsg::ElementInnerTextQuery(_) => "\tElementInnerTextQuery",
&QueryMsg::InnerWindowDimensionsQuery(_) => "\tInnerWindowDimensionsQuery",
&QueryMsg::CanvasFontQuery(..) => "\tCanvasFontQuery",
},
};

@@ -116,6 +116,7 @@ pub enum QueryMsg {
StyleQuery,
ElementInnerTextQuery(TrustedNodeAddress),
InnerWindowDimensionsQuery(BrowsingContextId),
CanvasFontQuery(TrustedNodeAddress, String),
}

/// Any query to perform with this reflow.
@@ -144,6 +145,7 @@ impl ReflowGoal {
QueryMsg::NodeScrollIdQuery(_) |
QueryMsg::ResolvedStyleQuery(..) |
QueryMsg::OffsetParentQuery(_) |
QueryMsg::CanvasFontQuery(..) |
QueryMsg::StyleQuery => false,
},
}
@@ -166,6 +168,7 @@ impl ReflowGoal {
QueryMsg::ResolvedStyleQuery(..) |
QueryMsg::OffsetParentQuery(_) |
QueryMsg::InnerWindowDimensionsQuery(_) |
QueryMsg::CanvasFontQuery(..) |
QueryMsg::StyleQuery => false,
},
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.