Commit 0adcae18 authored by Ramya Sharma's avatar Ramya Sharma Committed by Commit Bot

Shifts focus to newly created folder.

Two issues when new folder was created:
1. if row is behind k/b then it is not visible to user to edit. 
2. if the newly created folder is below visible area on screen, cell is not created
and hence we cannot shift focus to this newly created folder.

Demo: https://drive.google.com/a/chromium.org/file/d/0B5e_gsRJBxElb2ZUSWxqczBMX3M/view?usp=sharing
Bug: 695749,766623
Change-Id: Iea25042088942d4ada50f90e392e5921514743cb
Reviewed-on: https://chromium-review.googlesource.com/671825
Commit-Queue: Ramya Sharma <ramyasharma@chromium.org>
Reviewed-by: default avatarMarti Wong <martiw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502835}
parent 34ff18b2
......@@ -114,6 +114,9 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
@property(nonatomic, readonly, assign) NSInteger bookmarksSection;
@property(nonatomic, readonly, assign) NSInteger sectionCount;
// If a new folder is being added currently.
@property(nonatomic, assign) BOOL addingNewFolder;
@end
@implementation BookmarkTableView
......@@ -126,6 +129,7 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
@synthesize spinnerView = _spinnerView;
@synthesize editing = _editing;
@synthesize dispatcher = _dispatcher;
@synthesize addingNewFolder = _addingNewFolder;
+ (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry {
registry->RegisterIntegerPref(prefs::kIosBookmarkSigninPromoDisplayedCount,
......@@ -186,12 +190,14 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
[self addSubview:self.tableView];
[self bringSubviewToFront:self.tableView];
[self registerForKeyboardNotifications];
[self showEmptyOrLoadingSpinnerBackgroundIfNeeded];
}
return self;
}
- (void)dealloc {
[self removeKeyboardObservers];
[_signinPromoViewMediator signinPromoViewRemoved];
_tableView.dataSource = nil;
_tableView.delegate = nil;
......@@ -238,6 +244,7 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
if (!_currentRootNode) {
return;
}
self.addingNewFolder = YES;
base::string16 folderTitle = base::SysNSStringToUTF16(
l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_GROUP_DEFAULT_NAME));
_editingFolderNode = self.bookmarkModel->AddFolder(
......@@ -355,8 +362,11 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
[cell setNode:node];
if (node == _editingFolderNode) {
[cell startEdit];
cell.textDelegate = self;
// Delay starting edit, so that the cell is fully created.
dispatch_async(dispatch_get_main_queue(), ^{
[cell startEdit];
cell.textDelegate = self;
});
}
[self loadFaviconAtIndexPath:indexPath];
return cell;
......@@ -442,6 +452,7 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
// if editing folder name, cancel it.
if (_editingFolderNode) {
_editingFolderNode = NULL;
self.addingNewFolder = NO;
[self refreshContents];
}
[self.delegate bookmarkTableView:self selectedFolderForNavigation:node];
......@@ -641,6 +652,20 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
[self resetEditNodes];
[self.delegate bookmarkTableViewRefreshContextBar:self];
[self.tableView reloadData];
if (self.addingNewFolder) {
dispatch_async(dispatch_get_main_queue(), ^{
// Scroll to the end of the table if a new folder is being added.
NSIndexPath* indexPath =
[NSIndexPath indexPathForRow:_bookmarkItems.size() - 1
inSection:self.bookmarksSection];
if (indexPath) {
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
});
}
}
// Returns the bookmark node associated with |indexPath|.
......@@ -863,6 +888,58 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
_faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)] = taskId;
}
#pragma mark - Keyboard
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)removeKeyboardObservers {
NSNotificationCenter* notificationCenter =
[NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self
name:UIKeyboardDidShowNotification
object:nil];
[notificationCenter removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize =
[[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
UIEdgeInsets previousContentInsets = self.tableView.contentInset;
// Shift the content inset by the height of the keyboard so we can scoll to
// the bottom of the content that is potentially behind the keyboard.
UIEdgeInsets contentInsets =
UIEdgeInsetsMake(previousContentInsets.top, 0.0, kbSize.height, 0.0);
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
UIEdgeInsets previousContentInsets = self.tableView.contentInset;
// Restore the content inset now that the keyboard has been hidden.
UIEdgeInsets contentInsets =
UIEdgeInsetsMake(previousContentInsets.top, 0, 0, 0);
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
#pragma mark - SyncedSessionsObserver
- (void)reloadSessions {
......@@ -883,6 +960,7 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
- (void)textDidChangeTo:(NSString*)newName {
DCHECK(_editingFolderNode);
self.addingNewFolder = NO;
if (newName.length > 0) {
self.bookmarkModel->SetTitle(_editingFolderNode,
base::SysNSStringToUTF16(newName));
......
......@@ -2099,11 +2099,15 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
NSString* titleIdentifier = @"bookmark_editing_text";
// Type the folder title.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(titleIdentifier)]
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityID(titleIdentifier),
grey_sufficientlyVisible(), nil)]
performAction:grey_replaceText(folderTitle)];
// Press the keyboard return key.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(titleIdentifier)]
[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityID(titleIdentifier),
grey_sufficientlyVisible(), nil)]
performAction:grey_typeText(@"\n")];
// Wait until the editing textfield is gone.
......@@ -2114,9 +2118,11 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
// 1. Spinner background.
// 2. Reorder bookmarks.
// 3. Current root node removed: Verify that the New Folder, Select button are
// disabled and empty background appears when _currentRootNode becomes NULL
// (maybe programmatically remove the current root node from model, and trigger
// a sync).
// disabled and empty background appears when _currentRootNode becomes NULL
// (maybe programmatically remove the current root node from model, and
// trigger a sync).
// 4. Restoring y position when opening from cache.
// 5. Adding new folder when when existing bookmarks list covers full screen
// height,to ensure we scroll to the newly added folder.
@end
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