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 @@
FakeboxFocuser>>(self.browser->GetCommandDispatcher());
self.headerController.commandHandler = self.NTPMediator;
self.headerController.delegate = self.NTPMediator;
self.headerController.readingListModel =
ReadingListModelFactory::GetForBrowserState(
self.browser->GetBrowserState());
......
......@@ -40,12 +40,24 @@
using base::UserMetricsAction;
namespace {
const NSString* kScribbleFakeboxElementId = @"fakebox";
} // namespace
#if defined(__IPHONE_13_4)
@interface ContentSuggestionsHeaderViewController (Pointer) <
UIPointerInteractionDelegate>
@end
#endif // defined(__IPHONE_13_4)
#if defined(__IPHONE_14_0)
@interface ContentSuggestionsHeaderViewController (Scribble) <
UIIndirectScribbleInteractionDelegate>
@end
#endif // defined(__IPHONE14_0)
@interface ContentSuggestionsHeaderViewController () <
UserAccountImageUpdateDelegate>
......@@ -314,6 +326,14 @@ using base::UserMetricsAction;
[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
action:@selector(loadVoiceSearch:)
forControlEvents:UIControlEventTouchUpInside];
......@@ -574,6 +594,61 @@ using base::UserMetricsAction;
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
- (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
......
......@@ -45,6 +45,9 @@
// Returns the edit view animatee.
- (id<EditViewAnimatee>)editViewAnimatee;
// Target to forward omnibox-related scribble events to.
- (UIResponder<UITextInput>*)omniboxScribbleForwardingTarget;
@end
#endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_COORDINATOR_H_
......@@ -262,6 +262,10 @@
return self.omniboxCoordinator.animatee;
}
- (UIResponder<UITextInput>*)omniboxScribbleForwardingTarget {
return self.omniboxCoordinator.scribbleInput;
}
#pragma mark - LoadQueryCommands
- (void)loadQuery:(NSString*)query immediately:(BOOL)immediately {
......@@ -373,10 +377,6 @@
return [self.delegate locationBarModel];
}
- (UIResponder<UITextInput>*)scribbleForwardingTarget {
return self.omniboxCoordinator.scribbleInput;
}
- (void)locationBarRequestScribbleTargetFocus {
[self.omniboxCoordinator focusOmniboxForScribble];
}
......
......@@ -31,7 +31,7 @@
- (void)locationBarCopyTapped;
// 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.
- (void)locationBarRequestScribbleTargetFocus;
......
......@@ -422,7 +422,7 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
(UIScribbleElementIdentifier)elementIdentifier
API_AVAILABLE(ios(14.0)) {
DCHECK(elementIdentifier == kScribbleOmniboxElementId);
return self.delegate.scribbleForwardingTarget.isFirstResponder;
return self.delegate.omniboxScribbleForwardingTarget.isFirstResponder;
}
- (CGRect)
......@@ -442,11 +442,11 @@ const NSString* kScribbleOmniboxElementId = @"omnibox";
completion:
(void (^)(UIResponder<UITextInput>* focusedInput))
completion API_AVAILABLE(ios(14.0)) {
if (!self.delegate.scribbleForwardingTarget.isFirstResponder) {
if (!self.delegate.omniboxScribbleForwardingTarget.isFirstResponder) {
[self.delegate locationBarRequestScribbleTargetFocus];
}
completion(self.delegate.scribbleForwardingTarget);
completion(self.delegate.omniboxScribbleForwardingTarget);
}
#endif // defined(__IPHONE_14_0)
......
......@@ -9,6 +9,10 @@
@protocol NewTabPageControllerDelegate
// Sets the toolbar location bar alpha and vertical offset based on |progress|.
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress;
// The target for scribble events as forwarded by the NTP fakebox.
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_CONTROLLER_PROTOCOL_H_
......@@ -77,6 +77,7 @@
browser:self.browser];
self.contentSuggestionsCoordinator.webState = self.webState;
self.contentSuggestionsCoordinator.toolbarDelegate = self.toolbarDelegate;
[self.contentSuggestionsCoordinator start];
base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited"));
}
......
......@@ -103,6 +103,11 @@
[self.viewController setScrollProgressForTabletOmnibox:progress];
}
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget {
// Only works in primary toolbar.
return nil;
}
#pragma mark - ToolbarCommands
- (void)triggerToolsMenuButtonAnimation {
......
......@@ -27,9 +27,7 @@
// dismissed on such events. For example, the tools menu is closed upon
// rotation.
@interface AdaptiveToolbarViewController
: UIViewController<PopupMenuUIUpdating,
ToolbarConsumer,
NewTabPageControllerDelegate>
: UIViewController <PopupMenuUIUpdating, ToolbarConsumer>
// Button factory.
@property(nonatomic, strong) ToolbarButtonFactory* buttonFactory;
......@@ -48,6 +46,8 @@
- (void)updateForSideSwipeSnapshotOnNTP:(BOOL)onNTP;
// Resets the view after taking a snapshot for a side swipe.
- (void)resetAfterSideSwipeSnapshot;
// Sets the toolbar location bar alpha and vertical offset based on |progress|.
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress;
@end
......
......@@ -171,6 +171,12 @@
}
}
#pragma mark - NewTabPageControllerDelegate
- (UIResponder<UITextInput>*)fakeboxScribbleForwardingTarget {
return self.locationBarCoordinator.omniboxScribbleForwardingTarget;
}
#pragma mark - FakeboxFocuser
- (void)focusOmniboxNoAnimation {
......
......@@ -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
- (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