OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/feature_list.h" | |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 #include "chrome/browser/search/search.h" | 13 #include "chrome/browser/search/search.h" |
13 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
15 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 16 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
16 #include "chrome/browser/ui/views/theme_copying_widget.h" | 17 #include "chrome/browser/ui/views/theme_copying_widget.h" |
18 #include "components/omnibox/browser/omnibox_field_trial.h" | |
17 #include "components/omnibox/browser/omnibox_view.h" | 19 #include "components/omnibox/browser/omnibox_view.h" |
18 #include "third_party/skia/include/core/SkDrawLooper.h" | 20 #include "third_party/skia/include/core/SkDrawLooper.h" |
19 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
20 #include "ui/compositor/clip_recorder.h" | 22 #include "ui/compositor/clip_recorder.h" |
21 #include "ui/compositor/paint_recorder.h" | 23 #include "ui/compositor/paint_recorder.h" |
22 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/color_palette.h" | |
23 #include "ui/gfx/geometry/safe_integer_conversions.h" | 26 #include "ui/gfx/geometry/safe_integer_conversions.h" |
24 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/image/image_skia_operations.h" | 28 #include "ui/gfx/image/image_skia_operations.h" |
26 #include "ui/gfx/path.h" | 29 #include "ui/gfx/path.h" |
27 #include "ui/gfx/shadow_value.h" | 30 #include "ui/gfx/shadow_value.h" |
31 #include "ui/views/bubble/bubble_border.h" | |
28 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
29 #include "ui/views/view_targeter.h" | 33 #include "ui/views/view_targeter.h" |
30 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
31 #include "ui/views/window/non_client_view.h" | 35 #include "ui/views/window/non_client_view.h" |
32 | 36 |
33 namespace { | 37 namespace { |
34 | 38 |
35 // Cache the shadow images so that potentially expensive shadow drawing isn't | 39 // Cache the shadow images so that potentially expensive shadow drawing isn't |
36 // repeated. | 40 // repeated. |
37 base::LazyInstance<gfx::ImageSkia>::DestructorAtExit g_top_shadow = | 41 base::LazyInstance<gfx::ImageSkia>::DestructorAtExit g_top_shadow = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 omnibox_view_(omnibox_view), | 83 omnibox_view_(omnibox_view), |
80 location_bar_view_(location_bar_view), | 84 location_bar_view_(location_bar_view), |
81 font_list_(font_list), | 85 font_list_(font_list), |
82 ignore_mouse_drag_(false), | 86 ignore_mouse_drag_(false), |
83 size_animation_(this), | 87 size_animation_(this), |
84 start_margin_(0), | 88 start_margin_(0), |
85 end_margin_(0) { | 89 end_margin_(0) { |
86 // The contents is owned by the LocationBarView. | 90 // The contents is owned by the LocationBarView. |
87 set_owned_by_client(); | 91 set_owned_by_client(); |
88 | 92 |
89 if (g_top_shadow.Get().isNull()) { | 93 if (g_top_shadow.Get().isNull() && |
94 !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.
| |
90 std::vector<gfx::ShadowValue> shadows; | 95 std::vector<gfx::ShadowValue> shadows; |
91 // Blur by 1dp. See comment below about blur accounting. | 96 // Blur by 1dp. See comment below about blur accounting. |
92 shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); | 97 shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); |
93 g_top_shadow.Get() = | 98 g_top_shadow.Get() = |
94 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false); | 99 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false); |
95 } | 100 } |
96 if (g_bottom_shadow.Get().isNull()) { | 101 if (g_bottom_shadow.Get().isNull() && |
102 !base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { | |
97 const int kSmallShadowBlur = 3; | 103 const int kSmallShadowBlur = 3; |
98 const int kLargeShadowBlur = 8; | 104 const int kLargeShadowBlur = 8; |
99 const int kLargeShadowYOffset = 3; | 105 const int kLargeShadowYOffset = 3; |
100 | 106 |
101 std::vector<gfx::ShadowValue> shadows; | 107 std::vector<gfx::ShadowValue> shadows; |
102 // gfx::ShadowValue counts blur pixels both inside and outside the shape, | 108 // gfx::ShadowValue counts blur pixels both inside and outside the shape, |
103 // whereas these blur values only describe the outside portion, hence they | 109 // whereas these blur values only describe the outside portion, hence they |
104 // must be doubled. | 110 // must be doubled. |
105 shadows.emplace_back(gfx::Vector2d(), 2 * kSmallShadowBlur, | 111 shadows.emplace_back(gfx::Vector2d(), 2 * kSmallShadowBlur, |
106 SK_ColorBLACK); | 112 SK_ColorBLACK); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 } | 225 } |
220 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 226 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
221 max_match_contents_width_ = std::max( | 227 max_match_contents_width_ = std::max( |
222 max_match_contents_width_, view->GetMatchContentsWidth()); | 228 max_match_contents_width_, view->GetMatchContentsWidth()); |
223 } | 229 } |
224 } | 230 } |
225 | 231 |
226 for (size_t i = result_size; i < AutocompleteResult::GetMaxMatches(); ++i) | 232 for (size_t i = result_size; i < AutocompleteResult::GetMaxMatches(); ++i) |
227 child_at(i)->SetVisible(false); | 233 child_at(i)->SetVisible(false); |
228 | 234 |
229 // We want the popup to appear to overlay the bottom of the toolbar. So we | 235 int top_edge_overlap = 0; |
230 // shift the popup to completely cover the client edge, and then draw an | 236 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.
| |
231 // additional semitransparent shadow above that. | 237 // We want the popup to appear to overlay the bottom of the toolbar. So we |
232 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + | 238 // shift the popup to completely cover the client edge, and then draw an |
233 g_top_shadow.Get().height(); | 239 // additional semitransparent shadow above that. |
240 top_edge_overlap = g_top_shadow.Get().height() + | |
241 views::NonClientFrameView::kClientEdgeThickness; | |
242 } | |
234 | 243 |
235 gfx::Point top_left_screen_coord; | 244 gfx::Point top_left_screen_coord; |
236 int width; | 245 int width; |
237 location_bar_view_->GetOmniboxPopupPositioningInfo( | 246 location_bar_view_->GetOmniboxPopupPositioningInfo( |
238 &top_left_screen_coord, &width, &start_margin_, | 247 &top_left_screen_coord, &width, &start_margin_, |
239 &end_margin_, top_edge_overlap); | 248 &end_margin_, top_edge_overlap); |
240 gfx::Rect new_target_bounds(top_left_screen_coord, | 249 gfx::Rect new_target_bounds(top_left_screen_coord, |
241 gfx::Size(width, CalculatePopupHeight())); | 250 gfx::Size(width, CalculatePopupHeight())); |
242 | 251 |
252 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { | |
253 SkColor background_color = | |
254 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
| |
255 ? GetNativeTheme()->GetSystemColor( | |
256 ui::NativeTheme::kColorId_ResultsTableNormalBackground) | |
257 : gfx::kPlaceholderColor; | |
258 auto border = base::MakeUnique<views::BubbleBorder>( | |
259 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW, | |
260 background_color); | |
261 | |
262 // 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.
| |
263 int border_thickness = border->GetBorderThickness(); | |
264 new_target_bounds.Inset(-border_thickness, -border_thickness, | |
265 -border_thickness, -border_thickness); | |
266 | |
267 SetBackground(base::MakeUnique<views::BubbleBackground>(border.get())); | |
268 SetBorder(std::move(border)); | |
269 } | |
270 | |
243 // If we're animating and our target height changes, reset the animation. | 271 // If we're animating and our target height changes, reset the animation. |
244 // NOTE: If we just reset blindly on _every_ update, then when the user types | 272 // NOTE: If we just reset blindly on _every_ update, then when the user types |
245 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 273 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
246 // last few pixels to get to one visible result. | 274 // last few pixels to get to one visible result. |
247 if (new_target_bounds.height() != target_bounds_.height()) | 275 if (new_target_bounds.height() != target_bounds_.height()) |
248 size_animation_.Reset(); | 276 size_animation_.Reset(); |
249 target_bounds_ = new_target_bounds; | 277 target_bounds_ = new_target_bounds; |
250 | 278 |
251 if (!popup_) { | 279 if (!popup_) { |
252 views::Widget* popup_parent = location_bar_view_->GetWidget(); | 280 views::Widget* popup_parent = location_bar_view_->GetWidget(); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 } | 476 } |
449 | 477 |
450 //////////////////////////////////////////////////////////////////////////////// | 478 //////////////////////////////////////////////////////////////////////////////// |
451 // OmniboxPopupContentsView, views::View overrides, private: | 479 // OmniboxPopupContentsView, views::View overrides, private: |
452 | 480 |
453 const char* OmniboxPopupContentsView::GetClassName() const { | 481 const char* OmniboxPopupContentsView::GetClassName() const { |
454 return "OmniboxPopupContentsView"; | 482 return "OmniboxPopupContentsView"; |
455 } | 483 } |
456 | 484 |
457 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { | 485 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
486 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { | |
487 OnPaintBackground(canvas); | |
488 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.
| |
489 return; | |
490 } | |
491 | |
458 canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(), | 492 canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(), |
459 g_top_shadow.Get().height()); | 493 g_top_shadow.Get().height()); |
460 canvas->TileImageInt(g_bottom_shadow.Get(), 0, | 494 canvas->TileImageInt(g_bottom_shadow.Get(), 0, |
461 height() - g_bottom_shadow.Get().height(), width(), | 495 height() - g_bottom_shadow.Get().height(), width(), |
462 g_bottom_shadow.Get().height()); | 496 g_bottom_shadow.Get().height()); |
463 } | 497 } |
464 | 498 |
465 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { | 499 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { |
500 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) { | |
501 View::PaintChildren(context); | |
502 return; | |
503 } | |
504 | |
466 gfx::Rect contents_bounds = GetContentsBounds(); | 505 gfx::Rect contents_bounds = GetContentsBounds(); |
467 contents_bounds.Inset(0, g_top_shadow.Get().height(), 0, | 506 contents_bounds.Inset(0, g_top_shadow.Get().height(), 0, |
468 g_bottom_shadow.Get().height()); | 507 g_bottom_shadow.Get().height()); |
469 | 508 |
470 ui::ClipRecorder clip_recorder(context); | 509 ui::ClipRecorder clip_recorder(context); |
471 clip_recorder.ClipRect(contents_bounds); | 510 clip_recorder.ClipRect(contents_bounds); |
472 { | 511 { |
473 ui::PaintRecorder recorder(context, size()); | 512 ui::PaintRecorder recorder(context, size()); |
474 SkColor background_color = result_view_at(0)->GetColor( | 513 SkColor background_color = result_view_at(0)->GetColor( |
475 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); | 514 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 size_t index = GetIndexForPoint(event.location()); | 567 size_t index = GetIndexForPoint(event.location()); |
529 if (!HasMatchAt(index)) | 568 if (!HasMatchAt(index)) |
530 return; | 569 return; |
531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 570 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
532 GURL(), base::string16(), index); | 571 GURL(), base::string16(), index); |
533 } | 572 } |
534 | 573 |
535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 574 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 575 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
537 } | 576 } |
OLD | NEW |