diff --git a/ash/components/shortcut_viewer/vector_icons/BUILD.gn b/ash/components/shortcut_viewer/vector_icons/BUILD.gn index 124196b9c04d2..06735ca00f7aa 100644 --- a/ash/components/shortcut_viewer/vector_icons/BUILD.gn +++ b/ash/components/shortcut_viewer/vector_icons/BUILD.gn @@ -16,8 +16,6 @@ aggregate_vector_icons("ksv_vector_icons") { "ksv_search_close.icon", "ksv_search_no_result.1x.icon", "ksv_search_no_result.icon", - "ksv_search_start.1x.icon", - "ksv_search_start.icon", "ksv_separator_plus.1x.icon", "ksv_separator_plus.icon", "ksv_arrow_down.1x.icon", diff --git a/ash/components/shortcut_viewer/vector_icons/ksv_search_start.1x.icon b/ash/components/shortcut_viewer/vector_icons/ksv_search_start.1x.icon deleted file mode 100644 index 26f2c7dba3e42..0000000000000 --- a/ash/components/shortcut_viewer/vector_icons/ksv_search_start.1x.icon +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -CANVAS_DIMENSIONS, 150, -MOVE_TO, 110.58f, 43.5f, -H_LINE_TO, 38.47f, -R_CUBIC_TO, -4.96f, 0, -8.97f, 4.05f, -8.97f, 9, -R_LINE_TO, -0.04f, 45, -R_CUBIC_TO, 0, 4.95f, 4.06f, 9, 9.01f, 9, -R_H_LINE_TO, 72.11f, -R_CUBIC_TO, 4.96f, 0, 9.02f, -4.05f, 9.02f, -9, -R_V_LINE_TO, -45, -R_CUBIC_TO, 0, -4.95f, -4.06f, -9, -9.01f, -9, -CLOSE, -MOVE_TO, 70.01f, 57, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -CLOSE, -R_MOVE_TO, 0, 13.5f, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -CLOSE, -MOVE_TO, 56.49f, 57, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -CLOSE, -R_MOVE_TO, 0, 13.5f, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -CLOSE, -R_MOVE_TO, -4.51f, 9, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 0, -13.5f, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 40.56f, 31.5f, -H_LINE_TO, 56.49f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 36.06f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 0, -18, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 0, -13.5f, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 13.52f, 13.5f, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -R_MOVE_TO, 0, -13.5f, -R_H_LINE_TO, -9.01f, -R_V_LINE_TO, -9, -R_H_LINE_TO, 9.01f, -R_V_LINE_TO, 9, -CLOSE, -NEW_PATH, -PATH_COLOR_ARGB, 0xFF, 0x9A, 0xA0, 0xA6, -MOVE_TO, 121.85f, 106.5f, -R_H_LINE_TO, -1.79f, -R_LINE_TO, -0.62f, -0.62f, -R_ARC_TO, 14.47f, 14.47f, 0, 0, 0, 3.54f, -9.51f, -R_CUBIC_TO, 0, -8.08f, -6.56f, -14.62f, -14.65f, -14.62f, -R_CUBIC_TO, -8.09f, 0, -14.65f, 6.55f, -14.65f, 14.63f, -CUBIC_TO_SHORTHAND, 100.23f, 111, 108.32f, 111, -R_CUBIC_TO, 3.64f, 0, 6.96f, -1.33f, 9.52f, -3.52f, -R_LINE_TO, 0.62f, 0.62f, -R_V_LINE_TO, 1.78f, -R_LINE_TO, 11.27f, 11.23f, -R_LINE_TO, 3.36f, -3.35f, -R_LINE_TO, -11.24f, -11.25f, -CLOSE, -R_MOVE_TO, -13.52f, 0, -R_CUBIC_TO, -5.6f, 0, -10.14f, -4.53f, -10.14f, -10.12f, -R_CUBIC_TO, 0, -5.59f, 4.54f, -10.12f, 10.14f, -10.12f, -R_CUBIC_TO, 5.6f, 0, 10.14f, 4.53f, 10.14f, 10.13f, -R_CUBIC_TO, 0, 5.6f, -4.54f, 10.13f, -10.14f, 10.13f, -CLOSE, -END diff --git a/ash/components/shortcut_viewer/vector_icons/ksv_search_start.icon b/ash/components/shortcut_viewer/vector_icons/ksv_search_start.icon deleted file mode 100644 index ad402523b24f8..0000000000000 --- a/ash/components/shortcut_viewer/vector_icons/ksv_search_start.icon +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -CANVAS_DIMENSIONS, 300, -MOVE_TO, 221.16f, 87, -H_LINE_TO, 76.93f, -R_CUBIC_TO, -9.92f, 0, -17.94f, 8.1f, -17.94f, 18, -R_LINE_TO, -0.09f, 90, -R_CUBIC_TO, 0, 9.9f, 8.11f, 18, 18.03f, 18, -R_H_LINE_TO, 144.23f, -R_CUBIC_TO, 9.91f, 0, 18.03f, -8.1f, 18.03f, -18, -R_V_LINE_TO, -90, -R_CUBIC_TO, 0, -9.9f, -8.11f, -18, -18.03f, -18, -CLOSE, -R_MOVE_TO, -81.13f, 27, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -CLOSE, -R_MOVE_TO, 0, 27, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -CLOSE, -R_MOVE_TO, -27.04f, -27, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -CLOSE, -R_MOVE_TO, 0, 27, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -CLOSE, -R_MOVE_TO, -9.01f, 18, -H_LINE_TO, 85.94f, -R_V_LINE_TO, -18, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 0, -27, -H_LINE_TO, 85.94f, -R_V_LINE_TO, -18, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 81.13f, 63, -R_H_LINE_TO, -72.11f, -R_V_LINE_TO, -18, -R_H_LINE_TO, 72.11f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 0, -36, -H_LINE_TO, 167.07f, -R_V_LINE_TO, -18, -H_LINE_TO, 185.1f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 0, -27, -H_LINE_TO, 167.07f, -R_V_LINE_TO, -18, -H_LINE_TO, 185.1f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 27.04f, 27, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -CLOSE, -R_MOVE_TO, 0, -27, -R_H_LINE_TO, -18.03f, -R_V_LINE_TO, -18, -R_H_LINE_TO, 18.03f, -R_V_LINE_TO, 18, -CLOSE, -NEW_PATH, -PATH_COLOR_ARGB, 0xFF, 0x9A, 0xA0, 0xA6, -MOVE_TO, 243.69f, 213, -R_H_LINE_TO, -3.58f, -R_LINE_TO, -1.24f, -1.24f, -R_ARC_TO, 28.95f, 28.95f, 0, 0, 0, 7.08f, -19.01f, -R_CUBIC_TO, 0, -16.15f, -13.12f, -29.25f, -29.3f, -29.25f, -R_CUBIC_TO, -16.18f, 0, -29.3f, 13.1f, -29.3f, 29.25f, -CUBIC_TO_SHORTHAND, 200.47f, 222, 216.65f, 222, -R_ARC_TO, 29.14f, 29.14f, 0, 0, 0, 19.04f, -7.04f, -R_LINE_TO, 1.24f, 1.24f, -R_V_LINE_TO, 3.56f, -R_LINE_TO, 22.54f, 22.46f, -R_LINE_TO, 6.72f, -6.7f, -R_LINE_TO, -22.49f, -22.5f, -CLOSE, -R_MOVE_TO, -27.04f, 0, -R_CUBIC_TO, -11.2f, 0, -20.28f, -9.07f, -20.28f, -20.25f, -R_CUBIC_TO, 0, -11.18f, 9.08f, -20.25f, 20.28f, -20.25f, -R_CUBIC_TO, 11.2f, 0, 20.28f, 9.07f, 20.28f, 20.25f, -R_CUBIC_TO, 0, 11.18f, -9.08f, 20.25f, -20.28f, 20.25f, -CLOSE, -END diff --git a/ash/components/shortcut_viewer/views/keyboard_shortcut_item_view.cc b/ash/components/shortcut_viewer/views/keyboard_shortcut_item_view.cc index 9190a03efdb72..b0a8523601c80 100644 --- a/ash/components/shortcut_viewer/views/keyboard_shortcut_item_view.cc +++ b/ash/components/shortcut_viewer/views/keyboard_shortcut_item_view.cc @@ -148,8 +148,9 @@ void KeyboardShortcutItemView::MaybeCalculateAndDoLayout(int width) const { // The width of |description_label_view_| and |shortcut_label_view_| as a // ratio of its parent view's width. The unused width is to have some spacing // in between the two views. - constexpr float kDescriptionViewPreferredWidthRatio = 0.32f; - constexpr float kShortcutViewPreferredWidthRatio = 0.65f; + // These values are chosen to put all the bubble views in one line. + constexpr float kDescriptionViewPreferredWidthRatio = 0.29f; + constexpr float kShortcutViewPreferredWidthRatio = 0.69f; const int description_view_preferred_width = width * kDescriptionViewPreferredWidthRatio; const int shortcut_view_preferred_width = diff --git a/ash/components/shortcut_viewer/views/keyboard_shortcut_view.cc b/ash/components/shortcut_viewer/views/keyboard_shortcut_view.cc index 922e1a08fb08d..04914c9d38b7d 100644 --- a/ash/components/shortcut_viewer/views/keyboard_shortcut_view.cc +++ b/ash/components/shortcut_viewer/views/keyboard_shortcut_view.cc @@ -72,7 +72,7 @@ void SetupSearchIllustrationView(views::View* illustration_view, constexpr int kLabelFontSizeDelta = 1; ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); text->SetFontList(rb.GetFontListWithDelta( - kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM)); + kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL)); illustration_view->AddChildView(text); } @@ -100,7 +100,7 @@ views::Widget* KeyboardShortcutView::Show(gfx::NativeWindow context) { base::RecordAction( base::UserMetricsAction("KeyboardShortcutViewer.CreateWindow")); - constexpr gfx::Size kKSVWindowSize(768, 512); + constexpr gfx::Size kKSVWindowSize(800, 512); gfx::Rect window_bounds(kKSVWindowSize); if (context) { window_bounds = context->GetRootWindow()->bounds(); @@ -158,11 +158,6 @@ void KeyboardShortcutView::InitViews() { search_box_view_->Init(); AddChildView(search_box_view_.get()); - // Init start searching illustration view. - search_start_view_ = std::make_unique(); - SetupSearchIllustrationView(search_start_view_.get(), kKsvSearchStartIcon, - IDS_KSV_SEARCH_START); - // Init no search result illustration view. search_no_result_view_ = std::make_unique(); SetupSearchIllustrationView(search_no_result_view_.get(), @@ -172,7 +167,6 @@ void KeyboardShortcutView::InitViews() { search_results_container_ = new views::View(); search_results_container_->SetLayoutManager( std::make_unique()); - search_results_container_->AddChildView(search_start_view_.get()); search_results_container_->SetVisible(false); AddChildView(search_results_container_); @@ -246,7 +240,7 @@ void KeyboardShortcutView::Layout() { constexpr int kSearchBoxTopPadding = 8; constexpr int kSearchBoxBottomPadding = 16; - constexpr int kSearchBoxHorizontalPadding = 32; + constexpr int kSearchBoxHorizontalPadding = 30; const int left = content_bounds.x(); const int top = content_bounds.y(); gfx::Rect search_box_bounds(search_box_view_->GetPreferredSize()); @@ -270,78 +264,80 @@ void KeyboardShortcutView::Layout() { } void KeyboardShortcutView::BackButtonPressed() { - search_box_view_->SetSearchBoxActive(false); search_box_view_->ClearSearch(); + search_box_view_->SetSearchBoxActive(false); } void KeyboardShortcutView::QueryChanged(search_box::SearchBoxViewBase* sender) { - search_results_container_->RemoveAllChildViews(true); const bool query_empty = sender->IsSearchBoxTrimmedQueryEmpty(); - auto* search_container_content_view = search_start_view_.get(); - if (!query_empty) { - search_container_content_view = search_no_result_view_.get(); - - auto found_items_list_view = - std::make_unique(); - const base::string16& new_contents = sender->search_box()->text(); - base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder( - new_contents); - ShortcutCategory current_category = ShortcutCategory::kUnknown; - bool has_category_item = false; - for (auto* item_view : shortcut_views_) { - base::string16 description_text = - item_view->description_label_view()->text(); - base::string16 shortcut_text = item_view->shortcut_label_view()->text(); - size_t match_index = -1; - size_t match_length = 0; - // Only highlight |description_label_view_| in KeyboardShortcutItemView. - // |shortcut_label_view_| has customized style ranges for bubble views - // so it may have overlappings with the searched ranges. The highlighted - // behaviors are not defined so we don't highlight - // |shortcut_label_view_|. - if (finder.Search(description_text, &match_index, &match_length) || - finder.Search(shortcut_text, nullptr, nullptr)) { - const ShortcutCategory category = item_view->category(); - if (current_category != category) { - current_category = category; - has_category_item = false; - found_items_list_view->AddCategoryLabel( - GetStringForCategory(category)); - } - if (has_category_item) - found_items_list_view->AddHorizontalSeparator(); - else - has_category_item = true; - auto* matched_item_view = - new KeyboardShortcutItemView(*item_view->shortcut_item(), category); - // Highlight matched query in |description_label_view_|. - if (match_length > 0) { - views::StyledLabel::RangeStyleInfo style; - views::StyledLabel* description_label_view = - matched_item_view->description_label_view(); - style.custom_font = - description_label_view->GetDefaultFontList().Derive( - 0, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::BOLD); - description_label_view->AddStyleRange( - gfx::Range(match_index, match_index + match_length), style); - } - - found_items_list_view->AddChildView(matched_item_view); + if (is_search_box_empty_ != query_empty) { + is_search_box_empty_ = query_empty; + UpdateViewsLayout(/*is_search_box_active=*/true); + } + + // If search box is empty, do not show |search_results_container_|. + if (query_empty) + return; + + search_results_container_->RemoveAllChildViews(true); + auto* search_container_content_view = search_no_result_view_.get(); + auto found_items_list_view = std::make_unique(); + const base::string16& new_contents = sender->search_box()->text(); + base::i18n::FixedPatternStringSearchIgnoringCaseAndAccents finder( + new_contents); + ShortcutCategory current_category = ShortcutCategory::kUnknown; + bool has_category_item = false; + for (auto* item_view : shortcut_views_) { + base::string16 description_text = + item_view->description_label_view()->text(); + base::string16 shortcut_text = item_view->shortcut_label_view()->text(); + size_t match_index = -1; + size_t match_length = 0; + // Only highlight |description_label_view_| in KeyboardShortcutItemView. + // |shortcut_label_view_| has customized style ranges for bubble views + // so it may have overlappings with the searched ranges. The highlighted + // behaviors are not defined so we don't highlight + // |shortcut_label_view_|. + if (finder.Search(description_text, &match_index, &match_length) || + finder.Search(shortcut_text, nullptr, nullptr)) { + const ShortcutCategory category = item_view->category(); + if (current_category != category) { + current_category = category; + has_category_item = false; + found_items_list_view->AddCategoryLabel(GetStringForCategory(category)); + } + if (has_category_item) + found_items_list_view->AddHorizontalSeparator(); + else + has_category_item = true; + auto* matched_item_view = + new KeyboardShortcutItemView(*item_view->shortcut_item(), category); + // Highlight matched query in |description_label_view_|. + if (match_length > 0) { + views::StyledLabel::RangeStyleInfo style; + views::StyledLabel* description_label_view = + matched_item_view->description_label_view(); + style.custom_font = description_label_view->GetDefaultFontList().Derive( + 0, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::BOLD); + description_label_view->AddStyleRange( + gfx::Range(match_index, match_index + match_length), style); } - } - if (found_items_list_view->has_children()) { - // To offset the padding between the bottom of the |search_box_view_| and - // the top of the |search_results_container_|. - constexpr int kTopPadding = -16; - 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; + found_items_list_view->AddChildView(matched_item_view); } } + + if (found_items_list_view->has_children()) { + // To offset the padding between the bottom of the |search_box_view_| and + // the top of the |search_results_container_|. + constexpr int kTopPadding = -16; + 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_results_container_->AddChildView(search_container_content_view); Layout(); SchedulePaint(); @@ -349,14 +345,27 @@ void KeyboardShortcutView::QueryChanged(search_box::SearchBoxViewBase* sender) { void KeyboardShortcutView::ActiveChanged( search_box::SearchBoxViewBase* sender) { - const bool is_active = sender->is_search_box_active(); - sender->ShowBackOrGoogleIcon(is_active); - search_results_container_->SetVisible(is_active); - tabbed_pane_->SetVisible(!is_active); - if (is_active) { + const bool is_search_box_active = sender->is_search_box_active(); + is_search_box_empty_ = sender->IsSearchBoxTrimmedQueryEmpty(); + sender->ShowBackOrGoogleIcon(is_search_box_active); + if (is_search_box_active) { base::RecordAction( base::UserMetricsAction("KeyboardShortcutViewer.Search")); - } else { + } + UpdateViewsLayout(is_search_box_active); +} + +void KeyboardShortcutView::UpdateViewsLayout(bool is_search_box_active) { + // 1. Search box is not active: show |tabbed_pane_| and focus on active tab. + // 2. Search box is active and empty: show |tabbed_pane_| but focus on search + // box. + // 3. Search box is not empty, show |search_results_container_|. Focus is on + // search box. + const bool should_show_search_results = + is_search_box_active && !is_search_box_empty_; + search_results_container_->SetVisible(should_show_search_results); + tabbed_pane_->SetVisible(!should_show_search_results); + if (!is_search_box_active) { search_results_container_->RemoveAllChildViews(true); RequestFocusForActiveTab(); } diff --git a/ash/components/shortcut_viewer/views/keyboard_shortcut_view.h b/ash/components/shortcut_viewer/views/keyboard_shortcut_view.h index 0b73180ea045c..cb00eab28ad2f 100644 --- a/ash/components/shortcut_viewer/views/keyboard_shortcut_view.h +++ b/ash/components/shortcut_viewer/views/keyboard_shortcut_view.h @@ -52,8 +52,10 @@ class KeyboardShortcutView : public views::WidgetDelegateView, // after exiting search mode. void RequestFocusForActiveTab(); + // Update views' layout based on search box status. + void UpdateViewsLayout(bool is_search_box_active); + static KeyboardShortcutView* GetInstanceForTesting(); - int GetCategoryNumberForTesting() const; int GetTabCountForTesting() const; const std::vector& GetShortcutViewsForTesting() { return shortcut_views_; @@ -67,22 +69,25 @@ class KeyboardShortcutView : public views::WidgetDelegateView, // Owned by views hierarchy. views::TabbedPane* tabbed_pane_; + views::View* search_results_container_; + // SearchBoxViewBase is a WidgetDelegateView, which owns itself and cannot be // deleted from the views hierarchy automatically. std::unique_ptr search_box_view_; - views::View* search_results_container_; // Contains all the shortcut item views from all categories. This list is used // for searching. The views are owned by the Views hierarchy. std::vector shortcut_views_; - // Two illustrations to indicate the two search states: start searching and no - // result found. Since these two views need to be added and removed - // frequently from the |search_results_container_|, they are not owned by view - // hierarchy to avoid recreating them. - std::unique_ptr search_start_view_; + // An illustration to indicate no search results found. Since this view need + // to be added and removed frequently from the |search_results_container_|, it + // is not owned by view hierarchy to avoid recreating it. std::unique_ptr search_no_result_view_; + // Cached value of search box text status. When the status changes, need to + // update views' layout. + bool is_search_box_empty_ = true; + DISALLOW_COPY_AND_ASSIGN(KeyboardShortcutView); }; diff --git a/ash/components/shortcut_viewer/views/keyboard_shortcut_view_unittest.cc b/ash/components/shortcut_viewer/views/keyboard_shortcut_view_unittest.cc index 6498ba802ff74..59e07dc595f1a 100644 --- a/ash/components/shortcut_viewer/views/keyboard_shortcut_view_unittest.cc +++ b/ash/components/shortcut_viewer/views/keyboard_shortcut_view_unittest.cc @@ -20,11 +20,6 @@ class KeyboardShortcutViewTest : public ash::AshTestBase { ~KeyboardShortcutViewTest() override = default; protected: - int GetCategoryNumber() const { - DCHECK(GetView()); - return GetView()->GetCategoryNumberForTesting(); - } - int GetTabCount() const { DCHECK(GetView()); return GetView()->GetTabCountForTesting(); diff --git a/ash/components/shortcut_viewer/views/ksv_search_box_view.cc b/ash/components/shortcut_viewer/views/ksv_search_box_view.cc index 790a6f678613c..520c4603608fe 100644 --- a/ash/components/shortcut_viewer/views/ksv_search_box_view.cc +++ b/ash/components/shortcut_viewer/views/ksv_search_box_view.cc @@ -32,15 +32,15 @@ KSVSearchBoxView::KSVSearchBoxView(search_box::SearchBoxViewDelegate* delegate) SetSearchBoxBackgroundCornerRadius(kBorderCornerRadius); SetSearchBoxBackgroundColor(kDefaultSearchBoxBackgroundColor); search_box()->SetBackgroundColor(SK_ColorTRANSPARENT); - search_box()->set_placeholder_text( - l10n_util::GetStringUTF16(IDS_KSV_SEARCH_BOX_PLACEHOLDER)); constexpr SkColor kSearchBoxTextColor = SkColorSetARGBMacro(0xFF, 0x3C, 0x40, 0x43); search_box()->SetColor(kSearchBoxTextColor); search_box()->set_placeholder_text_color(kSearchBoxTextColor); search_box()->set_placeholder_text_draw_flags(gfx::Canvas::TEXT_ALIGN_CENTER); - search_box()->SetAccessibleName( + const base::string16 search_box_name( l10n_util::GetStringUTF16(IDS_KSV_SEARCH_BOX_ACCESSIBILITY_NAME)); + search_box()->set_placeholder_text(search_box_name); + search_box()->SetAccessibleName(search_box_name); constexpr SkColor kSearchBarIconColor = SkColorSetARGBMacro(0xFF, 0x3C, 0x40, 0x43); @@ -49,21 +49,29 @@ KSVSearchBoxView::KSVSearchBoxView(search_box::SearchBoxViewDelegate* delegate) } gfx::Size KSVSearchBoxView::CalculatePreferredSize() const { - return gfx::Size(704, 32); + return gfx::Size(740, 32); } void KSVSearchBoxView::OnKeyEvent(ui::KeyEvent* event) { - if (event->key_code() != ui::VKEY_BACK) + const ui::KeyboardCode key = event->key_code(); + const bool is_escape_key = (key == ui::VKEY_ESCAPE); + if (!is_escape_key && key != ui::VKEY_BROWSER_BACK) return; - if (!search_box()->text().empty()) - return; - - if (exit_search_mode_on_next_backspace_) { + event->SetHandled(); + // |VKEY_BROWSER_BACK| will only clear all the text. + ClearSearch(); + // |VKEY_ESCAPE| will clear text and exit search mode directly. + if (is_escape_key) SetSearchBoxActive(false); - event->SetHandled(); - } - exit_search_mode_on_next_backspace_ = !exit_search_mode_on_next_backspace_; +} + +void KSVSearchBoxView::ButtonPressed(views::Button* sender, + const ui::Event& event) { + // Focus on the search box text field after clicking close button. + if (close_button() && sender == close_button()) + search_box()->RequestFocus(); + SearchBoxViewBase::ButtonPressed(sender, event); } void KSVSearchBoxView::UpdateBackgroundColor(SkColor color) { @@ -71,6 +79,11 @@ void KSVSearchBoxView::UpdateBackgroundColor(SkColor color) { } void KSVSearchBoxView::UpdateSearchBoxBorder() { + // TODO(wutao): Rename this function or create another function in base class. + // It updates many things in addition to the border. + if (!search_box()->HasFocus() && search_box()->text().empty()) + SetSearchBoxActive(false); + constexpr int kBorderThichness = 2; constexpr SkColor kActiveBorderColor = SkColorSetARGBMacro(0x7F, 0x1A, 0x73, 0xE8); @@ -97,8 +110,10 @@ void KSVSearchBoxView::SetupCloseButton() { close->SetSize(gfx::Size(kIconSize, kIconSize)); close->SetImageAlignment(views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); - close->SetAccessibleName( + const base::string16 close_button_label( l10n_util::GetStringUTF16(IDS_KSV_CLEAR_SEARCHBOX_ACCESSIBILITY_NAME)); + close->SetAccessibleName(close_button_label); + close->SetTooltipText(close_button_label); close->SetVisible(false); } @@ -111,8 +126,10 @@ void KSVSearchBoxView::SetupBackButton() { back->SetSize(gfx::Size(kIconSize, kIconSize)); back->SetImageAlignment(views::ImageButton::ALIGN_CENTER, views::ImageButton::ALIGN_MIDDLE); - back->SetAccessibleName( + const base::string16 back_button_label( l10n_util::GetStringUTF16(IDS_KSV_BACK_ACCESSIBILITY_NAME)); + back->SetAccessibleName(back_button_label); + back->SetTooltipText(back_button_label); back->SetVisible(false); } diff --git a/ash/components/shortcut_viewer/views/ksv_search_box_view.h b/ash/components/shortcut_viewer/views/ksv_search_box_view.h index f47d0a1138abe..e32349bef8ea4 100644 --- a/ash/components/shortcut_viewer/views/ksv_search_box_view.h +++ b/ash/components/shortcut_viewer/views/ksv_search_box_view.h @@ -24,6 +24,9 @@ class KSVSearchBoxView : public search_box::SearchBoxViewBase { gfx::Size CalculatePreferredSize() const override; void OnKeyEvent(ui::KeyEvent* event) override; + // Overridden from views::ButtonListener: + void ButtonPressed(views::Button* sender, const ui::Event& event) override; + private: // search_box::SearchBoxViewBase: void ModelChanged() override {} @@ -35,9 +38,6 @@ class KSVSearchBoxView : public search_box::SearchBoxViewBase { void SetupCloseButton() override; void SetupBackButton() override; - // True to exit search mode on the next ui::VKEY_BACK event. - bool exit_search_mode_on_next_backspace_ = false; - DISALLOW_COPY_AND_ASSIGN(KSVSearchBoxView); }; diff --git a/ash/components/shortcut_viewer_strings.grdp b/ash/components/shortcut_viewer_strings.grdp index b584185d90f01..ad1a6b1b69815 100644 --- a/ash/components/shortcut_viewer_strings.grdp +++ b/ash/components/shortcut_viewer_strings.grdp @@ -7,24 +7,16 @@ - Search for shortcuts + Search for keyboard shortcuts - - Back + + Exit search mode Clear searchbox text - - - Search for shortcuts - - - - Start search... - No matching results found @@ -339,7 +331,7 @@ Open the webpage in a new tab - Type a web address (URL) in the address bar, then press $1$2$3 + Type a web address in the address bar, then press $1$2$3 Return the tab to its original position