aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/layout/construct.rs15
-rw-r--r--components/style/properties.mako.rs13
-rw-r--r--tests/ref/basic.list1
-rw-r--r--tests/ref/input_button_margins_a.html11
-rw-r--r--tests/ref/input_button_margins_ref.html12
5 files changed, 47 insertions, 5 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs
index 5976045e740..0e57bd13d1a 100644
--- a/components/layout/construct.rs
+++ b/components/layout/construct.rs
@@ -673,11 +673,13 @@ impl<'a> FlowConstructor<'a> {
fn build_flow_for_block_like(&mut self, flow: FlowRef, node: &ThreadSafeLayoutNode)
-> ConstructionResult {
let mut initial_fragments = IntermediateInlineFragments::new();
- if node.get_pseudo_element_type() != PseudoElementType::Normal ||
+ let node_is_input_or_text_area =
node.type_id() == Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
HTMLElementTypeId::HTMLInputElement))) ||
node.type_id() == Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
- HTMLElementTypeId::HTMLTextAreaElement))) {
+ HTMLElementTypeId::HTMLTextAreaElement)));
+ if node.get_pseudo_element_type() != PseudoElementType::Normal ||
+ node_is_input_or_text_area {
// A TextArea's text contents are displayed through the input text
// box, so don't construct them.
if node.type_id() == Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
@@ -687,9 +689,12 @@ impl<'a> FlowConstructor<'a> {
}
}
- self.create_fragments_for_node_text_content(&mut initial_fragments,
- node,
- &*node.style());
+ let mut style = node.style().clone();
+ if node_is_input_or_text_area {
+ properties::modify_style_for_input_text(&mut style);
+ }
+
+ self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style)
}
self.build_flow_for_block_starting_with_fragments(flow, node, initial_fragments)
diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs
index 93b73fecf65..fd22abbaf02 100644
--- a/components/style/properties.mako.rs
+++ b/components/style/properties.mako.rs
@@ -6518,6 +6518,19 @@ pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
}
}
+/// Adjusts the `margin` property as necessary to account for the text of an `input` element.
+///
+/// Margins apply to the `input` element itself, so including them in the text will cause them to
+/// be double-counted.
+pub fn modify_style_for_input_text(style: &mut Arc<ComputedValues>) {
+ let mut style = Arc::make_unique(style);
+ let margin_style = Arc::make_unique(&mut style.margin);
+ margin_style.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0));
+ margin_style.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0));
+ margin_style.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0));
+ margin_style.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0));
+}
+
pub fn is_supported_property(property: &str) -> bool {
match_ignore_ascii_case! { property,
% for property in SHORTHANDS + LONGHANDS[:-1]:
diff --git a/tests/ref/basic.list b/tests/ref/basic.list
index 6d5bba85d1e..3f6c6c6316f 100644
--- a/tests/ref/basic.list
+++ b/tests/ref/basic.list
@@ -170,6 +170,7 @@ experimental == iframe/size_attributes_vertical_writing_mode.html iframe/size_at
# inline_text_align_a.html inline_text_align_b.html
== inline_whitespace_a.html inline_whitespace_ref.html
== inline_whitespace_b.html inline_whitespace_ref.html
+== input_button_margins_a.html input_button_margins_ref.html
== input_button_size_a.html input_button_size_ref.html
!= input_height_a.html input_height_ref.html
== inset.html inset_ref.html
diff --git a/tests/ref/input_button_margins_a.html b/tests/ref/input_button_margins_a.html
new file mode 100644
index 00000000000..b35a3b5ccb6
--- /dev/null
+++ b/tests/ref/input_button_margins_a.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+body, html {
+ margin: 0;
+}
+input {
+ margin-left: 64px;
+}
+</style>
+<input type=button value=Hello>
+
diff --git a/tests/ref/input_button_margins_ref.html b/tests/ref/input_button_margins_ref.html
new file mode 100644
index 00000000000..07ecda7c227
--- /dev/null
+++ b/tests/ref/input_button_margins_ref.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+body, html {
+ margin: 0;
+}
+input {
+ position: absolute;
+ left: 64px;
+}
+</style>
+<input type=button value=Hello>
+