Title: [187391] trunk/Source/WebCore
- Revision
- 187391
- Author
- [email protected]
- Date
- 2015-07-25 16:11:16 -0700 (Sat, 25 Jul 2015)
Log Message
Expose TextIndicator-backed snapshot and rect gathering on DOMNode
https://bugs.webkit.org/show_bug.cgi?id=147298
<rdar://problem/21905839>
Reviewed by Sam Weinig.
* bindings/objc/DOM.mm:
(-[DOMNode getPreviewSnapshotImage:andRects:]):
* bindings/objc/DOMExtensions.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (187390 => 187391)
--- trunk/Source/WebCore/ChangeLog 2015-07-25 17:51:21 UTC (rev 187390)
+++ trunk/Source/WebCore/ChangeLog 2015-07-25 23:11:16 UTC (rev 187391)
@@ -1,3 +1,15 @@
+2015-07-25 Tim Horton <[email protected]>
+
+ Expose TextIndicator-backed snapshot and rect gathering on DOMNode
+ https://bugs.webkit.org/show_bug.cgi?id=147298
+ <rdar://problem/21905839>
+
+ Reviewed by Sam Weinig.
+
+ * bindings/objc/DOM.mm:
+ (-[DOMNode getPreviewSnapshotImage:andRects:]):
+ * bindings/objc/DOMExtensions.h:
+
2015-07-25 Ryosuke Niwa <[email protected]>
Another build fix. Removed the unused argument.
Modified: trunk/Source/WebCore/bindings/objc/DOM.mm (187390 => 187391)
--- trunk/Source/WebCore/bindings/objc/DOM.mm 2015-07-25 17:51:21 UTC (rev 187390)
+++ trunk/Source/WebCore/bindings/objc/DOM.mm 2015-07-25 23:11:16 UTC (rev 187391)
@@ -50,6 +50,7 @@
#import "Range.h"
#import "RenderImage.h"
#import "ScriptController.h"
+#import "TextIndicator.h"
#import "WebScriptObjectPrivate.h"
#import <_javascript_Core/APICast.h>
#import <wtf/HashMap.h>
@@ -541,6 +542,48 @@
#endif // PLATFORM(IOS)
+- (void)getPreviewSnapshotImage:(CGImageRef*)cgImage andRects:(NSArray **)rects
+{
+ if (!cgImage || !rects)
+ return;
+
+ *cgImage = nullptr;
+ *rects = nullptr;
+
+ Node* coreNode = core(self);
+
+ Ref<Range> range = rangeOfContents(*coreNode);
+
+ float deviceScaleFactor = coreNode->document().deviceScaleFactor();
+ const float margin = 4 * deviceScaleFactor;
+ RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, TextIndicatorPresentationTransition::None, margin);
+
+ if (!textIndicator)
+ return;
+
+ if (Image* image = textIndicator->contentImage())
+ *cgImage = (CGImageRef)CFAutorelease(CGImageRetain(image->getCGImageRef()));
+
+ RetainPtr<NSMutableArray> rectArray = adoptNS([[NSMutableArray alloc] init]);
+
+ if (*cgImage) {
+ FloatPoint origin = textIndicator->textBoundingRectInRootViewCoordinates().location();
+ for (const FloatRect& rect : textIndicator->textRectsInBoundingRectCoordinates()) {
+ CGRect cgRect = rect;
+ cgRect.origin.x += origin.x();
+ cgRect.origin.y += origin.y();
+ cgRect = coreNode->document().frame()->view()->contentsToWindow(enclosingIntRect(cgRect));
+ [rectArray addObject:[NSValue value:&cgRect withObjCType:@encode(CGRect)]];
+ }
+ } else {
+ CGRect cgRect = CGRectInset(range->boundingRect(), -margin, -margin);
+ cgRect = coreNode->document().frame()->view()->contentsToWindow(enclosingIntRect(cgRect));
+ [rectArray addObject:[NSValue value:&cgRect withObjCType:@encode(CGRect)]];
+ }
+
+ *rects = rectArray.autorelease();
+}
+
@end
@implementation DOMNode (DOMNodeExtensionsPendingPublic)
Modified: trunk/Source/WebCore/bindings/objc/DOMExtensions.h (187390 => 187391)
--- trunk/Source/WebCore/bindings/objc/DOMExtensions.h 2015-07-25 17:51:21 UTC (rev 187390)
+++ trunk/Source/WebCore/bindings/objc/DOMExtensions.h 2015-07-25 23:11:16 UTC (rev 187391)
@@ -109,6 +109,8 @@
- (DOMNode *)nextFocusNode;
- (DOMNode *)previousFocusNode;
#endif
+
+- (void)getPreviewSnapshotImage:(CGImageRef*)cgImage andRects:(NSArray **)rects;
@end
@interface DOMElement (DOMElementAppKitExtensions)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes