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

Side by Side Diff: chrome/browser/cocoa/browser_window_controller.mm

Issue 175025: Add a bare-bones extension shelf that displays extension items on OS X. (Closed)
Patch Set: Merge ToT, address more comments Created 11 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
OLDNEW
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"
11 #include "chrome/app/chrome_dll_resource.h" // IDC_* 11 #include "chrome/app/chrome_dll_resource.h" // IDC_*
12 #include "chrome/browser/bookmarks/bookmark_editor.h" 12 #include "chrome/browser/bookmarks/bookmark_editor.h"
13 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
14 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/encoding_menu_controller.h" 16 #include "chrome/browser/encoding_menu_controller.h"
17 #include "chrome/browser/location_bar.h" 17 #include "chrome/browser/location_bar.h"
18 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
19 #include "chrome/browser/renderer_host/render_widget_host_view.h" 19 #include "chrome/browser/renderer_host/render_widget_host_view.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/tab_contents/tab_contents_view.h" 21 #include "chrome/browser/tab_contents/tab_contents_view.h"
22 #include "chrome/browser/tabs/tab_strip_model.h" 22 #include "chrome/browser/tabs/tab_strip_model.h"
23 #import "chrome/browser/cocoa/bookmark_bar_controller.h" 23 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
24 #import "chrome/browser/cocoa/bookmark_editor_controller.h" 24 #import "chrome/browser/cocoa/bookmark_editor_controller.h"
25 #import "chrome/browser/cocoa/browser_window_cocoa.h" 25 #import "chrome/browser/cocoa/browser_window_cocoa.h"
26 #import "chrome/browser/cocoa/browser_window_controller.h" 26 #import "chrome/browser/cocoa/browser_window_controller.h"
27 #import "chrome/browser/cocoa/download_shelf_controller.h" 27 #import "chrome/browser/cocoa/download_shelf_controller.h"
28 #import "chrome/browser/cocoa/extension_shelf_controller.h"
28 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" 29 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h"
29 #include "chrome/browser/cocoa/find_bar_bridge.h" 30 #include "chrome/browser/cocoa/find_bar_bridge.h"
30 #import "chrome/browser/cocoa/fullscreen_window.h" 31 #import "chrome/browser/cocoa/fullscreen_window.h"
31 #import "chrome/browser/cocoa/infobar_container_controller.h" 32 #import "chrome/browser/cocoa/infobar_container_controller.h"
32 #import "chrome/browser/cocoa/status_bubble_mac.h" 33 #import "chrome/browser/cocoa/status_bubble_mac.h"
33 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" 34 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
34 #import "chrome/browser/cocoa/tab_strip_view.h" 35 #import "chrome/browser/cocoa/tab_strip_view.h"
35 #import "chrome/browser/cocoa/tab_strip_controller.h" 36 #import "chrome/browser/cocoa/tab_strip_controller.h"
36 #import "chrome/browser/cocoa/tab_view.h" 37 #import "chrome/browser/cocoa/tab_view.h"
37 #import "chrome/browser/cocoa/toolbar_controller.h" 38 #import "chrome/browser/cocoa/toolbar_controller.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 browser:browser 183 browser:browser
183 resizeDelegate:self 184 resizeDelegate:self
184 bookmarkDelegate:self]); 185 bookmarkDelegate:self]);
185 // If we are a pop-up, we have a titlebar and no toolbar. 186 // If we are a pop-up, we have a titlebar and no toolbar.
186 if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) && 187 if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) &&
187 browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) { 188 browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) {
188 [toolbarController_ setHasToolbar:NO]; 189 [toolbarController_ setHasToolbar:NO];
189 } 190 }
190 [[[self window] contentView] addSubview:[toolbarController_ view]]; 191 [[[self window] contentView] addSubview:[toolbarController_ view]];
191 192
193 if (browser_->SupportsWindowFeature(Browser::FEATURE_EXTENSIONSHELF)) {
194 // Create the extension shelf.
195 extensionShelfController_.reset([[ExtensionShelfController alloc]
196 initWithBrowser:browser_.get()
197 resizeDelegate:self]);
198 [[[self window] contentView] addSubview:[extensionShelfController_ view]];
199 [extensionShelfController_ wasInsertedIntoWindow];
200 [extensionShelfController_ show:nil];
201 }
202
192 [self fixWindowGradient]; 203 [self fixWindowGradient];
193 204
194 // Force a relayout of all the various bars. 205 // Force a relayout of all the various bars.
195 [self layoutSubviews]; 206 [self layoutSubviews];
196 207
197 // Create the bridge for the status bubble. 208 // Create the bridge for the status bubble.
198 statusBubble_.reset(new StatusBubbleMac([self window], self)); 209 statusBubble_.reset(new StatusBubbleMac([self window], self));
199 210
200 #if 0 211 #if 0
201 // Move all buttons down two pixels for visual balance. 212 // Move all buttons down two pixels for visual balance.
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 470
460 // If it wasn't reasonable, return NO. 471 // If it wasn't reasonable, return NO.
461 return NO; 472 return NO;
462 } 473 }
463 474
464 // Main method to resize browser window subviews. This method should be called 475 // Main method to resize browser window subviews. This method should be called
465 // when resizing any child of the content view, rather than resizing the views 476 // when resizing any child of the content view, rather than resizing the views
466 // directly. If the view is already the correct height, does not force a 477 // directly. If the view is already the correct height, does not force a
467 // relayout. 478 // relayout.
468 - (void)resizeView:(NSView*)view newHeight:(float)height { 479 - (void)resizeView:(NSView*)view newHeight:(float)height {
469 // We should only ever be called for one of the following three views. 480 // We should only ever be called for one of the following four views.
470 // |downloadShelfController_| may be nil. 481 // |downloadShelfController_| may be nil.
471 DCHECK(view); 482 DCHECK(view);
472 DCHECK(view == [toolbarController_ view] || 483 DCHECK(view == [toolbarController_ view] ||
473 view == [infoBarContainerController_ view] || 484 view == [infoBarContainerController_ view] ||
474 view == [downloadShelfController_ view]); 485 view == [downloadShelfController_ view] ||
486 view == [extensionShelfController_ view]);
475 487
476 // Change the height of the view and call layoutViews. We set the height here 488 // Change the height of the view and call layoutViews. We set the height here
477 // without regard to where the view is on the screen or whether it needs to 489 // without regard to where the view is on the screen or whether it needs to
478 // "grow up" or "grow down." The below call to layoutSubviews will position 490 // "grow up" or "grow down." The below call to layoutSubviews will position
479 // each view correctly. 491 // each view correctly.
480 NSRect frame = [view frame]; 492 NSRect frame = [view frame];
481 if (frame.size.height == height) 493 if (frame.size.height == height)
482 return; 494 return;
483 495
484 frame.size.height = height; 496 frame.size.height = height;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // Called when another part of the internal codebase needs to execute a 620 // Called when another part of the internal codebase needs to execute a
609 // command. 621 // command.
610 - (void)executeCommand:(int)command { 622 - (void)executeCommand:(int)command {
611 if (browser_->command_updater()->IsCommandEnabled(command)) 623 if (browser_->command_updater()->IsCommandEnabled(command))
612 browser_->ExecuteCommand(command); 624 browser_->ExecuteCommand(command);
613 } 625 }
614 626
615 // StatusBubble delegate method: tell the status bubble how far above the bottom 627 // StatusBubble delegate method: tell the status bubble how far above the bottom
616 // of the window it should position itself. 628 // of the window it should position itself.
617 - (float)verticalOffsetForStatusBubble { 629 - (float)verticalOffsetForStatusBubble {
618 float offset = 0.0; 630 return verticalOffsetForStatusBubble_;
619
620 // Don't create a download shelf if there isn't one.
621 if (downloadShelfController_.get() && [[self downloadShelf] isVisible])
622 offset += [[self downloadShelf] height];
623
624 return offset;
625 } 631 }
626 632
627 - (GTMWindowSheetController*)sheetController { 633 - (GTMWindowSheetController*)sheetController {
628 return [tabStripController_ sheetController]; 634 return [tabStripController_ sheetController];
629 } 635 }
630 636
631 - (LocationBar*)locationBar { 637 - (LocationBar*)locationBar {
632 return [toolbarController_ locationBar]; 638 return [toolbarController_ locationBar];
633 } 639 }
634 640
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 - (BOOL)isTabFullyVisible:(TabView*)tab { 826 - (BOOL)isTabFullyVisible:(TabView*)tab {
821 return [tabStripController_ isTabFullyVisible:tab]; 827 return [tabStripController_ isTabFullyVisible:tab];
822 } 828 }
823 829
824 - (void)showNewTabButton:(BOOL)show { 830 - (void)showNewTabButton:(BOOL)show {
825 [tabStripController_ showNewTabButton:show]; 831 [tabStripController_ showNewTabButton:show];
826 } 832 }
827 833
828 - (BOOL)isBookmarkBarVisible { 834 - (BOOL)isBookmarkBarVisible {
829 return [[toolbarController_ bookmarkBarController] isBookmarkBarVisible]; 835 return [[toolbarController_ bookmarkBarController] isBookmarkBarVisible];
830
831 } 836 }
832 837
833 - (void)toggleBookmarkBar { 838 - (void)toggleBookmarkBar {
834 BookmarkBarController* bar = [toolbarController_ bookmarkBarController]; 839 BookmarkBarController* bar = [toolbarController_ bookmarkBarController];
835 [bar toggleBookmarkBar]; 840 [bar toggleBookmarkBar];
836 } 841 }
837 842
838 - (BOOL)isDownloadShelfVisible { 843 - (BOOL)isDownloadShelfVisible {
839 return downloadShelfController_ != nil && 844 return downloadShelfController_ != nil &&
840 [downloadShelfController_ isVisible]; 845 [downloadShelfController_ isVisible];
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 [toolbarView setFrame:toolbarFrame]; 1240 [toolbarView setFrame:toolbarFrame];
1236 1241
1237 // Place the infobar container in place below the toolbar. 1242 // Place the infobar container in place below the toolbar.
1238 NSView* infoBarView = [infoBarContainerController_ view]; 1243 NSView* infoBarView = [infoBarContainerController_ view];
1239 NSRect infoBarFrame = [infoBarView frame]; 1244 NSRect infoBarFrame = [infoBarView frame];
1240 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); 1245 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame);
1241 infoBarFrame.size.width = NSWidth(contentFrame); 1246 infoBarFrame.size.width = NSWidth(contentFrame);
1242 [infoBarView setFrame:infoBarFrame]; 1247 [infoBarView setFrame:infoBarFrame];
1243 maxY -= NSHeight(infoBarFrame); 1248 maxY -= NSHeight(infoBarFrame);
1244 1249
1245 // Place the download shelf at the bottom of the view, if it exists. 1250 // Place the extension shelf at the bottom of the view, if it exists.
1251 if (extensionShelfController_.get()) {
1252 NSView* extensionView = [extensionShelfController_ view];
1253 NSRect extensionFrame = [extensionView frame];
1254 extensionFrame.origin.y = minY;
1255 extensionFrame.size.width = NSWidth(contentFrame);
1256 [extensionView setFrame:extensionFrame];
1257 minY += NSHeight(extensionFrame);
1258 }
1259
1260 // Place the download shelf above the extension shelf, if it exists.
1246 if (downloadShelfController_.get()) { 1261 if (downloadShelfController_.get()) {
1247 NSView* downloadView = [downloadShelfController_ view]; 1262 NSView* downloadView = [downloadShelfController_ view];
1248 NSRect downloadFrame = [downloadView frame]; 1263 NSRect downloadFrame = [downloadView frame];
1249 downloadFrame.origin.y = minY; 1264 downloadFrame.origin.y = minY;
1250 downloadFrame.size.width = NSWidth(contentFrame); 1265 downloadFrame.size.width = NSWidth(contentFrame);
1251 [downloadView setFrame:downloadFrame]; 1266 [downloadView setFrame:downloadFrame];
1252 minY += NSHeight(downloadFrame); 1267 minY += NSHeight(downloadFrame);
1253 } 1268 }
1254 1269
1255 // Finally, the tabContentArea takes up all of the remaining space. 1270 // Finally, the tabContentArea takes up all of the remaining space.
1256 NSView* tabContentView = [self tabContentArea]; 1271 NSView* tabContentView = [self tabContentArea];
1257 NSRect tabContentFrame = [tabContentView frame]; 1272 NSRect tabContentFrame = [tabContentView frame];
1258 tabContentFrame.origin.y = minY; 1273 tabContentFrame.origin.y = minY;
1259 tabContentFrame.size.height = maxY - minY; 1274 tabContentFrame.size.height = maxY - minY;
1260 tabContentFrame.size.width = NSWidth(contentFrame); 1275 tabContentFrame.size.width = NSWidth(contentFrame);
1261 [tabContentView setFrame:tabContentFrame]; 1276 [tabContentView setFrame:tabContentFrame];
1262 1277
1263 // Position the find bar relative to the infobar container. 1278 // Position the find bar relative to the infobar container.
1264 [findBarCocoaController_ 1279 [findBarCocoaController_
1265 positionFindBarView:[infoBarContainerController_ view]]; 1280 positionFindBarView:[infoBarContainerController_ view]];
1281
1282 verticalOffsetForStatusBubble_ = minY;
1266 } 1283 }
1267 1284
1268 @end 1285 @end
1269 1286
1270 @implementation GTMTheme (BrowserThemeProviderInitialization) 1287 @implementation GTMTheme (BrowserThemeProviderInitialization)
1271 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider 1288 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider
1272 isOffTheRecord:(BOOL)isOffTheRecord { 1289 isOffTheRecord:(BOOL)isOffTheRecord {
1273 // First check if it's in the cache. 1290 // First check if it's in the cache.
1274 // TODO(pinkerton): This might be a good candidate for a singleton. 1291 // TODO(pinkerton): This might be a good candidate for a singleton.
1275 typedef std::pair<std::string, BOOL> ThemeKey; 1292 typedef std::pair<std::string, BOOL> ThemeKey;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR); 1409 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR);
1393 [theme setValue:toolbarBackgroundColor 1410 [theme setValue:toolbarBackgroundColor
1394 forAttribute:@"backgroundColor" 1411 forAttribute:@"backgroundColor"
1395 style:GTMThemeStyleToolBar 1412 style:GTMThemeStyleToolBar
1396 state:GTMThemeStateActiveWindow]; 1413 state:GTMThemeStateActiveWindow];
1397 1414
1398 return theme; 1415 return theme;
1399 } 1416 }
1400 @end 1417 @end
1401 1418
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/extension_shelf_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698