Chromium Code Reviews| Index: chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
| diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
| index 8c5563303cd3529c20e9f013fb357e4dde5716a3..92096d766539fc8e464cf208967e842064a93bac 100644 |
| --- a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
| +++ b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc |
| @@ -6,6 +6,7 @@ |
| #include <algorithm> |
| +#include "base/feature_list.h" |
| #include "base/lazy_instance.h" |
| #include "base/macros.h" |
| #include "build/build_config.h" |
| @@ -14,17 +15,20 @@ |
| #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| #include "chrome/browser/ui/views/theme_copying_widget.h" |
| +#include "components/omnibox/browser/omnibox_field_trial.h" |
| #include "components/omnibox/browser/omnibox_view.h" |
| #include "third_party/skia/include/core/SkDrawLooper.h" |
| #include "ui/base/theme_provider.h" |
| #include "ui/compositor/clip_recorder.h" |
| #include "ui/compositor/paint_recorder.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/color_palette.h" |
| #include "ui/gfx/geometry/safe_integer_conversions.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/gfx/image/image_skia_operations.h" |
| #include "ui/gfx/path.h" |
| #include "ui/gfx/shadow_value.h" |
| +#include "ui/views/bubble/bubble_border.h" |
| #include "ui/views/controls/image_view.h" |
| #include "ui/views/view_targeter.h" |
| #include "ui/views/widget/widget.h" |
| @@ -86,14 +90,16 @@ OmniboxPopupContentsView::OmniboxPopupContentsView( |
| // The contents is owned by the LocationBarView. |
| set_owned_by_client(); |
| - if (g_top_shadow.Get().isNull()) { |
| + if (g_top_shadow.Get().isNull() && |
| + !base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
|
Peter Kasting
2017/06/09 19:49:30
Nit: Pull out to a temp
tommycli
2017/06/09 21:12:54
Done.
|
| std::vector<gfx::ShadowValue> shadows; |
| // Blur by 1dp. See comment below about blur accounting. |
| shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); |
| g_top_shadow.Get() = |
| gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false); |
| } |
| - if (g_bottom_shadow.Get().isNull()) { |
| + if (g_bottom_shadow.Get().isNull() && |
| + !base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
| const int kSmallShadowBlur = 3; |
| const int kLargeShadowBlur = 8; |
| const int kLargeShadowYOffset = 3; |
| @@ -226,11 +232,14 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { |
| for (size_t i = result_size; i < AutocompleteResult::GetMaxMatches(); ++i) |
| child_at(i)->SetVisible(false); |
| - // We want the popup to appear to overlay the bottom of the toolbar. So we |
| - // shift the popup to completely cover the client edge, and then draw an |
| - // additional semitransparent shadow above that. |
| - int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + |
| - g_top_shadow.Get().height(); |
| + int top_edge_overlap = 0; |
| + if (!base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
|
Peter Kasting
2017/06/09 19:49:30
Nit: Pull out to a temp
tommycli
2017/06/09 21:12:54
Done.
|
| + // We want the popup to appear to overlay the bottom of the toolbar. So we |
| + // shift the popup to completely cover the client edge, and then draw an |
| + // additional semitransparent shadow above that. |
| + top_edge_overlap = g_top_shadow.Get().height() + |
| + views::NonClientFrameView::kClientEdgeThickness; |
| + } |
| gfx::Point top_left_screen_coord; |
| int width; |
| @@ -240,6 +249,25 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { |
| gfx::Rect new_target_bounds(top_left_screen_coord, |
| gfx::Size(width, CalculatePopupHeight())); |
| + if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
| + SkColor background_color = |
| + GetNativeTheme() |
|
Peter Kasting
2017/06/09 19:49:30
When can this fail?
tommycli
2017/06/09 21:12:54
Done. Digging into it, I don't see a failure state
|
| + ? GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_ResultsTableNormalBackground) |
| + : gfx::kPlaceholderColor; |
| + auto border = base::MakeUnique<views::BubbleBorder>( |
| + views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, |
| + background_color); |
| + |
| + // Reposition the popup to factor in for the shadow size. |
|
Peter Kasting
2017/06/09 19:49:30
Nit: "Reposition" -> "Outdent"; Remove "for"
tommycli
2017/06/09 21:12:54
Done.
|
| + int border_thickness = border->GetBorderThickness(); |
| + new_target_bounds.Inset(-border_thickness, -border_thickness, |
| + -border_thickness, -border_thickness); |
| + |
| + SetBackground(base::MakeUnique<views::BubbleBackground>(border.get())); |
| + SetBorder(std::move(border)); |
| + } |
| + |
| // If we're animating and our target height changes, reset the animation. |
| // NOTE: If we just reset blindly on _every_ update, then when the user types |
| // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
| @@ -455,6 +483,12 @@ const char* OmniboxPopupContentsView::GetClassName() const { |
| } |
| void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
| + if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
| + OnPaintBackground(canvas); |
| + OnPaintBorder(canvas); |
|
Peter Kasting
2017/06/09 19:49:30
Just call View::OnPaint() instead of manually call
tommycli
2017/06/09 21:12:54
Done.
|
| + return; |
| + } |
| + |
| canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(), |
| g_top_shadow.Get().height()); |
| canvas->TileImageInt(g_bottom_shadow.Get(), 0, |
| @@ -463,6 +497,11 @@ void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
| } |
| void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { |
| + if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { |
| + View::PaintChildren(context); |
| + return; |
| + } |
| + |
| gfx::Rect contents_bounds = GetContentsBounds(); |
| contents_bounds.Inset(0, g_top_shadow.Get().height(), 0, |
| g_bottom_shadow.Get().height()); |