Commit edbaaa23 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Return unrounded size in iOS GetStringWidthF().

This is how other platforms work, and fixes some broken tests.

Bug: 546240
Change-Id: I3b1dc74bbe50b7033aa75b93822f87bab32dfadb
Reviewed-on: https://chromium-review.googlesource.com/c/1343563Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609753}
parent 45a0df8f
...@@ -58,15 +58,7 @@ struct TestData { ...@@ -58,15 +58,7 @@ struct TestData {
} // namespace } // namespace
// TODO(crbug.com/546240): This test fails on iOS because iOS version of TEST(TextEliderTest, ElideEmail) {
// GetStringWidthF that calls [NSString sizeWithFont] returns the rounded string
// width.
#if defined(OS_IOS)
#define MAYBE_ElideEmail DISABLED_ElideEmail
#else
#define MAYBE_ElideEmail ElideEmail
#endif
TEST(TextEliderTest, MAYBE_ElideEmail) {
const std::string kEllipsisStr(kEllipsis); const std::string kEllipsisStr(kEllipsis);
// Test emails and their expected elided forms (from which the available // Test emails and their expected elided forms (from which the available
...@@ -147,15 +139,7 @@ TEST(TextEliderTest, ElideEmailMoreSpace) { ...@@ -147,15 +139,7 @@ TEST(TextEliderTest, ElideEmailMoreSpace) {
} }
} }
// TODO(crbug.com/546240): This test fails on iOS because iOS version of TEST(TextEliderTest, TestFilenameEliding) {
// GetStringWidthF that calls [NSString sizeWithFont] returns the rounded string
// width.
#if defined(OS_IOS)
#define MAYBE_TestFilenameEliding DISABLED_TestFilenameEliding
#else
#define MAYBE_TestFilenameEliding TestFilenameEliding
#endif
TEST(TextEliderTest, MAYBE_TestFilenameEliding) {
const std::string kEllipsisStr(kEllipsis); const std::string kEllipsisStr(kEllipsis);
const base::FilePath::StringType kPathSeparator = const base::FilePath::StringType kPathSeparator =
base::FilePath::StringType().append(1, base::FilePath::kSeparators[0]); base::FilePath::StringType().append(1, base::FilePath::kSeparators[0]);
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/ios/NSString+CrStringDrawing.h"
namespace gfx { namespace gfx {
...@@ -25,7 +24,8 @@ float GetStringWidthF(const base::string16& text, ...@@ -25,7 +24,8 @@ float GetStringWidthF(const base::string16& text,
Typesetter typesetter) { Typesetter typesetter) {
NSString* ns_text = base::SysUTF16ToNSString(text); NSString* ns_text = base::SysUTF16ToNSString(text);
NativeFont native_font = font_list.GetPrimaryFont().GetNativeFont(); NativeFont native_font = font_list.GetPrimaryFont().GetNativeFont();
return [ns_text cr_sizeWithFont:native_font].width; NSDictionary* attributes = @{NSFontAttributeName : native_font};
return [ns_text sizeWithAttributes:attributes].width;
} }
} // namespace gfx } // namespace gfx
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment