2018-10-17 18:01:11 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WIN32_DESKTOP_NOTIFICATIONS_TOAST_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WIN32_DESKTOP_NOTIFICATIONS_TOAST_H_
|
2018-10-17 18:01:11 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/notifications/win/win32_desktop_notifications/desktop_notification_controller.h"
|
2018-10-17 18:01:11 +00:00
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "base/check.h"
|
2019-03-22 06:45:28 +00:00
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
namespace electron {
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-04-03 10:11:39 +00:00
|
|
|
class DesktopNotificationController::Toast {
|
2017-04-05 11:15:06 +00:00
|
|
|
public:
|
2018-04-18 01:46:27 +00:00
|
|
|
static void Register(HINSTANCE hinstance);
|
|
|
|
static HWND Create(HINSTANCE hinstance,
|
2018-10-17 18:01:11 +00:00
|
|
|
std::shared_ptr<NotificationData> data);
|
2018-04-18 01:46:27 +00:00
|
|
|
static Toast* Get(HWND hwnd) {
|
|
|
|
return reinterpret_cast<Toast*>(GetWindowLongPtr(hwnd, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hwnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wparam,
|
|
|
|
LPARAM lparam);
|
|
|
|
|
|
|
|
const std::shared_ptr<NotificationData>& GetNotification() const {
|
|
|
|
return data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetContents();
|
|
|
|
|
|
|
|
void Dismiss();
|
|
|
|
|
|
|
|
void PopUp(int y);
|
|
|
|
void SetVerticalPosition(int y);
|
|
|
|
int GetVerticalPosition() const { return vertical_pos_target_; }
|
|
|
|
int GetHeight() const { return toast_size_.cy; }
|
|
|
|
HDWP Animate(HDWP hdwp, const POINT& origin);
|
|
|
|
bool IsAnimationActive() const {
|
|
|
|
return ease_in_active_ || ease_out_active_ || IsStackCollapseActive();
|
|
|
|
}
|
|
|
|
bool IsHighlighted() const {
|
2019-03-22 05:50:33 +00:00
|
|
|
DCHECK(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
|
2018-04-18 01:46:27 +00:00
|
|
|
return is_highlighted_;
|
|
|
|
}
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-04-05 11:15:06 +00:00
|
|
|
private:
|
2018-04-18 01:46:27 +00:00
|
|
|
enum TimerID { TimerID_AutoDismiss = 1 };
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
Toast(HWND hwnd, std::shared_ptr<NotificationData>* data);
|
|
|
|
~Toast();
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
void UpdateBufferSize();
|
|
|
|
void UpdateScaledImage(const SIZE& size);
|
|
|
|
void Draw();
|
|
|
|
void Invalidate();
|
|
|
|
bool IsRedrawNeeded() const;
|
|
|
|
void UpdateContents();
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
void AutoDismiss();
|
|
|
|
void CancelDismiss();
|
|
|
|
void ScheduleDismissal();
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
void StartEaseIn();
|
|
|
|
void StartEaseOut();
|
|
|
|
bool IsStackCollapseActive() const;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
float AnimateEaseIn();
|
|
|
|
float AnimateEaseOut();
|
|
|
|
float AnimateStackCollapse();
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-04-05 11:15:06 +00:00
|
|
|
private:
|
2018-06-28 21:25:26 +00:00
|
|
|
static const TCHAR class_name_[];
|
2018-04-18 01:46:27 +00:00
|
|
|
|
|
|
|
const HWND hwnd_;
|
|
|
|
HDC hdc_;
|
|
|
|
HBITMAP bitmap_ = NULL;
|
|
|
|
|
2018-09-12 14:18:35 +00:00
|
|
|
class UIAutomationInterface;
|
|
|
|
UIAutomationInterface* uia_ = nullptr;
|
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
const std::shared_ptr<NotificationData> data_; // never null
|
|
|
|
|
|
|
|
SIZE toast_size_ = {};
|
|
|
|
SIZE margin_ = {};
|
|
|
|
RECT close_button_rect_ = {};
|
|
|
|
HBITMAP scaled_image_ = NULL;
|
|
|
|
|
|
|
|
int vertical_pos_ = 0;
|
|
|
|
int vertical_pos_target_ = 0;
|
|
|
|
bool is_non_interactive_ = false;
|
|
|
|
bool ease_in_active_ = false;
|
|
|
|
bool ease_out_active_ = false;
|
|
|
|
bool is_content_updated_ = false;
|
|
|
|
bool is_highlighted_ = false;
|
|
|
|
bool is_close_hot_ = false;
|
|
|
|
DWORD ease_in_start_, ease_out_start_, stack_collapse_start_;
|
|
|
|
float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0;
|
2017-03-15 12:56:06 +00:00
|
|
|
};
|
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WIN32_DESKTOP_NOTIFICATIONS_TOAST_H_
|