Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc

Issue 2923073004: Omnibox UI Experiments: Simple border for narrow mode (Closed)
Patch Set: reformat Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
23 #include "ui/gfx/geometry/safe_integer_conversions.h" 25 #include "ui/gfx/geometry/safe_integer_conversions.h"
24 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/image/image_skia_operations.h" 27 #include "ui/gfx/image/image_skia_operations.h"
26 #include "ui/gfx/path.h" 28 #include "ui/gfx/path.h"
27 #include "ui/gfx/shadow_value.h" 29 #include "ui/gfx/shadow_value.h"
30 #include "ui/views/bubble/bubble_border.h"
28 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
29 #include "ui/views/view_targeter.h" 32 #include "ui/views/view_targeter.h"
30 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
31 #include "ui/views/window/non_client_view.h" 34 #include "ui/views/window/non_client_view.h"
32 35
33 namespace { 36 namespace {
34 37
35 // Cache the shadow images so that potentially expensive shadow drawing isn't 38 // Cache the shadow images so that potentially expensive shadow drawing isn't
36 // repeated. 39 // repeated.
37 base::LazyInstance<gfx::ImageSkia>::DestructorAtExit g_top_shadow = 40 base::LazyInstance<gfx::ImageSkia>::DestructorAtExit g_top_shadow =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 omnibox_view_(omnibox_view), 82 omnibox_view_(omnibox_view),
80 location_bar_view_(location_bar_view), 83 location_bar_view_(location_bar_view),
81 font_list_(font_list), 84 font_list_(font_list),
82 ignore_mouse_drag_(false), 85 ignore_mouse_drag_(false),
83 size_animation_(this), 86 size_animation_(this),
84 start_margin_(0), 87 start_margin_(0),
85 end_margin_(0) { 88 end_margin_(0) {
86 // The contents is owned by the LocationBarView. 89 // The contents is owned by the LocationBarView.
87 set_owned_by_client(); 90 set_owned_by_client();
88 91
89 if (g_top_shadow.Get().isNull()) { 92 bool narrow_popup =
93 base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown);
94
95 if (g_top_shadow.Get().isNull() && !narrow_popup) {
90 std::vector<gfx::ShadowValue> shadows; 96 std::vector<gfx::ShadowValue> shadows;
91 // Blur by 1dp. See comment below about blur accounting. 97 // Blur by 1dp. See comment below about blur accounting.
92 shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK); 98 shadows.emplace_back(gfx::Vector2d(), 2, SK_ColorBLACK);
93 g_top_shadow.Get() = 99 g_top_shadow.Get() =
94 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false); 100 gfx::ImageSkiaOperations::CreateHorizontalShadow(shadows, false);
95 } 101 }
96 if (g_bottom_shadow.Get().isNull()) { 102 if (g_bottom_shadow.Get().isNull() && !narrow_popup) {
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
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 bool narrow_popup =
231 // additional semitransparent shadow above that. 237 base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown);
232 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + 238 if (!narrow_popup) {
233 g_top_shadow.Get().height(); 239 // We want the popup to appear to overlay the bottom of the toolbar. So we
240 // shift the popup to completely cover the client edge, and then draw an
241 // additional semitransparent shadow above that.
242 top_edge_overlap = g_top_shadow.Get().height() +
243 views::NonClientFrameView::kClientEdgeThickness;
244 }
234 245
235 gfx::Point top_left_screen_coord; 246 gfx::Point top_left_screen_coord;
236 int width; 247 int width;
237 location_bar_view_->GetOmniboxPopupPositioningInfo( 248 location_bar_view_->GetOmniboxPopupPositioningInfo(
238 &top_left_screen_coord, &width, &start_margin_, 249 &top_left_screen_coord, &width, &start_margin_,
239 &end_margin_, top_edge_overlap); 250 &end_margin_, top_edge_overlap);
240 gfx::Rect new_target_bounds(top_left_screen_coord, 251 gfx::Rect new_target_bounds(top_left_screen_coord,
241 gfx::Size(width, CalculatePopupHeight())); 252 gfx::Size(width, CalculatePopupHeight()));
242 253
254 if (narrow_popup) {
255 SkColor background_color = GetNativeTheme()->GetSystemColor(
256 ui::NativeTheme::kColorId_ResultsTableNormalBackground);
257 auto border = base::MakeUnique<views::BubbleBorder>(
258 views::BubbleBorder::NONE, views::BubbleBorder::SMALL_SHADOW,
259 background_color);
260
261 // Outdent the popup to factor in the shadow size.
262 int border_thickness = border->GetBorderThickness();
263 new_target_bounds.Inset(-border_thickness, -border_thickness,
264 -border_thickness, -border_thickness);
265
266 SetBackground(base::MakeUnique<views::BubbleBackground>(border.get()));
267 SetBorder(std::move(border));
268 }
269
243 // If we're animating and our target height changes, reset the animation. 270 // 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 271 // 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 272 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the
246 // last few pixels to get to one visible result. 273 // last few pixels to get to one visible result.
247 if (new_target_bounds.height() != target_bounds_.height()) 274 if (new_target_bounds.height() != target_bounds_.height())
248 size_animation_.Reset(); 275 size_animation_.Reset();
249 target_bounds_ = new_target_bounds; 276 target_bounds_ = new_target_bounds;
250 277
251 if (!popup_) { 278 if (!popup_) {
252 views::Widget* popup_parent = location_bar_view_->GetWidget(); 279 views::Widget* popup_parent = location_bar_view_->GetWidget();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 475 }
449 476
450 //////////////////////////////////////////////////////////////////////////////// 477 ////////////////////////////////////////////////////////////////////////////////
451 // OmniboxPopupContentsView, views::View overrides, private: 478 // OmniboxPopupContentsView, views::View overrides, private:
452 479
453 const char* OmniboxPopupContentsView::GetClassName() const { 480 const char* OmniboxPopupContentsView::GetClassName() const {
454 return "OmniboxPopupContentsView"; 481 return "OmniboxPopupContentsView";
455 } 482 }
456 483
457 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { 484 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) {
485 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) {
486 View::OnPaint(canvas);
487 return;
488 }
489
458 canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(), 490 canvas->TileImageInt(g_top_shadow.Get(), 0, 0, width(),
459 g_top_shadow.Get().height()); 491 g_top_shadow.Get().height());
460 canvas->TileImageInt(g_bottom_shadow.Get(), 0, 492 canvas->TileImageInt(g_bottom_shadow.Get(), 0,
461 height() - g_bottom_shadow.Get().height(), width(), 493 height() - g_bottom_shadow.Get().height(), width(),
462 g_bottom_shadow.Get().height()); 494 g_bottom_shadow.Get().height());
463 } 495 }
464 496
465 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { 497 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) {
498 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentNarrowDropdown)) {
499 View::PaintChildren(context);
500 return;
501 }
502
466 gfx::Rect contents_bounds = GetContentsBounds(); 503 gfx::Rect contents_bounds = GetContentsBounds();
467 contents_bounds.Inset(0, g_top_shadow.Get().height(), 0, 504 contents_bounds.Inset(0, g_top_shadow.Get().height(), 0,
468 g_bottom_shadow.Get().height()); 505 g_bottom_shadow.Get().height());
469 506
470 ui::ClipRecorder clip_recorder(context); 507 ui::ClipRecorder clip_recorder(context);
471 clip_recorder.ClipRect(contents_bounds); 508 clip_recorder.ClipRect(contents_bounds);
472 { 509 {
473 ui::PaintRecorder recorder(context, size()); 510 ui::PaintRecorder recorder(context, size());
474 SkColor background_color = result_view_at(0)->GetColor( 511 SkColor background_color = result_view_at(0)->GetColor(
475 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND); 512 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 size_t index = GetIndexForPoint(event.location()); 565 size_t index = GetIndexForPoint(event.location());
529 if (!HasMatchAt(index)) 566 if (!HasMatchAt(index))
530 return; 567 return;
531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, 568 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition,
532 GURL(), base::string16(), index); 569 GURL(), base::string16(), index);
533 } 570 }
534 571
535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { 572 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) {
536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); 573 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i)));
537 } 574 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698