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 "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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 OmniboxResultView* result = result_view_at(line); | 142 OmniboxResultView* result = result_view_at(line); |
143 result->Invalidate(); | 143 result->Invalidate(); |
144 | 144 |
145 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { | 145 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { |
146 result->ShowKeyword(IsSelectedIndex(line) && | 146 result->ShowKeyword(IsSelectedIndex(line) && |
147 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); | 147 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void OmniboxPopupContentsView::UpdatePopupAppearance() { | 151 void OmniboxPopupContentsView::UpdatePopupAppearance() { |
152 const size_t hidden_matches = model_->result().ShouldHideTopMatch() ? 1 : 0; | 152 if (model_->result().empty() || |
153 if (model_->result().size() <= hidden_matches || | |
154 omnibox_view_->IsImeShowingPopup()) { | 153 omnibox_view_->IsImeShowingPopup()) { |
155 // No matches or the IME is showing a popup window which may overlap | 154 // No matches or the IME is showing a popup window which may overlap |
156 // the omnibox popup window. Close any existing popup. | 155 // the omnibox popup window. Close any existing popup. |
157 if (popup_ != NULL) { | 156 if (popup_ != NULL) { |
158 size_animation_.Stop(); | 157 size_animation_.Stop(); |
159 | 158 |
160 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack | 159 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack |
161 // triggered by the popup receiving a message (e.g. LBUTTONUP), and | 160 // triggered by the popup receiving a message (e.g. LBUTTONUP), and |
162 // destroying the popup would cause us to read garbage when we unwind back | 161 // destroying the popup would cause us to read garbage when we unwind back |
163 // to that level. | 162 // to that level. |
164 popup_->Close(); // This will eventually delete the popup. | 163 popup_->Close(); // This will eventually delete the popup. |
165 popup_.reset(); | 164 popup_.reset(); |
166 } | 165 } |
167 return; | 166 return; |
168 } | 167 } |
169 | 168 |
170 // Update the match cached by each row, in the process of doing so make sure | 169 // Update the match cached by each row, in the process of doing so make sure |
171 // we have enough row views. | 170 // we have enough row views. |
172 const size_t result_size = model_->result().size(); | 171 const size_t result_size = model_->result().size(); |
173 max_match_contents_width_ = 0; | 172 max_match_contents_width_ = 0; |
174 for (size_t i = 0; i < result_size; ++i) { | 173 for (size_t i = 0; i < result_size; ++i) { |
175 OmniboxResultView* view = result_view_at(i); | 174 OmniboxResultView* view = result_view_at(i); |
176 const AutocompleteMatch& match = GetMatchAtIndex(i); | 175 const AutocompleteMatch& match = GetMatchAtIndex(i); |
177 view->SetMatch(match); | 176 view->SetMatch(match); |
178 view->SetVisible(i >= hidden_matches); | 177 view->SetVisible(true); |
179 if (match.answer && !model_->answer_bitmap().isNull()) { | 178 if (match.answer && !model_->answer_bitmap().isNull()) { |
180 view->SetAnswerImage( | 179 view->SetAnswerImage( |
181 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap())); | 180 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap())); |
182 } | 181 } |
183 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 182 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
184 max_match_contents_width_ = std::max( | 183 max_match_contents_width_ = std::max( |
185 max_match_contents_width_, view->GetMatchContentsWidth()); | 184 max_match_contents_width_, view->GetMatchContentsWidth()); |
186 } | 185 } |
187 } | 186 } |
188 | 187 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 371 } |
373 event->SetHandled(); | 372 event->SetHandled(); |
374 } | 373 } |
375 | 374 |
376 //////////////////////////////////////////////////////////////////////////////// | 375 //////////////////////////////////////////////////////////////////////////////// |
377 // OmniboxPopupContentsView, protected: | 376 // OmniboxPopupContentsView, protected: |
378 | 377 |
379 int OmniboxPopupContentsView::CalculatePopupHeight() { | 378 int OmniboxPopupContentsView::CalculatePopupHeight() { |
380 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 379 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
381 int popup_height = 0; | 380 int popup_height = 0; |
382 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; | 381 for (size_t i = 0; i < model_->result().size(); ++i) |
383 i < model_->result().size(); ++i) | |
384 popup_height += child_at(i)->GetPreferredSize().height(); | 382 popup_height += child_at(i)->GetPreferredSize().height(); |
385 | 383 |
386 // Add enough space on the top and bottom so it looks like there is the same | 384 // Add enough space on the top and bottom so it looks like there is the same |
387 // amount of space between the text and the popup border as there is in the | 385 // amount of space between the text and the popup border as there is in the |
388 // interior between each row of text. | 386 // interior between each row of text. |
389 // | 387 // |
390 // The * 2 accounts for vertical padding used at the top and bottom. | 388 // The * 2 accounts for vertical padding used at the top and bottom. |
391 return popup_height + | 389 return popup_height + |
392 views::NonClientFrameView::kClientEdgeThickness + // Top border. | 390 views::NonClientFrameView::kClientEdgeThickness + // Top border. |
393 OmniboxResultView::kMinimumTextVerticalPadding * 2 + // Padding. | 391 OmniboxResultView::kMinimumTextVerticalPadding * 2 + // Padding. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 size_t index = GetIndexForPoint(event.location()); | 484 size_t index = GetIndexForPoint(event.location()); |
487 if (!HasMatchAt(index)) | 485 if (!HasMatchAt(index)) |
488 return; | 486 return; |
489 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 487 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
490 GURL(), base::string16(), index); | 488 GURL(), base::string16(), index); |
491 } | 489 } |
492 | 490 |
493 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 491 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
494 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 492 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
495 } | 493 } |
OLD | NEW |