Coding style fixes

This commit is contained in:
Cheng Zhao 2017-05-31 16:17:29 +09:00
parent 227a2bd5dc
commit 5fa2831756
7 changed files with 23 additions and 33 deletions

View file

@ -4,24 +4,16 @@
#include "atom/browser/api/atom_api_notification.h" #include "atom/browser/api/atom_api_notification.h"
#include <map>
#include <string>
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
#include "atom/browser/browser.h" #include "atom/browser/browser.h"
#include "atom/common/api/atom_api_native_image.h"
#include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/node_includes.h" #include "atom/common/node_includes.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "brightray/browser/browser_client.h" #include "brightray/browser/browser_client.h"
#include "native_mate/constructor.h" #include "native_mate/constructor.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace atom { namespace atom {
@ -33,6 +25,8 @@ Notification::Notification(v8::Isolate* isolate,
mate::Arguments* args) { mate::Arguments* args) {
InitWith(isolate, wrapper); InitWith(isolate, wrapper);
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
mate::Dictionary opts; mate::Dictionary opts;
if (args->GetNext(&opts)) { if (args->GetNext(&opts)) {
opts.Get("title", &title_); opts.Get("title", &title_);
@ -45,11 +39,11 @@ Notification::Notification(v8::Isolate* isolate,
opts.Get("replyPlaceholder", &reply_placeholder_); opts.Get("replyPlaceholder", &reply_placeholder_);
opts.Get("hasReply", &has_reply_); opts.Get("hasReply", &has_reply_);
} }
OnInitialProps();
} }
Notification::~Notification() { Notification::~Notification() {
notification_->set_delegate(nullptr); if (notification_)
notification_->set_delegate(nullptr);
} }
// static // static
@ -65,15 +59,19 @@ mate::WrappableBase* Notification::New(mate::Arguments* args) {
base::string16 Notification::GetTitle() { base::string16 Notification::GetTitle() {
return title_; return title_;
} }
base::string16 Notification::GetBody() { base::string16 Notification::GetBody() {
return body_; return body_;
} }
bool Notification::GetSilent() { bool Notification::GetSilent() {
return silent_; return silent_;
} }
base::string16 Notification::GetReplyPlaceholder() { base::string16 Notification::GetReplyPlaceholder() {
return reply_placeholder_; return reply_placeholder_;
} }
bool Notification::GetHasReply() { bool Notification::GetHasReply() {
return has_reply_; return has_reply_;
} }
@ -82,15 +80,19 @@ bool Notification::GetHasReply() {
void Notification::SetTitle(const base::string16& new_title) { void Notification::SetTitle(const base::string16& new_title) {
title_ = new_title; title_ = new_title;
} }
void Notification::SetBody(const base::string16& new_body) { void Notification::SetBody(const base::string16& new_body) {
body_ = new_body; body_ = new_body;
} }
void Notification::SetSilent(bool new_silent) { void Notification::SetSilent(bool new_silent) {
silent_ = new_silent; silent_ = new_silent;
} }
void Notification::SetReplyPlaceholder(const base::string16& new_placeholder) { void Notification::SetReplyPlaceholder(const base::string16& new_placeholder) {
reply_placeholder_ = new_placeholder; reply_placeholder_ = new_placeholder;
} }
void Notification::SetHasReply(bool new_has_reply) { void Notification::SetHasReply(bool new_has_reply) {
has_reply_ = new_has_reply; has_reply_ = new_has_reply;
} }
@ -99,7 +101,7 @@ void Notification::NotificationClick() {
Emit("click"); Emit("click");
} }
void Notification::NotificationReplied(const std::string reply) { void Notification::NotificationReplied(const std::string& reply) {
Emit("reply", reply); Emit("reply", reply);
} }
@ -111,7 +113,8 @@ void Notification::NotificationDestroyed() {
Emit("close"); Emit("close");
} }
void Notification::NotificationClosed() {} void Notification::NotificationClosed() {
}
// Showing notifications // Showing notifications
void Notification::Show() { void Notification::Show() {
@ -124,14 +127,6 @@ void Notification::Show() {
} }
} }
bool initialized_ = false;
void Notification::OnInitialProps() {
if (!initialized_) {
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
initialized_ = true;
}
}
bool Notification::IsSupported() { bool Notification::IsSupported() {
return !!brightray::BrowserClient::Get()->GetNotificationPresenter(); return !!brightray::BrowserClient::Get()->GetNotificationPresenter();
} }

View file

@ -32,7 +32,7 @@ class Notification : public mate::TrackableObject<Notification>,
// NotificationDelegate: // NotificationDelegate:
void NotificationClick() override; void NotificationClick() override;
void NotificationReplied(const std::string reply) override; void NotificationReplied(const std::string& reply) override;
void NotificationDisplayed() override; void NotificationDisplayed() override;
void NotificationDestroyed() override; void NotificationDestroyed() override;
void NotificationClosed() override; void NotificationClosed() override;
@ -43,7 +43,6 @@ class Notification : public mate::TrackableObject<Notification>,
mate::Arguments* args); mate::Arguments* args);
~Notification() override; ~Notification() override;
void OnInitialProps();
void Show(); void Show();
// Prop Getters // Prop Getters
@ -69,6 +68,7 @@ class Notification : public mate::TrackableObject<Notification>,
bool silent_ = false; bool silent_ = false;
base::string16 reply_placeholder_; base::string16 reply_placeholder_;
bool has_reply_ = false; bool has_reply_ = false;
brightray::NotificationPresenter* presenter_; brightray::NotificationPresenter* presenter_;
base::WeakPtr<brightray::Notification> notification_; base::WeakPtr<brightray::Notification> notification_;

View file

@ -32,7 +32,7 @@ class CocoaNotification : public Notification {
void Dismiss() override; void Dismiss() override;
void NotificationDisplayed(); void NotificationDisplayed();
void NotificationReplied(const std::string reply); void NotificationReplied(const std::string& reply);
NSUserNotification* notification() const { return notification_; } NSUserNotification* notification() const { return notification_; }

View file

@ -69,7 +69,7 @@ void CocoaNotification::NotificationDisplayed() {
delegate()->NotificationDisplayed(); delegate()->NotificationDisplayed();
} }
void CocoaNotification::NotificationReplied(const std::string reply) { void CocoaNotification::NotificationReplied(const std::string& reply) {
if (delegate()) if (delegate())
delegate()->NotificationReplied(reply); delegate()->NotificationReplied(reply);
} }

View file

@ -21,10 +21,6 @@ Notification::~Notification() {
delegate()->NotificationDestroyed(); delegate()->NotificationDestroyed();
} }
void Notification::set_delegate(NotificationDelegate* delegate) {
delegate_ = delegate;
}
void Notification::NotificationClicked() { void Notification::NotificationClicked() {
if (delegate()) if (delegate())
delegate()->NotificationClick(); delegate()->NotificationClick();

View file

@ -20,6 +20,8 @@ class NotificationPresenter;
class Notification { class Notification {
public: public:
virtual ~Notification();
// Shows the notification. // Shows the notification.
virtual void Show(const base::string16& title, virtual void Show(const base::string16& title,
const base::string16& msg, const base::string16& msg,
@ -45,6 +47,7 @@ class Notification {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
void set_delegate(NotificationDelegate* delegate) { delegate_ = delegate; }
NotificationDelegate* delegate() const { return delegate_; } NotificationDelegate* delegate() const { return delegate_; }
NotificationPresenter* presenter() const { return presenter_; } NotificationPresenter* presenter() const { return presenter_; }
@ -52,10 +55,6 @@ class Notification {
Notification(NotificationDelegate* delegate, Notification(NotificationDelegate* delegate,
NotificationPresenter* presenter); NotificationPresenter* presenter);
public:
virtual ~Notification();
void set_delegate(NotificationDelegate* delegate);
private: private:
NotificationDelegate* delegate_; NotificationDelegate* delegate_;
NotificationPresenter* presenter_; NotificationPresenter* presenter_;

View file

@ -20,7 +20,7 @@ class NotificationDelegate : public content::DesktopNotificationDelegate {
virtual void NotificationFailed() {} virtual void NotificationFailed() {}
// Notification was replied to // Notification was replied to
virtual void NotificationReplied(const std::string reply) {} virtual void NotificationReplied(const std::string& reply) {}
}; };
} // namespace brightray } // namespace brightray