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

Side by Side Diff: ios/chrome/browser/ui/toolbar/toolbar_controller.mm

Issue 2808873002: [ObjC ARC] Converts ios/chrome/browser/ui/toolbar:toolbar to ARC. (Closed)
Patch Set: [ObjC ARC] Converts ios/chrome/browser/ui/toolbar:toolbar to ARC. Created 3 years, 8 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "ios/chrome/browser/ui/toolbar/toolbar_controller.h" 5 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h"
6 6
7 #include <QuartzCore/QuartzCore.h> 7 #include <QuartzCore/QuartzCore.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 // Macros for creating CGRects of height H, origin (0,0), with the portrait 70 // Macros for creating CGRects of height H, origin (0,0), with the portrait
71 // width of phone/pad devices. 71 // width of phone/pad devices.
72 // clang-format off 72 // clang-format off
73 #define IPHONE_FRAME(H) { { 0, 0 }, { kPortraitWidth[IPHONE_IDIOM], H } } 73 #define IPHONE_FRAME(H) { { 0, 0 }, { kPortraitWidth[IPHONE_IDIOM], H } }
74 #define IPAD_FRAME(H) { { 0, 0 }, { kPortraitWidth[IPAD_IDIOM], H } } 74 #define IPAD_FRAME(H) { { 0, 0 }, { kPortraitWidth[IPAD_IDIOM], H } }
75 75
76 // Makes a two-element C array of CGRects as described above, one for each 76 // Makes a two-element C array of CGRects as described above, one for each
77 // device idiom. 77 // device idiom.
78 #define FRAME_PAIR(H) { IPHONE_FRAME(H), IPAD_FRAME(H) } 78 #define FRAME_PAIR(H) { IPHONE_FRAME(H), IPAD_FRAME(H) }
79
80 #if !defined(__has_feature) || !__has_feature(objc_arc)
81 #error "This file requires ARC support."
82 #endif
79 // clang-format on 83 // clang-format on
80 84
81 const CGRect kToolbarFrame[INTERFACE_IDIOM_COUNT] = FRAME_PAIR(56); 85 const CGRect kToolbarFrame[INTERFACE_IDIOM_COUNT] = FRAME_PAIR(56);
82 86
83 namespace { 87 namespace {
84 88
85 // Color constants for the stack button text, normal and pressed states. These 89 // Color constants for the stack button text, normal and pressed states. These
86 // arrays are indexed by ToolbarControllerStyle enum values. 90 // arrays are indexed by ToolbarControllerStyle enum values.
87 const CGFloat kStackButtonNormalColors[] = { 91 const CGFloat kStackButtonNormalColors[] = {
88 85.0 / 255.0, // ToolbarControllerStyleLightMode 92 85.0 / 255.0, // ToolbarControllerStyleLightMode
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // explicit transition animations. 198 // explicit transition animations.
195 if (self.animatingTransition) 199 if (self.animatingTransition)
196 return (id<CAAction>)[NSNull null]; 200 return (id<CAAction>)[NSNull null];
197 return [super actionForLayer:layer forKey:event]; 201 return [super actionForLayer:layer forKey:event];
198 } 202 }
199 203
200 @end 204 @end
201 205
202 @interface ToolbarController () { 206 @interface ToolbarController () {
203 // The top-level toolbar view. 207 // The top-level toolbar view.
204 base::scoped_nsobject<ToolbarView> view_; 208 ToolbarView* view_;
stkhapugin 2017/04/10 15:57:51 You should be able to synthesize the first three i
205 // The view for the toolbar background image. 209 // The view for the toolbar background image.
206 base::scoped_nsobject<UIImageView> backgroundView_; 210 UIImageView* backgroundView_;
207 base::scoped_nsobject<UIImageView> shadowView_; 211 UIImageView* shadowView_;
208 base::scoped_nsobject<UIImageView> fullBleedShadowView_; 212 UIImageView* fullBleedShadowView_;
209 213
210 // The backing object for |self.transitionLayers|. 214 // The backing object for |self.transitionLayers|.
211 base::scoped_nsobject<NSMutableArray> transitionLayers_; 215 NSMutableArray* transitionLayers_;
212 216
213 base::scoped_nsobject<ToolbarToolsMenuButton> toolsMenuButton_; 217 ToolbarToolsMenuButton* toolsMenuButton_;
214 base::scoped_nsobject<UIButton> stackButton_; 218 UIButton* stackButton_;
215 base::scoped_nsobject<UIButton> shareButton_; 219 UIButton* shareButton_;
216 base::scoped_nsobject<NSArray> standardButtons_; 220 NSArray* standardButtons_;
217 base::scoped_nsobject<ToolsMenuButtonObserverBridge> 221 ToolsMenuButtonObserverBridge* toolsMenuButtonObserverBridge_;
218 toolsMenuButtonObserverBridge_;
219 ToolbarControllerStyle style_; 222 ToolbarControllerStyle style_;
220 223
221 // The following is nil if not visible. 224 // The following is nil if not visible.
222 base::scoped_nsobject<ToolsPopupController> toolsPopupController_; 225 ToolsPopupController* toolsPopupController_;
223 } 226 }
224 227
225 // Returns the background image that should be used for |style|. 228 // Returns the background image that should be used for |style|.
226 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style; 229 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style;
227 230
228 // Whether the share button should be visible in the toolbar. 231 // Whether the share button should be visible in the toolbar.
229 - (BOOL)shareButtonShouldBeVisible; 232 - (BOOL)shareButtonShouldBeVisible;
230 233
231 // Update share button visibility and |standardButtons_| array. 234 // Update share button visibility and |standardButtons_| array.
232 - (void)updateStandardButtons; 235 - (void)updateStandardButtons;
(...skipping 11 matching lines...) Expand all
244 247
245 @implementation ToolbarController 248 @implementation ToolbarController
246 249
247 @synthesize readingListModel = readingListModel_; 250 @synthesize readingListModel = readingListModel_;
248 251
249 @synthesize style = style_; 252 @synthesize style = style_;
250 253
251 - (void)setReadingListModel:(ReadingListModel*)readingListModel { 254 - (void)setReadingListModel:(ReadingListModel*)readingListModel {
252 readingListModel_ = readingListModel; 255 readingListModel_ = readingListModel;
253 if (readingListModel_) { 256 if (readingListModel_) {
254 toolsMenuButtonObserverBridge_.reset([[ToolsMenuButtonObserverBridge alloc] 257 toolsMenuButtonObserverBridge_ =
255 initWithModel:readingListModel_ 258 [[ToolsMenuButtonObserverBridge alloc] initWithModel:readingListModel_
256 toolbarButton:toolsMenuButton_]); 259 toolbarButton:toolsMenuButton_];
257 } 260 }
258 } 261 }
259 262
260 - (instancetype)initWithStyle:(ToolbarControllerStyle)style { 263 - (instancetype)initWithStyle:(ToolbarControllerStyle)style {
261 self = [super init]; 264 self = [super init];
262 if (self) { 265 if (self) {
263 style_ = style; 266 style_ = style;
264 DCHECK_LT(style_, ToolbarControllerStyleMaxStyles); 267 DCHECK_LT(style_, ToolbarControllerStyleMaxStyles);
265 268
266 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM; 269 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM;
267 CGRect viewFrame = kToolbarFrame[idiom]; 270 CGRect viewFrame = kToolbarFrame[idiom];
268 CGRect backgroundFrame = kBackgroundViewFrame[idiom]; 271 CGRect backgroundFrame = kBackgroundViewFrame[idiom];
269 CGRect stackButtonFrame = LayoutRectGetRect(kStackButtonFrame); 272 CGRect stackButtonFrame = LayoutRectGetRect(kStackButtonFrame);
270 CGRect toolsMenuButtonFrame = 273 CGRect toolsMenuButtonFrame =
271 LayoutRectGetRect(kToolsMenuButtonFrame[idiom]); 274 LayoutRectGetRect(kToolsMenuButtonFrame[idiom]);
272 275
273 if (idiom == IPHONE_IDIOM) { 276 if (idiom == IPHONE_IDIOM) {
274 CGFloat statusBarOffset = [self statusBarOffset]; 277 CGFloat statusBarOffset = [self statusBarOffset];
275 viewFrame.size.height += statusBarOffset; 278 viewFrame.size.height += statusBarOffset;
276 backgroundFrame.size.height += statusBarOffset; 279 backgroundFrame.size.height += statusBarOffset;
277 stackButtonFrame.origin.y += statusBarOffset; 280 stackButtonFrame.origin.y += statusBarOffset;
278 toolsMenuButtonFrame.origin.y += statusBarOffset; 281 toolsMenuButtonFrame.origin.y += statusBarOffset;
279 } 282 }
280 283
281 view_.reset([[ToolbarView alloc] initWithFrame:viewFrame]); 284 view_ = [[ToolbarView alloc] initWithFrame:viewFrame];
282 backgroundView_.reset([[UIImageView alloc] initWithFrame:backgroundFrame]); 285 backgroundView_ = [[UIImageView alloc] initWithFrame:backgroundFrame];
283 toolsMenuButton_.reset([[ToolbarToolsMenuButton alloc] 286 toolsMenuButton_ =
284 initWithFrame:toolsMenuButtonFrame 287 [[ToolbarToolsMenuButton alloc] initWithFrame:toolsMenuButtonFrame
285 style:style_]); 288 style:style_];
286 [toolsMenuButton_ setTag:IDC_SHOW_TOOLS_MENU]; 289 [toolsMenuButton_ setTag:IDC_SHOW_TOOLS_MENU];
287 [toolsMenuButton_ 290 [toolsMenuButton_
288 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() | 291 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
289 UIViewAutoresizingFlexibleBottomMargin]; 292 UIViewAutoresizingFlexibleBottomMargin];
290 293
291 [view_ addSubview:backgroundView_]; 294 [view_ addSubview:backgroundView_];
292 [view_ addSubview:toolsMenuButton_]; 295 [view_ addSubview:toolsMenuButton_];
293 [view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 296 [view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
294 [backgroundView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 297 [backgroundView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
295 UIViewAutoresizingFlexibleHeight]; 298 UIViewAutoresizingFlexibleHeight];
296 299
297 if (idiom == IPAD_IDIOM) { 300 if (idiom == IPAD_IDIOM) {
298 CGRect shareButtonFrame = LayoutRectGetRect(kShareMenuButtonFrame); 301 CGRect shareButtonFrame = LayoutRectGetRect(kShareMenuButtonFrame);
299 shareButton_.reset([[UIButton alloc] initWithFrame:shareButtonFrame]); 302 shareButton_ = [[UIButton alloc] initWithFrame:shareButtonFrame];
300 [shareButton_ setTag:IDC_SHARE_PAGE]; 303 [shareButton_ setTag:IDC_SHARE_PAGE];
301 [shareButton_ 304 [shareButton_
302 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() | 305 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
303 UIViewAutoresizingFlexibleBottomMargin]; 306 UIViewAutoresizingFlexibleBottomMargin];
304 [self setUpButton:shareButton_ 307 [self setUpButton:shareButton_
305 withImageEnum:ToolbarButtonNameShare 308 withImageEnum:ToolbarButtonNameShare
306 forInitialState:UIControlStateNormal 309 forInitialState:UIControlStateNormal
307 hasDisabledImage:YES 310 hasDisabledImage:YES
308 synchronously:NO]; 311 synchronously:NO];
309 SetA11yLabelAndUiAutomationName(shareButton_, IDS_IOS_TOOLS_MENU_SHARE, 312 SetA11yLabelAndUiAutomationName(shareButton_, IDS_IOS_TOOLS_MENU_SHARE,
310 kToolbarShareButtonIdentifier); 313 kToolbarShareButtonIdentifier);
311 [view_ addSubview:shareButton_]; 314 [view_ addSubview:shareButton_];
312 } 315 }
313 316
314 CGRect shadowFrame = kShadowViewFrame[idiom]; 317 CGRect shadowFrame = kShadowViewFrame[idiom];
315 shadowFrame.origin.y = CGRectGetMaxY(backgroundFrame); 318 shadowFrame.origin.y = CGRectGetMaxY(backgroundFrame);
316 shadowView_.reset([[UIImageView alloc] initWithFrame:shadowFrame]); 319 shadowView_ = [[UIImageView alloc] initWithFrame:shadowFrame];
317 [shadowView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 320 [shadowView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
318 [shadowView_ setUserInteractionEnabled:NO]; 321 [shadowView_ setUserInteractionEnabled:NO];
319 [view_ addSubview:shadowView_]; 322 [view_ addSubview:shadowView_];
320 [shadowView_ setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; 323 [shadowView_ setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)];
321 324
322 if (idiom == IPHONE_IDIOM) { 325 if (idiom == IPHONE_IDIOM) {
323 // iPad omnibox does not expand to full bleed. 326 // iPad omnibox does not expand to full bleed.
324 CGRect fullBleedShadowFrame = kFullBleedShadowViewFrame; 327 CGRect fullBleedShadowFrame = kFullBleedShadowViewFrame;
325 fullBleedShadowFrame.origin.y = shadowFrame.origin.y; 328 fullBleedShadowFrame.origin.y = shadowFrame.origin.y;
326 fullBleedShadowView_.reset( 329 fullBleedShadowView_ =
327 [[UIImageView alloc] initWithFrame:fullBleedShadowFrame]); 330 [[UIImageView alloc] initWithFrame:fullBleedShadowFrame];
328 [fullBleedShadowView_ 331 [fullBleedShadowView_
329 setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 332 setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
330 [fullBleedShadowView_ setUserInteractionEnabled:NO]; 333 [fullBleedShadowView_ setUserInteractionEnabled:NO];
331 [fullBleedShadowView_ setAlpha:0]; 334 [fullBleedShadowView_ setAlpha:0];
332 [view_ addSubview:fullBleedShadowView_]; 335 [view_ addSubview:fullBleedShadowView_];
333 [fullBleedShadowView_ 336 [fullBleedShadowView_
334 setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)]; 337 setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)];
335 } 338 }
336 339
337 transitionLayers_.reset( 340 transitionLayers_ =
338 [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity]); 341 [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity];
339 342
340 // UIImageViews do not default to userInteractionEnabled:YES. 343 // UIImageViews do not default to userInteractionEnabled:YES.
341 [view_ setUserInteractionEnabled:YES]; 344 [view_ setUserInteractionEnabled:YES];
342 [backgroundView_ setUserInteractionEnabled:YES]; 345 [backgroundView_ setUserInteractionEnabled:YES];
343 346
344 UIImage* tile = [self getBackgroundImageForStyle:style]; 347 UIImage* tile = [self getBackgroundImageForStyle:style];
345 [[self backgroundView] 348 [[self backgroundView]
346 setImage:StretchableImageFromUIImage(tile, 0.0, 3.0)]; 349 setImage:StretchableImageFromUIImage(tile, 0.0, 3.0)];
347 350
348 if (idiom == IPHONE_IDIOM) { 351 if (idiom == IPHONE_IDIOM) {
349 stackButton_.reset( 352 stackButton_ =
350 [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame]); 353 [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame];
351 [stackButton_ setTag:IDC_TOGGLE_TAB_SWITCHER]; 354 [stackButton_ setTag:IDC_TOGGLE_TAB_SWITCHER];
352 [[stackButton_ titleLabel] 355 [[stackButton_ titleLabel]
353 setFont:[self fontForSize:kFontSizeFewerThanTenTabs]]; 356 setFont:[self fontForSize:kFontSizeFewerThanTenTabs]];
354 [stackButton_ 357 [stackButton_
355 setTitleColor:[UIColor colorWithWhite:kStackButtonNormalColors[style_] 358 setTitleColor:[UIColor colorWithWhite:kStackButtonNormalColors[style_]
356 alpha:1.0] 359 alpha:1.0]
357 forState:UIControlStateNormal]; 360 forState:UIControlStateNormal];
358 UIColor* highlightColor = 361 UIColor* highlightColor =
359 UIColorFromRGB(kStackButtonHighlightedColors[style_], 1.0); 362 UIColorFromRGB(kStackButtonHighlightedColors[style_], 1.0);
360 [stackButton_ setTitleColor:highlightColor 363 [stackButton_ setTitleColor:highlightColor
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return nil; 403 return nil;
401 } 404 }
402 405
403 - (UIFont*)fontForSize:(NSInteger)size { 406 - (UIFont*)fontForSize:(NSInteger)size {
404 return [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:size]; 407 return [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:size];
405 } 408 }
406 409
407 - (void)dealloc { 410 - (void)dealloc {
408 [[NSNotificationCenter defaultCenter] removeObserver:self]; 411 [[NSNotificationCenter defaultCenter] removeObserver:self];
409 [toolsPopupController_ setDelegate:nil]; 412 [toolsPopupController_ setDelegate:nil];
410 [super dealloc];
411 } 413 }
412 414
413 - (UIImageView*)view { 415 - (UIImageView*)view {
414 return view_.get(); 416 return view_;
415 } 417 }
416 418
417 - (UIImageView*)backgroundView { 419 - (UIImageView*)backgroundView {
418 return backgroundView_.get(); 420 return backgroundView_;
419 } 421 }
420 422
421 - (CGFloat)statusBarOffset { 423 - (CGFloat)statusBarOffset {
422 return StatusBarHeight(); 424 return StatusBarHeight();
423 } 425 }
424 426
425 - (UIImageView*)shadowView { 427 - (UIImageView*)shadowView {
426 return shadowView_.get(); 428 return shadowView_;
427 } 429 }
428 430
429 - (NSMutableArray*)transitionLayers { 431 - (NSMutableArray*)transitionLayers {
430 return transitionLayers_.get(); 432 return transitionLayers_;
431 } 433 }
432 434
433 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum { 435 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum {
434 // None of the images this class knows about should flip. 436 // None of the images this class knows about should flip.
435 return NO; 437 return NO;
436 } 438 }
437 439
438 - (void)updateStandardButtons { 440 - (void)updateStandardButtons {
439 BOOL shareButtonShouldBeVisible = [self shareButtonShouldBeVisible]; 441 BOOL shareButtonShouldBeVisible = [self shareButtonShouldBeVisible];
440 [shareButton_ setHidden:!shareButtonShouldBeVisible]; 442 [shareButton_ setHidden:!shareButtonShouldBeVisible];
441 NSMutableArray* standardButtons = [NSMutableArray array]; 443 NSMutableArray* standardButtons = [NSMutableArray array];
442 [standardButtons addObject:toolsMenuButton_]; 444 [standardButtons addObject:toolsMenuButton_];
443 if (stackButton_) 445 if (stackButton_)
444 [standardButtons addObject:stackButton_]; 446 [standardButtons addObject:stackButton_];
445 if (shareButtonShouldBeVisible) 447 if (shareButtonShouldBeVisible)
446 [standardButtons addObject:shareButton_]; 448 [standardButtons addObject:shareButton_];
447 standardButtons_.reset([standardButtons retain]); 449 standardButtons_ = standardButtons;
448 } 450 }
449 451
450 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 452 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
451 [self updateStandardButtons]; 453 [self updateStandardButtons];
452 } 454 }
453 455
454 - (ToolsPopupController*)toolsPopupController { 456 - (ToolsPopupController*)toolsPopupController {
455 return toolsPopupController_.get(); 457 return toolsPopupController_;
456 } 458 }
457 459
458 - (void)applicationDidEnterBackground:(NSNotification*)notify { 460 - (void)applicationDidEnterBackground:(NSNotification*)notify {
459 if (toolsPopupController_.get()) { 461 if (toolsPopupController_) {
460 // Dismiss the tools popup menu without animation. 462 // Dismiss the tools popup menu without animation.
461 [toolsMenuButton_ setToolsMenuIsVisible:NO]; 463 [toolsMenuButton_ setToolsMenuIsVisible:NO];
462 toolsPopupController_.reset(nil); 464 toolsPopupController_ = nil;
463 [[NSNotificationCenter defaultCenter] 465 [[NSNotificationCenter defaultCenter]
464 postNotificationName:kMenuWillHideNotification 466 postNotificationName:kMenuWillHideNotification
465 object:nil]; 467 object:nil];
466 } 468 }
467 } 469 }
468 470
469 - (BOOL)shareButtonShouldBeVisible { 471 - (BOOL)shareButtonShouldBeVisible {
470 // The share button only exists on iPad, and when some tabs are visible 472 // The share button only exists on iPad, and when some tabs are visible
471 // (i.e. when not in DarkMode), and when the width is greater than 473 // (i.e. when not in DarkMode), and when the width is greater than
472 // the tablet mini view. 474 // the tablet mini view.
(...skipping 10 matching lines...) Expand all
483 485
484 - (UIImage*)imageForImageEnum:(int)imageEnum 486 - (UIImage*)imageForImageEnum:(int)imageEnum
485 forState:(ToolbarButtonUIState)state { 487 forState:(ToolbarButtonUIState)state {
486 int imageID = 488 int imageID =
487 [self imageIdForImageEnum:imageEnum style:[self style] forState:state]; 489 [self imageIdForImageEnum:imageEnum style:[self style] forState:state];
488 return NativeReversableImage( 490 return NativeReversableImage(
489 imageID, [self imageShouldFlipForRightToLeftLayoutDirection:imageEnum]); 491 imageID, [self imageShouldFlipForRightToLeftLayoutDirection:imageEnum]);
490 } 492 }
491 493
492 - (int)imageEnumForButton:(UIButton*)button { 494 - (int)imageEnumForButton:(UIButton*)button {
493 if (button == stackButton_.get()) 495 if (button == stackButton_)
494 return ToolbarButtonNameStack; 496 return ToolbarButtonNameStack;
495 return NumberOfToolbarButtonNames; 497 return NumberOfToolbarButtonNames;
496 } 498 }
497 499
498 - (int)imageIdForImageEnum:(int)index 500 - (int)imageIdForImageEnum:(int)index
499 style:(ToolbarControllerStyle)style 501 style:(ToolbarControllerStyle)style
500 forState:(ToolbarButtonUIState)state { 502 forState:(ToolbarButtonUIState)state {
501 DCHECK(index < NumberOfToolbarButtonNames); 503 DCHECK(index < NumberOfToolbarButtonNames);
502 DCHECK(style < ToolbarControllerStyleMaxStyles); 504 DCHECK(style < ToolbarControllerStyleMaxStyles);
503 DCHECK(state < NumberOfToolbarButtonUIStates); 505 DCHECK(state < NumberOfToolbarButtonUIStates);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if (synchronously || initialState == UIControlStateDisabled) { 558 if (synchronously || initialState == UIControlStateDisabled) {
557 disabledImageBlock(); 559 disabledImageBlock();
558 } else { 560 } else {
559 dispatch_after(addImageDelay, dispatch_get_main_queue(), 561 dispatch_after(addImageDelay, dispatch_get_main_queue(),
560 disabledImageBlock); 562 disabledImageBlock);
561 } 563 }
562 } 564 }
563 } 565 }
564 566
565 - (void)registerEventsForButton:(UIButton*)button { 567 - (void)registerEventsForButton:(UIButton*)button {
566 if (button != toolsMenuButton_.get()) { 568 if (button != toolsMenuButton_) {
567 // |target| must be |self| (as opposed to |nil|) because |self| isn't in the 569 // |target| must be |self| (as opposed to |nil|) because |self| isn't in the
568 // responder chain. 570 // responder chain.
569 [button addTarget:self 571 [button addTarget:self
570 action:@selector(standardButtonPressed:) 572 action:@selector(standardButtonPressed:)
571 forControlEvents:UIControlEventTouchUpInside]; 573 forControlEvents:UIControlEventTouchUpInside];
572 } 574 }
573 [button addTarget:self 575 [button addTarget:self
574 action:@selector(recordUserMetrics:) 576 action:@selector(recordUserMetrics:)
575 forControlEvents:UIControlEventTouchUpInside]; 577 forControlEvents:UIControlEventTouchUpInside];
576 [button addTarget:button 578 [button addTarget:button
577 action:@selector(chromeExecuteCommand:) 579 action:@selector(chromeExecuteCommand:)
578 forControlEvents:UIControlEventTouchUpInside]; 580 forControlEvents:UIControlEventTouchUpInside];
579 } 581 }
580 582
581 - (CGRect)shareButtonAnchorRect { 583 - (CGRect)shareButtonAnchorRect {
582 // Shrink the padding around the shareButton so the popovers are anchored 584 // Shrink the padding around the shareButton so the popovers are anchored
583 // correctly. 585 // correctly.
584 return CGRectInset([shareButton_ bounds], 10, 0); 586 return CGRectInset([shareButton_ bounds], 10, 0);
585 } 587 }
586 588
587 - (UIView*)shareButtonView { 589 - (UIView*)shareButtonView {
588 return shareButton_.get(); 590 return shareButton_;
589 } 591 }
590 592
591 - (void)showToolsMenuPopupWithConfiguration: 593 - (void)showToolsMenuPopupWithConfiguration:
592 (ToolsMenuConfiguration*)configuration { 594 (ToolsMenuConfiguration*)configuration {
593 // Because an animation hides and shows the tools popup menu it is possible to 595 // Because an animation hides and shows the tools popup menu it is possible to
594 // tap the tools button multiple times before the tools menu is shown. Ignore 596 // tap the tools button multiple times before the tools menu is shown. Ignore
595 // repeated taps between animations. 597 // repeated taps between animations.
596 if (toolsPopupController_) 598 if (toolsPopupController_)
597 return; 599 return;
598 600
599 base::RecordAction(UserMetricsAction("ShowAppMenu")); 601 base::RecordAction(UserMetricsAction("ShowAppMenu"));
600 602
601 // Keep the button pressed. 603 // Keep the button pressed.
602 [toolsMenuButton_ setToolsMenuIsVisible:YES]; 604 [toolsMenuButton_ setToolsMenuIsVisible:YES];
603 605
604 [configuration setToolsMenuButton:toolsMenuButton_]; 606 [configuration setToolsMenuButton:toolsMenuButton_];
605 toolsPopupController_.reset( 607 toolsPopupController_ =
606 [[ToolsPopupController alloc] initWithConfiguration:configuration]); 608 [[ToolsPopupController alloc] initWithConfiguration:configuration];
607 609
608 [toolsPopupController_ setDelegate:self]; 610 [toolsPopupController_ setDelegate:self];
609 611
610 [[NSNotificationCenter defaultCenter] 612 [[NSNotificationCenter defaultCenter]
611 postNotificationName:kMenuWillShowNotification 613 postNotificationName:kMenuWillShowNotification
612 object:nil]; 614 object:nil];
613 } 615 }
614 616
615 - (void)dismissToolsMenuPopup { 617 - (void)dismissToolsMenuPopup {
616 if (!toolsPopupController_.get()) 618 if (!toolsPopupController_)
617 return; 619 return;
618 ToolsPopupController* tempTPC = toolsPopupController_.get(); 620 ToolsPopupController* tempTPC = toolsPopupController_;
619 [tempTPC containerView].userInteractionEnabled = NO; 621 [tempTPC containerView].userInteractionEnabled = NO;
620 [tempTPC dismissAnimatedWithCompletion:^{ 622 [tempTPC dismissAnimatedWithCompletion:^{
621 // Unpress the tools menu button by restoring the normal and 623 // Unpress the tools menu button by restoring the normal and
622 // highlighted images to their usual state. 624 // highlighted images to their usual state.
623 [toolsMenuButton_ setToolsMenuIsVisible:NO]; 625 [toolsMenuButton_ setToolsMenuIsVisible:NO];
624 // Reference tempTPC so the block retains it. 626 // Reference tempTPC so the block retains it.
625 [tempTPC self]; 627 [tempTPC self];
626 }]; 628 }];
627 // reset tabHistoryPopupController_ to prevent -applicationDidEnterBackground 629 // reset tabHistoryPopupController_ to prevent -applicationDidEnterBackground
628 // from posting another kMenuWillHideNotification. 630 // from posting another kMenuWillHideNotification.
629 toolsPopupController_.reset(); 631 toolsPopupController_ = nil;
630 632
631 [[NSNotificationCenter defaultCenter] 633 [[NSNotificationCenter defaultCenter]
632 postNotificationName:kMenuWillHideNotification 634 postNotificationName:kMenuWillHideNotification
633 object:nil]; 635 object:nil];
634 } 636 }
635 637
636 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style { 638 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style {
637 int backgroundImageID; 639 int backgroundImageID;
638 if (style == ToolbarControllerStyleLightMode) 640 if (style == ToolbarControllerStyleLightMode)
639 backgroundImageID = IDR_IOS_TOOLBAR_LIGHT_BACKGROUND; 641 backgroundImageID = IDR_IOS_TOOLBAR_LIGHT_BACKGROUND;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 // Animate the opacity of the buttons to 0. 680 // Animate the opacity of the buttons to 0.
679 [CATransaction begin]; 681 [CATransaction begin];
680 [CATransaction setAnimationDuration:ios::material::kDuration2]; 682 [CATransaction setAnimationDuration:ios::material::kDuration2];
681 [CATransaction 683 [CATransaction
682 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)]; 684 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)];
683 CABasicAnimation* fadeButtons = 685 CABasicAnimation* fadeButtons =
684 [CABasicAnimation animationWithKeyPath:@"opacity"]; 686 [CABasicAnimation animationWithKeyPath:@"opacity"];
685 fadeButtons.fromValue = @1; 687 fadeButtons.fromValue = @1;
686 fadeButtons.toValue = @0; 688 fadeButtons.toValue = @0;
687 689
688 for (UIButton* button in standardButtons_.get()) { 690 for (UIButton* button in standardButtons_) {
689 if (![button isHidden]) { 691 if (![button isHidden]) {
690 [button layer].opacity = 0; 692 [button layer].opacity = 0;
691 [[button layer] addAnimation:fadeButtons forKey:@"fade"]; 693 [[button layer] addAnimation:fadeButtons forKey:@"fade"];
692 } 694 }
693 } 695 }
694 [CATransaction commit]; 696 [CATransaction commit];
695 697
696 // Animate the buttons 10 pixels in the leading-to-trailing direction 698 // Animate the buttons 10 pixels in the leading-to-trailing direction
697 [CATransaction begin]; 699 [CATransaction begin];
698 [CATransaction setAnimationDuration:ios::material::kDuration1]; 700 [CATransaction setAnimationDuration:ios::material::kDuration1];
699 [CATransaction 701 [CATransaction
700 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)]; 702 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)];
701 703
702 for (UIButton* button in standardButtons_.get()) { 704 for (UIButton* button in standardButtons_) {
703 CABasicAnimation* shiftButton = 705 CABasicAnimation* shiftButton =
704 [CABasicAnimation animationWithKeyPath:@"position"]; 706 [CABasicAnimation animationWithKeyPath:@"position"];
705 CGPoint startPosition = [button layer].position; 707 CGPoint startPosition = [button layer].position;
706 CGPoint endPosition = 708 CGPoint endPosition =
707 CGPointLayoutOffset(startPosition, kButtonFadeOutXOffset); 709 CGPointLayoutOffset(startPosition, kButtonFadeOutXOffset);
708 shiftButton.fromValue = [NSValue valueWithCGPoint:startPosition]; 710 shiftButton.fromValue = [NSValue valueWithCGPoint:startPosition];
709 shiftButton.toValue = [NSValue valueWithCGPoint:endPosition]; 711 shiftButton.toValue = [NSValue valueWithCGPoint:endPosition];
710 [[button layer] addAnimation:shiftButton forKey:@"shiftButton"]; 712 [[button layer] addAnimation:shiftButton forKey:@"shiftButton"];
711 } 713 }
712 714
713 [CATransaction commit]; 715 [CATransaction commit];
714 716
715 // Fade to the full bleed shadow. 717 // Fade to the full bleed shadow.
716 [UIView animateWithDuration:ios::material::kDuration1 718 [UIView animateWithDuration:ios::material::kDuration1
717 animations:^{ 719 animations:^{
718 [shadowView_ setAlpha:0]; 720 [shadowView_ setAlpha:0];
719 [fullBleedShadowView_ setAlpha:1]; 721 [fullBleedShadowView_ setAlpha:1];
720 }]; 722 }];
721 } 723 }
722 724
723 - (void)fadeInStandardControls { 725 - (void)fadeInStandardControls {
724 for (UIButton* button in standardButtons_.get()) { 726 for (UIButton* button in standardButtons_) {
725 [self fadeInView:button 727 [self fadeInView:button
726 fromLeadingOffset:10 728 fromLeadingOffset:10
727 withDuration:ios::material::kDuration2 729 withDuration:ios::material::kDuration2
728 afterDelay:ios::material::kDuration1]; 730 afterDelay:ios::material::kDuration1];
729 } 731 }
730 732
731 // Fade to the normal shadow. 733 // Fade to the normal shadow.
732 [UIView animateWithDuration:ios::material::kDuration1 734 [UIView animateWithDuration:ios::material::kDuration1
733 animations:^{ 735 animations:^{
734 [shadowView_ setAlpha:self.backgroundView.alpha]; 736 [shadowView_ setAlpha:self.backgroundView.alpha];
735 [fullBleedShadowView_ setAlpha:0]; 737 [fullBleedShadowView_ setAlpha:0];
736 }]; 738 }];
737 } 739 }
738 740
739 - (void)animationDidStart:(CAAnimation*)anim { 741 - (void)animationDidStart:(CAAnimation*)anim {
740 // Once the buttons start fading in, set their opacity to 1 so there's no 742 // Once the buttons start fading in, set their opacity to 1 so there's no
741 // flicker at the end of the animation. 743 // flicker at the end of the animation.
742 for (UIButton* button in standardButtons_.get()) { 744 for (UIButton* button in standardButtons_) {
743 if (anim == [[button layer] animationForKey:@"fadeIn"]) { 745 if (anim == [[button layer] animationForKey:@"fadeIn"]) {
744 [button layer].opacity = 1; 746 [button layer].opacity = 1;
745 return; 747 return;
746 } 748 }
747 } 749 }
748 } 750 }
749 751
750 - (void)fadeInView:(UIView*)view 752 - (void)fadeInView:(UIView*)view
751 fromLeadingOffset:(LayoutOffset)leadingOffset 753 fromLeadingOffset:(LayoutOffset)leadingOffset
752 withDuration:(NSTimeInterval)duration 754 withDuration:(NSTimeInterval)duration
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 transitionStyle:style]; 928 transitionStyle:style];
927 } 929 }
928 930
929 - (void)hideViewsForNewTabPage:(BOOL)hide { 931 - (void)hideViewsForNewTabPage:(BOOL)hide {
930 DCHECK(!IsIPadIdiom()); 932 DCHECK(!IsIPadIdiom());
931 [shadowView_ setHidden:hide]; 933 [shadowView_ setHidden:hide];
932 } 934 }
933 935
934 - (void)setStandardControlsVisible:(BOOL)visible { 936 - (void)setStandardControlsVisible:(BOOL)visible {
935 if (visible) { 937 if (visible) {
936 for (UIButton* button in standardButtons_.get()) { 938 for (UIButton* button in standardButtons_) {
937 [button setAlpha:1.0]; 939 [button setAlpha:1.0];
938 } 940 }
939 } else { 941 } else {
940 for (UIButton* button in standardButtons_.get()) { 942 for (UIButton* button in standardButtons_) {
941 [button setAlpha:0.0]; 943 [button setAlpha:0.0];
942 } 944 }
943 } 945 }
944 } 946 }
945 947
946 - (void)setStandardControlsAlpha:(CGFloat)alpha { 948 - (void)setStandardControlsAlpha:(CGFloat)alpha {
947 for (UIButton* button in standardButtons_.get()) { 949 for (UIButton* button in standardButtons_) {
948 if (![button isHidden]) 950 if (![button isHidden])
949 [button setAlpha:alpha]; 951 [button setAlpha:alpha];
950 } 952 }
951 } 953 }
952 954
953 - (void)setBackgroundAlpha:(CGFloat)alpha { 955 - (void)setBackgroundAlpha:(CGFloat)alpha {
954 [backgroundView_ setAlpha:alpha]; 956 [backgroundView_ setAlpha:alpha];
955 [shadowView_ setAlpha:alpha]; 957 [shadowView_ setAlpha:alpha];
956 } 958 }
957 959
958 - (void)setStandardControlsTransform:(CGAffineTransform)transform { 960 - (void)setStandardControlsTransform:(CGAffineTransform)transform {
959 for (UIButton* button in standardButtons_.get()) { 961 for (UIButton* button in standardButtons_) {
960 [button setTransform:transform]; 962 [button setTransform:transform];
961 } 963 }
962 } 964 }
963 965
964 - (void)standardButtonPressed:(UIButton*)sender { 966 - (void)standardButtonPressed:(UIButton*)sender {
965 // This check for valid button images assumes that the buttons all have a 967 // This check for valid button images assumes that the buttons all have a
966 // different image for the highlighted state as for the normal state. 968 // different image for the highlighted state as for the normal state.
967 // Currently, that assumption is true. 969 // Currently, that assumption is true.
968 if ([sender imageForState:UIControlStateHighlighted] == 970 if ([sender imageForState:UIControlStateHighlighted] ==
969 [sender imageForState:UIControlStateNormal]) { 971 [sender imageForState:UIControlStateNormal]) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 [[stackButton_ titleLabel] 1009 [[stackButton_ titleLabel]
1008 setFont:[self fontForSize:kFontSizeTenTabsOrMore]]; 1010 setFont:[self fontForSize:kFontSizeTenTabsOrMore]];
1009 } 1011 }
1010 } 1012 }
1011 1013
1012 [stackButton_ setTitle:stackButtonTitle forState:UIControlStateNormal]; 1014 [stackButton_ setTitle:stackButtonTitle forState:UIControlStateNormal];
1013 [stackButton_ setAccessibilityValue:stackButtonValue]; 1015 [stackButton_ setAccessibilityValue:stackButtonValue];
1014 } 1016 }
1015 1017
1016 - (IBAction)recordUserMetrics:(id)sender { 1018 - (IBAction)recordUserMetrics:(id)sender {
1017 if (sender == toolsMenuButton_.get()) 1019 if (sender == toolsMenuButton_)
1018 base::RecordAction(UserMetricsAction("MobileToolbarShowMenu")); 1020 base::RecordAction(UserMetricsAction("MobileToolbarShowMenu"));
1019 else if (sender == stackButton_.get()) 1021 else if (sender == stackButton_)
1020 base::RecordAction(UserMetricsAction("MobileToolbarShowStackView")); 1022 base::RecordAction(UserMetricsAction("MobileToolbarShowStackView"));
1021 else if (sender == shareButton_.get()) 1023 else if (sender == shareButton_)
1022 base::RecordAction(UserMetricsAction("MobileToolbarShareMenu")); 1024 base::RecordAction(UserMetricsAction("MobileToolbarShareMenu"));
1023 else 1025 else
1024 NOTREACHED(); 1026 NOTREACHED();
1025 } 1027 }
1026 1028
1027 - (IBAction)stackButtonTouchDown:(id)sender { 1029 - (IBAction)stackButtonTouchDown:(id)sender {
1028 // Exists only for override by subclasses. 1030 // Exists only for override by subclasses.
1029 } 1031 }
1030 1032
1031 + (CGFloat)toolbarDropShadowHeight { 1033 + (CGFloat)toolbarDropShadowHeight {
(...skipping 16 matching lines...) Expand all
1048 #pragma mark - 1050 #pragma mark -
1049 #pragma mark PopupMenuDelegate methods. 1051 #pragma mark PopupMenuDelegate methods.
1050 1052
1051 - (void)dismissPopupMenu:(PopupMenuController*)controller { 1053 - (void)dismissPopupMenu:(PopupMenuController*)controller {
1052 if ([controller isKindOfClass:[ToolsPopupController class]] && 1054 if ([controller isKindOfClass:[ToolsPopupController class]] &&
1053 (ToolsPopupController*)controller == toolsPopupController_) 1055 (ToolsPopupController*)controller == toolsPopupController_)
1054 [self dismissToolsMenuPopup]; 1056 [self dismissToolsMenuPopup];
1055 } 1057 }
1056 1058
1057 @end 1059 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698