Support high dpi icon as window icon.
This commit is contained in:
parent
b92e6e97ea
commit
ca1d2a32b0
4 changed files with 15 additions and 32 deletions
|
@ -16,6 +16,7 @@
|
||||||
#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/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"
|
||||||
|
@ -41,6 +42,8 @@
|
||||||
#include "ipc/ipc_message_macros.h"
|
#include "ipc/ipc_message_macros.h"
|
||||||
#include "native_mate/dictionary.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"
|
||||||
|
@ -73,9 +76,9 @@ 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.Get(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.Get(switches::kNodeIntegration, &node_integration_);
|
options.Get(switches::kNodeIntegration, &node_integration_);
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -32,6 +31,7 @@ class WebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
class Image;
|
||||||
class Point;
|
class Point;
|
||||||
class Rect;
|
class Rect;
|
||||||
class Size;
|
class Size;
|
||||||
|
@ -144,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();
|
||||||
|
@ -251,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.
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#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.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"
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#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 "native_mate/dictionary.h"
|
||||||
|
#include "ui/gfx/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"
|
||||||
|
@ -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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue