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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_extended_button.mm

Issue 2586993002: Upstream Chrome on iOS source code [3/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 2014 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/browser/ui/bookmarks/bookmark_extended_button.h"
6
7 #include "base/logging.h"
8
9 namespace {
10 // Apple's guidelines indicate that buttons should have a minimum touch area of
11 // 44pt x 44pt.
12 CGFloat kMinimumLength = 44;
13 } // namespace
14
15 @interface BookmarkExtendedButton ()
16 @property(nonatomic, assign) BOOL doesExtendEdges;
17 @end
18
19 @implementation BookmarkExtendedButton
20 @synthesize doesExtendEdges = _doesExtendEdges;
21 @synthesize extendedEdges = _extendedEdges;
22
23 - (instancetype)initWithFrame:(CGRect)frame {
24 self = [super initWithFrame:frame];
25 if (self) {
26 self.exclusiveTouch = YES;
27 }
28 return self;
29 }
30
31 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {
32 return CGRectContainsPoint([self touchArea], point);
33 }
34
35 - (void)setExtendedEdges:(UIEdgeInsets)extendedEdges {
36 // Check that the custom edge extensions meet Apple's guidelines.
37 DCHECK_GE(
38 extendedEdges.top + extendedEdges.bottom + CGRectGetHeight(self.bounds),
39 kMinimumLength - 0.001);
40 DCHECK_GE(
41 extendedEdges.left + extendedEdges.right + CGRectGetWidth(self.bounds),
42 kMinimumLength - 0.001);
43 _extendedEdges = extendedEdges;
44 self.doesExtendEdges = YES;
45 }
46
47 - (CGRect)touchArea {
48 UIEdgeInsets reversedInsets;
49 if (self.doesExtendEdges) {
50 reversedInsets =
51 UIEdgeInsetsMake(-self.extendedEdges.top, -self.extendedEdges.left,
52 -self.extendedEdges.bottom, -self.extendedEdges.right);
53 } else {
54 CGFloat horizontalExtension =
55 (kMinimumLength - CGRectGetWidth(self.bounds)) / 2.0;
56 horizontalExtension = MAX(horizontalExtension, 0);
57 CGFloat verticalExtension =
58 (kMinimumLength - CGRectGetHeight(self.bounds)) / 2.0;
59 verticalExtension = MAX(verticalExtension, 0);
60 reversedInsets = UIEdgeInsetsMake(-verticalExtension, -horizontalExtension,
61 -verticalExtension, -horizontalExtension);
62 }
63 return UIEdgeInsetsInsetRect(self.bounds, reversedInsets);
64 }
65
66 - (CGRect)accessibilityFrame {
67 CGRect touchArea = [self touchArea];
68 CGRect touchAreaInWindowCoordinates = [self convertRect:touchArea toView:nil];
69 CGRect touchAreaInScreenCoordinates =
70 [self.window convertRect:touchAreaInWindowCoordinates toWindow:nil];
71 return touchAreaInScreenCoordinates;
72 }
73
74 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698