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

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

Issue 1154063003: removing ShouldHideTopMatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed deprecated var name Created 5 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
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() || omnibox_view_->IsImeShowingPopup()) {
153 if (model_->result().size() <= hidden_matches ||
154 omnibox_view_->IsImeShowingPopup()) {
155 // No matches or the IME is showing a popup window which may overlap 153 // No matches or the IME is showing a popup window which may overlap
156 // the omnibox popup window. Close any existing popup. 154 // the omnibox popup window. Close any existing popup.
157 if (popup_ != NULL) { 155 if (popup_ != NULL) {
158 size_animation_.Stop(); 156 size_animation_.Stop();
159 157
160 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 158 // 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 159 // 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 160 // destroying the popup would cause us to read garbage when we unwind back
163 // to that level. 161 // to that level.
164 popup_->Close(); // This will eventually delete the popup. 162 popup_->Close(); // This will eventually delete the popup.
165 popup_.reset(); 163 popup_.reset();
166 } 164 }
167 return; 165 return;
168 } 166 }
169 167
170 // Update the match cached by each row, in the process of doing so make sure 168 // Update the match cached by each row, in the process of doing so make sure
171 // we have enough row views. 169 // we have enough row views.
172 const size_t result_size = model_->result().size(); 170 const size_t result_size = model_->result().size();
173 max_match_contents_width_ = 0; 171 max_match_contents_width_ = 0;
174 for (size_t i = 0; i < result_size; ++i) { 172 for (size_t i = 0; i < result_size; ++i) {
175 OmniboxResultView* view = result_view_at(i); 173 OmniboxResultView* view = result_view_at(i);
176 const AutocompleteMatch& match = GetMatchAtIndex(i); 174 const AutocompleteMatch& match = GetMatchAtIndex(i);
177 view->SetMatch(match); 175 view->SetMatch(match);
178 view->SetVisible(i >= hidden_matches); 176 view->SetVisible(true);
179 if (match.answer && !model_->answer_bitmap().isNull()) { 177 if (match.answer && !model_->answer_bitmap().isNull()) {
180 view->SetAnswerImage( 178 view->SetAnswerImage(
181 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap())); 179 gfx::ImageSkia::CreateFrom1xBitmap(model_->answer_bitmap()));
182 } 180 }
183 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { 181 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) {
184 max_match_contents_width_ = std::max( 182 max_match_contents_width_ = std::max(
185 max_match_contents_width_, view->GetMatchContentsWidth()); 183 max_match_contents_width_, view->GetMatchContentsWidth());
186 } 184 }
187 } 185 }
188 186
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 370 }
373 event->SetHandled(); 371 event->SetHandled();
374 } 372 }
375 373
376 //////////////////////////////////////////////////////////////////////////////// 374 ////////////////////////////////////////////////////////////////////////////////
377 // OmniboxPopupContentsView, protected: 375 // OmniboxPopupContentsView, protected:
378 376
379 int OmniboxPopupContentsView::CalculatePopupHeight() { 377 int OmniboxPopupContentsView::CalculatePopupHeight() {
380 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); 378 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
381 int popup_height = 0; 379 int popup_height = 0;
382 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; 380 for (size_t i = 0; i < model_->result().size(); ++i)
383 i < model_->result().size(); ++i)
384 popup_height += child_at(i)->GetPreferredSize().height(); 381 popup_height += child_at(i)->GetPreferredSize().height();
385 382
386 // Add enough space on the top and bottom so it looks like there is the same 383 // 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 384 // amount of space between the text and the popup border as there is in the
388 // interior between each row of text. 385 // interior between each row of text.
389 // 386 //
390 // The * 2 accounts for vertical padding used at the top and bottom. 387 // The * 2 accounts for vertical padding used at the top and bottom.
391 return popup_height + 388 return popup_height +
392 views::NonClientFrameView::kClientEdgeThickness + // Top border. 389 views::NonClientFrameView::kClientEdgeThickness + // Top border.
393 OmniboxResultView::kMinimumTextVerticalPadding * 2 + // Padding. 390 OmniboxResultView::kMinimumTextVerticalPadding * 2 + // Padding.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 size_t index = GetIndexForPoint(event.location()); 483 size_t index = GetIndexForPoint(event.location());
487 if (!HasMatchAt(index)) 484 if (!HasMatchAt(index))
488 return; 485 return;
489 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, 486 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition,
490 GURL(), base::string16(), index); 487 GURL(), base::string16(), index);
491 } 488 }
492 489
493 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { 490 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) {
494 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); 491 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i)));
495 } 492 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_controller.cc ('k') | components/metrics/proto/omnibox_event.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698