Skip to content

Commit

Permalink
ksv: Update tab contents in the second init.
Browse files Browse the repository at this point in the history
ksv inits the side tabs twice to reduce latency: first only inits the
default category to show users, and then inits all categories in the
background. However, in the second init, the view heirarchy changes,
which causes OnBlur on the Tab. This patch only updates the tab
contents in the second init in order to keep the focus.

Bug: 920409
Test: manual.
Change-Id: Id8bdba5cd5ca38d6a8f8490029cfda756733c8ec
Reviewed-on: https://chromium-review.googlesource.com/c/1406239
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622965}
  • Loading branch information
wutao authored and Commit Bot committed Jan 16, 2019
1 parent d3f9092 commit 6fde4b2
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions ash/components/shortcut_viewer/views/keyboard_shortcut_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ void SetupSearchIllustrationView(views::View* illustration_view,
illustration_view->AddChildView(text);
}

views::ScrollView* CreateScrollView() {
views::ScrollView* CreateScrollView(views::View* content_view) {
views::ScrollView* const scroller = new views::ScrollView();
scroller->set_draw_overflow_indicator(false);
scroller->ClipHeightTo(0, 0);
scroller->SetContents(content_view);
return scroller;
}

Expand Down Expand Up @@ -341,37 +342,44 @@ void KeyboardShortcutView::InitCategoriesTabbedPane(
// not want to cache.
active_tab_index_ =
std::max(0, categories_tabbed_pane_->GetSelectedTabIndex());
// Although we remove all child views, when the KeyboardShortcutItemView is
// added back to the |categories_tabbed_pane_|, because there is no width
// changes, it will not layout the KeyboardShortcutItemView again due to the
// |MaybeCalculateAndDoLayout()| optimization in KeyboardShortcutItemView.
// Cannot remove |tab_strip_| and |contents_|, child views of the
// |categories_tabbed_pane_|, because they are added in the ctor of
// TabbedPane.
categories_tabbed_pane_->child_at(0)->RemoveAllChildViews(true);
categories_tabbed_pane_->child_at(1)->RemoveAllChildViews(true);

const bool first_init = initial_category.has_value();
ShortcutCategory current_category = ShortcutCategory::kUnknown;
KeyboardShortcutItemListView* item_list_view;
KeyboardShortcutItemListView* item_list_view = nullptr;
const bool already_has_tabs = categories_tabbed_pane_->GetTabCount() > 0;
int tab_index = -1;
views::View* const tab_contents = categories_tabbed_pane_->child_at(1);
for (const auto& item_view : shortcut_views_) {
const ShortcutCategory category = item_view->category();
DCHECK_NE(ShortcutCategory::kUnknown, category);
if (current_category != category) {
current_category = category;
item_list_view = new KeyboardShortcutItemListView();
views::ScrollView* const scroller = CreateScrollView();
scroller->SetContents(item_list_view);
categories_tabbed_pane_->AddTab(GetStringForCategory(current_category),
scroller);
++tab_index;
views::View* content_view = nullptr;
// Delay constructing a KeyboardShortcutItemListView until it is needed.
if (initial_category.value_or(category) == category) {
item_list_view = new KeyboardShortcutItemListView();
content_view = item_list_view;
} else {
content_view = new views::View();
}

// Create new tabs or update the existing tabs' contents.
if (already_has_tabs) {
auto* scroll_view =
static_cast<views::ScrollView*>(tab_contents->child_at(tab_index));
scroll_view->SetContents(content_view);
} else {
categories_tabbed_pane_->AddTab(GetStringForCategory(current_category),
CreateScrollView(content_view));
}
}

// If |first_init| is true, we only initialize the pane with the
// If |initial_category| has a value, we only initialize the pane with the
// KeyboardShortcutItemView in the specific category in |initial_category|.
// Otherwise, we will initialize all the panes.
if (first_init && category != initial_category.value())
if (initial_category.value_or(category) != category)
continue;

// Add the item to the category contents container.
if (item_list_view->has_children())
item_list_view->AddHorizontalSeparator();
views::StyledLabel* description_label_view =
Expand All @@ -382,6 +390,7 @@ void KeyboardShortcutView::InitCategoriesTabbedPane(
// Remove the search query highlight.
description_label_view->Layout();
}
tab_contents->Layout();
Layout();
}

Expand Down Expand Up @@ -477,9 +486,8 @@ void KeyboardShortcutView::ShowSearchResults(
constexpr int kHorizontalPadding = 128;
found_items_list_view->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kTopPadding, kHorizontalPadding, 0, kHorizontalPadding)));
views::ScrollView* const scroller = CreateScrollView();
scroller->SetContents(found_items_list_view.release());
search_container_content_view = scroller;
search_container_content_view =
CreateScrollView(found_items_list_view.release());
}
replacement_strings.emplace_back(search_query);
search_box_view_->SetAccessibleValue(l10n_util::GetStringFUTF16(
Expand Down

0 comments on commit 6fde4b2

Please sign in to comment.