From 8e8857351fc059a792e9693f488dfd5d26be8d9c Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Fri, 16 Apr 1999 04:25:17 +0000 Subject: [PATCH] added zooming front end. git-svn-id: svn://10.0.0.236/trunk@27819 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 53 +++++++++++++++++++ mozilla/webshell/public/nsIWebShell.h | 8 ++- mozilla/webshell/src/nsWebShell.cpp | 53 +++++++++++++++++++ .../webshell/tests/viewer/nsBrowserWindow.cpp | 11 ++++ mozilla/webshell/tests/viewer/resources.h | 10 ++++ 5 files changed, 134 insertions(+), 1 deletion(-) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 3a13414834d..9ca8bf2d0e2 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -185,6 +185,8 @@ public: NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE); NS_IMETHOD GetIsFrame(PRBool& aIsFrame); NS_IMETHOD SetIsFrame(PRBool aIsFrame); + NS_IMETHOD SetZoom(float aZoom); + NS_IMETHOD GetZoom(float *aZoom); // Document load api's NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult); @@ -365,6 +367,8 @@ protected: nsURLReloadType aType, const PRUint32 aLocalIP); + float mZoom; + static nsIPluginHost *mPluginHost; static nsIPluginManager *mPluginManager; static PRUint32 mPluginInitCnt; @@ -1279,6 +1283,55 @@ nsWebShell::SetIsFrame(PRBool aIsFrame) return NS_OK; } +NS_IMETHODIMP +nsWebShell::SetZoom(float aZoom) +{ + mZoom = aZoom; + + if (mDeviceContext) + mDeviceContext->SetZoom(mZoom); + + if (mContentViewer) { + nsIDocumentViewer* docv = nsnull; + mContentViewer->QueryInterface(kIDocumentViewerIID, (void**) &docv); + if (nsnull != docv) { + nsIPresContext* cx = nsnull; + docv->GetPresContext(cx); + if (nsnull != cx) { + nsIPresShell *shell = nsnull; + cx->GetShell(&shell); + if (nsnull != shell) { + nsIViewManager *vm = nsnull; + shell->GetViewManager(&vm); + if (nsnull != vm) { + nsIView *rootview = nsnull; + nsIScrollableView *sv = nsnull; + vm->GetRootScrollableView(&sv); + if (nsnull != sv) + sv->ComputeScrollOffsets(); + vm->GetRootView(rootview); + if (nsnull != rootview) + vm->UpdateView(rootview, nsnull, 0); + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } + NS_RELEASE(cx); + } + NS_RELEASE(docv); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWebShell::GetZoom(float *aZoom) +{ + *aZoom = mZoom; + return NS_OK; +} + /** * Document Load methods diff --git a/mozilla/webshell/public/nsIWebShell.h b/mozilla/webshell/public/nsIWebShell.h index e582820b70c..1e3685f7cda 100644 --- a/mozilla/webshell/public/nsIWebShell.h +++ b/mozilla/webshell/public/nsIWebShell.h @@ -339,11 +339,17 @@ public: NS_IMETHOD GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet) = 0; NS_IMETHOD SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet) = 0; + /** + * Set/Get the document scale factor + */ + + NS_IMETHOD SetZoom(float aZoom) = 0; + NS_IMETHOD GetZoom(float *aZoom) = 0; + /** * Finds text in content */ NS_IMETHOD FindNext(const PRUnichar * aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0; - }; extern "C" NS_WEB nsresult diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 3a13414834d..9ca8bf2d0e2 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -185,6 +185,8 @@ public: NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE); NS_IMETHOD GetIsFrame(PRBool& aIsFrame); NS_IMETHOD SetIsFrame(PRBool aIsFrame); + NS_IMETHOD SetZoom(float aZoom); + NS_IMETHOD GetZoom(float *aZoom); // Document load api's NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult); @@ -365,6 +367,8 @@ protected: nsURLReloadType aType, const PRUint32 aLocalIP); + float mZoom; + static nsIPluginHost *mPluginHost; static nsIPluginManager *mPluginManager; static PRUint32 mPluginInitCnt; @@ -1279,6 +1283,55 @@ nsWebShell::SetIsFrame(PRBool aIsFrame) return NS_OK; } +NS_IMETHODIMP +nsWebShell::SetZoom(float aZoom) +{ + mZoom = aZoom; + + if (mDeviceContext) + mDeviceContext->SetZoom(mZoom); + + if (mContentViewer) { + nsIDocumentViewer* docv = nsnull; + mContentViewer->QueryInterface(kIDocumentViewerIID, (void**) &docv); + if (nsnull != docv) { + nsIPresContext* cx = nsnull; + docv->GetPresContext(cx); + if (nsnull != cx) { + nsIPresShell *shell = nsnull; + cx->GetShell(&shell); + if (nsnull != shell) { + nsIViewManager *vm = nsnull; + shell->GetViewManager(&vm); + if (nsnull != vm) { + nsIView *rootview = nsnull; + nsIScrollableView *sv = nsnull; + vm->GetRootScrollableView(&sv); + if (nsnull != sv) + sv->ComputeScrollOffsets(); + vm->GetRootView(rootview); + if (nsnull != rootview) + vm->UpdateView(rootview, nsnull, 0); + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } + NS_RELEASE(cx); + } + NS_RELEASE(docv); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWebShell::GetZoom(float *aZoom) +{ + *aZoom = mZoom; + return NS_OK; +} + /** * Document Load methods diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index 9af405dad2c..c262f5b9b55 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -611,6 +611,17 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) DoImageInspector(); break; + case VIEWER_ZOOM_500: + case VIEWER_ZOOM_300: + case VIEWER_ZOOM_200: + case VIEWER_ZOOM_100: + case VIEWER_ZOOM_070: + case VIEWER_ZOOM_050: + case VIEWER_ZOOM_030: + case VIEWER_ZOOM_020: + mWebShell->SetZoom((aID - VIEWER_ZOOM_BASE) / 10.0f); + break; + #ifdef ClientWallet case PRVCY_PREFILL: case PRVCY_QPREFILL: diff --git a/mozilla/webshell/tests/viewer/resources.h b/mozilla/webshell/tests/viewer/resources.h index a2a0eb4652f..6db2a4a6cfc 100644 --- a/mozilla/webshell/tests/viewer/resources.h +++ b/mozilla/webshell/tests/viewer/resources.h @@ -86,6 +86,16 @@ #define VIEWER_EDIT_JOIN_CELL_RIGHT 40558 #define VIEWER_EDIT_JOIN_CELL_BELOW 40559 +#define VIEWER_ZOOM_BASE 40600 +#define VIEWER_ZOOM_500 40650 +#define VIEWER_ZOOM_300 40630 +#define VIEWER_ZOOM_200 40620 +#define VIEWER_ZOOM_100 40610 +#define VIEWER_ZOOM_070 40607 +#define VIEWER_ZOOM_050 40605 +#define VIEWER_ZOOM_030 40603 +#define VIEWER_ZOOM_020 40602 + // Note: must be in ascending sequential order #define VIEWER_ONE_COLUMN 40050 #define VIEWER_TWO_COLUMN 40051