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

Side by Side Diff: ios/chrome/browser/ui/open_in_toolbar.mm

Issue 2589803002: Upstream Chrome on iOS source code [6/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/open_in_toolbar.h"
6
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
10 #include "ios/chrome/browser/ui/rtl_geometry.h"
11 #import "ios/chrome/browser/ui/uikit_ui_util.h"
12 #include "ios/chrome/grit/ios_strings.h"
13 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
14 #include "ui/base/l10n/l10n_util_mac.h"
15
16 namespace {
17
18 // The toolbar's open button constants.
19 const CGFloat kOpenButtonVerticalPadding = 8.0f;
20 const CGFloat kOpenButtonTrailingPadding = 16.0f;
21
22 // The toolbar's border related constants.
23 const CGFloat kTopBorderHeight = 0.5f;
24 const CGFloat kTopBorderTransparency = 0.13f;
25 const int kTopBorderColor = 0x000000;
26
27 // The toolbar's background related constants.
28 const int kToolbarBackgroundColor = 0xFFFFFF;
29 const CGFloat kToolbarBackgroundTransparency = 0.97f;
30
31 } // anonymous namespace
32
33 @interface OpenInToolbar () {
34 // Backing object for |self.openButton|.
35 base::scoped_nsobject<MDCButton> _openButton;
36 // Backing object for |self.topBorder|.
37 base::scoped_nsobject<UIView> _topBorder;
38 }
39
40 // The "Open in..." button that's hooked up with the target and action passed
41 // on initialization.
42 @property(nonatomic, retain, readonly) MDCButton* openButton;
43
44 // The line used as the border at the top of the toolbar.
45 @property(nonatomic, retain, readonly) UIView* topBorder;
46
47 @end
48
49 @implementation OpenInToolbar
50
51 - (instancetype)initWithFrame:(CGRect)aRect {
52 NOTREACHED();
53 return nil;
54 }
55
56 - (instancetype)initWithTarget:(id)target action:(SEL)action {
57 self = [super initWithFrame:CGRectZero];
58 if (self) {
59 DCHECK([target respondsToSelector:action]);
60 [self setBackgroundColor:UIColorFromRGB(kToolbarBackgroundColor,
61 kToolbarBackgroundTransparency)];
62 [self addSubview:self.openButton];
63 [self.openButton addTarget:target
64 action:action
65 forControlEvents:UIControlEventTouchUpInside];
66 [self addSubview:self.topBorder];
67 }
68 return self;
69 }
70
71 #pragma mark Accessors
72
73 - (MDCButton*)openButton {
74 if (!_openButton) {
75 _openButton.reset([[MDCFlatButton alloc] init]);
76 [_openButton setCustomTitleColor:[[MDCPalette cr_bluePalette] tint500]];
77 [_openButton setTitle:l10n_util::GetNSStringWithFixup(IDS_IOS_OPEN_IN)
78 forState:UIControlStateNormal];
79 [_openButton sizeToFit];
80 }
81 return _openButton.get();
82 }
83
84 - (UIView*)topBorder {
85 if (!_topBorder) {
86 _topBorder.reset([[UIView alloc] initWithFrame:CGRectZero]);
87 [_topBorder setBackgroundColor:UIColorFromRGB(kTopBorderColor,
88 kTopBorderTransparency)];
89 }
90 return _topBorder.get();
91 }
92
93 #pragma mark Layout
94
95 - (void)layoutSubviews {
96 [super layoutSubviews];
97
98 // openButton layout.
99 CGFloat buttonWidth = CGRectGetWidth(self.openButton.bounds);
100 CGFloat buttonHeight = CGRectGetHeight(self.openButton.bounds);
101
102 LayoutRect layout = LayoutRectMake(
103 CGRectGetMaxX(self.bounds) - buttonWidth - kOpenButtonTrailingPadding,
104 CGRectGetWidth(self.bounds),
105 CGRectGetMaxY(self.bounds) - buttonHeight - kOpenButtonVerticalPadding,
106 buttonWidth, buttonHeight);
107 self.openButton.frame = LayoutRectGetRect(layout);
108
109 // topBorder layout.
110 CGRect topBorderFrame = self.bounds;
111 topBorderFrame.size.height = kTopBorderHeight;
112 self.topBorder.frame = topBorderFrame;
113 }
114
115 - (CGSize)sizeThatFits:(CGSize)size {
116 CGSize openButtonSize = [self.openButton sizeThatFits:size];
117 CGFloat requiredHeight =
118 openButtonSize.height + 2.0 * kOpenButtonVerticalPadding;
119 return CGSizeMake(size.width, requiredHeight);
120 }
121
122 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/open_in_toolbar.h ('k') | ios/chrome/browser/ui/open_in_toolbar_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698