chore: replace absl::optional<T> with std::optional<T> (#40928)

* chore: replace absl::optional<T> with std::optional<T>

* IWYU
This commit is contained in:
Milan Burda 2024-01-10 23:23:35 +01:00 committed by GitHub
parent fac964ac0d
commit 892c9d78a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
129 changed files with 419 additions and 397 deletions

View file

@ -34,7 +34,7 @@ bool StringToAccelerator(const std::string& shortcut,
// Now, parse it into an accelerator.
int modifiers = ui::EF_NONE;
ui::KeyboardCode key = ui::VKEY_UNKNOWN;
absl::optional<char16_t> shifted_char;
std::optional<char16_t> shifted_char;
for (const auto& token : tokens) {
ui::KeyboardCode code = electron::KeyboardCodeFromStr(token, &shifted_char);
if (shifted_char)

View file

@ -7,9 +7,10 @@
#include <Quartz/Quartz.h>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "components/remote_cocoa/app_shim/views_nswindow_delegate.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace electron {
class NativeWindowMac;
@ -30,7 +31,7 @@ class NativeWindowMac;
// Only valid during a live resize.
// Used to keep track of whether a resize is happening horizontally or
// vertically, even if physically the user is resizing in both directions.
absl::optional<bool> resizingHorizontally_;
std::optional<bool> resizingHorizontally_;
}
- (id)initWithShell:(electron::NativeWindowMac*)shell;
@end

View file

@ -7,7 +7,8 @@
#import <Cocoa/Cocoa.h>
#include "third_party/abseil-cpp/absl/types/optional.h"
#include <optional>
#include "ui/gfx/geometry/point.h"
@class WindowButtonsProxy;
@ -48,7 +49,7 @@
- (void)setShowOnHover:(BOOL)yes;
// Set left-top margin of the window buttons..
- (void)setMargin:(const absl::optional<gfx::Point>&)margin;
- (void)setMargin:(const std::optional<gfx::Point>&)margin;
// Set height of button container
- (void)setHeight:(const float)height;

View file

@ -79,7 +79,7 @@
[self updateButtonsVisibility];
}
- (void)setMargin:(const absl::optional<gfx::Point>&)margin {
- (void)setMargin:(const std::optional<gfx::Point>&)margin {
if (margin)
margin_ = *margin;
else

View file

@ -100,7 +100,7 @@ void ElectronMenuModel::SetSharingItem(SharingItem item) {
sharing_item_.emplace(std::move(item));
}
const absl::optional<ElectronMenuModel::SharingItem>&
const std::optional<ElectronMenuModel::SharingItem>&
ElectronMenuModel::GetSharingItem() const {
return sharing_item_;
}

View file

@ -5,6 +5,7 @@
#ifndef ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_
#define ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_
#include <optional>
#include <string>
#include <vector>
@ -14,7 +15,6 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/models/simple_menu_model.h"
#include "url/gurl.h"
@ -29,9 +29,9 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
SharingItem(const SharingItem&) = delete;
~SharingItem();
absl::optional<std::vector<std::string>> texts;
absl::optional<std::vector<GURL>> urls;
absl::optional<std::vector<base::FilePath>> file_paths;
std::optional<std::vector<std::string>> texts;
std::optional<std::vector<GURL>> urls;
std::optional<std::vector<base::FilePath>> file_paths;
};
#endif
@ -98,7 +98,7 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
bool GetSharingItemAt(size_t index, SharingItem* item) const;
// Set/Get the SharingItem of this menu.
void SetSharingItem(SharingItem item);
const absl::optional<SharingItem>& GetSharingItem() const;
const std::optional<SharingItem>& GetSharingItem() const;
#endif
// ui::SimpleMenuModel:
@ -116,7 +116,7 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
raw_ptr<Delegate> delegate_; // weak ref.
#if BUILDFLAG(IS_MAC)
absl::optional<SharingItem> sharing_item_;
std::optional<SharingItem> sharing_item_;
#endif
base::flat_map<int, std::u16string> toolTips_; // command id -> tooltip

View file

@ -5,12 +5,12 @@
#ifndef ELECTRON_SHELL_BROWSER_UI_MESSAGE_BOX_H_
#define ELECTRON_SHELL_BROWSER_UI_MESSAGE_BOX_H_
#include <optional>
#include <string>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/image/image_skia.h"
namespace electron {
@ -29,7 +29,7 @@ struct MessageBoxSettings {
RAW_PTR_EXCLUSION electron::NativeWindow* parent_window = nullptr;
MessageBoxType type = electron::MessageBoxType::kNone;
std::vector<std::string> buttons;
absl::optional<int> id;
std::optional<int> id;
int default_id;
int cancel_id;
bool no_link = false;

View file

@ -192,7 +192,7 @@ class GtkMessageBox : public NativeWindowObserver {
private:
// The id of the dialog.
absl::optional<int> id_;
std::optional<int> id_;
// The id to return when the dialog is closed without pressing buttons.
int cancel_id_ = 0;

View file

@ -162,7 +162,7 @@ void ShowMessageBox(const MessageBoxSettings& settings,
// Duplicate the callback object here since c is a reference and gcd would
// only store the pointer, by duplication we can force gcd to store a copy.
__block MessageBoxCallback callback_ = std::move(callback);
__block absl::optional<int> id = std::move(settings.id);
__block std::optional<int> id = std::move(settings.id);
__block int cancel_id = settings.cancel_id;
auto handler = ^(NSModalResponse response) {

View file

@ -304,7 +304,7 @@ void ShowMessageBox(const MessageBoxSettings& settings,
dialog_thread::Run(base::BindOnce(&ShowTaskDialogUTF8, settings,
parent_widget, base::Unretained(hwnd)),
base::BindOnce(
[](MessageBoxCallback callback, absl::optional<int> id,
[](MessageBoxCallback callback, std::optional<int> id,
DialogResult result) {
if (id)
GetDialogsMap().erase(*id);

View file

@ -18,7 +18,7 @@ namespace electron {
class TrayIcon {
public:
static TrayIcon* Create(absl::optional<UUID> guid);
static TrayIcon* Create(std::optional<UUID> guid);
#if BUILDFLAG(IS_WIN)
using ImageType = HICON;

View file

@ -422,7 +422,7 @@ gfx::Rect TrayIconCocoa::GetBounds() {
}
// static
TrayIcon* TrayIcon::Create(absl::optional<UUID> guid) {
TrayIcon* TrayIcon::Create(std::optional<UUID> guid) {
return new TrayIconCocoa;
}

View file

@ -108,7 +108,7 @@ ui::StatusIconLinux* TrayIconLinux::GetStatusIcon() {
}
// static
TrayIcon* TrayIcon::Create(absl::optional<UUID> guid) {
TrayIcon* TrayIcon::Create(std::optional<UUID> guid) {
return new TrayIconLinux;
}

View file

@ -8,7 +8,7 @@
namespace electron {
// static
TrayIcon* TrayIcon::Create(absl::optional<UUID> guid) {
TrayIcon* TrayIcon::Create(std::optional<UUID> guid) {
static NotifyIconHost host;
return host.CreateNotifyIcon(guid);
}

View file

@ -147,8 +147,8 @@ bool AutofillPopupView::CanStartDragForView(views::View*,
}
void AutofillPopupView::OnSelectedRowChanged(
absl::optional<int> previous_row_selection,
absl::optional<int> current_row_selection) {
std::optional<int> previous_row_selection,
std::optional<int> current_row_selection) {
SchedulePaint();
if (current_row_selection) {
@ -436,7 +436,7 @@ void AutofillPopupView::AcceptSelection(const gfx::Point& point) {
AcceptSelectedLine();
}
void AutofillPopupView::SetSelectedLine(absl::optional<int> selected_line) {
void AutofillPopupView::SetSelectedLine(std::optional<int> selected_line) {
if (!popup_)
return;
if (selected_line_ == selected_line)
@ -479,7 +479,7 @@ void AutofillPopupView::SelectPreviousLine() {
}
void AutofillPopupView::ClearSelection() {
SetSelectedLine(absl::nullopt);
SetSelectedLine(std::nullopt);
}
void AutofillPopupView::RemoveObserver() {

View file

@ -6,6 +6,7 @@
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_AUTOFILL_POPUP_VIEW_H_
#include <memory>
#include <optional>
#include "shell/browser/ui/autofill_popup.h"
@ -14,7 +15,6 @@
#include "content/public/common/input/native_web_keyboard_event.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/osr/osr_view_proxy.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
@ -84,8 +84,8 @@ class AutofillPopupView : public views::WidgetDelegateView,
private:
friend class AutofillPopup;
void OnSelectedRowChanged(absl::optional<int> previous_row_selection,
absl::optional<int> current_row_selection);
void OnSelectedRowChanged(std::optional<int> previous_row_selection,
std::optional<int> current_row_selection);
// Draw the given autofill entry in |entry_rect|.
void DrawAutofillEntry(gfx::Canvas* canvas,
@ -122,7 +122,7 @@ class AutofillPopupView : public views::WidgetDelegateView,
void AcceptSuggestion(int index);
bool AcceptSelectedLine();
void AcceptSelection(const gfx::Point& point);
void SetSelectedLine(absl::optional<int> selected_line);
void SetSelectedLine(std::optional<int> selected_line);
void SetSelection(const gfx::Point& point);
void SelectNextLine();
void SelectPreviousLine();
@ -141,7 +141,7 @@ class AutofillPopupView : public views::WidgetDelegateView,
base::Time show_time_;
// The index of the currently selected line
absl::optional<int> selected_line_;
std::optional<int> selected_line_;
std::unique_ptr<OffscreenViewProxy> view_proxy_;

View file

@ -78,7 +78,7 @@ const gfx::FontList* MenuDelegate::GetLabelFontList(int id) const {
return adapter_->GetLabelFontList(id);
}
absl::optional<SkColor> MenuDelegate::GetLabelColor(int id) const {
std::optional<SkColor> MenuDelegate::GetLabelColor(int id) const {
return adapter_->GetLabelColor(id);
}

View file

@ -53,7 +53,7 @@ class MenuDelegate : public views::MenuDelegate {
bool GetAccelerator(int id, ui::Accelerator* accelerator) const override;
std::u16string GetLabel(int id) const override;
const gfx::FontList* GetLabelFontList(int id) const override;
absl::optional<SkColor> GetLabelColor(int id) const override;
std::optional<SkColor> GetLabelColor(int id) const override;
bool IsCommandEnabled(int id) const override;
bool IsCommandVisible(int id) const override;
bool IsItemChecked(int id) const override;

View file

@ -5,6 +5,7 @@
#include "shell/browser/ui/webui/accessibility_ui.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -42,7 +43,6 @@
#include "content/public/browser/web_ui_data_source.h"
#include "shell/browser/native_window.h"
#include "shell/browser/window_list.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
#include "ui/base/webui/web_ui_util.h"

View file

@ -4,11 +4,12 @@
#include "shell/browser/ui/win/electron_desktop_window_tree_host_win.h"
#include <optional>
#include "base/win/windows_version.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/ui/views/win_frame_view.h"
#include "shell/browser/win/dark_mode.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/win/hwnd_metrics.h"
#include "ui/base/win/shell.h"

View file

@ -7,8 +7,9 @@
#include <windows.h>
#include <optional>
#include "shell/browser/native_window_views.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
namespace electron {
@ -44,7 +45,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
private:
raw_ptr<NativeWindowViews> native_window_view_; // weak ref
absl::optional<bool> force_should_paint_as_active_;
std::optional<bool> force_should_paint_as_active_;
};
} // namespace electron

View file

@ -191,7 +191,7 @@ NotifyIconHost::~NotifyIconHost() {
delete ptr;
}
NotifyIcon* NotifyIconHost::CreateNotifyIcon(absl::optional<UUID> guid) {
NotifyIcon* NotifyIconHost::CreateNotifyIcon(std::optional<UUID> guid) {
if (guid.has_value()) {
for (NotifyIcons::const_iterator i(notify_icons_.begin());
i != notify_icons_.end(); ++i) {

View file

@ -7,10 +7,10 @@
#include <windows.h>
#include <optional>
#include <vector>
#include "shell/common/gin_converters/guid_converter.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
const GUID GUID_DEFAULT = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
@ -27,7 +27,7 @@ class NotifyIconHost {
NotifyIconHost(const NotifyIconHost&) = delete;
NotifyIconHost& operator=(const NotifyIconHost&) = delete;
NotifyIcon* CreateNotifyIcon(absl::optional<UUID> guid);
NotifyIcon* CreateNotifyIcon(std::optional<UUID> guid);
void Remove(NotifyIcon* notify_icon);
private: