chore: remove unneeded conversions between wstring and u16string (#30047)
This commit is contained in:
parent
ccfde6c9d4
commit
21f6937728
13 changed files with 63 additions and 66 deletions
|
@ -12,8 +12,8 @@ namespace electron {
|
|||
struct NotificationData {
|
||||
DesktopNotificationController* controller = nullptr;
|
||||
|
||||
std::wstring caption;
|
||||
std::wstring body_text;
|
||||
std::u16string caption;
|
||||
std::u16string body_text;
|
||||
HBITMAP image = NULL;
|
||||
|
||||
NotificationData() = default;
|
||||
|
|
|
@ -274,8 +274,8 @@ void DesktopNotificationController::AnimateAll() {
|
|||
}
|
||||
|
||||
DesktopNotificationController::Notification
|
||||
DesktopNotificationController::AddNotification(std::wstring caption,
|
||||
std::wstring body_text,
|
||||
DesktopNotificationController::AddNotification(std::u16string caption,
|
||||
std::u16string body_text,
|
||||
HBITMAP image) {
|
||||
auto data = std::make_shared<NotificationData>();
|
||||
data->controller = this;
|
||||
|
@ -395,8 +395,8 @@ void DesktopNotificationController::Notification::Close() {
|
|||
data_->controller->CloseNotification(*this);
|
||||
}
|
||||
|
||||
void DesktopNotificationController::Notification::Set(std::wstring caption,
|
||||
std::wstring body_text,
|
||||
void DesktopNotificationController::Notification::Set(std::u16string caption,
|
||||
std::u16string body_text,
|
||||
HBITMAP image) {
|
||||
// No business calling this when not pointing to a valid instance
|
||||
DCHECK(data_);
|
||||
|
|
|
@ -21,8 +21,8 @@ class DesktopNotificationController {
|
|||
~DesktopNotificationController();
|
||||
|
||||
class Notification;
|
||||
Notification AddNotification(std::wstring caption,
|
||||
std::wstring body_text,
|
||||
Notification AddNotification(std::u16string caption,
|
||||
std::u16string body_text,
|
||||
HBITMAP image);
|
||||
void CloseNotification(const Notification& notification);
|
||||
|
||||
|
@ -87,7 +87,7 @@ class DesktopNotificationController::Notification {
|
|||
bool operator==(const Notification& other) const;
|
||||
|
||||
void Close();
|
||||
void Set(std::wstring caption, std::wstring body_text, HBITMAP image);
|
||||
void Set(std::u16string caption, std::u16string body_text, HBITMAP image);
|
||||
|
||||
private:
|
||||
std::shared_ptr<NotificationData> data_;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util_win.h"
|
||||
#include "shell/browser/notifications/win/win32_desktop_notifications/common.h"
|
||||
#include "shell/browser/notifications/win/win32_desktop_notifications/toast_uia.h"
|
||||
|
||||
|
@ -479,7 +480,8 @@ void DesktopNotificationController::Toast::Draw() {
|
|||
|
||||
SelectFont(hdc_, caption_font);
|
||||
SetTextColor(hdc_, fore_color);
|
||||
DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), &rc,
|
||||
DrawText(hdc_, base::as_wcstr(data_->caption),
|
||||
(UINT)data_->caption.length(), &rc,
|
||||
DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX);
|
||||
}
|
||||
|
||||
|
@ -490,8 +492,8 @@ void DesktopNotificationController::Toast::Draw() {
|
|||
|
||||
SelectFont(hdc_, body_font);
|
||||
SetTextColor(hdc_, dimmed_color);
|
||||
DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(),
|
||||
&rc,
|
||||
DrawText(hdc_, base::as_wcstr(data_->body_text),
|
||||
(UINT)data_->body_text.length(), &rc,
|
||||
DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS |
|
||||
DT_EDITCONTROL);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <UIAutomation.h>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/strings/string_util_win.h"
|
||||
#include "shell/browser/notifications/win/win32_desktop_notifications/common.h"
|
||||
|
||||
#pragma comment(lib, "uiautomationcore.lib")
|
||||
|
@ -19,7 +20,7 @@ DesktopNotificationController::Toast::UIAutomationInterface::
|
|||
text_ = toast->data_->caption;
|
||||
if (!toast->data_->body_text.empty()) {
|
||||
if (!text_.empty())
|
||||
text_.append(L", ");
|
||||
text_.append(u", ");
|
||||
text_.append(toast->data_->body_text);
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +108,7 @@ DesktopNotificationController::Toast::UIAutomationInterface::GetPropertyValue(
|
|||
switch (property_id) {
|
||||
case UIA_NamePropertyId:
|
||||
retval->vt = VT_BSTR;
|
||||
retval->bstrVal = SysAllocString(text_.c_str());
|
||||
retval->bstrVal = SysAllocString(base::as_wcstr(text_));
|
||||
break;
|
||||
|
||||
case UIA_ClassNamePropertyId:
|
||||
|
|
|
@ -76,7 +76,7 @@ class DesktopNotificationController::Toast::UIAutomationInterface
|
|||
private:
|
||||
volatile LONG cref_ = 0;
|
||||
HWND hwnd_;
|
||||
std::wstring text_;
|
||||
std::u16string text_;
|
||||
};
|
||||
|
||||
} // namespace electron
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue