refactor: Chromium code style for enum classes (#26165)

This commit is contained in:
Milan Burda 2020-10-27 18:51:45 +01:00 committed by GitHub
parent dbf2931f0e
commit 1c99a9b425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 300 additions and 295 deletions

View file

@ -17,7 +17,7 @@ class Arguments;
namespace electron {
// Possible bundle movement conflicts
enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING };
enum class BundlerMoverConflictType { kExists, kExistsAndRunning };
class ElectronBundleMover {
public:

View file

@ -24,9 +24,9 @@ struct Converter<electron::BundlerMoverConflictType> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::BundlerMoverConflictType value) {
switch (value) {
case electron::BundlerMoverConflictType::EXISTS:
case electron::BundlerMoverConflictType::kExists:
return gin::StringToV8(isolate, "exists");
case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING:
case electron::BundlerMoverConflictType::kExistsAndRunning:
return gin::StringToV8(isolate, "existsAndRunning");
default:
return gin::StringToV8(isolate, "");
@ -117,7 +117,7 @@ bool ElectronBundleMover::Move(gin_helper::ErrorThrower thrower,
if (IsApplicationAtPathRunning(destinationPath)) {
// Check for callback handler and get user choice for open/quit
if (!ShouldContinueMove(
thrower, BundlerMoverConflictType::EXISTS_AND_RUNNING, args))
thrower, BundlerMoverConflictType::kExistsAndRunning, args))
return false;
// Unless explicitly denied, give running app focus and terminate self
@ -130,7 +130,7 @@ bool ElectronBundleMover::Move(gin_helper::ErrorThrower thrower,
return true;
} else {
// Check callback handler and get user choice for app trashing
if (!ShouldContinueMove(thrower, BundlerMoverConflictType::EXISTS,
if (!ShouldContinueMove(thrower, BundlerMoverConflictType::kExists,
args))
return false;

View file

@ -193,7 +193,7 @@ bool ScopedDisableResize::disable_resize_ = false;
- (void)performClose:(id)sender {
if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) {
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover) {
[[self delegate] windowShouldClose:self];
} else if (shell_->IsSimpleFullScreen()) {
if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
@ -234,7 +234,7 @@ bool ScopedDisableResize::disable_resize_ = false;
- (void)performMiniaturize:(id)sender {
if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER)
electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover)
[self miniaturize:self];
else
[super performMiniaturize:sender];

View file

@ -151,7 +151,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
- (void)windowDidResize:(NSNotification*)notification {
[super windowDidResize:notification];
shell_->NotifyWindowResize();
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights();
}
}
@ -216,7 +216,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
shell_->SetResizable(true);
// Hide the native toolbar before entering fullscreen, so there is no visual
// artifacts.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) {
if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
[window setToolbar:nil];
}
@ -233,14 +233,14 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
// FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under
// fullscreen mode.
// Show title if fullscreen_window_title flag is set
(shell_->title_bar_style() != TitleBarStyle::HIDDEN_INSET ||
(shell_->title_bar_style() != TitleBarStyle::kHiddenInset ||
shell_->fullscreen_window_title())) {
[window setTitleVisibility:NSWindowTitleVisible];
}
// Restore the native toolbar immediately after entering fullscreen, if we
// do this before leaving fullscreen, traffic light buttons will be jumping.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) {
if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
base::scoped_nsobject<NSToolbar> toolbar(
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[toolbar setShowsBaselineSeparator:NO];
@ -257,18 +257,18 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
// Restore the titlebar visibility.
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
if ((shell_->transparent() || !shell_->has_frame()) &&
(shell_->title_bar_style() != TitleBarStyle::HIDDEN_INSET ||
(shell_->title_bar_style() != TitleBarStyle::kHiddenInset ||
shell_->fullscreen_window_title())) {
[window setTitleVisibility:NSWindowTitleHidden];
}
// Turn off the style for toolbar.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) {
if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
shell_->SetStyleMask(false, NSWindowStyleMaskFullSizeContentView);
[window setTitlebarAppearsTransparent:YES];
}
shell_->SetExitingFullScreen(true);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights();
}
}
@ -277,7 +277,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
shell_->SetResizable(is_resizable_);
shell_->NotifyWindowLeaveFullScreen();
shell_->SetExitingFullScreen(false);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights();
}
}

View file

@ -55,10 +55,10 @@ class TrayIcon {
virtual std::string GetTitle() = 0;
#endif
enum class IconType { None, Info, Warning, Error, Custom };
enum class IconType { kNone, kInfo, kWarning, kError, kCustom };
struct BalloonOptions {
IconType icon_type = IconType::Custom;
IconType icon_type = IconType::kCustom;
#if defined(OS_WIN)
HICON icon = nullptr;
#else

View file

@ -83,7 +83,7 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
DCHECK(shell_link);
DCHECK(item);
item->type = JumpListItem::Type::TASK;
item->type = JumpListItem::Type::kTask;
wchar_t path[MAX_PATH];
if (FAILED(shell_link->GetPath(path, base::size(path), nullptr, 0)))
return false;
@ -134,7 +134,7 @@ void ConvertRemovedJumpListItems(IObjectArray* in,
IShellLink* shell_link;
for (UINT i = 0; i < removed_count; ++i) {
if (SUCCEEDED(in->GetAt(i, IID_PPV_ARGS(&shell_item)))) {
item.type = JumpListItem::Type::FILE;
item.type = JumpListItem::Type::kFile;
GetShellItemFileName(shell_item, &item.path);
out->push_back(item);
shell_item->Release();
@ -217,22 +217,22 @@ bool JumpList::Delete() {
JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
DCHECK(destinations_);
if (!destinations_)
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
if (category.items.empty())
return JumpListResult::SUCCESS;
return JumpListResult::kSuccess;
CComPtr<IObjectCollection> collection;
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection))) {
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
}
auto result = JumpListResult::SUCCESS;
auto result = JumpListResult::kSuccess;
// Keep track of how many items were actually appended to the category.
int appended_count = 0;
for (const auto& item : category.items) {
switch (item.type) {
case JumpListItem::Type::TASK:
case JumpListItem::Type::kTask:
if (AppendTask(item, collection))
++appended_count;
else
@ -241,8 +241,8 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
"to Jump List.";
break;
case JumpListItem::Type::SEPARATOR:
if (category.type == JumpListCategory::Type::TASKS) {
case JumpListItem::Type::kSeparator:
if (category.type == JumpListCategory::Type::kTasks) {
if (AppendSeparator(collection))
++appended_count;
} else {
@ -250,11 +250,11 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
<< "'" << category.name << "'. "
<< "Separators are only allowed in the standard 'Tasks' "
"Jump List category.";
result = JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR;
result = JumpListResult::kCustomCategorySeparatorError;
}
break;
case JumpListItem::Type::FILE:
case JumpListItem::Type::kFile:
if (AppendFile(item, collection))
++appended_count;
else
@ -269,17 +269,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
return result;
if ((static_cast<size_t>(appended_count) < category.items.size()) &&
(result == JumpListResult::SUCCESS)) {
result = JumpListResult::GENERIC_ERROR;
(result == JumpListResult::kSuccess)) {
result = JumpListResult::kGenericError;
}
CComQIPtr<IObjectArray> items(collection);
if (category.type == JumpListCategory::Type::TASKS) {
if (category.type == JumpListCategory::Type::kTasks) {
if (FAILED(destinations_->AddUserTasks(items))) {
LOG(ERROR) << "Failed to append items to the standard Tasks category.";
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
if (result == JumpListResult::kSuccess)
result = JumpListResult::kGenericError;
}
} else {
HRESULT hr = destinations_->AppendCategory(category.name.c_str(), items);
@ -288,17 +288,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' "
<< "to Jump List due to missing file type registration.";
result = JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR;
result = JumpListResult::kMissingFileTypeRegistrationError;
} else if (hr == E_ACCESSDENIED) {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' "
<< "to Jump List due to system privacy settings.";
result = JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR;
result = JumpListResult::kCustomCategoryAccessDeniedError;
} else {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' to Jump List.";
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
if (result == JumpListResult::kSuccess)
result = JumpListResult::kGenericError;
}
}
}
@ -313,36 +313,36 @@ JumpListResult JumpList::AppendCategories(
const std::vector<JumpListCategory>& categories) {
DCHECK(destinations_);
if (!destinations_)
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
auto result = JumpListResult::SUCCESS;
auto result = JumpListResult::kSuccess;
for (const auto& category : categories) {
auto latestResult = JumpListResult::SUCCESS;
auto latestResult = JumpListResult::kSuccess;
switch (category.type) {
case JumpListCategory::Type::TASKS:
case JumpListCategory::Type::CUSTOM:
case JumpListCategory::Type::kTasks:
case JumpListCategory::Type::kCustom:
latestResult = AppendCategory(category);
break;
case JumpListCategory::Type::RECENT:
case JumpListCategory::Type::kRecent:
if (FAILED(destinations_->AppendKnownCategory(KDC_RECENT))) {
LOG(ERROR) << "Failed to append Recent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR;
latestResult = JumpListResult::kGenericError;
}
break;
case JumpListCategory::Type::FREQUENT:
case JumpListCategory::Type::kFrequent:
if (FAILED(destinations_->AppendKnownCategory(KDC_FREQUENT))) {
LOG(ERROR) << "Failed to append Frequent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR;
latestResult = JumpListResult::kGenericError;
}
break;
}
// Keep the first non-generic error code as only one can be returned from
// the function (so try to make it the most useful one).
if (((result == JumpListResult::SUCCESS) ||
(result == JumpListResult::GENERIC_ERROR)) &&
(latestResult != JumpListResult::SUCCESS))
if (((result == JumpListResult::kSuccess) ||
(result == JumpListResult::kGenericError)) &&
(latestResult != JumpListResult::kSuccess))
result = latestResult;
}
return result;

View file

@ -15,34 +15,34 @@
namespace electron {
enum class JumpListResult : int {
SUCCESS = 0,
kSuccess = 0,
// In JS code this error will manifest as an exception.
ARGUMENT_ERROR = 1,
kArgumentError = 1,
// Generic error, the runtime logs may provide some clues.
GENERIC_ERROR = 2,
kGenericError = 2,
// Custom categories can't contain separators.
CUSTOM_CATEGORY_SEPARATOR_ERROR = 3,
kCustomCategorySeparatorError = 3,
// The app isn't registered to handle a file type found in a custom category.
MISSING_FILE_TYPE_REGISTRATION_ERROR = 4,
kMissingFileTypeRegistrationError = 4,
// Custom categories can't be created due to user privacy settings.
CUSTOM_CATEGORY_ACCESS_DENIED_ERROR = 5,
kCustomCategoryAccessDeniedError = 5,
};
struct JumpListItem {
enum class Type {
// A task will launch an app (usually the one that created the Jump List)
// with specific arguments.
TASK,
kTask,
// Separators can only be inserted between items in the standard Tasks
// category, they can't appear in custom categories.
SEPARATOR,
kSeparator,
// A file link will open a file using the app that created the Jump List,
// for this to work the app must be registered as a handler for the file
// type (though the app doesn't have to be the default handler).
FILE
kFile
};
Type type = Type::TASK;
Type type = Type::kTask;
// For tasks this is the path to the program executable, for file links this
// is the full filename.
base::FilePath path;
@ -61,18 +61,18 @@ struct JumpListItem {
struct JumpListCategory {
enum class Type {
// A custom category can contain tasks and files, but not separators.
CUSTOM,
kCustom,
// Frequent/Recent categories are managed by the OS, their name and items
// can't be set by the app (though items can be set indirectly).
FREQUENT,
RECENT,
kFrequent,
kRecent,
// The standard Tasks category can't be renamed by the app, but the app
// can set the items that should appear in this category, and those items
// can include tasks, files, and separators.
TASKS
kTasks
};
Type type = Type::TASKS;
Type type = Type::kTasks;
base::string16 name;
std::vector<JumpListItem> items;

View file

@ -25,15 +25,15 @@ namespace {
UINT ConvertIconType(electron::TrayIcon::IconType type) {
using IconType = electron::TrayIcon::IconType;
switch (type) {
case IconType::None:
case IconType::kNone:
return NIIF_NONE;
case IconType::Info:
case IconType::kInfo:
return NIIF_INFO;
case IconType::Warning:
case IconType::kWarning:
return NIIF_WARNING;
case IconType::Error:
case IconType::kError:
return NIIF_ERROR;
case IconType::Custom:
case IconType::kCustom:
return NIIF_USER;
default:
NOTREACHED() << "Invalid icon type";