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

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: feedback 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)
sdefresne 2017/04/28 08:02:50 This should move just below the "#include/#import"
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Don't allow UIView block-based animations if we're already performing 197 // Don't allow UIView block-based animations if we're already performing
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 shadow view. Only used on iPhone.
204 base::scoped_nsobject<ToolbarView> view_; 208 UIImageView* fullBleedShadowView_;
205 // The view for the toolbar background image.
206 base::scoped_nsobject<UIImageView> backgroundView_;
207 base::scoped_nsobject<UIImageView> shadowView_;
208 base::scoped_nsobject<UIImageView> fullBleedShadowView_;
209 209
210 // The backing object for |self.transitionLayers|. 210 // The backing object for |self.transitionLayers|.
211 base::scoped_nsobject<NSMutableArray> transitionLayers_; 211 NSMutableArray* transitionLayers_;
212 212
213 base::scoped_nsobject<ToolbarToolsMenuButton> toolsMenuButton_; 213 ToolbarToolsMenuButton* toolsMenuButton_;
214 base::scoped_nsobject<UIButton> stackButton_; 214 UIButton* stackButton_;
215 base::scoped_nsobject<UIButton> shareButton_; 215 UIButton* shareButton_;
216 base::scoped_nsobject<NSArray> standardButtons_; 216 NSArray* standardButtons_;
217 base::scoped_nsobject<ToolsMenuButtonObserverBridge> 217 ToolsMenuButtonObserverBridge* toolsMenuButtonObserverBridge_;
218 toolsMenuButtonObserverBridge_;
219 ToolbarControllerStyle style_; 218 ToolbarControllerStyle style_;
220 219
221 // The following is nil if not visible. 220 // The following is nil if not visible.
222 base::scoped_nsobject<ToolsPopupController> toolsPopupController_; 221 ToolsPopupController* toolsPopupController_;
223 } 222 }
224 223
225 // Returns the background image that should be used for |style|. 224 // Returns the background image that should be used for |style|.
226 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style; 225 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style;
227 226
228 // Whether the share button should be visible in the toolbar. 227 // Whether the share button should be visible in the toolbar.
229 - (BOOL)shareButtonShouldBeVisible; 228 - (BOOL)shareButtonShouldBeVisible;
230 229
231 // Update share button visibility and |standardButtons_| array. 230 // Update share button visibility and |standardButtons_| array.
232 - (void)updateStandardButtons; 231 - (void)updateStandardButtons;
233 232
234 // Returns an animation for |button| for a toolbar transition animation with 233 // Returns an animation for |button| for a toolbar transition animation with
235 // |style|. |button|'s frame will be interpolated between its layout in the 234 // |style|. |button|'s frame will be interpolated between its layout in the
236 // screen toolbar to the card's tab frame, and will be faded in for 235 // screen toolbar to the card's tab frame, and will be faded in for
237 // ToolbarTransitionStyleToStackView and faded out for 236 // ToolbarTransitionStyleToStackView and faded out for
238 // ToolbarTransitionStyleToBVC. 237 // ToolbarTransitionStyleToBVC.
239 - (CAAnimation*)transitionAnimationForButton:(UIButton*)button 238 - (CAAnimation*)transitionAnimationForButton:(UIButton*)button
240 containerBeginBounds:(CGRect)containerBeginBounds 239 containerBeginBounds:(CGRect)containerBeginBounds
241 containerEndBounds:(CGRect)containerEndBounds 240 containerEndBounds:(CGRect)containerEndBounds
242 withStyle:(ToolbarTransitionStyle)style; 241 withStyle:(ToolbarTransitionStyle)style;
243 @end 242 @end
244 243
245 @implementation ToolbarController 244 @implementation ToolbarController
246 245
247 @synthesize readingListModel = readingListModel_; 246 @synthesize readingListModel = readingListModel_;
248 247 @synthesize view = view_;
248 @synthesize backgroundView = backgroundView_;
249 @synthesize shadowView = shadowView_;
250 @synthesize toolsPopupController = toolsPopupController_;
249 @synthesize style = style_; 251 @synthesize style = style_;
250 252
251 - (void)setReadingListModel:(ReadingListModel*)readingListModel { 253 - (void)setReadingListModel:(ReadingListModel*)readingListModel {
252 readingListModel_ = readingListModel; 254 readingListModel_ = readingListModel;
253 if (readingListModel_) { 255 if (readingListModel_) {
254 toolsMenuButtonObserverBridge_.reset([[ToolsMenuButtonObserverBridge alloc] 256 toolsMenuButtonObserverBridge_ =
255 initWithModel:readingListModel_ 257 [[ToolsMenuButtonObserverBridge alloc] initWithModel:readingListModel_
256 toolbarButton:toolsMenuButton_]); 258 toolbarButton:toolsMenuButton_];
257 } 259 }
258 } 260 }
259 261
260 - (instancetype)initWithStyle:(ToolbarControllerStyle)style { 262 - (instancetype)initWithStyle:(ToolbarControllerStyle)style {
261 self = [super init]; 263 self = [super init];
262 if (self) { 264 if (self) {
263 style_ = style; 265 style_ = style;
264 DCHECK_LT(style_, ToolbarControllerStyleMaxStyles); 266 DCHECK_LT(style_, ToolbarControllerStyleMaxStyles);
265 267
266 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM; 268 InterfaceIdiom idiom = IsIPadIdiom() ? IPAD_IDIOM : IPHONE_IDIOM;
267 CGRect viewFrame = kToolbarFrame[idiom]; 269 CGRect viewFrame = kToolbarFrame[idiom];
268 CGRect backgroundFrame = kBackgroundViewFrame[idiom]; 270 CGRect backgroundFrame = kBackgroundViewFrame[idiom];
269 CGRect stackButtonFrame = LayoutRectGetRect(kStackButtonFrame); 271 CGRect stackButtonFrame = LayoutRectGetRect(kStackButtonFrame);
270 CGRect toolsMenuButtonFrame = 272 CGRect toolsMenuButtonFrame =
271 LayoutRectGetRect(kToolsMenuButtonFrame[idiom]); 273 LayoutRectGetRect(kToolsMenuButtonFrame[idiom]);
272 274
273 if (idiom == IPHONE_IDIOM) { 275 if (idiom == IPHONE_IDIOM) {
274 CGFloat statusBarOffset = [self statusBarOffset]; 276 CGFloat statusBarOffset = [self statusBarOffset];
275 viewFrame.size.height += statusBarOffset; 277 viewFrame.size.height += statusBarOffset;
276 backgroundFrame.size.height += statusBarOffset; 278 backgroundFrame.size.height += statusBarOffset;
277 stackButtonFrame.origin.y += statusBarOffset; 279 stackButtonFrame.origin.y += statusBarOffset;
278 toolsMenuButtonFrame.origin.y += statusBarOffset; 280 toolsMenuButtonFrame.origin.y += statusBarOffset;
279 } 281 }
280 282
281 view_.reset([[ToolbarView alloc] initWithFrame:viewFrame]); 283 view_ = [[ToolbarView alloc] initWithFrame:viewFrame];
282 backgroundView_.reset([[UIImageView alloc] initWithFrame:backgroundFrame]); 284 backgroundView_ = [[UIImageView alloc] initWithFrame:backgroundFrame];
283 toolsMenuButton_.reset([[ToolbarToolsMenuButton alloc] 285 toolsMenuButton_ =
284 initWithFrame:toolsMenuButtonFrame 286 [[ToolbarToolsMenuButton alloc] initWithFrame:toolsMenuButtonFrame
285 style:style_]); 287 style:style_];
286 [toolsMenuButton_ setTag:IDC_SHOW_TOOLS_MENU]; 288 [toolsMenuButton_ setTag:IDC_SHOW_TOOLS_MENU];
287 [toolsMenuButton_ 289 [toolsMenuButton_
288 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() | 290 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
289 UIViewAutoresizingFlexibleBottomMargin]; 291 UIViewAutoresizingFlexibleBottomMargin];
290 292
291 [view_ addSubview:backgroundView_]; 293 [view_ addSubview:backgroundView_];
292 [view_ addSubview:toolsMenuButton_]; 294 [view_ addSubview:toolsMenuButton_];
293 [view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 295 [view_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
294 [backgroundView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 296 [backgroundView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
295 UIViewAutoresizingFlexibleHeight]; 297 UIViewAutoresizingFlexibleHeight];
296 298
297 if (idiom == IPAD_IDIOM) { 299 if (idiom == IPAD_IDIOM) {
298 CGRect shareButtonFrame = LayoutRectGetRect(kShareMenuButtonFrame); 300 CGRect shareButtonFrame = LayoutRectGetRect(kShareMenuButtonFrame);
299 shareButton_.reset([[UIButton alloc] initWithFrame:shareButtonFrame]); 301 shareButton_ = [[UIButton alloc] initWithFrame:shareButtonFrame];
300 [shareButton_ setTag:IDC_SHARE_PAGE]; 302 [shareButton_ setTag:IDC_SHARE_PAGE];
301 [shareButton_ 303 [shareButton_
302 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() | 304 setAutoresizingMask:UIViewAutoresizingFlexibleLeadingMargin() |
303 UIViewAutoresizingFlexibleBottomMargin]; 305 UIViewAutoresizingFlexibleBottomMargin];
304 [self setUpButton:shareButton_ 306 [self setUpButton:shareButton_
305 withImageEnum:ToolbarButtonNameShare 307 withImageEnum:ToolbarButtonNameShare
306 forInitialState:UIControlStateNormal 308 forInitialState:UIControlStateNormal
307 hasDisabledImage:YES 309 hasDisabledImage:YES
308 synchronously:NO]; 310 synchronously:NO];
309 SetA11yLabelAndUiAutomationName(shareButton_, IDS_IOS_TOOLS_MENU_SHARE, 311 SetA11yLabelAndUiAutomationName(shareButton_, IDS_IOS_TOOLS_MENU_SHARE,
310 kToolbarShareButtonIdentifier); 312 kToolbarShareButtonIdentifier);
311 [view_ addSubview:shareButton_]; 313 [view_ addSubview:shareButton_];
312 } 314 }
313 315
314 CGRect shadowFrame = kShadowViewFrame[idiom]; 316 CGRect shadowFrame = kShadowViewFrame[idiom];
315 shadowFrame.origin.y = CGRectGetMaxY(backgroundFrame); 317 shadowFrame.origin.y = CGRectGetMaxY(backgroundFrame);
316 shadowView_.reset([[UIImageView alloc] initWithFrame:shadowFrame]); 318 shadowView_ = [[UIImageView alloc] initWithFrame:shadowFrame];
317 [shadowView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 319 [shadowView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
318 [shadowView_ setUserInteractionEnabled:NO]; 320 [shadowView_ setUserInteractionEnabled:NO];
319 [view_ addSubview:shadowView_]; 321 [view_ addSubview:shadowView_];
320 [shadowView_ setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; 322 [shadowView_ setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)];
321 323
322 if (idiom == IPHONE_IDIOM) { 324 if (idiom == IPHONE_IDIOM) {
323 // iPad omnibox does not expand to full bleed. 325 // iPad omnibox does not expand to full bleed.
324 CGRect fullBleedShadowFrame = kFullBleedShadowViewFrame; 326 CGRect fullBleedShadowFrame = kFullBleedShadowViewFrame;
325 fullBleedShadowFrame.origin.y = shadowFrame.origin.y; 327 fullBleedShadowFrame.origin.y = shadowFrame.origin.y;
326 fullBleedShadowView_.reset( 328 fullBleedShadowView_ =
327 [[UIImageView alloc] initWithFrame:fullBleedShadowFrame]); 329 [[UIImageView alloc] initWithFrame:fullBleedShadowFrame];
328 [fullBleedShadowView_ 330 [fullBleedShadowView_
329 setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 331 setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
330 [fullBleedShadowView_ setUserInteractionEnabled:NO]; 332 [fullBleedShadowView_ setUserInteractionEnabled:NO];
331 [fullBleedShadowView_ setAlpha:0]; 333 [fullBleedShadowView_ setAlpha:0];
332 [view_ addSubview:fullBleedShadowView_]; 334 [view_ addSubview:fullBleedShadowView_];
333 [fullBleedShadowView_ 335 [fullBleedShadowView_
334 setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)]; 336 setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)];
335 } 337 }
336 338
337 transitionLayers_.reset( 339 transitionLayers_ =
338 [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity]); 340 [[NSMutableArray alloc] initWithCapacity:kTransitionLayerCapacity];
339 341
340 // UIImageViews do not default to userInteractionEnabled:YES. 342 // UIImageViews do not default to userInteractionEnabled:YES.
341 [view_ setUserInteractionEnabled:YES]; 343 [view_ setUserInteractionEnabled:YES];
342 [backgroundView_ setUserInteractionEnabled:YES]; 344 [backgroundView_ setUserInteractionEnabled:YES];
343 345
344 UIImage* tile = [self getBackgroundImageForStyle:style]; 346 UIImage* tile = [self getBackgroundImageForStyle:style];
345 [[self backgroundView] 347 [[self backgroundView]
346 setImage:StretchableImageFromUIImage(tile, 0.0, 3.0)]; 348 setImage:StretchableImageFromUIImage(tile, 0.0, 3.0)];
347 349
348 if (idiom == IPHONE_IDIOM) { 350 if (idiom == IPHONE_IDIOM) {
349 stackButton_.reset( 351 stackButton_ =
350 [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame]); 352 [[ToolbarCenteredButton alloc] initWithFrame:stackButtonFrame];
351 [stackButton_ setTag:IDC_TOGGLE_TAB_SWITCHER]; 353 [stackButton_ setTag:IDC_TOGGLE_TAB_SWITCHER];
352 [[stackButton_ titleLabel] 354 [[stackButton_ titleLabel]
353 setFont:[self fontForSize:kFontSizeFewerThanTenTabs]]; 355 setFont:[self fontForSize:kFontSizeFewerThanTenTabs]];
354 [stackButton_ 356 [stackButton_
355 setTitleColor:[UIColor colorWithWhite:kStackButtonNormalColors[style_] 357 setTitleColor:[UIColor colorWithWhite:kStackButtonNormalColors[style_]
356 alpha:1.0] 358 alpha:1.0]
357 forState:UIControlStateNormal]; 359 forState:UIControlStateNormal];
358 UIColor* highlightColor = 360 UIColor* highlightColor =
359 UIColorFromRGB(kStackButtonHighlightedColors[style_], 1.0); 361 UIColorFromRGB(kStackButtonHighlightedColors[style_], 1.0);
360 [stackButton_ setTitleColor:highlightColor 362 [stackButton_ setTitleColor:highlightColor
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return nil; 402 return nil;
401 } 403 }
402 404
403 - (UIFont*)fontForSize:(NSInteger)size { 405 - (UIFont*)fontForSize:(NSInteger)size {
404 return [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:size]; 406 return [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:size];
405 } 407 }
406 408
407 - (void)dealloc { 409 - (void)dealloc {
408 [[NSNotificationCenter defaultCenter] removeObserver:self]; 410 [[NSNotificationCenter defaultCenter] removeObserver:self];
409 [toolsPopupController_ setDelegate:nil]; 411 [toolsPopupController_ setDelegate:nil];
410 [super dealloc];
411 }
412
413 - (UIImageView*)view {
414 return view_.get();
415 }
416
417 - (UIImageView*)backgroundView {
418 return backgroundView_.get();
419 } 412 }
420 413
421 - (CGFloat)statusBarOffset { 414 - (CGFloat)statusBarOffset {
422 return StatusBarHeight(); 415 return StatusBarHeight();
423 } 416 }
424 417
425 - (UIImageView*)shadowView {
426 return shadowView_.get();
427 }
428
429 - (NSMutableArray*)transitionLayers { 418 - (NSMutableArray*)transitionLayers {
430 return transitionLayers_.get(); 419 return transitionLayers_;
431 } 420 }
432 421
433 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum { 422 - (BOOL)imageShouldFlipForRightToLeftLayoutDirection:(int)imageEnum {
434 // None of the images this class knows about should flip. 423 // None of the images this class knows about should flip.
435 return NO; 424 return NO;
436 } 425 }
437 426
438 - (void)updateStandardButtons { 427 - (void)updateStandardButtons {
439 BOOL shareButtonShouldBeVisible = [self shareButtonShouldBeVisible]; 428 BOOL shareButtonShouldBeVisible = [self shareButtonShouldBeVisible];
440 [shareButton_ setHidden:!shareButtonShouldBeVisible]; 429 [shareButton_ setHidden:!shareButtonShouldBeVisible];
441 NSMutableArray* standardButtons = [NSMutableArray array]; 430 NSMutableArray* standardButtons = [NSMutableArray array];
442 [standardButtons addObject:toolsMenuButton_]; 431 [standardButtons addObject:toolsMenuButton_];
443 if (stackButton_) 432 if (stackButton_)
444 [standardButtons addObject:stackButton_]; 433 [standardButtons addObject:stackButton_];
445 if (shareButtonShouldBeVisible) 434 if (shareButtonShouldBeVisible)
446 [standardButtons addObject:shareButton_]; 435 [standardButtons addObject:shareButton_];
447 standardButtons_.reset([standardButtons retain]); 436 standardButtons_ = standardButtons;
448 } 437 }
449 438
450 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 439 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
451 [self updateStandardButtons]; 440 [self updateStandardButtons];
452 } 441 }
453 442
454 - (ToolsPopupController*)toolsPopupController {
455 return toolsPopupController_.get();
456 }
457
458 - (void)applicationDidEnterBackground:(NSNotification*)notify { 443 - (void)applicationDidEnterBackground:(NSNotification*)notify {
459 if (toolsPopupController_.get()) { 444 if (toolsPopupController_) {
460 // Dismiss the tools popup menu without animation. 445 // Dismiss the tools popup menu without animation.
461 [toolsMenuButton_ setToolsMenuIsVisible:NO]; 446 [toolsMenuButton_ setToolsMenuIsVisible:NO];
462 toolsPopupController_.reset(nil); 447 toolsPopupController_ = nil;
463 [[NSNotificationCenter defaultCenter] 448 [[NSNotificationCenter defaultCenter]
464 postNotificationName:kMenuWillHideNotification 449 postNotificationName:kMenuWillHideNotification
465 object:nil]; 450 object:nil];
466 } 451 }
467 } 452 }
468 453
469 - (BOOL)shareButtonShouldBeVisible { 454 - (BOOL)shareButtonShouldBeVisible {
470 // The share button only exists on iPad, and when some tabs are visible 455 // 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 456 // (i.e. when not in DarkMode), and when the width is greater than
472 // the tablet mini view. 457 // the tablet mini view.
(...skipping 10 matching lines...) Expand all
483 468
484 - (UIImage*)imageForImageEnum:(int)imageEnum 469 - (UIImage*)imageForImageEnum:(int)imageEnum
485 forState:(ToolbarButtonUIState)state { 470 forState:(ToolbarButtonUIState)state {
486 int imageID = 471 int imageID =
487 [self imageIdForImageEnum:imageEnum style:[self style] forState:state]; 472 [self imageIdForImageEnum:imageEnum style:[self style] forState:state];
488 return NativeReversableImage( 473 return NativeReversableImage(
489 imageID, [self imageShouldFlipForRightToLeftLayoutDirection:imageEnum]); 474 imageID, [self imageShouldFlipForRightToLeftLayoutDirection:imageEnum]);
490 } 475 }
491 476
492 - (int)imageEnumForButton:(UIButton*)button { 477 - (int)imageEnumForButton:(UIButton*)button {
493 if (button == stackButton_.get()) 478 if (button == stackButton_)
494 return ToolbarButtonNameStack; 479 return ToolbarButtonNameStack;
495 return NumberOfToolbarButtonNames; 480 return NumberOfToolbarButtonNames;
496 } 481 }
497 482
498 - (int)imageIdForImageEnum:(int)index 483 - (int)imageIdForImageEnum:(int)index
499 style:(ToolbarControllerStyle)style 484 style:(ToolbarControllerStyle)style
500 forState:(ToolbarButtonUIState)state { 485 forState:(ToolbarButtonUIState)state {
501 DCHECK(index < NumberOfToolbarButtonNames); 486 DCHECK(index < NumberOfToolbarButtonNames);
502 DCHECK(style < ToolbarControllerStyleMaxStyles); 487 DCHECK(style < ToolbarControllerStyleMaxStyles);
503 DCHECK(state < NumberOfToolbarButtonUIStates); 488 DCHECK(state < NumberOfToolbarButtonUIStates);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 if (synchronously || initialState == UIControlStateDisabled) { 541 if (synchronously || initialState == UIControlStateDisabled) {
557 disabledImageBlock(); 542 disabledImageBlock();
558 } else { 543 } else {
559 dispatch_after(addImageDelay, dispatch_get_main_queue(), 544 dispatch_after(addImageDelay, dispatch_get_main_queue(),
560 disabledImageBlock); 545 disabledImageBlock);
561 } 546 }
562 } 547 }
563 } 548 }
564 549
565 - (void)registerEventsForButton:(UIButton*)button { 550 - (void)registerEventsForButton:(UIButton*)button {
566 if (button != toolsMenuButton_.get()) { 551 if (button != toolsMenuButton_) {
567 // |target| must be |self| (as opposed to |nil|) because |self| isn't in the 552 // |target| must be |self| (as opposed to |nil|) because |self| isn't in the
568 // responder chain. 553 // responder chain.
569 [button addTarget:self 554 [button addTarget:self
570 action:@selector(standardButtonPressed:) 555 action:@selector(standardButtonPressed:)
571 forControlEvents:UIControlEventTouchUpInside]; 556 forControlEvents:UIControlEventTouchUpInside];
572 } 557 }
573 [button addTarget:self 558 [button addTarget:self
574 action:@selector(recordUserMetrics:) 559 action:@selector(recordUserMetrics:)
575 forControlEvents:UIControlEventTouchUpInside]; 560 forControlEvents:UIControlEventTouchUpInside];
576 [button addTarget:button 561 [button addTarget:button
577 action:@selector(chromeExecuteCommand:) 562 action:@selector(chromeExecuteCommand:)
578 forControlEvents:UIControlEventTouchUpInside]; 563 forControlEvents:UIControlEventTouchUpInside];
579 } 564 }
580 565
581 - (CGRect)shareButtonAnchorRect { 566 - (CGRect)shareButtonAnchorRect {
582 // Shrink the padding around the shareButton so the popovers are anchored 567 // Shrink the padding around the shareButton so the popovers are anchored
583 // correctly. 568 // correctly.
584 return CGRectInset([shareButton_ bounds], 10, 0); 569 return CGRectInset([shareButton_ bounds], 10, 0);
585 } 570 }
586 571
587 - (UIView*)shareButtonView { 572 - (UIView*)shareButtonView {
588 return shareButton_.get(); 573 return shareButton_;
589 } 574 }
590 575
591 - (void)showToolsMenuPopupWithConfiguration: 576 - (void)showToolsMenuPopupWithConfiguration:
592 (ToolsMenuConfiguration*)configuration { 577 (ToolsMenuConfiguration*)configuration {
593 // Because an animation hides and shows the tools popup menu it is possible to 578 // 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 579 // tap the tools button multiple times before the tools menu is shown. Ignore
595 // repeated taps between animations. 580 // repeated taps between animations.
596 if (toolsPopupController_) 581 if (toolsPopupController_)
597 return; 582 return;
598 583
599 base::RecordAction(UserMetricsAction("ShowAppMenu")); 584 base::RecordAction(UserMetricsAction("ShowAppMenu"));
600 585
601 // Keep the button pressed. 586 // Keep the button pressed.
602 [toolsMenuButton_ setToolsMenuIsVisible:YES]; 587 [toolsMenuButton_ setToolsMenuIsVisible:YES];
603 588
604 [configuration setToolsMenuButton:toolsMenuButton_]; 589 [configuration setToolsMenuButton:toolsMenuButton_];
605 toolsPopupController_.reset( 590 toolsPopupController_ =
606 [[ToolsPopupController alloc] initWithConfiguration:configuration]); 591 [[ToolsPopupController alloc] initWithConfiguration:configuration];
607 592
608 [toolsPopupController_ setDelegate:self]; 593 [toolsPopupController_ setDelegate:self];
609 594
610 [[NSNotificationCenter defaultCenter] 595 [[NSNotificationCenter defaultCenter]
611 postNotificationName:kMenuWillShowNotification 596 postNotificationName:kMenuWillShowNotification
612 object:nil]; 597 object:nil];
613 } 598 }
614 599
615 - (void)dismissToolsMenuPopup { 600 - (void)dismissToolsMenuPopup {
616 if (!toolsPopupController_.get()) 601 if (!toolsPopupController_)
617 return; 602 return;
618 ToolsPopupController* tempTPC = toolsPopupController_.get(); 603 ToolsPopupController* tempTPC = toolsPopupController_;
619 [tempTPC containerView].userInteractionEnabled = NO; 604 [tempTPC containerView].userInteractionEnabled = NO;
620 [tempTPC dismissAnimatedWithCompletion:^{ 605 [tempTPC dismissAnimatedWithCompletion:^{
621 // Unpress the tools menu button by restoring the normal and 606 // Unpress the tools menu button by restoring the normal and
622 // highlighted images to their usual state. 607 // highlighted images to their usual state.
623 [toolsMenuButton_ setToolsMenuIsVisible:NO]; 608 [toolsMenuButton_ setToolsMenuIsVisible:NO];
624 // Reference tempTPC so the block retains it. 609 // Reference tempTPC so the block retains it.
625 [tempTPC self]; 610 [tempTPC self];
626 }]; 611 }];
627 // reset tabHistoryPopupController_ to prevent -applicationDidEnterBackground 612 // reset tabHistoryPopupController_ to prevent -applicationDidEnterBackground
628 // from posting another kMenuWillHideNotification. 613 // from posting another kMenuWillHideNotification.
629 toolsPopupController_.reset(); 614 toolsPopupController_ = nil;
630 615
631 [[NSNotificationCenter defaultCenter] 616 [[NSNotificationCenter defaultCenter]
632 postNotificationName:kMenuWillHideNotification 617 postNotificationName:kMenuWillHideNotification
633 object:nil]; 618 object:nil];
634 } 619 }
635 620
636 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style { 621 - (UIImage*)getBackgroundImageForStyle:(ToolbarControllerStyle)style {
637 int backgroundImageID; 622 int backgroundImageID;
638 if (style == ToolbarControllerStyleLightMode) 623 if (style == ToolbarControllerStyleLightMode)
639 backgroundImageID = IDR_IOS_TOOLBAR_LIGHT_BACKGROUND; 624 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. 663 // Animate the opacity of the buttons to 0.
679 [CATransaction begin]; 664 [CATransaction begin];
680 [CATransaction setAnimationDuration:ios::material::kDuration2]; 665 [CATransaction setAnimationDuration:ios::material::kDuration2];
681 [CATransaction 666 [CATransaction
682 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)]; 667 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)];
683 CABasicAnimation* fadeButtons = 668 CABasicAnimation* fadeButtons =
684 [CABasicAnimation animationWithKeyPath:@"opacity"]; 669 [CABasicAnimation animationWithKeyPath:@"opacity"];
685 fadeButtons.fromValue = @1; 670 fadeButtons.fromValue = @1;
686 fadeButtons.toValue = @0; 671 fadeButtons.toValue = @0;
687 672
688 for (UIButton* button in standardButtons_.get()) { 673 for (UIButton* button in standardButtons_) {
689 if (![button isHidden]) { 674 if (![button isHidden]) {
690 [button layer].opacity = 0; 675 [button layer].opacity = 0;
691 [[button layer] addAnimation:fadeButtons forKey:@"fade"]; 676 [[button layer] addAnimation:fadeButtons forKey:@"fade"];
692 } 677 }
693 } 678 }
694 [CATransaction commit]; 679 [CATransaction commit];
695 680
696 // Animate the buttons 10 pixels in the leading-to-trailing direction 681 // Animate the buttons 10 pixels in the leading-to-trailing direction
697 [CATransaction begin]; 682 [CATransaction begin];
698 [CATransaction setAnimationDuration:ios::material::kDuration1]; 683 [CATransaction setAnimationDuration:ios::material::kDuration1];
699 [CATransaction 684 [CATransaction
700 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)]; 685 setAnimationTimingFunction:TimingFunction(ios::material::CurveEaseIn)];
701 686
702 for (UIButton* button in standardButtons_.get()) { 687 for (UIButton* button in standardButtons_) {
703 CABasicAnimation* shiftButton = 688 CABasicAnimation* shiftButton =
704 [CABasicAnimation animationWithKeyPath:@"position"]; 689 [CABasicAnimation animationWithKeyPath:@"position"];
705 CGPoint startPosition = [button layer].position; 690 CGPoint startPosition = [button layer].position;
706 CGPoint endPosition = 691 CGPoint endPosition =
707 CGPointLayoutOffset(startPosition, kButtonFadeOutXOffset); 692 CGPointLayoutOffset(startPosition, kButtonFadeOutXOffset);
708 shiftButton.fromValue = [NSValue valueWithCGPoint:startPosition]; 693 shiftButton.fromValue = [NSValue valueWithCGPoint:startPosition];
709 shiftButton.toValue = [NSValue valueWithCGPoint:endPosition]; 694 shiftButton.toValue = [NSValue valueWithCGPoint:endPosition];
710 [[button layer] addAnimation:shiftButton forKey:@"shiftButton"]; 695 [[button layer] addAnimation:shiftButton forKey:@"shiftButton"];
711 } 696 }
712 697
713 [CATransaction commit]; 698 [CATransaction commit];
714 699
715 // Fade to the full bleed shadow. 700 // Fade to the full bleed shadow.
716 [UIView animateWithDuration:ios::material::kDuration1 701 [UIView animateWithDuration:ios::material::kDuration1
717 animations:^{ 702 animations:^{
718 [shadowView_ setAlpha:0]; 703 [shadowView_ setAlpha:0];
719 [fullBleedShadowView_ setAlpha:1]; 704 [fullBleedShadowView_ setAlpha:1];
720 }]; 705 }];
721 } 706 }
722 707
723 - (void)fadeInStandardControls { 708 - (void)fadeInStandardControls {
724 for (UIButton* button in standardButtons_.get()) { 709 for (UIButton* button in standardButtons_) {
725 [self fadeInView:button 710 [self fadeInView:button
726 fromLeadingOffset:10 711 fromLeadingOffset:10
727 withDuration:ios::material::kDuration2 712 withDuration:ios::material::kDuration2
728 afterDelay:ios::material::kDuration1]; 713 afterDelay:ios::material::kDuration1];
729 } 714 }
730 715
731 // Fade to the normal shadow. 716 // Fade to the normal shadow.
732 [UIView animateWithDuration:ios::material::kDuration1 717 [UIView animateWithDuration:ios::material::kDuration1
733 animations:^{ 718 animations:^{
734 [shadowView_ setAlpha:self.backgroundView.alpha]; 719 [shadowView_ setAlpha:self.backgroundView.alpha];
735 [fullBleedShadowView_ setAlpha:0]; 720 [fullBleedShadowView_ setAlpha:0];
736 }]; 721 }];
737 } 722 }
738 723
739 - (void)animationDidStart:(CAAnimation*)anim { 724 - (void)animationDidStart:(CAAnimation*)anim {
740 // Once the buttons start fading in, set their opacity to 1 so there's no 725 // Once the buttons start fading in, set their opacity to 1 so there's no
741 // flicker at the end of the animation. 726 // flicker at the end of the animation.
742 for (UIButton* button in standardButtons_.get()) { 727 for (UIButton* button in standardButtons_) {
743 if (anim == [[button layer] animationForKey:@"fadeIn"]) { 728 if (anim == [[button layer] animationForKey:@"fadeIn"]) {
744 [button layer].opacity = 1; 729 [button layer].opacity = 1;
745 return; 730 return;
746 } 731 }
747 } 732 }
748 } 733 }
749 734
750 - (void)fadeInView:(UIView*)view 735 - (void)fadeInView:(UIView*)view
751 fromLeadingOffset:(LayoutOffset)leadingOffset 736 fromLeadingOffset:(LayoutOffset)leadingOffset
752 withDuration:(NSTimeInterval)duration 737 withDuration:(NSTimeInterval)duration
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 transitionStyle:style]; 911 transitionStyle:style];
927 } 912 }
928 913
929 - (void)hideViewsForNewTabPage:(BOOL)hide { 914 - (void)hideViewsForNewTabPage:(BOOL)hide {
930 DCHECK(!IsIPadIdiom()); 915 DCHECK(!IsIPadIdiom());
931 [shadowView_ setHidden:hide]; 916 [shadowView_ setHidden:hide];
932 } 917 }
933 918
934 - (void)setStandardControlsVisible:(BOOL)visible { 919 - (void)setStandardControlsVisible:(BOOL)visible {
935 if (visible) { 920 if (visible) {
936 for (UIButton* button in standardButtons_.get()) { 921 for (UIButton* button in standardButtons_) {
937 [button setAlpha:1.0]; 922 [button setAlpha:1.0];
938 } 923 }
939 } else { 924 } else {
940 for (UIButton* button in standardButtons_.get()) { 925 for (UIButton* button in standardButtons_) {
941 [button setAlpha:0.0]; 926 [button setAlpha:0.0];
942 } 927 }
943 } 928 }
944 } 929 }
945 930
946 - (void)setStandardControlsAlpha:(CGFloat)alpha { 931 - (void)setStandardControlsAlpha:(CGFloat)alpha {
947 for (UIButton* button in standardButtons_.get()) { 932 for (UIButton* button in standardButtons_) {
948 if (![button isHidden]) 933 if (![button isHidden])
949 [button setAlpha:alpha]; 934 [button setAlpha:alpha];
950 } 935 }
951 } 936 }
952 937
953 - (void)setBackgroundAlpha:(CGFloat)alpha { 938 - (void)setBackgroundAlpha:(CGFloat)alpha {
954 [backgroundView_ setAlpha:alpha]; 939 [backgroundView_ setAlpha:alpha];
955 [shadowView_ setAlpha:alpha]; 940 [shadowView_ setAlpha:alpha];
956 } 941 }
957 942
958 - (void)setStandardControlsTransform:(CGAffineTransform)transform { 943 - (void)setStandardControlsTransform:(CGAffineTransform)transform {
959 for (UIButton* button in standardButtons_.get()) { 944 for (UIButton* button in standardButtons_) {
960 [button setTransform:transform]; 945 [button setTransform:transform];
961 } 946 }
962 } 947 }
963 948
964 - (void)standardButtonPressed:(UIButton*)sender { 949 - (void)standardButtonPressed:(UIButton*)sender {
965 // This check for valid button images assumes that the buttons all have a 950 // 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. 951 // different image for the highlighted state as for the normal state.
967 // Currently, that assumption is true. 952 // Currently, that assumption is true.
968 if ([sender imageForState:UIControlStateHighlighted] == 953 if ([sender imageForState:UIControlStateHighlighted] ==
969 [sender imageForState:UIControlStateNormal]) { 954 [sender imageForState:UIControlStateNormal]) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 [[stackButton_ titleLabel] 992 [[stackButton_ titleLabel]
1008 setFont:[self fontForSize:kFontSizeTenTabsOrMore]]; 993 setFont:[self fontForSize:kFontSizeTenTabsOrMore]];
1009 } 994 }
1010 } 995 }
1011 996
1012 [stackButton_ setTitle:stackButtonTitle forState:UIControlStateNormal]; 997 [stackButton_ setTitle:stackButtonTitle forState:UIControlStateNormal];
1013 [stackButton_ setAccessibilityValue:stackButtonValue]; 998 [stackButton_ setAccessibilityValue:stackButtonValue];
1014 } 999 }
1015 1000
1016 - (IBAction)recordUserMetrics:(id)sender { 1001 - (IBAction)recordUserMetrics:(id)sender {
1017 if (sender == toolsMenuButton_.get()) 1002 if (sender == toolsMenuButton_)
1018 base::RecordAction(UserMetricsAction("MobileToolbarShowMenu")); 1003 base::RecordAction(UserMetricsAction("MobileToolbarShowMenu"));
1019 else if (sender == stackButton_.get()) 1004 else if (sender == stackButton_)
1020 base::RecordAction(UserMetricsAction("MobileToolbarShowStackView")); 1005 base::RecordAction(UserMetricsAction("MobileToolbarShowStackView"));
1021 else if (sender == shareButton_.get()) 1006 else if (sender == shareButton_)
1022 base::RecordAction(UserMetricsAction("MobileToolbarShareMenu")); 1007 base::RecordAction(UserMetricsAction("MobileToolbarShareMenu"));
1023 else 1008 else
1024 NOTREACHED(); 1009 NOTREACHED();
1025 } 1010 }
1026 1011
1027 - (IBAction)stackButtonTouchDown:(id)sender { 1012 - (IBAction)stackButtonTouchDown:(id)sender {
1028 // Exists only for override by subclasses. 1013 // Exists only for override by subclasses.
1029 } 1014 }
1030 1015
1031 + (CGFloat)toolbarDropShadowHeight { 1016 + (CGFloat)toolbarDropShadowHeight {
(...skipping 16 matching lines...) Expand all
1048 #pragma mark - 1033 #pragma mark -
1049 #pragma mark PopupMenuDelegate methods. 1034 #pragma mark PopupMenuDelegate methods.
1050 1035
1051 - (void)dismissPopupMenu:(PopupMenuController*)controller { 1036 - (void)dismissPopupMenu:(PopupMenuController*)controller {
1052 if ([controller isKindOfClass:[ToolsPopupController class]] && 1037 if ([controller isKindOfClass:[ToolsPopupController class]] &&
1053 (ToolsPopupController*)controller == toolsPopupController_) 1038 (ToolsPopupController*)controller == toolsPopupController_)
1054 [self dismissToolsMenuPopup]; 1039 [self dismissToolsMenuPopup];
1055 } 1040 }
1056 1041
1057 @end 1042 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698