| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/widget_extension/widget_view.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 10 #error "This file requires ARC support." | |
| 11 #endif | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const CGFloat kCursorHeight = 40; | |
| 16 const CGFloat kCursorWidth = 2; | |
| 17 const CGFloat kCursorHorizontalPadding = 10; | |
| 18 const CGFloat kCursorVerticalPadding = 10; | |
| 19 const CGFloat kFakeboxHorizontalPadding = 40; | |
| 20 const CGFloat kFakeboxVerticalPadding = 40; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 @interface WidgetView () { | |
| 25 __weak id<WidgetViewActionTarget> _target; | |
| 26 } | |
| 27 | |
| 28 @property(nonatomic, copy) NSString* copiedURL; | |
| 29 @property(nonatomic, strong) UILabel* copiedURLLabel; | |
| 30 @property(nonatomic, weak) UIView* cursor; | |
| 31 | |
| 32 // Creates and adds a fake omnibox with blinking cursor to the view and sets the | |
| 33 // class cursor property. | |
| 34 - (void)addFakebox; | |
| 35 | |
| 36 @end | |
| 37 | |
| 38 @implementation WidgetView | |
| 39 | |
| 40 @synthesize copiedURL = _copiedURL; | |
| 41 @synthesize copiedURLLabel = _copiedURLLabel; | |
| 42 | |
| 43 @synthesize cursor = _cursor; | |
| 44 | |
| 45 - (instancetype)initWithActionTarget:(id<WidgetViewActionTarget>)target { | |
| 46 self = [super initWithFrame:CGRectZero]; | |
| 47 if (self) { | |
| 48 DCHECK(target); | |
| 49 _target = target; | |
| 50 [self addFakebox]; | |
| 51 } | |
| 52 return self; | |
| 53 } | |
| 54 | |
| 55 - (void)addFakebox { | |
| 56 UIView* fakebox = [[UIView alloc] initWithFrame:CGRectZero]; | |
| 57 | |
| 58 UIGestureRecognizer* tapRecognizer = | |
| 59 [[UITapGestureRecognizer alloc] initWithTarget:_target | |
| 60 action:@selector(openSearch:)]; | |
| 61 | |
| 62 [fakebox addGestureRecognizer:tapRecognizer]; | |
| 63 [self addSubview:fakebox]; | |
| 64 | |
| 65 UIView* cursor = [[UIView alloc] initWithFrame:CGRectZero]; | |
| 66 self.cursor = cursor; | |
| 67 self.cursor.backgroundColor = [UIColor blueColor]; | |
| 68 [fakebox addSubview:self.cursor]; | |
| 69 | |
| 70 [fakebox setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
| 71 [self.cursor setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
| 72 [NSLayoutConstraint activateConstraints:@[ | |
| 73 [[fakebox leadingAnchor] constraintEqualToAnchor:self.leadingAnchor | |
| 74 constant:kFakeboxHorizontalPadding], | |
| 75 [[fakebox trailingAnchor] | |
| 76 constraintEqualToAnchor:self.trailingAnchor | |
| 77 constant:-kFakeboxHorizontalPadding], | |
| 78 [[fakebox topAnchor] constraintEqualToAnchor:self.topAnchor | |
| 79 constant:kFakeboxVerticalPadding], | |
| 80 [[fakebox heightAnchor] | |
| 81 constraintEqualToConstant:kCursorHeight + 2 * kCursorVerticalPadding], | |
| 82 | |
| 83 [[self.cursor widthAnchor] constraintEqualToConstant:kCursorWidth], | |
| 84 [[self.cursor leadingAnchor] | |
| 85 constraintEqualToAnchor:fakebox.leadingAnchor | |
| 86 constant:kCursorHorizontalPadding], | |
| 87 [[self.cursor heightAnchor] constraintEqualToConstant:kCursorHeight], | |
| 88 [[self.cursor centerYAnchor] constraintEqualToAnchor:fakebox.centerYAnchor] | |
| 89 ]]; | |
| 90 | |
| 91 [UIView animateWithDuration:0.3 | |
| 92 delay:0.0 | |
| 93 options:UIViewAnimationOptionRepeat | | |
| 94 UIViewAnimationOptionAutoreverse | |
| 95 animations:^{ | |
| 96 self.cursor.alpha = 0.0f; | |
| 97 } | |
| 98 completion:nil]; | |
| 99 } | |
| 100 | |
| 101 - (void)updateCopiedURL:(NSString*)copiedURL { | |
| 102 self.copiedURL = copiedURL; | |
| 103 self.copiedURLLabel.text = copiedURL; | |
| 104 } | |
| 105 | |
| 106 @end | |
| OLD | NEW |