OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/mac/attributed_string_coder.h" | 5 #include "content/common/mac/attributed_string_coder.h" |
6 | 6 |
7 #include <AppKit/AppKit.h> | 7 #include <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/public/common/common_param_traits.h" | 14 #include "content/public/common/common_param_traits.h" |
15 #include "ipc/ipc_message_utils.h" | 15 #include "ipc/ipc_message_utils.h" |
16 | 16 |
17 namespace mac { | 17 namespace mac { |
18 | 18 |
19 // static | 19 // static |
20 const AttributedStringCoder::EncodedString* AttributedStringCoder::Encode( | 20 const AttributedStringCoder::EncodedString* AttributedStringCoder::Encode( |
(...skipping 17 matching lines...) Expand all Loading... |
38 i = NSMaxRange(effective_range); | 38 i = NSMaxRange(effective_range); |
39 } | 39 } |
40 return encoded_string; | 40 return encoded_string; |
41 } | 41 } |
42 | 42 |
43 // static | 43 // static |
44 NSAttributedString* AttributedStringCoder::Decode( | 44 NSAttributedString* AttributedStringCoder::Decode( |
45 const AttributedStringCoder::EncodedString* str) { | 45 const AttributedStringCoder::EncodedString* str) { |
46 // Create the return value. | 46 // Create the return value. |
47 NSString* plain_text = base::SysUTF16ToNSString(str->string()); | 47 NSString* plain_text = base::SysUTF16ToNSString(str->string()); |
48 scoped_nsobject<NSMutableAttributedString> decoded_string( | 48 base::scoped_nsobject<NSMutableAttributedString> decoded_string( |
49 [[NSMutableAttributedString alloc] initWithString:plain_text]); | 49 [[NSMutableAttributedString alloc] initWithString:plain_text]); |
50 // Iterate over all the encoded attributes, attaching each to the string. | 50 // Iterate over all the encoded attributes, attaching each to the string. |
51 const std::vector<FontAttribute> attributes = str->attributes(); | 51 const std::vector<FontAttribute> attributes = str->attributes(); |
52 for (std::vector<FontAttribute>::const_iterator it = attributes.begin(); | 52 for (std::vector<FontAttribute>::const_iterator it = attributes.begin(); |
53 it != attributes.end(); ++it) { | 53 it != attributes.end(); ++it) { |
54 // Protect against ranges that are outside the range of the string. | 54 // Protect against ranges that are outside the range of the string. |
55 const ui::Range& range = it->effective_range(); | 55 const ui::Range& range = it->effective_range(); |
56 if (range.GetMin() > [plain_text length] || | 56 if (range.GetMin() > [plain_text length] || |
57 range.GetMax() > [plain_text length]) { | 57 range.GetMax() > [plain_text length]) { |
58 continue; | 58 continue; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 *p = AttributedStringCoder::FontAttribute(font, range); | 162 *p = AttributedStringCoder::FontAttribute(font, range); |
163 } | 163 } |
164 return success; | 164 return success; |
165 } | 165 } |
166 | 166 |
167 void ParamTraits<AttributedStringCoder::FontAttribute>::Log( | 167 void ParamTraits<AttributedStringCoder::FontAttribute>::Log( |
168 const param_type& p, std::string* l) { | 168 const param_type& p, std::string* l) { |
169 } | 169 } |
170 | 170 |
171 } // namespace IPC | 171 } // namespace IPC |
OLD | NEW |