Bug 956530 - Clear the delayed caret data when clicking on a selected part of a text control if the focus event handler selects the control; r=roc

This commit is contained in:
Ehsan Akhgari 2015-04-11 14:42:57 -04:00
parent 6a644bd5e1
commit 3ca164861a
7 changed files with 64 additions and 4 deletions

View File

@ -109,6 +109,7 @@
#include "HTMLSplitOnSpacesTokenizer.h"
#include "nsIController.h"
#include "nsIMIMEInfo.h"
#include "nsFrameSelection.h"
// input type=date
#include "js/Date.h"
@ -3285,6 +3286,19 @@ HTMLInputElement::Select()
return NS_OK;
}
nsTextEditorState* tes = GetEditorState();
if (tes) {
nsFrameSelection* fs = tes->GetConstFrameSelection();
if (fs && fs->MouseDownRecorded()) {
// This means that we're being called while the frame selection has a mouse
// down event recorded to adjust the caret during the mouse up event.
// We are probably called from the focus event handler. We should override
// the delayed caret data in this case to ensure that this select() call
// takes effect.
fs->SetDelayedCaretData(nullptr);
}
}
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
nsRefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html class="reftest-wait">
<script>
function test() {
focus();
var i = document.querySelector("input");
i.focus();
document.documentElement.removeAttribute("class");
}
</script>
<body onload="setTimeout(test, 0)">
<input value="text text text text text"
onfocus="this.select()">
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html class="reftest-wait">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script>
function test() {
focus();
var i = document.querySelector("input");
synthesizeMouseAtCenter(i, {});
setTimeout(function() {
synthesizeMouseAtCenter(document.body, {});
setTimeout(function() {
synthesizeMouseAtCenter(i, {});
setTimeout(function() {
document.documentElement.removeAttribute("class");
}, 0);
}, 0);
}, 0);
}
</script>
<body onload="setTimeout(test, 0)">
<input value="text text text text text"
onfocus="this.select()">
</body>
</html>

View File

@ -13,6 +13,8 @@ support-files =
enableTestPlugin.js
bug558663.html
bug644768.html
bug956530-1.html
bug956530-1-ref.html
bug989012-1.html
bug989012-1-ref.html
bug989012-2.html

View File

@ -143,6 +143,7 @@ var tests = [
[ 'bug682712-1.html' , 'bug682712-1-ref.html' ] ,
function() {SpecialPowers.pushPrefEnv({'clear': [['bidi.browser.ui']]}, nextTest);} ,
[ 'bug746993-1.html' , 'bug746993-1-ref.html' ] ,
[ 'bug956530-1.html' , 'bug956530-1-ref.html' ] ,
[ 'bug989012-1.html' , 'bug989012-1-ref.html' ] ,
[ 'bug989012-2.html' , 'bug989012-2-ref.html' ] ,
[ 'bug989012-3.html' , 'bug989012-3-ref.html' ] ,

View File

@ -3327,10 +3327,7 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext,
// If not, the user must have clicked in a part of the selection.
// Place the caret before continuing!
bool mouseDown = frameselection->GetDragState();
if (!mouseDown && frameselection->HasDelayedCaretData() &&
frameselection->GetClickCountInDelayedCaretData() < 2) {
if (frameselection->MouseDownRecorded()) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
handleTableSelection = false;

View File

@ -517,6 +517,13 @@ public:
return mDelayedMouseEventClickCount;
}
bool MouseDownRecorded()
{
return !GetDragState() &&
HasDelayedCaretData() &&
GetClickCountInDelayedCaretData() < 2;
}
/** Get the content node that limits the selection
* When searching up a nodes for parents, as in a text edit field
* in an browser page, we must stop at this node else we reach into the