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

Side by Side Diff: chrome/browser/ui/panels/panel_window_controller_cocoa.mm

Issue 7734003: Implement basic theming for panel titlebars. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
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;
24 29
25 @implementation PanelWindowControllerCocoa 30 @implementation PanelWindowControllerCocoa
26 31
27 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window { 32 - (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window {
28 NSString* nibpath = 33 NSString* nibpath =
29 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"]; 34 [base::mac::MainAppBundle() pathForResource:@"Panel" ofType:@"nib"];
30 if ((self = [super initWithWindowNibPath:nibpath owner:self])) 35 if ((self = [super initWithWindowNibPath:nibpath owner:self]))
31 windowShim_.reset(window); 36 windowShim_.reset(window);
32 return self; 37 return self;
33 } 38 }
34 39
40 - (ui::ThemeProvider*)themeProvider {
41 return ThemeServiceFactory::GetForProfile(windowShim_->browser()->profile());
42 }
43
44 - (ThemedWindowStyle)themedWindowStyle {
45 ThemedWindowStyle style = THEMED_POPUP;
46 if (windowShim_->browser()->profile()->IsOffTheRecord())
47 style |= THEMED_INCOGNITO;
48 return style;
49 }
50
51 - (NSPoint)themePatternPhase {
52 NSView* windowView = [[[self window] contentView] superview];
53 return [BrowserWindowUtils themePatternPhaseFor:windowView withTabStrip:nil];
54 }
55
35 - (void)awakeFromNib { 56 - (void)awakeFromNib {
36 NSWindow* window = [self window]; 57 NSWindow* window = [self window];
37 58
38 DCHECK(window); 59 DCHECK(window);
39 DCHECK(titlebar_view_); 60 DCHECK(titlebar_view_);
40 DCHECK_EQ(self, [window delegate]); 61 DCHECK_EQ(self, [window delegate]);
41 62
42 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25) 63 // Using NSModalPanelWindowLevel (8) rather then NSStatusWindowLevel (25)
43 // ensures notification balloons on top of regular windows, but below 64 // ensures notification balloons on top of regular windows, but below
44 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight 65 // popup menus which are at NSPopUpMenuWindowLevel (101) and Spotlight
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 [window setFrame:startFrame display:NO animate:NO]; 105 [window setFrame:startFrame display:NO animate:NO];
85 // Shows the window without making it key, on top of its layer, even if 106 // Shows the window without making it key, on top of its layer, even if
86 // Chromium is not an active app. 107 // Chromium is not an active app.
87 [window orderFrontRegardless]; 108 [window orderFrontRegardless];
88 [window setFrame:frame display:YES animate:YES]; 109 [window setFrame:frame display:YES animate:YES];
89 110
90 // Resume auto-resizing of the TabContents view. 111 // Resume auto-resizing of the TabContents view.
91 [self enableTabContentsViewAutosizing]; 112 [self enableTabContentsViewAutosizing];
92 } 113 }
93 114
115 - (void)updateTitleBar {
116 NSString* newTitle = base::SysUTF16ToNSString(
117 windowShim_->browser()->GetWindowTitleForCurrentTab());
118 pendingWindowTitle_.reset(
119 [BrowserWindowUtils scheduleReplaceOldTitle:pendingWindowTitle_.get()
120 withNewTitle:newTitle
121 forWindow:[self window]]);
122 [titlebar_view_ setTitle:newTitle];
123 }
124
94 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { 125 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController {
95 NSView* contentView = [[self window] contentView]; 126 NSView* contentView = [[self window] contentView];
96 [contentView addSubview:[findBarCocoaController view]]; 127 [contentView addSubview:[findBarCocoaController view]];
97 128
98 CGFloat maxY = NSMaxY([contentView frame]); 129 CGFloat maxY = NSMaxY([contentView frame]);
99 CGFloat maxWidth = NSWidth([contentView frame]); 130 CGFloat maxWidth = NSWidth([contentView frame]);
100 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth]; 131 [findBarCocoaController positionFindBarViewAtMaxY:maxY maxWidth:maxWidth];
101 } 132 }
102 133
103 - (NSView*)tabContentsView { 134 - (NSView*)tabContentsView {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // When windowShouldClose returns YES (or if controller receives direct 'close' 237 // When windowShouldClose returns YES (or if controller receives direct 'close'
207 // signal), window will be unconditionally closed. Clean up. 238 // signal), window will be unconditionally closed. Clean up.
208 - (void)windowWillClose:(NSNotification*)notification { 239 - (void)windowWillClose:(NSNotification*)notification {
209 DCHECK(windowShim_->browser()->tabstrip_model()->empty()); 240 DCHECK(windowShim_->browser()->tabstrip_model()->empty());
210 241
211 windowShim_->didCloseNativeWindow(); 242 windowShim_->didCloseNativeWindow();
212 [self autorelease]; 243 [self autorelease];
213 } 244 }
214 245
215 @end 246 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698