OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/sys_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" // IDC_* | 12 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/tabs/tab_strip_model.h" | 14 #include "chrome/browser/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/themes/theme_service.h" |
| 16 #include "chrome/browser/themes/theme_service_factory.h" |
13 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
14 #import "chrome/browser/ui/cocoa/event_utils.h" | 19 #import "chrome/browser/ui/cocoa/event_utils.h" |
15 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 20 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
16 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 21 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
17 #include "chrome/browser/ui/panels/panel.h" | 22 #include "chrome/browser/ui/panels/panel.h" |
18 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" | 23 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" |
19 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" | 24 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" |
20 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 25 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
21 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
22 | 27 |
23 const int kMinimumWindowSize = 1; | 28 const int kMinimumWindowSize = 1; |
(...skipping 11 matching lines...) Expand all Loading... |
35 @implementation PanelWindowControllerCocoa | 40 @implementation PanelWindowControllerCocoa |
36 | 41 |
37 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window { | 42 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window { |
38 NSString* nibpath = | 43 NSString* nibpath = |
39 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"]; | 44 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"]; |
40 if ((self = [super initWithWindowNibPath:nibpath owner:self])) | 45 if ((self = [super initWithWindowNibPath:nibpath owner:self])) |
41 windowShim_.reset(window); | 46 windowShim_.reset(window); |
42 return self; | 47 return self; |
43 } | 48 } |
44 | 49 |
| 50 - (ui::ThemeProvider*)themeProvider { |
| 51 return ThemeServiceFactory::GetForProfile(windowShim_->browser()->profile()); |
| 52 } |
| 53 |
| 54 - (ThemedWindowStyle)themedWindowStyle { |
| 55 ThemedWindowStyle style = THEMED_POPUP; |
| 56 if (windowShim_->browser()->profile()->IsOffTheRecord()) |
| 57 style |= THEMED_INCOGNITO; |
| 58 return style; |
| 59 } |
| 60 |
| 61 - (NSPoint)themePatternPhase { |
| 62 NSView* windowView = [[[self window] contentView] superview]; |
| 63 return [BrowserWindowUtils themePatternPhaseFor:windowView withTabStrip:nil]; |
| 64 } |
| 65 |
45 - (void)awakeFromNib { | 66 - (void)awakeFromNib { |
46 NSWindow* window = [self window]; | 67 NSWindow* window = [self window]; |
47 | 68 |
48 DCHECK(window); | 69 DCHECK(window); |
49 DCHECK(titlebar_view_); | 70 DCHECK(titlebar_view_); |
50 DCHECK_EQ(self, [window delegate]); | 71 DCHECK_EQ(self, [window delegate]); |
51 | 72 |
52 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25) | 73 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25) |
53 // ensures notification balloons on top of regular windows, but below | 74 // ensures notification balloons on top of regular windows, but below |
54 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight | 75 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 [window setFrame:startFrame display:NO animate:NO]; | 120 [window setFrame:startFrame display:NO animate:NO]; |
100 // Shows the window without making it key, on top of its layer, even if | 121 // Shows the window without making it key, on top of its layer, even if |
101 // Chromium is not an active app. | 122 // Chromium is not an active app. |
102 [window orderFrontRegardless]; | 123 [window orderFrontRegardless]; |
103 [window setFrame:frame display:YES animate:YES]; | 124 [window setFrame:frame display:YES animate:YES]; |
104 | 125 |
105 // Resume auto-resizing of the TabContents view. | 126 // Resume auto-resizing of the TabContents view. |
106 [self enableTabContentsViewAutosizing]; | 127 [self enableTabContentsViewAutosizing]; |
107 } | 128 } |
108 | 129 |
| 130 - (void)updateTitleBar { |
| 131 NSString* newTitle = base::SysUTF16ToNSString( |
| 132 windowShim_->browser()->GetWindowTitleForCurrentTab()); |
| 133 pendingWindowTitle_.reset( |
| 134 [BrowserWindowUtils scheduleReplaceOldTitle:pendingWindowTitle_.get() |
| 135 withNewTitle:newTitle |
| 136 forWindow:[self window]]); |
| 137 [titlebar_view_ setTitle:newTitle]; |
| 138 } |
| 139 |
109 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { | 140 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { |
110 NSView* contentView = [[self window] contentView]; | 141 NSView* contentView = [[self window] contentView]; |
111 [contentView addSubview:[findBarCocoaController view]]; | 142 [contentView addSubview:[findBarCocoaController view]]; |
112 | 143 |
113 CGFloat maxY = NSMaxY([contentView frame]); | 144 CGFloat maxY = NSMaxY([contentView frame]); |
114 CGFloat maxWidth = NSWidth([contentView frame]); | 145 CGFloat maxWidth = NSWidth([contentView frame]); |
115 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; | 146 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; |
116 } | 147 } |
117 | 148 |
118 - (NSView*)tabContentsView { | 149 - (NSView*)tabContentsView { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // When windowShouldClose returns YES (or if controller receives direct 'close' | 256 // When windowShouldClose returns YES (or if controller receives direct 'close' |
226 // signal), window will be unconditionally closed. Clean up. | 257 // signal), window will be unconditionally closed. Clean up. |
227 - (void)windowWillClose:(NSNotification*)notification { | 258 - (void)windowWillClose:(NSNotification*)notification { |
228 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); | 259 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); |
229 | 260 |
230 windowShim_->didCloseNativeWindow(); | 261 windowShim_->didCloseNativeWindow(); |
231 [self autorelease]; | 262 [self autorelease]; |
232 } | 263 } |
233 | 264 |
234 @end | 265 @end |
OLD | NEW |