зеркало из https://github.com/mozilla/gecko-dev.git
Bug 274626 - Show tooltips for disabled elements. r=smaug
This commit is contained in:
Родитель
5995592cc2
Коммит
a32bd1dff7
|
@ -2875,6 +2875,20 @@ nsGenericHTMLFormElement::FormIdUpdated(Element* aOldElement,
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGenericHTMLFormElement::IsElementDisabledForEvents(PRUint32 aMessage,
|
||||
nsIFrame* aFrame)
|
||||
{
|
||||
PRBool disabled = IsDisabled();
|
||||
if (!disabled && aFrame) {
|
||||
const nsStyleUserInterface* uiStyle = aFrame->GetStyleUserInterface();
|
||||
disabled = uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED;
|
||||
|
||||
}
|
||||
return disabled && aMessage != NS_MOUSE_MOVE;
|
||||
}
|
||||
|
||||
void
|
||||
nsGenericHTMLFormElement::UpdateFormOwner(bool aBindToTree,
|
||||
Element* aFormIdElement)
|
||||
|
|
|
@ -946,6 +946,9 @@ protected:
|
|||
static PRBool FormIdUpdated(Element* aOldElement, Element* aNewElement,
|
||||
void* aData);
|
||||
|
||||
// Returns true if the event should not be handled from PreHandleEvent
|
||||
virtual PRBool IsElementDisabledForEvents(PRUint32 aMessage, nsIFrame* aFrame);
|
||||
|
||||
// The focusability state of this form control. eUnfocusable means that it
|
||||
// shouldn't be focused at all, eInactiveWindow means it's in an inactive
|
||||
// window, eActiveWindow means it's in an active window.
|
||||
|
|
|
@ -282,23 +282,15 @@ nsHTMLButtonElement::ParseAttribute(PRInt32 aNamespaceID,
|
|||
nsresult
|
||||
nsHTMLButtonElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
||||
{
|
||||
// Do not process any DOM events if the element is disabled
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsDisabled()) {
|
||||
return NS_OK;
|
||||
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
|
||||
nsIFrame* formFrame = NULL;
|
||||
if (formControlFrame) {
|
||||
formFrame = do_QueryFrame(formControlFrame);
|
||||
}
|
||||
|
||||
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
|
||||
|
||||
if (formControlFrame) {
|
||||
nsIFrame* formFrame = do_QueryFrame(formControlFrame);
|
||||
if (formFrame) {
|
||||
const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
|
||||
|
||||
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
||||
return NS_OK;
|
||||
}
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsElementDisabledForEvents(aVisitor.mEvent->message, formFrame)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Track whether we're in the outermost Dispatch invocation that will
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "nsStyleConsts.h"
|
||||
#include "nsIForm.h"
|
||||
#include "nsIFormControl.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsEventDispatcher.h"
|
||||
|
||||
|
||||
|
@ -109,7 +110,7 @@ nsHTMLFieldSetElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|||
{
|
||||
// Do not process any DOM events if the element is disabled.
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsDisabled()) {
|
||||
if (IsElementDisabledForEvents(aVisitor.mEvent->message, NULL)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1854,24 +1854,10 @@ nsHTMLInputElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|||
{
|
||||
// Do not process any DOM events if the element is disabled
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsDisabled()) {
|
||||
if (IsElementDisabledForEvents(aVisitor.mEvent->message, GetPrimaryFrame())) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// For some reason or another we also need to check if the style shows us
|
||||
// as disabled.
|
||||
{
|
||||
nsIFrame* frame = GetPrimaryFrame();
|
||||
if (frame) {
|
||||
const nsStyleUserInterface* uiStyle = frame->GetStyleUserInterface();
|
||||
|
||||
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the editor if needed.
|
||||
if (NeedToInitializeEditorForEvent(aVisitor)) {
|
||||
nsITextControlFrame* textControlFrame = do_QueryFrame(GetPrimaryFrame());
|
||||
|
|
|
@ -1504,24 +1504,15 @@ nsHTMLSelectElement::GetAttributeMappingFunction() const
|
|||
nsresult
|
||||
nsHTMLSelectElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
||||
{
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
// Do not process any DOM events if the element is disabled
|
||||
// XXXsmaug This is not the right thing to do. But what is?
|
||||
if (IsDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
|
||||
nsIFrame* formFrame = nsnull;
|
||||
if (formControlFrame) {
|
||||
formFrame = do_QueryFrame(formControlFrame);
|
||||
}
|
||||
|
||||
if (formControlFrame &&
|
||||
(formFrame = do_QueryFrame(formControlFrame))) {
|
||||
const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
|
||||
|
||||
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
|
||||
return NS_OK;
|
||||
}
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsElementDisabledForEvents(aVisitor.mEvent->message, formFrame)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsGenericHTMLFormElement::PreHandleEvent(aVisitor);
|
||||
|
|
|
@ -677,23 +677,15 @@ nsHTMLTextAreaElement::GetAttributeMappingFunction() const
|
|||
nsresult
|
||||
nsHTMLTextAreaElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
||||
{
|
||||
// Do not process any DOM events if the element is disabled
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsDisabled()) {
|
||||
return NS_OK;
|
||||
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
|
||||
nsIFrame* formFrame = NULL;
|
||||
if (formControlFrame) {
|
||||
formFrame = do_QueryFrame(formControlFrame);
|
||||
}
|
||||
|
||||
nsIFormControlFrame* formControlFrame = GetFormControlFrame(PR_FALSE);
|
||||
nsIFrame* formFrame = nsnull;
|
||||
|
||||
if (formControlFrame &&
|
||||
(formFrame = do_QueryFrame(formControlFrame))) {
|
||||
const nsStyleUserInterface* uiStyle = formFrame->GetStyleUserInterface();
|
||||
|
||||
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
|
||||
return NS_OK;
|
||||
}
|
||||
aVisitor.mCanHandle = PR_FALSE;
|
||||
if (IsElementDisabledForEvents(aVisitor.mEvent->message, formFrame)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Don't dispatch a second select event if we are already handling
|
||||
|
|
|
@ -91,6 +91,7 @@ _TEST_FILES = \
|
|||
bug277890_iframe.html \
|
||||
bug277890_load.html \
|
||||
test_bug277890.html \
|
||||
test_bug274626.html \
|
||||
test_bug287465.html \
|
||||
test_bug209275.xhtml \
|
||||
file_bug209275_1.html \
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=274626
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 274626</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=274626">Mozilla Bug 274626</a>
|
||||
<br>
|
||||
|
||||
<input id='textbox_enabled' title='hello' value='hello' />
|
||||
<input id='textbox_disabled' title='hello' value='hello' disabled/>
|
||||
|
||||
<br>
|
||||
<input id='input_button_enabled' title='hello' value='hello' type='button' />
|
||||
<input id='input_button_disabled' title='hello' value='hello' type='button' disabled />
|
||||
|
||||
<br>
|
||||
<input id='checkbox_enabled' title='hello' type='checkbox'>hello</input>
|
||||
<input id='checkbox_disabled' title='hello' type='checkbox' disabled >hello</input>
|
||||
|
||||
<br>
|
||||
<button id='button_enabled' title='hello' value='hello' type='button'>test</button>
|
||||
<button id='button_disabled' title='hello' value='hello' type='button' disabled>test</button>
|
||||
|
||||
<br>
|
||||
<textarea id='textarea_enabled' title='hello' value='hello' onclick="alert('click event');"> </textarea>
|
||||
<textarea id='textarea_disabled' title='hello' value='hello' onclick="alert('click event');" disabled></textarea>
|
||||
|
||||
|
||||
<br>
|
||||
<select id='select_enabled' title='hello' onclick="alert('click event');">
|
||||
<option value='item1'>item1</option>
|
||||
<option value='item2'>item2</option>
|
||||
</select>
|
||||
<select id='select_disabled' title='hello' onclick="alert('click event');" disabled>
|
||||
<option value='item1'>item1</option>
|
||||
<option value='item2'>item2</option>
|
||||
</select>
|
||||
|
||||
<br>
|
||||
<form>
|
||||
<fieldset id='fieldset_enabled' title='hello' onclick="alert('click event');">
|
||||
<legend>Enabled fieldset:</legend>
|
||||
Name: <input type='text' size='30' /><br />
|
||||
Email: <input type='text' size='30' /><br />
|
||||
Date of birth: <input type='text' size='10' />
|
||||
</fieldset>
|
||||
</form>
|
||||
<form>
|
||||
<fieldset id='fieldset_disabled' title='hello' onclick="alert('click event');" disabled>
|
||||
<legend>Disabled fieldset:</legend>
|
||||
Name: <input type='text' size='30' /><br />
|
||||
Email: <input type='text' size='30' /><br />
|
||||
Date of birth: <input type='text' size='10' />
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
|
||||
/** Test for Bug 274626 **/
|
||||
|
||||
function HandlesMouseMove(evt) {
|
||||
evt.target.handlesMouseMove = true;
|
||||
}
|
||||
|
||||
var controls=["textbox_enabled","textbox_disabled",
|
||||
"input_button_enabled", "input_button_disabled", "checkbox_enabled",
|
||||
"checkbox_disabled", "button_enabled", "button_disabled",
|
||||
"textarea_enabled", "textarea_disabled", "select_enabled",
|
||||
"select_disabled", "fieldset_enabled", "fieldset_disabled"];
|
||||
|
||||
for each(id in controls) {
|
||||
var ctrl = document.getElementById(id);
|
||||
ctrl.addEventListener('mousemove', HandlesMouseMove, false);
|
||||
ctrl.handlesMouseMove = false;
|
||||
var evt = document.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("mousemove", true, true, window,
|
||||
0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
ctrl.dispatchEvent(evt);
|
||||
|
||||
// Mouse move events are what causes tooltips to show up.
|
||||
// Before this fix we would not allow mouse move events to go through
|
||||
// which in turn did not allow tooltips to be displayed.
|
||||
// This test will ensure that all HTML elements handle mouse move events
|
||||
// so that tooltips can be displayed
|
||||
ok(ctrl.handlesMouseMove, "Disabled element need mouse move for tooltips");
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче