diff --git a/mozilla/content/base/public/nsISelectionController.idl b/mozilla/content/base/public/nsISelectionController.idl index d05448cbd73..7bb3a196ae4 100644 --- a/mozilla/content/base/public/nsISelectionController.idl +++ b/mozilla/content/base/public/nsISelectionController.idl @@ -57,6 +57,7 @@ interface nsISelectionController : nsISelectionDisplay const short SELECTION_HIDDEN =1;//>HIDDEN displays selection const short SELECTION_ON = 2; const short SELECTION_DISABLED = 3; + const short SELECTION_ATTENTION = 4; /** * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index fe6987c8968..a878e355bfb 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -1151,6 +1151,8 @@ NS_IMETHODIMP nsCaret::SetCaretWidth(nscoord aPixels) return NS_OK; } -void nsCaret::SetVisibilityDuringSelection(PRBool aVisibility) { +NS_IMETHODIMP nsCaret::SetVisibilityDuringSelection(PRBool aVisibility) +{ mShowDuringSelection = aVisibility; + return NS_OK; } diff --git a/mozilla/layout/base/nsCaret.h b/mozilla/layout/base/nsCaret.h index 062d308d34f..6c87dc3d1fa 100644 --- a/mozilla/layout/base/nsCaret.h +++ b/mozilla/layout/base/nsCaret.h @@ -66,7 +66,7 @@ class nsCaret : public nsICaret, NS_IMETHOD EraseCaret(); NS_IMETHOD SetCaretWidth(nscoord aPixels); - void SetVisibilityDuringSelection(PRBool aVisibility); + NS_IMETHOD SetVisibilityDuringSelection(PRBool aVisibility); //nsISelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); diff --git a/mozilla/layout/base/nsICaret.h b/mozilla/layout/base/nsICaret.h index 7aa09a28692..9fe95791185 100644 --- a/mozilla/layout/base/nsICaret.h +++ b/mozilla/layout/base/nsICaret.h @@ -110,6 +110,7 @@ public: */ NS_IMETHOD SetCaretWidth(nscoord aPixels) = 0; + NS_IMETHOD SetVisibilityDuringSelection(PRBool aVisibilityDuringSelection) = 0; }; extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); diff --git a/mozilla/layout/base/public/nsICaret.h b/mozilla/layout/base/public/nsICaret.h index 7aa09a28692..9fe95791185 100644 --- a/mozilla/layout/base/public/nsICaret.h +++ b/mozilla/layout/base/public/nsICaret.h @@ -110,6 +110,7 @@ public: */ NS_IMETHOD SetCaretWidth(nscoord aPixels) = 0; + NS_IMETHOD SetVisibilityDuringSelection(PRBool aVisibilityDuringSelection) = 0; }; extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index fe6987c8968..a878e355bfb 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -1151,6 +1151,8 @@ NS_IMETHODIMP nsCaret::SetCaretWidth(nscoord aPixels) return NS_OK; } -void nsCaret::SetVisibilityDuringSelection(PRBool aVisibility) { +NS_IMETHODIMP nsCaret::SetVisibilityDuringSelection(PRBool aVisibility) +{ mShowDuringSelection = aVisibility; + return NS_OK; } diff --git a/mozilla/layout/base/src/nsCaret.h b/mozilla/layout/base/src/nsCaret.h index 062d308d34f..6c87dc3d1fa 100644 --- a/mozilla/layout/base/src/nsCaret.h +++ b/mozilla/layout/base/src/nsCaret.h @@ -66,7 +66,7 @@ class nsCaret : public nsICaret, NS_IMETHOD EraseCaret(); NS_IMETHOD SetCaretWidth(nscoord aPixels); - void SetVisibilityDuringSelection(PRBool aVisibility); + NS_IMETHOD SetVisibilityDuringSelection(PRBool aVisibility); //nsISelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index aabfdcf2e19..6c58e361d53 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -971,12 +971,11 @@ inline nscolor EnsureDifferentColors(nscolor colorA, nscolor colorB) //helper class for drawing multiply selected text class DrawSelectionIterator { - enum {DISABLED_COLOR = NS_RGB(176,176,176)}; enum {SELECTION_TYPES_WE_CARE_ABOUT=nsISelectionController::SELECTION_NONE+nsISelectionController::SELECTION_NORMAL}; public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, - PRInt16 aSelectionStatus); + PRInt16 aSelectionStatus, nsIPresContext *aPresContext); ~DrawSelectionIterator(); PRBool First(); PRBool Next(); @@ -1004,12 +1003,13 @@ private: PRBool mInit; PRInt16 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() nscolor mDisabledColor; + nscolor mAttentionColor; //private methods void FillCurrentData(); }; DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, - PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus) + PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus, nsIPresContext *aPresContext) :mOldStyle(aTextStyle) { mDetails = aSelDetails; @@ -1019,7 +1019,17 @@ DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails mTypes = nsnull; mInit = PR_FALSE; mSelectionStatus = aSelectionStatus; - mDisabledColor = EnsureDifferentColors(DISABLED_COLOR, mOldStyle.mSelectionBGColor); + + // Get background colors for disabled selection at attention-getting selection (used with type ahead find) + nsCOMPtr look; + if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(look))) && look) { + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, mAttentionColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, mDisabledColor); + mDisabledColor = EnsureDifferentColors(mDisabledColor, mOldStyle.mSelectionBGColor); + mAttentionColor = EnsureDifferentColors(mAttentionColor, mOldStyle.mSelectionBGColor); + } + else + mDisabledColor = mAttentionColor = mOldStyle.mSelectionBGColor; if (!aSelDetails) { @@ -1210,17 +1220,12 @@ PRBool DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) { //Find color based on mTypes[mCurrentIdx]; - if (!mTypes) - { - if (mCurrentIdx == (PRUint32)mDetails->mStart) - { - aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; - return PR_TRUE; - } - } - else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) - { - aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + if (mTypes? (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL): (mCurrentIdx == (PRUint32)mDetails->mStart)) { + aColor = mOldStyle.mSelectionBGColor; + if (mSelectionStatus==nsISelectionController::SELECTION_ATTENTION) + aColor = mAttentionColor; + else if (mSelectionStatus != nsISelectionController::SELECTION_ON) + aColor = mDisabledColor; return PR_TRUE; } return PR_FALSE; @@ -2146,7 +2151,7 @@ nsTextFrame::IsTextInSelection(nsIPresContext* aPresContext, } //while we have substrings... //PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL); + DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL, aPresContext); if (!iter.IsDone() && iter.First()) { return PR_TRUE; } @@ -2369,7 +2374,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, } //while we have substrings... //PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3037,7 +3042,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3249,7 +3254,7 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset; sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION + DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); //ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index aabfdcf2e19..6c58e361d53 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -971,12 +971,11 @@ inline nscolor EnsureDifferentColors(nscolor colorA, nscolor colorB) //helper class for drawing multiply selected text class DrawSelectionIterator { - enum {DISABLED_COLOR = NS_RGB(176,176,176)}; enum {SELECTION_TYPES_WE_CARE_ABOUT=nsISelectionController::SELECTION_NONE+nsISelectionController::SELECTION_NORMAL}; public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, - PRInt16 aSelectionStatus); + PRInt16 aSelectionStatus, nsIPresContext *aPresContext); ~DrawSelectionIterator(); PRBool First(); PRBool Next(); @@ -1004,12 +1003,13 @@ private: PRBool mInit; PRInt16 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() nscolor mDisabledColor; + nscolor mAttentionColor; //private methods void FillCurrentData(); }; DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, - PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus) + PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus, nsIPresContext *aPresContext) :mOldStyle(aTextStyle) { mDetails = aSelDetails; @@ -1019,7 +1019,17 @@ DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails mTypes = nsnull; mInit = PR_FALSE; mSelectionStatus = aSelectionStatus; - mDisabledColor = EnsureDifferentColors(DISABLED_COLOR, mOldStyle.mSelectionBGColor); + + // Get background colors for disabled selection at attention-getting selection (used with type ahead find) + nsCOMPtr look; + if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(look))) && look) { + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, mAttentionColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, mDisabledColor); + mDisabledColor = EnsureDifferentColors(mDisabledColor, mOldStyle.mSelectionBGColor); + mAttentionColor = EnsureDifferentColors(mAttentionColor, mOldStyle.mSelectionBGColor); + } + else + mDisabledColor = mAttentionColor = mOldStyle.mSelectionBGColor; if (!aSelDetails) { @@ -1210,17 +1220,12 @@ PRBool DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) { //Find color based on mTypes[mCurrentIdx]; - if (!mTypes) - { - if (mCurrentIdx == (PRUint32)mDetails->mStart) - { - aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; - return PR_TRUE; - } - } - else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) - { - aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + if (mTypes? (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL): (mCurrentIdx == (PRUint32)mDetails->mStart)) { + aColor = mOldStyle.mSelectionBGColor; + if (mSelectionStatus==nsISelectionController::SELECTION_ATTENTION) + aColor = mAttentionColor; + else if (mSelectionStatus != nsISelectionController::SELECTION_ON) + aColor = mDisabledColor; return PR_TRUE; } return PR_FALSE; @@ -2146,7 +2151,7 @@ nsTextFrame::IsTextInSelection(nsIPresContext* aPresContext, } //while we have substrings... //PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL); + DrawSelectionIterator iter(details,text,(PRUint32)textLength, ts, nsISelectionController::SELECTION_NORMAL, aPresContext); if (!iter.IsDone() && iter.First()) { return PR_TRUE; } @@ -2369,7 +2374,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, } //while we have substrings... //PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3037,7 +3042,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3249,7 +3254,7 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset; sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION + DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext); //ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; diff --git a/mozilla/widget/public/nsILookAndFeel.h b/mozilla/widget/public/nsILookAndFeel.h index 22982356976..07749aebe5c 100644 --- a/mozilla/widget/public/nsILookAndFeel.h +++ b/mozilla/widget/public/nsILookAndFeel.h @@ -73,6 +73,8 @@ public: eColor_TextForeground, eColor_TextSelectBackground, eColor_TextSelectForeground, + eColor_TextSelectBackgroundDisabled, + eColor_TextSelectBackgroundAttention, // New CSS 2 color definitions eColor_activeborder, diff --git a/mozilla/widget/src/xpwidgets/nsXPLookAndFeel.cpp b/mozilla/widget/src/xpwidgets/nsXPLookAndFeel.cpp index 65516756598..70c05bbacf5 100644 --- a/mozilla/widget/src/xpwidgets/nsXPLookAndFeel.cpp +++ b/mozilla/widget/src/xpwidgets/nsXPLookAndFeel.cpp @@ -128,6 +128,8 @@ char* nsXPLookAndFeel::sColorPrefs[] = "ui.textForeground", "ui.textSelectBackground", "ui.textSelectForeground", + "ui.textSelectBackgroundDisabled" + "ui.textSelectBackgroundAttention" "ui.activeborder", "ui.activecaption", "ui.appworkspace", @@ -347,6 +349,20 @@ NS_IMETHODIMP nsXPLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor) if (!sInitialized) Init(); + // There is no system color setting for these, so set them manually + switch (aID) { + case eColor_TextSelectBackgroundDisabled: + // This is used to gray out the selection when it's not focused + // Used with nsISelectionController::SELECTION_DISABLED + aColor = NS_RGB(0xb0, 0xb0, 0xb0); + return NS_OK; + case eColor_TextSelectBackgroundAttention: + // This makes the selection stand out when typeaheadfind is on + // Used with nsISelectionController::SELECTION_ATTENTION + aColor = NS_RGB(0x38, 0xd8, 0x78); + return NS_OK; + } + // define DEBUG_SYSTEM_COLOR_USE if you want to debug system color // use in a skin that uses them. When set, it will make all system // color pairs that are appropriate for foreground/background