adding a couple of prefs to make word selection better on mac. doesn't eat whitespace to next word and stops at punctuation. r=mjudge/sr=sfraser. bug# 98546
This commit is contained in:
Родитель
735e3c118a
Коммит
4d06bf2721
|
@ -783,6 +783,10 @@ protected:
|
||||||
PRBool aGetTextDimensions/* true=get dimensions false = return length up to aDimensionsResult->width size*/);
|
PRBool aGetTextDimensions/* true=get dimensions false = return length up to aDimensionsResult->width size*/);
|
||||||
nsresult GetContentAndOffsetsForSelection(nsIPresContext* aPresContext,nsIContent **aContent, PRInt32 *aOffset, PRInt32 *aLength);
|
nsresult GetContentAndOffsetsForSelection(nsIPresContext* aPresContext,nsIContent **aContent, PRInt32 *aOffset, PRInt32 *aLength);
|
||||||
|
|
||||||
|
// prefs used to configure the double-click word selection behavior
|
||||||
|
static PRPackedBool sWordSelectPrefInited; // have we read the prefs yet?
|
||||||
|
static PRPackedBool sWordSelectEatSpaceAfter; // should we include whitespace up to next word?
|
||||||
|
|
||||||
#ifdef IBMBIDI
|
#ifdef IBMBIDI
|
||||||
private:
|
private:
|
||||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
@ -806,6 +810,11 @@ NS_IMETHODIMP nsTextFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
PRPackedBool nsTextFrame::sWordSelectPrefInited = PR_FALSE;
|
||||||
|
PRPackedBool nsTextFrame::sWordSelectEatSpaceAfter = PR_TRUE;
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID,
|
NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID,
|
||||||
void** aInstancePtrResult)
|
void** aInstancePtrResult)
|
||||||
|
@ -1251,6 +1260,16 @@ NS_NewContinuingTextFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||||
|
|
||||||
nsTextFrame::nsTextFrame()
|
nsTextFrame::nsTextFrame()
|
||||||
{
|
{
|
||||||
|
// read in our global word selection prefs
|
||||||
|
if ( !sWordSelectPrefInited ) {
|
||||||
|
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||||
|
if ( prefService ) {
|
||||||
|
PRBool temp = PR_FALSE;
|
||||||
|
prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp);
|
||||||
|
sWordSelectEatSpaceAfter = temp;
|
||||||
|
}
|
||||||
|
sWordSelectPrefInited = PR_TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsTextFrame::~nsTextFrame()
|
nsTextFrame::~nsTextFrame()
|
||||||
|
@ -4055,37 +4074,44 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
|
||||||
|
|
||||||
if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){
|
if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){
|
||||||
aPos->mContentOffset = aPos->mStartOffset + contentLen;
|
aPos->mContentOffset = aPos->mStartOffset + contentLen;
|
||||||
//check for whitespace next.
|
// check for whitespace next. On some platforms (mac), we want the selection to end
|
||||||
keepSearching = PR_TRUE;
|
// at the end of the word (not the beginning of the next one), so don't slurp up any extra whitespace.
|
||||||
aPos->mEatingWS = PR_TRUE;
|
if ( sWordSelectEatSpaceAfter ) {
|
||||||
if (!isWhitespace){
|
keepSearching = PR_TRUE;
|
||||||
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
aPos->mEatingWS = PR_TRUE;
|
||||||
{
|
if (!isWhitespace){
|
||||||
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
||||||
goto TryNextFrame;
|
{
|
||||||
if (isWhitespace)
|
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
||||||
aPos->mContentOffset += contentLen;
|
goto TryNextFrame;
|
||||||
else
|
if (isWhitespace)
|
||||||
break;
|
aPos->mContentOffset += contentLen;
|
||||||
}
|
else
|
||||||
keepSearching = PR_FALSE;
|
break;
|
||||||
found = PR_TRUE;
|
}
|
||||||
}
|
keepSearching = PR_FALSE;
|
||||||
else //we just need to jump the space, done here
|
found = PR_TRUE;
|
||||||
{
|
}
|
||||||
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
else //we just need to jump the space, done here
|
||||||
{
|
{
|
||||||
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
||||||
goto TryNextFrame;
|
{
|
||||||
|
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
||||||
|
goto TryNextFrame;
|
||||||
|
|
||||||
if (isWhitespace)
|
if (isWhitespace)
|
||||||
aPos->mContentOffset += contentLen;
|
aPos->mContentOffset += contentLen;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
keepSearching = PR_FALSE;
|
keepSearching = PR_FALSE;
|
||||||
found = PR_TRUE;
|
found = PR_TRUE;
|
||||||
}
|
}
|
||||||
|
} // if we should eat space to the next word
|
||||||
|
else {
|
||||||
|
keepSearching = PR_FALSE;
|
||||||
|
found = PR_TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (aPos->mEatingWS)
|
else if (aPos->mEatingWS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,12 @@
|
||||||
#include "nsUnicharUtilCIID.h"
|
#include "nsUnicharUtilCIID.h"
|
||||||
#include "nsICaseConversion.h"
|
#include "nsICaseConversion.h"
|
||||||
#include "prenv.h"
|
#include "prenv.h"
|
||||||
|
#include "nsIPref.h"
|
||||||
|
|
||||||
|
|
||||||
|
PRPackedBool nsTextTransformer::sWordSelectPrefInited = PR_FALSE;
|
||||||
|
PRPackedBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
|
||||||
|
|
||||||
|
|
||||||
nsAutoTextBuffer::nsAutoTextBuffer()
|
nsAutoTextBuffer::nsAutoTextBuffer()
|
||||||
: mBuffer(mAutoBuffer),
|
: mBuffer(mAutoBuffer),
|
||||||
|
@ -102,6 +108,18 @@ nsresult
|
||||||
nsTextTransformer::Initialize()
|
nsTextTransformer::Initialize()
|
||||||
{
|
{
|
||||||
nsresult res = NS_OK;
|
nsresult res = NS_OK;
|
||||||
|
|
||||||
|
// read in our global word selection prefs
|
||||||
|
if ( !sWordSelectPrefInited ) {
|
||||||
|
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||||
|
if ( prefService ) {
|
||||||
|
PRBool temp = PR_FALSE;
|
||||||
|
prefService->GetBoolPref("layout.word_select.stop_at_punctuation", &temp);
|
||||||
|
sWordSelectStopAtPunctuation = temp;
|
||||||
|
}
|
||||||
|
sWordSelectPrefInited = PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
static nsresult EnsureCaseConv()
|
static nsresult EnsureCaseConv()
|
||||||
|
@ -377,6 +395,10 @@ nsTextTransformer::ScanNormalAsciiText_F_ForWordBreak(PRInt32* aWordLen,
|
||||||
else if (XP_IS_SPACE(ch)) {
|
else if (XP_IS_SPACE(ch)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (sWordSelectStopAtPunctuation && !isalnum(ch)) {
|
||||||
|
// on some platforms, punctuation breaks words too.
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (IS_DISCARDED(ch)) {
|
else if (IS_DISCARDED(ch)) {
|
||||||
// Strip discarded characters from the transformed output
|
// Strip discarded characters from the transformed output
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -275,6 +275,10 @@ protected:
|
||||||
// Flag for controling mLeaveAsAscii, mHasMultibyte, mTransformedTextIsAscii
|
// Flag for controling mLeaveAsAscii, mHasMultibyte, mTransformedTextIsAscii
|
||||||
PRUint8 mFlags;
|
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?
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void SelfTest(nsILineBreaker* aLineBreaker,
|
static void SelfTest(nsILineBreaker* aLineBreaker,
|
||||||
nsIWordBreaker* aWordBreaker,
|
nsIWordBreaker* aWordBreaker,
|
||||||
|
|
|
@ -783,6 +783,10 @@ protected:
|
||||||
PRBool aGetTextDimensions/* true=get dimensions false = return length up to aDimensionsResult->width size*/);
|
PRBool aGetTextDimensions/* true=get dimensions false = return length up to aDimensionsResult->width size*/);
|
||||||
nsresult GetContentAndOffsetsForSelection(nsIPresContext* aPresContext,nsIContent **aContent, PRInt32 *aOffset, PRInt32 *aLength);
|
nsresult GetContentAndOffsetsForSelection(nsIPresContext* aPresContext,nsIContent **aContent, PRInt32 *aOffset, PRInt32 *aLength);
|
||||||
|
|
||||||
|
// prefs used to configure the double-click word selection behavior
|
||||||
|
static PRPackedBool sWordSelectPrefInited; // have we read the prefs yet?
|
||||||
|
static PRPackedBool sWordSelectEatSpaceAfter; // should we include whitespace up to next word?
|
||||||
|
|
||||||
#ifdef IBMBIDI
|
#ifdef IBMBIDI
|
||||||
private:
|
private:
|
||||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
@ -806,6 +810,11 @@ NS_IMETHODIMP nsTextFrame::GetAccessible(nsIAccessible** aAccessible)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
PRPackedBool nsTextFrame::sWordSelectPrefInited = PR_FALSE;
|
||||||
|
PRPackedBool nsTextFrame::sWordSelectEatSpaceAfter = PR_TRUE;
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID,
|
NS_IMETHODIMP nsTextFrame::QueryInterface(const nsIID& aIID,
|
||||||
void** aInstancePtrResult)
|
void** aInstancePtrResult)
|
||||||
|
@ -1251,6 +1260,16 @@ NS_NewContinuingTextFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
||||||
|
|
||||||
nsTextFrame::nsTextFrame()
|
nsTextFrame::nsTextFrame()
|
||||||
{
|
{
|
||||||
|
// read in our global word selection prefs
|
||||||
|
if ( !sWordSelectPrefInited ) {
|
||||||
|
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||||
|
if ( prefService ) {
|
||||||
|
PRBool temp = PR_FALSE;
|
||||||
|
prefService->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp);
|
||||||
|
sWordSelectEatSpaceAfter = temp;
|
||||||
|
}
|
||||||
|
sWordSelectPrefInited = PR_TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsTextFrame::~nsTextFrame()
|
nsTextFrame::~nsTextFrame()
|
||||||
|
@ -4055,37 +4074,44 @@ nsTextFrame::PeekOffset(nsIPresContext* aPresContext, nsPeekOffsetStruct *aPos)
|
||||||
|
|
||||||
if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){
|
if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){
|
||||||
aPos->mContentOffset = aPos->mStartOffset + contentLen;
|
aPos->mContentOffset = aPos->mStartOffset + contentLen;
|
||||||
//check for whitespace next.
|
// check for whitespace next. On some platforms (mac), we want the selection to end
|
||||||
keepSearching = PR_TRUE;
|
// at the end of the word (not the beginning of the next one), so don't slurp up any extra whitespace.
|
||||||
aPos->mEatingWS = PR_TRUE;
|
if ( sWordSelectEatSpaceAfter ) {
|
||||||
if (!isWhitespace){
|
keepSearching = PR_TRUE;
|
||||||
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
aPos->mEatingWS = PR_TRUE;
|
||||||
{
|
if (!isWhitespace){
|
||||||
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
while (tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
||||||
goto TryNextFrame;
|
{
|
||||||
if (isWhitespace)
|
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
||||||
aPos->mContentOffset += contentLen;
|
goto TryNextFrame;
|
||||||
else
|
if (isWhitespace)
|
||||||
break;
|
aPos->mContentOffset += contentLen;
|
||||||
}
|
else
|
||||||
keepSearching = PR_FALSE;
|
break;
|
||||||
found = PR_TRUE;
|
}
|
||||||
}
|
keepSearching = PR_FALSE;
|
||||||
else //we just need to jump the space, done here
|
found = PR_TRUE;
|
||||||
{
|
}
|
||||||
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
else //we just need to jump the space, done here
|
||||||
{
|
{
|
||||||
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
while(tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &isWhitespace, &wasTransformed, PR_TRUE, PR_FALSE))
|
||||||
goto TryNextFrame;
|
{
|
||||||
|
if (aPos->mStartOffset + contentLen > (mContentLength + mContentOffset))
|
||||||
|
goto TryNextFrame;
|
||||||
|
|
||||||
if (isWhitespace)
|
if (isWhitespace)
|
||||||
aPos->mContentOffset += contentLen;
|
aPos->mContentOffset += contentLen;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
keepSearching = PR_FALSE;
|
keepSearching = PR_FALSE;
|
||||||
found = PR_TRUE;
|
found = PR_TRUE;
|
||||||
}
|
}
|
||||||
|
} // if we should eat space to the next word
|
||||||
|
else {
|
||||||
|
keepSearching = PR_FALSE;
|
||||||
|
found = PR_TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (aPos->mEatingWS)
|
else if (aPos->mEatingWS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,12 @@
|
||||||
#include "nsUnicharUtilCIID.h"
|
#include "nsUnicharUtilCIID.h"
|
||||||
#include "nsICaseConversion.h"
|
#include "nsICaseConversion.h"
|
||||||
#include "prenv.h"
|
#include "prenv.h"
|
||||||
|
#include "nsIPref.h"
|
||||||
|
|
||||||
|
|
||||||
|
PRPackedBool nsTextTransformer::sWordSelectPrefInited = PR_FALSE;
|
||||||
|
PRPackedBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE;
|
||||||
|
|
||||||
|
|
||||||
nsAutoTextBuffer::nsAutoTextBuffer()
|
nsAutoTextBuffer::nsAutoTextBuffer()
|
||||||
: mBuffer(mAutoBuffer),
|
: mBuffer(mAutoBuffer),
|
||||||
|
@ -102,6 +108,18 @@ nsresult
|
||||||
nsTextTransformer::Initialize()
|
nsTextTransformer::Initialize()
|
||||||
{
|
{
|
||||||
nsresult res = NS_OK;
|
nsresult res = NS_OK;
|
||||||
|
|
||||||
|
// read in our global word selection prefs
|
||||||
|
if ( !sWordSelectPrefInited ) {
|
||||||
|
nsCOMPtr<nsIPref> prefService ( do_GetService(NS_PREF_CONTRACTID) );
|
||||||
|
if ( prefService ) {
|
||||||
|
PRBool temp = PR_FALSE;
|
||||||
|
prefService->GetBoolPref("layout.word_select.stop_at_punctuation", &temp);
|
||||||
|
sWordSelectStopAtPunctuation = temp;
|
||||||
|
}
|
||||||
|
sWordSelectPrefInited = PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
static nsresult EnsureCaseConv()
|
static nsresult EnsureCaseConv()
|
||||||
|
@ -377,6 +395,10 @@ nsTextTransformer::ScanNormalAsciiText_F_ForWordBreak(PRInt32* aWordLen,
|
||||||
else if (XP_IS_SPACE(ch)) {
|
else if (XP_IS_SPACE(ch)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (sWordSelectStopAtPunctuation && !isalnum(ch)) {
|
||||||
|
// on some platforms, punctuation breaks words too.
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (IS_DISCARDED(ch)) {
|
else if (IS_DISCARDED(ch)) {
|
||||||
// Strip discarded characters from the transformed output
|
// Strip discarded characters from the transformed output
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -275,6 +275,10 @@ protected:
|
||||||
// Flag for controling mLeaveAsAscii, mHasMultibyte, mTransformedTextIsAscii
|
// Flag for controling mLeaveAsAscii, mHasMultibyte, mTransformedTextIsAscii
|
||||||
PRUint8 mFlags;
|
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?
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void SelfTest(nsILineBreaker* aLineBreaker,
|
static void SelfTest(nsILineBreaker* aLineBreaker,
|
||||||
nsIWordBreaker* aWordBreaker,
|
nsIWordBreaker* aWordBreaker,
|
||||||
|
|
|
@ -580,3 +580,7 @@ pref("bidi.characterset", 1);
|
||||||
|
|
||||||
|
|
||||||
pref("browser.throbber.url","chrome://navigator-region/locale/region.properties");
|
pref("browser.throbber.url","chrome://navigator-region/locale/region.properties");
|
||||||
|
|
||||||
|
// used for double-click word selection behavior. Mac will override.
|
||||||
|
pref("layout.word_select.eat_space_to_next_word", true);
|
||||||
|
pref("layout.word_select.stop_at_punctuation", false);
|
||||||
|
|
|
@ -44,6 +44,13 @@ pref("ui.key.saveLink.shift", false); // true = shift, false = meta
|
||||||
pref("editor.use_html_editor", false);
|
pref("editor.use_html_editor", false);
|
||||||
pref("editor.use_image_editor", false);
|
pref("editor.use_image_editor", false);
|
||||||
|
|
||||||
|
// override double-click word selection behavior.
|
||||||
|
pref("layout.word_select.eat_space_to_next_word", false);
|
||||||
|
pref("layout.word_select.stop_at_punctuation", true);
|
||||||
|
|
||||||
|
// should a GURL event open a new window or re-use (4.x compat)
|
||||||
|
pref("browser.always_reuse_window", false);
|
||||||
|
|
||||||
pref("mail.notification.sound", "");
|
pref("mail.notification.sound", "");
|
||||||
pref("mail.close_message_window.on_delete", true);
|
pref("mail.close_message_window.on_delete", true);
|
||||||
pref("mail.close_message_window.on_file", true);
|
pref("mail.close_message_window.on_file", true);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче