Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" | 5 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" | 8 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" |
| 9 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" | 9 #import "ios/clean/chrome/browser/ui/actions/settings_actions.h" |
| 10 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h" | 10 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h" |
| 11 #import "ios/clean/chrome/browser/ui/commands/settings_commands.h" | 11 #import "ios/clean/chrome/browser/ui/commands/settings_commands.h" |
| 12 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" | 12 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" |
| 13 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" | |
| 13 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_data_source.h " | 14 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_data_source.h " |
| 14 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" | 15 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" |
| 15 #import "ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.h" | 16 #import "ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.h" |
| 16 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" | 17 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" |
| 17 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_toolbar.h" | 18 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_toolbar.h" |
| 18 | 19 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 21 #error "This file requires ARC support." |
| 21 #endif | 22 #endif |
| 22 | 23 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 self.tabs.contentInset = | 84 self.tabs.contentInset = |
| 84 UIEdgeInsetsMake(CGRectGetMaxY(self.toolbar.frame), 0, 0, 0); | 85 UIEdgeInsetsMake(CGRectGetMaxY(self.toolbar.frame), 0, 0, 0); |
| 85 } | 86 } |
| 86 | 87 |
| 87 #pragma mark - SettingsActions | 88 #pragma mark - SettingsActions |
| 88 | 89 |
| 89 - (void)showSettings:(id)sender { | 90 - (void)showSettings:(id)sender { |
| 90 [self.dispatcher showSettings]; | 91 [self.dispatcher showSettings]; |
| 91 } | 92 } |
| 92 | 93 |
| 94 #pragma mark - ToolsMenuActions | |
| 95 | |
| 96 - (void)showToolsMenu:(id)sender { | |
| 97 [self.dispatcher showToolsMenu]; | |
| 98 } | |
| 99 | |
| 93 #pragma mark - TabGridActions | 100 #pragma mark - TabGridActions |
| 94 | 101 |
| 95 - (void)showTabGrid:(id)sender { | 102 - (void)showTabGrid:(id)sender { |
| 96 [self.dispatcher showTabGrid]; | 103 [self.dispatcher showTabGrid]; |
| 97 } | 104 } |
| 98 | 105 |
| 99 - (void)createNewTab:(id)sender { | 106 - (void)createNewTab:(id)sender { |
| 100 [self.dispatcher createAndShowNewTabInTabGrid]; | 107 [self.dispatcher createAndShowNewTabInTabGrid]; |
| 101 } | 108 } |
| 102 | 109 |
| 103 #pragma mark - ZoomTransitionDelegate methods | 110 #pragma mark - ZoomTransitionDelegate methods |
| 104 | 111 |
| 105 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { | 112 - (CGRect)rectForZoomWithKey:(NSObject*)key inView:(UIView*)view { |
| 113 // If key is nil we return a CGRect based on the toolbar position, if not it | |
|
lpromero
2017/04/13 20:43:57
Avoid we :)
| |
| 114 // was set by the TabGrid and we return a CGRect based on the IndexPath of the | |
| 115 // key. | |
| 116 if (!key) { | |
| 117 return [self.toolbar rectForZoomWithKey:key inView:view]; | |
|
lpromero
2017/04/13 20:43:57
Should you formalize as WithKey:nil?
| |
| 118 } | |
| 119 | |
| 106 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key); | 120 NSIndexPath* cellPath = base::mac::ObjCCastStrict<NSIndexPath>(key); |
| 107 if (!key) | |
| 108 return CGRectNull; | |
| 109 UICollectionViewCell* cell = [self.tabs cellForItemAtIndexPath:cellPath]; | 121 UICollectionViewCell* cell = [self.tabs cellForItemAtIndexPath:cellPath]; |
| 110 return [view convertRect:cell.bounds fromView:cell]; | 122 return [view convertRect:cell.bounds fromView:cell]; |
| 111 } | 123 } |
| 112 | 124 |
| 125 #pragma mark - MenuPresentationDelegate | |
| 126 | |
| 127 - (CGRect)frameForMenuPresentation:(UIPresentationController*)presentation { | |
|
lpromero
2017/04/13 20:43:57
Is this the method you wanted to put in a UI util?
| |
| 128 CGSize menuSize = presentation.presentedView.frame.size; | |
| 129 CGRect menuRect; | |
| 130 menuRect.size = menuSize; | |
| 131 | |
| 132 CGRect menuOriginRect = [self rectForZoomWithKey:nil inView:self.view]; | |
| 133 if (CGRectIsNull(menuOriginRect)) { | |
| 134 menuRect.origin = CGPointMake(50, 50); | |
| 135 return menuRect; | |
| 136 } | |
| 137 // Calculate which corner of the menu the origin rect is in. This is | |
| 138 // determined by comparing frames, and thus is RTL-independent. | |
| 139 if (CGRectGetMinX(menuOriginRect) - CGRectGetMinX(self.view.bounds) < | |
| 140 CGRectGetMaxX(self.view.bounds) - CGRectGetMaxX(menuOriginRect)) { | |
| 141 // Origin rect is closer to the left edge of |self.view| than to the right. | |
| 142 menuRect.origin.x = CGRectGetMinX(menuOriginRect); | |
| 143 } else { | |
| 144 // Origin rect is closer to the right edge of |self.view| than to the left. | |
| 145 menuRect.origin.x = CGRectGetMaxX(menuOriginRect) - menuSize.width; | |
| 146 } | |
| 147 | |
| 148 if (CGRectGetMinY(menuOriginRect) - CGRectGetMinY(self.view.bounds) < | |
| 149 CGRectGetMaxY(self.view.bounds) - CGRectGetMaxY(menuOriginRect)) { | |
| 150 // Origin rect is closer to the top edge of |self.view| than to the bottom. | |
| 151 menuRect.origin.y = CGRectGetMinY(menuOriginRect); | |
| 152 } else { | |
| 153 // Origin rect is closer to the bottom edge of |self.view| than to the top. | |
| 154 menuRect.origin.y = CGRectGetMaxY(menuOriginRect) - menuSize.height; | |
| 155 } | |
| 156 | |
| 157 return menuRect; | |
| 158 } | |
| 159 | |
| 113 #pragma mark - TabGridConsumer methods | 160 #pragma mark - TabGridConsumer methods |
| 114 | 161 |
| 115 - (void)addNoTabsOverlay { | 162 - (void)addNoTabsOverlay { |
| 116 // PLACEHOLDER: The new tab grid will have a completely different zero tab | 163 // PLACEHOLDER: The new tab grid will have a completely different zero tab |
| 117 // overlay from the tab switcher. Also, the overlay will be above the recent | 164 // overlay from the tab switcher. Also, the overlay will be above the recent |
| 118 // tabs section. | 165 // tabs section. |
| 119 TabSwitcherPanelOverlayView* overlayView = | 166 TabSwitcherPanelOverlayView* overlayView = |
| 120 [[TabSwitcherPanelOverlayView alloc] initWithFrame:self.tabs.bounds | 167 [[TabSwitcherPanelOverlayView alloc] initWithFrame:self.tabs.bounds |
| 121 browserState:nil]; | 168 browserState:nil]; |
| 122 overlayView.overlayType = | 169 overlayView.overlayType = |
| 123 TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_NO_OPEN_TABS; | 170 TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_NO_OPEN_TABS; |
| 124 overlayView.autoresizingMask = | 171 overlayView.autoresizingMask = |
| 125 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 172 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 126 [self.tabs addSubview:overlayView]; | 173 [self.tabs addSubview:overlayView]; |
| 127 self.noTabsOverlay = overlayView; | 174 self.noTabsOverlay = overlayView; |
| 128 } | 175 } |
| 129 | 176 |
| 130 - (void)removeNoTabsOverlay { | 177 - (void)removeNoTabsOverlay { |
| 131 [self.noTabsOverlay removeFromSuperview]; | 178 [self.noTabsOverlay removeFromSuperview]; |
| 132 } | 179 } |
| 133 | 180 |
| 134 @end | 181 @end |
| OLD | NEW |