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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 SetEventTargeter( | 114 SetEventTargeter( |
115 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 115 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
116 } | 116 } |
117 | 117 |
118 void OmniboxPopupContentsView::Init() { | 118 void OmniboxPopupContentsView::Init() { |
119 // This can't be done in the constructor as at that point we aren't | 119 // This can't be done in the constructor as at that point we aren't |
120 // necessarily our final class yet, and we may have subclasses | 120 // necessarily our final class yet, and we may have subclasses |
121 // overriding CreateResultView. | 121 // overriding CreateResultView. |
122 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 122 for (size_t i = 0; i < AutocompleteResult::GetMaxMatches(); ++i) { |
123 OmniboxResultView* result_view = CreateResultView(i, font_list_); | 123 OmniboxResultView* result_view = CreateResultView(i, font_list_); |
124 result_view->SetVisible(false); | 124 result_view->SetVisible(false); |
125 AddChildViewAt(result_view, static_cast<int>(i)); | 125 AddChildViewAt(result_view, static_cast<int>(i)); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 OmniboxPopupContentsView::~OmniboxPopupContentsView() { | 129 OmniboxPopupContentsView::~OmniboxPopupContentsView() { |
130 // We don't need to do anything with |popup_| here. The OS either has already | 130 // We don't need to do anything with |popup_| here. The OS either has already |
131 // closed the window, in which case it's been deleted, or it will soon, in | 131 // closed the window, in which case it's been deleted, or it will soon, in |
132 // which case there's nothing we need to do. | 132 // which case there's nothing we need to do. |
(...skipping 15 matching lines...) Expand all Loading... |
148 return current_frame_bounds; | 148 return current_frame_bounds; |
149 } | 149 } |
150 | 150 |
151 void OmniboxPopupContentsView::LayoutChildren() { | 151 void OmniboxPopupContentsView::LayoutChildren() { |
152 gfx::Rect contents_rect = GetContentsBounds(); | 152 gfx::Rect contents_rect = GetContentsBounds(); |
153 contents_rect.Inset(gfx::Insets(kPopupVerticalPadding, 0)); | 153 contents_rect.Inset(gfx::Insets(kPopupVerticalPadding, 0)); |
154 contents_rect.Inset(start_margin_, g_top_shadow.Get().height(), end_margin_, | 154 contents_rect.Inset(start_margin_, g_top_shadow.Get().height(), end_margin_, |
155 0); | 155 0); |
156 | 156 |
157 int top = contents_rect.y(); | 157 int top = contents_rect.y(); |
158 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 158 for (size_t i = 0; i < AutocompleteResult::GetMaxMatches(); ++i) { |
159 View* v = child_at(i); | 159 View* v = child_at(i); |
160 if (v->visible()) { | 160 if (v->visible()) { |
161 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 161 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
162 v->GetPreferredSize().height()); | 162 v->GetPreferredSize().height()); |
163 top = v->bounds().bottom(); | 163 top = v->bounds().bottom(); |
164 } | 164 } |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if (match.answer && !model_->answer_bitmap().isNull()) { | 216 if (match.answer && !model_->answer_bitmap().isNull()) { |
217 view->SetAnswerImage( | 217 view->SetAnswerImage( |
218 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap())); | 218 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap())); |
219 } | 219 } |
220 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 220 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
221 max_match_contents_width_ = std::max( | 221 max_match_contents_width_ = std::max( |
222 max_match_contents_width_, view->GetMatchContentsWidth()); | 222 max_match_contents_width_, view->GetMatchContentsWidth()); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 for (size_t i = result_size; i < AutocompleteResult::kMaxMatches; ++i) | 226 for (size_t i = result_size; i < AutocompleteResult::GetMaxMatches(); ++i) |
227 child_at(i)->SetVisible(false); | 227 child_at(i)->SetVisible(false); |
228 | 228 |
229 // We want the popup to appear to overlay the bottom of the toolbar. So we | 229 // We want the popup to appear to overlay the bottom of the toolbar. So we |
230 // shift the popup to completely cover the client edge, and then draw an | 230 // shift the popup to completely cover the client edge, and then draw an |
231 // additional semitransparent shadow above that. | 231 // additional semitransparent shadow above that. |
232 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + | 232 int top_edge_overlap = views::NonClientFrameView::kClientEdgeThickness + |
233 g_top_shadow.Get().height(); | 233 g_top_shadow.Get().height(); |
234 | 234 |
235 gfx::Point top_left_screen_coord; | 235 gfx::Point top_left_screen_coord; |
236 int width; | 236 int width; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 size_t index = GetIndexForPoint(event.location()); | 528 size_t index = GetIndexForPoint(event.location()); |
529 if (!HasMatchAt(index)) | 529 if (!HasMatchAt(index)) |
530 return; | 530 return; |
531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
532 GURL(), base::string16(), index); | 532 GURL(), base::string16(), index); |
533 } | 533 } |
534 | 534 |
535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
537 } | 537 } |
OLD | NEW |