Bug 948549 - Make <input type=number> behave and look disabled when the 'disabled' attribute is set or it's inside a disabled fieldset. r=smaug

This commit is contained in:
Jonathan Watt 2013-12-11 02:13:06 +00:00
parent d911eac635
commit 3c34ed2d2f
9 changed files with 83 additions and 1 deletions

View File

@ -150,11 +150,24 @@ nsNumberControlFrame::
xoffset, yoffset, 0);
}
void
nsNumberControlFrame::SyncDisabledState()
{
nsEventStates eventStates = mContent->AsElement()->State();
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
true);
} else {
mTextField->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
}
}
NS_IMETHODIMP
nsNumberControlFrame::AttributeChanged(int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
{
// nsGkAtoms::disabled is handled by SyncDisabledState
if (aNameSpaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::placeholder ||
aAttribute == nsGkAtoms::readonly ||
@ -175,6 +188,14 @@ nsNumberControlFrame::AttributeChanged(int32_t aNameSpaceID,
aModType);
}
void
nsNumberControlFrame::ContentStatesChanged(nsEventStates aStates)
{
if (aStates.HasState(NS_EVENT_STATE_DISABLED)) {
nsContentUtils::AddScriptRunner(new SyncDisabledStateEvent(this));
}
}
nsresult
nsNumberControlFrame::MakeAnonymousElement(Element** aResult,
nsTArray<ContentInfo>& aElements,
@ -310,6 +331,9 @@ nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
nsGkAtoms::div,
nsCSSPseudoElements::ePseudo_mozNumberSpinDown,
spinBoxCI.mStyleContext);
SyncDisabledState();
return rv;
}

View File

@ -43,7 +43,7 @@ public:
NS_DECL_FRAMEARENA_HELPERS
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
virtual void ContentStatesChanged(nsEventStates aStates);
virtual bool IsLeaf() const MOZ_OVERRIDE { return false; }
NS_IMETHOD Reflow(nsPresContext* aPresContext,
@ -142,6 +142,34 @@ private:
const nsHTMLReflowState& aReflowState,
nsIFrame* aOuterWrapperFrame);
class SyncDisabledStateEvent;
friend class SyncDisabledStateEvent;
class SyncDisabledStateEvent : public nsRunnable
{
public:
SyncDisabledStateEvent(nsNumberControlFrame* aFrame)
: mFrame(aFrame)
{}
NS_IMETHOD Run() MOZ_OVERRIDE
{
nsNumberControlFrame* frame =
static_cast<nsNumberControlFrame*>(mFrame.GetFrame());
NS_ENSURE_STATE(frame);
frame->SyncDisabledState();
return NS_OK;
}
private:
nsWeakFrame mFrame;
};
/**
* Sync the disabled state of the anonymous children up with our content's.
*/
void SyncDisabledState();
/**
* The text field used to edit and show the number.
* @see nsNumberControlFrame::CreateAnonymousContent.

View File

@ -5,6 +5,7 @@
<input type='file'>
<input type='checkbox'>
<input type='radio'>
<input type='number'>
<input>
<button>foo</button>
<textarea></textarea>

View File

@ -6,6 +6,7 @@
<input type='file'>
<input type='checkbox'>
<input type='radio'>
<input type='number'>
<input>
<button>foo</button>
<textarea></textarea>

View File

@ -5,6 +5,7 @@
<input type='file' disabled>
<input type='checkbox' disabled>
<input type='radio' disabled>
<input type='number' disabled>
<input disabled>
<button disabled>foo</button>
<textarea disabled></textarea>

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<input type="text" disabled>
<!-- div to cover spin box area -->
<div style="display:block; position:absolute; background-color:black; width:200px; height:100px; top:0px; left:100px;">
</body>
</html>

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
<input type="number" disabled>
<!-- div to cover spin box area -->
<div style="display:block; position:absolute; background-color:black; width:200px; height:100px; top:0px; left:100px;">
</body>
</html>

View File

@ -17,6 +17,9 @@ fuzzy-if(/^Windows\x20NT\x205\.1/.test(http.oscpu),64,4) fuzzy-if(cocoaWidget,63
# dynamic value changes:
== show-value.html show-value-ref.html
# disabled
== number-disabled.html number-disabled-ref.html
# focus
needs-focus == focus-handling.html focus-handling-ref.html

View File

@ -85,6 +85,14 @@ nsNativeTheme::GetContentState(nsIFrame* aFrame, uint8_t aWidgetType)
flags |= NS_EVENT_STATE_FOCUS;
}
}
nsNumberControlFrame* numberControlFrame =
nsNumberControlFrame::GetNumberControlFrameForSpinButton(aFrame);
if (numberControlFrame &&
numberControlFrame->GetContent()->AsElement()->State().
HasState(NS_EVENT_STATE_DISABLED)) {
flags |= NS_EVENT_STATE_DISABLED;
}
}
if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) {