From 3d1abdc603c6323e2c9bd038638d2766a9b3f44c Mon Sep 17 00:00:00 2001 From: "erik%netscape.com" Date: Sun, 2 Apr 2000 21:52:17 +0000 Subject: [PATCH] bug 30022; added Set/Get TextZoom for enlarging/reducing fonts only; also factored some code to reduce duplication; r=pierre,troy --- content/base/src/nsDocumentViewer.cpp | 216 +++++++++++++------------- layout/base/nsDocumentViewer.cpp | 216 +++++++++++++------------- layout/base/nsPresContext.cpp | 23 ++- layout/base/nsPresContext.h | 5 + layout/base/public/nsIPresContext.h | 5 + layout/base/public/nsPresContext.h | 5 + layout/base/src/nsDocumentViewer.cpp | 216 +++++++++++++------------- layout/base/src/nsPresContext.cpp | 23 ++- layout/base/src/nsPresContext.h | 1 + 9 files changed, 364 insertions(+), 346 deletions(-) diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index e457190e3a1..e59379d497a 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -37,6 +37,7 @@ #include "nsIPresShell.h" #include "nsIStyleSet.h" #include "nsIStyleSheet.h" +#include "nsIStyleContext.h" #include "nsIFrame.h" #include "nsIScriptGlobalObjectOwner.h" @@ -180,6 +181,10 @@ public: // nsIMarkupDocumentViewer NS_DECL_NSIMARKUPDOCUMENTVIEWER + typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, + void* aClosure); + nsresult CallChildren(CallChildFunc aFunc, void* aClosure); + // nsIImageGroupObserver interface virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -1402,6 +1407,76 @@ NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) return NS_OK; } +nsresult +DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) +{ + nsCOMPtr docShellNode(do_QueryInterface(mContainer)); + if (docShellNode) + { + PRInt32 i; + PRInt32 n; + docShellNode->GetChildCount(&n); + for (i=0; i < n; i++) + { + nsCOMPtr child; + docShellNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + NS_ASSERTION(childAsShell, "null child in docshell"); + if (childAsShell) + { + nsCOMPtr childCV; + childAsShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + (*aFunc)(markupCV, aClosure); + } + } + } + } + } + return NS_OK; +} + +struct TextZoomInfo +{ + float mTextZoom; +}; + +static void +SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure; + aChild->SetTextZoom(textZoomInfo->mTextZoom); +} + +NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) +{ + if (mDeviceContext) { + mDeviceContext->SetTextZoom(aTextZoom); + if (mPresContext) { + mPresContext->RemapStyleAndReflow(); + } + } + + // now set the text zoom on all children of mContainer + struct TextZoomInfo textZoomInfo = { aTextZoom }; + return CallChildren(SetChildTextZoom, &textZoomInfo); +} + +NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) +{ + NS_ENSURE_ARG_POINTER(aTextZoom); + + if (mDeviceContext) { + return mDeviceContext->GetTextZoom(*aTextZoom); + } + + *aTextZoom = 1.0; + return NS_OK; +} + // XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aDefaultCharacterSet) @@ -1434,37 +1509,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCha return NS_OK; } +static void +SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetDefaultCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) { mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet // now set the default char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildDefaultCharacterSet, + (void*) aDefaultCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1484,37 +1540,17 @@ NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharact return NS_OK; } +static void +SetChildForceCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetForceCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) { mForceCharacterSet = aForceCharacterSet; // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetForceCharacterSet(aForceCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1542,71 +1578,31 @@ NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharac return NS_OK; } +static void +SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSetSource((PRInt32) aClosure); +} NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) { mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); - } - } - } - } - } - return NS_OK; + // now set the hint char set source on all children of mContainer + return CallChildren(SetChildHintCharacterSetSource, + (void*) aHintCharacterSetSource); +} + +static void +SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSet((PRUnichar*) aClosure); } NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) { mHintCharset = aHintCharacterSet; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSet(aHintCharacterSet); - } - } - } - } - } - return NS_OK; + // now set the hint char set on all children of mContainer + return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); } NS_IMETHODIMP DocumentViewerImpl::SizeToContent() diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index e457190e3a1..e59379d497a 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -37,6 +37,7 @@ #include "nsIPresShell.h" #include "nsIStyleSet.h" #include "nsIStyleSheet.h" +#include "nsIStyleContext.h" #include "nsIFrame.h" #include "nsIScriptGlobalObjectOwner.h" @@ -180,6 +181,10 @@ public: // nsIMarkupDocumentViewer NS_DECL_NSIMARKUPDOCUMENTVIEWER + typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, + void* aClosure); + nsresult CallChildren(CallChildFunc aFunc, void* aClosure); + // nsIImageGroupObserver interface virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -1402,6 +1407,76 @@ NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) return NS_OK; } +nsresult +DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) +{ + nsCOMPtr docShellNode(do_QueryInterface(mContainer)); + if (docShellNode) + { + PRInt32 i; + PRInt32 n; + docShellNode->GetChildCount(&n); + for (i=0; i < n; i++) + { + nsCOMPtr child; + docShellNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + NS_ASSERTION(childAsShell, "null child in docshell"); + if (childAsShell) + { + nsCOMPtr childCV; + childAsShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + (*aFunc)(markupCV, aClosure); + } + } + } + } + } + return NS_OK; +} + +struct TextZoomInfo +{ + float mTextZoom; +}; + +static void +SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure; + aChild->SetTextZoom(textZoomInfo->mTextZoom); +} + +NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) +{ + if (mDeviceContext) { + mDeviceContext->SetTextZoom(aTextZoom); + if (mPresContext) { + mPresContext->RemapStyleAndReflow(); + } + } + + // now set the text zoom on all children of mContainer + struct TextZoomInfo textZoomInfo = { aTextZoom }; + return CallChildren(SetChildTextZoom, &textZoomInfo); +} + +NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) +{ + NS_ENSURE_ARG_POINTER(aTextZoom); + + if (mDeviceContext) { + return mDeviceContext->GetTextZoom(*aTextZoom); + } + + *aTextZoom = 1.0; + return NS_OK; +} + // XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aDefaultCharacterSet) @@ -1434,37 +1509,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCha return NS_OK; } +static void +SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetDefaultCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) { mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet // now set the default char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildDefaultCharacterSet, + (void*) aDefaultCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1484,37 +1540,17 @@ NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharact return NS_OK; } +static void +SetChildForceCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetForceCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) { mForceCharacterSet = aForceCharacterSet; // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetForceCharacterSet(aForceCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1542,71 +1578,31 @@ NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharac return NS_OK; } +static void +SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSetSource((PRInt32) aClosure); +} NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) { mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); - } - } - } - } - } - return NS_OK; + // now set the hint char set source on all children of mContainer + return CallChildren(SetChildHintCharacterSetSource, + (void*) aHintCharacterSetSource); +} + +static void +SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSet((PRUnichar*) aClosure); } NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) { mHintCharset = aHintCharacterSet; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSet(aHintCharacterSet); - } - } - } - } - } - return NS_OK; + // now set the hint char set on all children of mContainer + return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); } NS_IMETHODIMP DocumentViewerImpl::SizeToContent() diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 9c0fe66fc7b..d668bb8bb6d 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -255,15 +255,9 @@ nsPresContext::GetUserPreferences() GetFontPreferences(); } -void -nsPresContext::PreferenceChanged(const char* aPrefName) +NS_IMETHODIMP +nsPresContext::RemapStyleAndReflow() { - // Initialize our state from the user preferences - GetUserPreferences(); - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - } - if (mShell) { // Have the root frame's style context remap its style based on the // user preferences @@ -284,6 +278,19 @@ nsPresContext::PreferenceChanged(const char* aPrefName) mShell->StyleChangeReflow(); } } + + return NS_OK; +} + +void +nsPresContext::PreferenceChanged(const char* aPrefName) +{ + // Initialize our state from the user preferences + GetUserPreferences(); + if (mDeviceContext) { + mDeviceContext->FlushFontCache(); + RemapStyleAndReflow(); + } } NS_IMETHODIMP diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 034495da8c9..908b4f591e4 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -136,6 +136,11 @@ public: */ NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; + /** + * Remap style from the root frame downwards, and reflow. + */ + NS_IMETHOD RemapStyleAndReflow(void) = 0; + /** * Resolve style for the given piece of content that will be a child * of the aParentContext. Don't use this for pseudo frames. diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index 034495da8c9..908b4f591e4 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -136,6 +136,11 @@ public: */ NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; + /** + * Remap style from the root frame downwards, and reflow. + */ + NS_IMETHOD RemapStyleAndReflow(void) = 0; + /** * Resolve style for the given piece of content that will be a child * of the aParentContext. Don't use this for pseudo frames. diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index 034495da8c9..908b4f591e4 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -136,6 +136,11 @@ public: */ NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; + /** + * Remap style from the root frame downwards, and reflow. + */ + NS_IMETHOD RemapStyleAndReflow(void) = 0; + /** * Resolve style for the given piece of content that will be a child * of the aParentContext. Don't use this for pseudo frames. diff --git a/layout/base/src/nsDocumentViewer.cpp b/layout/base/src/nsDocumentViewer.cpp index e457190e3a1..e59379d497a 100644 --- a/layout/base/src/nsDocumentViewer.cpp +++ b/layout/base/src/nsDocumentViewer.cpp @@ -37,6 +37,7 @@ #include "nsIPresShell.h" #include "nsIStyleSet.h" #include "nsIStyleSheet.h" +#include "nsIStyleContext.h" #include "nsIFrame.h" #include "nsIScriptGlobalObjectOwner.h" @@ -180,6 +181,10 @@ public: // nsIMarkupDocumentViewer NS_DECL_NSIMARKUPDOCUMENTVIEWER + typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, + void* aClosure); + nsresult CallChildren(CallChildFunc aFunc, void* aClosure); + // nsIImageGroupObserver interface virtual void Notify(nsIImageGroup *aImageGroup, nsImageGroupNotification aNotificationType); @@ -1402,6 +1407,76 @@ NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) return NS_OK; } +nsresult +DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) +{ + nsCOMPtr docShellNode(do_QueryInterface(mContainer)); + if (docShellNode) + { + PRInt32 i; + PRInt32 n; + docShellNode->GetChildCount(&n); + for (i=0; i < n; i++) + { + nsCOMPtr child; + docShellNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsShell(do_QueryInterface(child)); + NS_ASSERTION(childAsShell, "null child in docshell"); + if (childAsShell) + { + nsCOMPtr childCV; + childAsShell->GetContentViewer(getter_AddRefs(childCV)); + if (childCV) + { + nsCOMPtr markupCV = do_QueryInterface(childCV); + if (markupCV) { + (*aFunc)(markupCV, aClosure); + } + } + } + } + } + return NS_OK; +} + +struct TextZoomInfo +{ + float mTextZoom; +}; + +static void +SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure; + aChild->SetTextZoom(textZoomInfo->mTextZoom); +} + +NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) +{ + if (mDeviceContext) { + mDeviceContext->SetTextZoom(aTextZoom); + if (mPresContext) { + mPresContext->RemapStyleAndReflow(); + } + } + + // now set the text zoom on all children of mContainer + struct TextZoomInfo textZoomInfo = { aTextZoom }; + return CallChildren(SetChildTextZoom, &textZoomInfo); +} + +NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) +{ + NS_ENSURE_ARG_POINTER(aTextZoom); + + if (mDeviceContext) { + return mDeviceContext->GetTextZoom(*aTextZoom); + } + + *aTextZoom = 1.0; + return NS_OK; +} + // XXX: SEMANTIC CHANGE! // returns a copy of the string. Caller is responsible for freeing result // using Recycle(aDefaultCharacterSet) @@ -1434,37 +1509,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCha return NS_OK; } +static void +SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetDefaultCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) { mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet // now set the default char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetDefaultCharacterSet(aDefaultCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildDefaultCharacterSet, + (void*) aDefaultCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1484,37 +1540,17 @@ NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharact return NS_OK; } +static void +SetChildForceCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetForceCharacterSet((PRUnichar*) aClosure); +} + NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) { mForceCharacterSet = aForceCharacterSet; // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetForceCharacterSet(aForceCharacterSet); - } - } - } - } - } - return NS_OK; + return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); } // XXX: SEMANTIC CHANGE! @@ -1542,71 +1578,31 @@ NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharac return NS_OK; } +static void +SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSetSource((PRInt32) aClosure); +} NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) { mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSetSource(aHintCharacterSetSource); - } - } - } - } - } - return NS_OK; + // now set the hint char set source on all children of mContainer + return CallChildren(SetChildHintCharacterSetSource, + (void*) aHintCharacterSetSource); +} + +static void +SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetHintCharacterSet((PRUnichar*) aClosure); } NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) { mHintCharset = aHintCharacterSet; - // now set the force char set on all children of mContainer - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - markupCV->SetHintCharacterSet(aHintCharacterSet); - } - } - } - } - } - return NS_OK; + // now set the hint char set on all children of mContainer + return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); } NS_IMETHODIMP DocumentViewerImpl::SizeToContent() diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 9c0fe66fc7b..d668bb8bb6d 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -255,15 +255,9 @@ nsPresContext::GetUserPreferences() GetFontPreferences(); } -void -nsPresContext::PreferenceChanged(const char* aPrefName) +NS_IMETHODIMP +nsPresContext::RemapStyleAndReflow() { - // Initialize our state from the user preferences - GetUserPreferences(); - if (mDeviceContext) { - mDeviceContext->FlushFontCache(); - } - if (mShell) { // Have the root frame's style context remap its style based on the // user preferences @@ -284,6 +278,19 @@ nsPresContext::PreferenceChanged(const char* aPrefName) mShell->StyleChangeReflow(); } } + + return NS_OK; +} + +void +nsPresContext::PreferenceChanged(const char* aPrefName) +{ + // Initialize our state from the user preferences + GetUserPreferences(); + if (mDeviceContext) { + mDeviceContext->FlushFontCache(); + RemapStyleAndReflow(); + } } NS_IMETHODIMP diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h index 95a9084ccbd..ffdb471986e 100644 --- a/layout/base/src/nsPresContext.h +++ b/layout/base/src/nsPresContext.h @@ -67,6 +67,7 @@ public: NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel); NS_IMETHOD GetBaseURL(nsIURI** aURLResult); NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; + NS_IMETHOD RemapStyleAndReflow(void); NS_IMETHOD ResolveStyleContextFor(nsIContent* aContent, nsIStyleContext* aParentContext, PRBool aForceUnique,