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

Side by Side Diff: ios/chrome/browser/ui/contextual_search/contextual_search_mask_view.mm

Issue 2588713002: Upstream Chrome on iOS source code [4/11]. (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
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 #include "ios/chrome/browser/ui/contextual_search/contextual_search_mask_view.h"
6
7 #include "base/logging.h"
8 #import "ios/chrome/browser/ui/contextual_search/contextual_search_panel_view.h"
9 #import "ios/chrome/browser/ui/uikit_ui_util.h"
10
11 // Linearly map |delta| in the range [0, 1] to a value in [min, max].
12 #define LERP(min, max, delta) (min * (1 - delta) + max * delta)
13
14 namespace {
15 const CGFloat kPhoneMaskLimit = 1.0;
16 const CGFloat kPadMaskLimit = 0.8;
17 }
18
19 @implementation ContextualSearchMaskView {
20 CGFloat _maskLimit;
21 }
22
23 - (instancetype)init {
24 if ((self = [super initWithFrame:CGRectZero])) {
25 self.userInteractionEnabled = NO;
26 self.translatesAutoresizingMaskIntoConstraints = NO;
27 self.accessibilityIdentifier = @"contextualSearchMask";
28 self.alpha = 0.0;
29 self.backgroundColor = [UIColor blackColor];
30 _maskLimit = IsIPadIdiom() ? kPadMaskLimit : kPhoneMaskLimit;
31 }
32 return self;
33 }
34
35 - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE {
36 NOTREACHED();
37 return nil;
38 }
39
40 - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE {
41 NOTREACHED();
42 return nil;
43 }
44
45 #pragma mark - UIView methods.
46
47 - (void)updateConstraints {
48 DCHECK(self.superview);
49 NSArray* constraints = @[ @"V:|[mask]|", @"H:|[mask]|" ];
50 ApplyVisualConstraints(constraints, @{ @"mask" : self }, self.superview);
51 [super updateConstraints];
52 }
53
54 #pragma mark - ContextualSearchPanelMotionObserver methods
55
56 - (void)panel:(ContextualSearchPanelView*)panel
57 didMoveWithMotion:(ContextualSearch::PanelMotion)motion {
58 CGFloat ratio;
59 if (motion.state < ContextualSearch::PEEKING) {
60 ratio = 0;
61 } else if (motion.state == ContextualSearch::COVERING) {
62 ratio = 1;
63 } else {
64 ratio = [panel.configuration gradationToState:ContextualSearch::COVERING
65 fromState:ContextualSearch::PEEKING
66 atPosition:motion.position];
67 }
68
69 ratio = LERP(0, _maskLimit, ratio);
70
71 self.alpha = ratio * ratio;
72 }
73
74 - (void)panelWillPromote:(ContextualSearchPanelView*)panel {
75 [panel removeMotionObserver:self];
76 }
77
78 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698