Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/qr_scanner/qr_scanner_view.h" | 5 #import "ios/chrome/browser/ui/qr_scanner/qr_scanner_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "ios/chrome/browser/ui/icons/chrome_icon.h" | 10 #include "ios/chrome/browser/ui/icons/chrome_icon.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 // Corner radius of the border around the viewport. | 35 // Corner radius of the border around the viewport. |
| 36 const CGFloat kViewportBorderCornerRadius = 2.0; | 36 const CGFloat kViewportBorderCornerRadius = 2.0; |
| 37 // Line width of the viewport border. | 37 // Line width of the viewport border. |
| 38 const CGFloat kViewportBorderLineWidth = 4.0; | 38 const CGFloat kViewportBorderLineWidth = 4.0; |
| 39 // Shadow opacity of the viewport border. | 39 // Shadow opacity of the viewport border. |
| 40 const CGFloat kViewportBorderShadowOpacity = 1.0; | 40 const CGFloat kViewportBorderShadowOpacity = 1.0; |
| 41 // Shadow radius of the viewport border. | 41 // Shadow radius of the viewport border. |
| 42 const CGFloat kViewportBorderShadowRadius = 10.0; | 42 const CGFloat kViewportBorderShadowRadius = 10.0; |
| 43 // Padding of the viewport caption, below the viewport. | 43 // Padding of the viewport caption, below the viewport. |
| 44 const CGFloat kViewportCaptionPadding = 24.0; | 44 const CGFloat kViewportCaptionVerticalPadding = 14.0; |
| 45 // Padding of the viewport caption from the edges of the superview. | |
| 46 const CGFloat kViewportCaptionHorizontalPadding = 20.0; | |
| 45 // Shadow opacity of the viewport caption. | 47 // Shadow opacity of the viewport caption. |
| 46 const CGFloat kViewportCaptionShadowOpacity = 1.0; | 48 const CGFloat kViewportCaptionShadowOpacity = 1.0; |
| 47 // Shadow radius of the viewport caption. | 49 // Shadow radius of the viewport caption. |
| 48 const CGFloat kViewportCaptionShadowRadius = 5.0; | 50 const CGFloat kViewportCaptionShadowRadius = 5.0; |
| 49 | 51 |
| 50 // Duration of the flash animation played when a code is scanned. | 52 // Duration of the flash animation played when a code is scanned. |
| 51 const CGFloat kFlashDuration = 0.5; | 53 const CGFloat kFlashDuration = 0.5; |
| 52 | 54 |
| 53 // Returns a square of size |rectSize| centered inside |frameSize|. | 55 // Returns a square of size |rectSize| centered inside |frameSize|. |
| 54 CGRect CenteredRectForViewport(CGSize frameSize, CGFloat rectSize) { | 56 CGRect CenteredRectForViewport(CGSize frameSize, CGFloat rectSize) { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 constant:-kButtonPadding], | 465 constant:-kButtonPadding], |
| 464 [[_torchButton bottomAnchor] constraintEqualToAnchor:[self bottomAnchor] | 466 [[_torchButton bottomAnchor] constraintEqualToAnchor:[self bottomAnchor] |
| 465 constant:-kButtonPadding] | 467 constant:-kButtonPadding] |
| 466 ]]; | 468 ]]; |
| 467 } | 469 } |
| 468 | 470 |
| 469 - (void)addViewportCaptionLabel { | 471 - (void)addViewportCaptionLabel { |
| 470 UILabel* viewportCaption = [[[UILabel alloc] init] autorelease]; | 472 UILabel* viewportCaption = [[[UILabel alloc] init] autorelease]; |
| 471 NSString* label = l10n_util::GetNSString(IDS_IOS_QR_SCANNER_VIEWPORT_CAPTION); | 473 NSString* label = l10n_util::GetNSString(IDS_IOS_QR_SCANNER_VIEWPORT_CAPTION); |
| 472 [viewportCaption setText:label]; | 474 [viewportCaption setText:label]; |
| 475 [viewportCaption setNumberOfLines:0]; | |
| 476 [viewportCaption setTextAlignment:NSTextAlignmentCenter]; | |
| 473 [viewportCaption setAccessibilityLabel:label]; | 477 [viewportCaption setAccessibilityLabel:label]; |
| 474 [viewportCaption setAccessibilityIdentifier:@"qr_scanner_viewport_caption"]; | 478 [viewportCaption setAccessibilityIdentifier:@"qr_scanner_viewport_caption"]; |
| 475 [viewportCaption setTextColor:[UIColor whiteColor]]; | 479 [viewportCaption setTextColor:[UIColor whiteColor]]; |
| 476 [viewportCaption.layer setShadowColor:[UIColor blackColor].CGColor]; | 480 [viewportCaption.layer setShadowColor:[UIColor blackColor].CGColor]; |
| 477 [viewportCaption.layer setShadowOffset:CGSizeZero]; | 481 [viewportCaption.layer setShadowOffset:CGSizeZero]; |
| 478 [viewportCaption.layer setShadowRadius:kViewportCaptionShadowRadius]; | 482 [viewportCaption.layer setShadowRadius:kViewportCaptionShadowRadius]; |
| 479 [viewportCaption.layer setShadowOpacity:kViewportCaptionShadowOpacity]; | 483 [viewportCaption.layer setShadowOpacity:kViewportCaptionShadowOpacity]; |
| 480 [viewportCaption.layer setMasksToBounds:NO]; | 484 [viewportCaption.layer setMasksToBounds:NO]; |
| 481 [viewportCaption.layer setShouldRasterize:YES]; | 485 [viewportCaption.layer setShouldRasterize:YES]; |
| 482 [self addSubview:viewportCaption]; | 486 [self addSubview:viewportCaption]; |
| 483 | 487 |
| 484 // Constraints for viewportCaption. | 488 // Constraints for viewportCaption. |
| 485 [viewportCaption setTranslatesAutoresizingMaskIntoConstraints:NO]; | 489 [viewportCaption setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 486 [NSLayoutConstraint activateConstraints:@[ | 490 [NSLayoutConstraint activateConstraints:@[ |
| 487 [[viewportCaption centerXAnchor] | 491 [[viewportCaption topAnchor] |
| 488 constraintEqualToAnchor:[self centerXAnchor]], | |
| 489 [[viewportCaption centerYAnchor] | |
| 490 constraintEqualToAnchor:[self centerYAnchor] | 492 constraintEqualToAnchor:[self centerYAnchor] |
| 491 constant:GetViewportSize() / 2 + kViewportCaptionPadding] | 493 constant:GetViewportSize() / 2 + |
| 494 kViewportCaptionVerticalPadding], | |
| 495 [viewportCaption.leftAnchor | |
|
gambard
2017/02/22 12:43:48
I am not sure about how left/right anchor are trea
jif
2017/02/22 12:59:07
Done.
| |
| 496 constraintEqualToAnchor:self.leftAnchor | |
| 497 constant:kViewportCaptionHorizontalPadding], | |
| 498 [viewportCaption.rightAnchor | |
| 499 constraintEqualToAnchor:self.rightAnchor | |
| 500 constant:-kViewportCaptionHorizontalPadding], | |
| 492 ]]; | 501 ]]; |
| 493 } | 502 } |
| 494 | 503 |
| 495 - (void)setupPreviewView { | 504 - (void)setupPreviewView { |
| 496 DCHECK(!_previewView); | 505 DCHECK(!_previewView); |
| 497 _previewView.reset([[VideoPreviewView alloc] initWithFrame:self.frame]); | 506 _previewView.reset([[VideoPreviewView alloc] initWithFrame:self.frame]); |
| 498 [self insertSubview:_previewView atIndex:0]; | 507 [self insertSubview:_previewView atIndex:0]; |
| 499 } | 508 } |
| 500 | 509 |
| 501 - (void)setupPreviewOverlayView { | 510 - (void)setupPreviewOverlayView { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 532 [NSLayoutConstraint activateConstraints:@[ | 541 [NSLayoutConstraint activateConstraints:@[ |
| 533 [[_previewOverlay centerXAnchor] | 542 [[_previewOverlay centerXAnchor] |
| 534 constraintEqualToAnchor:[self centerXAnchor]], | 543 constraintEqualToAnchor:[self centerXAnchor]], |
| 535 [[_previewOverlay centerYAnchor] | 544 [[_previewOverlay centerYAnchor] |
| 536 constraintEqualToAnchor:[self centerYAnchor]], | 545 constraintEqualToAnchor:[self centerYAnchor]], |
| 537 _overlaySquareConstraint, _overlayWidthConstraint, _overlayHeightConstraint | 546 _overlaySquareConstraint, _overlayWidthConstraint, _overlayHeightConstraint |
| 538 ]]; | 547 ]]; |
| 539 } | 548 } |
| 540 | 549 |
| 541 @end | 550 @end |
| OLD | NEW |