servo: Merge #19727 - Properly handle CR in textarea placeholders (fixes #19717) (from nox:cr-placeholder); r=emilio
authorAnthony Ramine <n.oxyde@gmail.com>
Wed, 10 Jan 2018 10:37:47 -0600
changeset 452862 c50305b32c5e7f68d39fc29b8f871677f5ca18ff
parent 452861 56528e7c9daccf6630cc0684655611f720e6b805
child 452863 606f0a73700999d1eab9124a2b9d9f6cb8eeefa1
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19727 - Properly handle CR in textarea placeholders (fixes #19717) (from nox:cr-placeholder); r=emilio Source-Repo: https://github.com/servo/servo Source-Revision: 2065fa6da23c304093b0fdbbf7c068e0b0c67366
servo/components/script/dom/htmltextareaelement.rs
servo/components/script/dom/node.rs
--- a/servo/components/script/dom/htmltextareaelement.rs
+++ b/servo/components/script/dom/htmltextareaelement.rs
@@ -45,35 +45,38 @@ pub struct HTMLTextAreaElement {
     placeholder: DomRefCell<DOMString>,
     // https://html.spec.whatwg.org/multipage/#concept-textarea-dirty
     value_changed: Cell<bool>,
     form_owner: MutNullableDom<HTMLFormElement>,
 }
 
 pub trait LayoutHTMLTextAreaElementHelpers {
     #[allow(unsafe_code)]
-    unsafe fn get_value_for_layout(self) -> String;
+    unsafe fn value_for_layout(self) -> String;
     #[allow(unsafe_code)]
     unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
     #[allow(unsafe_code)]
     fn get_cols(self) -> u32;
     #[allow(unsafe_code)]
     fn get_rows(self) -> u32;
 }
 
 impl LayoutHTMLTextAreaElementHelpers for LayoutDom<HTMLTextAreaElement> {
     #[allow(unrooted_must_root)]
     #[allow(unsafe_code)]
-    unsafe fn get_value_for_layout(self) -> String {
+    unsafe fn value_for_layout(self) -> String {
         let text = (*self.unsafe_get()).textinput.borrow_for_layout().get_content();
-        String::from(if text.is_empty() {
-            (*self.unsafe_get()).placeholder.borrow_for_layout().clone()
+        if text.is_empty() {
+            (*self.unsafe_get()).placeholder
+                .borrow_for_layout()
+                .replace("\r\n", "\n")
+                .replace("\r", "\n")
         } else {
-            text
-        })
+            text.into()
+        }
     }
 
     #[allow(unrooted_must_root)]
     #[allow(unsafe_code)]
     unsafe fn selection_for_layout(self) -> Option<Range<usize>> {
         if !(*self.unsafe_get()).upcast::<Element>().focus_state() {
             return None;
         }
@@ -133,17 +136,16 @@ impl HTMLTextAreaElement {
                            HTMLTextAreaElementBinding::Wrap)
     }
 
     fn update_placeholder_shown_state(&self) {
         let has_placeholder = !self.placeholder.borrow().is_empty();
         let has_value = !self.textinput.borrow().is_empty();
         let el = self.upcast::<Element>();
         el.set_placeholder_shown_state(has_placeholder && !has_value);
-        el.set_placeholder_shown_state(has_placeholder);
     }
 }
 
 impl TextControl for HTMLTextAreaElement {
     fn textinput(&self) -> &DomRefCell<TextInput<ScriptToConstellationChan>> {
         &self.textinput
     }
 
--- a/servo/components/script/dom/node.rs
+++ b/servo/components/script/dom/node.rs
@@ -1135,17 +1135,17 @@ impl LayoutNodeHelpers for LayoutDom<Nod
             return unsafe { text.upcast().data_for_layout().to_owned() };
         }
 
         if let Some(input) = self.downcast::<HTMLInputElement>() {
             return unsafe { input.value_for_layout() };
         }
 
         if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
-            return unsafe { area.get_value_for_layout() };
+            return unsafe { area.value_for_layout() };
         }
 
         panic!("not text!")
     }
 
     #[allow(unsafe_code)]
     fn selection(&self) -> Option<Range<usize>> {
         if let Some(area) = self.downcast::<HTMLTextAreaElement>() {