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

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

Issue 1319983002: Add a top shadow to material design omnibox dropdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new comments Created 5 years, 3 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 | « chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h ('k') | 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 "chrome/browser/search/search.h" 9 #include "chrome/browser/search/search.h"
10 #include "chrome/browser/themes/theme_properties.h" 10 #include "chrome/browser/themes/theme_properties.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 location_bar_view_(location_bar_view), 62 location_bar_view_(location_bar_view),
63 font_list_(font_list), 63 font_list_(font_list),
64 ignore_mouse_drag_(false), 64 ignore_mouse_drag_(false),
65 size_animation_(this), 65 size_animation_(this),
66 start_margin_(0), 66 start_margin_(0),
67 end_margin_(0) { 67 end_margin_(0) {
68 // The contents is owned by the LocationBarView. 68 // The contents is owned by the LocationBarView.
69 set_owned_by_client(); 69 set_owned_by_client();
70 70
71 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider(); 71 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider();
72 top_shadow_ = theme->GetImageSkiaNamed(IDR_OMNIBOX_DROPDOWN_SHADOW_TOP);
72 int bottom_shadow_asset = ui::MaterialDesignController::IsModeMaterial() ? 73 int bottom_shadow_asset = ui::MaterialDesignController::IsModeMaterial() ?
73 IDR_OMNIBOX_DROPDOWN_SHADOW_BOTTOM : IDR_BUBBLE_B; 74 IDR_OMNIBOX_DROPDOWN_SHADOW_BOTTOM : IDR_BUBBLE_B;
74 bottom_shadow_ = theme->GetImageSkiaNamed(bottom_shadow_asset); 75 bottom_shadow_ = theme->GetImageSkiaNamed(bottom_shadow_asset);
75 76
76 SetEventTargeter( 77 SetEventTargeter(
77 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 78 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
78 } 79 }
79 80
80 void OmniboxPopupContentsView::Init() { 81 void OmniboxPopupContentsView::Init() {
81 // This can't be done in the constructor as at that point we aren't 82 // This can't be done in the constructor as at that point we aren't
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 188 }
188 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { 189 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) {
189 max_match_contents_width_ = std::max( 190 max_match_contents_width_ = std::max(
190 max_match_contents_width_, view->GetMatchContentsWidth()); 191 max_match_contents_width_, view->GetMatchContentsWidth());
191 } 192 }
192 } 193 }
193 194
194 for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i) 195 for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i)
195 child_at(i)->SetVisible(false); 196 child_at(i)->SetVisible(false);
196 197
198 // In non-material mode, we want the popup to appear as if it's overlaying
199 // the top of the page content, i.e., is flush against the client edge at the
200 // bottom of the toolbar. However, if the bookmarks bar is attached, we want
201 // to draw over it (so as not to push the results below it), but that means
202 // the toolbar won't be drawing a client edge separating itself from the
203 // popup. So we unconditionally overlap the toolbar by the thickness of the
204 // client edge and draw our own edge (see OnPaint()), which fixes the
205 // attached bookmark bar case without breaking the other case.
206 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness;
207 if (ui::MaterialDesignController::IsModeMaterial()) {
208 // In material mode, we cover the bookmark bar similarly, but instead of
209 // appearing below the client edge, we want the popup to appear to overlay
210 // the bottom of the toolbar. So instead of drawing a client edge atop the
211 // popup, we shift the popup to completely cover the client edge, and then
212 // draw an additional semitransparent shadow above that. So the total
213 // overlap necessary is the client edge thickness plus the shadow height.
214 top_edge_overlap += top_shadow_->height();
215 }
216
197 gfx::Point top_left_screen_coord; 217 gfx::Point top_left_screen_coord;
198 int width; 218 int width;
199 location_bar_view_->GetOmniboxPopupPositioningInfo( 219 location_bar_view_->GetOmniboxPopupPositioningInfo(
200 &top_left_screen_coord, &width, &start_margin_, &end_margin_); 220 &top_left_screen_coord, &width, &start_margin_,
221 &end_margin_, top_edge_overlap);
201 gfx::Rect new_target_bounds(top_left_screen_coord, 222 gfx::Rect new_target_bounds(top_left_screen_coord,
202 gfx::Size(width, CalculatePopupHeight())); 223 gfx::Size(width, CalculatePopupHeight()));
203 224
204 // If we're animating and our target height changes, reset the animation. 225 // If we're animating and our target height changes, reset the animation.
205 // NOTE: If we just reset blindly on _every_ update, then when the user types 226 // NOTE: If we just reset blindly on _every_ update, then when the user types
206 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the 227 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the
207 // last few pixels to get to one visible result. 228 // last few pixels to get to one visible result.
208 if (new_target_bounds.height() != target_bounds_.height()) 229 if (new_target_bounds.height() != target_bounds_.height())
209 size_animation_.Reset(); 230 size_animation_.Reset();
210 target_bounds_ = new_target_bounds; 231 target_bounds_ = new_target_bounds;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 445
425 //////////////////////////////////////////////////////////////////////////////// 446 ////////////////////////////////////////////////////////////////////////////////
426 // OmniboxPopupContentsView, views::View overrides, private: 447 // OmniboxPopupContentsView, views::View overrides, private:
427 448
428 const char* OmniboxPopupContentsView::GetClassName() const { 449 const char* OmniboxPopupContentsView::GetClassName() const {
429 return "OmniboxPopupContentsView"; 450 return "OmniboxPopupContentsView";
430 } 451 }
431 452
432 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { 453 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) {
433 // Top border. 454 // Top border.
434 canvas->FillRect( 455 if (ui::MaterialDesignController::IsModeMaterial()) {
435 gfx::Rect(0, 0, width(), views::NonClientFrameView::kClientEdgeThickness), 456 canvas->TileImageInt(*top_shadow_, 0, 0, width(), top_shadow_->height());
436 ThemeProperties::GetDefaultColor( 457 } else {
437 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); 458 canvas->FillRect(
459 gfx::Rect(0, 0, width(),
460 views::NonClientFrameView::kClientEdgeThickness),
461 ThemeProperties::GetDefaultColor(
462 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
463 }
438 464
439 // Bottom border. 465 // Bottom border.
440 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), 466 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(),
441 width(), bottom_shadow_->height()); 467 width(), bottom_shadow_->height());
442 } 468 }
443 469
444 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) { 470 void OmniboxPopupContentsView::PaintChildren(const ui::PaintContext& context) {
445 gfx::Rect contents_bounds = GetContentsBounds(); 471 gfx::Rect contents_bounds = GetContentsBounds();
446 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider(); 472 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider();
447 const int border_interior = theme_provider->GetDisplayProperty( 473 const int border_interior = theme_provider->GetDisplayProperty(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 size_t index = GetIndexForPoint(event.location()); 537 size_t index = GetIndexForPoint(event.location());
512 if (!HasMatchAt(index)) 538 if (!HasMatchAt(index))
513 return; 539 return;
514 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, 540 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition,
515 GURL(), base::string16(), index); 541 GURL(), base::string16(), index);
516 } 542 }
517 543
518 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { 544 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) {
519 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); 545 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i)));
520 } 546 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698