Bug 232321 Make layout.word_select.stop_at_punctuation work as a user preference r/sr=bz

git-svn-id: svn://10.0.0.236/trunk@152928 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
neil%parkwaycc.co.uk 2004-02-19 11:10:31 +00:00
parent 0337575b97
commit 690c52c7f7
4 changed files with 66 additions and 20 deletions

View File

@ -48,6 +48,7 @@
#include "nsUnicharUtils.h"
#include "nsICaseConversion.h"
#include "prenv.h"
#include "nsIPrefBranchInternal.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#ifdef IBMBIDI
@ -55,9 +56,22 @@
#endif
PRPackedBool nsTextTransformer::sWordSelectPrefInited = PR_FALSE;
PRPackedBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
nsTextTransformer::WordSelectListener *nsTextTransformer::sWordSelectListener = nsnull;
PRBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
static const char kWordSelectPref[] = "layout.word_select.stop_at_punctuation";
NS_IMPL_ISUPPORTS1(nsTextTransformer::WordSelectListener, nsIObserver)
NS_IMETHODIMP
nsTextTransformer::WordSelectListener::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
"wrong topic");
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
return prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation);
}
nsAutoTextBuffer::nsAutoTextBuffer()
: mBuffer(mAutoBuffer),
@ -111,15 +125,17 @@ nsresult
nsTextTransformer::Initialize()
{
// read in our global word selection prefs
if ( !sWordSelectPrefInited ) {
nsCOMPtr<nsIPrefBranch> prefBranch =
if ( !sWordSelectListener ) {
nsCOMPtr<nsIPrefBranchInternal> prefBranch =
do_GetService( NS_PREFSERVICE_CONTRACTID );
if ( prefBranch ) {
PRBool temp = PR_FALSE;
prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp);
sWordSelectStopAtPunctuation = temp;
prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation);
sWordSelectListener = new WordSelectListener();
if (sWordSelectListener) {
NS_ADDREF(sWordSelectListener);
prefBranch->AddObserver(kWordSelectPref, sWordSelectListener, PR_FALSE);
}
}
sWordSelectPrefInited = PR_TRUE;
}
return NS_OK;
@ -139,6 +155,7 @@ static nsresult EnsureCaseConv()
void
nsTextTransformer::Shutdown()
{
NS_IF_RELEASE(sWordSelectListener);
if (gCaseConv) {
nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv);
gCaseConv = nsnull;

View File

@ -40,6 +40,7 @@
#include "nsTextFragment.h"
#include "nsISupports.h"
#include "nsIPresContext.h"
#include "nsIObserver.h"
#ifdef IBMBIDI
#include "nsBidi.h"
#include "nsBidiUtils.h"
@ -348,8 +349,13 @@ protected:
PRUint8 mFlags;
// prefs used to configure the double-click word selection behavior
static PRPackedBool sWordSelectPrefInited; // have we read the prefs yet?
static PRPackedBool sWordSelectStopAtPunctuation; // should we stop at punctuation?
class WordSelectListener: public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
static WordSelectListener *sWordSelectListener; // have we read the prefs yet?
static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation?
#ifdef DEBUG
static void SelfTest(nsILineBreaker* aLineBreaker,

View File

@ -48,6 +48,7 @@
#include "nsUnicharUtils.h"
#include "nsICaseConversion.h"
#include "prenv.h"
#include "nsIPrefBranchInternal.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#ifdef IBMBIDI
@ -55,9 +56,22 @@
#endif
PRPackedBool nsTextTransformer::sWordSelectPrefInited = PR_FALSE;
PRPackedBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
nsTextTransformer::WordSelectListener *nsTextTransformer::sWordSelectListener = nsnull;
PRBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
static const char kWordSelectPref[] = "layout.word_select.stop_at_punctuation";
NS_IMPL_ISUPPORTS1(nsTextTransformer::WordSelectListener, nsIObserver)
NS_IMETHODIMP
nsTextTransformer::WordSelectListener::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
"wrong topic");
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
return prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation);
}
nsAutoTextBuffer::nsAutoTextBuffer()
: mBuffer(mAutoBuffer),
@ -111,15 +125,17 @@ nsresult
nsTextTransformer::Initialize()
{
// read in our global word selection prefs
if ( !sWordSelectPrefInited ) {
nsCOMPtr<nsIPrefBranch> prefBranch =
if ( !sWordSelectListener ) {
nsCOMPtr<nsIPrefBranchInternal> prefBranch =
do_GetService( NS_PREFSERVICE_CONTRACTID );
if ( prefBranch ) {
PRBool temp = PR_FALSE;
prefBranch->GetBoolPref("layout.word_select.stop_at_punctuation", &temp);
sWordSelectStopAtPunctuation = temp;
prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation);
sWordSelectListener = new WordSelectListener();
if (sWordSelectListener) {
NS_ADDREF(sWordSelectListener);
prefBranch->AddObserver(kWordSelectPref, sWordSelectListener, PR_FALSE);
}
}
sWordSelectPrefInited = PR_TRUE;
}
return NS_OK;
@ -139,6 +155,7 @@ static nsresult EnsureCaseConv()
void
nsTextTransformer::Shutdown()
{
NS_IF_RELEASE(sWordSelectListener);
if (gCaseConv) {
nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv);
gCaseConv = nsnull;

View File

@ -40,6 +40,7 @@
#include "nsTextFragment.h"
#include "nsISupports.h"
#include "nsIPresContext.h"
#include "nsIObserver.h"
#ifdef IBMBIDI
#include "nsBidi.h"
#include "nsBidiUtils.h"
@ -348,8 +349,13 @@ protected:
PRUint8 mFlags;
// prefs used to configure the double-click word selection behavior
static PRPackedBool sWordSelectPrefInited; // have we read the prefs yet?
static PRPackedBool sWordSelectStopAtPunctuation; // should we stop at punctuation?
class WordSelectListener: public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
static WordSelectListener *sWordSelectListener; // have we read the prefs yet?
static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation?
#ifdef DEBUG
static void SelfTest(nsILineBreaker* aLineBreaker,