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

Side by Side Diff: chrome/browser/cocoa/extensions/browser_actions_controller.mm

Issue 1001001: [Mac] Do not take Browser Actions Container view changes into account in inco... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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 "browser_actions_controller.h" 5 #import "browser_actions_controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 - (void)createButtons { 167 - (void)createButtons {
168 // No extensions in incognito mode. 168 // No extensions in incognito mode.
169 if (!toolbarModel_) 169 if (!toolbarModel_)
170 return; 170 return;
171 171
172 NSUInteger i = 0; 172 NSUInteger i = 0;
173 for (ExtensionList::iterator iter = toolbarModel_->begin(); 173 for (ExtensionList::iterator iter = toolbarModel_->begin();
174 iter != toolbarModel_->end(); ++iter) { 174 iter != toolbarModel_->end(); ++iter) {
175 if (![self shouldDisplayBrowserAction:*iter])
176 continue;
177
175 [self createActionButtonForExtension:*iter withIndex:i++]; 178 [self createActionButtonForExtension:*iter withIndex:i++];
176 } 179 }
177 180
178 CGFloat width = [self savedWidth]; 181 CGFloat width = [self savedWidth];
179 // The width will never be 0 (due to the container's minimum size restriction) 182 // The width will never be 0 (due to the container's minimum size restriction)
180 // except when no width has been saved. In this case, set the width to be as 183 // except when no width has been saved. In this case, set the width to be as
181 // if all buttons are shown. 184 // if all buttons are shown.
182 if (width == 0) 185 if (width == 0)
183 width = [self containerWidthWithButtonCount:[self buttonCount]]; 186 width = [self containerWidthWithButtonCount:[self buttonCount]];
184 187
185 [containerView_ resizeToWidth:width animate:NO]; 188 [containerView_ resizeToWidth:width animate:NO];
186 } 189 }
187 190
188 - (void)createActionButtonForExtension:(Extension*)extension 191 - (void)createActionButtonForExtension:(Extension*)extension
189 withIndex:(NSUInteger)index { 192 withIndex:(NSUInteger)index {
190 if (!extension->browser_action()) 193 if (!extension->browser_action())
191 return; 194 return;
192 195
193 if (![self shouldDisplayBrowserAction:extension]) 196 if (![self shouldDisplayBrowserAction:extension])
194 return; 197 return;
195 198
199 if (profile_->IsOffTheRecord())
200 index = toolbarModel_->OriginalIndexToIncognito(index);
201
196 // Show the container if it's the first button. Otherwise it will be shown 202 // Show the container if it's the first button. Otherwise it will be shown
197 // already. 203 // already.
198 if ([buttons_ count] == 0) 204 if ([buttons_ count] == 0)
199 [containerView_ setHidden:NO]; 205 [containerView_ setHidden:NO];
200 206
201 BrowserActionButton* newButton = [[[BrowserActionButton alloc] 207 BrowserActionButton* newButton = [[[BrowserActionButton alloc]
202 initWithExtension:extension 208 initWithExtension:extension
203 profile:profile_ 209 profile:profile_
204 tabId:[self currentTabId]] autorelease]; 210 tabId:[self currentTabId]] autorelease];
205 [newButton setTarget:self]; 211 [newButton setTarget:self];
(...skipping 12 matching lines...) Expand all
218 224
219 - (void)removeActionButtonForExtension:(Extension*)extension { 225 - (void)removeActionButtonForExtension:(Extension*)extension {
220 if (!extension->browser_action()) 226 if (!extension->browser_action())
221 return; 227 return;
222 228
223 NSString* buttonKey = base::SysUTF8ToNSString(extension->id()); 229 NSString* buttonKey = base::SysUTF8ToNSString(extension->id());
224 if (!buttonKey) 230 if (!buttonKey)
225 return; 231 return;
226 232
227 BrowserActionButton* button = [buttons_ objectForKey:buttonKey]; 233 BrowserActionButton* button = [buttons_ objectForKey:buttonKey];
228 if (!button) { 234 // This could be the case in incognito, where only a subset of extensions are
229 NOTREACHED(); 235 // shown.
236 if (!button)
230 return; 237 return;
231 } 238
232 [button removeFromSuperview]; 239 [button removeFromSuperview];
233 [buttons_ removeObjectForKey:buttonKey]; 240 [buttons_ removeObjectForKey:buttonKey];
234 if ([buttons_ count] == 0) { 241 if ([buttons_ count] == 0) {
235 // No more buttons? Hide the container. 242 // No more buttons? Hide the container.
236 [containerView_ setHidden:YES]; 243 [containerView_ setHidden:YES];
237 } else { 244 } else {
238 [self repositionActionButtons]; 245 [self repositionActionButtons];
239 } 246 }
240 [containerView_ setNeedsDisplay:YES]; 247 [containerView_ setNeedsDisplay:YES];
241 } 248 }
242 249
243 - (void)repositionActionButtons { 250 - (void)repositionActionButtons {
244 NSUInteger i = 0; 251 NSUInteger i = 0;
245 for (ExtensionList::iterator iter = toolbarModel_->begin(); 252 for (ExtensionList::iterator iter = toolbarModel_->begin();
246 iter != toolbarModel_->end(); ++iter) { 253 iter != toolbarModel_->end(); ++iter) {
254 if (![self shouldDisplayBrowserAction:*iter])
255 continue;
256
247 CGFloat xOffset = kGrippyXOffset + 257 CGFloat xOffset = kGrippyXOffset +
248 (i * (kBrowserActionWidth + kBrowserActionButtonPadding)); 258 (i * (kBrowserActionWidth + kBrowserActionButtonPadding));
249 NSString* extensionId = base::SysUTF8ToNSString((*iter)->id()); 259 NSString* extensionId = base::SysUTF8ToNSString((*iter)->id());
250 DCHECK(extensionId); 260 DCHECK(extensionId);
251 if (!extensionId) 261 if (!extensionId)
252 continue; 262 continue;
253 BrowserActionButton* button = [buttons_ objectForKey:extensionId]; 263 BrowserActionButton* button = [buttons_ objectForKey:extensionId];
254 NSRect buttonFrame = [button frame]; 264 NSRect buttonFrame = [button frame];
255 buttonFrame.origin.x = xOffset; 265 buttonFrame.origin.x = xOffset;
256 [button setFrame:buttonFrame]; 266 [button setFrame:buttonFrame];
(...skipping 10 matching lines...) Expand all
267 return width; 277 return width;
268 } 278 }
269 279
270 // Resizes the container given the number of visible buttons in the container, 280 // Resizes the container given the number of visible buttons in the container,
271 // taking into account the size of the grippy. Also updates the persistent 281 // taking into account the size of the grippy. Also updates the persistent
272 // width preference. 282 // width preference.
273 - (void)resizeContainerWithAnimation:(BOOL)animate { 283 - (void)resizeContainerWithAnimation:(BOOL)animate {
274 CGFloat width = 284 CGFloat width =
275 [self containerWidthWithButtonCount:[self visibleButtonCount]]; 285 [self containerWidthWithButtonCount:[self visibleButtonCount]];
276 [containerView_ resizeToWidth:width animate:animate]; 286 [containerView_ resizeToWidth:width animate:animate];
277 profile_->GetPrefs()->SetReal(prefs::kBrowserActionContainerWidth, 287
278 NSWidth([containerView_ frame])); 288 if (!profile_->IsOffTheRecord())
289 profile_->GetPrefs()->SetReal(prefs::kBrowserActionContainerWidth,
290 NSWidth([containerView_ frame]));
279 291
280 [[NSNotificationCenter defaultCenter] 292 [[NSNotificationCenter defaultCenter]
281 postNotificationName:kBrowserActionVisibilityChangedNotification 293 postNotificationName:kBrowserActionVisibilityChangedNotification
282 object:self]; 294 object:self];
283 } 295 }
284 296
285 - (void)updateButtonOpacityAndDragAbilities { 297 - (void)updateButtonOpacityAndDragAbilities {
286 for (BrowserActionButton* button in [buttons_ allValues]) { 298 for (BrowserActionButton* button in [buttons_ allValues]) {
287 NSRect buttonFrame = [button frame]; 299 NSRect buttonFrame = [button frame];
288 buttonFrame.origin.x += kButtonOpacityLeadPadding; 300 buttonFrame.origin.x += kButtonOpacityLeadPadding;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 iter != toolbarModel_->end(); ++iter) { 417 iter != toolbarModel_->end(); ++iter) {
406 if (i == index) 418 if (i == index)
407 return [buttons_ objectForKey:base::SysUTF8ToNSString((*iter)->id())]; 419 return [buttons_ objectForKey:base::SysUTF8ToNSString((*iter)->id())];
408 420
409 ++i; 421 ++i;
410 } 422 }
411 return nil; 423 return nil;
412 } 424 }
413 425
414 - (bool)shouldDisplayBrowserAction:(Extension*)extension { 426 - (bool)shouldDisplayBrowserAction:(Extension*)extension {
427 // Only display incognito-enabled extensions while in incognito mode.
415 return (!profile_->IsOffTheRecord() || 428 return (!profile_->IsOffTheRecord() ||
416 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); 429 profile_->GetExtensionsService()->IsIncognitoEnabled(extension));
417 } 430 }
418 431
419 - (CGFloat)savedWidth { 432 - (CGFloat)savedWidth {
433 // Don't use the standard saved width for incognito until a separate pref is
434 // added.
435 if (profile_->IsOffTheRecord())
436 return 0.0;
437
420 return profile_->GetPrefs()->GetReal(prefs::kBrowserActionContainerWidth); 438 return profile_->GetPrefs()->GetReal(prefs::kBrowserActionContainerWidth);
421 } 439 }
422 440
423 + (void)registerUserPrefs:(PrefService*)prefs { 441 + (void)registerUserPrefs:(PrefService*)prefs {
424 prefs->RegisterRealPref(prefs::kBrowserActionContainerWidth, 0); 442 prefs->RegisterRealPref(prefs::kBrowserActionContainerWidth, 0);
425 } 443 }
426 444
427 @end 445 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.mm ('k') | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698