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
Родитель 778255c67a
Коммит aa54b70658
13 изменённых файлов: 88 добавлений и 421 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -1,419 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John C. Griggs <johng@corel.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLookAndFeel.h"
#include "nsQApplication.h"
#include <qpalette.h>
#define QCOLOR_TO_NS_RGB(c) \
((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
{
}
nsLookAndFeel::~nsLookAndFeel()
{
}
nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID,nscolor &aColor)
{
nsresult res = NS_OK;
if (!qApp)
return NS_ERROR_FAILURE;
QPalette palette = qApp->palette();
QColorGroup normalGroup = palette.inactive();
QColorGroup activeGroup = palette.active();
QColorGroup disabledGroup = palette.disabled();
switch (aID) {
case eColor_WindowBackground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_WindowForeground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eColor_WidgetBackground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_WidgetForeground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
break;
case eColor_WidgetSelectBackground:
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
case eColor_WidgetSelectForeground:
aColor = QCOLOR_TO_NS_RGB(activeGroup.foreground());
break;
case eColor_Widget3DHighlight:
aColor = NS_RGB(0xa0,0xa0,0xa0);
break;
case eColor_Widget3DShadow:
aColor = NS_RGB(0x40,0x40,0x40);
break;
case eColor_TextBackground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_TextForeground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_TextSelectBackground:
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
break;
case eColor_TextSelectForeground:
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
break;
case eColor_activeborder:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_activecaption:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_appworkspace:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_background:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_captiontext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_graytext:
aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
break;
case eColor_highlight:
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
break;
case eColor_highlighttext:
aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
break;
case eColor_inactiveborder:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_inactivecaption:
aColor = QCOLOR_TO_NS_RGB(disabledGroup.background());
break;
case eColor_inactivecaptiontext:
aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
break;
case eColor_infobackground:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_infotext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_menu:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_menutext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_scrollbar:
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
case eColor_threedface:
case eColor_buttonface:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_buttonhighlight:
case eColor_threedhighlight:
aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
break;
case eColor_buttontext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor_buttonshadow:
case eColor_threedshadow:
aColor = QCOLOR_TO_NS_RGB(normalGroup.shadow());
break;
case eColor_threeddarkshadow:
aColor = QCOLOR_TO_NS_RGB(normalGroup.dark());
break;
case eColor_threedlightshadow:
aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
break;
case eColor_window:
case eColor_windowframe:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor_windowtext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
// from the CSS3 working draft (not yet finalized)
// http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
case eColor__moz_field:
aColor = QCOLOR_TO_NS_RGB(normalGroup.base());
break;
case eColor__moz_fieldtext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor__moz_dialog:
aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
break;
case eColor__moz_dialogtext:
aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
break;
case eColor__moz_dragtargetzone:
aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
break;
default:
aColor = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric)
{
nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eMetric_WindowTitleHeight:
aMetric = 0;
break;
case eMetric_WindowBorderWidth:
// There was once code in nsDeviceContextQT::GetSystemAttribute to
// use the border width obtained from a widget in its Init method.
break;
case eMetric_WindowBorderHeight:
// There was once code in nsDeviceContextQT::GetSystemAttribute to
// use the border width obtained from a widget in its Init method.
break;
case eMetric_Widget3DBorder:
aMetric = 4;
break;
case eMetric_TextFieldHeight:
aMetric = 15;
break;
case eMetric_TextFieldBorder:
aMetric = 2;
break;
case eMetric_TextVerticalInsidePadding:
aMetric = 0;
break;
case eMetric_TextShouldUseVerticalInsidePadding:
aMetric = 0;
break;
case eMetric_TextHorizontalInsideMinimumPadding:
aMetric = 15;
break;
case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
aMetric = 1;
break;
case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
aMetric = 10;
break;
case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
aMetric = 8;
break;
case eMetric_CheckboxSize:
aMetric = 15;
break;
case eMetric_RadioboxSize:
aMetric = 15;
break;
case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
aMetric = 15;
break;
case eMetric_ListHorizontalInsideMinimumPadding:
aMetric = 15;
break;
case eMetric_ListShouldUseVerticalInsidePadding:
aMetric = 1;
break;
case eMetric_ListVerticalInsidePadding:
aMetric = 1;
break;
case eMetric_CaretBlinkTime:
aMetric = 500;
break;
case eMetric_SingleLineCaretWidth:
case eMetric_MultiLineCaretWidth:
aMetric = 1;
break;
case eMetric_ShowCaretDuringSelection:
aMetric = 0;
break;
case eMetric_SubmenuDelay:
aMetric = 200;
break;
case eMetric_MenusCanOverlapOSBar:
// we want XUL popups to be able to overlap the task bar.
aMetric = 1;
break;
case eMetric_DragFullWindow:
aMetric = 1;
break;
case eMetric_ScrollArrowStyle:
aMetric = eMetric_ScrollArrowStyleSingle;
break;
case eMetric_ScrollSliderStyle:
aMetric = eMetric_ScrollThumbStyleProportional;
break;
default:
aMetric = 0;
res = NS_ERROR_FAILURE;
}
return res;
}
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID,
float &aMetric)
{
nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eMetricFloat_TextFieldVerticalInsidePadding:
aMetric = 0.25f;
break;
case eMetricFloat_TextFieldHorizontalInsidePadding:
aMetric = 0.95f; // large number on purpose so minimum padding is used
break;
case eMetricFloat_TextAreaVerticalInsidePadding:
aMetric = 0.40f;
break;
case eMetricFloat_TextAreaHorizontalInsidePadding:
aMetric = 0.40f; // large number on purpose so minimum padding is used
break;
case eMetricFloat_ListVerticalInsidePadding:
aMetric = 0.10f;
break;
case eMetricFloat_ListHorizontalInsidePadding:
aMetric = 0.40f;
break;
case eMetricFloat_ButtonVerticalInsidePadding:
aMetric = 0.25f;
break;
case eMetricFloat_ButtonHorizontalInsidePadding:
aMetric = 0.25f;
break;
default:
aMetric = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
}

Просмотреть файл

@ -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;