Merge pull request #423 from atom/hidpi-icon

Add support for high resolution icon
This commit is contained in:
Cheng Zhao 2014-06-23 23:36:13 +08:00
commit a2c897aa9f
19 changed files with 152 additions and 144 deletions

View file

@ -7,7 +7,6 @@
#include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/common/native_mate_converters/function_converter.h" #include "atom/common/native_mate_converters/function_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
@ -61,7 +60,7 @@ void OnCapturePageDone(
} // namespace } // namespace
Window::Window(base::DictionaryValue* options) Window::Window(const mate::Dictionary& options)
: window_(NativeWindow::Create(options)) { : window_(NativeWindow::Create(options)) {
window_->InitFromOptions(options); window_->InitFromOptions(options);
window_->AddObserver(this); window_->AddObserver(this);
@ -108,10 +107,8 @@ void Window::OnRendererResponsive() {
} }
// static // static
mate::Wrappable* Window::New(mate::Arguments* args, mate::Wrappable* Window::New(const mate::Dictionary& options) {
const base::DictionaryValue& options) { return new Window(options);
scoped_ptr<base::DictionaryValue> copied_options(options.DeepCopy());
return new Window(copied_options.get());
} }
void Window::Destroy() { void Window::Destroy() {

View file

@ -15,10 +15,6 @@
class GURL; class GURL;
namespace base {
class DictionaryValue;
}
namespace mate { namespace mate {
class Arguments; class Arguments;
class Dictionary; class Dictionary;
@ -35,8 +31,7 @@ class WebContents;
class Window : public mate::EventEmitter, class Window : public mate::EventEmitter,
public NativeWindowObserver { public NativeWindowObserver {
public: public:
static mate::Wrappable* New(mate::Arguments* args, static mate::Wrappable* New(const mate::Dictionary& options);
const base::DictionaryValue& options);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Handle<v8::ObjectTemplate> prototype); v8::Handle<v8::ObjectTemplate> prototype);
@ -44,7 +39,7 @@ class Window : public mate::EventEmitter,
NativeWindow* window() const { return window_.get(); } NativeWindow* window() const { return window_.get(); }
protected: protected:
explicit Window(base::DictionaryValue* options); explicit Window(const mate::Dictionary& options);
virtual ~Window(); virtual ~Window();
// Implementations of NativeWindowObserver: // Implementations of NativeWindowObserver:

View file

@ -7,13 +7,13 @@
#include <string> #include <string>
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/values.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_manager.h" #include "content/public/browser/devtools_manager.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
namespace atom { namespace atom {
@ -37,9 +37,9 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window,
devtools_agent_host_.get(), devtools_client_host_.get()); devtools_agent_host_.get(), devtools_client_host_.get());
// Go! // Go!
base::DictionaryValue options; mate::Dictionary options;
options.SetString("title", "DevTools Debugger"); options.Set("title", "DevTools Debugger");
window->InitFromOptions(&options); window->InitFromOptions(options);
window->AddObserver(this); window->AddObserver(this);
web_contents->GetController().LoadURL( web_contents->GetController().LoadURL(
GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"), GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"),

View file

@ -16,6 +16,8 @@
#include "atom/browser/window_list.h" #include "atom/browser/window_list.h"
#include "atom/common/api/api_messages.h" #include "atom/common/api/api_messages.h"
#include "atom/common/atom_version.h" #include "atom/common/atom_version.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h" #include "base/file_util.h"
@ -25,7 +27,6 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/invalidate_type.h" #include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
@ -39,7 +40,10 @@
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "content/public/common/renderer_preferences.h" #include "content/public/common/renderer_preferences.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
@ -53,7 +57,7 @@ using content::NavigationEntry;
namespace atom { namespace atom {
NativeWindow::NativeWindow(content::WebContents* web_contents, NativeWindow::NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options) const mate::Dictionary& options)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
has_frame_(true), has_frame_(true),
is_closed_(false), is_closed_(false),
@ -63,7 +67,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
weak_factory_(this), weak_factory_(this),
inspectable_web_contents_( inspectable_web_contents_(
brightray::InspectableWebContents::Create(web_contents)) { brightray::InspectableWebContents::Create(web_contents)) {
options->GetBoolean(switches::kFrame, &has_frame_); options.Get(switches::kFrame, &has_frame_);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Temporary fix for flashing devtools, try removing this after upgraded to // Temporary fix for flashing devtools, try removing this after upgraded to
@ -72,20 +76,20 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
#endif #endif
// Read icon before window is created. // Read icon before window is created.
std::string icon; gfx::ImageSkia icon;
if (options->GetString(switches::kIcon, &icon) && !SetIcon(icon)) if (options.Get(switches::kIcon, &icon))
LOG(ERROR) << "Failed to set icon to " << icon; icon_.reset(new gfx::Image(icon));
// Read iframe security before any navigation. // Read iframe security before any navigation.
options->GetString(switches::kNodeIntegration, &node_integration_); options.Get(switches::kNodeIntegration, &node_integration_);
// Read the web preferences. // Read the web preferences.
base::DictionaryValue* web_preferences; scoped_ptr<mate::Dictionary> web_preferences(new mate::Dictionary);
if (options->GetDictionary(switches::kWebPreferences, &web_preferences)) if (options.Get(switches::kWebPreferences, web_preferences.get()))
web_preferences_.reset(web_preferences->DeepCopy()); web_preferences_.reset(web_preferences.release());
// Read the zoom factor before any navigation. // Read the zoom factor before any navigation.
options->GetDouble(switches::kZoomFactor, &zoom_factor_); options.Get(switches::kZoomFactor, &zoom_factor_);
web_contents->SetDelegate(this); web_contents->SetDelegate(this);
inspectable_web_contents()->SetDelegate(this); inspectable_web_contents()->SetDelegate(this);
@ -117,15 +121,15 @@ NativeWindow::~NativeWindow() {
} }
// static // static
NativeWindow* NativeWindow::Create(base::DictionaryValue* options) { NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
content::WebContents::CreateParams create_params(AtomBrowserContext::Get()); content::WebContents::CreateParams create_params(AtomBrowserContext::Get());
return Create(content::WebContents::Create(create_params), options); return Create(content::WebContents::Create(create_params), options);
} }
// static // static
NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) { NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) {
base::DictionaryValue options; mate::Dictionary options;
NativeWindow* window = NativeWindow::Create(&options); NativeWindow* window = NativeWindow::Create(options);
window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents)); window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents));
return window; return window;
} }
@ -146,56 +150,55 @@ NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
return NULL; return NULL;
} }
void NativeWindow::InitFromOptions(base::DictionaryValue* options) { void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
// Setup window from options. // Setup window from options.
int x = -1, y = -1; int x = -1, y = -1;
bool center; bool center;
if (options->GetInteger(switches::kX, &x) && if (options.Get(switches::kX, &x) && options.Get(switches::kY, &y)) {
options->GetInteger(switches::kY, &y)) {
int width = -1, height = -1; int width = -1, height = -1;
options->GetInteger(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options->GetInteger(switches::kHeight, &height); options.Get(switches::kHeight, &height);
Move(gfx::Rect(x, y, width, height)); Move(gfx::Rect(x, y, width, height));
} else if (options->GetBoolean(switches::kCenter, &center) && center) { } else if (options.Get(switches::kCenter, &center) && center) {
Center(); Center();
} }
int min_height = -1, min_width = -1; int min_height = -1, min_width = -1;
if (options->GetInteger(switches::kMinHeight, &min_height) && if (options.Get(switches::kMinHeight, &min_height) &&
options->GetInteger(switches::kMinWidth, &min_width)) { options.Get(switches::kMinWidth, &min_width)) {
SetMinimumSize(gfx::Size(min_width, min_height)); SetMinimumSize(gfx::Size(min_width, min_height));
} }
int max_height = -1, max_width = -1; int max_height = -1, max_width = -1;
if (options->GetInteger(switches::kMaxHeight, &max_height) && if (options.Get(switches::kMaxHeight, &max_height) &&
options->GetInteger(switches::kMaxWidth, &max_width)) { options.Get(switches::kMaxWidth, &max_width)) {
SetMaximumSize(gfx::Size(max_width, max_height)); SetMaximumSize(gfx::Size(max_width, max_height));
} }
bool resizable; bool resizable;
if (options->GetBoolean(switches::kResizable, &resizable)) { if (options.Get(switches::kResizable, &resizable)) {
SetResizable(resizable); SetResizable(resizable);
} }
bool top; bool top;
if (options->GetBoolean(switches::kAlwaysOnTop, &top) && top) { if (options.Get(switches::kAlwaysOnTop, &top) && top) {
SetAlwaysOnTop(true); SetAlwaysOnTop(true);
} }
bool fullscreen; bool fullscreen;
if (options->GetBoolean(switches::kFullscreen, &fullscreen) && fullscreen) { if (options.Get(switches::kFullscreen, &fullscreen) && fullscreen) {
SetFullscreen(true); SetFullscreen(true);
} }
bool skip; bool skip;
if (options->GetBoolean(switches::kSkipTaskbar, &skip) && skip) { if (options.Get(switches::kSkipTaskbar, &skip) && skip) {
SetSkipTaskbar(skip); SetSkipTaskbar(skip);
} }
bool kiosk; bool kiosk;
if (options->GetBoolean(switches::kKiosk, &kiosk) && kiosk) { if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
SetKiosk(kiosk); SetKiosk(kiosk);
} }
std::string title("Atom Shell"); std::string title("Atom Shell");
options->GetString(switches::kTitle, &title); options.Get(switches::kTitle, &title);
SetTitle(title); SetTitle(title);
// Then show it. // Then show it.
bool show = true; bool show = true;
options->GetBoolean(switches::kShow, &show); options.Get(switches::kShow, &show);
if (show) if (show)
Show(); Show();
} }
@ -257,26 +260,6 @@ bool NativeWindow::IsWebViewFocused() {
return host_view && host_view->HasFocus(); return host_view && host_view->HasFocus();
} }
bool NativeWindow::SetIcon(const std::string& str_path) {
base::FilePath path = base::FilePath::FromUTF8Unsafe(str_path);
// Read the file from disk.
std::string file_contents;
if (path.empty() || !base::ReadFileToString(path, &file_contents))
return false;
// Decode the bitmap using WebKit's image decoder.
const unsigned char* data =
reinterpret_cast<const unsigned char*>(file_contents.data());
scoped_ptr<SkBitmap> decoded(new SkBitmap());
gfx::PNGCodec::Decode(data, file_contents.length(), decoded.get());
if (decoded->empty())
return false; // Unable to decode.
icon_ = gfx::Image::CreateFrom1xBitmap(*decoded.release());
return true;
}
base::ProcessHandle NativeWindow::GetRenderProcessHandle() { base::ProcessHandle NativeWindow::GetRenderProcessHandle() {
return GetWebContents()->GetRenderProcessHost()->GetHandle(); return GetWebContents()->GetRenderProcessHost()->GetHandle();
} }
@ -376,35 +359,30 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
prefs->accelerated_compositing_enabled = false; prefs->accelerated_compositing_enabled = false;
bool b; bool b;
base::ListValue* list; std::vector<base::FilePath> list;
if (!web_preferences_) if (!web_preferences_)
return; return;
if (web_preferences_->GetBoolean("javascript", &b)) if (web_preferences_->Get("javascript", &b))
prefs->javascript_enabled = b; prefs->javascript_enabled = b;
if (web_preferences_->GetBoolean("web-security", &b)) if (web_preferences_->Get("web-security", &b))
prefs->web_security_enabled = b; prefs->web_security_enabled = b;
if (web_preferences_->GetBoolean("images", &b)) if (web_preferences_->Get("images", &b))
prefs->images_enabled = b; prefs->images_enabled = b;
if (web_preferences_->GetBoolean("java", &b)) if (web_preferences_->Get("java", &b))
prefs->java_enabled = b; prefs->java_enabled = b;
if (web_preferences_->GetBoolean("text-areas-are-resizable", &b)) if (web_preferences_->Get("text-areas-are-resizable", &b))
prefs->text_areas_are_resizable = b; prefs->text_areas_are_resizable = b;
if (web_preferences_->GetBoolean("webgl", &b)) if (web_preferences_->Get("webgl", &b))
prefs->experimental_webgl_enabled = b; prefs->experimental_webgl_enabled = b;
if (web_preferences_->GetBoolean("webaudio", &b)) if (web_preferences_->Get("webaudio", &b))
prefs->webaudio_enabled = b; prefs->webaudio_enabled = b;
if (web_preferences_->GetBoolean("accelerated-compositing", &b)) if (web_preferences_->Get("accelerated-compositing", &b))
prefs->accelerated_compositing_enabled = b; prefs->accelerated_compositing_enabled = b;
if (web_preferences_->GetBoolean("plugins", &b)) if (web_preferences_->Get("plugins", &b))
prefs->plugins_enabled = b; prefs->plugins_enabled = b;
if (web_preferences_->GetList("extra-plugin-dirs", &list)) if (web_preferences_->Get("extra-plugin-dirs", &list))
for (size_t i = 0; i < list->GetSize(); ++i) { for (size_t i = 0; i < list.size(); ++i)
base::FilePath::StringType path_string; content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
if (list->GetString(i, &path_string)) {
base::FilePath path(path_string);
content::PluginService::GetInstance()->AddExtraPluginDir(path);
}
}
} }
void NativeWindow::NotifyWindowClosed() { void NativeWindow::NotifyWindowClosed() {

View file

@ -18,7 +18,6 @@
#include "atom/browser/native_window_observer.h" #include "atom/browser/native_window_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "ui/gfx/image/image.h"
#include "vendor/brightray/browser/default_web_contents_delegate.h" #include "vendor/brightray/browser/default_web_contents_delegate.h"
#include "vendor/brightray/browser/inspectable_web_contents_delegate.h" #include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
#include "vendor/brightray/browser/inspectable_web_contents_impl.h" #include "vendor/brightray/browser/inspectable_web_contents_impl.h"
@ -26,22 +25,22 @@
class CommandLine; class CommandLine;
struct WebPreferences; struct WebPreferences;
namespace base {
class DictionaryValue;
class ListValue;
}
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class WebContents; class WebContents;
} }
namespace gfx { namespace gfx {
class Image;
class Point; class Point;
class Rect; class Rect;
class Size; class Size;
} }
namespace mate {
class Dictionary;
}
namespace atom { namespace atom {
class AtomJavaScriptDialogManager; class AtomJavaScriptDialogManager;
@ -80,11 +79,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Create window with existing WebContents, the caller is responsible for // Create window with existing WebContents, the caller is responsible for
// managing the window's live. // managing the window's live.
static NativeWindow* Create(content::WebContents* web_contents, static NativeWindow* Create(content::WebContents* web_contents,
base::DictionaryValue* options); const mate::Dictionary& options);
// Create window with new WebContents, the caller is responsible for // Create window with new WebContents, the caller is responsible for
// managing the window's live. // managing the window's live.
static NativeWindow* Create(base::DictionaryValue* options); static NativeWindow* Create(const mate::Dictionary& options);
// Creates a devtools window to debug the WebContents, the returned window // Creates a devtools window to debug the WebContents, the returned window
// will manage its own life. // will manage its own life.
@ -93,7 +92,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// Find a window from its process id and routing id. // Find a window from its process id and routing id.
static NativeWindow* FromRenderView(int process_id, int routing_id); static NativeWindow* FromRenderView(int process_id, int routing_id);
void InitFromOptions(base::DictionaryValue* options); void InitFromOptions(const mate::Dictionary& options);
virtual void Close() = 0; virtual void Close() = 0;
virtual void CloseImmediately() = 0; virtual void CloseImmediately() = 0;
@ -145,8 +144,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void BlurWebView(); virtual void BlurWebView();
virtual bool IsWebViewFocused(); virtual bool IsWebViewFocused();
virtual bool SetIcon(const std::string& path);
// Returns the process handle of render process, useful for killing the // Returns the process handle of render process, useful for killing the
// render process manually // render process manually
virtual base::ProcessHandle GetRenderProcessHandle(); virtual base::ProcessHandle GetRenderProcessHandle();
@ -198,7 +195,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
protected: protected:
explicit NativeWindow(content::WebContents* web_contents, explicit NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options); const mate::Dictionary& options);
brightray::InspectableWebContentsImpl* inspectable_web_contents() const { brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
return static_cast<brightray::InspectableWebContentsImpl*>( return static_cast<brightray::InspectableWebContentsImpl*>(
@ -252,7 +249,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
bool has_frame_; bool has_frame_;
// Window icon. // Window icon.
gfx::Image icon_; scoped_ptr<gfx::Image> icon_;
private: private:
// Schedule a notification unresponsive event. // Schedule a notification unresponsive event.
@ -292,7 +289,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
base::CancelableClosure window_unresposive_closure_; base::CancelableClosure window_unresposive_closure_;
// Web preferences. // Web preferences.
scoped_ptr<base::DictionaryValue> web_preferences_; scoped_ptr<mate::Dictionary> web_preferences_;
// Page's default zoom factor. // Page's default zoom factor.
double zoom_factor_; double zoom_factor_;

View file

@ -11,18 +11,19 @@
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/environment.h" #include "base/environment.h"
#include "base/nix/xdg_util.h" #include "base/nix/xdg_util.h"
#include "base/values.h"
#include "chrome/browser/ui/gtk/gtk_window_util.h" #include "chrome/browser/ui/gtk/gtk_window_util.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "content/public/common/renderer_preferences.h" #include "content/public/common/renderer_preferences.h"
#include "native_mate/dictionary.h"
#include "ui/base/accelerators/platform_accelerator_gtk.h" #include "ui/base/accelerators/platform_accelerator_gtk.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/base/x/active_window_watcher_x.h" #include "ui/base/x/active_window_watcher_x.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/gfx/font_render_params_linux.h" #include "ui/gfx/font_render_params_linux.h"
#include "ui/gfx/gtk_util.h" #include "ui/gfx/gtk_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/skia_utils_gtk.h" #include "ui/gfx/skia_utils_gtk.h"
@ -96,7 +97,7 @@ GetRendererPreferencesSubpixelRenderingEnum(
} // namespace } // namespace
NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
base::DictionaryValue* options) const mate::Dictionary& options)
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
window_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))), window_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))),
vbox_(gtk_vbox_new(FALSE, 0)), vbox_(gtk_vbox_new(FALSE, 0)),
@ -111,11 +112,11 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
GetWebContents()->GetView()->GetNativeView()); GetWebContents()->GetView()->GetNativeView());
int width = 800, height = 600; int width = 800, height = 600;
options->GetInteger(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options->GetInteger(switches::kHeight, &height); options.Get(switches::kHeight, &height);
bool use_content_size = false; bool use_content_size = false;
options->GetBoolean(switches::kUseContentSize, &use_content_size); options.Get(switches::kUseContentSize, &use_content_size);
if (has_frame_ && !use_content_size) if (has_frame_ && !use_content_size)
SubstractBorderSize(&width, &height); SubstractBorderSize(&width, &height);
@ -129,8 +130,8 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
// Create the underlying gdk window. // Create the underlying gdk window.
gtk_widget_realize(GTK_WIDGET(window_)); gtk_widget_realize(GTK_WIDGET(window_));
if (!icon_.IsEmpty()) if (icon_)
gtk_window_set_icon(window_, icon_.ToGdkPixbuf()); gtk_window_set_icon(window_, icon_->ToGdkPixbuf());
ui::ActiveWindowWatcherX::AddObserver(this); ui::ActiveWindowWatcherX::AddObserver(this);
@ -608,7 +609,7 @@ gboolean NativeWindowGtk::OnButtonPress(GtkWidget* widget,
// static // static
NativeWindow* NativeWindow::Create(content::WebContents* web_contents, NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
base::DictionaryValue* options) { const mate::Dictionary& options) {
return new NativeWindowGtk(web_contents, options); return new NativeWindowGtk(web_contents, options);
} }

View file

@ -26,7 +26,7 @@ class NativeWindowGtk : public NativeWindow,
public ui::ActiveWindowWatcherXObserver { public ui::ActiveWindowWatcherXObserver {
public: public:
explicit NativeWindowGtk(content::WebContents* web_contents, explicit NativeWindowGtk(content::WebContents* web_contents,
base::DictionaryValue* options); const mate::Dictionary& options);
virtual ~NativeWindowGtk(); virtual ~NativeWindowGtk();
// NativeWindow implementation. // NativeWindow implementation.

View file

@ -18,7 +18,7 @@ namespace atom {
class NativeWindowMac : public NativeWindow { class NativeWindowMac : public NativeWindow {
public: public:
explicit NativeWindowMac(content::WebContents* web_contents, explicit NativeWindowMac(content::WebContents* web_contents,
base::DictionaryValue* options); const mate::Dictionary& options);
virtual ~NativeWindowMac(); virtual ~NativeWindowMac();
// NativeWindow implementation. // NativeWindow implementation.

View file

@ -11,11 +11,11 @@
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/values.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "native_mate/dictionary.h"
#include "vendor/brightray/browser/inspectable_web_contents.h" #include "vendor/brightray/browser/inspectable_web_contents.h"
#include "vendor/brightray/browser/inspectable_web_contents_view.h" #include "vendor/brightray/browser/inspectable_web_contents_view.h"
@ -156,13 +156,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
namespace atom { namespace atom {
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
base::DictionaryValue* options) const mate::Dictionary& options)
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
is_kiosk_(false), is_kiosk_(false),
attention_request_id_(0) { attention_request_id_(0) {
int width = 800, height = 600; int width = 800, height = 600;
options->GetInteger(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options->GetInteger(switches::kHeight, &height); options.Get(switches::kHeight, &height);
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
NSRect cocoa_bounds = NSMakeRect( NSRect cocoa_bounds = NSMakeRect(
@ -193,18 +193,18 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
// On OS X the initial window size doesn't include window frame. // On OS X the initial window size doesn't include window frame.
bool use_content_size = false; bool use_content_size = false;
options->GetBoolean(switches::kUseContentSize, &use_content_size); options.Get(switches::kUseContentSize, &use_content_size);
if (has_frame_ && !use_content_size) if (has_frame_ && !use_content_size)
SetSize(gfx::Size(width, height)); SetSize(gfx::Size(width, height));
// Enable the NSView to accept first mouse event. // Enable the NSView to accept first mouse event.
bool acceptsFirstMouse = false; bool acceptsFirstMouse = false;
options->GetBoolean(switches::kAcceptFirstMouse, &acceptsFirstMouse); options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
[delegate setAcceptsFirstMouse:acceptsFirstMouse]; [delegate setAcceptsFirstMouse:acceptsFirstMouse];
// Disable fullscreen button when 'fullscreen' is specified to false. // Disable fullscreen button when 'fullscreen' is specified to false.
bool fullscreen; bool fullscreen;
if (!(options->GetBoolean(switches::kFullscreen, &fullscreen) && if (!(options.Get(switches::kFullscreen, &fullscreen) &&
!fullscreen)) { !fullscreen)) {
NSUInteger collectionBehavior = [window_ collectionBehavior]; NSUInteger collectionBehavior = [window_ collectionBehavior];
collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
@ -612,7 +612,7 @@ void NativeWindowMac::UpdateDraggableRegionsForCustomDrag(
// static // static
NativeWindow* NativeWindow::Create(content::WebContents* web_contents, NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
base::DictionaryValue* options) { const mate::Dictionary& options) {
return new NativeWindowMac(web_contents, options); return new NativeWindowMac(web_contents, options);
} }

View file

@ -15,13 +15,14 @@
#include "atom/common/draggable_region.h" #include "atom/common/draggable_region.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
@ -217,13 +218,13 @@ class NativeWindowFramelessView : public views::NonClientFrameView {
} // namespace } // namespace
NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
base::DictionaryValue* options) const mate::Dictionary& options)
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
window_(new views::Widget), window_(new views::Widget),
web_view_(inspectable_web_contents_view()->GetView()), web_view_(inspectable_web_contents_view()->GetView()),
use_content_size_(false), use_content_size_(false),
resizable_(true) { resizable_(true) {
options->GetBoolean(switches::kResizable, &resizable_); options.Get(switches::kResizable, &resizable_);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.delegate = this; params.delegate = this;
@ -236,11 +237,11 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
int width = 800, height = 600; int width = 800, height = 600;
options->GetInteger(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options->GetInteger(switches::kHeight, &height); options.Get(switches::kHeight, &height);
gfx::Size size(width, height); gfx::Size size(width, height);
options->GetBoolean(switches::kUseContentSize, &use_content_size_); options.Get(switches::kUseContentSize, &use_content_size_);
if (has_frame_ && use_content_size_) if (has_frame_ && use_content_size_)
ClientAreaSizeToWindowSize(&size); ClientAreaSizeToWindowSize(&size);
@ -527,10 +528,10 @@ bool NativeWindowWin::ShouldHandleSystemCommands() const {
} }
gfx::ImageSkia NativeWindowWin::GetWindowAppIcon() { gfx::ImageSkia NativeWindowWin::GetWindowAppIcon() {
if (icon_.IsEmpty()) if (icon_)
return gfx::ImageSkia(); return *(icon_->ToImageSkia());
else else
return *icon_.ToImageSkia(); return gfx::ImageSkia();
} }
gfx::ImageSkia NativeWindowWin::GetWindowIcon() { gfx::ImageSkia NativeWindowWin::GetWindowIcon() {
@ -624,7 +625,7 @@ void NativeWindowWin::RegisterAccelerators() {
// static // static
NativeWindow* NativeWindow::Create(content::WebContents* web_contents, NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
base::DictionaryValue* options) { const mate::Dictionary& options) {
return new NativeWindowWin(web_contents, options); return new NativeWindowWin(web_contents, options);
} }

View file

@ -35,7 +35,7 @@ class NativeWindowWin : public NativeWindow,
public views::WidgetDelegateView { public views::WidgetDelegateView {
public: public:
explicit NativeWindowWin(content::WebContents* web_contents, explicit NativeWindowWin(content::WebContents* web_contents,
base::DictionaryValue* options); const mate::Dictionary& options);
virtual ~NativeWindowWin(); virtual ~NativeWindowWin();
// NativeWindow implementation. // NativeWindow implementation.

View file

@ -6,7 +6,7 @@
#include "atom/browser/ui/cocoa/atom_menu_controller.h" #include "atom/browser/ui/cocoa/atom_menu_controller.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h" #include "ui/gfx/image/image.h"
@interface StatusItemController : NSObject { @interface StatusItemController : NSObject {
atom::TrayIconCocoa* trayIcon_; // weak atom::TrayIconCocoa* trayIcon_; // weak
@ -50,17 +50,17 @@ TrayIconCocoa::~TrayIconCocoa() {
void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) { void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) {
if (!image.isNull()) { if (!image.isNull()) {
NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap()); gfx::Image neutral(image);
if (ns_image) if (!neutral.IsEmpty())
[item_ setImage:ns_image]; [item_ setImage:neutral.ToNSImage()];
} }
} }
void TrayIconCocoa::SetPressedImage(const gfx::ImageSkia& image) { void TrayIconCocoa::SetPressedImage(const gfx::ImageSkia& image) {
if (!image.isNull()) { if (!image.isNull()) {
NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap()); gfx::Image neutral(image);
if (ns_image) if (!neutral.IsEmpty())
[item_ setAlternateImage:ns_image]; [item_ setAlternateImage:neutral.ToNSImage()];
} }
} }

View file

@ -8,12 +8,25 @@
#include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/strings/string_util.h"
#include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
namespace mate { namespace mate {
namespace {
ui::ScaleFactor GetScaleFactorFromFileName(const base::FilePath& path) {
std::string filename(path.BaseName().RemoveExtension().AsUTF8Unsafe());
if (EndsWith(filename, "@2x", true))
return ui::SCALE_FACTOR_200P;
else
return ui::SCALE_FACTOR_100P;
}
} // namespace
bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate, bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
gfx::ImageSkia* out) { gfx::ImageSkia* out) {
@ -34,7 +47,8 @@ bool Converter<gfx::ImageSkia>::FromV8(v8::Isolate* isolate,
decoded.reset(gfx::JPEGCodec::Decode(data, size)); decoded.reset(gfx::JPEGCodec::Decode(data, size));
if (decoded) { if (decoded) {
*out = gfx::ImageSkia::CreateFrom1xBitmap(*decoded.release()); *out = gfx::ImageSkia(gfx::ImageSkiaRep(*decoded.release(),
GetScaleFactorFromFileName(path)));
return true; return true;
} }
} }

View file

@ -15,7 +15,7 @@ bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter); scoped_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter);
scoped_ptr<base::Value> value(converter->FromV8Value( scoped_ptr<base::Value> value(converter->FromV8Value(
val, v8::Context::GetCurrent())); val, v8::Context::GetCurrent()));
if (value->IsType(base::Value::TYPE_DICTIONARY)) { if (value && value->IsType(base::Value::TYPE_DICTIONARY)) {
out->Swap(static_cast<DictionaryValue*>(value.get())); out->Swap(static_cast<DictionaryValue*>(value.get()));
return true; return true;
} else { } else {

View file

@ -47,7 +47,7 @@ You can also create a window without chrome by using
zoom percent / 100, so `3.0` represents `300%` zoom percent / 100, so `3.0` represents `300%`
* `kiosk` Boolean - The kiosk mode * `kiosk` Boolean - The kiosk mode
* `title` String - Default window title * `title` String - Default window title
* `icon` String - The path of icon file * `icon` [Image](image.md) - The window icon
* `show` Boolean - Whether window should be shown when created * `show` Boolean - Whether window should be shown when created
* `frame` Boolean - Specify `false` to create a * `frame` Boolean - Specify `false` to create a
[Frameless Window](frameless-window.md) [Frameless Window](frameless-window.md)

25
docs/api/image.md Normal file
View file

@ -0,0 +1,25 @@
# Image
In atom-shell images are represented by their file paths, we currently do not
support in-memory images or remote images.
For example when creating tray or setting window's icon, you can pass image's
file path as `String` to represent an image:
```javascript
var appIcon = new Tray('/Users/somebody/images/icon@2x.png');
var window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});
```
## Supported formats
Only `PNG` and `JPG` formats are supported, and `PNG` format is preferred.
## High resolution image
On platforms that have high-DPI support, you can append `@2x` after image's
file name's base name to mark it as a high resolution image.
For example if `icon.png` is a normal image that has standard resolution, the
`icon@2x.png` would be treated as a high resolution image that has double DPI
dense.

View file

@ -40,7 +40,7 @@ rely on `clicked` event and always attach a context menu to the tray icon.
### new Tray(image) ### new Tray(image)
* `image` String * `image` [Image](image.md)
Creates a new tray icon associated with the `image`. Creates a new tray icon associated with the `image`.
@ -50,13 +50,13 @@ Emitted when the tray icon is clicked.
### Tray.setImage(image) ### Tray.setImage(image)
* `image` String * `image` [Image](image.md)
Sets the `image` associated with this tray icon. Sets the `image` associated with this tray icon.
### Tray.setPressedImage(image) ### Tray.setPressedImage(image)
* `image` String * `image` [Image](image.md)
Sets the `image` associated with this tray icon when pressed. Sets the `image` associated with this tray icon when pressed.

View file

@ -15,7 +15,7 @@ describe 'crash-reporter module', ->
afterEach -> w.destroy() afterEach -> w.destroy()
it 'should send minidump when renderer crashes', (done) -> it 'should send minidump when renderer crashes', (done) ->
@timeout 5000 @timeout 60000
server = http.createServer (req, res) -> server = http.createServer (req, res) ->
form = new formidable.IncomingForm() form = new formidable.IncomingForm()
process.throwDeprecation = false process.throwDeprecation = false

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit c79aecf64de260dd239c6aed8397d3e152d7589d Subproject commit a5c4a2c7c64239ec5d007342f00f16f3981d6d80