Bug 420499 - "Caret browsing mode wrongly engaged" (Mochitest) [p=chris@pearce.org.nz (Chris Pearce [cpearce]) r+sr=roc a=blocking1.9+]

This commit is contained in:
reed@reedloden.com 2008-04-08 11:52:48 -07:00
parent dce1fd1773
commit daf0485896
6 changed files with 125 additions and 4 deletions

View File

@ -51,7 +51,7 @@ interface nsIDOMNode;
interface nsISelection;
interface nsISelectionDisplay;
[scriptable, uuid(80d2e85a-4ad2-45be-88e7-8c1fe943ac4d)]
[scriptable, uuid(513b9460-d56a-4c4e-b6f9-0b8ae4372a3b)]
interface nsISelectionController : nsISelectionDisplay
{
const short SELECTION_NONE=0;
@ -140,6 +140,13 @@ interface nsISelectionController : nsISelectionDisplay
*/
boolean getCaretEnabled();
/**
* This is true if the caret is enabled, visible, and currently blinking.
* This is still true when the caret is enabled, visible, but in its "off"
* blink cycle.
*/
readonly attribute boolean caretVisible;
/**
* Show the caret even in selections. By default the caret is hidden unless the
* selection is collapsed. Use this function to show the caret even in selections.
@ -252,6 +259,6 @@ interface nsISelectionController : nsISelectionDisplay
};
%{ C++
#define NS_ISELECTIONCONTROLLER_CID \
{ 0xd2d1d179, 0x85a7, 0x11d3, \
{ 0x99, 0x32, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }}
{ 0x513b9460, 0xd56a, 0x4c4e, \
{ 0xb6, 0xf9, 0x0b, 0x8a, 0xe4, 0x37, 0x2a, 0x3b }}
%}

View File

@ -242,7 +242,7 @@ NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible)
NS_IMETHODIMP nsCaret::GetCaretVisible(PRBool *outMakeVisible)
{
NS_ENSURE_ARG_POINTER(outMakeVisible);
*outMakeVisible = mVisible;
*outMakeVisible = (mVisible && MustDrawCaret(PR_TRUE));
return NS_OK;
}

View File

@ -920,6 +920,7 @@ public:
NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly);
NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled);
NS_IMETHOD SetCaretVisibilityDuringSelection(PRBool aVisibility);
NS_IMETHOD GetCaretVisible(PRBool *_retval);
virtual void SetCaret(nsICaret *aNewCaret);
virtual void RestoreCaret();
@ -2740,6 +2741,16 @@ NS_IMETHODIMP PresShell::SetCaretVisibilityDuringSelection(PRBool aVisibility)
return NS_OK;
}
NS_IMETHODIMP PresShell::GetCaretVisible(PRBool *aOutIsVisible)
{
*aOutIsVisible = PR_FALSE;
if (mCaret) {
nsresult rv = mCaret->GetCaretVisible(aOutIsVisible);
NS_ENSURE_SUCCESS(rv,rv);
}
return NS_OK;
}
NS_IMETHODIMP PresShell::SetSelectionFlags(PRInt16 aInEnable)
{
mSelectionFlags = aInEnable;

View File

@ -90,6 +90,7 @@ _TEST_FILES = \
test_bug399951.html \
test_bug404209.xhtml \
test_bug416896.html \
test_bug420499.xul \
$(NULL)
# test_bug396024.html is currently disabled because it interacts badly with
# the "You can't print-preview while the page is loading" dialog.

View File

@ -0,0 +1,95 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=420499
-->
<window title="Mozilla Bug 420499" onload="setTimeout(focusInput, 500);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js" />
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<menu id="menu" label="Menu">
<menupopup id="file-popup">
<!-- <textbox id="some-text" maxlength="10" value="some text"/> -->
<menu label="submenu">
<menupopup id="file-popup-inner">
<menuitem label="Item1"/>
<menuitem label="Item2"/>
<textbox id="some-text" maxlength="10" value="some more text"/>
</menupopup>
</menu>
<menuitem label="Item3"/>
<menuitem label="Item4"/>
</menupopup>
</menu>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml" bgcolor="white">
<p id="par1">Paragraph 1</p>
<p id="par2">Paragraph 2</p>
<p id="par3">Paragraph 3</p>
<p id="par4">Paragraph 4</p>
<p id="par5">Paragraph 5</p>
<input type="text" id="text-input" maxlength="10" value="some more text"/> <br />
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420499"
target="_blank">Mozilla Bug 420499</a>
</body>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Bug 420499 **/
SimpleTest.waitForExplicitFinish();
function getSelectionController() {
return document.docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController);
}
function isCaretVisible() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var selCon = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController);
return selCon.caretVisible;
}
function focusInput() {
ok(!isCaretVisible(), "Caret shouldn't be visible");
$("text-input").focus();
ok(isCaretVisible(), "Caret should be visible when input focused");
window.addEventListener("popupshown", popupMenuShownHandler, false);
$("menu").open = true;
}
function popupMenuShownHandler() {
window.removeEventListener("popupshown", popupMenuShownHandler, false);
ok(!isCaretVisible(), "Caret shouldn't be visible when menu open");
window.addEventListener("popuphidden", ensureParagraphFocused, false);
$("menu").open = false;
}
function ensureParagraphFocused() {
window.removeEventListener("popuphidden", ensureParagraphFocused, false);
ok(isCaretVisible(), "Caret should have returned to previous focus");
SimpleTest.finish();
}
]]></script>
</window>

View File

@ -579,6 +579,7 @@ public:
NS_IMETHOD SetCaretEnabled(PRBool enabled);
NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly);
NS_IMETHOD GetCaretEnabled(PRBool *_retval);
NS_IMETHOD GetCaretVisible(PRBool *_retval);
NS_IMETHOD SetCaretVisibilityDuringSelection(PRBool aVisibility);
NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend);
NS_IMETHOD CharacterExtendForDelete();
@ -754,6 +755,12 @@ nsTextInputSelectionImpl::SetCaretReadOnly(PRBool aReadOnly)
NS_IMETHODIMP
nsTextInputSelectionImpl::GetCaretEnabled(PRBool *_retval)
{
return GetCaretVisible(_retval);
}
NS_IMETHODIMP
nsTextInputSelectionImpl::GetCaretVisible(PRBool *_retval)
{
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsresult result;