Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / apps / native_app_window_cocoa.mm
index 11428d8..a14edf7 100644 (file)
@@ -4,12 +4,12 @@
 
 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
 
-#include "apps/app_shim/extension_app_shim_handler_mac.h"
 #include "base/command_line.h"
 #include "base/mac/foundation_util.h"
 #include "base/mac/mac_util.h"
 #include "base/mac/sdk_forward_declarations.h"
 #include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/ui/cocoa/browser_window_utils.h"
 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
@@ -42,7 +42,7 @@
 // windowWillUseStandardFrame, as the window would not restore back to the
 // desired size.
 
-using apps::AppWindow;
+using extensions::AppWindow;
 
 @interface NSWindow (NSPrivateApis)
 - (void)setBottomCornerRounded:(BOOL)rounded;
@@ -60,6 +60,15 @@ void SetFullScreenCollectionBehavior(NSWindow* window, bool allow_fullscreen) {
   [window setCollectionBehavior:behavior];
 }
 
+void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) {
+  NSWindowCollectionBehavior behavior = [window collectionBehavior];
+  if (always_visible)
+    behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
+  else
+    behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces;
+  [window setCollectionBehavior:behavior];
+}
+
 void InitCollectionBehavior(NSWindow* window) {
   // Since always-on-top windows have a higher window level
   // than NSNormalWindowLevel, they will default to
@@ -78,7 +87,7 @@ NSInteger AlwaysOnTopWindowLevel() {
 }
 
 NSRect GfxToCocoaBounds(gfx::Rect bounds) {
-  typedef apps::AppWindow::BoundsSpecification BoundsSpecification;
+  typedef AppWindow::BoundsSpecification BoundsSpecification;
 
   NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
 
@@ -205,7 +214,7 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
 - (CGFloat)roundedCornerRadius;
 @end
 
-// TODO(jamescook): Should these be AppNSWindow to match apps::AppWindow?
+// TODO(jamescook): Should these be AppNSWindow to match AppWindow?
 // http://crbug.com/344082
 @interface ShellNSWindow : ChromeEventProcessingWindow
 @end
@@ -337,8 +346,7 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
       shows_fullscreen_controls_(true),
       has_frame_color_(params.has_frame_color),
       active_frame_color_(params.active_frame_color),
-      inactive_frame_color_(params.inactive_frame_color),
-      attention_request_id_(0) {
+      inactive_frame_color_(params.inactive_frame_color) {
   Observe(WebContents());
 
   base::scoped_nsobject<NSWindow> window;
@@ -380,6 +388,8 @@ NativeAppWindowCocoa::NativeAppWindowCocoa(
     [window setLevel:AlwaysOnTopWindowLevel()];
   InitCollectionBehavior(window);
 
+  SetWorkspacesCollectionBehavior(window, params.visible_on_all_workspaces);
+
   window_controller_.reset(
       [[NativeAppWindowController alloc] initWithWindow:window.release()]);
 
@@ -531,10 +541,6 @@ bool NativeAppWindowCocoa::IsFullscreenOrPending() const {
   return is_fullscreen_;
 }
 
-bool NativeAppWindowCocoa::IsDetached() const {
-  return false;
-}
-
 gfx::NativeWindow NativeAppWindowCocoa::GetNativeWindow() {
   return window();
 }
@@ -569,7 +575,7 @@ void NativeAppWindowCocoa::Show() {
   if (is_hidden_with_app_) {
     // If there is a shim to gently request attention, return here. Otherwise
     // show the window as usual.
-    if (apps::ExtensionAppShimHandler::RequestUserAttentionForWindow(
+    if (apps::ExtensionAppShimHandler::ActivateAndRequestUserAttentionForWindow(
             app_window_)) {
       return;
     }
@@ -728,12 +734,10 @@ void NativeAppWindowCocoa::UpdateDraggableRegionViews() {
 }
 
 void NativeAppWindowCocoa::FlashFrame(bool flash) {
-  if (flash) {
-    attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
-  } else {
-    [NSApp cancelUserAttentionRequest:attention_request_id_];
-    attention_request_id_ = 0;
-  }
+  apps::ExtensionAppShimHandler::RequestUserAttentionForWindow(
+      app_window_,
+      flash ? apps::APP_SHIM_ATTENTION_CRITICAL
+            : apps::APP_SHIM_ATTENTION_CANCEL);
 }
 
 bool NativeAppWindowCocoa::IsAlwaysOnTop() const {
@@ -939,7 +943,7 @@ void NativeAppWindowCocoa::SetContentSizeConstraints(
                                          minimum_size.height())];
 
   gfx::Size maximum_size = size_constraints_.GetMaximumSize();
-  const int kUnboundedSize = apps::SizeConstraints::kUnboundedSize;
+  const int kUnboundedSize = extensions::SizeConstraints::kUnboundedSize;
   CGFloat max_width = maximum_size.width() == kUnboundedSize ?
       CGFLOAT_MAX : maximum_size.width();
   CGFloat max_height = maximum_size.height() == kUnboundedSize ?
@@ -974,6 +978,10 @@ void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) {
                                       NSNormalWindowLevel)];
 }
 
+void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) {
+  SetWorkspacesCollectionBehavior(window(), always_visible);
+}
+
 NativeAppWindowCocoa::~NativeAppWindowCocoa() {
 }