mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 28583. Select text field contents when focused, except by mouse click, on certain platforms. r=brade, sr=sfraser
This commit is contained in:
parent
435072c0fa
commit
f7218d0d8a
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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?
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user