From a3a70da91b8813ce3a15c6598a75e86013d87298 Mon Sep 17 00:00:00 2001 From: "erik%netscape.com" Date: Thu, 12 Apr 2001 23:35:24 +0000 Subject: [PATCH] bug 75066; author=simon@softel.co.il; r=jst; sr=erik; diffs from IBM bidi project (e.g. Arabic, Hebrew) git-svn-id: svn://10.0.0.236/trunk@92118 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 19 ++ mozilla/content/base/src/nsDocument.cpp | 96 ++++++++ mozilla/content/base/src/nsDocument.h | 24 ++ mozilla/content/base/src/nsDocumentViewer.cpp | 214 ++++++++++++++++++ .../content/base/src/nsGenericDOMDataNode.cpp | 9 + .../html/content/src/nsGenericHTMLElement.cpp | 34 +++ .../html/document/src/nsHTMLDocument.cpp | 20 +- .../html/document/src/nsHTMLDocument.h | 5 + .../xul/document/src/nsXULDocument.cpp | 29 +++ .../content/xul/document/src/nsXULDocument.h | 13 ++ mozilla/docshell/base/nsDocShell.cpp | 18 ++ .../docshell/base/nsIMarkupDocumentViewer.idl | 68 ++++++ mozilla/layout/base/nsDocumentViewer.cpp | 214 ++++++++++++++++++ 13 files changed, 762 insertions(+), 1 deletion(-) diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 2aacf200dce..7076a9b6ded 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -147,6 +147,25 @@ public: */ NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver) = 0; +#ifdef IBMBIDI + // The state BidiEnabled should persist across multiple views (screen, print) + // of the same document. + + /** + * Check if the document contains bidi data. + * If so, we have to apply the Unicode Bidi Algorithm. + */ + NS_IMETHOD GetBidiEnabled(PRBool* aBidiEnabled) const = 0; + + /** + * Indicate the document contains bidi data. + * Currently, we cannot disable bidi, because once bidi is enabled, + * it affects a frame model irreversibly, and plays even though + * the document no longer contains bidi data. + */ + NS_IMETHOD SetBidiEnabled(PRBool aBidiEnabled) = 0; +#endif // IBMBIDI + /** * Return the Line Breaker for the document */ diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index e3631e9e0cf..95da32dec5b 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -104,6 +104,10 @@ #include "nsPIBoxObject.h" #include "nsXULAtoms.h" +#ifdef IBMBIDI +#include "nsIUBidiUtils.h" +#endif + static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); @@ -487,6 +491,9 @@ nsDocument::nsDocument() mDTD = 0; mBoxObjectTable = nsnull; mNumCapturers = 0; +#ifdef IBMBIDI + mBidiEnabled = PR_FALSE; +#endif // IBMBIDI // Force initialization. mBindingManager = do_CreateInstance("@mozilla.org/xbl/binding-manager;1"); @@ -2304,16 +2311,76 @@ nsDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject) return NS_OK; } +#ifdef IBMBIDI +struct DirTable { + const char* mName; + PRUint8 mValue; +}; +static const DirTable dirAttributes[] = { + {"ltr", IBMBIDI_TEXTDIRECTION_LTR}, + {"rtl", IBMBIDI_TEXTDIRECTION_RTL}, + {0} +}; +#endif // IBMBIDI + +/** + * Retrieve the "direction" property of the document. + * + * @lina 01/09/2001 + */ NS_IMETHODIMP nsDocument::GetDir(nsAWritableString& aDirection) { +#ifdef IBMBIDI + nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); + if (shell) { + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context) ); + if (context) { + PRUint32 options; + context->GetBidi(&options); + for (const DirTable* elt = dirAttributes; elt->mName; elt++) { + if (GET_BIDI_OPTION_DIRECTION(options) == elt->mValue) { + aDirection.Assign(NS_ConvertASCIItoUCS2(elt->mName) ); + break; + } + } + } + } +#else aDirection.Assign(NS_LITERAL_STRING("ltr") ); +#endif // IBMBIDI return NS_OK; } +/** + * Set the "direction" property of the document. + * + * @lina 01/09/2001 + */ NS_IMETHODIMP nsDocument::SetDir(const nsAReadableString& aDirection) { +#ifdef IBMBIDI + nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); + if (shell) { + nsCOMPtr context; + shell->GetPresContext(getter_AddRefs(context) ); + if (context) { + PRUint32 options; + context->GetBidi(&options); + for (const DirTable* elt = dirAttributes; elt->mName; elt++) { + if (aDirection == NS_ConvertASCIItoUCS2(elt->mName) ) { + if (GET_BIDI_OPTION_DIRECTION(options) != elt->mValue) { + SET_BIDI_OPTION_DIRECTION(options, elt->mValue); + context->SetBidi(options, PR_TRUE); + } + break; + } + } // for + } + } +#endif // IBMBIDI return NS_OK; } @@ -3233,4 +3300,33 @@ nsDocument::GetDTD(nsIDTD** aDTD) const return NS_OK; } +#ifdef IBMBIDI +/** + * Check if bidi enabled (set depending on the presence of RTL + * characters). If enabled, we should apply the Unicode Bidi Algorithm + * + * @lina 07/12/2000 + */ +NS_IMETHODIMP +nsDocument::GetBidiEnabled(PRBool* aBidiEnabled) const +{ + NS_ENSURE_ARG_POINTER(aBidiEnabled); + *aBidiEnabled = mBidiEnabled; + return NS_OK; +} +/** + * Indicate the document contains RTL characters. + * + * @lina 07/12/2000 + */ +NS_IMETHODIMP +nsDocument::SetBidiEnabled(PRBool aBidiEnabled) +{ + NS_ASSERTION(aBidiEnabled, "cannot disable bidi once enabled"); + if (aBidiEnabled) { + mBidiEnabled = PR_TRUE; + } + return NS_OK; +} +#endif // IBMBIDI diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 8556f657d69..629010fab73 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -277,6 +277,18 @@ public: */ NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver); +#ifdef IBMBIDI + /** + * Check if the document contains bidi data. + * If so, we have to apply the Unicode Bidi Algorithm. + */ + NS_IMETHOD GetBidiEnabled(PRBool* aBidiEnabled) const; + /** + * Indicate the document contains RTL characters. + */ + NS_IMETHOD SetBidiEnabled(PRBool aBidiEnabled); +#endif // IBMBIDI + /** * Return the Line Breaker for the document */ @@ -457,7 +469,15 @@ public: NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins); NS_IMETHOD GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult); NS_IMETHOD SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject); + + /** + * Retrieve the "direction" property of the document. + */ NS_IMETHOD GetDir(nsAWritableString& aDirection); + + /** + * Set the "direction" property of the document. + */ NS_IMETHOD SetDir(const nsAReadableString& aDirection); // nsIDOMNode interface @@ -563,6 +583,10 @@ protected: // objects in the document's content model PRInt32 mNextContentID; +#ifdef IBMBIDI + PRBool mBidiEnabled; +#endif // IBMBIDI + // disk file members nsCOMPtr mFileSpec; PRInt32 mModCount; diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 36ef329ca71..068ad7e5c84 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -126,6 +126,10 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsITransformMediator.h" +#ifdef IBMBIDI +#include "nsIUBidiUtils.h" +#endif + static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); @@ -4564,6 +4568,216 @@ NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintChar return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); } +#ifdef IBMBIDI +static void +SetChildBidiOptions(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetBidiOptions((PRUint32)aClosure); +} + +#endif // IBMBIDI + +NS_IMETHODIMP DocumentViewerImpl::SetBidiTextDirection(PRUint8 aTextDirection) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_DIRECTION(bidiOptions, aTextDirection); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiTextDirection(PRUint8* aTextDirection) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aTextDirection) { + GetBidiOptions(&bidiOptions); + *aTextDirection = GET_BIDI_OPTION_DIRECTION(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiTextType(PRUint8 aTextType) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_TEXTTYPE(bidiOptions, aTextType); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiTextType(PRUint8* aTextType) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aTextType) { + GetBidiOptions(&bidiOptions); + *aTextType = GET_BIDI_OPTION_TEXTTYPE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiControlsTextMode(PRUint8 aControlsTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions, aControlsTextMode); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiControlsTextMode(PRUint8* aControlsTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aControlsTextMode) { + GetBidiOptions(&bidiOptions); + *aControlsTextMode = GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiClipboardTextMode(PRUint8 aClipboardTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions, aClipboardTextMode); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiClipboardTextMode(PRUint8* aClipboardTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aClipboardTextMode) { + GetBidiOptions(&bidiOptions); + *aClipboardTextMode = GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiNumeral(PRUint8 aNumeral) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_NUMERAL(bidiOptions, aNumeral); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiNumeral(PRUint8* aNumeral) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aNumeral) { + GetBidiOptions(&bidiOptions); + *aNumeral = GET_BIDI_OPTION_NUMERAL(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiSupport(PRUint8 aSupport) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_SUPPORT(bidiOptions, aSupport); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiSupport(PRUint8* aSupport) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aSupport) { + GetBidiOptions(&bidiOptions); + *aSupport = GET_BIDI_OPTION_SUPPORT(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiCharacterSet(PRUint8 aCharacterSet) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CHARACTERSET(bidiOptions, aCharacterSet); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiCharacterSet(PRUint8* aCharacterSet) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aCharacterSet) { + GetBidiOptions(&bidiOptions); + *aCharacterSet = GET_BIDI_OPTION_CHARACTERSET(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions) +{ +#ifdef IBMBIDI + if (mPresContext) { + mPresContext->SetBidi(aBidiOptions, PR_TRUE); // force reflow + } + // now set bidi on all children of mContainer + CallChildren(SetChildBidiOptions, (void*) aBidiOptions); +#endif // IBMBIDI + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiOptions(PRUint32* aBidiOptions) +{ +#ifdef IBMBIDI + if (aBidiOptions) { + if (mPresContext) { + mPresContext->GetBidi(aBidiOptions); + } + else + *aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS; + } +#endif // IBMBIDI + return NS_OK; +} + NS_IMETHODIMP DocumentViewerImpl::SizeToContent() { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE); diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index e46aa5cb866..7db06ac1905 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -946,6 +946,15 @@ nsGenericDOMDataNode::SetText(nsIContent *aOuterContent, if (aNotify && (nsnull != mDocument)) { mDocument->BeginUpdate(); } +#ifdef IBMBIDI + if (mDocument != nsnull) { + PRBool bidiEnabled = mText.SetTo(aBuffer, aLength); + if (bidiEnabled) { + mDocument->SetBidiEnabled(PR_TRUE); + } + } + else +#endif // IBMBIDI mText.SetTo(aBuffer, aLength); if (mDocument && nsGenericElement::HasMutationListeners(aOuterContent, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) { diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 28344552cdc..ac4552b5f0e 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -2100,11 +2100,38 @@ nsGenericHTMLElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, return NS_OK; } +#ifdef IBMBIDI +/** + * Handle attributes on the BDO element + */ +static void +MapBdoAttributesInto(const nsIHTMLMappedAttributes* aAttributes, + nsIMutableStyleContext* aStyleContext, + nsIPresContext* aPresContext) +{ + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aStyleContext, + aPresContext); + nsHTMLValue value; + // Get dir attribute + aAttributes->GetAttribute(nsHTMLAtoms::dir, value); + if (eHTMLUnit_Enumerated == value.GetUnit() ) { + nsStyleText* text = (nsStyleText*) + aStyleContext->GetMutableStyleData(eStyleStruct_Text); + text->mUnicodeBidi = NS_STYLE_UNICODE_BIDI_OVERRIDE; + } +} +#endif // IBMBIDI + NS_IMETHODIMP nsGenericHTMLElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc, nsMapAttributesFunc& aMapFunc) const { aFontMapFunc = nsnull; +#ifdef IBMBIDI + if (mNodeInfo->Equals(nsHTMLAtoms::bdo) ) + aMapFunc = &MapBdoAttributesInto; + else +#endif // IBMBIDI aMapFunc = &MapCommonAttributesInto; return NS_OK; } @@ -2886,6 +2913,13 @@ nsGenericHTMLElement::MapCommonAttributesInto(const nsIHTMLMappedAttributes* aAt nsStyleDisplay* display = (nsStyleDisplay*) aStyleContext->GetMutableStyleData(eStyleStruct_Display); display->mDirection = value.GetIntValue(); +#ifdef IBMBIDI + display->mExplicitDirection = display->mDirection; + + if (NS_STYLE_DIRECTION_RTL == display->mDirection) { + aPresContext->EnableBidi(); + } +#endif // IBMBIDI } aAttributes->GetAttribute(nsHTMLAtoms::lang, value); if (value.GetUnit() == eHTMLUnit_String) { diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index a933b870909..ad931ec12a9 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -113,6 +113,10 @@ #include "nsLayoutCID.h" #include "nsContentCID.h" #include "nsIPrompt.h" +//AHMED 12-2 +#ifdef IBMBIDI +#include "nsIUBidiUtils.h" +#endif #define DETECTOR_CONTRACTID_MAX 127 static char g_detector_contractid[DETECTOR_CONTRACTID_MAX + 1]; @@ -624,7 +628,15 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, nsCOMPtr dcInfo; docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo)); - +#ifdef IBMBIDI + nsCOMPtr cx; + docShell->GetPresContext(getter_AddRefs(cx)); + if(cx){ + PRUint32 mBidiOption; + cx->GetBidi(&mBidiOption); + mTexttype = GET_BIDI_OPTION_TEXTTYPE(mBidiOption); + } +#endif // IBMBIDI // // The following logic is mirrored in nsWebShell::Embed! // @@ -853,6 +865,12 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, if (NS_FAILED(rv)) { return rv; } +//ahmed +#ifdef IBMBIDI + // Check if 864 but in Implicit mode ! + if( (mTexttype == IBMBIDI_TEXTTYPE_LOGICAL)&&(charset.EqualsIgnoreCase("ibm864")) ) + charset.AssignWithConversion("IBM864i"); +#endif // IBMBIDI rv = this->SetDocumentCharacterSet(charset); if (NS_FAILED(rv)) { diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 478296cd725..1f9722ed931 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -220,6 +220,11 @@ protected: nsContentList *mLayers; nsIParser *mParser; + +//ahmed 12-2 +#ifdef IBMBIDI + PRInt32 mTexttype; +#endif static nsrefcnt gRefCntRDFService; static nsIRDFService* gRDF; diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 20cc593e78c..4594c20aea9 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -418,6 +418,9 @@ nsXULDocument::nsXULDocument(void) nsCOMPtr observer(do_QueryInterface(mBindingManager)); if (observer) // We must always be the first observer of the document. mObservers.InsertElementAt(observer, 0); +#ifdef IBMBIDI + mBidiEnabled = PR_FALSE; +#endif // IBMBIDI } nsXULDocument::~nsXULDocument() @@ -6251,6 +6254,32 @@ nsXULDocument::ParserObserver::OnStopRequest(nsIRequest *request, return rv; } +#ifdef IBMBIDI +/** + * Retrieve and get bidi state of the document + * set depending on presence of bidi data. + * (see nsIDocument.h) + */ + +NS_IMETHODIMP +nsXULDocument::GetBidiEnabled(PRBool* aBidiEnabled) const +{ + NS_ENSURE_ARG_POINTER(aBidiEnabled); + *aBidiEnabled = mBidiEnabled; + return NS_OK; +} + +NS_IMETHODIMP +nsXULDocument::SetBidiEnabled(PRBool aBidiEnabled) +{ + NS_ASSERTION(aBidiEnabled, "cannot disable bidi once enabled"); + if (aBidiEnabled) { + mBidiEnabled = PR_TRUE; + } + return NS_OK; +} +#endif // IBMBIDI + //---------------------------------------------------------------------- // diff --git a/mozilla/content/xul/document/src/nsXULDocument.h b/mozilla/content/xul/document/src/nsXULDocument.h index c8bd1214a2f..aa42cc8419e 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.h +++ b/mozilla/content/xul/document/src/nsXULDocument.h @@ -146,6 +146,15 @@ public: NS_IMETHOD SetDocumentCharacterSet(const nsAReadableString& aCharSetID); +#ifdef IBMBIDI + /** + * Retrieve and get bidi state of the document + * (set depending on presence of bidi data). + */ + NS_IMETHOD GetBidiEnabled(PRBool* aBidiEnabled) const; + NS_IMETHOD SetBidiEnabled(PRBool aBidiEnabled); +#endif // IBMBIDI + NS_IMETHOD AddCharSetObserver(nsIObserver* aObserver); NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver); @@ -521,6 +530,10 @@ protected: PRInt32 mNextContentID; PRInt32 mNumCapturers; //Number of capturing event handlers in doc. Used to optimize event delivery. +#ifdef IBMBIDI + PRBool mBidiEnabled; +#endif // IBMBIDI + // The following are pointers into the content model which provide access to // the objects triggering either a popup or a tooltip. These are marked as // [OWNER] only because someone could, through DOM calls, delete the object from the diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index ddf6278235f..374d5cc0ca2 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -91,6 +91,10 @@ // http://bugzilla.mozilla.org/show_bug.cgi?id=71482 #include "nsIBrowserHistory.h" +#ifdef IBMBIDI +#include "nsIUBidiUtils.h" +#endif + static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID); @@ -2930,6 +2934,10 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parentAsItem)), NS_ERROR_FAILURE); nsCOMPtr parent(do_QueryInterface(parentAsItem)); +#ifdef IBMBIDI + PRUint32 options; + nsIMarkupDocumentViewer* newViewer = nsnull; +#endif // IBMBIDI if(mContentViewer || parent) { @@ -2965,6 +2973,10 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource(&hintCharsetSource), NS_ERROR_FAILURE); +#ifdef IBMBIDI + NS_ENSURE_SUCCESS(oldMUDV->GetBidiOptions(&options), NS_ERROR_FAILURE); + newViewer = newMUDV.get(); +#endif // IBMBIDI // set the old state onto the new content viewer NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet(defaultCharset), @@ -3036,6 +3048,12 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer) return NS_ERROR_FAILURE; } +#ifdef IBMBIDI + if (newViewer) { + // set the old state onto the new content viewer + NS_ENSURE_SUCCESS(newViewer->SetBidiOptions(options), NS_ERROR_FAILURE); + } +#endif // IBMBIDI // XXX: It looks like the LayoutState gets restored again in Embed() // right after the call to SetupNewViewer(...) diff --git a/mozilla/docshell/base/nsIMarkupDocumentViewer.idl b/mozilla/docshell/base/nsIMarkupDocumentViewer.idl index afea227caa8..af96b8a34e6 100644 --- a/mozilla/docshell/base/nsIMarkupDocumentViewer.idl +++ b/mozilla/docshell/base/nsIMarkupDocumentViewer.idl @@ -77,4 +77,72 @@ interface nsIMarkupDocumentViewer : nsISupports * Tell the container to shrink-to-fit or grow-to-fit its contents */ void sizeToContent(); + + /** + * Options for Bidi presentation. + * + * Use these attributes to access the individual Bidi options. + */ + + /** + * bidiTextDirection: the default direction for the layout of bidirectional text. + * 1 - left to right + * 2 - right to left + */ + attribute octet bidiTextDirection; + + /** + * bidiTextType: the ordering of bidirectional text. This may be either "logical" + * or "visual". Logical text will be reordered for presentation using the Unicode + * Bidi Algorithm. Visual text will be displayed without reordering. + * 1 - the default order for the charset + * 2 - logical order + * 3 - visual order + */ + attribute octet bidiTextType; + + /** + * bidiControlsTextMode: the order of bidirectional text in form controls. + * 1 - logical + * 2 - visual + * 3 - like the containing document + */ + attribute octet bidiControlsTextMode; + + /** + * bidiClipboardTextMode: the order in which text is transferred to the clipboard. + * 1 - logical + * 2 - visual + * 3 - as source (unchanged) + */ + attribute octet bidiClipboardTextMode; + + /** + * bidiNumeral: the type of numerals to display. + * 1 - depending on context, default is Arabic numerals + * 2 - depending on context, default is Hindi numerals + * 3 - Arabic numerals + * 4 - Hindi numerals + */ + attribute octet bidiNumeral; + + /** + * bidiSupport: whether to use platform bidi support or Mozilla's bidi support + * 1 - Use Mozilla's bidi support + * 2 - Use the platform bidi support + * 3 - Disable bidi support + */ + attribute octet bidiSupport; + + /** + * bidiCharacterSet: whether to force the user's character set + * 1 - use the document character set + * 2 - use the character set chosen by the user + */ + attribute octet bidiCharacterSet; + + /** + * Use this attribute to access all the Bidi options in one operation + */ + attribute PRUint32 bidiOptions; }; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 36ef329ca71..068ad7e5c84 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -126,6 +126,10 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsITransformMediator.h" +#ifdef IBMBIDI +#include "nsIUBidiUtils.h" +#endif + static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); @@ -4564,6 +4568,216 @@ NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintChar return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); } +#ifdef IBMBIDI +static void +SetChildBidiOptions(nsIMarkupDocumentViewer* aChild, void* aClosure) +{ + aChild->SetBidiOptions((PRUint32)aClosure); +} + +#endif // IBMBIDI + +NS_IMETHODIMP DocumentViewerImpl::SetBidiTextDirection(PRUint8 aTextDirection) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_DIRECTION(bidiOptions, aTextDirection); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiTextDirection(PRUint8* aTextDirection) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aTextDirection) { + GetBidiOptions(&bidiOptions); + *aTextDirection = GET_BIDI_OPTION_DIRECTION(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiTextType(PRUint8 aTextType) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_TEXTTYPE(bidiOptions, aTextType); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiTextType(PRUint8* aTextType) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aTextType) { + GetBidiOptions(&bidiOptions); + *aTextType = GET_BIDI_OPTION_TEXTTYPE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiControlsTextMode(PRUint8 aControlsTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions, aControlsTextMode); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiControlsTextMode(PRUint8* aControlsTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aControlsTextMode) { + GetBidiOptions(&bidiOptions); + *aControlsTextMode = GET_BIDI_OPTION_CONTROLSTEXTMODE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiClipboardTextMode(PRUint8 aClipboardTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions, aClipboardTextMode); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiClipboardTextMode(PRUint8* aClipboardTextMode) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aClipboardTextMode) { + GetBidiOptions(&bidiOptions); + *aClipboardTextMode = GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiNumeral(PRUint8 aNumeral) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_NUMERAL(bidiOptions, aNumeral); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiNumeral(PRUint8* aNumeral) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aNumeral) { + GetBidiOptions(&bidiOptions); + *aNumeral = GET_BIDI_OPTION_NUMERAL(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiSupport(PRUint8 aSupport) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_SUPPORT(bidiOptions, aSupport); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiSupport(PRUint8* aSupport) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aSupport) { + GetBidiOptions(&bidiOptions); + *aSupport = GET_BIDI_OPTION_SUPPORT(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiCharacterSet(PRUint8 aCharacterSet) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + GetBidiOptions(&bidiOptions); + SET_BIDI_OPTION_CHARACTERSET(bidiOptions, aCharacterSet); + SetBidiOptions(bidiOptions); +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiCharacterSet(PRUint8* aCharacterSet) +{ +#ifdef IBMBIDI + PRUint32 bidiOptions; + + if (aCharacterSet) { + GetBidiOptions(&bidiOptions); + *aCharacterSet = GET_BIDI_OPTION_CHARACTERSET(bidiOptions); + } +#endif + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::SetBidiOptions(PRUint32 aBidiOptions) +{ +#ifdef IBMBIDI + if (mPresContext) { + mPresContext->SetBidi(aBidiOptions, PR_TRUE); // force reflow + } + // now set bidi on all children of mContainer + CallChildren(SetChildBidiOptions, (void*) aBidiOptions); +#endif // IBMBIDI + return NS_OK; +} + +NS_IMETHODIMP DocumentViewerImpl::GetBidiOptions(PRUint32* aBidiOptions) +{ +#ifdef IBMBIDI + if (aBidiOptions) { + if (mPresContext) { + mPresContext->GetBidi(aBidiOptions); + } + else + *aBidiOptions = IBMBIDI_DEFAULT_BIDI_OPTIONS; + } +#endif // IBMBIDI + return NS_OK; +} + NS_IMETHODIMP DocumentViewerImpl::SizeToContent() { NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);