summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/DEPS32
-rw-r--r--ios/chrome/browser/DEPS34
-rw-r--r--ios/chrome/common/README.txt2
-rw-r--r--ios/chrome/common/string_util.h44
-rw-r--r--ios/chrome/common/string_util.mm184
-rw-r--r--ios/chrome/common/string_util_unittest.mm58
-rw-r--r--ios/chrome/ios_chrome.gyp21
-rw-r--r--ios/chrome/ios_chrome_tests.gyp2
8 files changed, 32 insertions, 345 deletions
diff --git a/ios/chrome/DEPS b/ios/chrome/DEPS
index 6503a0e..f23eea2 100644
--- a/ios/chrome/DEPS
+++ b/ios/chrome/DEPS
@@ -2,4 +2,36 @@ include_rules = [
# The subdirectories in ios/chrome/ will manually allow their own include
# directories in ios/chrome/ so we disallow all of them.
"-ios/chrome",
+ "+ios/chrome/grit",
+
+ "+components/autofill/core/browser",
+ "+components/autofill/ios/browser",
+ "+components/data_reduction_proxy/core/common",
+ "+components/dom_distiller/core",
+ "+components/dom_distiller/ios",
+ "+components/infobars/core",
+ "+components/keyed_service/core",
+ "+components/keyed_service/ios",
+ "+components/leveldb_proto",
+ "+components/suggestions",
+ "+components/translate/core",
+ "+components/translate/ios",
+ "+components/web_resource",
+ "+components/webp_transcode",
+ "+ios/net",
+ "+ios/public/provider/chrome",
+ "+ios/web/public",
+ "+net",
+ "+third_party/google_toolbox_for_mac",
+ "+ui",
+
+ # For tests.
+ "+ios/public/test",
+
+ # Only parts of skia are compiled on iOS, so we explicitly list the
+ # files that can be included to avoid bringing in more code.
+ "+skia/ext/skia_utils_ios.h",
+
+ # Generated file for translated strings in components.
+ "+grit/components_strings.h",
]
diff --git a/ios/chrome/browser/DEPS b/ios/chrome/browser/DEPS
deleted file mode 100644
index f34a686..0000000
--- a/ios/chrome/browser/DEPS
+++ /dev/null
@@ -1,34 +0,0 @@
-include_rules = [
- "+ios/chrome/grit",
-
- "+components/autofill/core/browser",
- "+components/autofill/ios/browser",
- "+components/data_reduction_proxy/core/common",
- "+components/dom_distiller/core",
- "+components/dom_distiller/ios",
- "+components/infobars/core",
- "+components/keyed_service/core",
- "+components/keyed_service/ios",
- "+components/leveldb_proto",
- "+components/suggestions",
- "+components/translate/core",
- "+components/translate/ios",
- "+components/web_resource",
- "+components/webp_transcode",
- "+ios/net",
- "+ios/public/provider/chrome",
- "+ios/web/public",
- "+net",
- "+third_party/google_toolbox_for_mac",
- "+ui",
-
- # For tests.
- "+ios/public/test",
-
- # Only parts of skia are compiled on iOS, so we explicitly list the
- # files that can be included to avoid bringing in more code.
- "+skia/ext/skia_utils_ios.h",
-
- # Generated file for translated strings in components.
- "+grit/components_strings.h",
-]
diff --git a/ios/chrome/common/README.txt b/ios/chrome/common/README.txt
deleted file mode 100644
index 72023cf..0000000
--- a/ios/chrome/common/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-This directory holds code shared by Chrome and Chrome iOS extensions.
-
diff --git a/ios/chrome/common/string_util.h b/ios/chrome/common/string_util.h
deleted file mode 100644
index 9176a3a..0000000
--- a/ios/chrome/common/string_util.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IOS_CHROME_COMMON_STRING_UTIL_H_
-#define IOS_CHROME_COMMON_STRING_UTIL_H_
-
-#import <CoreGraphics/CoreGraphics.h>
-#import <Foundation/Foundation.h>
-#include <string>
-
-// Parses a string with an embedded link inside, delineated by BEGIN_LINK and
-// END_LINK. Returns the string without the link delimiters. If |out_link_range|
-// is not null, then it is filled out with the range of the link in the returned
-// string.
-// If no link is found, then it returns |text| and sets |out_link_range| to
-// {NSNotFound, 0}.
-NSString* ParseStringWithLink(NSString* text, NSRange* out_link_range);
-
-// Utility method that returns an NSCharacterSet containing Unicode graphics
-// and drawing characters (but not including the Braille Patterns characters).
-NSCharacterSet* GraphicCharactersSet();
-
-// Cleans an NSString by collapsing whitespace and (if |trim| is true)
-// removing leading and trailing spaces. If |removeGraphicChars| is true,
-// unicode graphic characters will also be removed from the string.
-NSString* CleanNSStringForDisplay(NSString* dirty,
- BOOL removeGraphicChars,
- BOOL trim);
-
-// Cleans a std::string identically to CleanNSStringForDisplay()
-std::string CleanStringForDisplay(std::string dirty,
- BOOL removeGraphicChars,
- BOOL trim);
-
-// Find the longest leading substring of |string| that, when rendered with
-// |attributes|, will fit on a single line inside |targetWidth|. If |trailing|
-// is YES, then find the trailing (instead of leading) substring.
-NSString* SubstringOfWidth(NSString* string,
- NSDictionary* attributes,
- CGFloat targetWidth,
- BOOL trailing);
-
-#endif // IOS_CHROME_COMMON_STRING_UTIL_H_
diff --git a/ios/chrome/common/string_util.mm b/ios/chrome/common/string_util.mm
deleted file mode 100644
index 1d0510a..0000000
--- a/ios/chrome/common/string_util.mm
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ios/chrome/common/string_util.h"
-
-#import <UIKit/UIKit.h>
-
-#include "base/logging.h"
-#include "base/mac/scoped_block.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/sys_string_conversions.h"
-
-namespace {
-typedef BOOL (^ArrayFilterProcedure)(id object, NSUInteger index, BOOL* stop);
-typedef NSString* (^SubstringExtractionProcedure)(NSUInteger);
-}
-
-NSString* ParseStringWithLink(NSString* text, NSRange* out_link_range) {
- // Find the range within |text| and create a substring without the link tags.
- NSRange begin_range = [text rangeOfString:@"BEGIN_LINK[ \t]*"
- options:NSRegularExpressionSearch];
- NSRange link_text_range = NSMakeRange(NSNotFound, 0);
- if (begin_range.length == 0) {
- if (out_link_range)
- *out_link_range = link_text_range;
- return text;
- }
-
- NSUInteger after_begin_link = NSMaxRange(begin_range);
- NSRange range_to_search_for_end_link =
- NSMakeRange(after_begin_link, text.length - after_begin_link);
- NSRange end_range = [text rangeOfString:@"[ \t]*END_LINK"
- options:NSRegularExpressionSearch
- range:range_to_search_for_end_link];
- if (end_range.length == 0) {
- if (out_link_range)
- *out_link_range = link_text_range;
- return text;
- }
-
- link_text_range.location = after_begin_link;
- link_text_range.length = end_range.location - link_text_range.location;
- base::scoped_nsobject<NSMutableString> out_text(
- [[NSMutableString alloc] init]);
- // First part - before the link.
- if (begin_range.location > 0)
- [out_text appendString:[text substringToIndex:begin_range.location]];
-
- // Link part.
- [out_text appendString:[text substringWithRange:link_text_range]];
-
- // Last part - after the link.
- NSUInteger after_end_link = NSMaxRange(end_range);
- if (after_end_link < [text length]) {
- [out_text appendString:[text substringFromIndex:after_end_link]];
- }
-
- link_text_range.location = begin_range.location;
- if (out_link_range)
- *out_link_range = link_text_range;
- return [NSString stringWithString:out_text];
-}
-
-// Ranges of unicode codepage containing drawing characters.
-// 2190—21FF Arrows
-// 2200—22FF Mathematical Operators
-// 2300—23FF Miscellaneous Technical
-// 2400—243F Control Pictures
-// 2440—245F Optical Character Recognition
-// 2460—24FF Enclosed Alphanumerics
-// 2500—257F Box Drawing
-// 2580—259F Block Elements
-// 25A0—25FF Geometric Shapes
-// 2600—26FF Miscellaneous Symbols
-// 2700—27BF Dingbats
-// 27C0—27EF Miscellaneous Mathematical Symbols-A
-// 27F0—27FF Supplemental Arrows-A
-// 2900—297F Supplemental Arrows-B
-// 2980—29FF Miscellaneous Mathematical Symbols-B
-// 2A00—2AFF Supplemental Mathematical Operators
-// 2B00—2BFF Miscellaneous Symbols and Arrows
-// The section 2800—28FF Braille Patterns must be preserved.
-// The list of characters that must be deleted from the selection.
-NSCharacterSet* GraphicCharactersSet() {
- static NSMutableCharacterSet* graphicalCharsSet;
- static dispatch_once_t dispatch_once_token;
- dispatch_once(&dispatch_once_token, ^{
- graphicalCharsSet = [[NSMutableCharacterSet alloc] init];
- NSRange graphicalCharsFirstRange = NSMakeRange(0x2190, 0x2800 - 0x2190);
- NSRange graphicalCharsSecondRange = NSMakeRange(0x2900, 0x2c00 - 0x2900);
- [graphicalCharsSet addCharactersInRange:graphicalCharsFirstRange];
- [graphicalCharsSet addCharactersInRange:graphicalCharsSecondRange];
- });
- return graphicalCharsSet;
-}
-
-// TODO(marq): Add unit tests for this function.
-NSString* CleanNSStringForDisplay(NSString* dirty,
- BOOL removeGraphicChars,
- BOOL trim) {
- NSCharacterSet* wspace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
- NSString* cleanString = dirty;
- if (removeGraphicChars) {
- cleanString = [[cleanString
- componentsSeparatedByCharactersInSet:GraphicCharactersSet()]
- componentsJoinedByString:@" "];
- }
- base::scoped_nsobject<NSMutableArray> spaceSeparatedCompoments(
- [[cleanString componentsSeparatedByCharactersInSet:wspace] mutableCopy]);
- ArrayFilterProcedure filter = ^(id object, NSUInteger index, BOOL* stop) {
- return [object isEqualToString:@""];
- };
- [spaceSeparatedCompoments
- removeObjectsAtIndexes:[spaceSeparatedCompoments
- indexesOfObjectsPassingTest:filter]];
- cleanString = [spaceSeparatedCompoments componentsJoinedByString:@" "];
- return trim ? [cleanString stringByTrimmingCharactersInSet:wspace]
- : cleanString;
-}
-
-std::string CleanStringForDisplay(std::string dirty,
- BOOL removeGraphicChars,
- BOOL trim) {
- return base::SysNSStringToUTF8(CleanNSStringForDisplay(
- base::SysUTF8ToNSString(dirty), removeGraphicChars, trim));
-}
-
-// TODO(marq): Add unit tests for this function.
-NSString* SubstringOfWidth(NSString* string,
- NSDictionary* attributes,
- CGFloat targetWidth,
- BOOL trailing) {
- if (![string length])
- return nil;
-
- UIFont* font = [attributes objectForKey:NSFontAttributeName];
- DCHECK(font);
-
- // Function to get the correct substring while insulating against
- // length overrun/underrun.
- base::mac::ScopedBlock<SubstringExtractionProcedure> getSubstring;
- if (trailing) {
- getSubstring.reset([^NSString*(NSUInteger chars) {
- NSUInteger length = [string length];
- return [string substringFromIndex:length - MIN(length, chars)];
- } copy]);
- } else {
- getSubstring.reset([^NSString*(NSUInteger chars) {
- return [string substringToIndex:MIN(chars, [string length])];
- } copy]);
- }
-
- // Guess at the number of characters that will fit, assuming
- // the font's x-height is about 25% wider than an average character (25%
- // value was determined experimentally).
- NSUInteger characters =
- MIN(targetWidth / (font.xHeight * 0.8), [string length]);
- NSInteger increment = 1;
- NSString* substring = getSubstring.get()(characters);
- CGFloat prevWidth = [substring sizeWithAttributes:attributes].width;
- do {
- characters += increment;
- substring = getSubstring.get()(characters);
- CGFloat thisWidth = [substring sizeWithAttributes:attributes].width;
- if (prevWidth > targetWidth) {
- if (thisWidth < targetWidth)
- break; // Shrinking the string, found the right size.
- else
- increment = -1; // Shrink the string
- } else if (prevWidth < targetWidth) {
- if (thisWidth < targetWidth)
- increment = 1; // Grow the string
- else {
- substring = getSubstring.get()(characters - increment);
- break; // Growing the string, found the right size.
- }
- }
- prevWidth = thisWidth;
- } while (characters > 0 && characters < [string length]);
-
- return substring;
-}
diff --git a/ios/chrome/common/string_util_unittest.mm b/ios/chrome/common/string_util_unittest.mm
deleted file mode 100644
index fb70bec..0000000
--- a/ios/chrome/common/string_util_unittest.mm
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ios/chrome/common/string_util.h"
-
-#include "base/mac/scoped_nsobject.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-namespace {
-
-TEST(StringUtilTest, ParseStringWithLink) {
- NSArray* const all_test_data = @[
- @{
- @"input" : @"Text without link.",
- @"expected" : @"Text without link.",
- @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
- },
- @{
- @"input" : @"Text with empty link BEGIN_LINK END_LINK.",
- @"expected" : @"Text with empty link .",
- @"link range" : [NSValue valueWithRange:NSMakeRange(21, 0)]
- },
- @{
- @"input" : @"Text with BEGIN_LINK and no end link.",
- @"expected" : @"Text with BEGIN_LINK and no end link.",
- @"link range" : [NSValue valueWithRange:NSMakeRange(NSNotFound, 0)]
- },
- @{
- @"input" : @"Text with valid BEGIN_LINK link END_LINK and spaces.",
- @"expected" : @"Text with valid link and spaces.",
- @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
- },
- @{
- @"input" : @"Text with valid BEGIN_LINKlinkEND_LINK and no spaces.",
- @"expected" : @"Text with valid link and no spaces.",
- @"link range" : [NSValue valueWithRange:NSMakeRange(16, 4)]
- }
- ];
- for (NSDictionary* test_data : all_test_data) {
- NSString* input_text = test_data[@"input"];
- NSString* expected_text = test_data[@"expected"];
- NSRange expected_range = [test_data[@"link range"] rangeValue];
-
- EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, nullptr));
-
- // Initialize |range| with some values that are not equal to the expected
- // ones.
- NSRange range = NSMakeRange(1000, 2000);
- EXPECT_NSEQ(expected_text, ParseStringWithLink(input_text, &range));
- EXPECT_EQ(expected_range.location, range.location);
- EXPECT_EQ(expected_range.length, range.length);
- }
-}
-
-} // namespace
diff --git a/ios/chrome/ios_chrome.gyp b/ios/chrome/ios_chrome.gyp
index 3b0d999..b2029dc 100644
--- a/ios/chrome/ios_chrome.gyp
+++ b/ios/chrome/ios_chrome.gyp
@@ -39,7 +39,6 @@
'../provider/ios_provider_chrome.gyp:ios_provider_chrome_browser',
'../web/ios_web.gyp:ios_web',
'injected_js',
- 'ios_chrome_common',
'ios_chrome_resources.gyp:ios_theme_resources_gen',
],
'link_settings': {
@@ -200,26 +199,6 @@
],
},
{
- 'target_name': 'ios_chrome_common',
- 'type': 'static_library',
- 'include_dirs': [
- '../..',
- ],
- 'dependencies': [
- '../../base/base.gyp:base',
- ],
- 'link_settings': {
- 'libraries': [
- '$(SDKROOT)/System/Library/Frameworks/CoreGraphics.framework',
- '$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
- ],
- },
- 'sources': [
- 'common/string_util.h',
- 'common/string_util.mm',
- ]
- },
- {
'target_name': 'injected_js',
'type': 'none',
'sources': [
diff --git a/ios/chrome/ios_chrome_tests.gyp b/ios/chrome/ios_chrome_tests.gyp
index 3af8d8f..7cea1a3 100644
--- a/ios/chrome/ios_chrome_tests.gyp
+++ b/ios/chrome/ios_chrome_tests.gyp
@@ -20,7 +20,6 @@
'../web/ios_web.gyp:ios_web',
'../web/ios_web.gyp:test_support_ios_web',
'ios_chrome.gyp:ios_chrome_browser',
- 'ios_chrome.gyp:ios_chrome_common',
'ios_chrome_test_support',
],
'sources': [
@@ -33,7 +32,6 @@
'browser/ui/commands/set_up_for_testing_command_unittest.mm',
'browser/ui/ui_util_unittest.mm',
'browser/ui/uikit_ui_util_unittest.mm',
- 'common/string_util_unittest.mm',
],
},
{