OLD | NEW |
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/ui/cocoa/sidebar_controller.h" | 5 #import "chrome/browser/ui/cocoa/sidebar_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include <Cocoa/Cocoa.h> | 9 #include <Cocoa/Cocoa.h> |
10 | 10 |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/sidebar/sidebar_manager.h" | 13 #include "chrome/browser/sidebar/sidebar_manager.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // By default sidebar width is 1/7th of the current page content width. | 21 // By default sidebar width is 1/7th of the current page content width. |
21 const CGFloat kDefaultSidebarWidthRatio = 1.0 / 7; | 22 const CGFloat kDefaultSidebarWidthRatio = 1.0 / 7; |
22 | 23 |
23 // Never make the web part of the tab contents smaller than this (needed if the | 24 // Never make the web part of the tab contents smaller than this (needed if the |
24 // window is only a few pixels wide). | 25 // window is only a few pixels wide). |
25 const int kMinWebWidth = 50; | 26 const int kMinWebWidth = 50; |
(...skipping 30 matching lines...) Expand all Loading... |
56 } | 57 } |
57 | 58 |
58 - (NSSplitView*)view { | 59 - (NSSplitView*)view { |
59 return splitView_.get(); | 60 return splitView_.get(); |
60 } | 61 } |
61 | 62 |
62 - (NSSplitView*)splitView { | 63 - (NSSplitView*)splitView { |
63 return splitView_.get(); | 64 return splitView_.get(); |
64 } | 65 } |
65 | 66 |
66 - (void)updateSidebarForTabContents:(TabContents*)contents { | 67 - (void)updateSidebarForTab:(TabContentsWrapper*)tab { |
67 // Get the active sidebar content. | 68 // Get the active sidebar content. |
68 if (SidebarManager::GetInstance() == NULL) // Happens in tests. | 69 if (SidebarManager::GetInstance() == NULL) // Happens in tests. |
69 return; | 70 return; |
70 | 71 |
| 72 TabContents* contents = tab ? tab->tab_contents() : NULL; |
| 73 |
71 TabContents* sidebarContents = NULL; | 74 TabContents* sidebarContents = NULL; |
72 if (contents && SidebarManager::IsSidebarAllowed()) { | 75 if (contents && SidebarManager::IsSidebarAllowed()) { |
73 SidebarContainer* activeSidebar = | 76 SidebarContainer* activeSidebar = |
74 SidebarManager::GetInstance()->GetActiveSidebarContainerFor(contents); | 77 SidebarManager::GetInstance()->GetActiveSidebarContainerFor(tab); |
75 if (activeSidebar) | 78 if (activeSidebar) |
76 sidebarContents = activeSidebar->sidebar_contents(); | 79 sidebarContents = activeSidebar->sidebar_contents(); |
77 } | 80 } |
78 | 81 |
79 TabContents* oldSidebarContents = [contentsController_ tabContents]; | 82 TabContents* oldSidebarContents = [contentsController_ tabContents]; |
80 if (oldSidebarContents == sidebarContents) | 83 if (oldSidebarContents == sidebarContents) |
81 return; | 84 return; |
82 | 85 |
83 // Adjust sidebar view. | 86 // Adjust sidebar view. |
84 [self showSidebarContents:sidebarContents]; | 87 [self showSidebarContents:sidebarContents]; |
85 | 88 |
86 // Notify extensions. | 89 // Notify extensions. |
87 SidebarManager::GetInstance()->NotifyStateChanges( | 90 SidebarManager::GetInstance()->NotifyStateChanges( |
88 oldSidebarContents, sidebarContents); | 91 oldSidebarContents, sidebarContents); |
89 } | 92 } |
90 | 93 |
91 - (void)ensureContentsVisible { | 94 - (void)ensureContentsVisible { |
92 [contentsController_ ensureContentsVisible]; | 95 [contentsController_ ensureContentsVisible]; |
93 } | 96 } |
94 | 97 |
95 - (void)showSidebarContents:(TabContents*)sidebarContents { | 98 - (void)showSidebarContents:(TabContents*)sidebarContents { |
96 [contentsController_ ensureContentsSizeDoesNotChange]; | 99 [contentsController_ ensureContentsSizeDoesNotChange]; |
97 | 100 |
98 NSArray* subviews = [splitView_ subviews]; | 101 NSArray* subviews = [splitView_ subviews]; |
99 if (sidebarContents) { | 102 if (sidebarContents) { |
100 DCHECK_GE([subviews count], 1u); | 103 DCHECK_GE([subviews count], 1u); |
101 | 104 |
102 // Native view is a TabContentsViewCocoa object, whose ViewID was | 105 // Native view is a TabContentsViewCocoa object, whose ViewID was |
103 // set to VIEW_ID_TAB_CONTAINER initially, so change it to | 106 // set to VIEW_ID_TAB_CONTAINER initially, so change it to |
104 // VIEW_ID_SIDE_BAR_CONTAINER here. | 107 // VIEW_ID_SIDEBAR_CONTAINER here. |
105 view_id_util::SetID( | 108 view_id_util::SetID( |
106 sidebarContents->GetNativeView(), VIEW_ID_SIDE_BAR_CONTAINER); | 109 sidebarContents->GetNativeView(), VIEW_ID_SIDEBAR_CONTAINER); |
107 | 110 |
108 CGFloat sidebarWidth = 0; | 111 CGFloat sidebarWidth = 0; |
109 if ([subviews count] == 1) { | 112 if ([subviews count] == 1) { |
110 // Load the default split offset. | 113 // Load the default split offset. |
111 sidebarWidth = g_browser_process->local_state()->GetInteger( | 114 sidebarWidth = g_browser_process->local_state()->GetInteger( |
112 prefs::kExtensionSidebarWidth); | 115 prefs::kExtensionSidebarWidth); |
113 if (sidebarWidth < 0) { | 116 if (sidebarWidth < 0) { |
114 // Initial load, set to default value. | 117 // Initial load, set to default value. |
115 sidebarWidth = | 118 sidebarWidth = |
116 NSWidth([splitView_ frame]) * kDefaultSidebarWidthRatio; | 119 NSWidth([splitView_ frame]) * kDefaultSidebarWidthRatio; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 - (BOOL)splitView:(NSSplitView *)splitView | 172 - (BOOL)splitView:(NSSplitView *)splitView |
170 shouldAdjustSizeOfSubview:(NSView *)subview { | 173 shouldAdjustSizeOfSubview:(NSView *)subview { |
171 // Return NO for the sidebar view to indicate that it should not be resized | 174 // Return NO for the sidebar view to indicate that it should not be resized |
172 // automatically. The sidebar keeps the width set by the user. | 175 // automatically. The sidebar keeps the width set by the user. |
173 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 176 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
174 return NO; | 177 return NO; |
175 return YES; | 178 return YES; |
176 } | 179 } |
177 | 180 |
178 @end | 181 @end |
OLD | NEW |