Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: third_party/WebKit/Source/web/mac/WebSubstringUtil.mm

Issue 1656163002: Consider Zoom factor when getting bounding rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (!layoutObject) 76 if (!layoutObject)
77 continue; 77 continue;
78 78
79 const ComputedStyle* style = layoutObject->style(); 79 const ComputedStyle* style = layoutObject->style();
80 const FontPlatformData& fontPlatformData = style->font().primaryFont()-> platformData(); 80 const FontPlatformData& fontPlatformData = style->font().primaryFont()-> platformData();
81 NSFont* font = toNSFont(fontPlatformData.ctFont()); 81 NSFont* font = toNSFont(fontPlatformData.ctFont());
82 // If the platform font can't be loaded, it's likely that the site is 82 // If the platform font can't be loaded, it's likely that the site is
83 // using a web font. For now, just use the default font instead. 83 // using a web font. For now, just use the default font instead.
84 // TODO(rsesek): Change the font activation flags to allow other process es 84 // TODO(rsesek): Change the font activation flags to allow other process es
85 // to use the font. 85 // to use the font.
86 // TODO(shuchen): Support scaling the font as necessary according to CSS transforms.
86 if (!font) 87 if (!font)
87 font = [NSFont systemFontOfSize:style->font().fontDescription().comput edSize()]; 88 font = [NSFont systemFontOfSize:style->font().fontDescription().comp utedSize()];
88 [attrs setObject:font forKey:NSFontAttributeName]; 89 [attrs setObject:font forKey:NSFontAttributeName];
89 90
90 if (style->visitedDependentColor(CSSPropertyColor).alpha()) 91 if (style->visitedDependentColor(CSSPropertyColor).alpha())
91 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyCol or)) forKey:NSForegroundColorAttributeName]; 92 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyCol or)) forKey:NSForegroundColorAttributeName];
92 else 93 else
93 [attrs removeObjectForKey:NSForegroundColorAttributeName]; 94 [attrs removeObjectForKey:NSForegroundColorAttributeName];
94 if (style->visitedDependentColor(CSSPropertyBackgroundColor).alpha()) 95 if (style->visitedDependentColor(CSSPropertyBackgroundColor).alpha())
95 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyBac kgroundColor)) forKey:NSBackgroundColorAttributeName]; 96 [attrs setObject:nsColor(style->visitedDependentColor(CSSPropertyBac kgroundColor)) forKey:NSBackgroundColorAttributeName];
96 else 97 else
97 [attrs removeObjectForKey:NSBackgroundColorAttributeName]; 98 [attrs removeObjectForKey:NSBackgroundColorAttributeName];
98 99
99 Vector<UChar> characters; 100 Vector<UChar> characters;
100 it.text().appendTextTo(characters); 101 it.text().appendTextTo(characters);
101 NSString* substring = 102 NSString* substring =
102 [[[NSString alloc] initWithCharacters:characters.data() 103 [[[NSString alloc] initWithCharacters:characters.data()
103 length:characters.size()] autorelease ]; 104 length:characters.size()] autorelease ];
104 [string replaceCharactersInRange:NSMakeRange(position, 0) 105 [string replaceCharactersInRange:NSMakeRange(position, 0)
105 withString:substring]; 106 withString:substring];
106 [string setAttributes:attrs range:NSMakeRange(position, numCharacters)]; 107 [string setAttributes:attrs range:NSMakeRange(position, numCharacters)];
107 position += numCharacters; 108 position += numCharacters;
108 } 109 }
109 return [string autorelease]; 110 return [string autorelease];
110 } 111 }
111 112
112 WebPoint getBaselinePoint(FrameView* frameView, const EphemeralRange& range, NSA ttributedString* string) 113 WebPoint getBaselinePoint(FrameView* frameView, const EphemeralRange& range, NSA ttributedString* string)
113 { 114 {
114 // Compute bottom left corner and convert to AppKit coordinates. 115 // Compute bottom left corner and convert to AppKit coordinates.
115 // TODO(yosin) We shold avoid to create |Range| object. See crbug.com/529985 . 116 // TODO(yosin): We shold avoid to create |Range| object. See crbug.com/52998 5.
116 IntRect stringRect = enclosingIntRect(createRange(range)->boundingRect()); 117 // TODO(shuchen): Support page-zoom for getting the baseline point.
118 IntRect stringRect = frameView->contentsToRootFrame(createRange(range)->boun dingBox());
117 IntPoint stringPoint = stringRect.minXMaxYCorner(); 119 IntPoint stringPoint = stringRect.minXMaxYCorner();
118 stringPoint.setY(frameView->height() - stringPoint.y()); 120 stringPoint.setY(frameView->height() - stringPoint.y());
119 121
120 // Adjust for the font's descender. AppKit wants the baseline point. 122 // Adjust for the font's descender. AppKit wants the baseline point.
121 if ([string length]) { 123 if ([string length]) {
122 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL]; 124 NSDictionary* attributes = [string attributesAtIndex:0 effectiveRange:NU LL];
123 if (NSFont* font = [attributes objectForKey:NSFontAttributeName]) 125 if (NSFont* font = [attributes objectForKey:NSFontAttributeName])
124 stringPoint.move(0, ceil(-[font descender])); 126 stringPoint.move(0, ceil(-[font descender]));
125 } 127 }
126 return stringPoint; 128 return stringPoint;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (ephemeralRange.isNull()) 169 if (ephemeralRange.isNull())
168 return nil; 170 return nil;
169 171
170 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange); 172 NSAttributedString* result = attributedSubstringFromRange(ephemeralRange);
171 if (baselinePoint) 173 if (baselinePoint)
172 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result) ; 174 *baselinePoint = getBaselinePoint(frame->view(), ephemeralRange, result) ;
173 return result; 175 return result;
174 } 176 }
175 177
176 } // namespace blink 178 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698