[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - sw/qa sw/source

Mike Kaganski mike.kaganski at collabora.com
Sun Feb 12 21:41:16 UTC 2017


 sw/qa/extras/uiwriter/data/tdf105625.fodt               |    9 ++
 sw/qa/extras/uiwriter/data/tdf90362.fodt                |    6 +
 sw/qa/extras/uiwriter/uiwriter.cxx                      |   47 ++++++++++++-
 sw/source/core/crsr/callnk.cxx                          |    4 -
 sw/source/core/crsr/pam.cxx                             |   54 +++++-----------
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    9 ++
 sw/source/uibase/wrtsh/delete.cxx                       |   24 ++++++-
 7 files changed, 107 insertions(+), 46 deletions(-)

New commits:
commit 00e2a8b58f152cce8070311da821f3db5f45afd3
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Fri Feb 10 13:29:38 2017 +1000

    Tdf#105625: backport commits
    
    f72b866c9cf4f07fce6744fbf482c4c6488106e2
    c34fc4520dfee4ca068f249ee0756dacaa7a60cf
    af42aab836626fdf7b29921dff5d344a8b0e47c6
    c484c5532a9508606d65dfbb805163cd00178f4c
    d4036d3a89b65a4912f62e3930eb1a31cd90a16b
    
    Change-Id: I2d27a12dcc51e4213d6cf1332749d32fe1cc630f
    Reviewed-on: https://gerrit.libreoffice.org/34124
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/qa/extras/uiwriter/data/tdf105625.fodt b/sw/qa/extras/uiwriter/data/tdf105625.fodt
new file mode 100644
index 0000000..9a1d573
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf105625.fodt
@@ -0,0 +1,9 @@
+<?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:p><field:fieldmark field:type="vnd.oasis.opendocument.field.FORMCHECKBOX"/></text:p>
+   <text:p><field:fieldmark-start field:type="vnd.oasis.opendocument.field.FORMTEXT"/>Field<field:fieldmark-end/></text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/uiwriter/data/tdf90362.fodt b/sw/qa/extras/uiwriter/data/tdf90362.fodt
index bf74255..97db3d5 100644
--- a/sw/qa/extras/uiwriter/data/tdf90362.fodt
+++ b/sw/qa/extras/uiwriter/data/tdf90362.fodt
@@ -3,8 +3,10 @@
  <office:body>
   <office:text>
    <text:p>Before</text:p>
-   <text:p><field:fieldmark-start text:name="__Fieldmark__2_34585131" field:type="xxx"/><field:fieldmark-end/></text:p>
+   <text:section text:name="Protected" text:protected="true">
+    <text:p>Inside</text:p>
+   </text:section>
    <text:p>After</text:p>
   </office:text>
  </office:body>
-</office:document>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 61c2cbf..c50e26a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -205,6 +205,7 @@ public:
     void testTdf104425();
     void testTdf104814();
     void testTdf105417();
+    void testTdf105625();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -309,6 +310,7 @@ public:
     CPPUNIT_TEST(testTdf104425);
     CPPUNIT_TEST(testTdf104814);
     CPPUNIT_TEST(testTdf105417);
+    CPPUNIT_TEST(testTdf105625);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2626,20 +2628,21 @@ void SwUiWriterTest::testTdf88899()
 
 void SwUiWriterTest::testTdf90362()
 {
-    // First check if the end of the second paragraph is indeed protected.
     SwDoc* pDoc = createDoc("tdf90362.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);
+    // First check if the end of the second paragraph is indeed protected.
     pWrtShell->EndPara();
     pWrtShell->Down(/*bSelect=*/false);
     CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel());
 
     // Then enable ignoring of protected areas and make sure that this time the cursor is read-write.
-    pWrtShell->Up(/*bSelect=*/false);
-    SwViewOption aViewOptions(*pWrtShell->GetViewOptions());
-    aViewOptions.SetIgnoreProtectedArea(true);
-    pWrtShell->ApplyViewOptions(aViewOptions);
-    pWrtShell->Down(/*bSelect=*/false);
+    comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(true), comphelper::EConfigurationModes::Standard);
     CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel());
+    // Clean up, otherwise following tests will have that option set
+    comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(false), comphelper::EConfigurationModes::Standard);
 }
 
 void SwUiWriterTest::testUndoCharAttribute()
@@ -3557,6 +3560,38 @@ void SwUiWriterTest::testTdf104814()
         pEditShell->AcceptRedline(0);
 }
 
+void SwUiWriterTest::testTdf105625()
+{
+    SwDoc* pDoc = createDoc("tdf105625.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);
+    // We should be able to edit at positions adjacent to fields.
+    // Check if the start and the end of the 1st paragraph are not protected
+    // (they are adjacent to FORMCHECKBOX)
+    pWrtShell->SttPara();
+    CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel());
+    pWrtShell->EndPara();
+    CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel());
+    // 2nd paragraph - FORMTEXT
+    pWrtShell->Down(/*bSelect=*/false);
+    // Check selection across FORMTEXT field boundary - must be read-only
+    pWrtShell->SttPara();
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
+    CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel());
+    // Test deletion of whole field with single backspace
+    // Previously it only removed right boundary of FORMTEXT, or failed removal at all
+    const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
+    sal_Int32 nMarksBefore = pMarksAccess->getAllMarksCount();
+    pWrtShell->EndPara();
+    pWrtShell->DelLeft();
+    sal_Int32 nMarksAfter = pMarksAccess->getAllMarksCount();
+    CPPUNIT_ASSERT_EQUAL(nMarksBefore, nMarksAfter + 1);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/crsr/callnk.cxx b/sw/source/core/crsr/callnk.cxx
index bcdec68..0d9b31e 100644
--- a/sw/source/core/crsr/callnk.cxx
+++ b/sw/source/core/crsr/callnk.cxx
@@ -195,8 +195,8 @@ SwCallLink::~SwCallLink()
             {
                 const OUString rText = pCNd->GetTextNode()->GetText();
                 if( !nCmp ||
-                    g_pBreakIt->GetBreakIter()->getScriptType( rText, nCmp )
-                     != g_pBreakIt->GetBreakIter()->getScriptType( rText, nCmp - 1 ))
+                    g_pBreakIt->GetBreakIter()->getScriptType( rText, nContent )
+                    != g_pBreakIt->GetBreakIter()->getScriptType(rText, nAktContent))
                 {
                     rShell.CallChgLnk();
                     return;
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 65b347c..62a1a35 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -581,7 +581,7 @@ static const SwFrame* lcl_FindEditInReadonlyFrame( const SwFrame& rFrame )
 }
 
 /// is in protected section or selection surrounds something protected
-bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const
+bool SwPaM::HasReadonlySel( bool bFormView, bool /*bAnnotationMode*/ ) const
 {
     bool bRet = false;
 
@@ -692,32 +692,35 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const
         }
     }
 
-    //FIXME FieldBk
-    // TODO: Form Protection when Enhanced Fields are enabled
     const SwDoc *pDoc = GetDoc();
     const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess();
-    sw::mark::IMark* pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : nullptr;
-    sw::mark::IMark* pB = GetMark( ) ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA;
-
-    bool bUnhandledMark = false;
-    sw::mark::IFieldmark* pFieldmark = pMarksAccess->getFieldmarkFor( *GetPoint() );
-    if ( pFieldmark )
-        bUnhandledMark = pFieldmark->GetFieldname( ) == ODF_UNHANDLED;
+    sw::mark::IFieldmark* pA = GetPoint() ? pMarksAccess->getFieldmarkFor( *GetPoint( ) ) : nullptr;
+    sw::mark::IFieldmark* pB = GetMark()  ? pMarksAccess->getFieldmarkFor( *GetMark( ) ) : pA;
 
     if (!bRet)
     {
+        bool bUnhandledMark = pA && pA->GetFieldname( ) == ODF_UNHANDLED;
         // Unhandled fieldmarks case shouldn't be edited manually to avoid breaking anything
         if ( ( pA == pB ) && bUnhandledMark )
             bRet = true;
         else
         {
-            // Form protection case
-            bool bAtStartA = pA != nullptr && pA->GetMarkStart() == *GetPoint();
-            bool bAtStartB = pB != nullptr && pB->GetMarkStart() == *GetMark();
-            bRet = ( pA != pB ) || bAtStartA || bAtStartB;
-            bool bProtectForm = pDoc->GetDocumentSettingManager().get( DocumentSettingId::PROTECT_FORM );
-            if ( bProtectForm )
-                bRet |= ( pA == nullptr || pB == nullptr );
+            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)
+            {
+                // If both points are either outside or at marks edges (i.e. selection either
+                // touches fields, or fully encloses it), then don't disable editing
+                bRet = !( ( !pA || bAtStartA ) && ( !pB || bAtStartB ) );
+            }
+            if( !bRet && pDoc->GetDocumentSettingManager().get( DocumentSettingId::PROTECT_FORM ) )
+            {
+                // Form protection case
+                bRet = ( pA == nullptr ) || ( pB == nullptr ) || ( bAtStartA ) || ( bAtStartB );
+            }
         }
     }
     else
@@ -725,23 +728,6 @@ bool SwPaM::HasReadonlySel( bool bFormView, bool bAnnotationMode ) const
         bRet = !( pA == pB && pA != nullptr );
     }
 
-    // Don't allow inserting characters between the 'field mark end' and
-    // the 'comment anchor', unless the cursor is inside the annotation.
-    if (!bRet && !bAnnotationMode)
-    {
-        if (!pA && GetPoint() && GetPoint()->nNode.GetNode().IsTextNode() && GetPoint()->nContent.GetIndex() > 0)
-        {
-            // getFieldmarkFor() searches for >= start and < end, so check for
-            // the previous character, to also get the fieldmark, if we're
-            // exactly at the end.
-            SwPosition aPrevChar(*GetPoint());
-            --aPrevChar.nContent;
-            pFieldmark = pMarksAccess->getFieldmarkFor(aPrevChar);
-            if (pFieldmark && pFieldmark->GetMarkEnd() == *GetPoint())
-                bRet = true;
-        }
-    }
-
     return bRet;
 }
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 33533cf..e919df1 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -265,6 +265,15 @@ namespace
                 lcl_SetCpyPos(pMark->GetOtherMarkPos(), rStt, *pCpyStt, *aTmpPam.GetMark(), nDelCount);
             }
 
+            const IDocumentMarkAccess::MarkType aMarkType = IDocumentMarkAccess::GetType(*pMark);
+            if (aMarkType == IDocumentMarkAccess::MarkType::CHECKBOX_FIELDMARK)
+            {
+                // Node's CopyText() copies also dummy characters, which need to be removed
+                // (they will be added later in MarkBase::InitDoc inside IDocumentMarkAccess::makeMark)
+                // CHECKBOX_FIELDMARK doesn't contain any other data in its range, so just clear it
+                pDestDoc->getIDocumentContentOperations().DeleteRange(aTmpPam);
+            }
+
             ::sw::mark::IMark* const pNewMark = pDestDoc->getIDocumentMarkAccess()->makeMark(
                 aTmpPam,
                 pMark->GetName(),
diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx
index 725d642..1dd0c1b 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -213,8 +213,19 @@ long SwWrtShell::DelLeft()
     }
     else
     {
+        // If we are just to the right to a fieldmark, then remove it completely
+        const SwPosition* pCurPos = GetCursor()->GetPoint();
+        SwPosition aPrevChar(*pCurPos);
+        --aPrevChar.nContent;
+        sw::mark::IFieldmark* pFm = getIDocumentMarkAccess()->getFieldmarkFor(aPrevChar);
+        if (pFm && pFm->GetMarkEnd() == *pCurPos)
+        {
+            getIDocumentMarkAccess()->deleteMark(pFm);
+            return 1;
+        }
+
         OpenMark();
-        SwCursorShell::Left(1,CRSR_SKIP_CHARS);
+        SwCursorShell::Left(1, CRSR_SKIP_CHARS);
     }
     long nRet = Delete();
     if( !nRet && bSwap )
@@ -333,10 +344,19 @@ long SwWrtShell::DelRight()
                 // restore cursor
                 SwCursorShell::Pop( false );
             }
+
+            // If we are just ahead of a fieldmark, then remove it completely
+            sw::mark::IFieldmark* pFm = GetCurrentFieldmark();
+            if (pFm && pFm->GetMarkStart() == *GetCursor()->GetPoint())
+            {
+                getIDocumentMarkAccess()->deleteMark(pFm);
+                nRet = 1;
+                break;
+            }
         }
 
         OpenMark();
-        SwCursorShell::Right(1,CRSR_SKIP_CELLS);
+        SwCursorShell::Right(1, CRSR_SKIP_CELLS);
         nRet = Delete();
         CloseMark( 0 != nRet );
         break;


More information about the Libreoffice-commits mailing list