| 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/contextual_search/contextual_search_highlighter_v
iew.h" | 5 #import "ios/chrome/browser/ui/contextual_search/contextual_search_highlighter_v
iew.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/browser/ui/contextual_search/contextual_search_controller.h" | 8 #import "ios/chrome/browser/ui/contextual_search/contextual_search_controller.h" |
| 10 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 11 #error "This file requires ARC support." |
| 12 #endif |
| 13 |
| 11 @implementation ContextualSearchHighlighterView { | 14 @implementation ContextualSearchHighlighterView { |
| 12 // Store size of the container view. If size change, text layout will likely | 15 // Store size of the container view. If size change, text layout will likely |
| 13 // change and should be updated. | 16 // change and should be updated. |
| 14 CGSize _previousSize; | 17 CGSize _previousSize; |
| 15 | 18 |
| 16 // Store values that were used last time the rects were drawn. | 19 // Store values that were used last time the rects were drawn. |
| 17 CGPoint _scroll; | 20 CGPoint _scroll; |
| 18 CGFloat _zoom; | 21 CGFloat _zoom; |
| 19 CGFloat _offset; | 22 CGFloat _offset; |
| 20 | 23 |
| 21 __unsafe_unretained id<ContextualSearchHighlighterDelegate> _delegate; | 24 __weak id<ContextualSearchHighlighterDelegate> _delegate; |
| 22 } | 25 } |
| 23 | 26 |
| 24 - (instancetype)initWithFrame:(CGRect)frame | 27 - (instancetype)initWithFrame:(CGRect)frame |
| 25 delegate: | 28 delegate: |
| 26 (id<ContextualSearchHighlighterDelegate>)delegate { | 29 (id<ContextualSearchHighlighterDelegate>)delegate { |
| 27 self = [super initWithFrame:frame]; | 30 self = [super initWithFrame:frame]; |
| 28 if (self) { | 31 if (self) { |
| 29 [self setUserInteractionEnabled:NO]; | 32 [self setUserInteractionEnabled:NO]; |
| 30 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 33 [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
| 31 UIViewAutoresizingFlexibleHeight]; | 34 UIViewAutoresizingFlexibleHeight]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 [view removeFromSuperview]; | 66 [view removeFromSuperview]; |
| 64 } | 67 } |
| 65 for (NSValue* value in rects) { | 68 for (NSValue* value in rects) { |
| 66 CGRect rect = [value CGRectValue]; | 69 CGRect rect = [value CGRectValue]; |
| 67 rect.origin.x *= zoom; | 70 rect.origin.x *= zoom; |
| 68 rect.origin.y *= zoom; | 71 rect.origin.y *= zoom; |
| 69 rect.size.width *= zoom; | 72 rect.size.width *= zoom; |
| 70 rect.size.height *= zoom; | 73 rect.size.height *= zoom; |
| 71 rect.origin.x -= scroll.x; | 74 rect.origin.x -= scroll.x; |
| 72 rect.origin.y += offset - scroll.y; | 75 rect.origin.y += offset - scroll.y; |
| 73 UIView* view = [[[UIView alloc] initWithFrame:rect] autorelease]; | 76 UIView* view = [[UIView alloc] initWithFrame:rect]; |
| 74 [self addSubview:view]; | 77 [self addSubview:view]; |
| 75 view.backgroundColor = | 78 view.backgroundColor = |
| 76 [UIColor colorWithRed:0.67 green:0.88 blue:0.96 alpha:0.6]; | 79 [UIColor colorWithRed:0.67 green:0.88 blue:0.96 alpha:0.6]; |
| 77 } | 80 } |
| 78 [[self superview] bringSubviewToFront:self]; | 81 [[self superview] bringSubviewToFront:self]; |
| 79 _zoom = zoom; | 82 _zoom = zoom; |
| 80 _scroll = scroll; | 83 _scroll = scroll; |
| 81 _offset = offset; | 84 _offset = offset; |
| 82 } | 85 } |
| 83 | 86 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 104 CGRect bounding = CGRectNull; | 107 CGRect bounding = CGRectNull; |
| 105 for (UIView* view : [self subviews]) { | 108 for (UIView* view : [self subviews]) { |
| 106 bounding = CGRectUnion(bounding, view.frame); | 109 bounding = CGRectUnion(bounding, view.frame); |
| 107 } | 110 } |
| 108 bounding.origin.x += _scroll.x; | 111 bounding.origin.x += _scroll.x; |
| 109 bounding.origin.y += _scroll.y; | 112 bounding.origin.y += _scroll.y; |
| 110 return bounding; | 113 return bounding; |
| 111 } | 114 } |
| 112 | 115 |
| 113 @end | 116 @end |
| OLD | NEW |