From 9a238506131d004efe41940b40f91836e5517471 Mon Sep 17 00:00:00 2001 From: "anthonyd%netscape.com" Date: Sun, 30 Apr 2000 18:56:26 +0000 Subject: [PATCH] r: mjudge table bacgrounds now sleected properly with disabled selection (grey selection) --- layout/generic/nsFrame.cpp | 16 ++++----- layout/generic/nsFrame.h | 2 +- layout/generic/nsTextFrame.cpp | 2 +- layout/html/base/src/nsFrame.cpp | 16 ++++----- layout/html/base/src/nsFrame.h | 2 +- layout/html/base/src/nsTextFrame.cpp | 2 +- layout/html/table/src/nsTableCellFrame.cpp | 38 ++++++++++++++++++---- layout/tables/nsTableCellFrame.cpp | 38 ++++++++++++++++++---- 8 files changed, 84 insertions(+), 32 deletions(-) diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 84e8b23010f6..896fd53f6e37 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -576,10 +576,10 @@ NS_IMETHODIMP nsFrame::FirstChild(nsIPresContext* aPresContext, return nsnull == aListName ? NS_OK : NS_ERROR_INVALID_ARG; } -PRBool +PRInt16 nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) { - PRInt16 result = PR_FALSE; + PRInt16 result = nsISelectionController::SELECTION_OFF; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); @@ -600,14 +600,14 @@ nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) } } if (userinterface->mUserSelect == NS_STYLE_USER_SELECT_NONE) { - result = PR_FALSE; + result = nsISelectionController::SELECTION_OFF; isOkToTurnOn = PR_FALSE; } } } if (isOkToTurnOn && !result) { selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); - result = PR_TRUE; + result = nsISelectionController::SELECTION_ON; } } } @@ -921,7 +921,7 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, { if (!IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_TRUE); - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } @@ -974,7 +974,7 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } nsMouseEvent *me = (nsMouseEvent *)aEvent; @@ -1058,7 +1058,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } nsresult result; @@ -1102,7 +1102,7 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext* aPresContext, if (IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_FALSE); - if (!DisplaySelection(aPresContext)) + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) return NS_OK; nsresult result; diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index 0bb9549fedd5..ef32297c877c 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -396,7 +396,7 @@ protected: nsFrame(); virtual ~nsFrame(); - PRBool DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn = PR_FALSE); + PRInt16 DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn = PR_FALSE); //this will modify aPos and return the next frame ect. NS_IMETHOD GetFrameFromDirection(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos); diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index c276fc658cbb..337b0611fe11 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -3374,7 +3374,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } diff --git a/layout/html/base/src/nsFrame.cpp b/layout/html/base/src/nsFrame.cpp index 84e8b23010f6..896fd53f6e37 100644 --- a/layout/html/base/src/nsFrame.cpp +++ b/layout/html/base/src/nsFrame.cpp @@ -576,10 +576,10 @@ NS_IMETHODIMP nsFrame::FirstChild(nsIPresContext* aPresContext, return nsnull == aListName ? NS_OK : NS_ERROR_INVALID_ARG; } -PRBool +PRInt16 nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) { - PRInt16 result = PR_FALSE; + PRInt16 result = nsISelectionController::SELECTION_OFF; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); @@ -600,14 +600,14 @@ nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) } } if (userinterface->mUserSelect == NS_STYLE_USER_SELECT_NONE) { - result = PR_FALSE; + result = nsISelectionController::SELECTION_OFF; isOkToTurnOn = PR_FALSE; } } } if (isOkToTurnOn && !result) { selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); - result = PR_TRUE; + result = nsISelectionController::SELECTION_ON; } } } @@ -921,7 +921,7 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, { if (!IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_TRUE); - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } @@ -974,7 +974,7 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } nsMouseEvent *me = (nsMouseEvent *)aEvent; @@ -1058,7 +1058,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } nsresult result; @@ -1102,7 +1102,7 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext* aPresContext, if (IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_FALSE); - if (!DisplaySelection(aPresContext)) + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) return NS_OK; nsresult result; diff --git a/layout/html/base/src/nsFrame.h b/layout/html/base/src/nsFrame.h index 0bb9549fedd5..ef32297c877c 100644 --- a/layout/html/base/src/nsFrame.h +++ b/layout/html/base/src/nsFrame.h @@ -396,7 +396,7 @@ protected: nsFrame(); virtual ~nsFrame(); - PRBool DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn = PR_FALSE); + PRInt16 DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn = PR_FALSE); //this will modify aPos and return the next frame ect. NS_IMETHOD GetFrameFromDirection(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos); diff --git a/layout/html/base/src/nsTextFrame.cpp b/layout/html/base/src/nsTextFrame.cpp index c276fc658cbb..337b0611fe11 100644 --- a/layout/html/base/src/nsTextFrame.cpp +++ b/layout/html/base/src/nsTextFrame.cpp @@ -3374,7 +3374,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (!DisplaySelection(aPresContext)) { + if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } diff --git a/layout/html/table/src/nsTableCellFrame.cpp b/layout/html/table/src/nsTableCellFrame.cpp index cd026c6f5563..8c365bddd126 100644 --- a/layout/html/table/src/nsTableCellFrame.cpp +++ b/layout/html/table/src/nsTableCellFrame.cpp @@ -255,7 +255,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, //TABLECELL SELECTION - PRBool displaySelection; + PRInt16 displaySelection; displaySelection = DisplaySelection(aPresContext); if (displaySelection) { @@ -278,11 +278,18 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, if (NS_SUCCEEDED(result) && tableCellSelectionMode) { frameSelection->GetTableCellSelectionStyleColor(&myColor); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, ((nsStyleColor *)myColor)->mBackgroundColor);//VERY BAD CAST..TEMPORARY - NS_RELEASE(look); - } + if(displaySelection==nsISelectionController::SELECTION_DISABLED) + { + ((nsStyleColor *)myColor)->mBackgroundColor = NS_RGB(176,176,176);// disabled color + } + else + { + nsILookAndFeel* look = nsnull; + if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { + look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, ((nsStyleColor *)myColor)->mBackgroundColor);//VERY BAD CAST..TEMPORARY + NS_RELEASE(look); + } + } } } } @@ -401,6 +408,25 @@ nsTableCellFrame::SetSelected(nsIPresContext* aPresContext, // Note that in current version, aRange and aSpread are ignored, // only this frame is considered nsFrame::SetSelected(aPresContext, aRange, aSelected, aSpread); + + nsCOMPtr shell; + nsresult result = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(result)) + return result; + nsCOMPtr frameSelection; + result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); + if (NS_SUCCEEDED(result) && frameSelection) + { + PRBool tableCellSelectionMode; + result = frameSelection->GetTableCellSelection(&tableCellSelectionMode); + if (NS_SUCCEEDED(result) && tableCellSelectionMode) + { + nsRect frameRect; + GetRect(frameRect); + nsRect rect(0, 0, frameRect.width, frameRect.height); + Invalidate(aPresContext, rect, PR_FALSE); + } + } return NS_OK; } diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp index cd026c6f5563..8c365bddd126 100644 --- a/layout/tables/nsTableCellFrame.cpp +++ b/layout/tables/nsTableCellFrame.cpp @@ -255,7 +255,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, //TABLECELL SELECTION - PRBool displaySelection; + PRInt16 displaySelection; displaySelection = DisplaySelection(aPresContext); if (displaySelection) { @@ -278,11 +278,18 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext* aPresContext, if (NS_SUCCEEDED(result) && tableCellSelectionMode) { frameSelection->GetTableCellSelectionStyleColor(&myColor); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, ((nsStyleColor *)myColor)->mBackgroundColor);//VERY BAD CAST..TEMPORARY - NS_RELEASE(look); - } + if(displaySelection==nsISelectionController::SELECTION_DISABLED) + { + ((nsStyleColor *)myColor)->mBackgroundColor = NS_RGB(176,176,176);// disabled color + } + else + { + nsILookAndFeel* look = nsnull; + if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { + look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, ((nsStyleColor *)myColor)->mBackgroundColor);//VERY BAD CAST..TEMPORARY + NS_RELEASE(look); + } + } } } } @@ -401,6 +408,25 @@ nsTableCellFrame::SetSelected(nsIPresContext* aPresContext, // Note that in current version, aRange and aSpread are ignored, // only this frame is considered nsFrame::SetSelected(aPresContext, aRange, aSelected, aSpread); + + nsCOMPtr shell; + nsresult result = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(result)) + return result; + nsCOMPtr frameSelection; + result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); + if (NS_SUCCEEDED(result) && frameSelection) + { + PRBool tableCellSelectionMode; + result = frameSelection->GetTableCellSelection(&tableCellSelectionMode); + if (NS_SUCCEEDED(result) && tableCellSelectionMode) + { + nsRect frameRect; + GetRect(frameRect); + nsRect rect(0, 0, frameRect.width, frameRect.height); + Invalidate(aPresContext, rect, PR_FALSE); + } + } return NS_OK; }