[Libreoffice-commits] core.git: sw/qa sw/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Thu May 9 08:05:11 UTC 2019


 sw/qa/extras/uiwriter/data/tdf125151_protected.fodt  |   11 +++++
 sw/qa/extras/uiwriter/data/tdf125151_protectedB.fodt |   14 ++++++
 sw/qa/extras/uiwriter/uiwriter.cxx                   |   40 +++++++++++++++++++
 sw/source/core/crsr/pam.cxx                          |   10 ++--
 4 files changed, 71 insertions(+), 4 deletions(-)

New commits:
commit c5c425296debb2fbd67af8ec29f87e285d08575f
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Tue May 7 09:38:19 2019 +0300
Commit:     Justin Luth <justin_luth at sil.org>
CommitDate: Thu May 9 10:03:58 2019 +0200

    tdf#125151 sw: allow protection around field marks
    
    Similar to bug 105625, the cursor should be considered outside
    of a fieldmark when it is at the start. A delete at the start would
    normally delete the entire form field, but in this case the section
    is supposed to be protected, so deleting should be forbidden.
    
    This atStart situation is already looked for when the document is
    not protected. However, when the section is already protected, then
    a different code path is followed, and there the start position
    was ignored and thus became an editable part of the page,
    allowing the user to easily delete the field by mistake.
    
    LO6.2's commit 63ec2e8d07dff652a68c9dc96859c4c61f26b9df
    accurately identfied that this is in a protected section,
    and so exposed this missing scenario.
    
    Related idea: Also added a unit test to ensure that Protect_Form
    keeps protecting the formfields as well.
    A test document in the bug report, containing a combobox and checkbox,
    confirms that this fix is good for all three types of fieldmarks.
    
    Change-Id: Ida08163f3376e55c620d6670da160832e79cd252
    Reviewed-on: https://gerrit.libreoffice.org/71927
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>

diff --git a/sw/qa/extras/uiwriter/data/tdf125151_protected.fodt b/sw/qa/extras/uiwriter/data/tdf125151_protected.fodt
new file mode 100644
index 000000000000..634f2d2231a4
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf125151_protected.fodt
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <text:section text:name="Section1" text:protected="true">
+    <text:p>Protected Section</text:p>
+    <text:p text:style-name="Standard"><field:fieldmark-start text:name="Unknown1" field:type="vnd.oasis.opendocument.field.FORMTEXT"/>Form Text<field:fieldmark-end/></text:p>
+   </text:section>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/data/tdf125151_protectedB.fodt b/sw/qa/extras/uiwriter/data/tdf125151_protectedB.fodt
new file mode 100644
index 000000000000..82e7bd2673fb
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf125151_protectedB.fodt
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+  <config:config-item-set config:name="ooo:configuration-settings">
+   <config:config-item config:name="ProtectForm" config:type="boolean">true</config:config-item>
+  </config:config-item-set>
+ </office:settings>
+ <office:body>
+  <office:text>
+    <text:p>UnProtected Section, but with Protect_Form set</text:p>
+    <text:p text:style-name="Standard"><field:fieldmark-start text:name="Unknown1" field:type="vnd.oasis.opendocument.field.FORMTEXT"/>Form Text<field:fieldmark-end/></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 2f69a53ef5ce..e3fb10cb9946 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -304,6 +304,8 @@ public:
     void testTdf107362();
     void testTdf105417();
     void testTdf105625();
+    void testTdf125151_protected();
+    void testTdf125151_protectedB();
     void testTdf106736();
     void testTdf58604();
     void testTdf112025();
@@ -510,6 +512,8 @@ public:
     CPPUNIT_TEST(testTdf107362);
     CPPUNIT_TEST(testTdf105417);
     CPPUNIT_TEST(testTdf105625);
+    CPPUNIT_TEST(testTdf125151_protected);
+    CPPUNIT_TEST(testTdf125151_protectedB);
     CPPUNIT_TEST(testTdf106736);
     CPPUNIT_TEST(testTdf58604);
     CPPUNIT_TEST(testTdf112025);
@@ -5695,6 +5699,42 @@ void SwUiWriterTest::testTdf105625()
     CPPUNIT_ASSERT_EQUAL(nMarksBefore, nMarksAfter + 1);
 }
 
+void SwUiWriterTest::testTdf125151_protected()
+{
+    // Similar to testTdf105625 except this is in a protected section,
+    // so read-only is already true when fieldmarks are considered.
+    SwDoc* pDoc = createDoc("tdf125151_protected.fodt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+    // Ensure correct initial setting
+    comphelper::ConfigurationHelper::writeDirectKey(xComponentContext,
+        "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea",
+        css::uno::Any(false), comphelper::EConfigurationModes::Standard);
+    pWrtShell->Down(/*bSelect=*/false);
+    // The cursor moved inside of the FieldMark textbox.
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Readonly 1", false, pWrtShell->HasReadonlySel());
+    // Move left to the start/definition of the textbox
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Readonly 2", true, pWrtShell->HasReadonlySel());
+}
+
+void SwUiWriterTest::testTdf125151_protectedB()
+{
+    // Similar to testTdf105625 except this is protected with the Protect_Form compat setting
+    SwDoc* pDoc = createDoc("tdf125151_protectedB.fodt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+    // Ensure correct initial setting
+    comphelper::ConfigurationHelper::writeDirectKey(xComponentContext,
+        "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea",
+        css::uno::Any(false), comphelper::EConfigurationModes::Standard);
+    // The cursor starts inside of the FieldMark textbox.
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Readonly 1", false, pWrtShell->HasReadonlySel());
+    // Move left to the start/definition of the textbox
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Readonly 2", true, pWrtShell->HasReadonlySel());
+}
+
 void SwUiWriterTest::testTdf106736()
 {
     createDoc("tdf106736-grid.odt");
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index c13b7979e501..6dcd0192df5d 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -702,9 +702,13 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
     }
 
     const SwDoc *pDoc = GetDoc();
+    // Legacy text/combo/checkbox: never return read-only when inside these form fields.
     const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
     sw::mark::IFieldmark* pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : nullptr;
     sw::mark::IFieldmark* pB = GetMark()  ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA;
+    // prevent the user from accidentally deleting the field itself when modifying the text.
+    const bool bAtStartA = (pA != nullptr) && (pA->GetMarkStart() == *GetPoint());
+    const bool bAtStartB = (pB != nullptr) && (pB->GetMarkStart() == *GetMark());
 
     if (!bRet)
     {
@@ -714,9 +718,6 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
             bRet = true;
         else
         {
-            bool bAtStartA = (pA != nullptr) && (pA->GetMarkStart() == *GetPoint());
-            bool bAtStartB = (pB != nullptr) && (pB->GetMarkStart() == *GetMark());
-
             if ((pA == pB) && (bAtStartA != bAtStartB))
                 bRet = true;
             else if (pA != pB)
@@ -734,7 +735,8 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
     }
     else
     {
-        bRet = !( pA == pB && pA != nullptr );
+        // Allow editing when the cursor/selection is fully inside of a legacy form field.
+        bRet = !( pA != nullptr && !bAtStartA && !bAtStartB && pA == pB );
     }
 
     if (!bRet)


More information about the Libreoffice-commits mailing list