Commit d97c6e27 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Remove dependency on profile based theme provider

Use Views based theme provider instead of profile based theme provider
to reduce the dependencies on profile based theme provider.

Also, change to use OnThemeChanged() to make sure theme change can
propagate properly.

BUG=none

Change-Id: I9253999dbcd4bc167b3034ef27f48f2a3ff9364e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018484
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738801}
parent 1f4ec0ff
...@@ -59,17 +59,36 @@ WidgetEventPair GetParentWidgetAndEvent(views::View* this_view, ...@@ -59,17 +59,36 @@ WidgetEventPair GetParentWidgetAndEvent(views::View* this_view,
#endif // !USE_AURA #endif // !USE_AURA
// Subclass for results view which sets the correct background color on
// theme changes.
class OmniboxResultsContentsView : public views::View {
public:
OmniboxResultsContentsView() = default;
~OmniboxResultsContentsView() override = default;
void OnThemeChanged() override {
const SkColor background_color =
GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND);
SetBackground(views::CreateSolidBackground(background_color));
}
};
// View at the top of the frame which paints transparent pixels to make a hole // View at the top of the frame which paints transparent pixels to make a hole
// so that the location bar shows through. // so that the location bar shows through.
class TopBackgroundView : public views::View { class TopBackgroundView : public views::View {
public: public:
TopBackgroundView(const LocationBarView* location_bar, explicit TopBackgroundView(const LocationBarView* location_bar)
SkColor background_color) { : location_bar_(location_bar) {}
void OnThemeChanged() override {
const SkColor background_color =
GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND);
// Paint a stroke of the background color as a 1 px border to hide the // Paint a stroke of the background color as a 1 px border to hide the
// underlying antialiased location bar/toolbar edge. The round rect here is // underlying antialiased location bar/toolbar edge. The round rect here is
// not antialiased, since the goal is to completely cover the underlying // not antialiased, since the goal is to completely cover the underlying
// pixels, and AA would let those on the edge partly bleed through. // pixels, and AA would let those on the edge partly bleed through.
SetBackground(location_bar->CreateRoundRectBackground( SetBackground(location_bar_->CreateRoundRectBackground(
SK_ColorTRANSPARENT, background_color, SkBlendMode::kSrc, false)); SK_ColorTRANSPARENT, background_color, SkBlendMode::kSrc, false));
} }
...@@ -110,6 +129,9 @@ class TopBackgroundView : public views::View { ...@@ -110,6 +129,9 @@ class TopBackgroundView : public views::View {
return nullptr; return nullptr;
} }
#endif // !USE_AURA #endif // !USE_AURA
private:
const LocationBarView* location_bar_;
}; };
// Insets used to position |contents_| within |contents_host_|. // Insets used to position |contents_| within |contents_host_|.
...@@ -125,23 +147,18 @@ RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame( ...@@ -125,23 +147,18 @@ RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame(
LocationBarView* location_bar) LocationBarView* location_bar)
: contents_(contents) { : contents_(contents) {
// Host the contents in its own View to simplify layout and customization. // Host the contents in its own View to simplify layout and customization.
contents_host_ = new views::View(); contents_host_ = new OmniboxResultsContentsView();
contents_host_->SetPaintToLayer(); contents_host_->SetPaintToLayer();
contents_host_->layer()->SetFillsBoundsOpaquely(false); contents_host_->layer()->SetFillsBoundsOpaquely(false);
// Use a solid background with rounded corners. // Use rounded corners.
const SkColor background_color = GetOmniboxColor(
&ThemeService::GetThemeProviderForProfile(location_bar->profile()),
OmniboxPart::RESULTS_BACKGROUND);
contents_host_->SetBackground(views::CreateSolidBackground(background_color));
int corner_radius = int corner_radius =
views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH); views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH);
contents_host_->layer()->SetRoundedCornerRadius( contents_host_->layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF(corner_radius)); gfx::RoundedCornersF(corner_radius));
contents_host_->layer()->SetIsFastRoundedCorner(true); contents_host_->layer()->SetIsFastRoundedCorner(true);
top_background_ = new TopBackgroundView(location_bar, background_color); top_background_ = new TopBackgroundView(location_bar);
contents_host_->AddChildView(top_background_); contents_host_->AddChildView(top_background_);
contents_host_->AddChildView(contents_); contents_host_->AddChildView(contents_);
...@@ -151,11 +168,6 @@ RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame( ...@@ -151,11 +168,6 @@ RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame(
gfx::kPlaceholderColor); gfx::kPlaceholderColor);
border->SetCornerRadius(corner_radius); border->SetCornerRadius(corner_radius);
border->set_md_shadow_elevation(kElevation); border->set_md_shadow_elevation(kElevation);
// Use a darker shadow that's more visible on darker tints.
border->set_md_shadow_color(color_utils::IsDark(background_color)
? SK_ColorBLACK
: gfx::kGoogleGrey800);
SetBorder(std::move(border)); SetBorder(std::move(border));
AddChildView(contents_host_); AddChildView(contents_host_);
...@@ -256,3 +268,16 @@ void RoundedOmniboxResultsFrame::OnMouseEvent(ui::MouseEvent* event) { ...@@ -256,3 +268,16 @@ void RoundedOmniboxResultsFrame::OnMouseEvent(ui::MouseEvent* event) {
} }
#endif // !USE_AURA #endif // !USE_AURA
void RoundedOmniboxResultsFrame::OnThemeChanged() {
const SkColor background_color =
GetOmniboxColor(GetThemeProvider(), OmniboxPart::RESULTS_BACKGROUND);
// Use a darker shadow that's more visible on darker tints.
views::BubbleBorder* border =
static_cast<views::BubbleBorder*>(this->border());
border->set_md_shadow_color(color_utils::IsDark(background_color)
? SK_ColorBLACK
: gfx::kGoogleGrey800);
SchedulePaint();
}
...@@ -41,6 +41,7 @@ class RoundedOmniboxResultsFrame : public views::View { ...@@ -41,6 +41,7 @@ class RoundedOmniboxResultsFrame : public views::View {
void OnMouseMoved(const ui::MouseEvent& event) override; void OnMouseMoved(const ui::MouseEvent& event) override;
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
#endif // !USE_AURA #endif // !USE_AURA
void OnThemeChanged() override;
private: private:
views::View* top_background_ = nullptr; views::View* top_background_ = nullptr;
......
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