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 centerXAnchor] |
488 constraintEqualToAnchor:[self centerXAnchor]], | 492 constraintEqualToAnchor:[self centerXAnchor]], |
489 [[viewportCaption centerYAnchor] | 493 [[viewportCaption topAnchor] |
gambard
2017/02/22 10:49:04
Don't we want to just align on the _previewView.bo
jif
2017/02/22 12:42:15
_previewView is the view that contains the video.
| |
490 constraintEqualToAnchor:[self centerYAnchor] | 494 constraintEqualToAnchor:[self centerYAnchor] |
491 constant:GetViewportSize() / 2 + kViewportCaptionPadding] | 495 constant:GetViewportSize() / 2 + |
496 kViewportCaptionVerticalPadding], | |
497 [viewportCaption.widthAnchor | |
gambard
2017/02/22 10:49:04
Why using this and not constraints on leading/trai
jif
2017/02/22 12:42:15
Done.
| |
498 constraintLessThanOrEqualToAnchor:self.widthAnchor | |
499 multiplier:1.0 | |
500 constant:-2 * | |
501 kViewportCaptionHorizontalPadding] | |
492 ]]; | 502 ]]; |
493 } | 503 } |
494 | 504 |
495 - (void)setupPreviewView { | 505 - (void)setupPreviewView { |
496 DCHECK(!_previewView); | 506 DCHECK(!_previewView); |
497 _previewView.reset([[VideoPreviewView alloc] initWithFrame:self.frame]); | 507 _previewView.reset([[VideoPreviewView alloc] initWithFrame:self.frame]); |
498 [self insertSubview:_previewView atIndex:0]; | 508 [self insertSubview:_previewView atIndex:0]; |
499 } | 509 } |
500 | 510 |
501 - (void)setupPreviewOverlayView { | 511 - (void)setupPreviewOverlayView { |
(...skipping 30 matching lines...) Expand all Loading... | |
532 [NSLayoutConstraint activateConstraints:@[ | 542 [NSLayoutConstraint activateConstraints:@[ |
533 [[_previewOverlay centerXAnchor] | 543 [[_previewOverlay centerXAnchor] |
534 constraintEqualToAnchor:[self centerXAnchor]], | 544 constraintEqualToAnchor:[self centerXAnchor]], |
535 [[_previewOverlay centerYAnchor] | 545 [[_previewOverlay centerYAnchor] |
536 constraintEqualToAnchor:[self centerYAnchor]], | 546 constraintEqualToAnchor:[self centerYAnchor]], |
537 _overlaySquareConstraint, _overlayWidthConstraint, _overlayHeightConstraint | 547 _overlaySquareConstraint, _overlayWidthConstraint, _overlayHeightConstraint |
538 ]]; | 548 ]]; |
539 } | 549 } |
540 | 550 |
541 @end | 551 @end |
OLD | NEW |