OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 static NSAttributedString* attributedSubstringFromRange( | 62 static NSAttributedString* attributedSubstringFromRange( |
63 const EphemeralRange& range) { | 63 const EphemeralRange& range) { |
64 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]; | 64 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]; |
65 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; | 65 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; |
66 size_t length = range.endPosition().computeOffsetInContainerNode() - | 66 size_t length = range.endPosition().computeOffsetInContainerNode() - |
67 range.startPosition().computeOffsetInContainerNode(); | 67 range.startPosition().computeOffsetInContainerNode(); |
68 | 68 |
69 unsigned position = 0; | 69 unsigned position = 0; |
70 | 70 |
71 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets nee
ds to be audited. | 71 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets |
72 // see http://crbug.com/590369 for more details. | 72 // needs to be audited. see http://crbug.com/590369 for more details. |
73 range.startPosition() | 73 range.startPosition() |
74 .document() | 74 .document() |
75 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 75 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
76 | 76 |
77 for (TextIterator it(range.startPosition(), range.endPosition()); | 77 for (TextIterator it(range.startPosition(), range.endPosition()); |
78 !it.atEnd() && [string length] < length; it.advance()) { | 78 !it.atEnd() && [string length] < length; it.advance()) { |
79 unsigned numCharacters = it.length(); | 79 unsigned numCharacters = it.length(); |
80 if (!numCharacters) | 80 if (!numCharacters) |
81 continue; | 81 continue; |
82 | 82 |
83 Node* container = it.currentContainer(); | 83 Node* container = it.currentContainer(); |
84 LayoutObject* layoutObject = container->layoutObject(); | 84 LayoutObject* layoutObject = container->layoutObject(); |
85 DCHECK(layoutObject); | 85 DCHECK(layoutObject); |
86 if (!layoutObject) | 86 if (!layoutObject) |
87 continue; | 87 continue; |
88 | 88 |
89 const ComputedStyle* style = layoutObject->style(); | 89 const ComputedStyle* style = layoutObject->style(); |
90 const FontPlatformData& fontPlatformData = | 90 const FontPlatformData& fontPlatformData = |
91 style->font().primaryFont()->platformData(); | 91 style->font().primaryFont()->platformData(); |
92 NSFont* font = toNSFont(fontPlatformData.ctFont()); | 92 NSFont* font = toNSFont(fontPlatformData.ctFont()); |
93 // If the platform font can't be loaded, or the size is incorrect comparing | 93 // If the platform font can't be loaded, or the size is incorrect comparing |
94 // to the computed style, it's likely that the site is using a web font. | 94 // to the computed style, it's likely that the site is using a web font. |
95 // For now, just use the default font instead. | 95 // For now, just use the default font instead. |
96 // TODO(rsesek): Change the font activation flags to allow other processes | 96 // TODO(rsesek): Change the font activation flags to allow other processes |
97 // to use the font. | 97 // to use the font. |
98 // TODO(shuchen): Support scaling the font as necessary according to CSS tra
nsforms. | 98 // TODO(shuchen): Support scaling the font as necessary according to CSS |
| 99 // transforms. |
99 if (!font || | 100 if (!font || |
100 floor(fontPlatformData.size()) != | 101 floor(fontPlatformData.size()) != |
101 floor([[font fontDescriptor] pointSize])) | 102 floor([[font fontDescriptor] pointSize])) |
102 font = [NSFont | 103 font = [NSFont |
103 systemFontOfSize:style->font().getFontDescription().computedSize()]; | 104 systemFontOfSize:style->font().getFontDescription().computedSize()]; |
104 [attrs setObject:font forKey:NSFontAttributeName]; | 105 [attrs setObject:font forKey:NSFontAttributeName]; |
105 | 106 |
106 if (style->visitedDependentColor(CSSPropertyColor).alpha()) | 107 if (style->visitedDependentColor(CSSPropertyColor).alpha()) |
107 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyColor)) | 108 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyColor)) |
108 forKey:NSForegroundColorAttributeName]; | 109 forKey:NSForegroundColorAttributeName]; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (ephemeralRange.isNull()) | 202 if (ephemeralRange.isNull()) |
202 return nil; | 203 return nil; |
203 | 204 |
204 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); | 205 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); |
205 if (baselinePoint) | 206 if (baselinePoint) |
206 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result); | 207 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result); |
207 return result; | 208 return result; |
208 } | 209 } |
209 | 210 |
210 } // namespace blink | 211 } // namespace blink |
OLD | NEW |