From 239bfe970cfa38ce0c9618977c3ee6b31319d797 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 23 Jan 2016 02:55:12 -0800 Subject: [PATCH] Make hasShadow work on Windows/Linux --- atom/browser/native_window.cc | 11 ++++------- atom/browser/native_window.h | 4 ++-- atom/browser/native_window_mac.mm | 6 ------ atom/browser/native_window_views.cc | 18 +++++++++++++----- atom/browser/native_window_views.h | 2 ++ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 7d0ae5a..73370d2 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -125,6 +125,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { if (options.Get(options::kMovable, &movable) && movable) { SetMovable(movable); } + bool has_shadow; + if (options.Get(options::kHasShadow, &has_shadow)) { + SetHasShadow(has_shadow); + } bool top; if (options.Get(options::kAlwaysOnTop, &top) && top) { SetAlwaysOnTop(true); @@ -555,13 +559,6 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, callback.Run(bitmap); } -void NativeWindow::SetHasShadow(bool has_shadow) { -} - -bool NativeWindow::HasShadow() { - return true; -} - SkColor NativeWindow::ParseHexColor(const std::string& name) { SkColor result = 0xFF000000; unsigned value = 0; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 2b715e6..ea5f063 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -145,8 +145,8 @@ class NativeWindow : public base::SupportsUserData, virtual void SetKiosk(bool kiosk) = 0; virtual bool IsKiosk() = 0; virtual void SetBackgroundColor(const std::string& color_name) = 0; - virtual void SetHasShadow(bool has_shadow); - virtual bool HasShadow(); + virtual void SetHasShadow(bool has_shadow) = 0; + virtual bool HasShadow() = 0; virtual void SetRepresentedFilename(const std::string& filename); virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index e989ad9..a5dd284 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -449,12 +449,6 @@ NativeWindowMac::NativeWindowMac( if (!has_frame()) [window_ setOpaque:NO]; - bool has_shadow = true; - options.Get(options::kHasShadow, &has_shadow); - if (!has_shadow) { - SetHasShadow(false); - } - // We will manage window's lifetime ourselves. [window_ setReleasedWhenClosed:NO]; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 216a76e..9244a32 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -155,6 +155,11 @@ NativeWindowViews::NativeWindowViews( if (transparent()) params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; + // The given window is most likely not rectangular since it uses + // transparency and has no standard frame, don't show a shadow for it. + if (transparent() && !has_frame()) + params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE; + #if defined(OS_WIN) params.native_widget = new views::DesktopNativeWidgetAura(window_.get()); @@ -259,11 +264,6 @@ NativeWindowViews::NativeWindowViews( window_->FrameTypeChanged(); } - // The given window is most likely not rectangular since it uses - // transparency and has no standard frame, don't show a shadow for it. - if (transparent() && !has_frame()) - wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE); - gfx::Size size = bounds.size(); if (has_frame() && options.Get(options::kUseContentSize, &use_content_size_) && @@ -597,6 +597,14 @@ void NativeWindowViews::SetBackgroundColor(const std::string& color_name) { #endif } +void NativeWindowViews::SetHasShadow(bool has_shadow) { + wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE); +} + +bool NativeWindowViews::HasShadow() { + return wm::GetShadowType(GetNativeWindow()) != wm::SHADOW_TYPE_NONE; +} + void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) { if (menu_model == nullptr) { // Remove accelerators diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 61d0f95..934f2aa 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -88,6 +88,8 @@ class NativeWindowViews : public NativeWindow, void SetKiosk(bool kiosk) override; bool IsKiosk() override; void SetBackgroundColor(const std::string& color_name) override; + void SetHasShadow(bool has_shadow) override; + bool HasShadow() override; void SetMenu(ui::MenuModel* menu_model) override; gfx::NativeWindow GetNativeWindow() override; void SetOverlayIcon(const gfx::Image& overlay, -- 2.7.4