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 "chrome/app/chrome_command_ids.h" // IDC_* | 11 #include "chrome/app/chrome_command_ids.h" // IDC_* |
12 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
14 #include "chrome/browser/themes/theme_service.h" | |
15 #include "chrome/browser/themes/theme_service_factory.h" | |
13 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
14 #import "chrome/browser/ui/cocoa/event_utils.h" | 17 #import "chrome/browser/ui/cocoa/event_utils.h" |
15 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 18 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
16 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 19 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
17 #include "chrome/browser/ui/panels/panel.h" | 20 #include "chrome/browser/ui/panels/panel.h" |
18 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" | 21 #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" |
19 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" | 22 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" |
20 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 23 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
21 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
22 | 25 |
23 const int kMinimumWindowSize = 1; | 26 const int kMinimumWindowSize = 1; |
24 | 27 |
25 @implementation PanelWindowControllerCocoa | 28 @implementation PanelWindowControllerCocoa |
26 | 29 |
27 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window { | 30 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window { |
28 NSString* nibpath = | 31 NSString* nibpath = |
29 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"]; | 32 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"]; |
30 if ((self = [super initWithWindowNibPath:nibpath owner:self])) | 33 if ((self = [super initWithWindowNibPath:nibpath owner:self])) |
31 windowShim_.reset(window); | 34 windowShim_.reset(window); |
32 return self; | 35 return self; |
33 } | 36 } |
34 | 37 |
38 - (ui::ThemeProvider*)themeProvider { | |
39 return ThemeServiceFactory::GetForProfile(windowShim_->browser()->profile()); | |
40 } | |
41 | |
42 - (ThemedWindowStyle)themedWindowStyle { | |
43 ThemedWindowStyle style = THEMED_POPUP; | |
44 if (windowShim_->browser()->profile()->IsOffTheRecord()) | |
45 style |= THEMED_INCOGNITO; | |
46 return style; | |
47 } | |
48 | |
49 - (NSPoint)themePatternPhase { | |
50 // TODO(dcheng): These constants and the following logic are duplicated from | |
Dmitry Titov
2011/08/27 20:30:58
Lets just share this code in this patch the new ut
dcheng
2011/08/31 00:05:04
Done.
| |
51 // BrowserWindowController. Determine if we need to share the code somehow or | |
52 // if we will always use the same constants as BrowserWindowController. | |
53 const CGFloat kPatternHorizontalOffset = -5; | |
54 const CGFloat kPatternVerticalOffset = 2; | |
55 NSView* windowView = [[[self window] contentView] superview]; | |
56 return NSMakePoint(kPatternHorizontalOffset, windowView + kPatternVerticalOffs et); | |
57 } | |
58 | |
35 - (void)awakeFromNib { | 59 - (void)awakeFromNib { |
36 NSWindow* window = [self window]; | 60 NSWindow* window = [self window]; |
37 | 61 |
38 DCHECK(window); | 62 DCHECK(window); |
39 DCHECK(titlebar_view_); | 63 DCHECK(titlebar_view_); |
40 DCHECK_EQ(self, [window delegate]); | 64 DCHECK_EQ(self, [window delegate]); |
41 | 65 |
42 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25) | 66 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25) |
43 // ensures notification balloons on top of regular windows, but below | 67 // ensures notification balloons on top of regular windows, but below |
44 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight | 68 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // Chromium is not an active app. | 110 // Chromium is not an active app. |
87 [window orderFrontRegardless]; | 111 [window orderFrontRegardless]; |
88 [window setFrame:frame display:YES animate:YES]; | 112 [window setFrame:frame display:YES animate:YES]; |
89 | 113 |
90 // Resume auto-resizing of the TabContents view. | 114 // Resume auto-resizing of the TabContents view. |
91 [self enableTabContentsViewAutosizing]; | 115 [self enableTabContentsViewAutosizing]; |
92 } | 116 } |
93 | 117 |
94 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { | 118 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { |
95 NSView* contentView = [[self window] contentView]; | 119 NSView* contentView = [[self window] contentView]; |
96 [contentView addSubview:[findBarCocoaController view]]; | 120 // Append as the last subview of the superview so that we can draw over our |
121 // custom title bar, which draws over the native title bar. | |
122 [[contentView superview] addSubview:[findBarCocoaController view]]; | |
97 | 123 |
98 CGFloat maxY = NSMaxY([contentView frame]); | 124 CGFloat maxY = NSMaxY([contentView frame]); |
99 CGFloat maxWidth = NSWidth([contentView frame]); | 125 CGFloat maxWidth = NSWidth([contentView frame]); |
100 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; | 126 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; |
101 } | 127 } |
102 | 128 |
103 - (NSView*)tabContentsView { | 129 - (NSView*)tabContentsView { |
104 TabContents* contents = windowShim_->browser()->GetSelectedTabContents(); | 130 TabContents* contents = windowShim_->browser()->GetSelectedTabContents(); |
105 CHECK(contents); | 131 CHECK(contents); |
106 NSView* tabContentView = contents->GetNativeView(); | 132 NSView* tabContentView = contents->GetNativeView(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 // When windowShouldClose returns YES (or if controller receives direct 'close' | 232 // When windowShouldClose returns YES (or if controller receives direct 'close' |
207 // signal), window will be unconditionally closed. Clean up. | 233 // signal), window will be unconditionally closed. Clean up. |
208 - (void)windowWillClose:(NSNotification*)notification { | 234 - (void)windowWillClose:(NSNotification*)notification { |
209 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); | 235 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); |
210 | 236 |
211 windowShim_->didCloseNativeWindow(); | 237 windowShim_->didCloseNativeWindow(); |
212 [self autorelease]; | 238 [self autorelease]; |
213 } | 239 } |
214 | 240 |
215 @end | 241 @end |
OLD | NEW |