Commit dcd71cdf authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS] Support scribble in fakebox.

Adds support for scribble in fakebox. For this, an indirect scribble
interaction is added to the fakebox. This interaction delays focusing,
which allows users to write without the fakebox jumping away. Then it
forwards the scribble events to the omnibox.
Adds a ton of plumbing to connect the fakebox and the omnibox.

Bug: 1098342
Change-Id: I3a5783218b5a25dc8146f53252e50348ac1886d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340978
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797211}
parent a349c9ad
...@@ -179,6 +179,7 @@ ...@@ -179,6 +179,7 @@
FakeboxFocuser>>(self.browser->GetCommandDispatcher()); FakeboxFocuser>>(self.browser->GetCommandDispatcher());
self.headerController.commandHandler = self.NTPMediator; self.headerController.commandHandler = self.NTPMediator;
self.headerController.delegate = self.NTPMediator; self.headerController.delegate = self.NTPMediator;
self.headerController.readingListModel = self.headerController.readingListModel =
ReadingListModelFactory::GetForBrowserState( ReadingListModelFactory::GetForBrowserState(
self.browser->GetBrowserState()); self.browser->GetBrowserState());
......
...@@ -40,12 +40,24 @@ ...@@ -40,12 +40,24 @@
using base::UserMetricsAction; using base::UserMetricsAction;
namespace {
const NSString* kScribbleFakeboxElementId = @"fakebox";
} // namespace
#if defined(__IPHONE_13_4) #if defined(__IPHONE_13_4)
@interface ContentSuggestionsHeaderViewController (Pointer) < @interface ContentSuggestionsHeaderViewController (Pointer) <
UIPointerInteractionDelegate> UIPointerInteractionDelegate>
@end @end
#endif // defined(__IPHONE_13_4) #endif // defined(__IPHONE_13_4)
#if defined(__IPHONE_14_0)
@interface ContentSuggestionsHeaderViewController (Scribble) <
UIIndirectScribbleInteractionDelegate>
@end
#endif // defined(__IPHONE14_0)
@interface ContentSuggestionsHeaderViewController () < @interface ContentSuggestionsHeaderViewController () <
UserAccountImageUpdateDelegate> UserAccountImageUpdateDelegate>
...@@ -314,6 +326,14 @@ using base::UserMetricsAction; ...@@ -314,6 +326,14 @@ using base::UserMetricsAction;
[self.headerView addViewsToSearchField:self.fakeOmnibox]; [self.headerView addViewsToSearchField:self.fakeOmnibox];
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
if (@available(iOS 14, *)) {
UIIndirectScribbleInteraction* scribbleInteraction =
[[UIIndirectScribbleInteraction alloc] initWithDelegate:self];
[self.fakeOmnibox addInteraction:scribbleInteraction];
}
#endif // defined(__IPHONE_14_0)
[self.headerView.voiceSearchButton addTarget:self [self.headerView.voiceSearchButton addTarget:self
action:@selector(loadVoiceSearch:) action:@selector(loadVoiceSearch:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
...@@ -574,6 +594,61 @@ using base::UserMetricsAction; ...@@ -574,6 +594,61 @@ using base::UserMetricsAction;
return self.parentViewController.view.safeAreaInsets.top; return self.parentViewController.view.safeAreaInsets.top;
} }
#pragma mark - UIIndirectScribbleInteractionDelegate
#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
- (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
requestElementsInRect:(CGRect)rect
completion:
(void (^)(NSArray<UIScribbleElementIdentifier>*
elements))completion
API_AVAILABLE(ios(14.0)) {
completion(@[ kScribbleFakeboxElementId ]);
}
- (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
isElementFocused:
(UIScribbleElementIdentifier)elementIdentifier
API_AVAILABLE(ios(14.0)) {
DCHECK(elementIdentifier == kScribbleFakeboxElementId);
return self.toolbarDelegate.fakeboxScribbleForwardingTarget.isFirstResponder;
}
- (CGRect)
indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
frameForElement:(UIScribbleElementIdentifier)elementIdentifier
API_AVAILABLE(ios(14.0)) {
DCHECK(elementIdentifier == kScribbleFakeboxElementId);
// Imitate the entire location bar being scribblable.
return interaction.view.bounds;
}
- (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
focusElementIfNeeded:
(UIScribbleElementIdentifier)elementIdentifier
referencePoint:(CGPoint)focusReferencePoint
completion:
(void (^)(UIResponder<UITextInput>* focusedInput))
completion API_AVAILABLE(ios(14.0)) {
if (!self.toolbarDelegate.fakeboxScribbleForwardingTarget.isFirstResponder) {
[self.toolbarDelegate.fakeboxScribbleForwardingTarget becomeFirstResponder];
}
completion(self.toolbarDelegate.fakeboxScribbleForwardingTarget);
}
- (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
shouldDelayFocusForElement:
(UIScribbleElementIdentifier)elementIdentifier
API_AVAILABLE(ios(14.0)) {
DCHECK(elementIdentifier == kScribbleFakeboxElementId);
return YES;
}
#endif // defined(__IPHONE_14_0)
#pragma mark - LogoAnimationControllerOwnerOwner #pragma mark - LogoAnimationControllerOwnerOwner
- (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
......
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
// Returns the edit view animatee. // Returns the edit view animatee.
- (id<EditViewAnimatee>)editViewAnimatee; - (id<EditViewAnimatee>)editViewAnimatee;
// Target to forward omnibox-related scribble events to.
- (UIResponder<UITextInput>*)omniboxScribbleForwardingTarget;
@end @end
#endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_COORDINATOR_H_
...@@ -262,6 +262,10 @@ ...@@ -262,6 +262,10 @@
return self.omniboxCoordinator.animatee; return self.omniboxCoordinator.animatee;
} }
- (UIResponder<UITextInput>*)omniboxScribbleForwardingTarget {
return self.omniboxCoordinator.scribbleInput;
}
#pragma mark - LoadQueryCommands #pragma mark - LoadQueryCommands
- (void)loadQuery:(NSString*)query immediately:(BOOL)immediately { - (void)loadQuery:(NSString*)query immediately:(BOOL)immediately {
...@@ -373,10 +377,6 @@ ...@@ -373,10 +377,6 @@
return [self.delegate locationBarModel]; return [self.delegate locationBarModel];
} }
- (UIResponder<UITextInput>*)scribbleForwardingTarget {
return self.omniboxCoordinator.scribbleInput;
}
- (void)locationBarRequestScribbleTargetFocus { - (void)locationBarRequestScribbleTargetFocus {
[self.omniboxCoordinator focusOmniboxForScribble]; [self.omniboxCoordinator focusOmniboxForScribble];
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
- (void)locationBarCopyTapped; - (void)locationBarCopyTapped;
// Returns the target that location bar scribble events should be forwarded to. // Returns the target that location bar scribble events should be forwarded to.
- (UIResponder<UITextInput>*)scribbleForwardingTarget; - (UIResponder<UITextInput>*)omniboxScribbleForwardingTarget;
// Request the scribble target to be focused. // Request the scribble target to be focused.
- (void)locationBarRequestScribbleTargetFocus; - (void)locationBarRequestScribbleTargetFocus;
......
...@@ -422,7 +422,7 @@ const NSString* kScribbleOmniboxElementId = @"omnibox"; ...@@ -422,7 +422,7 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
(UIScribbleElementIdentifier)elementIdentifier (UIScribbleElementIdentifier)elementIdentifier
API_AVAILABLE(ios(14.0)) { API_AVAILABLE(ios(14.0)) {
DCHECK(elementIdentifier == kScribbleOmniboxElementId); DCHECK(elementIdentifier == kScribbleOmniboxElementId);
return self.delegate.scribbleForwardingTarget.isFirstResponder; return self.delegate.omniboxScribbleForwardingTarget.isFirstResponder;
} }
- (CGRect) - (CGRect)
...@@ -442,11 +442,11 @@ const NSString* kScribbleOmniboxElementId = @"omnibox"; ...@@ -442,11 +442,11 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
completion: completion:
(void (^)(UIResponder<UITextInput>* focusedInput)) (void (^)(UIResponder<UITextInput>* focusedInput))
completion API_AVAILABLE(ios(14.0)) { completion API_AVAILABLE(ios(14.0)) {
if (!self.delegate.scribbleForwardingTarget.isFirstResponder) { if (!self.delegate.omniboxScribbleForwardingTarget.isFirstResponder) {
[self.delegate locationBarRequestScribbleTargetFocus]; [self.delegate locationBarRequestScribbleTargetFocus];
} }
completion(self.delegate.scribbleForwardingTarget); completion(self.delegate.omniboxScribbleForwardingTarget);
} }
#endif // defined(__IPHONE_14_0) #endif // defined(__IPHONE_14_0)
......
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
@protocol NewTabPageControllerDelegate @protocol NewTabPageControllerDelegate
// Sets the toolbar location bar alpha and vertical offset based on |progress|. // Sets the toolbar location bar alpha and vertical offset based on |progress|.
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress; - (void)setScrollProgressForTabletOmnibox:(CGFloat)progress;
// The target for scribble events as forwarded by the NTP fakebox.
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget;
@end @end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_CONTROLLER_PROTOCOL_H_ #endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_CONTROLLER_PROTOCOL_H_
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
browser:self.browser]; browser:self.browser];
self.contentSuggestionsCoordinator.webState = self.webState; self.contentSuggestionsCoordinator.webState = self.webState;
self.contentSuggestionsCoordinator.toolbarDelegate = self.toolbarDelegate; self.contentSuggestionsCoordinator.toolbarDelegate = self.toolbarDelegate;
[self.contentSuggestionsCoordinator start]; [self.contentSuggestionsCoordinator start];
base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited")); base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited"));
} }
......
...@@ -103,6 +103,11 @@ ...@@ -103,6 +103,11 @@
[self.viewController setScrollProgressForTabletOmnibox:progress]; [self.viewController setScrollProgressForTabletOmnibox:progress];
} }
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget {
// Only works in primary toolbar.
return nil;
}
#pragma mark - ToolbarCommands #pragma mark - ToolbarCommands
- (void)triggerToolsMenuButtonAnimation { - (void)triggerToolsMenuButtonAnimation {
......
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
// dismissed on such events. For example, the tools menu is closed upon // dismissed on such events. For example, the tools menu is closed upon
// rotation. // rotation.
@interface AdaptiveToolbarViewController @interface AdaptiveToolbarViewController
: UIViewController<PopupMenuUIUpdating, : UIViewController <PopupMenuUIUpdating, ToolbarConsumer>
ToolbarConsumer,
NewTabPageControllerDelegate>
// Button factory. // Button factory.
@property(nonatomic, strong) ToolbarButtonFactory* buttonFactory; @property(nonatomic, strong) ToolbarButtonFactory* buttonFactory;
...@@ -48,6 +46,8 @@ ...@@ -48,6 +46,8 @@
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP; - (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP;
// Resets the view after taking a snapshot for a side swipe. // Resets the view after taking a snapshot for a side swipe.
- (void)resetAfterSideSwipeSnapshot; - (void)resetAfterSideSwipeSnapshot;
// Sets the toolbar location bar alpha and vertical offset based on |progress|.
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress;
@end @end
......
...@@ -171,6 +171,12 @@ ...@@ -171,6 +171,12 @@
} }
} }
#pragma mark - NewTabPageControllerDelegate
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget {
return self.locationBarCoordinator.omniboxScribbleForwardingTarget;
}
#pragma mark - FakeboxFocuser #pragma mark - FakeboxFocuser
- (void)focusOmniboxNoAnimation { - (void)focusOmniboxNoAnimation {
......
...@@ -47,6 +47,15 @@ ...@@ -47,6 +47,15 @@
} }
} }
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget {
for (id<NewTabPageControllerDelegate> coordinator in self.coordinators) {
if (coordinator.fakeboxScribbleForwardingTarget) {
return coordinator.fakeboxScribbleForwardingTarget;
}
}
return nil;
}
#pragma mark - ToolbarCommands #pragma mark - ToolbarCommands
- (void)triggerToolsMenuButtonAnimation { - (void)triggerToolsMenuButtonAnimation {
......
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