Skip to content

Commit

Permalink
Add util to get the LayoutGuideCenter
Browse files Browse the repository at this point in the history
The layout guide center is inferred from a Browser object. This CL adds a method
to quickly retrieve it.

Bug: 1304193
Change-Id: I57fe059549138df666594700aad566a7d51ed3d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3924342
Commit-Queue: Louis Romero <lpromero@google.com>
Reviewed-by: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052908}
  • Loading branch information
Arcank authored and Chromium LUCI CQ committed Sep 29, 2022
1 parent b42e43b commit 43f5551
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ source_set("form_input_accessory") {
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/default_promo:utils",
"//ios/chrome/browser/ui/main:layout_guide_scene_agent",
"//ios/chrome/browser/ui/main:layout_guide_util",
"//ios/chrome/browser/ui/main:scene_state_header",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:util_swift",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/commands/security_alert_commands.h"
#import "ios/chrome/browser/ui/main/layout_guide_scene_agent.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/main/layout_guide_util.h"
#import "ios/chrome/browser/ui/util/layout_guide_names.h"
#import "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
Expand Down Expand Up @@ -147,9 +145,6 @@ @interface FormInputAccessoryCoordinator () <
@property(nonatomic, readonly)
feature_engagement::Tracker* featureEngagementTracker;

// The layout guide center to use to coordinate views.
@property(nonatomic, readonly) LayoutGuideCenter* layoutGuideCenter;

@end

@implementation FormInputAccessoryCoordinator
Expand Down Expand Up @@ -180,8 +175,9 @@ - (void)start {
self.formInputAccessoryViewController =
[[FormInputAccessoryViewController alloc]
initWithManualFillAccessoryViewControllerDelegate:self];
self.formInputAccessoryViewController.layoutGuideCenter =
self.layoutGuideCenter;
LayoutGuideCenter* layoutGuideCenter =
LayoutGuideCenterForBrowser(self.browser);
self.formInputAccessoryViewController.layoutGuideCenter = layoutGuideCenter;

DCHECK(self.browserState);
auto passwordStore = IOSChromePasswordStoreFactory::GetForBrowserState(
Expand Down Expand Up @@ -210,8 +206,8 @@ - (void)start {
[self.formInputAccessoryViewController.view
addGestureRecognizer:self.formInputAccessoryTapRecognizer];

self.layoutGuide = [self.layoutGuideCenter
makeLayoutGuideNamed:kAutofillFirstSuggestionGuide];
self.layoutGuide =
[layoutGuideCenter makeLayoutGuideNamed:kAutofillFirstSuggestionGuide];
[self.baseViewController.view addLayoutGuide:self.layoutGuide];
}

Expand Down Expand Up @@ -536,18 +532,6 @@ - (ChromeBrowserState*)browserState {
return tracker;
}

- (LayoutGuideCenter*)layoutGuideCenter {
SceneState* sceneState =
SceneStateBrowserAgent::FromBrowser(self.browser)->GetSceneState();
LayoutGuideSceneAgent* layoutGuideSceneAgent =
[LayoutGuideSceneAgent agentFromScene:sceneState];
if (self.browserState && self.browserState->IsOffTheRecord()) {
return layoutGuideSceneAgent.incognitoLayoutGuideCenter;
} else {
return layoutGuideSceneAgent.layoutGuideCenter;
}
}

// Shows confirmation dialog before opening Other passwords.
- (void)showConfirmationDialogToUseOtherPassword {
WebStateList* webStateList = self.browser->GetWebStateList();
Expand Down
13 changes: 13 additions & 0 deletions ios/chrome/browser/ui/main/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ source_set("layout_guide_scene_agent") {
frameworks = [ "UIKit.framework" ]
}

source_set("layout_guide_util") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"layout_guide_util.h",
"layout_guide_util.mm",
]
deps = [
":layout_guide_scene_agent",
":scene_state_header",
"//ios/chrome/browser/browser_state",
]
}

source_set("scene_ui_provider") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "scene_ui_provider.h" ]
Expand Down
14 changes: 14 additions & 0 deletions ios/chrome/browser/ui/main/layout_guide_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_UI_MAIN_LAYOUT_GUIDE_UTIL_H_
#define IOS_CHROME_BROWSER_UI_MAIN_LAYOUT_GUIDE_UTIL_H_

class Browser;
@class LayoutGuideCenter;

// Returns the layout guide center assigned to the given `browser`.
LayoutGuideCenter* LayoutGuideCenterForBrowser(Browser* browser);

#endif // IOS_CHROME_BROWSER_UI_MAIN_LAYOUT_GUIDE_UTIL_H_
27 changes: 27 additions & 0 deletions ios/chrome/browser/ui/main/layout_guide_util.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/ui/main/layout_guide_util.h"

#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/main/layout_guide_scene_agent.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

LayoutGuideCenter* LayoutGuideCenterForBrowser(Browser* browser) {
SceneState* sceneState =
SceneStateBrowserAgent::FromBrowser(browser)->GetSceneState();
LayoutGuideSceneAgent* layoutGuideSceneAgent =
[LayoutGuideSceneAgent agentFromScene:sceneState];
ChromeBrowserState* browserState = browser->GetBrowserState();
if (browserState && browserState->IsOffTheRecord()) {
return layoutGuideSceneAgent.incognitoLayoutGuideCenter;
} else {
return layoutGuideSceneAgent.layoutGuideCenter;
}
}
2 changes: 1 addition & 1 deletion ios/chrome/browser/ui/popup_menu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ source_set("popup_menu") {
"//ios/chrome/browser/ui/icons:action_icons",
"//ios/chrome/browser/ui/icons:symbols",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/main:layout_guide_scene_agent",
"//ios/chrome/browser/ui/main:layout_guide_util",
"//ios/chrome/browser/ui/main:scene_state_header",
"//ios/chrome/browser/ui/ntp/metrics",
"//ios/chrome/browser/ui/popup_menu:metrics_protocols",
Expand Down
22 changes: 4 additions & 18 deletions ios/chrome/browser/ui/popup_menu/popup_menu_help_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/feature_engagement/tracker_factory.h"
#import "ios/chrome/browser/ui/bubble/bubble_view_controller_presenter.h"
#import "ios/chrome/browser/ui/main/layout_guide_scene_agent.h"
#import "ios/chrome/browser/ui/main/layout_guide_util.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/feature_flags.h"
Expand Down Expand Up @@ -47,9 +47,6 @@ @interface PopupMenuHelpCoordinator () <SceneStateObserver>
// (thus the returned value must be checked for null).
@property(nonatomic, readonly) ChromeBrowserState* browserState;

// The layout guide center to use to coordinate views.
@property(nonatomic, readonly) LayoutGuideCenter* layoutGuideCenter;

// The layout guide installed in the base view controller on which to anchor the
// potential IPH bubble.
@property(nonatomic, strong) UILayoutGuide* layoutGuide;
Expand All @@ -73,18 +70,6 @@ - (ChromeBrowserState*)browserState {
return self.browser ? self.browser->GetBrowserState() : nullptr;
}

- (LayoutGuideCenter*)layoutGuideCenter {
SceneState* sceneState =
SceneStateBrowserAgent::FromBrowser(self.browser)->GetSceneState();
LayoutGuideSceneAgent* layoutGuideSceneAgent =
[LayoutGuideSceneAgent agentFromScene:sceneState];
if (self.browserState && self.browserState->IsOffTheRecord()) {
return layoutGuideSceneAgent.incognitoLayoutGuideCenter;
} else {
return layoutGuideSceneAgent.layoutGuideCenter;
}
}

- (feature_engagement::Tracker*)featureEngagementTracker {
ChromeBrowserState* browserState = self.browserState;
if (!browserState)
Expand All @@ -102,8 +87,9 @@ - (void)start {
SceneStateBrowserAgent::FromBrowser(self.browser)->GetSceneState();
[sceneState addObserver:self];

self.layoutGuide =
[self.layoutGuideCenter makeLayoutGuideNamed:kToolsMenuGuide];
LayoutGuideCenter* layoutGuideCenter =
LayoutGuideCenterForBrowser(self.browser);
self.layoutGuide = [layoutGuideCenter makeLayoutGuideNamed:kToolsMenuGuide];
[self.baseViewController.view addLayoutGuide:self.layoutGuide];
}

Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/ui/toolbar/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ source_set("toolbar") {
"//ios/chrome/browser/ui/icons:infobar_icons",
"//ios/chrome/browser/ui/icons:symbols",
"//ios/chrome/browser/ui/location_bar",
"//ios/chrome/browser/ui/main:layout_guide_scene_agent",
"//ios/chrome/browser/ui/main:layout_guide_util",
"//ios/chrome/browser/ui/main:scene_state_header",
"//ios/chrome/browser/ui/menu",
"//ios/chrome/browser/ui/ntp",
Expand Down
21 changes: 3 additions & 18 deletions ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
#import "ios/chrome/browser/ui/commands/find_in_page_commands.h"
#import "ios/chrome/browser/ui/commands/omnibox_commands.h"
#import "ios/chrome/browser/ui/commands/popup_menu_commands.h"
#import "ios/chrome/browser/ui/main/layout_guide_scene_agent.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/main/layout_guide_util.h"
#import "ios/chrome/browser/ui/menu/browser_action_factory.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator+subclassing.h"
Expand All @@ -44,8 +42,6 @@ @interface AdaptiveToolbarCoordinator ()
@property(nonatomic, strong) ToolbarMediator* mediator;
// Actions handler for the toolbar buttons.
@property(nonatomic, strong) ToolbarButtonActionsHandler* actionHandler;
// The layout guide center to use to coordinate views.
@property(nonatomic, readonly) LayoutGuideCenter* layoutGuideCenter;

@end

Expand All @@ -69,7 +65,8 @@ - (void)start {
self.browser->GetBrowserState()->IsOffTheRecord()
? UIUserInterfaceStyleDark
: UIUserInterfaceStyleUnspecified;
self.viewController.layoutGuideCenter = self.layoutGuideCenter;
self.viewController.layoutGuideCenter =
LayoutGuideCenterForBrowser(self.browser);

self.mediator = [[ToolbarMediator alloc] init];
self.mediator.incognito = self.browser->GetBrowserState()->IsOffTheRecord();
Expand All @@ -95,18 +92,6 @@ - (void)stop {

#pragma mark - Properties

- (LayoutGuideCenter*)layoutGuideCenter {
SceneState* sceneState =
SceneStateBrowserAgent::FromBrowser(self.browser)->GetSceneState();
LayoutGuideSceneAgent* layoutGuideSceneAgent =
[LayoutGuideSceneAgent agentFromScene:sceneState];
if (self.browser->GetBrowserState()->IsOffTheRecord()) {
return layoutGuideSceneAgent.incognitoLayoutGuideCenter;
} else {
return layoutGuideSceneAgent.layoutGuideCenter;
}
}

- (void)setLongPressDelegate:(id<PopupMenuLongPressDelegate>)longPressDelegate {
_longPressDelegate = longPressDelegate;
self.viewController.longPressDelegate = longPressDelegate;
Expand Down

0 comments on commit 43f5551

Please sign in to comment.