From 6cac69238cef158d1bfbbb86af9cf3ca8bc892bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 12:59:10 +0800 Subject: [PATCH 1/9] mac: Convert from ImageSkia to NSImage to reserve DPI info. --- atom/browser/ui/tray_icon_cocoa.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 03461634378c..ef456897e91f 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -6,7 +6,7 @@ #include "atom/browser/ui/cocoa/atom_menu_controller.h" #include "base/strings/sys_string_conversions.h" -#include "skia/ext/skia_utils_mac.h" +#include "ui/gfx/image/image.h" @interface StatusItemController : NSObject { atom::TrayIconCocoa* trayIcon_; // weak @@ -50,17 +50,17 @@ TrayIconCocoa::~TrayIconCocoa() { void TrayIconCocoa::SetImage(const gfx::ImageSkia& image) { if (!image.isNull()) { - NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap()); - if (ns_image) - [item_ setImage:ns_image]; + gfx::Image neutral(image); + if (!neutral.IsEmpty()) + [item_ setImage:neutral.ToNSImage()]; } } void TrayIconCocoa::SetPressedImage(const gfx::ImageSkia& image) { if (!image.isNull()) { - NSImage* ns_image = gfx::SkBitmapToNSImage(*image.bitmap()); - if (ns_image) - [item_ setAlternateImage:ns_image]; + gfx::Image neutral(image); + if (!neutral.IsEmpty()) + [item_ setAlternateImage:neutral.ToNSImage()]; } } From 11e4111f25f2d129c40c700bc0ffaaf7961d5276 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 13:09:06 +0800 Subject: [PATCH 2/9] Recognize the "@2x" suffix of icon's filename. --- .../native_mate_converters/image_converter.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/atom/common/native_mate_converters/image_converter.cc b/atom/common/native_mate_converters/image_converter.cc index 5564f1e5dfc0..ca676c8d0091 100644 --- a/atom/common/native_mate_converters/image_converter.cc +++ b/atom/common/native_mate_converters/image_converter.cc @@ -8,12 +8,25 @@ #include "atom/common/native_mate_converters/file_path_converter.h" #include "base/file_util.h" +#include "base/strings/string_util.h" #include "ui/gfx/codec/jpeg_codec.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/image/image_skia.h" 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::FromV8(v8::Isolate* isolate, v8::Handle val, gfx::ImageSkia* out) { @@ -34,7 +47,8 @@ bool Converter::FromV8(v8::Isolate* isolate, decoded.reset(gfx::JPEGCodec::Decode(data, size)); if (decoded) { - *out = gfx::ImageSkia::CreateFrom1xBitmap(*decoded.release()); + *out = gfx::ImageSkia(gfx::ImageSkiaRep(*decoded.release(), + GetScaleFactorFromFileName(path))); return true; } } From 0349fdfd679b80998cf950210823cc2dc28f2ba5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 21:50:28 +0800 Subject: [PATCH 3/9] Fix converting empty V8 dictionary. --- atom/common/native_mate_converters/value_converter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/common/native_mate_converters/value_converter.cc b/atom/common/native_mate_converters/value_converter.cc index 626917d62054..79848b28bf44 100644 --- a/atom/common/native_mate_converters/value_converter.cc +++ b/atom/common/native_mate_converters/value_converter.cc @@ -15,7 +15,7 @@ bool Converter::FromV8(v8::Isolate* isolate, scoped_ptr converter(new atom::V8ValueConverter); scoped_ptr value(converter->FromV8Value( val, v8::Context::GetCurrent())); - if (value->IsType(base::Value::TYPE_DICTIONARY)) { + if (value && value->IsType(base::Value::TYPE_DICTIONARY)) { out->Swap(static_cast(value.get())); return true; } else { From 84e2c35611fccf18cc2dcdfbdea88f2d1b057636 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 21:51:42 +0800 Subject: [PATCH 4/9] Use mate::Dictionary instead of base::DictionaryValue for options. mate::Dictionary can represent arbitray type, which matches our use. --- atom/browser/api/atom_api_window.cc | 9 ++--- atom/browser/api/atom_api_window.h | 9 +---- atom/browser/devtools_delegate.cc | 8 ++-- atom/browser/native_window.cc | 57 +++++++++++++++-------------- atom/browser/native_window.h | 12 ++++-- atom/browser/native_window_gtk.cc | 12 +++--- atom/browser/native_window_gtk.h | 2 +- atom/browser/native_window_mac.h | 2 +- atom/browser/native_window_mac.mm | 16 ++++---- atom/browser/native_window_win.cc | 14 +++---- atom/browser/native_window_win.h | 2 +- vendor/native_mate | 2 +- 12 files changed, 71 insertions(+), 74 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index e0816755f9c7..5a74b86bfdf0 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -7,7 +7,6 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/native_window.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/callback.h" #include "content/public/browser/render_process_host.h" @@ -61,7 +60,7 @@ void OnCapturePageDone( } // namespace -Window::Window(base::DictionaryValue* options) +Window::Window(const mate::Dictionary& options) : window_(NativeWindow::Create(options)) { window_->InitFromOptions(options); window_->AddObserver(this); @@ -108,10 +107,8 @@ void Window::OnRendererResponsive() { } // static -mate::Wrappable* Window::New(mate::Arguments* args, - const base::DictionaryValue& options) { - scoped_ptr copied_options(options.DeepCopy()); - return new Window(copied_options.get()); +mate::Wrappable* Window::New(const mate::Dictionary& options) { + return new Window(options); } void Window::Destroy() { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 820651f39253..19d6dc55bee7 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -15,10 +15,6 @@ class GURL; -namespace base { -class DictionaryValue; -} - namespace mate { class Arguments; class Dictionary; @@ -35,8 +31,7 @@ class WebContents; class Window : public mate::EventEmitter, public NativeWindowObserver { public: - static mate::Wrappable* New(mate::Arguments* args, - const base::DictionaryValue& options); + static mate::Wrappable* New(const mate::Dictionary& options); static void BuildPrototype(v8::Isolate* isolate, v8::Handle prototype); @@ -44,7 +39,7 @@ class Window : public mate::EventEmitter, NativeWindow* window() const { return window_.get(); } protected: - explicit Window(base::DictionaryValue* options); + explicit Window(const mate::Dictionary& options); virtual ~Window(); // Implementations of NativeWindowObserver: diff --git a/atom/browser/devtools_delegate.cc b/atom/browser/devtools_delegate.cc index ed8dcfa3a222..6981f7397d35 100644 --- a/atom/browser/devtools_delegate.cc +++ b/atom/browser/devtools_delegate.cc @@ -7,13 +7,13 @@ #include #include "base/message_loop/message_loop.h" -#include "base/values.h" #include "atom/browser/native_window.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/web_contents.h" +#include "native_mate/dictionary.h" #include "ui/gfx/point.h" namespace atom { @@ -37,9 +37,9 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window, devtools_agent_host_.get(), devtools_client_host_.get()); // Go! - base::DictionaryValue options; - options.SetString("title", "DevTools Debugger"); - window->InitFromOptions(&options); + mate::Dictionary options; + options.Set("title", "DevTools Debugger"); + window->InitFromOptions(options); window->AddObserver(this); web_contents->GetController().LoadURL( GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"), diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 97a4ae515f06..e7e320184a44 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -16,6 +16,7 @@ #include "atom/browser/window_list.h" #include "atom/common/api/api_messages.h" #include "atom/common/atom_version.h" +#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/file_util.h" @@ -39,6 +40,7 @@ #include "content/public/browser/web_contents_view.h" #include "content/public/common/renderer_preferences.h" #include "ipc/ipc_message_macros.h" +#include "native_mate/dictionary.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" @@ -53,7 +55,7 @@ using content::NavigationEntry; namespace atom { NativeWindow::NativeWindow(content::WebContents* web_contents, - base::DictionaryValue* options) + const mate::Dictionary& options) : content::WebContentsObserver(web_contents), has_frame_(true), is_closed_(false), @@ -63,7 +65,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, weak_factory_(this), inspectable_web_contents_( brightray::InspectableWebContents::Create(web_contents)) { - options->GetBoolean(switches::kFrame, &has_frame_); + options.Get(switches::kFrame, &has_frame_); #if defined(OS_MACOSX) // Temporary fix for flashing devtools, try removing this after upgraded to @@ -73,19 +75,19 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, // Read icon before window is created. std::string icon; - if (options->GetString(switches::kIcon, &icon) && !SetIcon(icon)) + if (options.Get(switches::kIcon, &icon) && !SetIcon(icon)) LOG(ERROR) << "Failed to set icon to " << icon; // Read iframe security before any navigation. - options->GetString(switches::kNodeIntegration, &node_integration_); + options.Get(switches::kNodeIntegration, &node_integration_); // Read the web preferences. - base::DictionaryValue* web_preferences; - if (options->GetDictionary(switches::kWebPreferences, &web_preferences)) - web_preferences_.reset(web_preferences->DeepCopy()); + base::DictionaryValue web_preferences; + if (options.Get(switches::kWebPreferences, &web_preferences)) + web_preferences_.reset(web_preferences.DeepCopy()); // Read the zoom factor before any navigation. - options->GetDouble(switches::kZoomFactor, &zoom_factor_); + options.Get(switches::kZoomFactor, &zoom_factor_); web_contents->SetDelegate(this); inspectable_web_contents()->SetDelegate(this); @@ -117,15 +119,15 @@ NativeWindow::~NativeWindow() { } // static -NativeWindow* NativeWindow::Create(base::DictionaryValue* options) { +NativeWindow* NativeWindow::Create(const mate::Dictionary& options) { content::WebContents::CreateParams create_params(AtomBrowserContext::Get()); return Create(content::WebContents::Create(create_params), options); } // static NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) { - base::DictionaryValue options; - NativeWindow* window = NativeWindow::Create(&options); + mate::Dictionary options; + NativeWindow* window = NativeWindow::Create(options); window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents)); return window; } @@ -146,56 +148,55 @@ NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) { return NULL; } -void NativeWindow::InitFromOptions(base::DictionaryValue* options) { +void NativeWindow::InitFromOptions(const mate::Dictionary& options) { // Setup window from options. int x = -1, y = -1; bool center; - if (options->GetInteger(switches::kX, &x) && - options->GetInteger(switches::kY, &y)) { + if (options.Get(switches::kX, &x) && options.Get(switches::kY, &y)) { int width = -1, height = -1; - options->GetInteger(switches::kWidth, &width); - options->GetInteger(switches::kHeight, &height); + options.Get(switches::kWidth, &width); + options.Get(switches::kHeight, &height); Move(gfx::Rect(x, y, width, height)); - } else if (options->GetBoolean(switches::kCenter, ¢er) && center) { + } else if (options.Get(switches::kCenter, ¢er) && center) { Center(); } int min_height = -1, min_width = -1; - if (options->GetInteger(switches::kMinHeight, &min_height) && - options->GetInteger(switches::kMinWidth, &min_width)) { + if (options.Get(switches::kMinHeight, &min_height) && + options.Get(switches::kMinWidth, &min_width)) { SetMinimumSize(gfx::Size(min_width, min_height)); } int max_height = -1, max_width = -1; - if (options->GetInteger(switches::kMaxHeight, &max_height) && - options->GetInteger(switches::kMaxWidth, &max_width)) { + if (options.Get(switches::kMaxHeight, &max_height) && + options.Get(switches::kMaxWidth, &max_width)) { SetMaximumSize(gfx::Size(max_width, max_height)); } bool resizable; - if (options->GetBoolean(switches::kResizable, &resizable)) { + if (options.Get(switches::kResizable, &resizable)) { SetResizable(resizable); } bool top; - if (options->GetBoolean(switches::kAlwaysOnTop, &top) && top) { + if (options.Get(switches::kAlwaysOnTop, &top) && top) { SetAlwaysOnTop(true); } bool fullscreen; - if (options->GetBoolean(switches::kFullscreen, &fullscreen) && fullscreen) { + if (options.Get(switches::kFullscreen, &fullscreen) && fullscreen) { SetFullscreen(true); } bool skip; - if (options->GetBoolean(switches::kSkipTaskbar, &skip) && skip) { + if (options.Get(switches::kSkipTaskbar, &skip) && skip) { SetSkipTaskbar(skip); } bool kiosk; - if (options->GetBoolean(switches::kKiosk, &kiosk) && kiosk) { + if (options.Get(switches::kKiosk, &kiosk) && kiosk) { SetKiosk(kiosk); } std::string title("Atom Shell"); - options->GetString(switches::kTitle, &title); + options.Get(switches::kTitle, &title); SetTitle(title); // Then show it. bool show = true; - options->GetBoolean(switches::kShow, &show); + options.Get(switches::kShow, &show); if (show) Show(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 9562d863b85b..355d0b398e3d 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -42,6 +42,10 @@ class Rect; class Size; } +namespace mate { +class Dictionary; +} + namespace atom { class AtomJavaScriptDialogManager; @@ -80,11 +84,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Create window with existing WebContents, the caller is responsible for // managing the window's live. static NativeWindow* Create(content::WebContents* web_contents, - base::DictionaryValue* options); + const mate::Dictionary& options); // Create window with new WebContents, the caller is responsible for // 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 // will manage its own life. @@ -93,7 +97,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // Find a window from its process id and 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 CloseImmediately() = 0; @@ -198,7 +202,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, protected: explicit NativeWindow(content::WebContents* web_contents, - base::DictionaryValue* options); + const mate::Dictionary& options); brightray::InspectableWebContentsImpl* inspectable_web_contents() const { return static_cast( diff --git a/atom/browser/native_window_gtk.cc b/atom/browser/native_window_gtk.cc index df788d28fd12..96a58ca89169 100644 --- a/atom/browser/native_window_gtk.cc +++ b/atom/browser/native_window_gtk.cc @@ -11,12 +11,12 @@ #include "atom/common/options_switches.h" #include "base/environment.h" #include "base/nix/xdg_util.h" -#include "base/values.h" #include "chrome/browser/ui/gtk/gtk_window_util.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/common/renderer_preferences.h" +#include "native_mate/dictionary.h" #include "ui/base/accelerators/platform_accelerator_gtk.h" #include "ui/base/models/simple_menu_model.h" #include "ui/base/x/active_window_watcher_x.h" @@ -96,7 +96,7 @@ GetRendererPreferencesSubpixelRenderingEnum( } // namespace NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, - base::DictionaryValue* options) + const mate::Dictionary& options) : NativeWindow(web_contents, options), window_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))), vbox_(gtk_vbox_new(FALSE, 0)), @@ -111,11 +111,11 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, GetWebContents()->GetView()->GetNativeView()); int width = 800, height = 600; - options->GetInteger(switches::kWidth, &width); - options->GetInteger(switches::kHeight, &height); + options.Get(switches::kWidth, &width); + options.Get(switches::kHeight, &height); 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) SubstractBorderSize(&width, &height); @@ -608,7 +608,7 @@ gboolean NativeWindowGtk::OnButtonPress(GtkWidget* widget, // static NativeWindow* NativeWindow::Create(content::WebContents* web_contents, - base::DictionaryValue* options) { + const mate::Dictionary& options) { return new NativeWindowGtk(web_contents, options); } diff --git a/atom/browser/native_window_gtk.h b/atom/browser/native_window_gtk.h index 725b1d3b02cc..61dcdf92e9d1 100644 --- a/atom/browser/native_window_gtk.h +++ b/atom/browser/native_window_gtk.h @@ -26,7 +26,7 @@ class NativeWindowGtk : public NativeWindow, public ui::ActiveWindowWatcherXObserver { public: explicit NativeWindowGtk(content::WebContents* web_contents, - base::DictionaryValue* options); + const mate::Dictionary& options); virtual ~NativeWindowGtk(); // NativeWindow implementation. diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index c2bd8441c56f..a57b24ce9dbd 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -18,7 +18,7 @@ namespace atom { class NativeWindowMac : public NativeWindow { public: explicit NativeWindowMac(content::WebContents* web_contents, - base::DictionaryValue* options); + const mate::Dictionary& options); virtual ~NativeWindowMac(); // NativeWindow implementation. diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index e3e54513f900..e88491d8fd6f 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -11,11 +11,11 @@ #include "atom/common/options_switches.h" #include "base/mac/mac_util.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/web_contents.h" #include "content/public/browser/web_contents_view.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_view.h" @@ -156,13 +156,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; namespace atom { NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, - base::DictionaryValue* options) + const mate::Dictionary& options) : NativeWindow(web_contents, options), is_kiosk_(false), attention_request_id_(0) { int width = 800, height = 600; - options->GetInteger(switches::kWidth, &width); - options->GetInteger(switches::kHeight, &height); + options.Get(switches::kWidth, &width); + options.Get(switches::kHeight, &height); NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; 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. 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) SetSize(gfx::Size(width, height)); // Enable the NSView to accept first mouse event. bool acceptsFirstMouse = false; - options->GetBoolean(switches::kAcceptFirstMouse, &acceptsFirstMouse); + options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse); [delegate setAcceptsFirstMouse:acceptsFirstMouse]; // Disable fullscreen button when 'fullscreen' is specified to false. bool fullscreen; - if (!(options->GetBoolean(switches::kFullscreen, &fullscreen) && + if (!(options.Get(switches::kFullscreen, &fullscreen) && !fullscreen)) { NSUInteger collectionBehavior = [window_ collectionBehavior]; collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; @@ -612,7 +612,7 @@ void NativeWindowMac::UpdateDraggableRegionsForCustomDrag( // static NativeWindow* NativeWindow::Create(content::WebContents* web_contents, - base::DictionaryValue* options) { + const mate::Dictionary& options) { return new NativeWindowMac(web_contents, options); } diff --git a/atom/browser/native_window_win.cc b/atom/browser/native_window_win.cc index 84b26e953ad8..4a0493c5bb81 100644 --- a/atom/browser/native_window_win.cc +++ b/atom/browser/native_window_win.cc @@ -15,13 +15,13 @@ #include "atom/common/draggable_region.h" #include "atom/common/options_switches.h" #include "base/strings/utf_string_conversions.h" -#include "base/values.h" #include "base/win/scoped_comptr.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" +#include "native_mate/dictionary.h" #include "ui/gfx/path.h" #include "ui/base/models/simple_menu_model.h" #include "ui/views/widget/widget.h" @@ -217,13 +217,13 @@ class NativeWindowFramelessView : public views::NonClientFrameView { } // namespace NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, - base::DictionaryValue* options) + const mate::Dictionary& options) : NativeWindow(web_contents, options), window_(new views::Widget), web_view_(inspectable_web_contents_view()->GetView()), use_content_size_(false), resizable_(true) { - options->GetBoolean(switches::kResizable, &resizable_); + options.Get(switches::kResizable, &resizable_); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); params.delegate = this; @@ -236,11 +236,11 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); int width = 800, height = 600; - options->GetInteger(switches::kWidth, &width); - options->GetInteger(switches::kHeight, &height); + options.Get(switches::kWidth, &width); + options.Get(switches::kHeight, &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_) ClientAreaSizeToWindowSize(&size); @@ -624,7 +624,7 @@ void NativeWindowWin::RegisterAccelerators() { // static NativeWindow* NativeWindow::Create(content::WebContents* web_contents, - base::DictionaryValue* options) { + const mate::Dictionary& options) { return new NativeWindowWin(web_contents, options); } diff --git a/atom/browser/native_window_win.h b/atom/browser/native_window_win.h index 44d158e9c5a1..0a5047523fac 100644 --- a/atom/browser/native_window_win.h +++ b/atom/browser/native_window_win.h @@ -35,7 +35,7 @@ class NativeWindowWin : public NativeWindow, public views::WidgetDelegateView { public: explicit NativeWindowWin(content::WebContents* web_contents, - base::DictionaryValue* options); + const mate::Dictionary& options); virtual ~NativeWindowWin(); // NativeWindow implementation. diff --git a/vendor/native_mate b/vendor/native_mate index c79aecf64de2..a5c4a2c7c642 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit c79aecf64de260dd239c6aed8397d3e152d7589d +Subproject commit a5c4a2c7c64239ec5d007342f00f16f3981d6d80 From b92e6e97eaf5ced9bdf7e0ff9b727739a7e7f299 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 22:08:40 +0800 Subject: [PATCH 5/9] Dicard uses of base::Value in native_window. --- atom/browser/native_window.cc | 40 +++++++++++++++-------------------- atom/browser/native_window.h | 7 +----- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index e7e320184a44..b7331ba39474 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -16,7 +16,7 @@ #include "atom/browser/window_list.h" #include "atom/common/api/api_messages.h" #include "atom/common/atom_version.h" -#include "atom/common/native_mate_converters/value_converter.h" +#include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/file_util.h" @@ -26,7 +26,6 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "base/values.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/invalidate_type.h" #include "content/public/browser/navigation_entry.h" @@ -82,9 +81,9 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, options.Get(switches::kNodeIntegration, &node_integration_); // Read the web preferences. - base::DictionaryValue web_preferences; - if (options.Get(switches::kWebPreferences, &web_preferences)) - web_preferences_.reset(web_preferences.DeepCopy()); + scoped_ptr web_preferences(new mate::Dictionary); + if (options.Get(switches::kWebPreferences, web_preferences.get())) + web_preferences_.reset(web_preferences.release()); // Read the zoom factor before any navigation. options.Get(switches::kZoomFactor, &zoom_factor_); @@ -377,35 +376,30 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { prefs->accelerated_compositing_enabled = false; bool b; - base::ListValue* list; + std::vector list; if (!web_preferences_) return; - if (web_preferences_->GetBoolean("javascript", &b)) + if (web_preferences_->Get("javascript", &b)) prefs->javascript_enabled = b; - if (web_preferences_->GetBoolean("web-security", &b)) + if (web_preferences_->Get("web-security", &b)) prefs->web_security_enabled = b; - if (web_preferences_->GetBoolean("images", &b)) + if (web_preferences_->Get("images", &b)) prefs->images_enabled = b; - if (web_preferences_->GetBoolean("java", &b)) + if (web_preferences_->Get("java", &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; - if (web_preferences_->GetBoolean("webgl", &b)) + if (web_preferences_->Get("webgl", &b)) prefs->experimental_webgl_enabled = b; - if (web_preferences_->GetBoolean("webaudio", &b)) + if (web_preferences_->Get("webaudio", &b)) prefs->webaudio_enabled = b; - if (web_preferences_->GetBoolean("accelerated-compositing", &b)) + if (web_preferences_->Get("accelerated-compositing", &b)) prefs->accelerated_compositing_enabled = b; - if (web_preferences_->GetBoolean("plugins", &b)) + if (web_preferences_->Get("plugins", &b)) prefs->plugins_enabled = b; - if (web_preferences_->GetList("extra-plugin-dirs", &list)) - for (size_t i = 0; i < list->GetSize(); ++i) { - base::FilePath::StringType path_string; - if (list->GetString(i, &path_string)) { - base::FilePath path(path_string); - content::PluginService::GetInstance()->AddExtraPluginDir(path); - } - } + if (web_preferences_->Get("extra-plugin-dirs", &list)) + for (size_t i = 0; i < list.size(); ++i) + content::PluginService::GetInstance()->AddExtraPluginDir(list[i]); } void NativeWindow::NotifyWindowClosed() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 355d0b398e3d..3f9f24e1bf1a 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -26,11 +26,6 @@ class CommandLine; struct WebPreferences; -namespace base { -class DictionaryValue; -class ListValue; -} - namespace content { class BrowserContext; class WebContents; @@ -296,7 +291,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, base::CancelableClosure window_unresposive_closure_; // Web preferences. - scoped_ptr web_preferences_; + scoped_ptr web_preferences_; // Page's default zoom factor. double zoom_factor_; From ca1d2a32b0426ee3b133ea63a8729d1c1643bcf3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 22:26:01 +0800 Subject: [PATCH 6/9] Support high dpi icon as window icon. --- atom/browser/native_window.cc | 29 ++++++----------------------- atom/browser/native_window.h | 6 ++---- atom/browser/native_window_gtk.cc | 5 +++-- atom/browser/native_window_win.cc | 7 ++++--- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index b7331ba39474..fc907af67a82 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -16,6 +16,7 @@ #include "atom/browser/window_list.h" #include "atom/common/api/api_messages.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 "base/command_line.h" @@ -41,6 +42,8 @@ #include "ipc/ipc_message_macros.h" #include "native_mate/dictionary.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/rect.h" #include "ui/gfx/size.h" @@ -73,9 +76,9 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, #endif // Read icon before window is created. - std::string icon; - if (options.Get(switches::kIcon, &icon) && !SetIcon(icon)) - LOG(ERROR) << "Failed to set icon to " << icon; + gfx::ImageSkia icon; + if (options.Get(switches::kIcon, &icon)) + icon_.reset(new gfx::Image(icon)); // Read iframe security before any navigation. options.Get(switches::kNodeIntegration, &node_integration_); @@ -257,26 +260,6 @@ bool NativeWindow::IsWebViewFocused() { 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(file_contents.data()); - scoped_ptr 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() { return GetWebContents()->GetRenderProcessHost()->GetHandle(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 3f9f24e1bf1a..667df9743f26 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -18,7 +18,6 @@ #include "atom/browser/native_window_observer.h" #include "content/public/browser/notification_registrar.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/inspectable_web_contents_delegate.h" #include "vendor/brightray/browser/inspectable_web_contents_impl.h" @@ -32,6 +31,7 @@ class WebContents; } namespace gfx { +class Image; class Point; class Rect; class Size; @@ -144,8 +144,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void BlurWebView(); virtual bool IsWebViewFocused(); - virtual bool SetIcon(const std::string& path); - // Returns the process handle of render process, useful for killing the // render process manually virtual base::ProcessHandle GetRenderProcessHandle(); @@ -251,7 +249,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, bool has_frame_; // Window icon. - gfx::Image icon_; + scoped_ptr icon_; private: // Schedule a notification unresponsive event. diff --git a/atom/browser/native_window_gtk.cc b/atom/browser/native_window_gtk.cc index 96a58ca89169..f0f6b5995c5e 100644 --- a/atom/browser/native_window_gtk.cc +++ b/atom/browser/native_window_gtk.cc @@ -23,6 +23,7 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/font_render_params_linux.h" #include "ui/gfx/gtk_util.h" +#include "ui/gfx/image.h" #include "ui/gfx/rect.h" #include "ui/gfx/skia_utils_gtk.h" @@ -129,8 +130,8 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, // Create the underlying gdk window. gtk_widget_realize(GTK_WIDGET(window_)); - if (!icon_.IsEmpty()) - gtk_window_set_icon(window_, icon_.ToGdkPixbuf()); + if (icon_) + gtk_window_set_icon(window_, icon_->ToGdkPixbuf()); ui::ActiveWindowWatcherX::AddObserver(this); diff --git a/atom/browser/native_window_win.cc b/atom/browser/native_window_win.cc index 4a0493c5bb81..15f723ed023e 100644 --- a/atom/browser/native_window_win.cc +++ b/atom/browser/native_window_win.cc @@ -22,6 +22,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "native_mate/dictionary.h" +#include "ui/gfx/image.h" #include "ui/gfx/path.h" #include "ui/base/models/simple_menu_model.h" #include "ui/views/widget/widget.h" @@ -527,10 +528,10 @@ bool NativeWindowWin::ShouldHandleSystemCommands() const { } gfx::ImageSkia NativeWindowWin::GetWindowAppIcon() { - if (icon_.IsEmpty()) - return gfx::ImageSkia(); + if (icon_) + return *(icon_->ToImageSkia()); else - return *icon_.ToImageSkia(); + return gfx::ImageSkia(); } gfx::ImageSkia NativeWindowWin::GetWindowIcon() { From 2ff4d56d6d1f16bad9d0aed695146f46a64dff91 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 22:31:02 +0800 Subject: [PATCH 7/9] Fix compilation error. --- atom/browser/native_window_gtk.cc | 2 +- atom/browser/native_window_win.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window_gtk.cc b/atom/browser/native_window_gtk.cc index f0f6b5995c5e..3b1f6f8d3484 100644 --- a/atom/browser/native_window_gtk.cc +++ b/atom/browser/native_window_gtk.cc @@ -23,7 +23,7 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/font_render_params_linux.h" #include "ui/gfx/gtk_util.h" -#include "ui/gfx/image.h" +#include "ui/gfx/image/image.h" #include "ui/gfx/rect.h" #include "ui/gfx/skia_utils_gtk.h" diff --git a/atom/browser/native_window_win.cc b/atom/browser/native_window_win.cc index 15f723ed023e..3ba3daa91ad9 100644 --- a/atom/browser/native_window_win.cc +++ b/atom/browser/native_window_win.cc @@ -22,7 +22,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "native_mate/dictionary.h" -#include "ui/gfx/image.h" +#include "ui/gfx/image/image.h" #include "ui/gfx/path.h" #include "ui/base/models/simple_menu_model.h" #include "ui/views/widget/widget.h" From 1a0d8a4aa97214df97e5965b2a64b3a5ae144388 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 22:58:42 +0800 Subject: [PATCH 8/9] :memo: Add docs on image support in atom-shell. --- docs/api/browser-window.md | 2 +- docs/api/image.md | 25 +++++++++++++++++++++++++ docs/api/tray.md | 6 +++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 docs/api/image.md diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index d6391ce6ca82..84f3fdf5f4c1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -47,7 +47,7 @@ You can also create a window without chrome by using zoom percent / 100, so `3.0` represents `300%` * `kiosk` Boolean - The kiosk mode * `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 * `frame` Boolean - Specify `false` to create a [Frameless Window](frameless-window.md) diff --git a/docs/api/image.md b/docs/api/image.md new file mode 100644 index 000000000000..a18e3e8ae1a5 --- /dev/null +++ b/docs/api/image.md @@ -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. diff --git a/docs/api/tray.md b/docs/api/tray.md index 01aca310522c..ebdeae3d0dcc 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -40,7 +40,7 @@ rely on `clicked` event and always attach a context menu to the tray icon. ### new Tray(image) -* `image` String +* `image` [Image](image.md) Creates a new tray icon associated with the `image`. @@ -50,13 +50,13 @@ Emitted when the tray icon is clicked. ### Tray.setImage(image) -* `image` String +* `image` [Image](image.md) Sets the `image` associated with this tray icon. ### Tray.setPressedImage(image) -* `image` String +* `image` [Image](image.md) Sets the `image` associated with this tray icon when pressed. From a8de6150342abcc5ae350f8e91c1ad40693be70c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jun 2014 23:01:50 +0800 Subject: [PATCH 9/9] Wait for crash reporter spec longer. --- spec/api-crash-reporter-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-crash-reporter-spec.coffee b/spec/api-crash-reporter-spec.coffee index 4a7cff6ccd06..2dd1499edb7d 100644 --- a/spec/api-crash-reporter-spec.coffee +++ b/spec/api-crash-reporter-spec.coffee @@ -15,7 +15,7 @@ describe 'crash-reporter module', -> afterEach -> w.destroy() it 'should send minidump when renderer crashes', (done) -> - @timeout 5000 + @timeout 60000 server = http.createServer (req, res) -> form = new formidable.IncomingForm() process.throwDeprecation = false