Commit d34fe91c authored by edchin's avatar edchin Committed by Commit Bot

[ios] Add drop interaction to incognito NTP

Test: Enable DragAndDrop flag. On iPad multitasking, drop a URL onto incognito NTP.
Bug: 1102574
Change-Id: I006821ad6c4e753769e8cecb3165ac7c0d1f4da5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289547Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790938}
parent 4aa7add5
...@@ -95,6 +95,7 @@ source_set("ntp_internal") { ...@@ -95,6 +95,7 @@ source_set("ntp_internal") {
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/drag_and_drop",
"//ios/chrome/browser/favicon", "//ios/chrome/browser/favicon",
"//ios/chrome/browser/history", "//ios/chrome/browser/history",
"//ios/chrome/browser/metrics:metrics_internal", "//ios/chrome/browser/metrics:metrics_internal",
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/drag_and_drop/drag_and_drop_flag.h"
#import "ios/chrome/browser/drag_and_drop/url_drag_drop_handler.h"
#import "ios/chrome/browser/ui/ntp/incognito_cookies_view.h" #import "ios/chrome/browser/ui/ntp/incognito_cookies_view.h"
#import "ios/chrome/browser/ui/page_info/features.h" #import "ios/chrome/browser/ui/page_info/features.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
...@@ -121,7 +123,7 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) { ...@@ -121,7 +123,7 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
} // namespace } // namespace
@interface IncognitoView () @interface IncognitoView () <URLDropDelegate>
@property(nonatomic, strong) IncognitoCookiesView* cookiesView; @property(nonatomic, strong) IncognitoCookiesView* cookiesView;
...@@ -150,6 +152,9 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) { ...@@ -150,6 +152,9 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
// The UrlLoadingService associated with this view. // The UrlLoadingService associated with this view.
UrlLoadingBrowserAgent* _URLLoader; // weak UrlLoadingBrowserAgent* _URLLoader; // weak
// Handles drop interactions for this view.
URLDragDropHandler* _dragDropHandler;
} }
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
URLLoader:(UrlLoadingBrowserAgent*)URLLoader { URLLoader:(UrlLoadingBrowserAgent*)URLLoader {
...@@ -157,6 +162,13 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) { ...@@ -157,6 +162,13 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
if (self) { if (self) {
_URLLoader = URLLoader; _URLLoader = URLLoader;
if (DragAndDropIsEnabled()) {
_dragDropHandler = [[URLDragDropHandler alloc] init];
_dragDropHandler.dropDelegate = self;
[self addInteraction:[[UIDropInteraction alloc]
initWithDelegate:_dragDropHandler]];
}
self.alwaysBounceVertical = YES; self.alwaysBounceVertical = YES;
// The bottom safe area is taken care of with the bottomUnsafeArea guides. // The bottom safe area is taken care of with the bottomUnsafeArea guides.
self.contentInsetAdjustmentBehavior = self.contentInsetAdjustmentBehavior =
...@@ -350,6 +362,16 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) { ...@@ -350,6 +362,16 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
_visibleDataLabel.textColor = bodyTextColor; _visibleDataLabel.textColor = bodyTextColor;
} }
#pragma mark - URLDropDelegate
- (BOOL)canHandleURLDropInView:(UIView*)view {
return YES;
}
- (void)view:(UIView*)view didDropURL:(const GURL&)URL atPoint:(CGPoint)point {
_URLLoader->Load(UrlLoadParams::InCurrentTab(URL));
}
#pragma mark - Private #pragma mark - Private
// Updates the height of the margins for the top and bottom toolbars. // Updates the height of the margins for the top and bottom toolbars.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment