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

Unified Diff: ios/web/web_state/ui/crw_context_menu_controller.mm

Issue 2801213004: Eliminate extra Native->JS->Native roundrip when showing context menu. (Closed)
Patch Set: Fixed tests Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/ui/crw_context_menu_controller.mm
diff --git a/ios/web/web_state/ui/crw_context_menu_controller.mm b/ios/web/web_state/ui/crw_context_menu_controller.mm
index 8e25f6a435c55ca6ae67178f910c6297a40d0e62..2e7d1dd0fc41a099ea60b6ae72e8f491fab0894d 100644
--- a/ios/web/web_state/ui/crw_context_menu_controller.mm
+++ b/ios/web/web_state/ui/crw_context_menu_controller.mm
@@ -58,8 +58,6 @@ void CancelTouches(UIGestureRecognizer* gesture_recognizer) {
- (void)showContextMenu:(UIGestureRecognizer*)gestureRecognizer;
// Cancels all touch events in the web view (long presses, tapping, scrolling).
- (void)cancelAllTouches;
-// Asynchronously fetches full width of the rendered web page.
-- (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler;
// Asynchronously fetches information about DOM element for the given point (in
// UIView coordinates). |handler| can not be nil. See |_DOMElementForLastTouch|
// for element format description.
@@ -225,33 +223,21 @@ void CancelTouches(UIGestureRecognizer* gesture_recognizer) {
#pragma mark -
#pragma mark Web Page Features
-- (void)fetchWebPageWidthWithCompletionHandler:(void (^)(CGFloat))handler {
- [self executeJavaScript:@"__gCrWeb.getPageWidth();"
- completionHandler:^(id pageWidth, NSError*) {
- handler([base::mac::ObjCCastStrict<NSNumber>(pageWidth) floatValue]);
- }];
-}
-
- (void)fetchDOMElementAtPoint:(CGPoint)point
completionHandler:(void (^)(NSDictionary*))handler {
DCHECK(handler);
- // Convert point into web page's coordinate system (which may be scaled and/or
- // scrolled).
CGPoint scrollOffset = self.scrollPosition;
- CGFloat webViewContentWidth = self.webScrollView.contentSize.width;
- CRWContextMenuController* weakSelf = self;
- [self fetchWebPageWidthWithCompletionHandler:^(CGFloat pageWidth) {
- CGFloat scale = pageWidth / webViewContentWidth;
- CGPoint localPoint = CGPointMake((point.x + scrollOffset.x) * scale,
- (point.y + scrollOffset.y) * scale);
- NSString* const kGetElementScript =
- [NSString stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g);",
- localPoint.x, localPoint.y];
- [weakSelf executeJavaScript:kGetElementScript
- completionHandler:^(id element, NSError*) {
- handler(base::mac::ObjCCastStrict<NSDictionary>(element));
- }];
- }];
+ CGSize webViewContentSize = self.webScrollView.contentSize;
+ CGFloat webViewContentWidth = webViewContentSize.width;
+ CGFloat webViewContentHeight = webViewContentSize.height;
+ NSString* getElementScript = [NSString
+ stringWithFormat:@"__gCrWeb.getElementFromPoint(%g, %g, %g, %g);",
+ point.x + scrollOffset.x, point.y + scrollOffset.y,
+ webViewContentWidth, webViewContentHeight];
+ [self executeJavaScript:getElementScript
+ completionHandler:^(id element, NSError*) {
+ handler(base::mac::ObjCCastStrict<NSDictionary>(element));
+ }];
}
@end
« ios/web/web_state/js/core_js_unittest.mm ('K') | « ios/web/web_state/js/resources/context_menu.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698