Bug 596088 - Make <input type='file'> looks disabled when inside a disabled fieldset by adding a ContentStatesChanged method in nsIFrame. r=bz sr=roc a=blocking-final

--HG--
rename : layout/reftests/bugs/557087.html => layout/reftests/bugs/557087-1.html
rename : layout/reftests/bugs/557087.html => layout/reftests/bugs/557087-2.html
extra : rebase_source : 350455e646775e42916e90dee7e09f63f84f4db4
This commit is contained in:
Mounir Lamouri 2010-12-14 10:00:57 -08:00
parent df9f4b15c7
commit db6bb54ae9
7 changed files with 85 additions and 14 deletions

View File

@ -8144,9 +8144,9 @@ nsCSSFrameConstructor::DoContentStateChanged(Element* aElement,
// If it's generated content, ignore LOADING/etc state changes on it.
if (!primaryFrame->IsGeneratedContentFrame() &&
aStateMask.HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN |
NS_EVENT_STATE_USERDISABLED |
NS_EVENT_STATE_SUPPRESSED |
NS_EVENT_STATE_LOADING)) {
NS_EVENT_STATE_USERDISABLED |
NS_EVENT_STATE_SUPPRESSED |
NS_EVENT_STATE_LOADING)) {
hint = nsChangeHint_ReconstructFrame;
} else {
PRUint8 app = primaryFrame->GetStyleDisplay()->mAppearance;
@ -8162,6 +8162,8 @@ nsCSSFrameConstructor::DoContentStateChanged(Element* aElement,
}
}
}
primaryFrame->ContentStatesChanged(aStateMask);
}
nsRestyleHint rshint =

View File

@ -97,7 +97,6 @@ namespace dom = mozilla::dom;
#define SYNC_TEXT 0x1
#define SYNC_BUTTON 0x2
#define SYNC_BOTH 0x3
nsIFrame*
NS_NewFileControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
@ -344,7 +343,7 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
systemGroup);
SyncAttr(kNameSpaceID_None, nsGkAtoms::size, SYNC_TEXT);
SyncAttr(kNameSpaceID_None, nsGkAtoms::disabled, SYNC_BOTH);
SyncDisabledState();
return NS_OK;
}
@ -589,17 +588,28 @@ nsFileControlFrame::SyncAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
}
}
void
nsFileControlFrame::SyncDisabledState()
{
nsEventStates eventStates = mContent->IntrinsicState();
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
PR_TRUE);
mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
PR_TRUE);
} else {
mTextContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE);
mBrowse->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, PR_TRUE);
}
}
NS_IMETHODIMP
nsFileControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
// propagate disabled to text / button inputs
if (aNameSpaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::disabled) {
SyncAttr(aNameSpaceID, aAttribute, SYNC_BOTH);
// propagate size to text
} else if (aAttribute == nsGkAtoms::size) {
if (aAttribute == nsGkAtoms::size) {
SyncAttr(aNameSpaceID, aAttribute, SYNC_TEXT);
} else if (aAttribute == nsGkAtoms::tabindex) {
SyncAttr(aNameSpaceID, aAttribute, SYNC_BUTTON);
@ -609,6 +619,14 @@ nsFileControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
return nsBlockFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
}
void
nsFileControlFrame::ContentStatesChanged(nsEventStates aStates)
{
if (aStates.HasState(NS_EVENT_STATE_DISABLED)) {
nsContentUtils::AddScriptRunner(new SyncDisabledStateEvent(this));
}
}
PRBool
nsFileControlFrame::IsLeaf() const
{

View File

@ -87,6 +87,7 @@ public:
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType);
virtual void ContentStatesChanged(nsEventStates aStates);
virtual PRBool IsLeaf() const;
@ -134,7 +135,28 @@ protected:
protected:
nsFileControlFrame* mFrame;
};
class SyncDisabledStateEvent;
friend class SyncDisabledStateEvent;
class SyncDisabledStateEvent : public nsRunnable
{
public:
SyncDisabledStateEvent(nsFileControlFrame* aFrame)
: mFrame(aFrame)
{}
NS_IMETHOD Run() {
nsFileControlFrame* frame = static_cast<nsFileControlFrame*>(mFrame.GetFrame());
NS_ENSURE_STATE(frame);
frame->SyncDisabledState();
return NS_OK;
}
private:
nsWeakFrame mFrame;
};
class CaptureMouseListener: public MouseListener {
public:
CaptureMouseListener(nsFileControlFrame* aFrame) : MouseListener(aFrame),
@ -203,11 +225,15 @@ private:
* Copy an attribute from file content to text and button content.
* @param aNameSpaceID namespace of attr
* @param aAttribute attribute atom
* @param aWhichControls which controls to apply to (SYNC_TEXT or SYNC_FILE
* or SYNC_BOTH)
* @param aWhichControls which controls to apply to (SYNC_TEXT or SYNC_FILE)
*/
void SyncAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRInt32 aWhichControls);
/**
* Sync the disabled state of the content with anonymous children.
*/
void SyncDisabledState();
};
#endif

View File

@ -1297,6 +1297,14 @@ public:
nsIAtom* aAttribute,
PRInt32 aModType) = 0;
/**
* When the content states of a content object change, this method is invoked
* on the primary frame of that content object.
*
* @param aStates the changed states
*/
virtual void ContentStatesChanged(nsEventStates aStates) { };
/**
* Return how your frame can be split.
*/

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<body onload="document.getElementsByTagName('fieldset')[0].disabled = true;
document.documentElement.className='';">
<fieldset>
<input type='file'>
<input type='checkbox'>
<input type='radio'>
<input>
<button>foo</button>
<textarea></textarea>
<select><option>foo</option></select>
<fieldset></fieldset>
</fieldset>
</body>
</html>

View File

@ -1447,7 +1447,8 @@ random-if(!haveTestPlugin) == 546071-1.html 546071-1-ref.html
== 552334-1.html 552334-1-ref.html
random-if(d2d) == 555388-1.html 555388-1-ref.html
== 556661-1.html 556661-1-ref.html
== 557087.html 557087-ref.html
== 557087-1.html 557087-ref.html
== 557087-2.html 557087-ref.html
== 557736-1.html 557736-1-ref.html
== 559284-1.html 559284-1-ref.html
== 560455-1.xul 560455-1-ref.xul