From: leethomas Date: Wed, 25 Jan 2017 04:08:08 +0000 (-0800) Subject: throw an error for out of bounds window levels X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f5518b91efad274e75000313727f936c4fbfbe8;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git throw an error for out of bounds window levels --- diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 44126cf..2f97a88 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -513,9 +513,16 @@ bool Window::IsClosable() { void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) { std::string level = "floating"; int relativeLevel = 0; + std::string error; + args->GetNext(&level); args->GetNext(&relativeLevel); - window_->SetAlwaysOnTop(top, level, relativeLevel); + + window_->SetAlwaysOnTop(top, level, relativeLevel, &error); + + if (!error.empty()) { + args->ThrowError(error); + } } bool Window::IsAlwaysOnTop() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 05c06df..6f2d525 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -120,7 +120,8 @@ class NativeWindow : public base::SupportsUserData, virtual bool IsClosable() = 0; virtual void SetAlwaysOnTop(bool top, const std::string& level = "floating", - int relativeLevel = 0) = 0; + int relativeLevel = 0, + std::string* error = nullptr) = 0; virtual bool IsAlwaysOnTop() = 0; virtual void Center() = 0; virtual void SetTitle(const std::string& title) = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 37786be..1860512 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -68,7 +68,7 @@ class NativeWindowMac : public NativeWindow, void SetClosable(bool closable) override; bool IsClosable() override; void SetAlwaysOnTop(bool top, const std::string& level, - int relativeLevel) override; + int relativeLevel, std::string* error) override; bool IsAlwaysOnTop() override; void Center() override; void SetTitle(const std::string& title) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 6962611..589accf 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1056,8 +1056,10 @@ bool NativeWindowMac::IsClosable() { return [window_ styleMask] & NSClosableWindowMask; } -void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel) { +void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel, + std::string* error) { int windowLevel = NSNormalWindowLevel; + CGWindowLevel maxWindowLevel = CGWindowLevelForKey(kCGMaximumWindowLevelKey); if (top) { if (level == "floating") { @@ -1081,10 +1083,12 @@ void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int rel } NSInteger newLevel = windowLevel + relativeLevel; - if (newLevel >= 0 && newLevel < CGWindowLevelForKey(kCGMaximumWindowLevelKey)) { + + if (newLevel >= 0 && newLevel <= maxWindowLevel) { [window_ setLevel:newLevel]; } else { - [window_ setLevel:windowLevel]; + *error = std::string([[NSString stringWithFormat: + @"relativeLevel must be between 0 and %d", maxWindowLevel] UTF8String]); } } diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index e13608f..16a10b3 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -683,7 +683,7 @@ bool NativeWindowViews::IsClosable() { } void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level, - int relativeLevel) { + int relativeLevel, std::string* error) { window_->SetAlwaysOnTop(top); } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index f70904b..a6a43b3 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -87,7 +87,7 @@ class NativeWindowViews : public NativeWindow, void SetClosable(bool closable) override; bool IsClosable() override; void SetAlwaysOnTop(bool top, const std::string& level, - int relativeLevel) override; + int relativeLevel, std::string& error) override; bool IsAlwaysOnTop() override; void Center() override; void SetTitle(const std::string& title) override;