Skip to content

Commit 6bc92de

Browse files
Bug 1311240 Fix odd "{" and "}" of control statements in editor for conforming to our coding rules r=smaug
Currently, editor code uses following style (or similar style) in a lot of places: if (foo) { } else { } This patch fixes this as conforming to our coding rules, i.e., it becomes: if (foo) { } else { } Additionally, this fixes other odd control statements in the files which include above issue because it's difficult to find following issues with searching the files: * if (foo) bar; * if (foo) { bar; } * if (foo) bar; Finally, if it becomes much simpler than current code, this patch rewrites existing code with "early return style". But this case is only a few places because this is risky. MozReview-Commit-ID: 2Gs26goWXrF --HG-- extra : rebase_source : 603f9003a3566b3203bdeb27dc73ac33502d2853
1 parent f7791e7 commit 6bc92de

30 files changed

+2625
-3255
lines changed

editor/composer/nsComposerCommands.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ nsListItemCommand::GetCurrentState(nsIEditor* aEditor,
327327
NS_ENSURE_SUCCESS(rv, rv);
328328

329329
bool inList = false;
330-
if (!bMixed)
331-
{
330+
if (!bMixed) {
332331
if (bLI) {
333332
inList = mTagName == nsGkAtoms::li;
334333
} else if (bDT) {
@@ -418,8 +417,7 @@ nsRemoveListCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
418417
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
419418

420419
nsresult rv = NS_OK;
421-
if (editor)
422-
{
420+
if (editor) {
423421
// This removes any list type
424422
rv = editor->RemoveList(EmptyString());
425423
}
@@ -464,8 +462,7 @@ nsIndentCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
464462
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
465463

466464
nsresult rv = NS_OK;
467-
if (editor)
468-
{
465+
if (editor) {
469466
rv = editor->Indent(NS_LITERAL_STRING("indent"));
470467
}
471468

@@ -583,8 +580,7 @@ nsMultiStateCommand::DoCommandParams(const char *aCommandName,
583580
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
584581

585582
nsresult rv = NS_OK;
586-
if (editor)
587-
{
583+
if (editor) {
588584
nsAutoString tString;
589585

590586
if (aParams) {
@@ -609,8 +605,7 @@ nsMultiStateCommand::GetCommandStateParams(const char *aCommandName,
609605
{
610606
nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
611607
nsresult rv = NS_OK;
612-
if (editor)
613-
{
608+
if (editor) {
614609
rv = GetCurrentState(editor, aParams);
615610
}
616611
return rv;
@@ -633,8 +628,7 @@ nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor,
633628
bool outMixed;
634629
nsAutoString outStateString;
635630
nsresult rv = htmlEditor->GetParagraphState(&outMixed, outStateString);
636-
if (NS_SUCCEEDED(rv))
637-
{
631+
if (NS_SUCCEEDED(rv)) {
638632
nsAutoCString tOutStateString;
639633
tOutStateString.AssignWithConversion(outStateString);
640634
aParams->SetBooleanValue(STATE_MIXED,outMixed);
@@ -670,8 +664,7 @@ nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor,
670664
nsAutoString outStateString;
671665
bool outMixed;
672666
nsresult rv = htmlEditor->GetFontFaceState(&outMixed, outStateString);
673-
if (NS_SUCCEEDED(rv))
674-
{
667+
if (NS_SUCCEEDED(rv)) {
675668
aParams->SetBooleanValue(STATE_MIXED,outMixed);
676669
aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
677670
}
@@ -933,8 +926,7 @@ nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams)
933926
NS_ENSURE_SUCCESS(rv, rv);
934927

935928
nsAutoString outStateString;
936-
switch (firstAlign)
937-
{
929+
switch (firstAlign) {
938930
default:
939931
case nsIHTMLEditor::eLeft:
940932
outStateString.AssignLiteral("left");
@@ -982,8 +974,7 @@ nsAbsolutePositioningCommand::IsCommandEnabled(const char * aCommandName,
982974
{
983975
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
984976
nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aCommandRefCon);
985-
if (htmlEditor)
986-
{
977+
if (htmlEditor) {
987978
bool isEditable = false;
988979
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
989980
NS_ENSURE_SUCCESS(rv, rv);
@@ -1171,8 +1162,7 @@ nsRemoveStylesCommand::DoCommand(const char *aCommandName,
11711162
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
11721163

11731164
nsresult rv = NS_OK;
1174-
if (editor)
1175-
{
1165+
if (editor) {
11761166
rv = editor->RemoveAllInlineProperties();
11771167
}
11781168

@@ -1219,8 +1209,7 @@ nsIncreaseFontSizeCommand::DoCommand(const char *aCommandName,
12191209
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
12201210

12211211
nsresult rv = NS_OK;
1222-
if (editor)
1223-
{
1212+
if (editor) {
12241213
rv = editor->IncreaseFontSize();
12251214
}
12261215

@@ -1267,8 +1256,7 @@ nsDecreaseFontSizeCommand::DoCommand(const char *aCommandName,
12671256
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
12681257

12691258
nsresult rv = NS_OK;
1270-
if (editor)
1271-
{
1259+
if (editor) {
12721260
rv = editor->DecreaseFontSize();
12731261
}
12741262

editor/composer/nsComposerCommandsUpdater.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ nsComposerCommandsUpdater::nsComposerCommandsUpdater()
3434
nsComposerCommandsUpdater::~nsComposerCommandsUpdater()
3535
{
3636
// cancel any outstanding update timer
37-
if (mUpdateTimer)
38-
{
37+
if (mUpdateTimer) {
3938
mUpdateTimer->Cancel();
4039
}
4140
}
@@ -59,8 +58,7 @@ NS_IMETHODIMP
5958
nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
6059
{
6160
// cancel any outstanding update timer
62-
if (mUpdateTimer)
63-
{
61+
if (mUpdateTimer) {
6462
mUpdateTimer->Cancel();
6563
mUpdateTimer = nullptr;
6664
}
@@ -108,10 +106,10 @@ nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
108106
// only need to update if the status of the Undo menu item changes.
109107
int32_t undoCount;
110108
aManager->GetNumberOfUndoItems(&undoCount);
111-
if (undoCount == 1)
112-
{
113-
if (mFirstDoOfFirstUndo)
109+
if (undoCount == 1) {
110+
if (mFirstDoOfFirstUndo) {
114111
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
112+
}
115113
mFirstDoOfFirstUndo = false;
116114
}
117115

@@ -224,8 +222,7 @@ nsComposerCommandsUpdater::Init(nsPIDOMWindowOuter* aDOMWindow)
224222
nsresult
225223
nsComposerCommandsUpdater::PrimeUpdateTimer()
226224
{
227-
if (!mUpdateTimer)
228-
{
225+
if (!mUpdateTimer) {
229226
nsresult rv = NS_OK;
230227
mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
231228
NS_ENSURE_SUCCESS(rv, rv);
@@ -242,8 +239,7 @@ void nsComposerCommandsUpdater::TimerCallback()
242239
{
243240
// if the selection state has changed, update stuff
244241
bool isCollapsed = SelectionIsCollapsed();
245-
if (static_cast<int8_t>(isCollapsed) != mSelectionCollapsed)
246-
{
242+
if (static_cast<int8_t>(isCollapsed) != mSelectionCollapsed) {
247243
UpdateCommandGroup(NS_LITERAL_STRING("select"));
248244
mSelectionCollapsed = isCollapsed;
249245
}
@@ -256,8 +252,7 @@ void nsComposerCommandsUpdater::TimerCallback()
256252
nsresult
257253
nsComposerCommandsUpdater::UpdateDirtyState(bool aNowDirty)
258254
{
259-
if (mDirtyState != static_cast<int8_t>(aNowDirty))
260-
{
255+
if (mDirtyState != static_cast<int8_t>(aNowDirty)) {
261256
UpdateCommandGroup(NS_LITERAL_STRING("save"));
262257
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
263258
mDirtyState = aNowDirty;
@@ -275,14 +270,14 @@ nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
275270

276271
// This hardcoded list of commands is temporary.
277272
// This code should use nsIControllerCommandGroup.
278-
if (aCommandGroup.EqualsLiteral("undo"))
279-
{
273+
if (aCommandGroup.EqualsLiteral("undo")) {
280274
commandUpdater->CommandStatusChanged("cmd_undo");
281275
commandUpdater->CommandStatusChanged("cmd_redo");
276+
return NS_OK;
282277
}
283-
else if (aCommandGroup.EqualsLiteral("select") ||
284-
aCommandGroup.EqualsLiteral("style"))
285-
{
278+
279+
if (aCommandGroup.EqualsLiteral("select") ||
280+
aCommandGroup.EqualsLiteral("style")) {
286281
commandUpdater->CommandStatusChanged("cmd_bold");
287282
commandUpdater->CommandStatusChanged("cmd_italic");
288283
commandUpdater->CommandStatusChanged("cmd_underline");
@@ -310,13 +305,16 @@ nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
310305
commandUpdater->CommandStatusChanged("cmd_fontColor");
311306
commandUpdater->CommandStatusChanged("cmd_backgroundColor");
312307
commandUpdater->CommandStatusChanged("cmd_highlight");
308+
return NS_OK;
313309
}
314-
else if (aCommandGroup.EqualsLiteral("save"))
315-
{
310+
311+
if (aCommandGroup.EqualsLiteral("save")) {
316312
// save commands (most are not in C++)
317313
commandUpdater->CommandStatusChanged("cmd_setDocumentModified");
318314
commandUpdater->CommandStatusChanged("cmd_save");
315+
return NS_OK;
319316
}
317+
320318
return NS_OK;
321319
}
322320

@@ -337,16 +335,14 @@ nsComposerCommandsUpdater::SelectionIsCollapsed()
337335
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryReferent(mDOMWindow);
338336
NS_ENSURE_TRUE(domWindow, true);
339337

340-
if (nsCOMPtr<nsISelection> domSelection = domWindow->GetSelection())
341-
{
342-
bool selectionCollapsed = false;
343-
domSelection->GetIsCollapsed(&selectionCollapsed);
344-
return selectionCollapsed;
338+
nsCOMPtr<nsISelection> domSelection = domWindow->GetSelection();
339+
if (NS_WARN_IF(!domSelection)) {
340+
return false;
345341
}
346342

347-
NS_WARNING("nsComposerCommandsUpdater::SelectionIsCollapsed - no domSelection");
348-
349-
return false;
343+
bool selectionCollapsed = false;
344+
domSelection->GetIsCollapsed(&selectionCollapsed);
345+
return selectionCollapsed;
350346
}
351347

352348
already_AddRefed<nsPICommandUpdater>

0 commit comments

Comments
 (0)