Skip to content

Commit

Permalink
[API] Implement Window.toggleKioskMode() and Window.toggleFullscreen().
Browse files Browse the repository at this point in the history
Also add properties isFullscreen and isKioskMode for Window. Fix #125
  • Loading branch information
zhchbin committed Nov 22, 2012
1 parent ccd132a commit 9d1d39d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/api/window/window.cc
Expand Up @@ -64,10 +64,14 @@ void Window::Call(const std::string& method,
shell_->window()->SetFullscreen(true);
} else if (method == "LeaveFullscreen") {
shell_->window()->SetFullscreen(false);
} else if (method == "ToggleFullscreen") {
shell_->window()->SetFullscreen(!shell_->window()->IsFullscreen());
} else if (method == "EnterKioskMode") {
shell_->window()->SetKiosk(true);
} else if (method == "LeaveKioskMode") {
shell_->window()->SetKiosk(false);
} else if (method == "ToggleKioskMode") {
shell_->window()->SetKiosk(!shell_->window()->IsFullscreen());
} else if (method == "ShowDevTools") {
shell_->ShowDevTools();
} else if (method == "SetMaximumSize") {
Expand Down Expand Up @@ -97,7 +101,20 @@ void Window::Call(const std::string& method,
if (arguments.GetInteger(0, &id))
shell_->window()->SetMenu(dispatcher_host()->GetObject<Menu>(id));
} else {
NOTREACHED() << "Invalid call to Clipboard method:" << method
NOTREACHED() << "Invalid call to Window method:" << method
<< " arguments:" << arguments;
}
}

void Window::CallSync(const std::string& method,
const base::ListValue& arguments,
base::ListValue* result) {
if (method == "IsFullscreen") {
result->AppendBoolean(shell_->window()->IsFullscreen());
} else if (method == "IsKioskMode") {
result->AppendBoolean(shell_->window()->IsKiosk());
} else {
NOTREACHED() << "Invalid call to Window method:" << method
<< " arguments:" << arguments;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/api/window/window.h
Expand Up @@ -39,7 +39,9 @@ class Window : public Base {

virtual void Call(const std::string& method,
const base::ListValue& arguments) OVERRIDE;

virtual void CallSync(const std::string& method,
const base::ListValue& arguments,
base::ListValue* result) OVERRIDE;
private:
content::Shell* shell_;

Expand Down
18 changes: 18 additions & 0 deletions src/api/window/window.js
Expand Up @@ -78,6 +78,16 @@ Window.prototype.__defineGetter__('menu', function() {
return this.getHiddenValue('menu');
});

Window.prototype.__defineGetter__('isFullscreen', function() {
var result = nw.callObjectMethodSync(this, 'IsFullscreen', []);
return Boolean(result[0]);
});

Window.prototype.__defineGetter__('isKioskMode', function() {
var result = nw.callObjectMethodSync(this, 'IsKioskMode', []);
return Boolean(result[0]);
});

Window.prototype.moveTo = function(x, y) {
window.moveTo(x, y);
}
Expand Down Expand Up @@ -144,6 +154,10 @@ Window.prototype.leaveFullscreen = function() {
nw.callObjectMethod(this, 'LeaveFullscreen', []);
}

Window.prototype.toggleFullscreen = function() {
nw.callObjectMethod(this, 'ToggleFullscreen', []);
}

Window.prototype.enterKioskMode = function() {
nw.callObjectMethod(this, 'EnterKioskMode', []);
}
Expand All @@ -152,6 +166,10 @@ Window.prototype.leaveKioskMode = function() {
nw.callObjectMethod(this, 'LeaveKioskMode', []);
}

Window.prototype.toggleKioskMode = function() {
nw.callObjectMethod(this, 'ToggleKioskMode', []);
}

Window.prototype.showDevTools = function() {
nw.callObjectMethod(this, 'ShowDevTools', []);
}
Expand Down
2 changes: 2 additions & 0 deletions src/browser/native_window.h
Expand Up @@ -72,6 +72,7 @@ class NativeWindow {
virtual void Minimize() = 0;
virtual void Restore() = 0;
virtual void SetFullscreen(bool fullscreen) = 0;
virtual bool IsFullscreen() = 0;
virtual void SetMinimumSize(int width, int height) = 0;
virtual void SetMaximumSize(int width, int height) = 0;
virtual void SetResizable(bool resizable) = 0;
Expand All @@ -80,6 +81,7 @@ class NativeWindow {
virtual void SetTitle(const std::string& title) = 0;
virtual void FlashFrame(bool flash) = 0;
virtual void SetKiosk(bool kiosk) = 0;
virtual bool IsKiosk() = 0;
virtual void SetMenu(api::Menu* menu) = 0;

// Toolbar related controls.
Expand Down
8 changes: 8 additions & 0 deletions src/browser/native_window_gtk.cc
Expand Up @@ -180,6 +180,10 @@ void NativeWindowGtk::SetFullscreen(bool fullscreen) {
gtk_window_unfullscreen(window_);
}

bool NativeWindowGtk::IsFullscreen() {
return content_thinks_its_fullscreen_;
}

void NativeWindowGtk::SetMinimumSize(int width, int height) {
GdkGeometry geometry = { 0 };
geometry.min_width = width;
Expand Down Expand Up @@ -233,6 +237,10 @@ void NativeWindowGtk::SetKiosk(bool kiosk) {
SetFullscreen(kiosk);
}

bool NativeWindowGtk::IsKiosk() {
return IsFullscreen();
}

void NativeWindowGtk::SetMenu(api::Menu* menu) {
gtk_box_pack_start(GTK_BOX(vbox_), menu->menu_, FALSE, FALSE, 0);
gtk_box_reorder_child(GTK_BOX(vbox_), menu->menu_, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/browser/native_window_gtk.h
Expand Up @@ -46,6 +46,7 @@ class NativeWindowGtk : public NativeWindow {
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreen() OVERRIDE;
virtual void SetMinimumSize(int width, int height) OVERRIDE;
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
Expand All @@ -54,6 +55,7 @@ class NativeWindowGtk : public NativeWindow {
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual void FlashFrame(bool flash) OVERRIDE;
virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE;
virtual void SetMenu(api::Menu* menu) OVERRIDE;
virtual void SetToolbarButtonEnabled(TOOLBAR_BUTTON button,
bool enabled) OVERRIDE;
Expand Down
3 changes: 3 additions & 0 deletions src/browser/native_window_mac.h
Expand Up @@ -50,6 +50,7 @@ class NativeWindowCocoa : public NativeWindow {
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreen() OVERRIDE;
virtual void SetMinimumSize(int width, int height) OVERRIDE;
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
Expand All @@ -58,6 +59,7 @@ class NativeWindowCocoa : public NativeWindow {
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual void FlashFrame(bool flash) OVERRIDE;
virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE;
virtual void SetMenu(api::Menu* menu) OVERRIDE;
virtual void SetToolbarButtonEnabled(TOOLBAR_BUTTON button,
bool enabled) OVERRIDE;
Expand Down Expand Up @@ -100,6 +102,7 @@ class NativeWindowCocoa : public NativeWindow {
scoped_nsobject<ShellToolbarDelegate> toolbar_delegate_;

bool is_fullscreen_;
bool is_kiosk_;
NSRect restored_bounds_;

NSInteger attention_request_id_; // identifier from requestUserAttention
Expand Down
10 changes: 10 additions & 0 deletions src/browser/native_window_mac.mm
Expand Up @@ -411,6 +411,10 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
SetNonLionFullscreen(fullscreen);
}

bool NativeWindowCocoa::IsFullscreen() {
return is_fullscreen_;
}

void NativeWindowCocoa::SetNonLionFullscreen(bool fullscreen) {
if (fullscreen == is_fullscreen_)
return;
Expand Down Expand Up @@ -520,13 +524,19 @@ - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
NSApplicationPresentationDisableSessionTermination +
NSApplicationPresentationDisableHideApplication;
[NSApp setPresentationOptions:options];
is_kiosk_ = ture;
SetNonLionFullscreen(true);
} else {
[NSApp setPresentationOptions:[NSApp currentSystemPresentationOptions]];
is_kiosk_ = false;
SetNonLionFullscreen(false);
}
}

bool NativeWindowCocoa::IsKiosk() {
return is_kiosk_;
}

void NativeWindowCocoa::SetMenu(api::Menu* menu) {
StandardMenusMac standard_menus(shell_->GetPackage()->GetName());
[NSApp setMainMenu:menu->menu_];
Expand Down
8 changes: 8 additions & 0 deletions src/browser/native_window_win.cc
Expand Up @@ -312,6 +312,10 @@ void NativeWindowWin::SetFullscreen(bool fullscreen) {
shell()->SendEvent("leave-fullscreen");
}

bool NativeWindowWin::IsFullscreen() {
return is_fullscreen_;
}

void NativeWindowWin::SetMinimumSize(int width, int height) {
minimum_size_.set_width(width);
minimum_size_.set_height(height);
Expand Down Expand Up @@ -353,6 +357,10 @@ void NativeWindowWin::SetKiosk(bool kiosk) {
SetFullscreen(kiosk);
}

bool NativeWindowWin::IsKiosk() {
return IsFullscreen();
}

void NativeWindowWin::SetMenu(api::Menu* menu) {
window_->set_has_menu_bar(true);
menu_ = menu;
Expand Down
2 changes: 2 additions & 0 deletions src/browser/native_window_win.h
Expand Up @@ -60,6 +60,7 @@ class NativeWindowWin : public NativeWindow,
virtual void Minimize() OVERRIDE;
virtual void Restore() OVERRIDE;
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
virtual bool IsFullscreen() OVERRIDE;
virtual void SetMinimumSize(int width, int height) OVERRIDE;
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
Expand All @@ -68,6 +69,7 @@ class NativeWindowWin : public NativeWindow,
virtual void SetTitle(const std::string& title) OVERRIDE;
virtual void FlashFrame(bool flash) OVERRIDE;
virtual void SetKiosk(bool kiosk) OVERRIDE;
virtual bool IsKiosk() OVERRIDE;
virtual void SetMenu(api::Menu* menu) OVERRIDE;
virtual void SetToolbarButtonEnabled(TOOLBAR_BUTTON button,
bool enabled) OVERRIDE;
Expand Down

0 comments on commit 9d1d39d

Please sign in to comment.