| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 8 #include "base/scoped_nsdisable_screen_updates.h" | 8 #include "base/scoped_nsdisable_screen_updates.h" |
| 9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // Size of the gradient. Empirically determined so that the gradient looks | 47 // Size of the gradient. Empirically determined so that the gradient looks |
| 48 // like what the heuristic does when there are just a few tabs. | 48 // like what the heuristic does when there are just a few tabs. |
| 49 const int kWindowGradientHeight = 24; | 49 const int kWindowGradientHeight = 24; |
| 50 | 50 |
| 51 } | 51 } |
| 52 | 52 |
| 53 @interface GTMTheme (BrowserThemeProviderInitialization) | 53 @interface GTMTheme (BrowserThemeProviderInitialization) |
| 54 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider | 54 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider |
| 55 isOffTheRecord:(BOOL)offTheRecord; | 55 isOffTheRecord:(BOOL)offTheRecord; |
| 56 @end | 56 @end |
| 57 | 57 |
| 58 @interface NSWindow (NSPrivateApis) | 58 @interface NSWindow (NSPrivateApis) |
| 59 // Note: These functions are private, use -[NSObject respondsToSelector:] | 59 // Note: These functions are private, use -[NSObject respondsToSelector:] |
| 60 // before calling them. | 60 // before calling them. |
| 61 | 61 |
| 62 - (void)setAutorecalculatesContentBorderThickness:(BOOL)b | 62 - (void)setAutorecalculatesContentBorderThickness:(BOOL)b |
| 63 forEdge:(NSRectEdge)e; | 63 forEdge:(NSRectEdge)e; |
| 64 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e; | 64 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e; |
| 65 | 65 |
| 66 - (void)setBottomCornerRounded:(BOOL)rounded; | 66 - (void)setBottomCornerRounded:(BOOL)rounded; |
| 67 | 67 |
| 68 - (NSRect)_growBoxRect; | 68 - (NSRect)_growBoxRect; |
| 69 | 69 |
| 70 @end | 70 @end |
| 71 | 71 |
| 72 | 72 |
| 73 @interface BrowserWindowController(Private) | 73 @interface BrowserWindowController(Private) |
| 74 | 74 |
| 75 // Leopard's gradient heuristic gets confused by our tabs and makes the title | |
| 76 // gradient jump when creating a tab that is less than a tab width from the | |
| 77 // right side of the screen. This function disables Leopard's gradient | |
| 78 // heuristic. | |
| 79 - (void)fixWindowGradient; | |
| 80 | |
| 81 // Saves the window's position in the local state preferences. | 75 // Saves the window's position in the local state preferences. |
| 82 - (void)saveWindowPositionIfNeeded; | 76 - (void)saveWindowPositionIfNeeded; |
| 83 | 77 |
| 84 // Saves the window's position to the given pref service. | 78 // Saves the window's position to the given pref service. |
| 85 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; | 79 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; |
| 86 | 80 |
| 87 // We need to adjust where sheets come out of the window, as by default they | 81 // We need to adjust where sheets come out of the window, as by default they |
| 88 // erupt from the omnibox, which is rather weird. | 82 // erupt from the omnibox, which is rather weird. |
| 89 - (NSRect)window:(NSWindow*)window | 83 - (NSRect)window:(NSWindow*)window |
| 90 willPositionSheet:(NSWindow*)sheet | 84 willPositionSheet:(NSWindow*)sheet |
| 91 usingRect:(NSRect)defaultSheetRect; | 85 usingRect:(NSRect)defaultSheetRect; |
| 92 | 86 |
| 93 // Assign a theme to the window. | 87 // Assign a theme to the window. |
| 94 - (void)setTheme; | 88 - (void)setTheme; |
| 95 | 89 |
| 96 // Theme up the window. | |
| 97 - (void)applyTheme; | |
| 98 | |
| 99 // Repositions the windows subviews. | 90 // Repositions the windows subviews. |
| 100 - (void)layoutSubviews; | 91 - (void)layoutSubviews; |
| 101 | 92 |
| 102 @end | 93 @end |
| 103 | 94 |
| 104 | 95 |
| 105 @implementation BrowserWindowController | 96 @implementation BrowserWindowController |
| 106 | 97 |
| 107 // Load the browser window nib and do any Cocoa-specific initialization. | 98 // Load the browser window nib and do any Cocoa-specific initialization. |
| 108 // Takes ownership of |browser|. Note that the nib also sets this controller | 99 // Takes ownership of |browser|. Note that the nib also sets this controller |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 210 |
| 220 if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { | 211 if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) { |
| 221 // Create the extension shelf. | 212 // Create the extension shelf. |
| 222 extensionShelfController_.reset([[ExtensionShelfController alloc] | 213 extensionShelfController_.reset([[ExtensionShelfController alloc] |
| 223 initWithBrowser:browser_.get() | 214 initWithBrowser:browser_.get() |
| 224 resizeDelegate:self]); | 215 resizeDelegate:self]); |
| 225 [[[self window] contentView] addSubview:[extensionShelfController_ view]]; | 216 [[[self window] contentView] addSubview:[extensionShelfController_ view]]; |
| 226 [extensionShelfController_ wasInsertedIntoWindow]; | 217 [extensionShelfController_ wasInsertedIntoWindow]; |
| 227 } | 218 } |
| 228 | 219 |
| 229 [self fixWindowGradient]; | |
| 230 | |
| 231 // Force a relayout of all the various bars. | 220 // Force a relayout of all the various bars. |
| 232 [self layoutSubviews]; | 221 [self layoutSubviews]; |
| 233 | 222 |
| 234 // Create the bridge for the status bubble. | 223 // Create the bridge for the status bubble. |
| 235 statusBubble_.reset(new StatusBubbleMac([self window], self)); | 224 statusBubble_.reset(new StatusBubbleMac([self window], self)); |
| 236 | 225 |
| 237 #if 0 | 226 #if 0 |
| 238 // Move all buttons down two pixels for visual balance. | 227 // Move all buttons down two pixels for visual balance. |
| 239 // TODO(alcor): remove this if we can't prevent window resize from breaking. | 228 // TODO(alcor): remove this if we can't prevent window resize from breaking. |
| 240 NSArray* buttons = | 229 NSArray* buttons = |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 320 } |
| 332 | 321 |
| 333 // the tab strip is empty, it's ok to close the window | 322 // the tab strip is empty, it's ok to close the window |
| 334 return YES; | 323 return YES; |
| 335 } | 324 } |
| 336 | 325 |
| 337 // Called right after our window became the main window. | 326 // Called right after our window became the main window. |
| 338 - (void)windowDidBecomeMain:(NSNotification*)notification { | 327 - (void)windowDidBecomeMain:(NSNotification*)notification { |
| 339 BrowserList::SetLastActive(browser_.get()); | 328 BrowserList::SetLastActive(browser_.get()); |
| 340 [self saveWindowPositionIfNeeded]; | 329 [self saveWindowPositionIfNeeded]; |
| 341 [self applyTheme]; | 330 |
| 331 // TODO(dmaclach): Instead of redrawing the whole window, views that care |
| 332 // about the active window state should be registering for notifications. |
| 333 [[self window] setViewsNeedDisplay:YES]; |
| 342 } | 334 } |
| 343 | 335 |
| 344 - (void)windowDidResignMain:(NSNotification*)notification { | 336 - (void)windowDidResignMain:(NSNotification*)notification { |
| 345 [self applyTheme]; | 337 // TODO(dmaclach): Instead of redrawing the whole window, views that care |
| 338 // about the active window state should be registering for notifications. |
| 339 [[self window] setViewsNeedDisplay:YES]; |
| 346 } | 340 } |
| 347 | 341 |
| 348 // Called when we are activated (when we gain focus). | 342 // Called when we are activated (when we gain focus). |
| 349 - (void)windowDidBecomeKey:(NSNotification*)notification { | 343 - (void)windowDidBecomeKey:(NSNotification*)notification { |
| 350 // We need to activate the controls (in the "WebView"). To do this, get the | 344 // We need to activate the controls (in the "WebView"). To do this, get the |
| 351 // selected TabContents's RenderWidgetHostViewMac and tell it to activate. | 345 // selected TabContents's RenderWidgetHostViewMac and tell it to activate. |
| 352 if (TabContents* contents = browser_->GetSelectedTabContents()) { | 346 if (TabContents* contents = browser_->GetSelectedTabContents()) { |
| 353 if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) | 347 if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) |
| 354 rwhv->SetActive(true); | 348 rwhv->SetActive(true); |
| 355 } | 349 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 if (oldState != newState) | 521 if (oldState != newState) |
| 528 [item setState:newState]; | 522 [item setState:newState]; |
| 529 } | 523 } |
| 530 | 524 |
| 531 // Update the checked/Unchecked state of items in the encoding menu. | 525 // Update the checked/Unchecked state of items in the encoding menu. |
| 532 // On Windows, this logic is part of |EncodingMenuModel| in | 526 // On Windows, this logic is part of |EncodingMenuModel| in |
| 533 // browser/views/toolbar_view.h. | 527 // browser/views/toolbar_view.h. |
| 534 EncodingMenuController encoding_controller; | 528 EncodingMenuController encoding_controller; |
| 535 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) { | 529 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) { |
| 536 DCHECK(browser_.get()); | 530 DCHECK(browser_.get()); |
| 537 Profile *profile = browser_->profile(); | 531 Profile* profile = browser_->profile(); |
| 538 DCHECK(profile); | 532 DCHECK(profile); |
| 539 TabContents* current_tab = browser_->GetSelectedTabContents(); | 533 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 540 if (!current_tab) { | 534 if (!current_tab) { |
| 541 return; | 535 return; |
| 542 } | 536 } |
| 543 const std::string encoding = current_tab->encoding(); | 537 const std::string encoding = current_tab->encoding(); |
| 544 | 538 |
| 545 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); | 539 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); |
| 546 NSInteger oldState = [item state]; | 540 NSInteger oldState = [item state]; |
| 547 NSInteger newState = toggled ? NSOnState : NSOffState; | 541 NSInteger newState = toggled ? NSOnState : NSOffState; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 // put into a different tab strip, such as during a drop on another window. | 740 // put into a different tab strip, such as during a drop on another window. |
| 747 - (void)detachTabView:(NSView*)view { | 741 - (void)detachTabView:(NSView*)view { |
| 748 int index = [tabStripController_ indexForTabView:view]; | 742 int index = [tabStripController_ indexForTabView:view]; |
| 749 browser_->tabstrip_model()->DetachTabContentsAt(index); | 743 browser_->tabstrip_model()->DetachTabContentsAt(index); |
| 750 } | 744 } |
| 751 | 745 |
| 752 - (NSView*)selectedTabView { | 746 - (NSView*)selectedTabView { |
| 753 return [tabStripController_ selectedTabView]; | 747 return [tabStripController_ selectedTabView]; |
| 754 } | 748 } |
| 755 | 749 |
| 756 - (TabStripController *)tabStripController { | 750 - (TabStripController*)tabStripController { |
| 757 return tabStripController_; | 751 return tabStripController_; |
| 758 } | 752 } |
| 759 | 753 |
| 760 - (void)setIsLoading:(BOOL)isLoading { | 754 - (void)setIsLoading:(BOOL)isLoading { |
| 761 [toolbarController_ setIsLoading:isLoading]; | 755 [toolbarController_ setIsLoading:isLoading]; |
| 762 } | 756 } |
| 763 | 757 |
| 764 // Make the location bar the first responder, if possible. | 758 // Make the location bar the first responder, if possible. |
| 765 - (void)focusLocationBar { | 759 - (void)focusLocationBar { |
| 766 [toolbarController_ focusLocationBar]; | 760 [toolbarController_ focusLocationBar]; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 atIndex:(NSInteger)index | 1009 atIndex:(NSInteger)index |
| 1016 loadingOnly:(BOOL)loading { | 1010 loadingOnly:(BOOL)loading { |
| 1017 if (index == browser_->tabstrip_model()->selected_index()) { | 1011 if (index == browser_->tabstrip_model()->selected_index()) { |
| 1018 // Update titles if this is the currently selected tab. | 1012 // Update titles if this is the currently selected tab. |
| 1019 windowShim_->UpdateTitleBar(); | 1013 windowShim_->UpdateTitleBar(); |
| 1020 } | 1014 } |
| 1021 } | 1015 } |
| 1022 | 1016 |
| 1023 - (void)userChangedTheme { | 1017 - (void)userChangedTheme { |
| 1024 [self setTheme]; | 1018 [self setTheme]; |
| 1025 [self applyTheme]; | 1019 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 1020 [defaultCenter postNotificationName:kGTMThemeDidChangeNotification |
| 1021 object:theme_]; |
| 1022 // TODO(dmaclach): Instead of redrawing the whole window, views that care |
| 1023 // about the active window state should be registering for notifications. |
| 1024 [[self window] setViewsNeedDisplay:YES]; |
| 1026 } | 1025 } |
| 1027 | 1026 |
| 1028 - (GTMTheme *)gtm_themeForWindow:(NSWindow*)window { | 1027 - (GTMTheme*)gtm_themeForWindow:(NSWindow*)window { |
| 1029 return theme_ ? theme_ : [GTMTheme defaultTheme]; | 1028 return theme_ ? theme_ : [GTMTheme defaultTheme]; |
| 1030 } | 1029 } |
| 1031 | 1030 |
| 1031 - (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow*)window { |
| 1032 // Our patterns want to be drawn from the upper left hand corner of the view. |
| 1033 // Cocoa wants to do it from the lower left of the window. |
| 1034 // Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.) |
| 1035 // will phase their patterns relative to this so all the views look right. |
| 1036 NSView* tabStripView = [self tabStripView]; |
| 1037 NSRect tabStripViewWindowBounds = [tabStripView bounds]; |
| 1038 NSView* windowChromeView = [[window contentView] superview]; |
| 1039 tabStripViewWindowBounds = |
| 1040 [tabStripView convertRect:tabStripViewWindowBounds |
| 1041 toView:windowChromeView]; |
| 1042 NSPoint phase = NSMakePoint(NSMinX(tabStripViewWindowBounds), |
| 1043 NSMinY(tabStripViewWindowBounds) |
| 1044 + [TabStripController defaultTabHeight]); |
| 1045 return phase; |
| 1046 } |
| 1047 |
| 1032 - (NSPoint)topLeftForBubble { | 1048 - (NSPoint)topLeftForBubble { |
| 1033 NSRect rect = [toolbarController_ starButtonInWindowCoordinates]; | 1049 NSRect rect = [toolbarController_ starButtonInWindowCoordinates]; |
| 1034 NSPoint p = NSMakePoint(NSMinX(rect), NSMinY(rect)); // bottom left | 1050 NSPoint p = NSMakePoint(NSMinX(rect), NSMinY(rect)); // bottom left |
| 1035 | 1051 |
| 1036 // Adjust top-left based on our knowledge of how the view looks. | 1052 // Adjust top-left based on our knowledge of how the view looks. |
| 1037 p.x -= 2; | 1053 p.x -= 2; |
| 1038 p.y += 7; | 1054 p.y += 7; |
| 1039 | 1055 |
| 1040 return p; | 1056 return p; |
| 1041 } | 1057 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 [shadow setShadowBlurRadius:2.0]; | 1143 [shadow setShadowBlurRadius:2.0]; |
| 1128 [incognitoView setShadow:shadow]; | 1144 [incognitoView setShadow:shadow]; |
| 1129 | 1145 |
| 1130 // Shrink the tab strip's width so there's no overlap and install the | 1146 // Shrink the tab strip's width so there's no overlap and install the |
| 1131 // view. | 1147 // view. |
| 1132 tabFrame.size.width -= incognitoFrame.size.width + kOffset; | 1148 tabFrame.size.width -= incognitoFrame.size.width + kOffset; |
| 1133 [[self tabStripView] setFrame:tabFrame]; | 1149 [[self tabStripView] setFrame:tabFrame]; |
| 1134 [[[[self window] contentView] superview] addSubview:incognitoView.get()]; | 1150 [[[[self window] contentView] superview] addSubview:incognitoView.get()]; |
| 1135 } | 1151 } |
| 1136 | 1152 |
| 1137 - (void)fixWindowGradient { | |
| 1138 NSWindow* win = [self window]; | |
| 1139 if ([win respondsToSelector:@selector( | |
| 1140 setAutorecalculatesContentBorderThickness:forEdge:)] && | |
| 1141 [win respondsToSelector:@selector( | |
| 1142 setContentBorderThickness:forEdge:)]) { | |
| 1143 [win setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; | |
| 1144 [win setContentBorderThickness:kWindowGradientHeight forEdge:NSMaxYEdge]; | |
| 1145 } | |
| 1146 } | |
| 1147 | |
| 1148 - (void)saveWindowPositionIfNeeded { | 1153 - (void)saveWindowPositionIfNeeded { |
| 1149 if (browser_ != BrowserList::GetLastActive()) | 1154 if (browser_ != BrowserList::GetLastActive()) |
| 1150 return; | 1155 return; |
| 1151 | 1156 |
| 1152 if (!g_browser_process || !g_browser_process->local_state() || | 1157 if (!g_browser_process || !g_browser_process->local_state() || |
| 1153 !browser_->ShouldSaveWindowPlacement()) | 1158 !browser_->ShouldSaveWindowPlacement()) |
| 1154 return; | 1159 return; |
| 1155 | 1160 |
| 1156 [self saveWindowPositionToPrefs:g_browser_process->local_state()]; | 1161 [self saveWindowPositionToPrefs:g_browser_process->local_state()]; |
| 1157 } | 1162 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 } | 1213 } |
| 1209 | 1214 |
| 1210 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { | 1215 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { |
| 1211 // Ask the toolbar controller if it wants to return a custom field editor | 1216 // Ask the toolbar controller if it wants to return a custom field editor |
| 1212 // for the specific object. | 1217 // for the specific object. |
| 1213 return [toolbarController_ customFieldEditorForObject:obj]; | 1218 return [toolbarController_ customFieldEditorForObject:obj]; |
| 1214 } | 1219 } |
| 1215 | 1220 |
| 1216 - (void)setTheme { | 1221 - (void)setTheme { |
| 1217 ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); | 1222 ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); |
| 1218 if (theme_provider) { | 1223 BrowserThemeProvider* browser_theme_provider = |
| 1219 GTMTheme *theme = [GTMTheme themeWithBrowserThemeProvider: | 1224 static_cast<BrowserThemeProvider*>(theme_provider); |
| 1220 (BrowserThemeProvider *)theme_provider | 1225 if (browser_theme_provider) { |
| 1221 isOffTheRecord:browser_->profile()->IsOffTheRecord()]; | 1226 bool offtheRecord = browser_->profile()->IsOffTheRecord(); |
| 1227 GTMTheme* theme = |
| 1228 [GTMTheme themeWithBrowserThemeProvider:browser_theme_provider |
| 1229 isOffTheRecord:offtheRecord]; |
| 1222 theme_.reset([theme retain]); | 1230 theme_.reset([theme retain]); |
| 1223 } | 1231 } |
| 1224 } | 1232 } |
| 1225 | 1233 |
| 1226 - (void)applyTheme { | |
| 1227 NSColor* color = | |
| 1228 [theme_ backgroundPatternColorForStyle:GTMThemeStyleWindow | |
| 1229 state:[[self window] isMainWindow]]; | |
| 1230 [[self window] setBackgroundColor:color]; | |
| 1231 [tabStripController_ applyTheme]; | |
| 1232 } | |
| 1233 | |
| 1234 // Private method to layout browser window subviews. Positions the toolbar and | 1234 // Private method to layout browser window subviews. Positions the toolbar and |
| 1235 // the infobar above the tab content area. Positions the download shelf below | 1235 // the infobar above the tab content area. Positions the download shelf below |
| 1236 // the tab content area. If the toolbar is not a child of the contentview, this | 1236 // the tab content area. If the toolbar is not a child of the contentview, this |
| 1237 // method will not leave room for it. If we are currently running in fullscreen | 1237 // method will not leave room for it. If we are currently running in fullscreen |
| 1238 // mode, or if the tabstrip is not a descendant of the window, this method fills | 1238 // mode, or if the tabstrip is not a descendant of the window, this method fills |
| 1239 // the entire content area. Otherwise, this method places the topmost view | 1239 // the entire content area. Otherwise, this method places the topmost view |
| 1240 // directly beneath the tabstrip. | 1240 // directly beneath the tabstrip. |
| 1241 - (void)layoutSubviews { | 1241 - (void)layoutSubviews { |
| 1242 NSView* contentView = fullscreen_ ? [fullscreen_window_ contentView] | 1242 NSView* contentView = fullscreen_ ? [fullscreen_window_ contentView] |
| 1243 : [[self window] contentView]; | 1243 : [[self window] contentView]; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 BOOL bookmarkToolbarShowsDivider = [bookmarkBarController_ isAlwaysVisible]; | 1342 BOOL bookmarkToolbarShowsDivider = [bookmarkBarController_ isAlwaysVisible]; |
| 1343 [[toolbarController_ backgroundGradientView] | 1343 [[toolbarController_ backgroundGradientView] |
| 1344 setShowsDivider:!bookmarkToolbarShowsDivider]; | 1344 setShowsDivider:!bookmarkToolbarShowsDivider]; |
| 1345 [[bookmarkBarController_ backgroundGradientView] | 1345 [[bookmarkBarController_ backgroundGradientView] |
| 1346 setShowsDivider:bookmarkToolbarShowsDivider]; | 1346 setShowsDivider:bookmarkToolbarShowsDivider]; |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 @end | 1349 @end |
| 1350 | 1350 |
| 1351 @implementation GTMTheme (BrowserThemeProviderInitialization) | 1351 @implementation GTMTheme (BrowserThemeProviderInitialization) |
| 1352 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider | 1352 + (GTMTheme*)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider |
| 1353 isOffTheRecord:(BOOL)isOffTheRecord { | 1353 isOffTheRecord:(BOOL)isOffTheRecord { |
| 1354 // First check if it's in the cache. | 1354 // First check if it's in the cache. |
| 1355 // TODO(pinkerton): This might be a good candidate for a singleton. | 1355 // TODO(pinkerton): This might be a good candidate for a singleton. |
| 1356 typedef std::pair<std::string, BOOL> ThemeKey; | 1356 typedef std::pair<std::string, BOOL> ThemeKey; |
| 1357 static std::map<ThemeKey, GTMTheme*> cache; | 1357 static std::map<ThemeKey, GTMTheme*> cache; |
| 1358 ThemeKey key(provider->GetThemeID(), isOffTheRecord); | 1358 ThemeKey key(provider->GetThemeID(), isOffTheRecord); |
| 1359 GTMTheme* theme = cache[key]; | 1359 GTMTheme* theme = cache[key]; |
| 1360 if (theme) | 1360 if (theme) |
| 1361 return theme; | 1361 return theme; |
| 1362 | 1362 |
| 1363 theme = [[GTMTheme alloc] init]; // "Leak" it in the cache. | 1363 theme = [[GTMTheme alloc] init]; // "Leak" it in the cache. |
| 1364 cache[key] = theme; | 1364 cache[key] = theme; |
| 1365 | 1365 |
| 1366 // TODO(pinkerton): Need to be able to theme the entire incognito window | 1366 // TODO(pinkerton): Need to be able to theme the entire incognito window |
| 1367 // http://crbug.com/18568 The hardcoding of the colors here will need to be | 1367 // http://crbug.com/18568 The hardcoding of the colors here will need to be |
| 1368 // removed when that bug is addressed, but are here in order for things to be | 1368 // removed when that bug is addressed, but are here in order for things to be |
| 1369 // usable in the meantime. | 1369 // usable in the meantime. |
| 1370 if (isOffTheRecord) { | 1370 if (isOffTheRecord) { |
| 1371 NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0 | 1371 NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0 |
| 1372 green:108.0/255.0 | 1372 green:108.0/255.0 |
| 1373 blue:140/255.0 | 1373 blue:140/255.0 |
| 1374 alpha:1.0]; | 1374 alpha:1.0]; |
| 1375 [theme setBackgroundColor:incognitoColor]; | 1375 [theme setBackgroundColor:incognitoColor]; |
| 1376 [theme setValue:[NSColor blackColor] | 1376 [theme setValue:[NSColor blackColor] |
| 1377 forAttribute:@"textColor" | 1377 forAttribute:@"textColor" |
| 1378 style:GTMThemeStyleToolBar | 1378 style:GTMThemeStyleTabBarSelected |
| 1379 state:GTMThemeStateActiveWindow]; | 1379 state:GTMThemeStateActiveWindow]; |
| 1380 [theme setValue:[NSColor blackColor] | 1380 [theme setValue:[NSColor blackColor] |
| 1381 forAttribute:@"textColor" | 1381 forAttribute:@"textColor" |
| 1382 style:GTMThemeStyleTabBarDeselected | 1382 style:GTMThemeStyleTabBarDeselected |
| 1383 state:GTMThemeStateActiveWindow]; | 1383 state:GTMThemeStateActiveWindow]; |
| 1384 [theme setValue:[NSColor blackColor] | 1384 [theme setValue:[NSColor blackColor] |
| 1385 forAttribute:@"textColor" | 1385 forAttribute:@"textColor" |
| 1386 style:GTMThemeStyleBookmarksBarButton | 1386 style:GTMThemeStyleBookmarksBarButton |
| 1387 state:GTMThemeStateActiveWindow]; | 1387 state:GTMThemeStateActiveWindow]; |
| 1388 return theme; | 1388 return theme; |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 NSImage* frameImage = provider->GetNSImageNamed(IDR_THEME_FRAME); | 1391 NSImage* frameImage = provider->GetNSImageNamed(IDR_THEME_FRAME); |
| 1392 NSImage* frameInactiveImage = | 1392 NSImage* frameInactiveImage = |
| 1393 provider->GetNSImageNamed(IDR_THEME_FRAME_INACTIVE); | 1393 provider->GetNSImageNamed(IDR_THEME_FRAME_INACTIVE); |
| 1394 | 1394 |
| 1395 [theme setValue:frameImage | 1395 [theme setValue:frameImage |
| 1396 forAttribute:@"backgroundImage" | 1396 forAttribute:@"backgroundImage" |
| 1397 style:GTMThemeStyleWindow | 1397 style:GTMThemeStyleWindow |
| 1398 state:GTMThemeStateActiveWindow]; | 1398 state:GTMThemeStateActiveWindow]; |
| 1399 | 1399 |
| 1400 NSColor* tabTextColor = | 1400 NSColor* tabTextColor = |
| 1401 provider->GetNSColor(BrowserThemeProvider::COLOR_TAB_TEXT); | 1401 provider->GetNSColor(BrowserThemeProvider::COLOR_TAB_TEXT); |
| 1402 [theme setValue:tabTextColor | 1402 [theme setValue:tabTextColor |
| 1403 forAttribute:@"textColor" | 1403 forAttribute:@"textColor" |
| 1404 style:GTMThemeStyleToolBar | 1404 style:GTMThemeStyleTabBarSelected |
| 1405 state:GTMThemeStateActiveWindow]; | 1405 state:GTMThemeStateActiveWindow]; |
| 1406 | 1406 |
| 1407 NSColor* tabInactiveTextColor = | 1407 NSColor* tabInactiveTextColor = |
| 1408 provider->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT); | 1408 provider->GetNSColor(BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT); |
| 1409 [theme setValue:tabInactiveTextColor | 1409 [theme setValue:tabInactiveTextColor |
| 1410 forAttribute:@"textColor" | 1410 forAttribute:@"textColor" |
| 1411 style:GTMThemeStyleTabBarDeselected | 1411 style:GTMThemeStyleTabBarDeselected |
| 1412 state:GTMThemeStateActiveWindow]; | 1412 state:GTMThemeStateActiveWindow]; |
| 1413 | 1413 |
| 1414 NSColor* bookmarkBarTextColor = | 1414 NSColor* bookmarkBarTextColor = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 style:GTMThemeStyleToolBar | 1473 style:GTMThemeStyleToolBar |
| 1474 state:GTMThemeStateActiveWindow]; | 1474 state:GTMThemeStateActiveWindow]; |
| 1475 | 1475 |
| 1476 NSColor* toolbarBackgroundColor = | 1476 NSColor* toolbarBackgroundColor = |
| 1477 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR); | 1477 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR); |
| 1478 [theme setValue:toolbarBackgroundColor | 1478 [theme setValue:toolbarBackgroundColor |
| 1479 forAttribute:@"backgroundColor" | 1479 forAttribute:@"backgroundColor" |
| 1480 style:GTMThemeStyleToolBar | 1480 style:GTMThemeStyleToolBar |
| 1481 state:GTMThemeStateActiveWindow]; | 1481 state:GTMThemeStateActiveWindow]; |
| 1482 | 1482 |
| 1483 NSImage* frameOverlayImage = |
| 1484 provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY); |
| 1485 if (frameOverlayImage) { |
| 1486 [theme setValue:frameOverlayImage |
| 1487 forAttribute:@"overlay" |
| 1488 style:GTMThemeStyleWindow |
| 1489 state:GTMThemeStateActiveWindow]; |
| 1490 } |
| 1491 |
| 1492 NSImage* frameOverlayInactiveImage = |
| 1493 provider->GetNSImageNamed(IDR_THEME_FRAME_OVERLAY_INACTIVE); |
| 1494 if (frameOverlayInactiveImage) { |
| 1495 [theme setValue:frameOverlayInactiveImage |
| 1496 forAttribute:@"overlay" |
| 1497 style:GTMThemeStyleWindow |
| 1498 state:GTMThemeStateInactiveWindow]; |
| 1499 } |
| 1500 |
| 1483 return theme; | 1501 return theme; |
| 1484 } | 1502 } |
| 1485 @end | 1503 @end |
| 1486 | |
| OLD | NEW |