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

Side by Side Diff: ios/chrome/today_extension/transparent_button.mm

Issue 2586713002: Upstream code and resources for Chrome on iOS extensions. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « ios/chrome/today_extension/transparent_button.h ('k') | ios/chrome/today_extension/ui_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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/today_extension/transparent_button.h"
6
7 #import <NotificationCenter/NotificationCenter.h>
8 #import <QuartzCore/QuartzCore.h>
9
10 #import "base/ios/weak_nsobject.h"
11 #import "base/mac/scoped_nsobject.h"
12 #import "ios/chrome/today_extension/ui_util.h"
13 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material Ink.h"
14
15 @implementation TransparentButton {
16 base::scoped_nsobject<MDCInkView> _backgroundView;
17 CGPoint _touchLocation;
18 BOOL _highlightStatus;
19 base::scoped_nsobject<UIView> _effectView;
20 base::WeakNSObject<UIView> _effectContentView;
21 }
22
23 - (instancetype)initWithFrame:(CGRect)frame {
24 self = [super initWithFrame:frame];
25 if (self) {
26 CGRect insideFrame = frame;
27 insideFrame.origin = CGPointZero;
28 [self setTranslatesAutoresizingMaskIntoConstraints:NO];
29
30 if (!UIAccessibilityIsReduceTransparencyEnabled()) {
31 UIVisualEffectView* effectView = [[UIVisualEffectView alloc]
32 initWithEffect:[UIVibrancyEffect notificationCenterVibrancyEffect]];
33 _effectView.reset(effectView);
34 _effectContentView.reset([effectView contentView]);
35 } else {
36 _effectView.reset([[UIView alloc] initWithFrame:insideFrame]);
37 _effectContentView.reset(_effectView);
38 }
39 [self addSubview:_effectView];
40 ui_util::ConstrainAllSidesOfViewToView(self, _effectView);
41 [_effectView setTranslatesAutoresizingMaskIntoConstraints:NO];
42 [_effectView setUserInteractionEnabled:NO];
43
44 _backgroundView.reset([[MDCInkView alloc] initWithFrame:insideFrame]);
45 [_backgroundView setMaxRippleRadius:frame.size.width];
46 [_effectContentView addSubview:_backgroundView];
47 ui_util::ConstrainAllSidesOfViewToView(_effectContentView, _backgroundView);
48 [_backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO];
49 [self sendSubviewToBack:_effectView];
50 [self setCornerRadius:0];
51 }
52 return self;
53 }
54
55 - (UIView*)contentView {
56 return _effectContentView.get();
57 }
58
59 - (void)setInkColor:(UIColor*)color {
60 [_backgroundView setInkColor:color];
61 }
62
63 - (UIColor*)inkColor {
64 return [_backgroundView inkColor];
65 }
66
67 - (void)setBorderColor:(UIColor*)color {
68 [[_backgroundView layer] setBorderColor:color.CGColor];
69 }
70
71 - (UIColor*)borderColor {
72 return [UIColor colorWithCGColor:[[_backgroundView layer] borderColor]];
73 }
74
75 - (void)setBorderWidth:(CGFloat)width {
76 [[_backgroundView layer] setBorderWidth:width];
77 }
78
79 - (CGFloat)borderWidth {
80 return [[_backgroundView layer] borderWidth];
81 }
82
83 - (void)setBackgroundColor:(UIColor*)color {
84 [_backgroundView setBackgroundColor:color];
85 }
86
87 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
88 UITouch* touch = [touches anyObject];
89 _touchLocation = [touch locationInView:self];
90 [super touchesBegan:touches withEvent:event];
91 }
92
93 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
94 UITouch* touch = [touches anyObject];
95 _touchLocation = [touch locationInView:self];
96 [super touchesEnded:touches withEvent:event];
97 }
98
99 - (void)setCornerRadius:(const CGFloat)radius {
100 [self layer].cornerRadius = radius;
101 [_backgroundView layer].cornerRadius = radius;
102 }
103
104 - (CGFloat)cornerRadius {
105 return [self layer].cornerRadius;
106 }
107
108 - (void)setHighlighted:(BOOL)highlighted {
109 [super setHighlighted:highlighted];
110 if (highlighted == _highlightStatus) {
111 return;
112 }
113 _highlightStatus = highlighted;
114
115 if (highlighted) {
116 [_backgroundView startTouchBeganAnimationAtPoint:_touchLocation
117 completion:nil];
118 } else {
119 [_backgroundView startTouchEndedAnimationAtPoint:_touchLocation
120 completion:nil];
121 }
122 }
123
124 @end
OLDNEW
« no previous file with comments | « ios/chrome/today_extension/transparent_button.h ('k') | ios/chrome/today_extension/ui_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698