Skip to content

Commit

Permalink
Fix app list bubble search box focus bar painting
Browse files Browse the repository at this point in the history
When I added transparency and blur to the search box I had to switch the
AppListBubbleView to use a layer with type SOLID_COLOR, which broke the
blue focus bar painting. I don't think a view with a solid color layer
can directly paint to its canvas (otherwise it wouldn't be a single
color).

Move painting to SearchBoxView. Tweak the position slightly to align
with the search icon. (It's not clear to me from the spec what this bar
is supposed to line up with.) The bar color is too light on the
transparent background, but we can fix that separately, since I think
it affects other focus rings as well.

Original: https://screenshot.googleplex.com/AvjAzyNZqJoDKsJ
Regressed: https://screenshot.googleplex.com/7KFUmMAk7fve6CG
This CL: https://screenshot.googleplex.com/3w4QNq6RXk9Ah4X

Bug: 1218229
Change-Id: I0376b753842d86e2d33b14b0e35a33159a0fe122
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3098576
Commit-Queue: James Cook <jamescook@chromium.org>
Commit-Queue: Yulun Wu <yulunwu@chromium.org>
Reviewed-by: Yulun Wu <yulunwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#912408}
  • Loading branch information
James Cook authored and Chromium LUCI CQ committed Aug 17, 2021
1 parent a1fd299 commit b7e5f3a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ash/app_list/app_list_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ ASH_EXPORT gfx::ImageSkia CreateIconWithCircleBackground(
const gfx::ImageSkia& icon,
SkColor background_color);

// Paints a rounded focus bar on the left edge of |canvas|.
// Paints a rounded focus bar on |canvas| starting at |content_origin| extending
// |height| dips vertically.
ASH_EXPORT void PaintFocusBar(gfx::Canvas* canvas,
const gfx::Point content_origin,
const int height);
Expand Down
15 changes: 0 additions & 15 deletions ash/app_list/views/app_list_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <algorithm>
#include <memory>

#include "ash/app_list/app_list_util.h"
#include "ash/app_list/views/app_list_bubble_apps_page.h"
#include "ash/app_list/views/app_list_bubble_search_page.h"
#include "ash/app_list/views/assistant/app_list_bubble_assistant_page.h"
Expand Down Expand Up @@ -223,20 +222,6 @@ gfx::Size AppListBubbleView::CalculatePreferredSize() const {
return gfx::Size(default_width, height);
}

void AppListBubbleView::OnPaint(gfx::Canvas* canvas) {
// Used to draw/hide the focus bar for the search box view.
if (search_box_view_->search_box()->HasFocus() &&
search_box_view_->search_box()->GetText().empty()) {
PaintFocusBar(
canvas,
GetContentsBounds().origin() +
gfx::Vector2d(0,
kUnifiedTrayCornerRadius /*downshift the focus bar*/),
/*height=*/kSearchBoxIconSize);
}
views::View::OnPaint(canvas);
}

void AppListBubbleView::OnThemeChanged() {
views::View::OnThemeChanged();

Expand Down
1 change: 0 additions & 1 deletion ash/app_list/views/app_list_bubble_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class ASH_EXPORT AppListBubbleView : public views::View,
// views::View:
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
gfx::Size CalculatePreferredSize() const override;
void OnPaint(gfx::Canvas* canvas) override;
void OnThemeChanged() override;

// SearchBoxViewDelegate:
Expand Down
12 changes: 12 additions & 0 deletions ash/app_list/views/search_box_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ void SearchBoxView::UpdateSearchBoxBorder() {
}

void SearchBoxView::OnPaintBackground(gfx::Canvas* canvas) {
if (is_app_list_bubble_) {
// When the search box is focused, paint a vertical focus bar along the left
// edge, vertically aligned with the search icon.
if (search_box()->HasFocus() && search_box()->GetText().empty()) {
gfx::Point icon_origin;
views::View::ConvertPointToTarget(search_icon(), this, &icon_origin);
PaintFocusBar(canvas, gfx::Point(0, icon_origin.y()),
/*height=*/kSearchBoxIconSize);
}
return;
}

// Paints the focus ring if the search box is focused.
if (search_box()->HasFocus() && !is_search_box_active() &&
view_delegate_->KeyboardTraversalEngaged()) {
Expand Down
1 change: 1 addition & 0 deletions ash/search_box/search_box_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class SearchBoxViewBase : public views::View,

SearchBoxViewDelegate* delegate() { return delegate_; }
views::BoxLayout* box_layout() { return box_layout_; }
views::ImageView* search_icon() { return search_icon_; }

void SetSearchBoxBackgroundCornerRadius(int corner_radius);

Expand Down

0 comments on commit b7e5f3a

Please sign in to comment.