Bug 28583. Select text field contents when focused, except by mouse click, on certain platforms. r=brade, sr=sfraser

This commit is contained in:
aaronl%netscape.com 2002-10-05 15:39:33 +00:00
parent 435072c0fa
commit f7218d0d8a
13 changed files with 94 additions and 2 deletions

View File

@ -141,6 +141,7 @@ nsIDocument * gLastFocusedDocument = 0; // Strong reference
nsIPresContext* gLastFocusedPresContext = 0; // Weak reference
PRInt32 nsEventStateManager::sTabFocusModel = eTabFocus_unset;
PRInt8 nsEventStateManager::sTextfieldSelectModel = eTextfieldSelect_unset;
PRUint32 nsEventStateManager::mInstanceCount = 0;
PRInt32 nsEventStateManager::gGeneralAccesskeyModifier = -1; // magic value of -1 means uninitialized
@ -219,6 +220,15 @@ nsEventStateManager::Init()
mPrefService->GetIntPref("ui.key.generalAccessKey", &nsEventStateManager::gGeneralAccesskeyModifier);
}
if (nsEventStateManager::sTextfieldSelectModel == eTextfieldSelect_unset) {
nsCOMPtr<nsILookAndFeel> lookNFeel(do_GetService(kLookAndFeelCID));
PRInt32 selectTextfieldsOnKeyFocus = 0;
lookNFeel->GetMetric(nsILookAndFeel::eMetric_SelectTextfieldsOnKeyFocus,
selectTextfieldsOnKeyFocus);
sTextfieldSelectModel = selectTextfieldsOnKeyFocus ? eTextfieldSelect_auto:
eTextfieldSelect_manual;
}
return rv;
}
@ -4797,6 +4807,23 @@ NS_IMETHODIMP nsEventStateManager::MoveFocusToCaret(PRBool aCanFocusDoc, PRBool
NS_IMETHODIMP nsEventStateManager::MoveCaretToFocus()
{
// First, select text fields when focused via keyboard (tab or accesskey)
if (sTextfieldSelectModel == eTextfieldSelect_auto &&
mCurrentFocus &&
mCurrentFocus->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(mCurrentFocus));
PRInt32 controlType;
formControl->GetType(&controlType);
if (controlType == NS_FORM_INPUT_TEXT ||
controlType == NS_FORM_INPUT_PASSWORD) {
nsCOMPtr<nsIDOMHTMLInputElement> inputElement =
do_QueryInterface(mCurrentFocus);
if (inputElement) {
inputElement->Select();
}
}
}
// If in HTML content and the pref accessibility.browsewithcaret is TRUE,
// then always move the caret to beginning of a new focus

View File

@ -79,6 +79,12 @@ class nsEventStateManager : public nsSupportsWeakReference,
eTabFocus_linksMask = (1<<2) // links
};
enum nsTextfieldSelectModel {
eTextfieldSelect_unset = -1,
eTextfieldSelect_manual = 0,
eTextfieldSelect_auto = 1, // select textfields when focused with keyboard
};
public:
nsEventStateManager();
virtual ~nsEventStateManager();
@ -283,6 +289,7 @@ protected:
// Tab focus policy (static, constant across the app):
// Which types of elements are in the tab order?
static PRInt32 sTabFocusModel;
static PRInt8 sTextfieldSelectModel;
// Recursion guard for tabbing
PRBool mTabbedThroughDocument;

View File

@ -160,6 +160,7 @@ public:
eMetric_SingleLineCaretWidth, // pixel width of caret in a single line field
eMetric_MultiLineCaretWidth, // pixel width of caret in a multi-line field
eMetric_ShowCaretDuringSelection, // show the caret when text is selected?
eMetric_SelectTextfieldsOnKeyFocus, // select textfields when focused via tab/accesskey?
eMetric_SubmenuDelay, // delay before submenus open
eMetric_MenusCanOverlapOSBar, // can popups overlap menu/task bar?
eMetric_DragFullWindow, // show window contents while dragging?

View File

@ -340,7 +340,12 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
aMetric = 2;
break;
case eMetric_ShowCaretDuringSelection:
aMetric =0;
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Do not select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 0;
break;
case eMetric_SubmenuDelay:
aMetric = 500;

View File

@ -477,6 +477,11 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -343,9 +343,14 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_MultiLineCaretWidth:
aMetric = 1;
break;
case eMetric_ShowCaretDuringSelection:
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -348,6 +348,11 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -477,6 +477,11 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -282,6 +282,11 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Do not select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 0;
break;
case eMetric_SubmenuDelay:
aMetric = 300;
break;

View File

@ -298,6 +298,14 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_MultiLineCaretWidth:
aMetric = 1;
break;
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Do not select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 0;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -342,6 +342,12 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric)
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;

View File

@ -277,6 +277,11 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
{
static PRInt32 sSubmenuDelay = -1;

View File

@ -274,6 +274,14 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
case eMetric_MultiLineCaretWidth:
aMetric = 1;
break;
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SelectTextfieldsOnKeyFocus:
// Select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aMetric = 1;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;