Commit fa4f6f47 authored by wutao's avatar wutao Committed by Commit Bot

cros: Reduce the search latency for KSV.

This cl reduces the search latency in Keyboard Shortcut Viewer (KSV).
1. Set a time delay to process key events in search mode. In this way,
users can keep typing in the search box.
2. Reuse the KeyboardShortcutItemView between TabbedView and the search
results. This reduces the layout time for |shortcut_label_view_| in
KeyboardShortcutItemView.
3. To highight matched search queries, we cannot avoid layouting
|description_label_view_| in KeyboardShortcutItemView.

Bug: 818882
Test: Tested on Eve and Minnie
Change-Id: I4b36e18fe3f72fba4884c0cc02fea24ff4416630
Reviewed-on: https://chromium-review.googlesource.com/951709Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542020}
parent 621948db
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/timer/timer.h"
#include "ui/chromeos/search_box/search_box_view_delegate.h" #include "ui/chromeos/search_box/search_box_view_delegate.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -48,6 +49,10 @@ class KeyboardShortcutView : public views::WidgetDelegateView, ...@@ -48,6 +49,10 @@ class KeyboardShortcutView : public views::WidgetDelegateView,
void InitViews(); void InitViews();
// Initialize |categories_tabbed_pane_| with category tabs and containers of
// |shortcut_views_|, called on construction and when exiting search mode.
void InitCategoriesTabbedPane();
// Put focus on the active tab. Used when the first time to show the widget or // Put focus on the active tab. Used when the first time to show the widget or
// after exiting search mode. // after exiting search mode.
void RequestFocusForActiveTab(); void RequestFocusForActiveTab();
...@@ -55,11 +60,8 @@ class KeyboardShortcutView : public views::WidgetDelegateView, ...@@ -55,11 +60,8 @@ class KeyboardShortcutView : public views::WidgetDelegateView,
// Update views' layout based on search box status. // Update views' layout based on search box status.
void UpdateViewsLayout(bool is_search_box_active); void UpdateViewsLayout(bool is_search_box_active);
static KeyboardShortcutView* GetInstanceForTesting(); // Show search results in |search_results_container_|.
int GetTabCountForTesting() const; void ShowSearchResults(const base::string16& search_query);
const std::vector<KeyboardShortcutItemView*>& GetShortcutViewsForTesting() {
return shortcut_views_;
}
// views::WidgetDelegate: // views::WidgetDelegate:
bool CanMaximize() const override; bool CanMaximize() const override;
...@@ -67,17 +69,25 @@ class KeyboardShortcutView : public views::WidgetDelegateView, ...@@ -67,17 +69,25 @@ class KeyboardShortcutView : public views::WidgetDelegateView,
bool CanResize() const override; bool CanResize() const override;
views::ClientView* CreateClientView(views::Widget* widget) override; views::ClientView* CreateClientView(views::Widget* widget) override;
static KeyboardShortcutView* GetInstanceForTesting();
int GetTabCountForTesting() const;
const std::vector<std::unique_ptr<KeyboardShortcutItemView>>&
GetShortcutViewsForTesting() const;
// Owned by views hierarchy. // Owned by views hierarchy.
views::TabbedPane* tabbed_pane_; // The container for category tabs and lists of KeyboardShortcutItemViews.
views::View* search_results_container_; views::TabbedPane* categories_tabbed_pane_ = nullptr;
// The container for KeyboardShortcutItemViews matching a user's query.
views::View* search_results_container_ = nullptr;
// SearchBoxViewBase is a WidgetDelegateView, which owns itself and cannot be // SearchBoxViewBase is a WidgetDelegateView, which owns itself and cannot be
// deleted from the views hierarchy automatically. // deleted from the views hierarchy automatically.
std::unique_ptr<KSVSearchBoxView> search_box_view_; std::unique_ptr<KSVSearchBoxView> search_box_view_;
// Contains all the shortcut item views from all categories. This list is used // Contains all the shortcut item views from all categories. This list is also
// for searching. The views are owned by the Views hierarchy. // used for searching. The views are not owned by the Views hierarchy to avoid
std::vector<KeyboardShortcutItemView*> shortcut_views_; // KeyboardShortcutItemView layout when switching between tabs and search.
std::vector<std::unique_ptr<KeyboardShortcutItemView>> shortcut_views_;
// An illustration to indicate no search results found. Since this view need // An illustration to indicate no search results found. Since this view need
// to be added and removed frequently from the |search_results_container_|, it // to be added and removed frequently from the |search_results_container_|, it
...@@ -88,6 +98,12 @@ class KeyboardShortcutView : public views::WidgetDelegateView, ...@@ -88,6 +98,12 @@ class KeyboardShortcutView : public views::WidgetDelegateView,
// update views' layout. // update views' layout.
bool is_search_box_empty_ = true; bool is_search_box_empty_ = true;
// Cached value of active tab index before entering search mode.
int active_tab_index_ = 0;
// Debounce for search queries.
base::OneShotTimer debounce_timer_;
DISALLOW_COPY_AND_ASSIGN(KeyboardShortcutView); DISALLOW_COPY_AND_ASSIGN(KeyboardShortcutView);
}; };
......
...@@ -25,7 +25,8 @@ class KeyboardShortcutViewTest : public ash::AshTestBase { ...@@ -25,7 +25,8 @@ class KeyboardShortcutViewTest : public ash::AshTestBase {
return GetView()->GetTabCountForTesting(); return GetView()->GetTabCountForTesting();
} }
const std::vector<KeyboardShortcutItemView*>& GetShortcutViews() { const std::vector<std::unique_ptr<KeyboardShortcutItemView>>&
GetShortcutViews() {
DCHECK(GetView()); DCHECK(GetView());
return GetView()->GetShortcutViewsForTesting(); return GetView()->GetShortcutViewsForTesting();
} }
...@@ -55,7 +56,7 @@ TEST_F(KeyboardShortcutViewTest, SideTabsCount) { ...@@ -55,7 +56,7 @@ TEST_F(KeyboardShortcutViewTest, SideTabsCount) {
int category_number = 0; int category_number = 0;
ShortcutCategory current_category = ShortcutCategory::kUnknown; ShortcutCategory current_category = ShortcutCategory::kUnknown;
for (auto* item_view : GetShortcutViews()) { for (const auto& item_view : GetShortcutViews()) {
const ShortcutCategory category = item_view->category(); const ShortcutCategory category = item_view->category();
if (current_category != category) { if (current_category != category) {
DCHECK(current_category < category); DCHECK(current_category < category);
...@@ -74,7 +75,7 @@ TEST_F(KeyboardShortcutViewTest, TopLineCenterAlignedInItemView) { ...@@ -74,7 +75,7 @@ TEST_F(KeyboardShortcutViewTest, TopLineCenterAlignedInItemView) {
// Showing the widget. // Showing the widget.
views::Widget* widget = KeyboardShortcutView::Show(CurrentContext()); views::Widget* widget = KeyboardShortcutView::Show(CurrentContext());
for (auto* item_view : GetShortcutViews()) { for (const auto& item_view : GetShortcutViews()) {
DCHECK(item_view->child_count() == 2); DCHECK(item_view->child_count() == 2);
// The top lines in both |description_label_view_| and // The top lines in both |description_label_view_| and
......
...@@ -274,6 +274,11 @@ void StyledLabel::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { ...@@ -274,6 +274,11 @@ void StyledLabel::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
SchedulePaint(); SchedulePaint();
} }
void StyledLabel::ClearStyleRanges() {
style_ranges_.clear();
PreferredSizeChanged();
}
int StyledLabel::GetDefaultLineHeight() const { int StyledLabel::GetDefaultLineHeight() const {
return specified_line_height_ > 0 return specified_line_height_ > 0
? specified_line_height_ ? specified_line_height_
......
...@@ -139,6 +139,9 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener { ...@@ -139,6 +139,9 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener {
// Sets the horizontal alignment; the argument value is mirrored in RTL UI. // Sets the horizontal alignment; the argument value is mirrored in RTL UI.
void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); void SetHorizontalAlignment(gfx::HorizontalAlignment alignment);
// Clears all the styles applied to the label.
void ClearStyleRanges();
private: private:
struct StyleRange { struct StyleRange {
StyleRange(const gfx::Range& range, StyleRange(const gfx::Range& range,
......
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