OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/panels/panel_window_controller_cocoa.h" | 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 else | 1013 else |
1014 [NSApp deactivate]; | 1014 [NSApp deactivate]; |
1015 } | 1015 } |
1016 | 1016 |
1017 - (void)preventBecomingKeyWindow:(BOOL)prevent { | 1017 - (void)preventBecomingKeyWindow:(BOOL)prevent { |
1018 canBecomeKeyWindow_ = !prevent; | 1018 canBecomeKeyWindow_ = !prevent; |
1019 } | 1019 } |
1020 | 1020 |
1021 - (void)fullScreenModeChanged:(bool)isFullScreen { | 1021 - (void)fullScreenModeChanged:(bool)isFullScreen { |
1022 [self updateWindowLevel]; | 1022 [self updateWindowLevel]; |
1023 | |
1024 // The full-screen window is in normal level and changing the panel window to | |
1025 // same normal level will not move it below the full-screen window. Thus we | |
1026 // need to reorder the panel window. | |
1027 if (isFullScreen) | |
1028 [[self window] orderBack:nil]; | |
1029 else | |
1030 [[self window] orderFrontRegardless]; | |
1031 } | 1023 } |
1032 | 1024 |
1033 - (BOOL)canBecomeKeyWindow { | 1025 - (BOOL)canBecomeKeyWindow { |
1034 // Panel can only gain focus if it is expanded. Minimized panels do not | 1026 // Panel can only gain focus if it is expanded. Minimized panels do not |
1035 // participate in Cmd-~ rotation. | 1027 // participate in Cmd-~ rotation. |
1036 // TODO(dimich): If it will be ever desired to expand/focus the Panel on | 1028 // TODO(dimich): If it will be ever desired to expand/focus the Panel on |
1037 // keyboard navigation or via main menu, the care should be taken to avoid | 1029 // keyboard navigation or via main menu, the care should be taken to avoid |
1038 // cases when minimized Panel is getting keyboard input, invisibly. | 1030 // cases when minimized Panel is getting keyboard input, invisibly. |
1039 return canBecomeKeyWindow_; | 1031 return canBecomeKeyWindow_; |
1040 } | 1032 } |
1041 | 1033 |
1042 - (int)numPanels { | 1034 - (int)numPanels { |
1043 return windowShim_->panel()->manager()->num_panels(); | 1035 return windowShim_->panel()->manager()->num_panels(); |
1044 } | 1036 } |
1045 | 1037 |
1046 - (BOOL)activationRequestedByBrowser { | 1038 - (BOOL)activationRequestedByBrowser { |
1047 return windowShim_->ActivationRequestedByBrowser(); | 1039 return windowShim_->ActivationRequestedByBrowser(); |
1048 } | 1040 } |
1049 | 1041 |
1050 - (void)updateWindowLevel { | 1042 - (void)updateWindowLevel { |
1051 if (![self isWindowLoaded]) | 1043 if (![self isWindowLoaded]) |
1052 return; | 1044 return; |
1053 // Make sure we don't draw on top of a window in full screen mode. | 1045 // Make sure we don't draw on top of a window in full screen mode. |
1054 Panel* panel = windowShim_->panel(); | 1046 if (windowShim_->panel()->manager()->is_full_screen() || |
1055 if (panel->manager()->display_settings_provider()->is_full_screen() || | 1047 !windowShim_->panel()->always_on_top()) { |
1056 !panel->always_on_top()) { | |
1057 [[self window] setLevel:NSNormalWindowLevel]; | 1048 [[self window] setLevel:NSNormalWindowLevel]; |
1058 return; | 1049 return; |
1059 } | 1050 } |
1060 // If we simply use NSStatusWindowLevel (25) for all docked panel windows, | 1051 // If we simply use NSStatusWindowLevel (25) for all docked panel windows, |
1061 // IME composition windows for things like CJK languages appear behind panels. | 1052 // IME composition windows for things like CJK languages appear behind panels. |
1062 // Pre 10.7, IME composition windows have a window level of 19, which is | 1053 // Pre 10.7, IME composition windows have a window level of 19, which is |
1063 // lower than the dock at level 20. Since we want panels to appear on top of | 1054 // lower than the dock at level 20. Since we want panels to appear on top of |
1064 // the dock, it is impossible to enforce an ordering where IME > panel > dock, | 1055 // the dock, it is impossible to enforce an ordering where IME > panel > dock, |
1065 // since IME < dock. | 1056 // since IME < dock. |
1066 // On 10.7, IME composition windows and the dock both live at level 20, so we | 1057 // On 10.7, IME composition windows and the dock both live at level 20, so we |
1067 // use the same window level for panels. Since newly created windows appear at | 1058 // use the same window level for panels. Since newly created windows appear at |
1068 // the top of their window level, panels are typically on top of the dock, and | 1059 // the top of their window level, panels are typically on top of the dock, and |
1069 // the IME composition window correctly draws over the panel. | 1060 // the IME composition window correctly draws over the panel. |
1070 // An autohide dock causes problems though: since it's constantly being | 1061 // An autohide dock causes problems though: since it's constantly being |
1071 // revealed, it ends up drawing on top of other windows at the same level. | 1062 // revealed, it ends up drawing on top of other windows at the same level. |
1072 // While this is OK for expanded panels, it makes minimized panels impossible | 1063 // While this is OK for expanded panels, it makes minimized panels impossible |
1073 // to activate. As a result, we still use NSStatusWindowLevel for minimized | 1064 // to activate. As a result, we still use NSStatusWindowLevel for minimized |
1074 // panels, since it's impossible to compose IME text in them anyway. | 1065 // panels, since it's impossible to compose IME text in them anyway. |
1075 if (panel->IsMinimized()) { | 1066 if (windowShim_->panel()->IsMinimized()) { |
1076 [[self window] setLevel:NSStatusWindowLevel]; | 1067 [[self window] setLevel:NSStatusWindowLevel]; |
1077 return; | 1068 return; |
1078 } | 1069 } |
1079 [[self window] setLevel:NSDockWindowLevel]; | 1070 [[self window] setLevel:NSDockWindowLevel]; |
1080 } | 1071 } |
1081 | 1072 |
1082 - (void)enableResizeByMouse:(BOOL)enable { | 1073 - (void)enableResizeByMouse:(BOOL)enable { |
1083 if (![self isWindowLoaded]) | 1074 if (![self isWindowLoaded]) |
1084 return; | 1075 return; |
1085 [[self window] invalidateCursorRectsForView:overlayView_]; | 1076 [[self window] invalidateCursorRectsForView:overlayView_]; |
1086 } | 1077 } |
1087 | 1078 |
1088 - (BOOL)isActivationByClickingTitlebarEnabled { | 1079 - (BOOL)isActivationByClickingTitlebarEnabled { |
1089 return !windowShim_->panel()->always_on_top(); | 1080 return !windowShim_->panel()->always_on_top(); |
1090 } | 1081 } |
1091 | 1082 |
1092 @end | 1083 @end |
OLD | NEW |