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

Side by Side Diff: ios/chrome/browser/ui/autofill/storage_switch_tooltip.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 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/browser/ui/autofill/storage_switch_tooltip.h"
6
7 #include "base/logging.h"
8 #include "components/strings/grit/components_strings.h"
9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
10 #include "ui/base/l10n/l10n_util.h"
11
12 namespace {
13
14 const CGFloat kCornerRadius = 2.0f;
15 const CGFloat kFontSize = 12.0f;
16 const CGFloat kInset = 8.0f;
17
18 } // namespace
19
20 @implementation StorageSwitchTooltip
21
22 - (instancetype)initWithFrame:(CGRect)frame {
23 self = [super initWithFrame:frame];
24 if (self) {
25 NSString* tooltipText =
26 l10n_util::GetNSString(IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP);
27 [self setText:tooltipText];
28 [self setTextColor:[UIColor whiteColor]];
29 [self setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.9]];
30 [[self layer] setCornerRadius:kCornerRadius];
31 [[self layer] setMasksToBounds:YES];
32 [self setFont:[[MDFRobotoFontLoader sharedInstance]
33 regularFontOfSize:kFontSize]];
34 [self setNumberOfLines:0]; // Allows multi-line layout.
35 }
36 return self;
37 }
38
39 - (instancetype)init {
40 return [self initWithFrame:CGRectZero];
41 }
42
43 - (instancetype)initWithCoder:(NSCoder*)aDecoder {
44 NOTREACHED();
45 return nil;
46 }
47
48 // The logic in textRectForBounds:limitedToNumberOfLines: and drawTextInRect:
49 // adds an inset. Based on
50 // http://stackoverflow.com/questions/21167226/resizing-a-uilabel-to-accomodate- insets/21267507#21267507
51 - (CGRect)textRectForBounds:(CGRect)bounds
52 limitedToNumberOfLines:(NSInteger)numberOfLines {
53 UIEdgeInsets insets = {kInset, kInset, kInset, kInset};
54 CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, insets)
55 limitedToNumberOfLines:numberOfLines];
56
57 rect.origin.x -= insets.left;
58 rect.origin.y -= insets.top;
59 rect.size.width += (insets.left + insets.right);
60 rect.size.height += (insets.top + insets.bottom);
61
62 return rect;
63 }
64
65 - (void)drawTextInRect:(CGRect)rect {
66 UIEdgeInsets insets = {kInset, kInset, kInset, kInset};
67 [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
68 }
69
70 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/autofill/storage_switch_tooltip.h ('k') | ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698