From 284aca68c02e04e58caeaf01756720894df8c925 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 17 Apr 2018 21:46:27 -0400 Subject: [PATCH] clang-format brightray --- brightray/browser/brightray_paths.h | 4 +- brightray/browser/browser_context.h | 4 +- .../devtools_contents_resizing_strategy.h | 3 +- .../devtools_embedder_message_dispatcher.h | 2 +- .../browser/devtools_file_system_indexer.h | 6 +- brightray/browser/devtools_manager_delegate.h | 7 +- .../inspectable_web_contents_delegate.h | 23 ++- .../browser/inspectable_web_contents_impl.h | 21 ++- .../browser/inspectable_web_contents_view.h | 4 +- .../inspectable_web_contents_view_delegate.h | 4 +- brightray/browser/io_thread.h | 2 +- .../browser/linux/libnotify_notification.h | 11 +- .../mac/bry_inspectable_web_contents_view.h | 10 +- .../mac/notification_center_delegate.h | 7 +- .../media/media_capture_devices_dispatcher.h | 21 ++- brightray/browser/network_delegate.h | 3 +- .../browser/url_request_context_getter.h | 2 +- .../inspectable_web_contents_view_views.h | 2 +- brightray/browser/views/views_delegate.h | 13 +- brightray/browser/web_ui_controller_factory.h | 7 +- .../browser/win/notification_presenter_win7.h | 25 ++-- .../win/win32_desktop_notifications/common.h | 68 +++++---- .../desktop_notification_controller.h | 128 ++++++++--------- .../win/win32_desktop_notifications/toast.h | 135 +++++++++--------- brightray/browser/win/win32_notification.h | 29 ++-- 25 files changed, 268 insertions(+), 273 deletions(-) diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index 56525baeaab7..5c6c6d9e7adb 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -21,8 +21,8 @@ enum { PATH_START = 11000, DIR_USER_DATA = PATH_START, // Directory where user data can be written. - DIR_USER_CACHE, // Directory where user cache can be written. - DIR_APP_LOGS, // Directory where app logs live + DIR_USER_CACHE, // Directory where user cache can be written. + DIR_APP_LOGS, // Directory where app logs live #if defined(OS_LINUX) DIR_APP_DATA, // Application Data directory under the user profile. diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 25386099dd93..96c3e661d651 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -32,8 +32,8 @@ class BrowserContext : public base::RefCounted, public: // Get the BrowserContext according to its |partition| and |in_memory|, // empty pointer when be returned when there is no matching BrowserContext. - static scoped_refptr Get( - const std::string& partition, bool in_memory); + static scoped_refptr Get(const std::string& partition, + bool in_memory); base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h index e3fcb27c6ba8..e634874bfed6 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.h +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -14,8 +14,7 @@ class DevToolsContentsResizingStrategy { public: DevToolsContentsResizingStrategy(); - explicit DevToolsContentsResizingStrategy( - const gfx::Rect& bounds); + explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds); void CopyFrom(const DevToolsContentsResizingStrategy& strategy); bool Equals(const DevToolsContentsResizingStrategy& strategy); diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 1891daf6bc8c..060275a964be 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -16,7 +16,7 @@ namespace base { class ListValue; class Value; -} +} // namespace base namespace brightray { diff --git a/brightray/browser/devtools_file_system_indexer.h b/brightray/browser/devtools_file_system_indexer.h index 49e5f4b4c147..949a7acdb3a4 100644 --- a/brightray/browser/devtools_file_system_indexer.h +++ b/brightray/browser/devtools_file_system_indexer.h @@ -21,7 +21,7 @@ namespace base { class FilePath; class FileEnumerator; class Time; -} +} // namespace base namespace content { class WebContents; @@ -56,9 +56,7 @@ class DevToolsFileSystemIndexer void IndexFiles(); void StartFileIndexing(base::File::Error error); void ReadFromFile(); - void OnRead(base::File::Error error, - const char* data, - int bytes_read); + void OnRead(base::File::Error error, const char* data, int bytes_read); void FinishFileIndexing(bool success); void CloseFile(); void CloseCallback(base::File::Error error); diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index ac779fe16272..631111cc6aa1 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -22,10 +22,9 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { // DevToolsManagerDelegate implementation. void Inspect(content::DevToolsAgentHost* agent_host) override; - bool HandleCommand( - content::DevToolsAgentHost* agent_host, - int session_id, - base::DictionaryValue* command) override; + bool HandleCommand(content::DevToolsAgentHost* agent_host, + int session_id, + base::DictionaryValue* command) override; scoped_refptr CreateNewTarget( const GURL& url) override; std::string GetDiscoveryPageHTML() override; diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 85a05dbe3876..31a31285456d 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -11,22 +11,21 @@ class InspectableWebContentsDelegate { // Requested by WebContents of devtools. virtual void DevToolsReloadPage() {} - virtual void DevToolsSaveToFile( - const std::string& url, const std::string& content, bool save_as) {} - virtual void DevToolsAppendToFile( - const std::string& url, const std::string& content) {} + virtual void DevToolsSaveToFile(const std::string& url, + const std::string& content, + bool save_as) {} + virtual void DevToolsAppendToFile(const std::string& url, + const std::string& content) {} virtual void DevToolsRequestFileSystems() {} - virtual void DevToolsAddFileSystem( - const base::FilePath& file_system_path) {} + virtual void DevToolsAddFileSystem(const base::FilePath& file_system_path) {} virtual void DevToolsRemoveFileSystem( const base::FilePath& file_system_path) {} - virtual void DevToolsIndexPath( - int request_id, const std::string& file_system_path) {} + virtual void DevToolsIndexPath(int request_id, + const std::string& file_system_path) {} virtual void DevToolsStopIndexing(int request_id) {} - virtual void DevToolsSearchInPath( - int request_id, - const std::string& file_system_path, - const std::string& query) {} + virtual void DevToolsSearchInPath(int request_id, + const std::string& file_system_path, + const std::string& query) {} }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 6c1b34d8635e..0cd7d2b45b04 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -29,13 +29,13 @@ namespace brightray { class InspectableWebContentsDelegate; class InspectableWebContentsView; -class InspectableWebContentsImpl : - public InspectableWebContents, - public content::DevToolsAgentHostClient, - public content::WebContentsObserver, - public content::WebContentsDelegate, - public DevToolsEmbedderMessageDispatcher::Delegate, - public net::URLFetcherDelegate { +class InspectableWebContentsImpl + : public InspectableWebContents, + public content::DevToolsAgentHostClient, + public content::WebContentsObserver, + public content::WebContentsDelegate, + public DevToolsEmbedderMessageDispatcher::Delegate, + public net::URLFetcherDelegate { public: static void RegisterPrefs(PrefRegistrySimple* pref_registry); @@ -156,8 +156,8 @@ class InspectableWebContentsImpl : const GURL& target_url, const std::string& partition_id, content::SessionStorageNamespace* session_storage_namespace) override; - void HandleKeyboardEvent( - content::WebContents*, const content::NativeWebKeyboardEvent&) override; + void HandleKeyboardEvent(content::WebContents*, + const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; content::ColorChooser* OpenColorChooser( content::WebContents* source, @@ -172,8 +172,7 @@ class InspectableWebContentsImpl : // net::URLFetcherDelegate: void OnURLFetchComplete(const net::URLFetcher* source) override; - void SendMessageAck(int request_id, - const base::Value* arg1); + void SendMessageAck(int request_id, const base::Value* arg1); bool frontend_loaded_; scoped_refptr agent_host_; diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 480515ef4c2b..29a7f6152aae 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -25,9 +25,7 @@ class InspectableWebContentsView { void SetDelegate(InspectableWebContentsViewDelegate* delegate) { delegate_ = delegate; } - InspectableWebContentsViewDelegate* GetDelegate() const { - return delegate_; - } + InspectableWebContentsViewDelegate* GetDelegate() const { return delegate_; } #if defined(TOOLKIT_VIEWS) // Returns the container control, which has devtools view attached. diff --git a/brightray/browser/inspectable_web_contents_view_delegate.h b/brightray/browser/inspectable_web_contents_view_delegate.h index 1f30735497c4..e124bb730526 100644 --- a/brightray/browser/inspectable_web_contents_view_delegate.h +++ b/brightray/browser/inspectable_web_contents_view_delegate.h @@ -20,8 +20,8 @@ class InspectableWebContentsViewDelegate { #if defined(USE_X11) // Called when creating devtools window. - virtual void GetDevToolsWindowWMClass( - std::string* name, std::string* class_name) {} + virtual void GetDevToolsWindowWMClass(std::string* name, + std::string* class_name) {} #endif }; diff --git a/brightray/browser/io_thread.h b/brightray/browser/io_thread.h index 866008eb4e45..b7ddae0eb7e8 100644 --- a/brightray/browser/io_thread.h +++ b/brightray/browser/io_thread.h @@ -13,7 +13,7 @@ namespace net { class URLRequestContext; class URLRequestContextGetter; -} +} // namespace net namespace brightray { diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index c3ca30881282..a33055180b07 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -27,10 +27,15 @@ class LibnotifyNotification : public Notification { void Dismiss() override; private: - CHROMEG_CALLBACK_0(LibnotifyNotification, void, OnNotificationClosed, + CHROMEG_CALLBACK_0(LibnotifyNotification, + void, + OnNotificationClosed, NotifyNotification*); - CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView, - NotifyNotification*, char*); + CHROMEG_CALLBACK_1(LibnotifyNotification, + void, + OnNotificationView, + NotifyNotification*, + char*); NotifyNotification* notification_; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index c243b30fc473..2a99ff0e9f9f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -10,8 +10,8 @@ class InspectableWebContentsViewMac; using brightray::InspectableWebContentsViewMac; -@interface BRYInspectableWebContentsView : BaseView { -@private +@interface BRYInspectableWebContentsView : BaseView { + @private brightray::InspectableWebContentsViewMac* inspectableWebContentsView_; base::scoped_nsobject devtools_window_; @@ -22,14 +22,16 @@ using brightray::InspectableWebContentsViewMac; DevToolsContentsResizingStrategy strategy_; } -- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; +- (instancetype)initWithInspectableWebContentsViewMac: + (InspectableWebContentsViewMac*)view; - (void)removeObservers; - (void)notifyDevToolsFocused; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; - (BOOL)isDevToolsFocused; - (void)setIsDocked:(BOOL)docked; -- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; +- (void)setContentsResizingStrategy: + (const DevToolsContentsResizingStrategy&)strategy; - (void)setTitle:(NSString*)title; @end diff --git a/brightray/browser/mac/notification_center_delegate.h b/brightray/browser/mac/notification_center_delegate.h index 6bee83d411b4..49e2c87c3068 100644 --- a/brightray/browser/mac/notification_center_delegate.h +++ b/brightray/browser/mac/notification_center_delegate.h @@ -11,12 +11,13 @@ namespace brightray { class NotificationPresenterMac; } -@interface NotificationCenterDelegate : - NSObject { +@interface NotificationCenterDelegate + : NSObject { @private brightray::NotificationPresenterMac* presenter_; } -- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter; +- (instancetype)initWithPresenter: + (brightray::NotificationPresenterMac*)presenter; @end #endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_ diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index 32f3b60ff8b0..b0d212e5f6d6 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -34,10 +34,10 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { // Helpers for picking particular requested devices, identified by raw id. // If the device requested is not available it will return NULL. - const content::MediaStreamDevice* - GetRequestedAudioDevice(const std::string& requested_audio_device_id); - const content::MediaStreamDevice* - GetRequestedVideoDevice(const std::string& requested_video_device_id); + const content::MediaStreamDevice* GetRequestedAudioDevice( + const std::string& requested_audio_device_id); + const content::MediaStreamDevice* GetRequestedVideoDevice( + const std::string& requested_video_device_id); // Returns the first available audio or video device, or NULL if no devices // are available. @@ -52,13 +52,12 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { // Overridden from content::MediaObserver: void OnAudioCaptureDevicesChanged() override; void OnVideoCaptureDevicesChanged() override; - void OnMediaRequestStateChanged( - int render_process_id, - int render_view_id, - int page_request_id, - const GURL& security_origin, - content::MediaStreamType stream_type, - content::MediaRequestState state) override; + void OnMediaRequestStateChanged(int render_process_id, + int render_view_id, + int page_request_id, + const GURL& security_origin, + content::MediaStreamType stream_type, + content::MediaRequestState state) override; void OnCreatingAudioStream(int render_process_id, int render_view_id) override; void OnSetCapturingLinkSecured(int render_process_id, diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index eb14bc8153a3..03e8235129c4 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -45,8 +45,7 @@ class NetworkDelegate : public net::NetworkDelegate { int64_t bytes_sent) override; void OnCompleted(net::URLRequest* request, bool started) override; void OnURLRequestDestroyed(net::URLRequest* request) override; - void OnPACScriptError(int line_number, - const base::string16& error) override; + void OnPACScriptError(int line_number, const base::string16& error) override; AuthRequiredResponse OnAuthRequired( net::URLRequest* request, const net::AuthChallengeInfo& auth_info, diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 51c70ee92e30..049d23548c6e 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -34,7 +34,7 @@ class NetworkDelegate; class ProxyConfigService; class URLRequestContextStorage; class URLRequestJobFactory; -} +} // namespace net namespace brightray { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 848e7dcdb3fe..ebc2b90edf1d 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -10,7 +10,7 @@ namespace views { class WebView; class Widget; class WidgetDelegate; -} +} // namespace views namespace brightray { diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h index ae3f16d100a3..a0609cd3db78 100644 --- a/brightray/browser/views/views_delegate.h +++ b/brightray/browser/views/views_delegate.h @@ -23,13 +23,12 @@ class ViewsDelegate : public views::ViewsDelegate { const std::string& window_name, const gfx::Rect& bounds, ui::WindowShowState show_state) override; - bool GetSavedWindowPlacement( - const views::Widget* widget, - const std::string& window_name, - gfx::Rect* bounds, - ui::WindowShowState* show_state) const override; - void NotifyAccessibilityEvent( - views::View* view, ui::AXEvent event_type) override; + bool GetSavedWindowPlacement(const views::Widget* widget, + const std::string& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const override; + void NotifyAccessibilityEvent(views::View* view, + ui::AXEvent event_type) override; void NotifyMenuItemFocused(const base::string16& menu_name, const base::string16& menu_item_name, int item_index, diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 1739466f9207..51e53ef510ee 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -10,7 +10,8 @@ #include "content/public/browser/web_ui_controller_factory.h" namespace base { -template struct DefaultSingletonTraits; +template +struct DefaultSingletonTraits; } namespace brightray { @@ -24,8 +25,8 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { WebUIControllerFactory(); virtual ~WebUIControllerFactory(); - content::WebUI::TypeID GetWebUIType( - content::BrowserContext* browser_context, const GURL& url) const override; + content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, + const GURL& url) const override; bool UseWebUIForURL(content::BrowserContext* browser_context, const GURL& url) const override; bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index ecd1cb28f98a..26e6f644c157 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -6,25 +6,24 @@ namespace brightray { class Win32Notification; -class NotificationPresenterWin7 : - public NotificationPresenter, - public DesktopNotificationController { +class NotificationPresenterWin7 : public NotificationPresenter, + public DesktopNotificationController { public: - NotificationPresenterWin7() = default; + NotificationPresenterWin7() = default; - Win32Notification* GetNotificationObjectByRef( - const DesktopNotificationController::Notification& ref); + Win32Notification* GetNotificationObjectByRef( + const DesktopNotificationController::Notification& ref); - Win32Notification* GetNotificationObjectByTag(const std::string& tag); + Win32Notification* GetNotificationObjectByTag(const std::string& tag); private: - brightray::Notification* CreateNotificationObject( - NotificationDelegate* delegate) override; + brightray::Notification* CreateNotificationObject( + NotificationDelegate* delegate) override; - void OnNotificationClicked(Notification& notification) override; - void OnNotificationDismissed(Notification& notification) override; + void OnNotificationClicked(Notification& notification) override; + void OnNotificationDismissed(Notification& notification) override; - DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); }; -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 49095b76d65c..967ad247481f 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -4,51 +4,57 @@ namespace brightray { struct NotificationData { - DesktopNotificationController* controller = nullptr; + DesktopNotificationController* controller = nullptr; - std::wstring caption; - std::wstring body_text; - HBITMAP image = NULL; + std::wstring caption; + std::wstring body_text; + HBITMAP image = NULL; - NotificationData() = default; + NotificationData() = default; - ~NotificationData() { - if (image) DeleteObject(image); - } + ~NotificationData() { + if (image) + DeleteObject(image); + } - NotificationData(const NotificationData& other) = delete; - NotificationData& operator=(const NotificationData& other) = delete; + NotificationData(const NotificationData& other) = delete; + NotificationData& operator=(const NotificationData& other) = delete; }; -template +template constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) { - return value * dpi / source_dpi; + return value * dpi / source_dpi; } struct ScreenMetrics { - UINT dpi_x, dpi_y; + UINT dpi_x, dpi_y; - ScreenMetrics() { - typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); + ScreenMetrics() { + typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); - auto GetDpiForMonitor = reinterpret_cast( - GetProcAddress(GetModuleHandle(TEXT("shcore")), - "GetDpiForMonitor")); + auto GetDpiForMonitor = reinterpret_cast( + GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor")); - if (GetDpiForMonitor) { - auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); - if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) - return; - } - - HDC hdc = GetDC(NULL); - dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); - dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); - ReleaseDC(NULL, hdc); + if (GetDpiForMonitor) { + auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); + if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) + return; } - template T X(T value) const { return ScaleForDpi(value, dpi_x); } - template T Y(T value) const { return ScaleForDpi(value, dpi_y); } + HDC hdc = GetDC(NULL); + dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); + dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + } + + template + T X(T value) const { + return ScaleForDpi(value, dpi_x); + } + template + T Y(T value) const { + return ScaleForDpi(value, dpi_y); + } }; -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 1e76e1e1ad2e..ad62fa727b45 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -1,9 +1,9 @@ #pragma once +#include #include #include #include #include -#include namespace brightray { @@ -11,95 +11,95 @@ struct NotificationData; class DesktopNotificationController { public: - explicit DesktopNotificationController(unsigned maximum_toasts = 3); - ~DesktopNotificationController(); + explicit DesktopNotificationController(unsigned maximum_toasts = 3); + ~DesktopNotificationController(); - class Notification; - Notification AddNotification(std::wstring caption, std::wstring body_text, - HBITMAP image); - void CloseNotification(Notification& notification); + class Notification; + Notification AddNotification(std::wstring caption, + std::wstring body_text, + HBITMAP image); + void CloseNotification(Notification& notification); - // Event handlers -- override to receive the events + // Event handlers -- override to receive the events private: - virtual void OnNotificationClosed(Notification& notification) {} - virtual void OnNotificationClicked(Notification& notification) {} - virtual void OnNotificationDismissed(Notification& notification) {} + virtual void OnNotificationClosed(Notification& notification) {} + virtual void OnNotificationClicked(Notification& notification) {} + virtual void OnNotificationDismissed(Notification& notification) {} private: - static HINSTANCE RegisterWndClasses(); - void StartAnimation(); - HFONT GetCaptionFont(); - HFONT GetBodyFont(); + static HINSTANCE RegisterWndClasses(); + void StartAnimation(); + HFONT GetCaptionFont(); + HFONT GetBodyFont(); private: - enum TimerID { - TimerID_Animate = 1 - }; + enum TimerID { TimerID_Animate = 1 }; - static constexpr int toast_margin_ = 20; + static constexpr int toast_margin_ = 20; - // Wrapper around `NotificationData` which makes sure that - // the `controller` member is cleared when the controller object - // stops tracking the notification - struct NotificationLink : std::shared_ptr { - explicit NotificationLink(DesktopNotificationController* controller); - ~NotificationLink(); + // Wrapper around `NotificationData` which makes sure that + // the `controller` member is cleared when the controller object + // stops tracking the notification + struct NotificationLink : std::shared_ptr { + explicit NotificationLink(DesktopNotificationController* controller); + ~NotificationLink(); - NotificationLink(NotificationLink&&) = default; - NotificationLink(const NotificationLink&) = delete; - NotificationLink& operator=(NotificationLink&&) = default; - }; + NotificationLink(NotificationLink&&) = default; + NotificationLink(const NotificationLink&) = delete; + NotificationLink& operator=(NotificationLink&&) = default; + }; - struct ToastInstance { - HWND hwnd; - NotificationLink data; - }; + struct ToastInstance { + HWND hwnd; + NotificationLink data; + }; - class Toast; + class Toast; - static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam); - static DesktopNotificationController* Get(HWND hwnd) { - return reinterpret_cast( - GetWindowLongPtr(hwnd, 0)); - } + static LRESULT CALLBACK WndProc(HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam); + static DesktopNotificationController* Get(HWND hwnd) { + return reinterpret_cast( + GetWindowLongPtr(hwnd, 0)); + } - DesktopNotificationController( - const DesktopNotificationController&) = delete; + DesktopNotificationController(const DesktopNotificationController&) = delete; - void InitializeFonts(); - void ClearAssets(); - void AnimateAll(); - void CheckQueue(); - void CreateToast(NotificationLink&& data); - HWND GetToast(const NotificationData* data) const; - void DestroyToast(ToastInstance& inst); + void InitializeFonts(); + void ClearAssets(); + void AnimateAll(); + void CheckQueue(); + void CreateToast(NotificationLink&& data); + HWND GetToast(const NotificationData* data) const; + void DestroyToast(ToastInstance& inst); private: - static constexpr const TCHAR class_name_[] = - TEXT("DesktopNotificationController"); + static constexpr const TCHAR class_name_[] = + TEXT("DesktopNotificationController"); - HWND hwnd_controller_ = NULL; - HFONT caption_font_ = NULL, body_font_ = NULL; - std::vector instances_; - std::deque queue_; - bool is_animating_ = false; + HWND hwnd_controller_ = NULL; + HFONT caption_font_ = NULL, body_font_ = NULL; + std::vector instances_; + std::deque queue_; + bool is_animating_ = false; }; class DesktopNotificationController::Notification { public: - Notification() = default; - explicit Notification(const std::shared_ptr& data); + Notification() = default; + explicit Notification(const std::shared_ptr& data); - bool operator==(const Notification& other) const; + bool operator==(const Notification& other) const; - void Close(); - void Set(std::wstring caption, std::wstring body_text, HBITMAP image); + void Close(); + void Set(std::wstring caption, std::wstring body_text, HBITMAP image); private: - std::shared_ptr data_; + std::shared_ptr data_; - friend class DesktopNotificationController; + friend class DesktopNotificationController; }; -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 2a49a38b1473..967697ac8cca 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -5,93 +5,88 @@ namespace brightray { class DesktopNotificationController::Toast { public: - static void Register(HINSTANCE hinstance); - static HWND Create(HINSTANCE hinstance, - std::shared_ptr& data); - static Toast* Get(HWND hwnd) { - return reinterpret_cast(GetWindowLongPtr(hwnd, 0)); - } + static void Register(HINSTANCE hinstance); + static HWND Create(HINSTANCE hinstance, + std::shared_ptr& data); + static Toast* Get(HWND hwnd) { + return reinterpret_cast(GetWindowLongPtr(hwnd, 0)); + } - static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam); + static LRESULT CALLBACK WndProc(HWND hwnd, + UINT message, + WPARAM wparam, + LPARAM lparam); - const std::shared_ptr& GetNotification() const { - return data_; - } + const std::shared_ptr& GetNotification() const { + return data_; + } - void ResetContents(); + void ResetContents(); - void Dismiss(); + 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 { - _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_))); - return is_highlighted_; - } + 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 { + _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_))); + return is_highlighted_; + } private: - enum TimerID { - TimerID_AutoDismiss = 1 - }; + enum TimerID { TimerID_AutoDismiss = 1 }; - Toast(HWND hwnd, std::shared_ptr* data); - ~Toast(); + Toast(HWND hwnd, std::shared_ptr* data); + ~Toast(); - void UpdateBufferSize(); - void UpdateScaledImage(const SIZE& size); - void Draw(); - void Invalidate(); - bool IsRedrawNeeded() const; - void UpdateContents(); + void UpdateBufferSize(); + void UpdateScaledImage(const SIZE& size); + void Draw(); + void Invalidate(); + bool IsRedrawNeeded() const; + void UpdateContents(); - void AutoDismiss(); - void CancelDismiss(); - void ScheduleDismissal(); + void AutoDismiss(); + void CancelDismiss(); + void ScheduleDismissal(); - void StartEaseIn(); - void StartEaseOut(); - bool IsStackCollapseActive() const; + void StartEaseIn(); + void StartEaseOut(); + bool IsStackCollapseActive() const; - float AnimateEaseIn(); - float AnimateEaseOut(); - float AnimateStackCollapse(); + float AnimateEaseIn(); + float AnimateEaseOut(); + float AnimateStackCollapse(); private: - static constexpr const TCHAR class_name_[] = - TEXT("DesktopNotificationToast"); + static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast"); - const HWND hwnd_; - HDC hdc_; - HBITMAP bitmap_ = NULL; + const HWND hwnd_; + HDC hdc_; + HBITMAP bitmap_ = NULL; - const std::shared_ptr data_; // never null + const std::shared_ptr data_; // never null - SIZE toast_size_ = {}; - SIZE margin_ = {}; - RECT close_button_rect_ = {}; - HBITMAP scaled_image_ = 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; + 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; }; -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index e4d1b3ddedd8..62b66ba23e36 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -6,26 +6,23 @@ namespace brightray { class Win32Notification : public brightray::Notification { public: - Win32Notification(NotificationDelegate* delegate, - NotificationPresenterWin7* presenter) : - Notification(delegate, presenter) { - } - void Show(const NotificationOptions& options) override; - void Dismiss() override; + Win32Notification(NotificationDelegate* delegate, + NotificationPresenterWin7* presenter) + : Notification(delegate, presenter) {} + void Show(const NotificationOptions& options) override; + void Dismiss() override; - const DesktopNotificationController::Notification& GetRef() const { - return notification_ref_; - } + const DesktopNotificationController::Notification& GetRef() const { + return notification_ref_; + } - const std::string& GetTag() const { - return tag_; - } + const std::string& GetTag() const { return tag_; } private: - DesktopNotificationController::Notification notification_ref_; - std::string tag_; + DesktopNotificationController::Notification notification_ref_; + std::string tag_; - DISALLOW_COPY_AND_ASSIGN(Win32Notification); + DISALLOW_COPY_AND_ASSIGN(Win32Notification); }; -} // namespace brightray +} // namespace brightray