bug 28071 - added Use DTD compatibility mode to viewer. layout uses single mechanism for determining compatibility mode. r=rods.

This commit is contained in:
karnaze%netscape.com 2000-03-20 23:39:22 +00:00
parent f77e29ffcd
commit e68861558c
20 changed files with 101 additions and 126 deletions

View File

@ -644,17 +644,23 @@ static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
}
PRBool
nsGenericHTMLElement::InNavQuirksMode() const
nsGenericHTMLElement::InNavQuirksMode(nsIDocument* aDoc)
{
PRBool status = PR_FALSE;
if (mDocument) {
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(mDocument));
if (hdoc) {
nsDTDMode mode;
hdoc->GetDTDMode(mode);
if (eDTDMode_Nav == mode) {
status = PR_TRUE;
if (aDoc) {
nsCompatibility mode;
// multiple shells on the same doc are out of luck
nsIPresShell* shell = aDoc->GetShellAt(0);
if (shell) {
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
presContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
status = PR_TRUE;
}
}
NS_RELEASE(shell);
}
}
return status;
@ -1869,19 +1875,8 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
aResult.SetStringValue(colorStr, eHTMLUnit_ColorName);
return PR_TRUE;
}
nsDTDMode mode = eDTDMode_NoQuirks;
if (aDocument) {
nsIHTMLDocument* htmlDoc;
nsresult result;
result = aDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
if (NS_SUCCEEDED(result)) {
// Check the compatibility mode
result = htmlDoc->GetDTDMode(mode);
NS_RELEASE(htmlDoc);
}
}
if (eDTDMode_NoQuirks == mode) {
if (!InNavQuirksMode(aDocument)) {
if (colorStr.CharAt(0) == '#') {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &color)) {
@ -2132,7 +2127,7 @@ PRBool
nsGenericHTMLElement::ParseTableHAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
@ -2142,7 +2137,7 @@ PRBool
nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
@ -2172,7 +2167,7 @@ PRBool
nsGenericHTMLElement::ParseTableCellHAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableCellHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
@ -2182,7 +2177,7 @@ PRBool
nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableCellHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
@ -2215,7 +2210,7 @@ PRBool
nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatDivAlignTable, aResult);
}
return ParseEnumValue(aString, kDivAlignTable, aResult);
@ -2225,7 +2220,7 @@ PRBool
nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatDivAlignTable, aResult);
}
return EnumValueToString(aValue, kDivAlignTable, aResult);

View File

@ -312,7 +312,7 @@ public:
// See if the content object is in a document that has nav-quirks
// mode enabled.
PRBool InNavQuirksMode() const;
static PRBool InNavQuirksMode(nsIDocument* aDoc);
nsIHTMLAttributes* mAttributes;
};

View File

@ -350,7 +350,7 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
if (nsGenericHTMLElement::ParseValue(aValue, -1, MAX_COLSPAN, aResult, eHTMLUnit_Integer)) {
PRInt32 val = aResult.GetIntValue();
// quirks mode does not honor the special html 4 value of 0
if ((val < 0) || ((0 == val) && mInner.InNavQuirksMode())) {
if ((val < 0) || ((0 == val) && mInner.InNavQuirksMode(mInner.mDocument))) {
nsHTMLUnit unit = aResult.GetUnit();
aResult.SetIntValue(1, unit);
}

View File

@ -275,7 +275,7 @@ TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
if ((count+rows) > aIndex) {
body.Item(aIndex-count, aReturn);
NS_RELEASE(tbodies);
return NS_OK;
return NS_OK;
}
count += rows;
theIndex++;

View File

@ -197,33 +197,11 @@ nsLineLayout::~nsLineLayout()
PRBool
nsLineLayout::InStrictMode()
{
// XXX For now this is always part of the build until harishd lands
// the dtd auto-detect code...
#if 1
static PRBool forceStrictMode = PR_FALSE;
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
{
static int firstTime = 1;
if (firstTime) {
if (getenv("GECKO_FORCE_STRICT_MODE")) {
forceStrictMode = PR_TRUE;
}
firstTime = 0;
}
}
#endif
if (forceStrictMode) {
mKnowStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
return mInStrictMode;
}
#endif
if (!mKnowStrictMode) {
mKnowStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
// Dig up the compatabilty mode out of the underlying document, if
// we can find it.
// Get the compatabilty mode from pres context via the document and pres shell
if (mBlockReflowState->frame) {
nsCOMPtr<nsIContent> content;
mBlockReflowState->frame->GetContent(getter_AddRefs(content));
@ -231,13 +209,18 @@ nsLineLayout::InStrictMode()
nsCOMPtr<nsIDocument> doc;
content->GetDocument(*getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(doc));
if (hdoc) {
nsDTDMode mode;
hdoc->GetDTDMode(mode);
if (eDTDMode_NoQuirks != mode) {
mInStrictMode = PR_FALSE;
nsIPresShell* shell = doc->GetShellAt(0);
if (shell) {
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsCompatibility mode;
presContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
mInStrictMode = PR_FALSE;
}
}
NS_RELEASE(shell);
}
}
}

View File

@ -197,33 +197,11 @@ nsLineLayout::~nsLineLayout()
PRBool
nsLineLayout::InStrictMode()
{
// XXX For now this is always part of the build until harishd lands
// the dtd auto-detect code...
#if 1
static PRBool forceStrictMode = PR_FALSE;
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
{
static int firstTime = 1;
if (firstTime) {
if (getenv("GECKO_FORCE_STRICT_MODE")) {
forceStrictMode = PR_TRUE;
}
firstTime = 0;
}
}
#endif
if (forceStrictMode) {
mKnowStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
return mInStrictMode;
}
#endif
if (!mKnowStrictMode) {
mKnowStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
mInStrictMode = PR_TRUE;
// Dig up the compatabilty mode out of the underlying document, if
// we can find it.
// Get the compatabilty mode from pres context via the document and pres shell
if (mBlockReflowState->frame) {
nsCOMPtr<nsIContent> content;
mBlockReflowState->frame->GetContent(getter_AddRefs(content));
@ -231,13 +209,18 @@ nsLineLayout::InStrictMode()
nsCOMPtr<nsIDocument> doc;
content->GetDocument(*getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(doc));
if (hdoc) {
nsDTDMode mode;
hdoc->GetDTDMode(mode);
if (eDTDMode_NoQuirks != mode) {
mInStrictMode = PR_FALSE;
nsIPresShell* shell = doc->GetShellAt(0);
if (shell) {
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
nsCompatibility mode;
presContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
mInStrictMode = PR_FALSE;
}
}
NS_RELEASE(shell);
}
}
}

View File

@ -644,17 +644,23 @@ static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
}
PRBool
nsGenericHTMLElement::InNavQuirksMode() const
nsGenericHTMLElement::InNavQuirksMode(nsIDocument* aDoc)
{
PRBool status = PR_FALSE;
if (mDocument) {
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(mDocument));
if (hdoc) {
nsDTDMode mode;
hdoc->GetDTDMode(mode);
if (eDTDMode_Nav == mode) {
status = PR_TRUE;
if (aDoc) {
nsCompatibility mode;
// multiple shells on the same doc are out of luck
nsIPresShell* shell = aDoc->GetShellAt(0);
if (shell) {
nsCOMPtr<nsIPresContext> presContext;
shell->GetPresContext(getter_AddRefs(presContext));
if (presContext) {
presContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
status = PR_TRUE;
}
}
NS_RELEASE(shell);
}
}
return status;
@ -1869,19 +1875,8 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
aResult.SetStringValue(colorStr, eHTMLUnit_ColorName);
return PR_TRUE;
}
nsDTDMode mode = eDTDMode_NoQuirks;
if (aDocument) {
nsIHTMLDocument* htmlDoc;
nsresult result;
result = aDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
if (NS_SUCCEEDED(result)) {
// Check the compatibility mode
result = htmlDoc->GetDTDMode(mode);
NS_RELEASE(htmlDoc);
}
}
if (eDTDMode_NoQuirks == mode) {
if (!InNavQuirksMode(aDocument)) {
if (colorStr.CharAt(0) == '#') {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &color)) {
@ -2132,7 +2127,7 @@ PRBool
nsGenericHTMLElement::ParseTableHAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
@ -2142,7 +2137,7 @@ PRBool
nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
@ -2172,7 +2167,7 @@ PRBool
nsGenericHTMLElement::ParseTableCellHAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableCellHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
@ -2182,7 +2177,7 @@ PRBool
nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableCellHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
@ -2215,7 +2210,7 @@ PRBool
nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatDivAlignTable, aResult);
}
return ParseEnumValue(aString, kDivAlignTable, aResult);
@ -2225,7 +2220,7 @@ PRBool
nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode()) {
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatDivAlignTable, aResult);
}
return EnumValueToString(aValue, kDivAlignTable, aResult);

View File

@ -312,7 +312,7 @@ public:
// See if the content object is in a document that has nav-quirks
// mode enabled.
PRBool InNavQuirksMode() const;
static PRBool InNavQuirksMode(nsIDocument* aDoc);
nsIHTMLAttributes* mAttributes;
};

View File

@ -350,7 +350,7 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
if (nsGenericHTMLElement::ParseValue(aValue, -1, MAX_COLSPAN, aResult, eHTMLUnit_Integer)) {
PRInt32 val = aResult.GetIntValue();
// quirks mode does not honor the special html 4 value of 0
if ((val < 0) || ((0 == val) && mInner.InNavQuirksMode())) {
if ((val < 0) || ((0 == val) && mInner.InNavQuirksMode(mInner.mDocument))) {
nsHTMLUnit unit = aResult.GetUnit();
aResult.SetIntValue(1, unit);
}

View File

@ -275,7 +275,7 @@ TableRowsCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
if ((count+rows) > aIndex) {
body.Item(aIndex-count, aReturn);
NS_RELEASE(tbodies);
return NS_OK;
return NS_OK;
}
count += rows;
theIndex++;

View File

@ -3525,12 +3525,21 @@ nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
#endif // NS_DEBUG
#define USE_DTD 0
#define STANDARD 1
#define QUIRKS 2
void
nsBrowserWindow::SetCompatibilityMode(PRBool aIsStandard)
nsBrowserWindow::SetCompatibilityMode(PRUint32 aMode)
{
nsCOMPtr<nsIPref> pref(do_GetService(NS_PREF_PROGID));
if (pref) {
int32 prefInt = (aIsStandard) ? eCompatibility_Standard : eCompatibility_NavQuirks;
int32 prefInt = USE_DTD;
if (STANDARD == aMode) {
prefInt = eCompatibility_Standard;
}
else if (QUIRKS == aMode) {
prefInt = eCompatibility_NavQuirks;
}
pref->SetIntPref("nglayout.compatibility.mode", prefInt);
pref->SavePrefFile();
}
@ -3624,9 +3633,10 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID)
result = nsEventStatus_eConsumeNoDefault;
break;
case VIEWER_USE_DTD_MODE:
case VIEWER_NAV_QUIRKS_MODE:
case VIEWER_STANDARD_MODE:
SetCompatibilityMode(VIEWER_STANDARD_MODE == aID);
SetCompatibilityMode(aID - VIEWER_USE_DTD_MODE);
result = nsEventStatus_eConsumeNoDefault;
break;
}

View File

@ -196,7 +196,7 @@ public:
void GetStringPref(const char * aPrefName, nsString& aValue);
nsEventStatus DispatchStyleMenu(PRInt32 aID);
void SetCompatibilityMode(PRBool aIsStandard);
void SetCompatibilityMode(PRUint32 aMode);
nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent);

View File

@ -120,7 +120,8 @@ enum
item_GFXWidgetMode = 24,
item_NativeWidgetMode,
cmd_Compatibility_NavQuirks = 4200,
cmd_Compatibility_UseDTD = 4200,
cmd_Compatibility_NavQuirks,
cmd_Compatibility_Standard,
cmd_JSConsole = 5000,
@ -395,6 +396,7 @@ nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
case submenu_CompatibilityMode:
switch (menuItem)
{
case cmd_Compatibility_UseDTD: xpID = VIEWER_USE_DTD_MODE; break;
case cmd_Compatibility_NavQuirks: xpID = VIEWER_NAV_QUIRKS_MODE; break;
case cmd_Compatibility_Standard: xpID = VIEWER_STANDARD_MODE; break;
}

View File

@ -240,6 +240,7 @@ struct MenuList_s DemoList[18] =
CreateMenuItem(submenu2, "Select Alternative 3", VIEWER_SELECT_STYLE_THREE);
CreateMenuItem(submenu2, "Select Alternative 4", VIEWER_SELECT_STYLE_FOUR);
submenu2=CreateSubMenu(submenu, "Compatibility Mode");
CreateMenuItem(submenu2, "Use DTD", VIEWER_USE_DTD_MODE);
CreateMenuItem(submenu2, "Nav Quirks", VIEWER_NAV_QUIRKS_MODE);
CreateMenuItem(submenu2, "Standard", VIEWER_STANDARD_MODE);
submenu2=CreateSubMenu(submenu, "Widget Render Mode");

View File

@ -30,7 +30,7 @@
class nsIImageGroup;
class nsITimer;
class nsRect;
struct nsRect;
class nsThrobber : public nsIImageRequestObserver {
public:

View File

@ -66,8 +66,7 @@
#define VIEWER_DEBUGSAVE 40062
#define VIEWER_SHOW_CONTENT_QUALITY 40063
#define VIEWER_TOGGLE_SELECTION 40064
#define VIEWER_NAV_QUIRKS_MODE 40065
#define VIEWER_STANDARD_MODE 40066
#define VIEWER_TABLE_INSPECTOR 40067
#define VIEWER_IMAGE_INSPECTOR 40068
#define VIEWER_NATIVE_WIDGET_MODE 40069
@ -80,6 +79,9 @@
#define VIEWER_GOTO_TEST_URL2 40076
#define VIEWER_SAVE_TEST_URL1 40077
#define VIEWER_SAVE_TEST_URL2 40078
#define VIEWER_USE_DTD_MODE 40079
#define VIEWER_STANDARD_MODE 40080
#define VIEWER_NAV_QUIRKS_MODE 40081
#define VIEWER_TOGGLE_PAINT_FLASHING 40200
#define VIEWER_TOGGLE_PAINT_DUMPING 40210

View File

@ -130,6 +130,7 @@ GtkItemFactoryEntry menu_items[] =
{ "/Style/Select Style Sheet/Select Alternative 3", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_THREE, nsnull },
{ "/Style/Select Style Sheet/Select Alternative 4", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_FOUR, nsnull },
{ "/Style/_Compatibility Mode", nsnull, nsnull, 0, "<Branch>" },
{ "/Style/Compatibility Mode/Use DTD", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_USE_DTD_MODE, nsnull },
{ "/Style/Compatibility Mode/Nav Quirks", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_NAV_QUIRKS_MODE, nsnull },
{ "/Style/Compatibility Mode/Standard", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_STANDARD_MODE, nsnull },
{ "/Style/_Gfx Scrollbars Mode", nsnull, nsnull, 0, "<Branch>" },

View File

@ -196,6 +196,7 @@ void CreateViewerMenus(QWidget *aParent, void * data, PRInt32 * aMenuBarHeight)
style->insertItem("Select &Style Sheet", select);
InsertMenuItem(compatibility, "Use DTD", eventHandler, VIEWER_USE_DTD_MODE);
InsertMenuItem(compatibility, "Nav Quirks", eventHandler, VIEWER_NAV_QUIRKS_MODE);
InsertMenuItem(compatibility, "Standard", eventHandler, VIEWER_STANDARD_MODE);

View File

@ -131,6 +131,7 @@ VIEWER MENU DISCARDABLE
}
POPUP "&Compatibility Mode Pref"
{
MENUITEM "Use DTD", VIEWER_USE_DTD_MODE
MENUITEM "Nav Quirks", VIEWER_NAV_QUIRKS_MODE
MENUITEM "Standard", VIEWER_STANDARD_MODE
}

View File

@ -119,6 +119,7 @@ MENU IDM_VIEWERBAR
}
SUBMENU "~Compatibility Mode Pref", 0
{
MENUITEM "Use DTD", VIEWER_USE_DTD_MODE
MENUITEM "Nav Quirks", VIEWER_NAV_QUIRKS_MODE
MENUITEM "Standard", VIEWER_STANDARD_MODE
}