Add SetVisibleOnAllWorkspaces/IsVisibleOnAllWorkspaces API.

These two APIs are only available on OS X/Linux platforms.
This commit is contained in:
Haojian Wu 2015-03-26 14:18:37 +08:00
parent 1804466334
commit 476b61322f
8 changed files with 74 additions and 0 deletions

View file

@ -424,6 +424,16 @@ void Window::ShowDefinitionForSelection() {
} }
#endif #endif
#if defined(OS_MACOSX) || defined(OS_LINUX)
void Window::SetVisibleOnAllWorkspaces(bool visible) {
return window_->SetVisibleOnAllWorkspaces(visible);
}
bool Window::IsVisibleOnAllWorkspaces() {
return window_->IsVisibleOnAllWorkspaces();
}
#endif
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const { mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
return WebContents::CreateFrom(isolate, window_->GetWebContents()); return WebContents::CreateFrom(isolate, window_->GetWebContents());
} }
@ -494,6 +504,12 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide) .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
.SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility) .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
.SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible) .SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
#if defined(OS_MACOSX) || defined(OS_LINUX)
.SetMethod("setVisibleOnAllWorkspaces",
&Window::SetVisibleOnAllWorkspaces)
.SetMethod("isVisibleOnAllWorkspaces",
&Window::IsVisibleOnAllWorkspaces)
#endif
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
.SetMethod("showDefinitionForSelection", .SetMethod("showDefinitionForSelection",
&Window::ShowDefinitionForSelection) &Window::ShowDefinitionForSelection)

View file

@ -130,6 +130,11 @@ class Window : public mate::EventEmitter,
void ShowDefinitionForSelection(); void ShowDefinitionForSelection();
#endif #endif
#if defined(OS_MACOSX) || defined(OS_LINUX)
void SetVisibleOnAllWorkspaces(bool visible);
bool IsVisibleOnAllWorkspaces();
#endif
// APIs for WebContents. // APIs for WebContents.
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const; mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const; mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;

View file

@ -280,6 +280,13 @@ bool NativeWindow::IsMenuBarVisible() {
return true; return true;
} }
void NativeWindow::SetVisibleOnAllWorkspaces(bool visible) {
}
bool NativeWindow::IsVisibleOnAllWorkspaces() {
return false;
}
bool NativeWindow::HasModalDialog() { bool NativeWindow::HasModalDialog() {
return has_dialog_attached_; return has_dialog_attached_;
} }

View file

@ -172,6 +172,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void SetMenuBarVisibility(bool visible); virtual void SetMenuBarVisibility(bool visible);
virtual bool IsMenuBarVisible(); virtual bool IsMenuBarVisible();
// Visible on all workspaces.
virtual void SetVisibleOnAllWorkspaces(bool visible);
virtual bool IsVisibleOnAllWorkspaces();
// The same with closing a tab in a real browser. // The same with closing a tab in a real browser.
// //
// Should be called by platform code when user want to close the window. // Should be called by platform code when user want to close the window.

View file

@ -77,6 +77,9 @@ class NativeWindowMac : public NativeWindow {
const std::string& description) override; const std::string& description) override;
void ShowDefinitionForSelection() override; void ShowDefinitionForSelection() override;
void SetVisibleOnAllWorkspaces(bool visible) override;
bool IsVisibleOnAllWorkspaces() override;
// Returns true if |point| in local Cocoa coordinate system falls within // Returns true if |point| in local Cocoa coordinate system falls within
// the draggable region. // the draggable region.
bool IsWithinDraggableRegion(NSPoint point) const; bool IsWithinDraggableRegion(NSPoint point) const;
@ -112,6 +115,8 @@ class NativeWindowMac : public NativeWindow {
bool is_kiosk_; bool is_kiosk_;
bool is_visible_on_all_workspaces_;
NSInteger attention_request_id_; // identifier from requestUserAttention NSInteger attention_request_id_; // identifier from requestUserAttention
// The presentation options before entering kiosk mode. // The presentation options before entering kiosk mode.

View file

@ -310,6 +310,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
const mate::Dictionary& options) const mate::Dictionary& options)
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
is_kiosk_(false), is_kiosk_(false),
is_visible_on_all_workspaces_(false),
attention_request_id_(0) { attention_request_id_(0) {
int width = 800, height = 600; int width = 800, height = 600;
options.Get(switches::kWidth, &width); options.Get(switches::kWidth, &width);
@ -692,6 +693,21 @@ void NativeWindowMac::ShowDefinitionForSelection() {
rwhv->ShowDefinitionForSelection(); rwhv->ShowDefinitionForSelection();
} }
void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) {
NSUInteger collectionBehavior = [window_ collectionBehavior];
is_visible_on_all_workspaces_ = visible;
if (visible) {
collectionBehavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
} else {
collectionBehavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces;
}
[window_ setCollectionBehavior:collectionBehavior];
}
bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
return is_visible_on_all_workspaces_;
}
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const { bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
if (!draggable_region_) if (!draggable_region_)
return false; return false;

View file

@ -150,6 +150,9 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
menu_bar_autohide_(false), menu_bar_autohide_(false),
menu_bar_visible_(false), menu_bar_visible_(false),
menu_bar_alt_pressed_(false), menu_bar_alt_pressed_(false),
#if defined(OS_LINUX)
is_visible_on_all_workspaces_(false),
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
is_minimized_(false), is_minimized_(false),
#endif #endif
@ -674,6 +677,15 @@ bool NativeWindowViews::IsMenuBarVisible() {
return menu_bar_visible_; return menu_bar_visible_;
} }
void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) {
is_visible_on_all_workspaces_ = visible;
window_->SetVisibleOnAllWorkspaces(visible);
}
bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
return is_visible_on_all_workspaces_;
}
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
} }

View file

@ -81,6 +81,11 @@ class NativeWindowViews : public NativeWindow,
void SetMenuBarVisibility(bool visible) override; void SetMenuBarVisibility(bool visible) override;
bool IsMenuBarVisible() override; bool IsMenuBarVisible() override;
#if defined(OS_LINUX)
void SetVisibleOnAllWorkspaces(bool visible) override;
bool IsVisibleOnAllWorkspaces() override;
#endif
gfx::AcceleratedWidget GetAcceleratedWidget(); gfx::AcceleratedWidget GetAcceleratedWidget();
SkRegion* draggable_region() const { return draggable_region_.get(); } SkRegion* draggable_region() const { return draggable_region_.get(); }
@ -149,6 +154,10 @@ class NativeWindowViews : public NativeWindow,
bool menu_bar_visible_; bool menu_bar_visible_;
bool menu_bar_alt_pressed_; bool menu_bar_alt_pressed_;
#if defined(OS_LINUX)
bool is_visible_on_all_workspaces_;
#endif
#if defined(USE_X11) #if defined(USE_X11)
scoped_ptr<GlobalMenuBarX11> global_menu_bar_; scoped_ptr<GlobalMenuBarX11> global_menu_bar_;