Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / ui / ios / NSString+CrStringDrawing.mm
blobe9274e9849979fabb6b81e422603e5ebc6b80d83
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.
5 #import "ui/ios/NSString+CrStringDrawing.h"
7 #include "base/logging.h"
8 #include "ui/ios/uikit_util.h"
10 @implementation NSString (CrStringDrawing)
12 - (CGRect)cr_boundingRectWithSize:(CGSize)size
13                              font:(UIFont*)font {
14   NSDictionary* attributes = font ? @{NSFontAttributeName: font} : @{};
15   return [self boundingRectWithSize:size
16                             options:NSStringDrawingUsesLineFragmentOrigin
17                          attributes:attributes
18                             context:nil];
21 - (CGSize)cr_boundingSizeWithSize:(CGSize)size
22                              font:(UIFont*)font {
23   return [self cr_boundingRectWithSize:size font:font].size;
26 - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font {
27   DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value";
28   NSDictionary* attributes = @{ NSFontAttributeName : font };
29   return ui::AlignSizeToUpperPixel([self sizeWithAttributes:attributes]);
32 - (CGSize)cr_sizeWithFont:(UIFont*)font {
33   if (!font)
34     return CGSizeZero;
35   NSDictionary* attributes = @{ NSFontAttributeName : font };
36   CGSize size = [self sizeWithAttributes:attributes];
37   return CGSizeMake(ceil(size.width), ceil(size.height));
40 @end