Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm

Issue 1105613002: [MacViews] Implement AlwaysOnTop and VisibleOnAllWorkspaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/mac/nswindow_frame_controls.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 using extensions::AppWindow; 45 using extensions::AppWindow;
46 46
47 @interface NSWindow (NSPrivateApis) 47 @interface NSWindow (NSPrivateApis)
48 - (void)setBottomCornerRounded:(BOOL)rounded; 48 - (void)setBottomCornerRounded:(BOOL)rounded;
49 - (BOOL)_isTitleHidden; 49 - (BOOL)_isTitleHidden;
50 @end 50 @end
51 51
52 namespace { 52 namespace {
53 53
54 void SetWorkspacesCollectionBehavior(NSWindow* window, bool always_visible) {
55 NSWindowCollectionBehavior behavior = [window collectionBehavior];
56 if (always_visible)
57 behavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
58 else
59 behavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces;
60 [window setCollectionBehavior:behavior];
61 }
62
63 void InitCollectionBehavior(NSWindow* window) {
64 // Since always-on-top windows have a higher window level
65 // than NSNormalWindowLevel, they will default to
66 // NSWindowCollectionBehaviorTransient. Set the value
67 // explicitly here to match normal windows.
68 NSWindowCollectionBehavior behavior = [window collectionBehavior];
69 behavior |= NSWindowCollectionBehaviorManaged;
70 [window setCollectionBehavior:behavior];
71 }
72
73 // Returns the level for windows that are configured to be always on top.
74 // This is not a constant because NSFloatingWindowLevel is a macro defined
75 // as a function call.
76 NSInteger AlwaysOnTopWindowLevel() {
77 return NSFloatingWindowLevel;
78 }
79
80 NSRect GfxToCocoaBounds(gfx::Rect bounds) { 54 NSRect GfxToCocoaBounds(gfx::Rect bounds) {
81 typedef AppWindow::BoundsSpecification BoundsSpecification; 55 typedef AppWindow::BoundsSpecification BoundsSpecification;
82 56
83 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; 57 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
84 58
85 // If coordinates are unspecified, center window on primary screen. 59 // If coordinates are unspecified, center window on primary screen.
86 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition) 60 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition)
87 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2)); 61 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2));
88 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition) 62 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition)
89 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2)); 63 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2));
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 [titlebar_background_view_ 325 [titlebar_background_view_
352 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) 326 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_)
353 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; 327 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)];
354 } 328 }
355 329
356 if (base::mac::IsOSSnowLeopard() && 330 if (base::mac::IsOSSnowLeopard() &&
357 [window respondsToSelector:@selector(setBottomCornerRounded:)]) 331 [window respondsToSelector:@selector(setBottomCornerRounded:)])
358 [window setBottomCornerRounded:NO]; 332 [window setBottomCornerRounded:NO];
359 333
360 if (params.always_on_top) 334 if (params.always_on_top)
361 [window setLevel:AlwaysOnTopWindowLevel()]; 335 gfx::SetNSWindowAlwaysOnTop(window, true);
362 InitCollectionBehavior(window);
363 336
364 SetWorkspacesCollectionBehavior(window, params.visible_on_all_workspaces); 337 gfx::SetNSWindowVisibleOnAllWorkspaces(window,
338 params.visible_on_all_workspaces);
365 339
366 window_controller_.reset( 340 window_controller_.reset(
367 [[NativeAppWindowController alloc] initWithWindow:window.release()]); 341 [[NativeAppWindowController alloc] initWithWindow:window.release()]);
368 342
369 NSView* view = WebContents()->GetNativeView(); 343 NSView* view = WebContents()->GetNativeView();
370 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 344 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
371 345
372 InstallView(); 346 InstallView();
373 347
374 [[window_controller_ window] setDelegate:window_controller_]; 348 [[window_controller_ window] setDelegate:window_controller_];
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } 676 }
703 677
704 void NativeAppWindowCocoa::FlashFrame(bool flash) { 678 void NativeAppWindowCocoa::FlashFrame(bool flash) {
705 apps::ExtensionAppShimHandler::RequestUserAttentionForWindow( 679 apps::ExtensionAppShimHandler::RequestUserAttentionForWindow(
706 app_window_, 680 app_window_,
707 flash ? apps::APP_SHIM_ATTENTION_CRITICAL 681 flash ? apps::APP_SHIM_ATTENTION_CRITICAL
708 : apps::APP_SHIM_ATTENTION_CANCEL); 682 : apps::APP_SHIM_ATTENTION_CANCEL);
709 } 683 }
710 684
711 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { 685 bool NativeAppWindowCocoa::IsAlwaysOnTop() const {
712 return [window() level] == AlwaysOnTopWindowLevel(); 686 return gfx::IsNSWindowAlwaysOnTop(window());
713 } 687 }
714 688
715 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) { 689 void NativeAppWindowCocoa::RenderViewCreated(content::RenderViewHost* rvh) {
716 if (IsActive()) 690 if (IsActive())
717 WebContents()->RestoreFocus(); 691 WebContents()->RestoreFocus();
718 } 692 }
719 693
720 bool NativeAppWindowCocoa::IsFrameless() const { 694 bool NativeAppWindowCocoa::IsFrameless() const {
721 return !has_frame_; 695 return !has_frame_;
722 } 696 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 is_resizable_ && !size_constraints_.HasFixedSize(); 890 is_resizable_ && !size_constraints_.HasFixedSize();
917 shows_fullscreen_controls_ = 891 shows_fullscreen_controls_ =
918 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_; 892 is_resizable_ && !size_constraints_.HasMaximumSize() && has_frame_;
919 893
920 gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size, 894 gfx::ApplyNSWindowSizeConstraints(window(), min_size, max_size,
921 shows_resize_controls_, 895 shows_resize_controls_,
922 shows_fullscreen_controls_); 896 shows_fullscreen_controls_);
923 } 897 }
924 898
925 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) { 899 void NativeAppWindowCocoa::SetAlwaysOnTop(bool always_on_top) {
926 [window() setLevel:(always_on_top ? AlwaysOnTopWindowLevel() : 900 gfx::SetNSWindowAlwaysOnTop(window(), always_on_top);
927 NSNormalWindowLevel)];
928 } 901 }
929 902
930 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) { 903 void NativeAppWindowCocoa::SetVisibleOnAllWorkspaces(bool always_visible) {
931 SetWorkspacesCollectionBehavior(window(), always_visible); 904 gfx::SetNSWindowVisibleOnAllWorkspaces(window(), always_visible);
932 } 905 }
933 906
934 void NativeAppWindowCocoa::SetInterceptAllKeys(bool want_all_key) { 907 void NativeAppWindowCocoa::SetInterceptAllKeys(bool want_all_key) {
935 // TODO(sriramsr): implement for OSX (http://crbug.com/166928). 908 // TODO(sriramsr): implement for OSX (http://crbug.com/166928).
936 NOTIMPLEMENTED(); 909 NOTIMPLEMENTED();
937 } 910 }
938 911
939 NativeAppWindowCocoa::~NativeAppWindowCocoa() { 912 NativeAppWindowCocoa::~NativeAppWindowCocoa() {
940 } 913 }
941 914
942 AppNSWindow* NativeAppWindowCocoa::window() const { 915 AppNSWindow* NativeAppWindowCocoa::window() const {
943 NSWindow* window = [window_controller_ window]; 916 NSWindow* window = [window_controller_ window];
944 CHECK(!window || [window isKindOfClass:[AppNSWindow class]]); 917 CHECK(!window || [window isKindOfClass:[AppNSWindow class]]);
945 return static_cast<AppNSWindow*>(window); 918 return static_cast<AppNSWindow*>(window);
946 } 919 }
947 920
948 content::WebContents* NativeAppWindowCocoa::WebContents() const { 921 content::WebContents* NativeAppWindowCocoa::WebContents() const {
949 return app_window_->web_contents(); 922 return app_window_->web_contents();
950 } 923 }
951 924
952 void NativeAppWindowCocoa::UpdateRestoredBounds() { 925 void NativeAppWindowCocoa::UpdateRestoredBounds() {
953 if (IsRestored(*this)) 926 if (IsRestored(*this))
954 restored_bounds_ = [window() frame]; 927 restored_bounds_ = [window() frame];
955 } 928 }
956 929
957 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { 930 void NativeAppWindowCocoa::HideWithoutMarkingHidden() {
958 [window() orderOut:window_controller_]; 931 [window() orderOut:window_controller_];
959 } 932 }
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/mac/nswindow_frame_controls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698