Update to Chromium version 91.0.4472.0 (#870763)

This commit is contained in:
Marshall Greenblatt
2021-04-20 18:52:34 -04:00
parent b189c7b472
commit ae4f68f695
193 changed files with 1381 additions and 1897 deletions

View File

@@ -295,7 +295,7 @@ ui::KeyEvent CefBrowserPlatformDelegateNativeLinux::TranslateUiKeyEvent(
ui::KeycodeConverter::NativeKeycodeToDomCode(key_event.native_key_code);
int keysym = ui::XKeysymForWindowsKeyCode(
key_code, !!(key_event.modifiers & EVENTFLAG_SHIFT_DOWN));
base::char16 character = ui::GetUnicodeCharacterFromXKeySym(keysym);
char16_t character = ui::GetUnicodeCharacterFromXKeySym(keysym);
base::TimeTicks time_stamp = GetEventTimeStamp();
if (key_event.type == KEYEVENT_CHAR) {

View File

@@ -69,7 +69,7 @@ const int kMaxAddressLengthChars = 2048;
bool HasExternalHandler(const std::string& scheme) {
base::win::RegKey key;
const std::wstring registry_path =
base::ASCIIToUTF16(scheme + "\\shell\\open\\command");
base::ASCIIToWide(scheme + "\\shell\\open\\command");
key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ);
if (key.Valid()) {
DWORD size = 0;

View File

@@ -15,7 +15,7 @@ namespace cursor_util {
cef_cursor_handle_t GetPlatformCursor(ui::mojom::CursorType type) {
auto cursor = ui::CursorFactory::GetInstance()->GetDefaultCursor(type);
if (cursor) {
return ToCursorHandle(*cursor);
return ToCursorHandle(cursor);
}
return 0;
}

View File

@@ -47,12 +47,16 @@ LPCWSTR ToCursorID(ui::mojom::CursorType type) {
return IDC_SIZENESW;
case ui::mojom::CursorType::kWestResize:
return IDC_SIZEWE;
case ui::mojom::CursorType::kNorthSouthNoResize:
case ui::mojom::CursorType::kNorthSouthResize:
return IDC_SIZENS;
case ui::mojom::CursorType::kEastWestNoResize:
case ui::mojom::CursorType::kEastWestResize:
return IDC_SIZEWE;
case ui::mojom::CursorType::kNorthEastSouthWestNoResize:
case ui::mojom::CursorType::kNorthEastSouthWestResize:
return IDC_SIZENESW;
case ui::mojom::CursorType::kNorthWestSouthEastNoResize:
case ui::mojom::CursorType::kNorthWestSouthEastResize:
return IDC_SIZENWSE;
case ui::mojom::CursorType::kColumnResize:

View File

@@ -25,7 +25,7 @@
namespace {
base::string16 GetDescriptionFromMimeType(const std::string& mime_type) {
std::u16string GetDescriptionFromMimeType(const std::string& mime_type) {
// Check for wild card mime types and return an appropriate description.
static const struct {
const char* mime_type;
@@ -42,31 +42,31 @@ base::string16 GetDescriptionFromMimeType(const std::string& mime_type) {
return l10n_util::GetStringUTF16(kWildCardMimeTypes[i].string_id);
}
return base::string16();
return std::u16string();
}
void AddFilters(NSPopUpButton* button,
const std::vector<base::string16>& accept_filters,
const std::vector<std::u16string>& accept_filters,
bool include_all_files,
std::vector<std::vector<base::string16>>* all_extensions) {
std::vector<std::vector<std::u16string>>* all_extensions) {
for (size_t i = 0; i < accept_filters.size(); ++i) {
const base::string16& filter = accept_filters[i];
const std::u16string& filter = accept_filters[i];
if (filter.empty())
continue;
std::vector<base::string16> extensions;
base::string16 description;
std::vector<std::u16string> extensions;
std::u16string description;
size_t sep_index = filter.find('|');
if (sep_index != std::string::npos) {
// Treat as a filter of the form "Filter Name|.ext1;.ext2;.ext3".
description = filter.substr(0, sep_index);
const std::vector<base::string16>& ext = base::SplitString(
filter.substr(sep_index + 1), base::ASCIIToUTF16(";"),
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
const std::vector<std::u16string>& ext =
base::SplitString(filter.substr(sep_index + 1), u";",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
for (size_t x = 0; x < ext.size(); ++x) {
const base::string16& file_ext = ext[x];
const std::u16string& file_ext = ext[x];
if (!file_ext.empty() && file_ext[0] == '.')
extensions.push_back(file_ext);
}
@@ -80,7 +80,7 @@ void AddFilters(NSPopUpButton* button,
net::GetExtensionsForMimeType(ascii, &ext);
if (!ext.empty()) {
for (size_t x = 0; x < ext.size(); ++x)
extensions.push_back(base::ASCIIToUTF16("." + ext[x]));
extensions.push_back(u"." + base::ASCIIToUTF16(ext[x]));
description = GetDescriptionFromMimeType(ascii);
}
}
@@ -92,22 +92,21 @@ void AddFilters(NSPopUpButton* button,
// will keep growing.
const size_t kMaxExtensions = 10;
base::string16 ext_str;
std::u16string ext_str;
for (size_t x = 0; x < std::min(kMaxExtensions, extensions.size()); ++x) {
const base::string16& pattern = base::ASCIIToUTF16("*") + extensions[x];
const std::u16string& pattern = u"*" + extensions[x];
if (x != 0)
ext_str += base::ASCIIToUTF16(";");
ext_str += u";";
ext_str += pattern;
}
if (extensions.size() > kMaxExtensions)
ext_str += base::ASCIIToUTF16(";...");
ext_str += u";...";
if (description.empty()) {
description = ext_str;
} else {
description +=
base::ASCIIToUTF16(" (") + ext_str + base::ASCIIToUTF16(")");
description += u" (" + ext_str + u")";
}
[button addItemWithTitle:base::SysUTF16ToNSString(description)];
@@ -119,7 +118,7 @@ void AddFilters(NSPopUpButton* button,
// is implied).
if (include_all_files && !all_extensions->empty()) {
[button addItemWithTitle:base::SysUTF8ToNSString("All Files (*)")];
all_extensions->push_back(std::vector<base::string16>());
all_extensions->push_back(std::vector<std::u16string>());
}
}
@@ -129,11 +128,11 @@ void AddFilters(NSPopUpButton* button,
@interface CefFilterDelegate : NSObject {
@private
NSSavePanel* panel_;
std::vector<std::vector<base::string16>> extensions_;
std::vector<std::vector<std::u16string>> extensions_;
int selected_index_;
}
- (id)initWithPanel:(NSSavePanel*)panel
andAcceptFilters:(const std::vector<base::string16>&)accept_filters
andAcceptFilters:(const std::vector<std::u16string>&)accept_filters
andFilterIndex:(int)index;
- (void)setFilter:(int)index;
- (int)filter;
@@ -144,7 +143,7 @@ void AddFilters(NSPopUpButton* button,
@implementation CefFilterDelegate
- (id)initWithPanel:(NSSavePanel*)panel
andAcceptFilters:(const std::vector<base::string16>&)accept_filters
andAcceptFilters:(const std::vector<std::u16string>&)accept_filters
andFilterIndex:(int)index {
if (self = [super init]) {
DCHECK(panel);
@@ -204,7 +203,7 @@ void AddFilters(NSPopUpButton* button,
// Set the extension on the currently selected file name.
- (void)setFileExtension {
const std::vector<base::string16>& filter = extensions_[selected_index_];
const std::vector<std::u16string>& filter = extensions_[selected_index_];
if (filter.empty()) {
// All extensions are allowed so don't change anything.
return;
@@ -214,7 +213,7 @@ void AddFilters(NSPopUpButton* button,
// If the file name currently includes an extension from |filter| then don't
// change anything.
base::string16 extension = base::UTF8ToUTF16(path.Extension());
std::u16string extension = base::UTF8ToUTF16(path.Extension());
if (!extension.empty()) {
for (size_t i = 0; i < filter.size(); ++i) {
if (filter[i] == extension)
@@ -259,7 +258,7 @@ void CefFileDialogRunnerMac::RunOpenFileDialog(
int filter_index) {
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
base::string16 title;
std::u16string title;
if (!params.title.empty()) {
title = params.title;
} else {
@@ -347,7 +346,7 @@ void CefFileDialogRunnerMac::RunSaveFileDialog(
int filter_index) {
NSSavePanel* savePanel = [NSSavePanel savePanel];
base::string16 title;
std::u16string title;
if (!params.title.empty())
title = params.title;
else

View File

@@ -69,8 +69,8 @@ std::wstring FormatFilterForExtensions(
bool include_all_files) {
const std::wstring all_ext = L"*.*";
const std::wstring all_desc =
l10n_util::GetStringUTF16(IDS_APP_SAVEAS_ALL_FILES) + L" (" + all_ext +
L")";
base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_APP_SAVEAS_ALL_FILES)) +
L" (" + all_ext + L")";
DCHECK(file_ext.size() >= ext_desc.size());
@@ -97,7 +97,8 @@ std::wstring FormatFilterForExtensions(
ext += L";" + std::wstring(*it);
}
std::wstring desc =
l10n_util::GetStringUTF16(IDS_CUSTOM_FILES) + L" (" + ext + L")";
base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_CUSTOM_FILES)) +
L" (" + ext + L")";
result.append(desc.c_str(), desc.size() + 1); // Append NULL too.
result.append(ext.c_str(), ext.size() + 1);
@@ -167,34 +168,36 @@ std::wstring GetDescriptionFromMimeType(const std::string& mime_type) {
};
for (size_t i = 0; i < base::size(kWildCardMimeTypes); ++i) {
if (mime_type == std::string(kWildCardMimeTypes[i].mime_type) + "/*")
return l10n_util::GetStringUTF16(kWildCardMimeTypes[i].string_id);
if (mime_type == std::string(kWildCardMimeTypes[i].mime_type) + "/*") {
return base::UTF16ToWide(
l10n_util::GetStringUTF16(kWildCardMimeTypes[i].string_id));
}
}
return std::wstring();
}
std::wstring GetFilterString(
const std::vector<base::string16>& accept_filters) {
const std::vector<std::u16string>& accept_filters) {
std::vector<std::wstring> extensions;
std::vector<std::wstring> descriptions;
for (size_t i = 0; i < accept_filters.size(); ++i) {
const base::string16& filter = accept_filters[i];
const std::wstring& filter = base::UTF16ToWide(accept_filters[i]);
if (filter.empty())
continue;
size_t sep_index = filter.find('|');
if (sep_index != base::string16::npos) {
size_t sep_index = filter.find(L'|');
if (sep_index != std::wstring::npos) {
// Treat as a filter of the form "Filter Name|.ext1;.ext2;.ext3".
const base::string16& desc = filter.substr(0, sep_index);
const std::vector<base::string16>& ext = base::SplitString(
filter.substr(sep_index + 1), base::ASCIIToUTF16(";"),
const std::wstring& desc = filter.substr(0, sep_index);
const std::vector<std::u16string>& ext = base::SplitString(
base::WideToUTF16(filter.substr(sep_index + 1)), u";",
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
std::wstring ext_str;
for (size_t x = 0; x < ext.size(); ++x) {
const base::string16& file_ext = ext[x];
if (!file_ext.empty() && file_ext[0] == '.') {
const std::wstring& file_ext = base::UTF16ToWide(ext[x]);
if (!file_ext.empty() && file_ext[0] == L'.') {
if (!ext_str.empty())
ext_str += L";";
ext_str += L"*" + file_ext;
@@ -210,7 +213,7 @@ std::wstring GetFilterString(
descriptions.push_back(std::wstring());
} else {
// Otherwise convert mime type to one or more extensions.
const std::string& ascii = base::UTF16ToASCII(filter);
const std::string& ascii = base::WideToASCII(filter);
std::vector<base::FilePath::StringType> ext;
std::wstring ext_str;
net::GetExtensionsForMimeType(ascii, &ext);
@@ -264,10 +267,12 @@ bool RunOpenFileDialog(const CefFileDialogRunner::FileChooserParams& params,
ofn.lpstrInitialDir = directory.c_str();
std::wstring title;
if (!params.title.empty())
title = params.title;
else
title = l10n_util::GetStringUTF16(IDS_OPEN_FILE_DIALOG_TITLE);
if (!params.title.empty()) {
title = base::UTF16ToWide(params.title);
} else {
title = base::UTF16ToWide(
l10n_util::GetStringUTF16(IDS_OPEN_FILE_DIALOG_TITLE));
}
if (!title.empty())
ofn.lpstrTitle = title.c_str();
@@ -326,10 +331,12 @@ bool RunOpenMultiFileDialog(
ofn.lpstrInitialDir = directory.c_str();
std::wstring title;
if (!params.title.empty())
title = params.title;
else
title = l10n_util::GetStringUTF16(IDS_OPEN_FILES_DIALOG_TITLE);
if (!params.title.empty()) {
title = base::UTF16ToWide(params.title);
} else {
title = base::UTF16ToWide(
l10n_util::GetStringUTF16(IDS_OPEN_FILES_DIALOG_TITLE));
}
if (!title.empty())
ofn.lpstrTitle = title.c_str();
@@ -404,10 +411,12 @@ bool RunOpenFolderDialog(const CefFileDialogRunner::FileChooserParams& params,
browse_info.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS;
std::wstring title;
if (!params.title.empty())
title = params.title;
else
title = l10n_util::GetStringUTF16(IDS_SELECT_FOLDER_DIALOG_TITLE);
if (!params.title.empty()) {
title = base::UTF16ToWide(params.title);
} else {
title = base::UTF16ToWide(
l10n_util::GetStringUTF16(IDS_SELECT_FOLDER_DIALOG_TITLE));
}
if (!title.empty())
browse_info.lpszTitle = title.c_str();
@@ -479,10 +488,12 @@ bool RunSaveFileDialog(const CefFileDialogRunner::FileChooserParams& params,
ofn.lpstrInitialDir = directory.c_str();
std::wstring title;
if (!params.title.empty())
title = params.title;
else
title = l10n_util::GetStringUTF16(IDS_SAVE_AS_DIALOG_TITLE);
if (!params.title.empty()) {
title = base::UTF16ToWide(params.title);
} else {
title =
base::UTF16ToWide(l10n_util::GetStringUTF16(IDS_SAVE_AS_DIALOG_TITLE));
}
if (!title.empty())
ofn.lpstrTitle = title.c_str();

View File

@@ -26,14 +26,14 @@ class CefJavaScriptDialogRunnerMac : public CefJavaScriptDialogRunner {
// CefJavaScriptDialogRunner methods:
void Run(AlloyBrowserHostImpl* browser,
content::JavaScriptDialogType message_type,
const base::string16& display_url,
const base::string16& message_text,
const base::string16& default_prompt_text,
const std::u16string& display_url,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback) override;
void Cancel() override;
// Callback from CefJavaScriptDialogHelper when the dialog is closed.
void DialogClosed(bool success, const base::string16& user_input);
void DialogClosed(bool success, const std::u16string& user_input);
private:
DialogClosedCallback callback_;

View File

@@ -65,7 +65,7 @@
return;
bool success = returnCode == NSAlertFirstButtonReturn;
base::string16 input;
std::u16string input;
if (textField_)
input = base::SysNSStringToUTF16([textField_ stringValue]);
@@ -89,9 +89,9 @@ CefJavaScriptDialogRunnerMac::~CefJavaScriptDialogRunnerMac() {
void CefJavaScriptDialogRunnerMac::Run(
AlloyBrowserHostImpl* browser,
content::JavaScriptDialogType message_type,
const base::string16& display_url,
const base::string16& message_text,
const base::string16& default_prompt_text,
const std::u16string& display_url,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback) {
DCHECK(!helper_.get());
callback_ = std::move(callback);
@@ -114,20 +114,20 @@ void CefJavaScriptDialogRunnerMac::Run(
[alert setDelegate:helper_];
[alert setInformativeText:base::SysUTF16ToNSString(message_text)];
base::string16 label;
std::u16string label;
switch (message_type) {
case content::JAVASCRIPT_DIALOG_TYPE_ALERT:
label = base::ASCIIToUTF16("JavaScript Alert");
label = u"JavaScript Alert";
break;
case content::JAVASCRIPT_DIALOG_TYPE_PROMPT:
label = base::ASCIIToUTF16("JavaScript Prompt");
label = u"JavaScript Prompt";
break;
case content::JAVASCRIPT_DIALOG_TYPE_CONFIRM:
label = base::ASCIIToUTF16("JavaScript Confirm");
label = u"JavaScript Confirm";
break;
}
if (!display_url.empty())
label += base::ASCIIToUTF16(" - ") + display_url;
label += u" - " + display_url;
[alert setMessageText:base::SysUTF16ToNSString(label)];
@@ -165,7 +165,7 @@ void CefJavaScriptDialogRunnerMac::Cancel() {
void CefJavaScriptDialogRunnerMac::DialogClosed(
bool success,
const base::string16& user_input) {
const std::u16string& user_input) {
helper_.reset(nil);
std::move(callback_).Run(success, user_input);
}

View File

@@ -39,7 +39,7 @@ INT_PTR CALLBACK CefJavaScriptDialogRunnerWin::DialogProc(HWND dialog,
reinterpret_cast<CefJavaScriptDialogRunnerWin*>(
GetWindowLongPtr(dialog, DWLP_USER));
if (owner) {
owner->CloseDialog(false, base::string16());
owner->CloseDialog(false, std::wstring());
// No need for the system to call DestroyWindow() because it will be
// called by the Cancel() method.
@@ -51,7 +51,7 @@ INT_PTR CALLBACK CefJavaScriptDialogRunnerWin::DialogProc(HWND dialog,
CefJavaScriptDialogRunnerWin* owner =
reinterpret_cast<CefJavaScriptDialogRunnerWin*>(
GetWindowLongPtr(dialog, DWLP_USER));
base::string16 user_input;
std::wstring user_input;
bool finish = false;
bool result = false;
switch (LOWORD(wparam)) {
@@ -62,8 +62,9 @@ INT_PTR CALLBACK CefJavaScriptDialogRunnerWin::DialogProc(HWND dialog,
size_t length =
GetWindowTextLength(GetDlgItem(dialog, IDC_PROMPTEDIT)) + 1;
if (length > 1) {
GetDlgItemText(dialog, IDC_PROMPTEDIT,
base::WriteInto(&user_input, length), length);
user_input.reserve(length);
user_input.resize(length - 1);
GetDlgItemText(dialog, IDC_PROMPTEDIT, &user_input[0], length);
}
}
break;
@@ -93,15 +94,15 @@ CefJavaScriptDialogRunnerWin::~CefJavaScriptDialogRunnerWin() {
void CefJavaScriptDialogRunnerWin::Run(
AlloyBrowserHostImpl* browser,
content::JavaScriptDialogType message_type,
const base::string16& display_url,
const base::string16& message_text,
const base::string16& default_prompt_text,
const std::u16string& display_url,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback) {
DCHECK(!dialog_win_);
message_type_ = message_type;
message_text_ = message_text;
default_prompt_text_ = default_prompt_text;
message_text_ = base::UTF16ToWide(message_text);
default_prompt_text_ = base::UTF16ToWide(default_prompt_text);
callback_ = std::move(callback);
InstallMessageHook();
@@ -135,11 +136,11 @@ void CefJavaScriptDialogRunnerWin::Run(
if (!display_url.empty()) {
// Add the display URL to the window title.
TCHAR text[64];
GetWindowText(dialog_win_, text, sizeof(text) / sizeof(TCHAR));
wchar_t text[64];
GetWindowText(dialog_win_, text, sizeof(text) / sizeof(wchar_t));
base::string16 new_window_text =
text + base::ASCIIToUTF16(" - ") + display_url;
std::wstring new_window_text =
std::wstring(text) + L" - " + base::UTF16ToWide(display_url);
SetWindowText(dialog_win_, new_window_text.c_str());
}
@@ -170,14 +171,13 @@ void CefJavaScriptDialogRunnerWin::Cancel() {
}
}
void CefJavaScriptDialogRunnerWin::CloseDialog(
bool success,
const base::string16& user_input) {
void CefJavaScriptDialogRunnerWin::CloseDialog(bool success,
const std::wstring& user_input) {
// Run the callback first so that RenderProcessHostImpl::IsBlocked is
// cleared. Otherwise, RenderWidgetHostImpl::IsIgnoringInputEvents will
// return true and RenderWidgetHostViewAura::OnWindowFocused will fail to
// re-assign browser focus.
std::move(callback_).Run(success, user_input);
std::move(callback_).Run(success, base::WideToUTF16(user_input));
Cancel();
}

View File

@@ -19,21 +19,21 @@ class CefJavaScriptDialogRunnerWin : public CefJavaScriptDialogRunner {
// CefJavaScriptDialogRunner methods:
void Run(AlloyBrowserHostImpl* browser,
content::JavaScriptDialogType message_type,
const base::string16& display_url,
const base::string16& message_text,
const base::string16& default_prompt_text,
const std::u16string& display_url,
const std::u16string& message_text,
const std::u16string& default_prompt_text,
DialogClosedCallback callback) override;
void Cancel() override;
private:
void CloseDialog(bool success, const base::string16& user_input);
void CloseDialog(bool success, const std::wstring& user_input);
HWND dialog_win_;
HWND parent_win_;
content::JavaScriptDialogType message_type_;
base::string16 message_text_;
base::string16 default_prompt_text_;
std::wstring message_text_;
std::wstring default_prompt_text_;
DialogClosedCallback callback_;
bool hook_installed_;

View File

@@ -37,8 +37,8 @@ void CefMenuRunnerLinux::CancelContextMenu() {
menu_->Cancel();
}
bool CefMenuRunnerLinux::FormatLabel(base::string16& label) {
bool CefMenuRunnerLinux::FormatLabel(std::u16string& label) {
// Remove the accelerator indicator (&) from label strings.
const base::string16::value_type replace[] = {L'&', 0};
return base::ReplaceChars(label, replace, base::string16(), &label);
const std::u16string::value_type replace[] = {u'&', 0};
return base::ReplaceChars(label, replace, std::u16string(), &label);
}

View File

@@ -19,7 +19,7 @@ class CefMenuRunnerLinux : public CefMenuRunner {
CefMenuModelImpl* model,
const content::ContextMenuParams& params) override;
void CancelContextMenu() override;
bool FormatLabel(base::string16& label) override;
bool FormatLabel(std::u16string& label) override;
private:
std::unique_ptr<views::MenuRunner> menu_;

View File

@@ -93,7 +93,7 @@ HFONT CreateNativeFont(const gfx::Font& font) {
italic, underline, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
base::UTF8ToUTF16(font.GetFontName()).c_str());
base::UTF8ToWide(font.GetFontName()).c_str());
}
} // namespace
@@ -102,7 +102,7 @@ struct CefNativeMenuWin::ItemData {
// The Windows API requires that whoever creates the menus must own the
// strings used for labels, and keep them around for the lifetime of the
// created menu. So be it.
base::string16 label;
std::wstring label;
// Someone needs to own submenus, it may as well be us.
std::unique_ptr<Menu2> submenu;
@@ -204,14 +204,14 @@ class CefNativeMenuWin::MenuHostWindow {
if (data) {
gfx::FontList font_list;
measure_item_struct->itemWidth =
gfx::GetStringWidth(data->label, font_list) + kIconWidth +
kItemLeftMargin + kItemLabelSpacing -
gfx::GetStringWidth(base::WideToUTF16(data->label), font_list) +
kIconWidth + kItemLeftMargin + kItemLabelSpacing -
GetSystemMetrics(SM_CXMENUCHECK);
if (data->submenu.get())
measure_item_struct->itemWidth += kArrowWidth;
// If the label contains an accelerator, make room for tab.
if (data->label.find(L'\t') != base::string16::npos)
measure_item_struct->itemWidth += gfx::GetStringWidth(L" ", font_list);
if (data->label.find(L'\t') != std::wstring::npos)
measure_item_struct->itemWidth += gfx::GetStringWidth(u" ", font_list);
measure_item_struct->itemHeight =
font_list.GetHeight() + kItemBottomMargin + kItemTopMargin;
} else {
@@ -267,10 +267,10 @@ class CefNativeMenuWin::MenuHostWindow {
// left and the accelerator on the right.
// TODO(jungshik): This will break in RTL UI. Currently, he/ar use the
// window system UI font and will not hit here.
base::string16 label = data->label;
base::string16 accel;
base::string16::size_type tab_pos = label.find(L'\t');
if (tab_pos != base::string16::npos) {
std::wstring label = data->label;
std::wstring accel;
std::wstring::size_type tab_pos = label.find(L'\t');
if (tab_pos != std::wstring::npos) {
accel = label.substr(tab_pos);
label = label.substr(0, tab_pos);
}
@@ -527,7 +527,7 @@ void CefNativeMenuWin::UpdateStates() {
if (model_->IsItemDynamicAt(model_index)) {
// TODO(atwilson): Update the icon as well (http://crbug.com/66508).
SetMenuItemLabel(menu_index, model_index,
model_->GetLabelAt(model_index));
base::UTF16ToWide(model_->GetLabelAt(model_index)));
}
Menu2* submenu = (*it)->submenu.get();
if (submenu)
@@ -643,7 +643,7 @@ void CefNativeMenuWin::AddMenuItemAt(int menu_index, int model_index) {
mii.fType = MFT_OWNERDRAW;
std::unique_ptr<ItemData> item_data = std::make_unique<ItemData>();
item_data->label = base::string16();
item_data->label = std::wstring();
ui::MenuModel::ItemType type = model_->GetTypeAt(model_index);
if (type == ui::MenuModel::TYPE_SUBMENU) {
item_data->submenu.reset(new Menu2(model_->GetSubmenuModelAt(model_index)));
@@ -659,8 +659,8 @@ void CefNativeMenuWin::AddMenuItemAt(int menu_index, int model_index) {
item_data->model_index = model_index;
mii.dwItemData = reinterpret_cast<ULONG_PTR>(item_data.get());
items_.insert(items_.begin() + model_index, std::move(item_data));
UpdateMenuItemInfoForString(&mii, model_index,
model_->GetLabelAt(model_index));
UpdateMenuItemInfoForString(
&mii, model_index, base::UTF16ToWide(model_->GetLabelAt(model_index)));
InsertMenuItem(menu_, menu_index, TRUE, &mii);
}
@@ -697,7 +697,7 @@ void CefNativeMenuWin::SetMenuItemState(int menu_index,
void CefNativeMenuWin::SetMenuItemLabel(int menu_index,
int model_index,
const base::string16& label) {
const std::wstring& label) {
if (IsSeparatorItemAt(menu_index))
return;
@@ -707,11 +707,10 @@ void CefNativeMenuWin::SetMenuItemLabel(int menu_index,
SetMenuItemInfo(menu_, menu_index, MF_BYPOSITION, &mii);
}
void CefNativeMenuWin::UpdateMenuItemInfoForString(
MENUITEMINFO* mii,
int model_index,
const base::string16& label) {
base::string16 formatted = label;
void CefNativeMenuWin::UpdateMenuItemInfoForString(MENUITEMINFO* mii,
int model_index,
const std::wstring& label) {
std::wstring formatted = label;
ui::MenuModel::ItemType type = model_->GetTypeAt(model_index);
// Strip out any tabs, otherwise they get interpreted as accelerators and can
// lead to weird behavior.
@@ -721,7 +720,7 @@ void CefNativeMenuWin::UpdateMenuItemInfoForString(
ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE);
if (model_->GetAcceleratorAt(model_index, &accelerator)) {
formatted += L"\t";
formatted += accelerator.GetShortcutText();
formatted += base::UTF16ToWide(accelerator.GetShortcutText());
}
}

View File

@@ -14,7 +14,6 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
namespace ui {
class MenuModel;
@@ -73,7 +72,7 @@ class CefNativeMenuWin : public MenuWrapper {
// Sets the label of the item at the specified index.
void SetMenuItemLabel(int menu_index,
int model_index,
const base::string16& label);
const std::wstring& label);
// Updates the local data structure with the correctly formatted version of
// |label| at the specified model_index, and adds string data to |mii| if
@@ -81,7 +80,7 @@ class CefNativeMenuWin : public MenuWrapper {
// of the peculiarities of the Windows menu API.
void UpdateMenuItemInfoForString(MENUITEMINFO* mii,
int model_index,
const base::string16& label);
const std::wstring& label);
// Returns the alignment flags to be passed to TrackPopupMenuEx, based on the
// supplied alignment and the UI text direction.