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

Side by Side Diff: ios/chrome/browser/ui/ntp/recent_tabs/views/panel_bar_view.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 #include "ios/chrome/browser/ui/ntp/recent_tabs/views/panel_bar_view.h"
6
7 #import "ios/chrome/browser/ui/ntp/recent_tabs/views/views_utils.h"
8 #include "ios/chrome/browser/ui/rtl_geometry.h"
9 #include "ios/chrome/browser/ui/ui_util.h"
10 #import "ios/chrome/browser/ui/uikit_ui_util.h"
11 #include "ios/chrome/grit/ios_strings.h"
12 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
13 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
14 #include "ui/base/l10n/l10n_util_mac.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 namespace {
21
22 const int kBackgroundColor = 0xf2f2f2;
23 const CGFloat kFontSize = 20;
24
25 } // namespace
26
27 @interface PanelBarView () {
28 UIButton* _closeButton;
29 NSLayoutConstraint* _statusBarSpacerConstraint;
30 }
31 // Whether the panel view extends throughout the whole screen. For example,
32 // when presented fullscreen, the panel bar extends to the borders of the app
33 // and the function returns YES.
34 // When presented modally as on iPad and iPhone 6 Plus landscape, it returns NO.
35 - (BOOL)coversFullAppWidth;
36 @end
37
38 @implementation PanelBarView
39
40 - (instancetype)init {
41 self = [super initWithFrame:CGRectZero];
42 if (self) {
43 [self setBackgroundColor:UIColorFromRGB(kBackgroundColor)];
44 // Create and add the bar's title.
45 UILabel* title = [[UILabel alloc] initWithFrame:CGRectZero];
46 [title setTranslatesAutoresizingMaskIntoConstraints:NO];
47 [title setFont:[[MDFRobotoFontLoader sharedInstance]
48 mediumFontOfSize:kFontSize]];
49 [title setTextColor:recent_tabs::GetTextColorGray()];
50 [title setTextAlignment:NSTextAlignmentNatural];
51 [title setText:l10n_util::GetNSString(IDS_IOS_NEW_TAB_RECENT_TABS)];
52 [title setBackgroundColor:UIColorFromRGB(kBackgroundColor)];
53 [self addSubview:title];
54
55 // Create and add the bar's close button.
56 _closeButton = [[UIButton alloc] initWithFrame:CGRectZero];
57 [_closeButton setTranslatesAutoresizingMaskIntoConstraints:NO];
58 [_closeButton
59 setTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)
60 .uppercaseString
61 forState:UIControlStateNormal];
62 [_closeButton setTitleColor:recent_tabs::GetTextColorGray()
63 forState:UIControlStateNormal];
64 [[_closeButton titleLabel] setFont:[MDCTypography buttonFont]];
65 [_closeButton setAccessibilityIdentifier:@"Exit"];
66 [self addSubview:_closeButton];
67
68 // Create and add the view that adds vertical padding that matches the
69 // status bar's height.
70 UIView* statusBarSpacer = [[UIView alloc] initWithFrame:CGRectZero];
71 [statusBarSpacer setTranslatesAutoresizingMaskIntoConstraints:NO];
72 [self addSubview:statusBarSpacer];
73
74 // Add the constraints on all the subviews.
75 NSDictionary* viewsDictionary = @{
76 @"title" : title,
77 @"closeButton" : _closeButton,
78 @"statusBar" : statusBarSpacer,
79 };
80 NSArray* constraints = @[
81 @"V:|-0-[statusBar]-14-[closeButton]-13-|",
82 @"H:|-16-[title]-(>=0)-[closeButton]-16-|",
83 ];
84 ApplyVisualConstraintsWithOptions(constraints, viewsDictionary,
85 LayoutOptionForRTLSupport(), self);
86 AddSameCenterYConstraint(self, title, _closeButton);
87 _statusBarSpacerConstraint =
88 [NSLayoutConstraint constraintWithItem:statusBarSpacer
89 attribute:NSLayoutAttributeHeight
90 relatedBy:NSLayoutRelationEqual
91 toItem:nil
92 attribute:NSLayoutAttributeNotAnAttribute
93 multiplier:1
94 constant:0];
95 [self addConstraint:_statusBarSpacerConstraint];
96 }
97 return self;
98 }
99
100 - (void)updateConstraints {
101 UIInterfaceOrientation orientation =
102 [[UIApplication sharedApplication] statusBarOrientation];
103 // On Plus phones in landscape, the modal is not fullscreen. The panel bar
104 // doesn't need to take the status bar into account.
105 BOOL takeStatusBarIntoAccount = [self coversFullAppWidth] ||
106 UIInterfaceOrientationIsPortrait(orientation);
107 if (takeStatusBarIntoAccount) {
108 CGFloat statusBarHeight = StatusBarHeight();
109 [_statusBarSpacerConstraint setConstant:statusBarHeight];
110 } else {
111 [_statusBarSpacerConstraint setConstant:0];
112 }
113 [super updateConstraints];
114 }
115
116 - (void)setCloseTarget:(id)target action:(SEL)action {
117 [_closeButton addTarget:target
118 action:action
119 forControlEvents:UIControlEventTouchUpInside];
120 }
121
122 - (void)layoutSubviews {
123 [self setNeedsUpdateConstraints];
124 [super layoutSubviews];
125 }
126
127 - (BOOL)coversFullAppWidth {
128 return self.traitCollection.horizontalSizeClass ==
129 self.window.traitCollection.horizontalSizeClass;
130 }
131
132 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698