Bug 638293 - When the value of <input type=number> changes, keep its anonymous text input field child in sync as appropriate. r=smaug

This commit is contained in:
Jonathan Watt 2011-06-21 16:17:10 +02:00
parent 812c62e395
commit 3a0e546acc
6 changed files with 98 additions and 0 deletions

View File

@ -2696,6 +2696,14 @@ HTMLInputElement::SetValueInternal(const nsAString& aValue,
SetValueChanged(true);
}
OnValueChanged(!mParserCreating);
if (mType == NS_FORM_INPUT_NUMBER) {
nsNumberControlFrame* numberControlFrame =
do_QueryFrame(GetPrimaryFrame());
if (numberControlFrame) {
numberControlFrame->UpdateForValueChange(value);
}
}
}
// Call parent's SetAttr for color input so its control frame is notified

View File

@ -223,6 +223,11 @@ nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("text"), PR_FALSE);
// Initialize the text field value:
nsAutoString value;
HTMLInputElement::FromContent(mContent)->GetValue(value);
mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::value, value, false);
if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS)) {
// We don't want to focus the frame but the text field.
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
@ -277,3 +282,13 @@ nsNumberControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
// Only one direct anonymous child:
aElements.MaybeAppendElement(mOuterWrapper);
}
void
nsNumberControlFrame::UpdateForValueChange(const nsAString& aValue)
{
// We need to update the value of our anonymous text control here. Note that
// this must be its value, and not its 'value' attribute (the default value),
// since the default value is ignored once a user types into the text
// control.
HTMLInputElement::FromContent(mTextField)->SetValue(aValue);
}

View File

@ -65,6 +65,12 @@ public:
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
}
/**
* When our HTMLInputElement's value changes, it calls this method to tell
* us to sync up our anonymous text input field child.
*/
void UpdateForValueChange(const nsAString& aValue);
HTMLInputElement* GetAnonTextControl();
private:

View File

@ -14,6 +14,9 @@ skip-if(!Android&&!B2G) == number-same-as-text-unthemed.html number-same-as-text
fuzzy-if(/^Windows\x20NT\x205\.1/.test(http.oscpu),64,4) fuzzy-if(cocoaWidget,63,4) == to-number-from-other-type-unthemed-1.html to-number-from-other-type-unthemed-1-ref.html
== from-number-to-other-type-unthemed-1.html from-number-to-other-type-unthemed-1-ref.html
# dynamic value changes:
== show-value.html show-value-ref.html
# focus
fails-if(B2G) needs-focus == focus-handling.html focus-handling-ref.html # bug 940760

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
input {
-moz-appearance: none;
}
</style>
</head>
<body>
<input value='42'><br>
<input value='42'><br>
<input value='42'><br>
<input value='42'><br>
<input value='42'><br>
<form>
<input value='42'>
</form>
<!-- div to cover spin box area for type=number to type=text comparison -->
<div style="display:block; position:absolute; background-color:black; width:200px; height:400px; top:0px; left:100px;">
</body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<head>
<meta charset="utf-8">
<style>
input {
-moz-appearance: none;
}
</style>
<script>
function run() {
var numbers = document.getElementsByTagName('input');
numbers[2].style.display = 'inline-block'; // none -> inline-block
numbers[3].setAttribute('value', '42');
numbers[4].value = '42';
numbers[5].varue = '1337'; // deliberately misspelt - should not set value
document.forms[0].reset(); // numbers[5] value should be 42 again.
document.documentElement.className = '';
}
document.addEventListener("MozReftestInvalidate", run);
</script>
</head>
<body onload="run();">
<input type='number' value='42'><br>
<input value='42' type='number'><br>
<input type='number' value='42' style="display: none;"><br>
<input type='number' value='1337'><br>
<input type='number' value='1337'><br>
<form>
<input type='number' value='42'>
</form>
<!-- div to cover spin box area for type=number to type=text comparison -->
<div style="display:block; position:absolute; background-color:black; width:200px; height:400px; top:0px; left:100px;">
</body>
</html>