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

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

Issue 3228003: Sidebar view, implementation for Mac. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/tab_strip_controller.h" 5 #import "chrome/browser/cocoa/tab_strip_controller.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 #import "chrome/browser/cocoa/constrained_window_mac.h" 24 #import "chrome/browser/cocoa/constrained_window_mac.h"
25 #import "chrome/browser/cocoa/new_tab_button.h" 25 #import "chrome/browser/cocoa/new_tab_button.h"
26 #import "chrome/browser/cocoa/tab_strip_view.h" 26 #import "chrome/browser/cocoa/tab_strip_view.h"
27 #import "chrome/browser/cocoa/tab_contents_controller.h" 27 #import "chrome/browser/cocoa/tab_contents_controller.h"
28 #import "chrome/browser/cocoa/tab_controller.h" 28 #import "chrome/browser/cocoa/tab_controller.h"
29 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" 29 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
30 #import "chrome/browser/cocoa/tab_view.h" 30 #import "chrome/browser/cocoa/tab_view.h"
31 #import "chrome/browser/cocoa/throbber_view.h" 31 #import "chrome/browser/cocoa/throbber_view.h"
32 #include "chrome/browser/debugger/devtools_window.h" 32 #include "chrome/browser/debugger/devtools_window.h"
33 #include "chrome/browser/net/url_fixer_upper.h" 33 #include "chrome/browser/net/url_fixer_upper.h"
34 #include "chrome/browser/sidebar/sidebar_container.h"
35 #include "chrome/browser/sidebar/sidebar_manager.h"
34 #include "chrome/browser/tab_contents/navigation_controller.h" 36 #include "chrome/browser/tab_contents/navigation_controller.h"
35 #include "chrome/browser/tab_contents/navigation_entry.h" 37 #include "chrome/browser/tab_contents/navigation_entry.h"
36 #include "chrome/browser/tab_contents/tab_contents.h" 38 #include "chrome/browser/tab_contents/tab_contents.h"
37 #include "chrome/browser/tab_contents/tab_contents_view.h" 39 #include "chrome/browser/tab_contents/tab_contents_view.h"
38 #include "chrome/browser/tabs/tab_strip_model.h" 40 #include "chrome/browser/tabs/tab_strip_model.h"
39 #include "grit/app_resources.h" 41 #include "grit/app_resources.h"
40 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
41 #include "grit/theme_resources.h" 43 #include "grit/theme_resources.h"
42 #include "skia/ext/skia_utils_mac.h" 44 #include "skia/ext/skia_utils_mac.h"
43 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 45 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 [tabContentsArray_ objectAtIndex:index]; 1041 [tabContentsArray_ objectAtIndex:index];
1040 [newController willBecomeSelectedTab]; 1042 [newController willBecomeSelectedTab];
1041 1043
1042 // Relayout for new tabs and to let the selected tab grow to be larger in 1044 // Relayout for new tabs and to let the selected tab grow to be larger in
1043 // size than surrounding tabs if the user has many. This also raises the 1045 // size than surrounding tabs if the user has many. This also raises the
1044 // selected tab to the top. 1046 // selected tab to the top.
1045 [self layoutTabs]; 1047 [self layoutTabs];
1046 1048
1047 // Swap in the contents for the new tab. 1049 // Swap in the contents for the new tab.
1048 [self swapInTabAtIndex:modelIndex]; 1050 [self swapInTabAtIndex:modelIndex];
1051 [self updateSidebarForContents:newContents];
1049 [self updateDevToolsForContents:newContents]; 1052 [self updateDevToolsForContents:newContents];
1050 1053
1051 if (newContents) { 1054 if (newContents) {
1052 newContents->DidBecomeSelected(); 1055 newContents->DidBecomeSelected();
1053 newContents->view()->RestoreFocus(); 1056 newContents->view()->RestoreFocus();
1054 1057
1055 if (newContents->find_ui_active()) 1058 if (newContents->find_ui_active())
1056 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); 1059 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection();
1057 } 1060 }
1058 } 1061 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1149
1147 TabController* tab = [tabArray_ objectAtIndex:index]; 1150 TabController* tab = [tabArray_ objectAtIndex:index];
1148 if (tabStripModel_->count() > 0) { 1151 if (tabStripModel_->count() > 0) {
1149 [self startClosingTabWithAnimation:tab]; 1152 [self startClosingTabWithAnimation:tab];
1150 [self layoutTabs]; 1153 [self layoutTabs];
1151 } else { 1154 } else {
1152 [self removeTab:tab]; 1155 [self removeTab:tab];
1153 } 1156 }
1154 1157
1155 // Does nothing, purely for consistency with the windows/linux code. 1158 // Does nothing, purely for consistency with the windows/linux code.
1159 [self updateSidebarForContents:NULL];
1156 [self updateDevToolsForContents:NULL]; 1160 [self updateDevToolsForContents:NULL];
1157 1161
1158 // Send a broadcast that the number of tabs have changed. 1162 // Send a broadcast that the number of tabs have changed.
1159 [[NSNotificationCenter defaultCenter] 1163 [[NSNotificationCenter defaultCenter]
1160 postNotificationName:kTabStripNumberOfTabsChanged 1164 postNotificationName:kTabStripNumberOfTabsChanged
1161 object:self]; 1165 object:self];
1162 } 1166 }
1163 1167
1164 // A helper routine for creating an NSImageView to hold the fav icon or app icon 1168 // A helper routine for creating an NSImageView to hold the fav icon or app icon
1165 // for |contents|. 1169 // for |contents|.
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 } 1785 }
1782 1786
1783 - (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { 1787 - (void)attachConstrainedWindow:(ConstrainedWindowMac*)window {
1784 // TODO(thakis, avi): Figure out how to make this work when tabs are dragged 1788 // TODO(thakis, avi): Figure out how to make this work when tabs are dragged
1785 // out or if fullscreen mode is toggled. 1789 // out or if fullscreen mode is toggled.
1786 1790
1787 // View hierarchy of the contents view: 1791 // View hierarchy of the contents view:
1788 // NSView -- switchView, same for all tabs 1792 // NSView -- switchView, same for all tabs
1789 // +- NSView -- TabContentsController's view 1793 // +- NSView -- TabContentsController's view
1790 // +- NSSplitView 1794 // +- NSSplitView
1791 // +- TabContentsViewCocoa 1795 // +- NSSplitView
1796 // +- TabContentsViewCocoa
1792 // We use the TabContentsController's view in |swapInTabAtIndex|, so we have 1797 // We use the TabContentsController's view in |swapInTabAtIndex|, so we have
1793 // to pass it to the sheet controller here. 1798 // to pass it to the sheet controller here.
1794 NSView* tabContentsView = 1799 NSView* tabContentsView =
1795 [[window->owner()->GetNativeView() superview] superview]; 1800 [[[window->owner()->GetNativeView() superview] superview] superview];
1796 window->delegate()->RunSheet([self sheetController], tabContentsView); 1801 window->delegate()->RunSheet([self sheetController], tabContentsView);
1797 1802
1798 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets 1803 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets
1799 // between windows. Until then, we have to prevent having to move a tabsheet 1804 // between windows. Until then, we have to prevent having to move a tabsheet
1800 // between windows, e.g. no tearing off of tabs. 1805 // between windows, e.g. no tearing off of tabs.
1801 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; 1806 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView];
1802 NSInteger index = [self indexFromModelIndex:modelIndex]; 1807 NSInteger index = [self indexFromModelIndex:modelIndex];
1803 BrowserWindowController* controller = 1808 BrowserWindowController* controller =
1804 (BrowserWindowController*)[[switchView_ window] windowController]; 1809 (BrowserWindowController*)[[switchView_ window] windowController];
1805 DCHECK(controller != nil); 1810 DCHECK(controller != nil);
1806 DCHECK(index >= 0); 1811 DCHECK(index >= 0);
1807 if (index >= 0) { 1812 if (index >= 0) {
1808 [controller setTab:[self viewAtIndex:index] isDraggable:NO]; 1813 [controller setTab:[self viewAtIndex:index] isDraggable:NO];
1809 } 1814 }
1810 } 1815 }
1811 1816
1812 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { 1817 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window {
1813 NSView* tabContentsView = 1818 NSView* tabContentsView =
1814 [[window->owner()->GetNativeView() superview] superview]; 1819 [[[window->owner()->GetNativeView() superview] superview] superview];
1815 1820
1816 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets 1821 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets
1817 // between windows. Until then, we have to prevent having to move a tabsheet 1822 // between windows. Until then, we have to prevent having to move a tabsheet
1818 // between windows, e.g. no tearing off of tabs. 1823 // between windows, e.g. no tearing off of tabs.
1819 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; 1824 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView];
1820 NSInteger index = [self indexFromModelIndex:modelIndex]; 1825 NSInteger index = [self indexFromModelIndex:modelIndex];
1821 BrowserWindowController* controller = 1826 BrowserWindowController* controller =
1822 (BrowserWindowController*)[[switchView_ window] windowController]; 1827 (BrowserWindowController*)[[switchView_ window] windowController];
1823 DCHECK(index >= 0); 1828 DCHECK(index >= 0);
1824 if (index >= 0) { 1829 if (index >= 0) {
(...skipping 14 matching lines...) Expand all
1839 if (index < 0 || index >= (NSInteger)[tabContentsArray_ count]) 1844 if (index < 0 || index >= (NSInteger)[tabContentsArray_ count])
1840 return; 1845 return;
1841 1846
1842 TabContentsController* tabController = 1847 TabContentsController* tabController =
1843 [tabContentsArray_ objectAtIndex:index]; 1848 [tabContentsArray_ objectAtIndex:index];
1844 TabContents* devtoolsContents = contents ? 1849 TabContents* devtoolsContents = contents ?
1845 DevToolsWindow::GetDevToolsContents(contents) : NULL; 1850 DevToolsWindow::GetDevToolsContents(contents) : NULL;
1846 [tabController showDevToolsContents:devtoolsContents]; 1851 [tabController showDevToolsContents:devtoolsContents];
1847 } 1852 }
1848 1853
1854 // This function is very similar to updateDevToolsContents.
1855 // TODO(alekseys): refactor and move both to browser window.
1856 // I (alekseys) intend to do it very soon.
1857 - (void)updateSidebarForContents:(TabContents*)contents {
1858 if (SidebarManager::GetInstance() == NULL) // Happens in tests.
1859 return;
1860
1861 int modelIndex = tabStripModel_->GetIndexOfTabContents(contents);
1862
1863 // This happens e.g. if one hits cmd-q with sidebar expanded.
1864 if (modelIndex == TabStripModel::kNoTab)
1865 return;
1866
1867 NSInteger index = [self indexFromModelIndex:modelIndex];
1868 DCHECK_GE(index, 0);
1869 DCHECK_LT(index, (NSInteger)[tabContentsArray_ count]);
1870 if (index < 0 || index >= (NSInteger)[tabContentsArray_ count])
1871 return;
1872
1873 TabContentsController* tabController =
1874 [tabContentsArray_ objectAtIndex:index];
1875 TabContents* sidebar_contents = NULL;
1876 if (contents && SidebarManager::IsSidebarAllowed()) {
1877 SidebarContainer* active_sidebar =
1878 SidebarManager::GetInstance()->GetActiveSidebarContainerFor(contents);
1879 if (active_sidebar)
1880 sidebar_contents = active_sidebar->sidebar_contents();
1881 }
1882 TabContents* old_sidebar_contents = [tabController sidebarContents];
1883 [tabController showSidebarContents:sidebar_contents];
1884 SidebarManager::GetInstance()->NotifyStateChanges(
1885 old_sidebar_contents, sidebar_contents);
1886 }
1887
1849 @end 1888 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.h ('k') | chrome/browser/cocoa/view_id_util_browsertest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698