Bug 1352799 - Always set maxlength on initializing editor. r=masayuki
maxlength will be set by nsTextControlFrame::AttributeChanged via RestyleManager. If element is display:none, RestyleManager won't call Frame's AttributeChanged. So we should always initialize maxlength when setting focus. Also, wrap attribute for textarea element will be updated by HTMLTextAreaElement even if display:none. So this issue doesn't occur. maxlength might have to be updated by HTMLInputElement. But it is unnecessary to update editor's maxlength on display:none since this is used on focused editor. MozReview-Commit-ID: JHODOBTv62v
This commit is contained in:
@@ -1462,19 +1462,16 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue)
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldInitializeEditor) {
|
||||
// Initialize the plaintext editor
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor(do_QueryInterface(newEditor));
|
||||
if (textEditor) {
|
||||
// Initialize the plaintext editor
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(newEditor);
|
||||
if (textEditor) {
|
||||
if (shouldInitializeEditor) {
|
||||
// Set up wrapping
|
||||
textEditor->SetWrapColumn(GetWrapCols());
|
||||
|
||||
// Set max text field length
|
||||
int32_t maxLength;
|
||||
if (GetMaxLength(&maxLength)) {
|
||||
textEditor->SetMaxTextLength(maxLength);
|
||||
}
|
||||
}
|
||||
|
||||
// Set max text field length
|
||||
textEditor->SetMaxTextLength(GetMaxLength());
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mTextCtrlElement);
|
||||
@@ -2333,22 +2330,22 @@ nsTextEditorState::CreatePreviewNode()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsTextEditorState::GetMaxLength(int32_t* aMaxLength)
|
||||
int32_t
|
||||
nsTextEditorState::GetMaxLength()
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mTextCtrlElement);
|
||||
nsGenericHTMLElement* element =
|
||||
nsGenericHTMLElement::FromContentOrNull(content);
|
||||
NS_ENSURE_TRUE(element, false);
|
||||
if (NS_WARN_IF(!element)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const nsAttrValue* attr = element->GetParsedAttr(nsGkAtoms::maxlength);
|
||||
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
||||
*aMaxLength = attr->GetIntegerValue();
|
||||
|
||||
return true;
|
||||
return attr->GetIntegerValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user