Chromium Code Reviews| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 32 #include "ui/views/window/non_client_view.h" | 32 #include "ui/views/window/non_client_view.h" |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Cache the shadow images so that potentially expensive shadow drawing isn't | 36 // Cache the shadow images so that potentially expensive shadow drawing isn't |
| 37 // repeated. | 37 // repeated. |
| 38 base::LazyInstance<gfx::ImageSkia> g_top_shadow = LAZY_INSTANCE_INITIALIZER; | 38 base::LazyInstance<gfx::ImageSkia> g_top_shadow = LAZY_INSTANCE_INITIALIZER; |
| 39 base::LazyInstance<gfx::ImageSkia> g_bottom_shadow = LAZY_INSTANCE_INITIALIZER; | 39 base::LazyInstance<gfx::ImageSkia> g_bottom_shadow = LAZY_INSTANCE_INITIALIZER; |
| 40 | 40 |
| 41 const int kPopupVerticalPadding = 4; | |
| 42 | |
| 41 } // namespace | 43 } // namespace |
| 42 | 44 |
| 43 class OmniboxPopupContentsView::AutocompletePopupWidget | 45 class OmniboxPopupContentsView::AutocompletePopupWidget |
| 44 : public ThemeCopyingWidget, | 46 : public ThemeCopyingWidget, |
| 45 public base::SupportsWeakPtr<AutocompletePopupWidget> { | 47 public base::SupportsWeakPtr<AutocompletePopupWidget> { |
| 46 public: | 48 public: |
| 47 explicit AutocompletePopupWidget(views::Widget* role_model) | 49 explicit AutocompletePopupWidget(views::Widget* role_model) |
| 48 : ThemeCopyingWidget(role_model) {} | 50 : ThemeCopyingWidget(role_model) {} |
| 49 ~AutocompletePopupWidget() override {} | 51 ~AutocompletePopupWidget() override {} |
| 50 | 52 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 // height differences. | 142 // height differences. |
| 141 int current_height_delta = static_cast<int>( | 143 int current_height_delta = static_cast<int>( |
| 142 size_animation_.GetCurrentValue() * total_height_delta - 0.5); | 144 size_animation_.GetCurrentValue() * total_height_delta - 0.5); |
| 143 current_frame_bounds.set_height( | 145 current_frame_bounds.set_height( |
| 144 current_frame_bounds.height() + current_height_delta); | 146 current_frame_bounds.height() + current_height_delta); |
| 145 return current_frame_bounds; | 147 return current_frame_bounds; |
| 146 } | 148 } |
| 147 | 149 |
| 148 void OmniboxPopupContentsView::LayoutChildren() { | 150 void OmniboxPopupContentsView::LayoutChildren() { |
| 149 gfx::Rect contents_rect = GetContentsBounds(); | 151 gfx::Rect contents_rect = GetContentsBounds(); |
| 150 contents_rect.Inset(GetLayoutInsets(OMNIBOX_DROPDOWN)); | 152 contents_rect.Inset(gfx::Insets(kPopupVerticalPadding, 0)); |
|
Peter Kasting
2016/11/22 22:12:08
Nit: contents_rect.Inset(0, kPopupVerticalPadding)
Evan Stade
2016/11/29 03:01:45
I strongly dislike that Rect's Inset methods mess
| |
| 151 contents_rect.Inset(start_margin_, g_top_shadow.Get().height(), end_margin_, | 153 contents_rect.Inset(start_margin_, g_top_shadow.Get().height(), end_margin_, |
| 152 0); | 154 0); |
| 153 | 155 |
| 154 int top = contents_rect.y(); | 156 int top = contents_rect.y(); |
| 155 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 157 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| 156 View* v = child_at(i); | 158 View* v = child_at(i); |
| 157 if (v->visible()) { | 159 if (v->visible()) { |
| 158 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 160 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
| 159 v->GetPreferredSize().height()); | 161 v->GetPreferredSize().height()); |
| 160 top = v->bounds().bottom(); | 162 top = v->bounds().bottom(); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 | 429 |
| 428 int OmniboxPopupContentsView::CalculatePopupHeight() { | 430 int OmniboxPopupContentsView::CalculatePopupHeight() { |
| 429 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 431 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 430 int popup_height = 0; | 432 int popup_height = 0; |
| 431 for (size_t i = 0; i < model_->result().size(); ++i) | 433 for (size_t i = 0; i < model_->result().size(); ++i) |
| 432 popup_height += child_at(i)->GetPreferredSize().height(); | 434 popup_height += child_at(i)->GetPreferredSize().height(); |
| 433 | 435 |
| 434 // Add enough space on the top and bottom so it looks like there is the same | 436 // Add enough space on the top and bottom so it looks like there is the same |
| 435 // amount of space between the text and the popup border as there is in the | 437 // amount of space between the text and the popup border as there is in the |
| 436 // interior between each row of text. | 438 // interior between each row of text. |
| 437 return popup_height + GetLayoutInsets(OMNIBOX_DROPDOWN).height() + | 439 return popup_height + kPopupVerticalPadding * 2 + |
| 438 g_top_shadow.Get().height() + g_bottom_shadow.Get().height(); | 440 g_top_shadow.Get().height() + g_bottom_shadow.Get().height(); |
| 439 } | 441 } |
| 440 | 442 |
| 441 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( | 443 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
| 442 int model_index, | 444 int model_index, |
| 443 const gfx::FontList& font_list) { | 445 const gfx::FontList& font_list) { |
| 444 return new OmniboxResultView(this, model_index, font_list); | 446 return new OmniboxResultView(this, model_index, font_list); |
| 445 } | 447 } |
| 446 | 448 |
| 447 //////////////////////////////////////////////////////////////////////////////// | 449 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 size_t index = GetIndexForPoint(event.location()); | 527 size_t index = GetIndexForPoint(event.location()); |
| 526 if (!HasMatchAt(index)) | 528 if (!HasMatchAt(index)) |
| 527 return; | 529 return; |
| 528 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 530 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 529 GURL(), base::string16(), index); | 531 GURL(), base::string16(), index); |
| 530 } | 532 } |
| 531 | 533 |
| 532 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 534 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 533 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 535 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 534 } | 536 } |
| OLD | NEW |