Permalink
Browse files

Merge pull request #398 from zhchbin/issue251

[WIN][GTK]hide the window from task bar while keeping it shown
  • Loading branch information...
2 parents e0c9a02 + 51771f2 commit 0e186b4bd94e0514edb21fd2306260c0bdf5c3ff @rogerwang rogerwang committed Jan 29, 2013
View
@@ -101,6 +101,10 @@ void Window::Call(const std::string& method,
bool top;
if (arguments.GetBoolean(0, &top))
shell_->window()->SetAlwaysOnTop(top);
+ } else if (method == "SetShowInTaskbar" ) {
+ bool show;
+ if (arguments.GetBoolean(0, &show))
+ shell_->window()->SetShowInTaskbar(show);
} else if (method == "MoveTo") {
int x, y;
if (arguments.GetInteger(0, &x) &&
@@ -289,6 +289,11 @@ Window.prototype.setAlwaysOnTop = function(flag) {
CallObjectMethod(this, 'SetAlwaysOnTop', [ Boolean(flag) ]);
}
+Window.prototype.setShowInTaskbar = function(flag) {
+ flag = Boolean(flag);
+ CallObjectMethod(this, 'SetShowInTaskbar', [ flag ]);
+}
+
Window.prototype.requestAttention = function(flash) {
flash = Boolean(flash);
CallObjectMethod(this, 'RequestAttention', [ flash ]);
@@ -113,6 +113,11 @@ void NativeWindow::InitFromManifest(base::DictionaryValue* manifest) {
if (manifest->GetBoolean(switches::kmAlwaysOnTop, &top) && top) {
SetAlwaysOnTop(true);
}
+ bool showInTaskbar;
+ if (manifest->GetBoolean(switches::kmShowInTaskbar, &showInTaskbar) &&
+ !showInTaskbar) {
+ SetShowInTaskbar(false);
+ }
bool fullscreen;
if (manifest->GetBoolean(switches::kmFullscreen, &fullscreen) && fullscreen) {
SetFullscreen(true);
@@ -81,6 +81,7 @@ class NativeWindow {
virtual void SetMaximumSize(int width, int height) = 0;
virtual void SetResizable(bool resizable) = 0;
virtual void SetAlwaysOnTop(bool top) = 0;
+ virtual void SetShowInTaskbar(bool show = true) = 0;
virtual void SetPosition(const std::string& position) = 0;
virtual void SetPosition(const gfx::Point& position) = 0;
virtual gfx::Point GetPosition() = 0;
@@ -236,6 +236,10 @@ void NativeWindowGtk::SetAlwaysOnTop(bool top) {
gtk_window_set_keep_above(window_, top ? TRUE : FALSE);
}
+void NativeWindowGtk::SetShowInTaskbar(bool show) {
+ gtk_window_set_skip_taskbar_hint(window_, show ? FALSE : TRUE);
+}
+
void NativeWindowGtk::SetPosition(const std::string& position) {
if (position == "center")
gtk_window_set_position(window_, GTK_WIN_POS_CENTER);
@@ -53,6 +53,7 @@ class NativeWindowGtk : public NativeWindow {
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
+ virtual void SetShowInTaskbar(bool show = true) OVERRIDE;
virtual void SetPosition(const std::string& position) OVERRIDE;
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
virtual gfx::Point GetPosition() OVERRIDE;
@@ -20,8 +20,12 @@
#include "content/nw/src/browser/native_window_win.h"
+#include <shobjidl.h>
+
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "base/win/scoped_comptr.h"
+#include "base/win/windows_version.h"
#include "base/win/wrapped_window_proc.h"
#include "chrome/browser/platform_util.h"
#include "chrome/common/extensions/draggable_region.h"
@@ -347,6 +351,43 @@ void NativeWindowWin::SetResizable(bool resizable) {
::SetWindowLong(window_->GetNativeView(), GWL_STYLE, style);
}
+void NativeWindowWin::SetShowInTaskbar(bool show) {
+ if (show == false && base::win::GetVersion() < base::win::VERSION_VISTA) {
+ if (hidden_owner_window_.get() == NULL) {
+ hidden_owner_window_.reset(new HiddenOwnerWindow());
+ }
+
+ // Change the owner of native window. Only needed on Windows XP.
+ ::SetWindowLong(window_->GetNativeView(),
+ GWL_HWNDPARENT,
+ (LONG)hidden_owner_window_->hwnd());
+ }
+
+ base::win::ScopedComPtr<ITaskbarList> taskbar;
+ HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
+ CLSCTX_INPROC_SERVER);
+ if (FAILED(result)) {
+ VLOG(1) << "Failed creating a TaskbarList object: " << result;
+ return;
+ }
+
+ result = taskbar->HrInit();
+ if (FAILED(result)) {
+ LOG(ERROR) << "Failed initializing an ITaskbarList interface.";
+ return;
+ }
+
+ if (show)
+ result = taskbar->AddTab(window_->GetNativeWindow());
+ else
+ result = taskbar->DeleteTab(window_->GetNativeWindow());
+
+ if (FAILED(result)) {
+ LOG(ERROR) << "Failed to change the show in taskbar attribute";
+ return;
+ }
+}
+
void NativeWindowWin::SetAlwaysOnTop(bool top) {
window_->SetAlwaysOnTop(top);
}
@@ -24,6 +24,7 @@
#include "content/nw/src/browser/native_window.h"
#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/base/win/window_impl.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect.h"
#include "ui/views/focus/widget_focus_manager.h"
@@ -37,6 +38,31 @@ namespace nw {
class NativeWindowToolbarWin;
+///////////////////////////////////////////////////////////////////////////////
+//
+// HiddenOwnerWindow
+// This class is used as a hidden owner window for NativeWindowWin.
+// Note: The reason for using it is on Windows XP, while using the
+// ITaskbarList::DeleteTab to remove the icon from the taskbar, the icon will
+// appear in taskbar again when it blur and being focused again. This class
+// object will only exist on Windows XP. See the implementation about
+// |NativeWindowWin::SetShowInTaskbar|.
+//
+///////////////////////////////////////////////////////////////////////////////
+class HiddenOwnerWindow : public ui::WindowImpl {
+ public:
+ HiddenOwnerWindow() {
+ Init(NULL, gfx::Rect());
+ }
+
+ ~HiddenOwnerWindow() {
+ DestroyWindow(hwnd());
+ }
+
+ BEGIN_MSG_MAP_EX(HiddenOwnerWindow)
+ END_MSG_MAP()
+};
+
class NativeWindowWin : public NativeWindow,
public views::WidgetFocusChangeListener,
public views::WidgetDelegateView {
@@ -67,6 +93,7 @@ class NativeWindowWin : public NativeWindow,
virtual void SetMaximumSize(int width, int height) OVERRIDE;
virtual void SetResizable(bool resizable) OVERRIDE;
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
+ virtual void SetShowInTaskbar(bool show = true) OVERRIDE;
virtual void SetPosition(const std::string& position) OVERRIDE;
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
virtual gfx::Point GetPosition() OVERRIDE;
@@ -137,6 +164,10 @@ class NativeWindowWin : public NativeWindow,
scoped_ptr<SkRegion> draggable_region_;
+ // This is only useful on Windows XP. Hidden owner window for Windows XP to
+ // let SetShowInTaskbar work like on Windows 7.
+ scoped_ptr<HiddenOwnerWindow> hidden_owner_window_;
+
// The window's menubar.
api::Menu* menu_;
@@ -68,6 +68,9 @@ const char kmResizable[] = "resizable";
const char kmAsDesktop[] = "as_desktop";
const char kmFullscreen[] = "fullscreen";
+// Make windows icon hide show or hide in taskbar.
+const char kmShowInTaskbar[] = "show_in_taskbar";
+
// Start with the kiosk mode, see Opera's page for description:
// http://www.opera.com/support/mastering/kiosk/
const char kmKiosk[] = "kiosk";
@@ -43,6 +43,7 @@ extern const char kmMaxHeight[];
extern const char kmResizable[];
extern const char kmAsDesktop[];
extern const char kmFullscreen[];
+extern const char kmShowInTaskbar[];
extern const char kmKiosk[];
extern const char kmAlwaysOnTop[];

0 comments on commit 0e186b4

Please sign in to comment.