diff options
author | Mihai Varga <mihai.varga@collabora.com> | 2015-11-06 14:34:28 +0200 |
---|---|---|
committer | Mihai Varga <mihai.mv13@gmail.com> | 2015-11-13 09:55:19 +0200 |
commit | 96cd2abd748ed24e5aba50cc4c300cf06e512db3 (patch) | |
tree | a1e6636aef83f49a1d9ee81c87d0a9f71c88b5d2 | |
parent | 249f8b1cc9897ac9666dd5c69dc22fae7586c207 (diff) |
LOK: setClientZoom() - sets the client zoom level
We need to know the client's view level to correctly handle the mouse
events in calc. PaintTile() set a zoom level that corresponds to the
requested tiles and previously postMouseEvent would call SetZoom(1,1).
Now we can make use of knowing the client's view level and call
SetZoom() with the correct parameters
Change-Id: I34b5afcdcc06a671a8ac92c03e87404e42adf4cd
Conflicts:
sc/source/ui/unoobj/docuno.cxx
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/Document.java | 2 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/LOKitThread.java | 13 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/LOKitTileProvider.java | 11 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/TileProvider.java | 4 | ||||
-rw-r--r-- | android/source/src/java/org/mozilla/gecko/gfx/ImmutableViewportMetrics.java | 4 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 20 | ||||
-rw-r--r-- | desktop/source/lib/lokandroid.cxx | 8 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 7 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 17 | ||||
-rw-r--r-- | include/vcl/ITiledRenderable.hxx | 18 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 38 | ||||
-rw-r--r-- | libreofficekit/source/gtk/tilebuffer.hxx | 11 | ||||
-rw-r--r-- | sc/inc/docuno.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 18 |
14 files changed, 158 insertions, 16 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java index 4cc4ba345c04..dcc315faca4c 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/Document.java +++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java @@ -143,6 +143,8 @@ public class Document { private native int getDocumentTypeNative(); + public native void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight); + private native void saveAs(String url, String format, String options); private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight); diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java index a8f4d303293c..978056dab1d7 100644 --- a/android/source/src/java/org/libreoffice/LOKitThread.java +++ b/android/source/src/java/org/libreoffice/LOKitThread.java @@ -299,17 +299,18 @@ public class LOKitThread extends Thread { // to handle hyperlinks, enable single tap even in the Viewer boolean editing = LOKitShell.isEditingEnabled(); + float zoomFactor = mViewportMetrics.getZoomFactor(); if (touchType.equals("LongPress") && editing) { mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION); - mTileProvider.mouseButtonDown(documentCoordinate, 1); - mTileProvider.mouseButtonUp(documentCoordinate, 1); - mTileProvider.mouseButtonDown(documentCoordinate, 2); - mTileProvider.mouseButtonUp(documentCoordinate, 2); + mTileProvider.mouseButtonDown(documentCoordinate, 1, zoomFactor); + mTileProvider.mouseButtonUp(documentCoordinate, 1, zoomFactor); + mTileProvider.mouseButtonDown(documentCoordinate, 2, zoomFactor); + mTileProvider.mouseButtonUp(documentCoordinate, 2, zoomFactor); } else if (touchType.equals("SingleTap")) { mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION); - mTileProvider.mouseButtonDown(documentCoordinate, 1); - mTileProvider.mouseButtonUp(documentCoordinate, 1); + mTileProvider.mouseButtonDown(documentCoordinate, 1, zoomFactor); + mTileProvider.mouseButtonUp(documentCoordinate, 1, zoomFactor); } else if (touchType.equals("GraphicSelectionStart") && editing) { mTileProvider.setGraphicSelectionStart(documentCoordinate); } else if (touchType.equals("GraphicSelectionEnd") && editing) { diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index f859b7a1bc62..b70e8524ecc3 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -397,10 +397,11 @@ public class LOKitTileProvider implements TileProvider { } } - private void mouseButton(int type, PointF inDocument, int numberOfClicks) { + private void mouseButton(int type, PointF inDocument, int numberOfClicks, float zoomFactor) { int x = (int) pixelToTwip(inDocument.x, mDPI); int y = (int) pixelToTwip(inDocument.y, mDPI); + mDocument.setClientZoom(TILE_SIZE, TILE_SIZE, (int) (mTileWidth / zoomFactor), (int) (mTileHeight / zoomFactor)); mDocument.postMouseEvent(type, x, y, numberOfClicks, Document.MOUSE_BUTTON_LEFT, Document.KEYBOARD_MODIFIER_NONE); } @@ -408,16 +409,16 @@ public class LOKitTileProvider implements TileProvider { * @see TileProvider#mouseButtonDown(android.graphics.PointF, int) */ @Override - public void mouseButtonDown(PointF documentCoordinate, int numberOfClicks) { - mouseButton(Document.MOUSE_EVENT_BUTTON_DOWN, documentCoordinate, numberOfClicks); + public void mouseButtonDown(PointF documentCoordinate, int numberOfClicks, float zoomFactor) { + mouseButton(Document.MOUSE_EVENT_BUTTON_DOWN, documentCoordinate, numberOfClicks, zoomFactor); } /** * @see TileProvider#mouseButtonUp(android.graphics.PointF, int) */ @Override - public void mouseButtonUp(PointF documentCoordinate, int numberOfClicks) { - mouseButton(Document.MOUSE_EVENT_BUTTON_UP, documentCoordinate, numberOfClicks); + public void mouseButtonUp(PointF documentCoordinate, int numberOfClicks, float zoomFactor) { + mouseButton(Document.MOUSE_EVENT_BUTTON_UP, documentCoordinate, numberOfClicks, zoomFactor); } @Override diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java index 3104172ef5cf..0ab5a1f641c9 100644 --- a/android/source/src/java/org/libreoffice/TileProvider.java +++ b/android/source/src/java/org/libreoffice/TileProvider.java @@ -88,7 +88,7 @@ public interface TileProvider { * @param documentCoordinate - coordinate relative to the document where the mouse button should be triggered * @param numberOfClicks - number of clicks (1 - single click, 2 - double click) */ - void mouseButtonDown(PointF documentCoordinate, int numberOfClicks); + void mouseButtonDown(PointF documentCoordinate, int numberOfClicks, float zoomFactor); /** @@ -107,7 +107,7 @@ public interface TileProvider { * @param documentCoordinate - coordinate relative to the document where the mouse button should be triggered * @param numberOfClicks - number of clicks (1 - single click, 2 - double click) */ - void mouseButtonUp(PointF documentCoordinate, int numberOfClicks); + void mouseButtonUp(PointF documentCoordinate, int numberOfClicks, float zoomFactor); /** * Post a UNO command to LOK. diff --git a/android/source/src/java/org/mozilla/gecko/gfx/ImmutableViewportMetrics.java b/android/source/src/java/org/mozilla/gecko/gfx/ImmutableViewportMetrics.java index 35b417593acf..f90580fbee8c 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/ImmutableViewportMetrics.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/ImmutableViewportMetrics.java @@ -106,6 +106,10 @@ public class ImmutableViewportMetrics { return new RectF(cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom); } + public float getZoomFactor() { + return zoomFactor; + } + /* * Returns the viewport metrics that represent a linear transition between "this" and "to" at * time "t", which is on the scale [0, 1). This function interpolates all values stored in diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index e33544abec90..94b81e049cd2 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -318,7 +318,11 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis, int nY); static void doc_resetSelection (LibreOfficeKitDocument* pThis); static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand); - +static void doc_setClientZoom(LibreOfficeKitDocument* pThis, + int nTilePixelWidth, + int nTilePixelHeight, + int nTileTwipWidth, + int nTileTwipHeight); static int doc_createView(LibreOfficeKitDocument* pThis); static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId); static void doc_setView(LibreOfficeKitDocument* pThis, int nId); @@ -358,6 +362,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection; m_pDocumentClass->resetSelection = doc_resetSelection; m_pDocumentClass->getCommandValues = doc_getCommandValues; + m_pDocumentClass->setClientZoom = doc_setClientZoom; m_pDocumentClass->createView = doc_createView; m_pDocumentClass->destroyView = doc_destroyView; @@ -1470,6 +1475,19 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo } } +static void doc_setClientZoom(LibreOfficeKitDocument* pThis, int nTilePixelWidth, int nTilePixelHeight, + int nTileTwipWidth, int nTileTwipHeight) +{ + ITiledRenderable* pDoc = getTiledRenderable(pThis); + if (!pDoc) + { + gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering"; + return; + } + + pDoc->setClientZoom(nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight); +} + static int doc_createView(LibreOfficeKitDocument* /*pThis*/) { SolarMutexGuard aGuard; diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx index 017ab8a9cdaf..0c360d3c2b9c 100644 --- a/desktop/source/lib/lokandroid.cxx +++ b/desktop/source/lib/lokandroid.cxx @@ -358,4 +358,12 @@ extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getC return pEnv->NewStringUTF(pValue); } + +extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setClientZoom + (JNIEnv* pEnv, jobject aObject, jint nTilePixelWidth, jint nTilePixelHeight, jint nTileTwipWidth, jint nTileTwipHeight) +{ + LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject); + pDocument->pClass->setClientZoom(pDocument, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight); + +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index c887f5f64b8a..03210376c61e 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -181,6 +181,13 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::getCommandValues(). char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand); + /// @see lok::Document::setClientZoom(). + void (*setClientZoom) (LibreOfficeKitDocument* pThis, + int nTilePixelWidth, + int nTilePixelHeight, + int nTileTwipWidth, + int nTileTwipHeight); + /// @see lok::Document::createView(). int (*createView) (LibreOfficeKitDocument* pThis); /// @see lok::Document::destroyView(). diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index fe8c4d19aa29..d21abddd0448 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -294,6 +294,23 @@ public: } /** + * Save the client's view so that we can compute the right zoom level + * for the mouse events. This only affects CALC. + * @param nTilePixelWidth - tile width in pixels + * @param nTilePixelHeight - tile height in pixels + * @param nTileTwipWidth - tile width in twips + * @param nTileTwipHeight - tile height in twips + */ + inline void setClientZoom( + int nTilePixelWidth, + int nTilePixelHeight, + int nTileTwipWidth, + int nTileTwipHeight) + { + mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight); + } + + /** * Create a new view for an existing document. * By default a loaded document has 1 view. * @return the ID of the new view. diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index 99c31b8da9a7..e1cdf83ac439 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -23,6 +23,9 @@ namespace vcl class VCL_DLLPUBLIC ITiledRenderable { +protected: + int nTilePixelWidth, nTilePixelHeight; + int nTileTwipWidth, nTileTwipHeight; public: virtual ~ITiledRenderable(); @@ -180,6 +183,21 @@ public: /// If the current contents of the clipboard is something we can paste. virtual bool isMimeTypeSupported() = 0; + + /** + * Save the client's view so that we can compute the right zoom level + * for the mouse events. + * @param nTilePixelWidth - tile width in pixels + * @param nTilePixelHeight - tile height in pixels + * @param nTileTwipWidth - tile width in twips + * @param nTileTwipHeight - tile height in twips + */ + virtual void setClientZoom(int /*nTilePixelWidth*/, + int /*nTilePixelHeight*/, + int /*nTileTwipWidth*/, + int /*nTileTwipHeight*/) + { + } }; } // namespace vcl diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 550a9221744e..f52ba6176b31 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1506,6 +1506,23 @@ setGraphicSelectionInThread(gpointer data) } static void +setClientZoomInThread(gpointer data) +{ + GTask* task = G_TASK(data); + LOKDocView* pDocView = LOK_DOC_VIEW(g_task_get_source_object(task)); + LOKDocViewPrivate& priv = getPrivate(pDocView); + LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task)); + + if (!priv->m_pDocument) + return; + priv->m_pDocument->pClass->setClientZoom(priv->m_pDocument, + pLOEvent->m_nTilePixelWidth, + pLOEvent->m_nTilePixelHeight, + pLOEvent->m_nTileTwipWidth, + pLOEvent->m_nTileTwipHeight); +} + +static void postMouseEventInThread(gpointer data) { GTask* task = G_TASK(data); @@ -1721,6 +1738,9 @@ lokThreadFunc(gpointer data, gpointer /*user_data*/) case LOK_SET_GRAPHIC_SELECTION: setGraphicSelectionInThread(task); break; + case LOK_SET_CLIENT_ZOOM: + setClientZoomInThread(task); + break; } g_object_unref(task); @@ -2301,6 +2321,7 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom) { LOKDocViewPrivate& priv = getPrivate(pDocView); + GError* error = NULL; priv->m_fZoom = fZoom; long nDocumentWidthPixels = twipToPixel(priv->m_nDocumentWidthTwips, fZoom); @@ -2313,6 +2334,23 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom) gtk_widget_set_size_request(GTK_WIDGET(pDocView), nDocumentWidthPixels, nDocumentHeightPixels); + + // Update the client's view size + GTask* task = g_task_new(pDocView, NULL, NULL, NULL); + LOEvent* pLOEvent = new LOEvent(LOK_SET_CLIENT_ZOOM); + pLOEvent->m_nTilePixelWidth = nTileSizePixels; + pLOEvent->m_nTilePixelHeight = nTileSizePixels; + pLOEvent->m_nTileTwipWidth = pixelToTwip(nTileSizePixels, fZoom); + pLOEvent->m_nTileTwipHeight = pixelToTwip(nTileSizePixels, fZoom); + g_task_set_task_data(task, pLOEvent, LOEvent::destroy); + + g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error); + if (error != NULL) + { + g_warning("Unable to call LOK_SET_CLIENT_ZOOM: %s", error->message); + g_clear_error(&error); + } + g_object_unref(task); } SAL_DLLPUBLIC_EXPORT float diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx index 7d7160e0450e..c8f401d38c0a 100644 --- a/libreofficekit/source/gtk/tilebuffer.hxx +++ b/libreofficekit/source/gtk/tilebuffer.hxx @@ -157,7 +157,8 @@ enum LOK_POST_KEY, LOK_PAINT_TILE, LOK_POST_MOUSE_EVENT, - LOK_SET_GRAPHIC_SELECTION + LOK_SET_GRAPHIC_SELECTION, + LOK_SET_CLIENT_ZOOM }; enum @@ -231,6 +232,14 @@ struct LOEvent int m_nSetGraphicSelectionY; ///@} + /// @name setClientView parameters + ///@{ + int m_nTilePixelWidth; + int m_nTilePixelHeight; + int m_nTileTwipWidth; + int m_nTileTwipHeight; + ///@} + /// Constructor to instantiate an object of type `type`. LOEvent(int type) : m_nType(type) diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index c208db36ec34..4c79af8343b5 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -405,6 +405,9 @@ public: /// @see vcl::ITiledRenderable::isMimeTypeSupported(). virtual bool isMimeTypeSupported() override; + /// @see vcl::ITiledRenderable::setClientZoom(). + virtual void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight) override; + /// @see vcl::ITiledRenderable::getRowColumnHeaders(). virtual OUString getRowColumnHeaders(const Rectangle& rRectangle) override; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index b3f80b28f2d2..01ca52d393cb 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -604,7 +604,8 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt return; // update the aLogicMode in ScViewData to something predictable - pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true); + pViewData->SetZoom(Fraction(nTilePixelWidth * TWIPS_PER_PIXEL, nTileTwipWidth), + Fraction(nTilePixelHeight * TWIPS_PER_PIXEL, nTileTwipHeight), true); // Calc operates in pixels... MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount, @@ -872,6 +873,14 @@ bool ScModelObj::isMimeTypeSupported() return EditEngine::HasValidData(aDataHelper.GetTransferable()); } +void ScModelObj::setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int nTileTwipWidth_, int nTileTwipHeight_) +{ + nTilePixelWidth = nTilePixelWidth_; + nTilePixelHeight = nTilePixelHeight_; + nTileTwipWidth = nTileTwipWidth_; + nTileTwipHeight = nTileTwipHeight_; +} + OUString ScModelObj::getRowColumnHeaders(const Rectangle& rRectangle) { ScViewData* pViewData = ScDocShell::GetViewData(); @@ -930,6 +939,13 @@ void ScModelObj::initializeForTiledRendering() // tdf#93154: in tiled rendering LO doesn't always detect changes SvtMiscOptions aMiscOpt; aMiscOpt.SetSaveAlwaysAllowed(true); + + // default tile size in pixels + nTilePixelWidth = 256; + nTilePixelHeight = 256; + // the default zoom level will be 1 + nTileTwipWidth = nTilePixelWidth * TWIPS_PER_PIXEL; + nTileTwipHeight = nTilePixelHeight * TWIPS_PER_PIXEL; } uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType ) |