clang-format brightray

This commit is contained in:
Shelley Vohr 2018-04-17 21:46:27 -04:00
parent 7a8a0f6b4b
commit 284aca68c0
No known key found for this signature in database
GPG key ID: F13993A75599653C
25 changed files with 268 additions and 273 deletions

View file

@ -21,8 +21,8 @@ enum {
PATH_START = 11000, PATH_START = 11000,
DIR_USER_DATA = PATH_START, // Directory where user data can be written. DIR_USER_DATA = PATH_START, // Directory where user data can be written.
DIR_USER_CACHE, // Directory where user cache can be written. DIR_USER_CACHE, // Directory where user cache can be written.
DIR_APP_LOGS, // Directory where app logs live DIR_APP_LOGS, // Directory where app logs live
#if defined(OS_LINUX) #if defined(OS_LINUX)
DIR_APP_DATA, // Application Data directory under the user profile. DIR_APP_DATA, // Application Data directory under the user profile.

View file

@ -32,8 +32,8 @@ class BrowserContext : public base::RefCounted<BrowserContext>,
public: public:
// Get the BrowserContext according to its |partition| and |in_memory|, // Get the BrowserContext according to its |partition| and |in_memory|,
// empty pointer when be returned when there is no matching BrowserContext. // empty pointer when be returned when there is no matching BrowserContext.
static scoped_refptr<BrowserContext> Get( static scoped_refptr<BrowserContext> Get(const std::string& partition,
const std::string& partition, bool in_memory); bool in_memory);
base::WeakPtr<BrowserContext> GetWeakPtr() { base::WeakPtr<BrowserContext> GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();

View file

@ -14,8 +14,7 @@
class DevToolsContentsResizingStrategy { class DevToolsContentsResizingStrategy {
public: public:
DevToolsContentsResizingStrategy(); DevToolsContentsResizingStrategy();
explicit DevToolsContentsResizingStrategy( explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds);
const gfx::Rect& bounds);
void CopyFrom(const DevToolsContentsResizingStrategy& strategy); void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
bool Equals(const DevToolsContentsResizingStrategy& strategy); bool Equals(const DevToolsContentsResizingStrategy& strategy);

View file

@ -16,7 +16,7 @@
namespace base { namespace base {
class ListValue; class ListValue;
class Value; class Value;
} } // namespace base
namespace brightray { namespace brightray {

View file

@ -21,7 +21,7 @@ namespace base {
class FilePath; class FilePath;
class FileEnumerator; class FileEnumerator;
class Time; class Time;
} } // namespace base
namespace content { namespace content {
class WebContents; class WebContents;
@ -56,9 +56,7 @@ class DevToolsFileSystemIndexer
void IndexFiles(); void IndexFiles();
void StartFileIndexing(base::File::Error error); void StartFileIndexing(base::File::Error error);
void ReadFromFile(); void ReadFromFile();
void OnRead(base::File::Error error, void OnRead(base::File::Error error, const char* data, int bytes_read);
const char* data,
int bytes_read);
void FinishFileIndexing(bool success); void FinishFileIndexing(bool success);
void CloseFile(); void CloseFile();
void CloseCallback(base::File::Error error); void CloseCallback(base::File::Error error);

View file

@ -22,10 +22,9 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate {
// DevToolsManagerDelegate implementation. // DevToolsManagerDelegate implementation.
void Inspect(content::DevToolsAgentHost* agent_host) override; void Inspect(content::DevToolsAgentHost* agent_host) override;
bool HandleCommand( bool HandleCommand(content::DevToolsAgentHost* agent_host,
content::DevToolsAgentHost* agent_host, int session_id,
int session_id, base::DictionaryValue* command) override;
base::DictionaryValue* command) override;
scoped_refptr<content::DevToolsAgentHost> CreateNewTarget( scoped_refptr<content::DevToolsAgentHost> CreateNewTarget(
const GURL& url) override; const GURL& url) override;
std::string GetDiscoveryPageHTML() override; std::string GetDiscoveryPageHTML() override;

View file

@ -11,22 +11,21 @@ class InspectableWebContentsDelegate {
// Requested by WebContents of devtools. // Requested by WebContents of devtools.
virtual void DevToolsReloadPage() {} virtual void DevToolsReloadPage() {}
virtual void DevToolsSaveToFile( virtual void DevToolsSaveToFile(const std::string& url,
const std::string& url, const std::string& content, bool save_as) {} const std::string& content,
virtual void DevToolsAppendToFile( bool save_as) {}
const std::string& url, const std::string& content) {} virtual void DevToolsAppendToFile(const std::string& url,
const std::string& content) {}
virtual void DevToolsRequestFileSystems() {} virtual void DevToolsRequestFileSystems() {}
virtual void DevToolsAddFileSystem( virtual void DevToolsAddFileSystem(const base::FilePath& file_system_path) {}
const base::FilePath& file_system_path) {}
virtual void DevToolsRemoveFileSystem( virtual void DevToolsRemoveFileSystem(
const base::FilePath& file_system_path) {} const base::FilePath& file_system_path) {}
virtual void DevToolsIndexPath( virtual void DevToolsIndexPath(int request_id,
int request_id, const std::string& file_system_path) {} const std::string& file_system_path) {}
virtual void DevToolsStopIndexing(int request_id) {} virtual void DevToolsStopIndexing(int request_id) {}
virtual void DevToolsSearchInPath( virtual void DevToolsSearchInPath(int request_id,
int request_id, const std::string& file_system_path,
const std::string& file_system_path, const std::string& query) {}
const std::string& query) {}
}; };
} // namespace brightray } // namespace brightray

View file

@ -29,13 +29,13 @@ namespace brightray {
class InspectableWebContentsDelegate; class InspectableWebContentsDelegate;
class InspectableWebContentsView; class InspectableWebContentsView;
class InspectableWebContentsImpl : class InspectableWebContentsImpl
public InspectableWebContents, : public InspectableWebContents,
public content::DevToolsAgentHostClient, public content::DevToolsAgentHostClient,
public content::WebContentsObserver, public content::WebContentsObserver,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public DevToolsEmbedderMessageDispatcher::Delegate, public DevToolsEmbedderMessageDispatcher::Delegate,
public net::URLFetcherDelegate { public net::URLFetcherDelegate {
public: public:
static void RegisterPrefs(PrefRegistrySimple* pref_registry); static void RegisterPrefs(PrefRegistrySimple* pref_registry);
@ -156,8 +156,8 @@ class InspectableWebContentsImpl :
const GURL& target_url, const GURL& target_url,
const std::string& partition_id, const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) override; content::SessionStorageNamespace* session_storage_namespace) override;
void HandleKeyboardEvent( void HandleKeyboardEvent(content::WebContents*,
content::WebContents*, const content::NativeWebKeyboardEvent&) override; const content::NativeWebKeyboardEvent&) override;
void CloseContents(content::WebContents* source) override; void CloseContents(content::WebContents* source) override;
content::ColorChooser* OpenColorChooser( content::ColorChooser* OpenColorChooser(
content::WebContents* source, content::WebContents* source,
@ -172,8 +172,7 @@ class InspectableWebContentsImpl :
// net::URLFetcherDelegate: // net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override; void OnURLFetchComplete(const net::URLFetcher* source) override;
void SendMessageAck(int request_id, void SendMessageAck(int request_id, const base::Value* arg1);
const base::Value* arg1);
bool frontend_loaded_; bool frontend_loaded_;
scoped_refptr<content::DevToolsAgentHost> agent_host_; scoped_refptr<content::DevToolsAgentHost> agent_host_;

View file

@ -25,9 +25,7 @@ class InspectableWebContentsView {
void SetDelegate(InspectableWebContentsViewDelegate* delegate) { void SetDelegate(InspectableWebContentsViewDelegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
} }
InspectableWebContentsViewDelegate* GetDelegate() const { InspectableWebContentsViewDelegate* GetDelegate() const { return delegate_; }
return delegate_;
}
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
// Returns the container control, which has devtools view attached. // Returns the container control, which has devtools view attached.

View file

@ -20,8 +20,8 @@ class InspectableWebContentsViewDelegate {
#if defined(USE_X11) #if defined(USE_X11)
// Called when creating devtools window. // Called when creating devtools window.
virtual void GetDevToolsWindowWMClass( virtual void GetDevToolsWindowWMClass(std::string* name,
std::string* name, std::string* class_name) {} std::string* class_name) {}
#endif #endif
}; };

View file

@ -13,7 +13,7 @@
namespace net { namespace net {
class URLRequestContext; class URLRequestContext;
class URLRequestContextGetter; class URLRequestContextGetter;
} } // namespace net
namespace brightray { namespace brightray {

View file

@ -27,10 +27,15 @@ class LibnotifyNotification : public Notification {
void Dismiss() override; void Dismiss() override;
private: private:
CHROMEG_CALLBACK_0(LibnotifyNotification, void, OnNotificationClosed, CHROMEG_CALLBACK_0(LibnotifyNotification,
void,
OnNotificationClosed,
NotifyNotification*); NotifyNotification*);
CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView, CHROMEG_CALLBACK_1(LibnotifyNotification,
NotifyNotification*, char*); void,
OnNotificationView,
NotifyNotification*,
char*);
NotifyNotification* notification_; NotifyNotification* notification_;

View file

@ -10,8 +10,8 @@ class InspectableWebContentsViewMac;
using brightray::InspectableWebContentsViewMac; using brightray::InspectableWebContentsViewMac;
@interface BRYInspectableWebContentsView : BaseView<NSWindowDelegate> { @interface BRYInspectableWebContentsView : BaseView <NSWindowDelegate> {
@private @private
brightray::InspectableWebContentsViewMac* inspectableWebContentsView_; brightray::InspectableWebContentsViewMac* inspectableWebContentsView_;
base::scoped_nsobject<NSWindow> devtools_window_; base::scoped_nsobject<NSWindow> devtools_window_;
@ -22,14 +22,16 @@ using brightray::InspectableWebContentsViewMac;
DevToolsContentsResizingStrategy strategy_; DevToolsContentsResizingStrategy strategy_;
} }
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; - (instancetype)initWithInspectableWebContentsViewMac:
(InspectableWebContentsViewMac*)view;
- (void)removeObservers; - (void)removeObservers;
- (void)notifyDevToolsFocused; - (void)notifyDevToolsFocused;
- (void)setDevToolsVisible:(BOOL)visible; - (void)setDevToolsVisible:(BOOL)visible;
- (BOOL)isDevToolsVisible; - (BOOL)isDevToolsVisible;
- (BOOL)isDevToolsFocused; - (BOOL)isDevToolsFocused;
- (void)setIsDocked:(BOOL)docked; - (void)setIsDocked:(BOOL)docked;
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; - (void)setContentsResizingStrategy:
(const DevToolsContentsResizingStrategy&)strategy;
- (void)setTitle:(NSString*)title; - (void)setTitle:(NSString*)title;
@end @end

View file

@ -11,12 +11,13 @@ namespace brightray {
class NotificationPresenterMac; class NotificationPresenterMac;
} }
@interface NotificationCenterDelegate : @interface NotificationCenterDelegate
NSObject<NSUserNotificationCenterDelegate> { : NSObject <NSUserNotificationCenterDelegate> {
@private @private
brightray::NotificationPresenterMac* presenter_; brightray::NotificationPresenterMac* presenter_;
} }
- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter; - (instancetype)initWithPresenter:
(brightray::NotificationPresenterMac*)presenter;
@end @end
#endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_ #endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_

View file

@ -34,10 +34,10 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
// Helpers for picking particular requested devices, identified by raw id. // Helpers for picking particular requested devices, identified by raw id.
// If the device requested is not available it will return NULL. // If the device requested is not available it will return NULL.
const content::MediaStreamDevice* const content::MediaStreamDevice* GetRequestedAudioDevice(
GetRequestedAudioDevice(const std::string& requested_audio_device_id); const std::string& requested_audio_device_id);
const content::MediaStreamDevice* const content::MediaStreamDevice* GetRequestedVideoDevice(
GetRequestedVideoDevice(const std::string& requested_video_device_id); const std::string& requested_video_device_id);
// Returns the first available audio or video device, or NULL if no devices // Returns the first available audio or video device, or NULL if no devices
// are available. // are available.
@ -52,13 +52,12 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
// Overridden from content::MediaObserver: // Overridden from content::MediaObserver:
void OnAudioCaptureDevicesChanged() override; void OnAudioCaptureDevicesChanged() override;
void OnVideoCaptureDevicesChanged() override; void OnVideoCaptureDevicesChanged() override;
void OnMediaRequestStateChanged( void OnMediaRequestStateChanged(int render_process_id,
int render_process_id, int render_view_id,
int render_view_id, int page_request_id,
int page_request_id, const GURL& security_origin,
const GURL& security_origin, content::MediaStreamType stream_type,
content::MediaStreamType stream_type, content::MediaRequestState state) override;
content::MediaRequestState state) override;
void OnCreatingAudioStream(int render_process_id, void OnCreatingAudioStream(int render_process_id,
int render_view_id) override; int render_view_id) override;
void OnSetCapturingLinkSecured(int render_process_id, void OnSetCapturingLinkSecured(int render_process_id,

View file

@ -45,8 +45,7 @@ class NetworkDelegate : public net::NetworkDelegate {
int64_t bytes_sent) override; int64_t bytes_sent) override;
void OnCompleted(net::URLRequest* request, bool started) override; void OnCompleted(net::URLRequest* request, bool started) override;
void OnURLRequestDestroyed(net::URLRequest* request) override; void OnURLRequestDestroyed(net::URLRequest* request) override;
void OnPACScriptError(int line_number, void OnPACScriptError(int line_number, const base::string16& error) override;
const base::string16& error) override;
AuthRequiredResponse OnAuthRequired( AuthRequiredResponse OnAuthRequired(
net::URLRequest* request, net::URLRequest* request,
const net::AuthChallengeInfo& auth_info, const net::AuthChallengeInfo& auth_info,

View file

@ -34,7 +34,7 @@ class NetworkDelegate;
class ProxyConfigService; class ProxyConfigService;
class URLRequestContextStorage; class URLRequestContextStorage;
class URLRequestJobFactory; class URLRequestJobFactory;
} } // namespace net
namespace brightray { namespace brightray {

View file

@ -10,7 +10,7 @@ namespace views {
class WebView; class WebView;
class Widget; class Widget;
class WidgetDelegate; class WidgetDelegate;
} } // namespace views
namespace brightray { namespace brightray {

View file

@ -23,13 +23,12 @@ class ViewsDelegate : public views::ViewsDelegate {
const std::string& window_name, const std::string& window_name,
const gfx::Rect& bounds, const gfx::Rect& bounds,
ui::WindowShowState show_state) override; ui::WindowShowState show_state) override;
bool GetSavedWindowPlacement( bool GetSavedWindowPlacement(const views::Widget* widget,
const views::Widget* widget, const std::string& window_name,
const std::string& window_name, gfx::Rect* bounds,
gfx::Rect* bounds, ui::WindowShowState* show_state) const override;
ui::WindowShowState* show_state) const override; void NotifyAccessibilityEvent(views::View* view,
void NotifyAccessibilityEvent( ui::AXEvent event_type) override;
views::View* view, ui::AXEvent event_type) override;
void NotifyMenuItemFocused(const base::string16& menu_name, void NotifyMenuItemFocused(const base::string16& menu_name,
const base::string16& menu_item_name, const base::string16& menu_item_name,
int item_index, int item_index,

View file

@ -10,7 +10,8 @@
#include "content/public/browser/web_ui_controller_factory.h" #include "content/public/browser/web_ui_controller_factory.h"
namespace base { namespace base {
template <typename T> struct DefaultSingletonTraits; template <typename T>
struct DefaultSingletonTraits;
} }
namespace brightray { namespace brightray {
@ -24,8 +25,8 @@ class WebUIControllerFactory : public content::WebUIControllerFactory {
WebUIControllerFactory(); WebUIControllerFactory();
virtual ~WebUIControllerFactory(); virtual ~WebUIControllerFactory();
content::WebUI::TypeID GetWebUIType( content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
content::BrowserContext* browser_context, const GURL& url) const override; const GURL& url) const override;
bool UseWebUIForURL(content::BrowserContext* browser_context, bool UseWebUIForURL(content::BrowserContext* browser_context,
const GURL& url) const override; const GURL& url) const override;
bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, bool UseWebUIBindingsForURL(content::BrowserContext* browser_context,

View file

@ -6,25 +6,24 @@ namespace brightray {
class Win32Notification; class Win32Notification;
class NotificationPresenterWin7 : class NotificationPresenterWin7 : public NotificationPresenter,
public NotificationPresenter, public DesktopNotificationController {
public DesktopNotificationController {
public: public:
NotificationPresenterWin7() = default; NotificationPresenterWin7() = default;
Win32Notification* GetNotificationObjectByRef( Win32Notification* GetNotificationObjectByRef(
const DesktopNotificationController::Notification& ref); const DesktopNotificationController::Notification& ref);
Win32Notification* GetNotificationObjectByTag(const std::string& tag); Win32Notification* GetNotificationObjectByTag(const std::string& tag);
private: private:
brightray::Notification* CreateNotificationObject( brightray::Notification* CreateNotificationObject(
NotificationDelegate* delegate) override; NotificationDelegate* delegate) override;
void OnNotificationClicked(Notification& notification) override; void OnNotificationClicked(Notification& notification) override;
void OnNotificationDismissed(Notification& notification) override; void OnNotificationDismissed(Notification& notification) override;
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7);
}; };
} // namespace brightray } // namespace brightray

View file

@ -4,51 +4,57 @@
namespace brightray { namespace brightray {
struct NotificationData { struct NotificationData {
DesktopNotificationController* controller = nullptr; DesktopNotificationController* controller = nullptr;
std::wstring caption; std::wstring caption;
std::wstring body_text; std::wstring body_text;
HBITMAP image = NULL; HBITMAP image = NULL;
NotificationData() = default; NotificationData() = default;
~NotificationData() { ~NotificationData() {
if (image) DeleteObject(image); if (image)
} DeleteObject(image);
}
NotificationData(const NotificationData& other) = delete; NotificationData(const NotificationData& other) = delete;
NotificationData& operator=(const NotificationData& other) = delete; NotificationData& operator=(const NotificationData& other) = delete;
}; };
template<typename T> template <typename T>
constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) { constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
return value * dpi / source_dpi; return value * dpi / source_dpi;
} }
struct ScreenMetrics { struct ScreenMetrics {
UINT dpi_x, dpi_y; UINT dpi_x, dpi_y;
ScreenMetrics() { ScreenMetrics() {
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>( auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
GetProcAddress(GetModuleHandle(TEXT("shcore")), GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"));
"GetDpiForMonitor"));
if (GetDpiForMonitor) { if (GetDpiForMonitor) {
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)
return; return;
}
HDC hdc = GetDC(NULL);
dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
} }
template<class T> T X(T value) const { return ScaleForDpi(value, dpi_x); } HDC hdc = GetDC(NULL);
template<class T> T Y(T value) const { return ScaleForDpi(value, dpi_y); } dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
}
template <class T>
T X(T value) const {
return ScaleForDpi(value, dpi_x);
}
template <class T>
T Y(T value) const {
return ScaleForDpi(value, dpi_y);
}
}; };
} // namespace brightray } // namespace brightray

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <Windows.h>
#include <deque> #include <deque>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <Windows.h>
namespace brightray { namespace brightray {
@ -11,95 +11,95 @@ struct NotificationData;
class DesktopNotificationController { class DesktopNotificationController {
public: public:
explicit DesktopNotificationController(unsigned maximum_toasts = 3); explicit DesktopNotificationController(unsigned maximum_toasts = 3);
~DesktopNotificationController(); ~DesktopNotificationController();
class Notification; class Notification;
Notification AddNotification(std::wstring caption, std::wstring body_text, Notification AddNotification(std::wstring caption,
HBITMAP image); std::wstring body_text,
void CloseNotification(Notification& notification); HBITMAP image);
void CloseNotification(Notification& notification);
// Event handlers -- override to receive the events // Event handlers -- override to receive the events
private: private:
virtual void OnNotificationClosed(Notification& notification) {} virtual void OnNotificationClosed(Notification& notification) {}
virtual void OnNotificationClicked(Notification& notification) {} virtual void OnNotificationClicked(Notification& notification) {}
virtual void OnNotificationDismissed(Notification& notification) {} virtual void OnNotificationDismissed(Notification& notification) {}
private: private:
static HINSTANCE RegisterWndClasses(); static HINSTANCE RegisterWndClasses();
void StartAnimation(); void StartAnimation();
HFONT GetCaptionFont(); HFONT GetCaptionFont();
HFONT GetBodyFont(); HFONT GetBodyFont();
private: private:
enum TimerID { enum TimerID { TimerID_Animate = 1 };
TimerID_Animate = 1
};
static constexpr int toast_margin_ = 20; static constexpr int toast_margin_ = 20;
// Wrapper around `NotificationData` which makes sure that // Wrapper around `NotificationData` which makes sure that
// the `controller` member is cleared when the controller object // the `controller` member is cleared when the controller object
// stops tracking the notification // stops tracking the notification
struct NotificationLink : std::shared_ptr<NotificationData> { struct NotificationLink : std::shared_ptr<NotificationData> {
explicit NotificationLink(DesktopNotificationController* controller); explicit NotificationLink(DesktopNotificationController* controller);
~NotificationLink(); ~NotificationLink();
NotificationLink(NotificationLink&&) = default; NotificationLink(NotificationLink&&) = default;
NotificationLink(const NotificationLink&) = delete; NotificationLink(const NotificationLink&) = delete;
NotificationLink& operator=(NotificationLink&&) = default; NotificationLink& operator=(NotificationLink&&) = default;
}; };
struct ToastInstance { struct ToastInstance {
HWND hwnd; HWND hwnd;
NotificationLink data; NotificationLink data;
}; };
class Toast; class Toast;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, static LRESULT CALLBACK WndProc(HWND hwnd,
WPARAM wparam, LPARAM lparam); UINT message,
static DesktopNotificationController* Get(HWND hwnd) { WPARAM wparam,
return reinterpret_cast<DesktopNotificationController*>( LPARAM lparam);
GetWindowLongPtr(hwnd, 0)); static DesktopNotificationController* Get(HWND hwnd) {
} return reinterpret_cast<DesktopNotificationController*>(
GetWindowLongPtr(hwnd, 0));
}
DesktopNotificationController( DesktopNotificationController(const DesktopNotificationController&) = delete;
const DesktopNotificationController&) = delete;
void InitializeFonts(); void InitializeFonts();
void ClearAssets(); void ClearAssets();
void AnimateAll(); void AnimateAll();
void CheckQueue(); void CheckQueue();
void CreateToast(NotificationLink&& data); void CreateToast(NotificationLink&& data);
HWND GetToast(const NotificationData* data) const; HWND GetToast(const NotificationData* data) const;
void DestroyToast(ToastInstance& inst); void DestroyToast(ToastInstance& inst);
private: private:
static constexpr const TCHAR class_name_[] = static constexpr const TCHAR class_name_[] =
TEXT("DesktopNotificationController"); TEXT("DesktopNotificationController");
HWND hwnd_controller_ = NULL; HWND hwnd_controller_ = NULL;
HFONT caption_font_ = NULL, body_font_ = NULL; HFONT caption_font_ = NULL, body_font_ = NULL;
std::vector<ToastInstance> instances_; std::vector<ToastInstance> instances_;
std::deque<NotificationLink> queue_; std::deque<NotificationLink> queue_;
bool is_animating_ = false; bool is_animating_ = false;
}; };
class DesktopNotificationController::Notification { class DesktopNotificationController::Notification {
public: public:
Notification() = default; Notification() = default;
explicit Notification(const std::shared_ptr<NotificationData>& data); explicit Notification(const std::shared_ptr<NotificationData>& data);
bool operator==(const Notification& other) const; bool operator==(const Notification& other) const;
void Close(); void Close();
void Set(std::wstring caption, std::wstring body_text, HBITMAP image); void Set(std::wstring caption, std::wstring body_text, HBITMAP image);
private: private:
std::shared_ptr<NotificationData> data_; std::shared_ptr<NotificationData> data_;
friend class DesktopNotificationController; friend class DesktopNotificationController;
}; };
} // namespace brightray } // namespace brightray

View file

@ -5,93 +5,88 @@ namespace brightray {
class DesktopNotificationController::Toast { class DesktopNotificationController::Toast {
public: public:
static void Register(HINSTANCE hinstance); static void Register(HINSTANCE hinstance);
static HWND Create(HINSTANCE hinstance, static HWND Create(HINSTANCE hinstance,
std::shared_ptr<NotificationData>& data); std::shared_ptr<NotificationData>& data);
static Toast* Get(HWND hwnd) { static Toast* Get(HWND hwnd) {
return reinterpret_cast<Toast*>(GetWindowLongPtr(hwnd, 0)); return reinterpret_cast<Toast*>(GetWindowLongPtr(hwnd, 0));
} }
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, static LRESULT CALLBACK WndProc(HWND hwnd,
WPARAM wparam, LPARAM lparam); UINT message,
WPARAM wparam,
LPARAM lparam);
const std::shared_ptr<NotificationData>& GetNotification() const { const std::shared_ptr<NotificationData>& GetNotification() const {
return data_; return data_;
} }
void ResetContents(); void ResetContents();
void Dismiss(); void Dismiss();
void PopUp(int y); void PopUp(int y);
void SetVerticalPosition(int y); void SetVerticalPosition(int y);
int GetVerticalPosition() const { int GetVerticalPosition() const { return vertical_pos_target_; }
return vertical_pos_target_; int GetHeight() const { return toast_size_.cy; }
} HDWP Animate(HDWP hdwp, const POINT& origin);
int GetHeight() const { bool IsAnimationActive() const {
return toast_size_.cy; return ease_in_active_ || ease_out_active_ || IsStackCollapseActive();
} }
HDWP Animate(HDWP hdwp, const POINT& origin); bool IsHighlighted() const {
bool IsAnimationActive() const { _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
return ease_in_active_ || ease_out_active_ || IsStackCollapseActive(); return is_highlighted_;
} }
bool IsHighlighted() const {
_ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
return is_highlighted_;
}
private: private:
enum TimerID { enum TimerID { TimerID_AutoDismiss = 1 };
TimerID_AutoDismiss = 1
};
Toast(HWND hwnd, std::shared_ptr<NotificationData>* data); Toast(HWND hwnd, std::shared_ptr<NotificationData>* data);
~Toast(); ~Toast();
void UpdateBufferSize(); void UpdateBufferSize();
void UpdateScaledImage(const SIZE& size); void UpdateScaledImage(const SIZE& size);
void Draw(); void Draw();
void Invalidate(); void Invalidate();
bool IsRedrawNeeded() const; bool IsRedrawNeeded() const;
void UpdateContents(); void UpdateContents();
void AutoDismiss(); void AutoDismiss();
void CancelDismiss(); void CancelDismiss();
void ScheduleDismissal(); void ScheduleDismissal();
void StartEaseIn(); void StartEaseIn();
void StartEaseOut(); void StartEaseOut();
bool IsStackCollapseActive() const; bool IsStackCollapseActive() const;
float AnimateEaseIn(); float AnimateEaseIn();
float AnimateEaseOut(); float AnimateEaseOut();
float AnimateStackCollapse(); float AnimateStackCollapse();
private: private:
static constexpr const TCHAR class_name_[] = static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast");
TEXT("DesktopNotificationToast");
const HWND hwnd_; const HWND hwnd_;
HDC hdc_; HDC hdc_;
HBITMAP bitmap_ = NULL; HBITMAP bitmap_ = NULL;
const std::shared_ptr<NotificationData> data_; // never null const std::shared_ptr<NotificationData> data_; // never null
SIZE toast_size_ = {}; SIZE toast_size_ = {};
SIZE margin_ = {}; SIZE margin_ = {};
RECT close_button_rect_ = {}; RECT close_button_rect_ = {};
HBITMAP scaled_image_ = NULL; HBITMAP scaled_image_ = NULL;
int vertical_pos_ = 0; int vertical_pos_ = 0;
int vertical_pos_target_ = 0; int vertical_pos_target_ = 0;
bool is_non_interactive_ = false; bool is_non_interactive_ = false;
bool ease_in_active_ = false; bool ease_in_active_ = false;
bool ease_out_active_ = false; bool ease_out_active_ = false;
bool is_content_updated_ = false; bool is_content_updated_ = false;
bool is_highlighted_ = false; bool is_highlighted_ = false;
bool is_close_hot_ = false; bool is_close_hot_ = false;
DWORD ease_in_start_, ease_out_start_, stack_collapse_start_; DWORD ease_in_start_, ease_out_start_, stack_collapse_start_;
float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0; float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0;
}; };
} // namespace brightray } // namespace brightray

View file

@ -6,26 +6,23 @@ namespace brightray {
class Win32Notification : public brightray::Notification { class Win32Notification : public brightray::Notification {
public: public:
Win32Notification(NotificationDelegate* delegate, Win32Notification(NotificationDelegate* delegate,
NotificationPresenterWin7* presenter) : NotificationPresenterWin7* presenter)
Notification(delegate, presenter) { : Notification(delegate, presenter) {}
} void Show(const NotificationOptions& options) override;
void Show(const NotificationOptions& options) override; void Dismiss() override;
void Dismiss() override;
const DesktopNotificationController::Notification& GetRef() const { const DesktopNotificationController::Notification& GetRef() const {
return notification_ref_; return notification_ref_;
} }
const std::string& GetTag() const { const std::string& GetTag() const { return tag_; }
return tag_;
}
private: private:
DesktopNotificationController::Notification notification_ref_; DesktopNotificationController::Notification notification_ref_;
std::string tag_; std::string tag_;
DISALLOW_COPY_AND_ASSIGN(Win32Notification); DISALLOW_COPY_AND_ASSIGN(Win32Notification);
}; };
} // namespace brightray } // namespace brightray