mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 303896 - Refactor AttributeChanged() to follow code style and make it easier to read (no functional change). r=ehsan
This commit is contained in:
parent
127dd8ead1
commit
e677cfd801
@ -1108,82 +1108,73 @@ nsTextControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
if (needEditor) {
|
||||
GetEditor(getter_AddRefs(editor));
|
||||
}
|
||||
if ((needEditor && !editor) || !selCon)
|
||||
if ((needEditor && !editor) || !selCon) {
|
||||
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (nsGkAtoms::maxlength == aAttribute)
|
||||
{
|
||||
if (nsGkAtoms::maxlength == aAttribute) {
|
||||
int32_t maxLength;
|
||||
bool maxDefined = GetMaxLength(&maxLength);
|
||||
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(editor);
|
||||
if (textEditor)
|
||||
{
|
||||
if (maxDefined)
|
||||
{ // set the maxLength attribute
|
||||
textEditor->SetMaxTextLength(maxLength);
|
||||
if (textEditor) {
|
||||
if (maxDefined) { // set the maxLength attribute
|
||||
textEditor->SetMaxTextLength(maxLength);
|
||||
// if maxLength>docLength, we need to truncate the doc content
|
||||
}
|
||||
else { // unset the maxLength attribute
|
||||
textEditor->SetMaxTextLength(-1);
|
||||
} else { // unset the maxLength attribute
|
||||
textEditor->SetMaxTextLength(-1);
|
||||
}
|
||||
}
|
||||
rv = NS_OK; // don't propagate the error
|
||||
}
|
||||
else if (nsGkAtoms::readonly == aAttribute)
|
||||
{
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
if (AttributeExists(nsGkAtoms::readonly))
|
||||
{ // set readonly
|
||||
flags |= nsIPlaintextEditor::eEditorReadonlyMask;
|
||||
if (nsContentUtils::IsFocusedContent(mContent))
|
||||
selCon->SetCaretEnabled(false);
|
||||
}
|
||||
else
|
||||
{ // unset readonly
|
||||
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
|
||||
if (!(flags & nsIPlaintextEditor::eEditorDisabledMask) &&
|
||||
nsContentUtils::IsFocusedContent(mContent))
|
||||
selCon->SetCaretEnabled(true);
|
||||
}
|
||||
editor->SetFlags(flags);
|
||||
}
|
||||
else if (nsGkAtoms::disabled == aAttribute)
|
||||
{
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
if (AttributeExists(nsGkAtoms::disabled))
|
||||
{ // set disabled
|
||||
flags |= nsIPlaintextEditor::eEditorDisabledMask;
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
|
||||
if (nsContentUtils::IsFocusedContent(mContent))
|
||||
selCon->SetCaretEnabled(false);
|
||||
}
|
||||
else
|
||||
{ // unset disabled
|
||||
flags &= ~(nsIPlaintextEditor::eEditorDisabledMask);
|
||||
if (nsContentUtils::IsFocusedContent(mContent)) {
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
selCon->SetCaretEnabled(true);
|
||||
} else {
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);
|
||||
}
|
||||
}
|
||||
editor->SetFlags(flags);
|
||||
}
|
||||
else if (!mUseEditor && nsGkAtoms::value == aAttribute) {
|
||||
UpdateValueDisplay(true);
|
||||
}
|
||||
// Allow the base class to handle common attributes supported
|
||||
// by all form elements...
|
||||
else {
|
||||
rv = nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
if (nsGkAtoms::readonly == aAttribute) {
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
if (AttributeExists(nsGkAtoms::readonly)) { // set readonly
|
||||
flags |= nsIPlaintextEditor::eEditorReadonlyMask;
|
||||
if (nsContentUtils::IsFocusedContent(mContent)) {
|
||||
selCon->SetCaretEnabled(false);
|
||||
}
|
||||
} else { // unset readonly
|
||||
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
|
||||
if (!(flags & nsIPlaintextEditor::eEditorDisabledMask) &&
|
||||
nsContentUtils::IsFocusedContent(mContent)) {
|
||||
selCon->SetCaretEnabled(true);
|
||||
}
|
||||
}
|
||||
editor->SetFlags(flags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (nsGkAtoms::disabled == aAttribute) {
|
||||
uint32_t flags;
|
||||
editor->GetFlags(&flags);
|
||||
int16_t displaySelection = nsISelectionController::SELECTION_OFF;
|
||||
const bool focused = nsContentUtils::IsFocusedContent(mContent);
|
||||
const bool hasAttr = AttributeExists(nsGkAtoms::disabled);
|
||||
if (hasAttr) { // set disabled
|
||||
flags |= nsIPlaintextEditor::eEditorDisabledMask;
|
||||
} else { // unset disabled
|
||||
flags &= ~(nsIPlaintextEditor::eEditorDisabledMask);
|
||||
displaySelection = focused ? nsISelectionController::SELECTION_ON
|
||||
: nsISelectionController::SELECTION_HIDDEN;
|
||||
}
|
||||
selCon->SetDisplaySelection(displaySelection);
|
||||
if (focused) {
|
||||
selCon->SetCaretEnabled(!hasAttr);
|
||||
}
|
||||
editor->SetFlags(flags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mUseEditor && nsGkAtoms::value == aAttribute) {
|
||||
UpdateValueDisplay(true);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Allow the base class to handle common attributes supported by all form
|
||||
// elements...
|
||||
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user