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

Side by Side Diff: chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_popup_contents_view. h" 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
10 #include "chrome/browser/instant/instant_confirm_dialog.h" 10 #include "chrome/browser/instant/instant_confirm_dialog.h"
11 #include "chrome/browser/instant/promo_counter.h" 11 #include "chrome/browser/instant/promo_counter.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/omnibox/omnibox_view.h" 13 #include "chrome/browser/ui/omnibox/omnibox_view.h"
14 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" 14 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h"
15 #include "chrome/browser/ui/views/bubble/bubble_border.h" 15 #include "chrome/browser/ui/views/bubble/bubble_border.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 #include "third_party/skia/include/core/SkShader.h" 20 #include "third_party/skia/include/core/SkShader.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/base/theme_provider.h" 23 #include "ui/base/theme_provider.h"
24 #include "ui/gfx/canvas_skia.h" 24 #include "ui/gfx/canvas_skia.h"
25 #include "ui/gfx/insets.h" 25 #include "ui/gfx/insets.h"
26 #include "ui/gfx/path.h" 26 #include "ui/gfx/path.h"
27 #include "ui/gfx/rect.h"
27 #include "unicode/ubidi.h" 28 #include "unicode/ubidi.h"
28 #include "views/controls/button/text_button.h" 29 #include "views/controls/button/text_button.h"
29 #include "views/controls/label.h" 30 #include "views/controls/label.h"
30 #include "views/layout/grid_layout.h" 31 #include "views/layout/grid_layout.h"
31 #include "views/layout/layout_constants.h" 32 #include "views/layout/layout_constants.h"
32 #include "views/painter.h" 33 #include "views/painter.h"
33 #include "views/widget/widget.h" 34 #include "views/widget/widget.h"
34 35
35 #if defined(OS_WIN) 36 #if defined(OS_WIN)
36 #include <commctrl.h> 37 #include <commctrl.h>
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } // namespace 136 } // namespace
136 137
137 class AutocompletePopupContentsView::AutocompletePopupWidget 138 class AutocompletePopupContentsView::AutocompletePopupWidget
138 : public views::Widget, 139 : public views::Widget,
139 public base::SupportsWeakPtr<AutocompletePopupWidget> { 140 public base::SupportsWeakPtr<AutocompletePopupWidget> {
140 public: 141 public:
141 AutocompletePopupWidget() {} 142 AutocompletePopupWidget() {}
142 virtual ~AutocompletePopupWidget() {} 143 virtual ~AutocompletePopupWidget() {}
143 144
144 private: 145 private:
145 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); 146 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget);
146 }; 147 };
147 148
148 class AutocompletePopupContentsView::InstantOptInView 149 class AutocompletePopupContentsView::InstantOptInView
149 : public views::View, 150 : public views::View,
150 public views::ButtonListener { 151 public views::ButtonListener {
151 public: 152 public:
152 InstantOptInView(AutocompletePopupContentsView* contents_view, 153 InstantOptInView(AutocompletePopupContentsView* contents_view,
153 const gfx::Font& label_font, 154 const gfx::Font& label_font,
154 const gfx::Font& button_font) 155 const gfx::Font& button_font)
155 : contents_view_(contents_view), 156 : contents_view_(contents_view),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), 240 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)),
240 ignore_mouse_drag_(false), 241 ignore_mouse_drag_(false),
241 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { 242 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) {
242 // The following little dance is required because set_border() requires a 243 // The following little dance is required because set_border() requires a
243 // pointer to a non-const object. 244 // pointer to a non-const object.
244 BubbleBorder* bubble_border = new BubbleBorder(BubbleBorder::NONE); 245 BubbleBorder* bubble_border = new BubbleBorder(BubbleBorder::NONE);
245 bubble_border_ = bubble_border; 246 bubble_border_ = bubble_border;
246 set_border(bubble_border); 247 set_border(bubble_border);
247 // The contents is owned by the LocationBarView. 248 // The contents is owned by the LocationBarView.
248 set_parent_owned(false); 249 set_parent_owned(false);
250
251 for (size_t i = 0; i < AutocompleteResult::kMaxMatches * 2; ++i) {
sky 2011/08/01 16:02:15 I don't like always creating the max result views
252 AutocompleteResultView* result_view =
253 CreateResultView(this, i, result_font_, result_bold_font_);
254 AddChildViewAt(result_view, static_cast<int>(i));
255 result_view->SetVisible(false);
256
257 if (i < AutocompleteResult::kMaxMatches) {
258 ui::SlideAnimation* anim = new ui::SlideAnimation(this);
259 anim->SetSlideDuration(500);
sky 2011/08/01 16:02:15 500 is too long. Can you use the default?
260 keyword_animations_.push_back(anim);
261 }
262 }
249 } 263 }
250 264
251 AutocompletePopupContentsView::~AutocompletePopupContentsView() { 265 AutocompletePopupContentsView::~AutocompletePopupContentsView() {
252 // We don't need to do anything with |popup_| here. The OS either has already 266 // We don't need to do anything with |popup_| here. The OS either has already
253 // closed the window, in which case it's been deleted, or it will soon, in 267 // closed the window, in which case it's been deleted, or it will soon, in
254 // which case there's nothing we need to do. 268 // which case there's nothing we need to do.
255 } 269 }
256 270
257 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { 271 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const {
258 if (!size_animation_.is_animating()) 272 if (!size_animation_.is_animating())
259 return target_bounds_; 273 return target_bounds_;
260 274
261 gfx::Rect current_frame_bounds = start_bounds_; 275 gfx::Rect current_frame_bounds = start_bounds_;
262 int total_height_delta = target_bounds_.height() - start_bounds_.height(); 276 int total_height_delta = target_bounds_.height() - start_bounds_.height();
263 // Round |current_height_delta| instead of truncating so we won't leave single 277 // Round |current_height_delta| instead of truncating so we won't leave single
264 // white pixels at the bottom of the popup as long when animating very small 278 // white pixels at the bottom of the popup as long when animating very small
265 // height differences. 279 // height differences.
266 int current_height_delta = static_cast<int>( 280 int current_height_delta = static_cast<int>(
267 size_animation_.GetCurrentValue() * total_height_delta - 0.5); 281 size_animation_.GetCurrentValue() * total_height_delta - 0.5);
268 current_frame_bounds.set_height( 282 current_frame_bounds.set_height(
269 current_frame_bounds.height() + current_height_delta); 283 current_frame_bounds.height() + current_height_delta);
270 return current_frame_bounds; 284 return current_frame_bounds;
271 } 285 }
272 286
273 void AutocompletePopupContentsView::LayoutChildren() { 287 void AutocompletePopupContentsView::LayoutChildren() {
274 gfx::Rect contents_rect = GetContentsBounds(); 288 gfx::Rect contents_rect = GetContentsBounds();
275 int top = contents_rect.y(); 289 int top = contents_rect.y();
276 for (int i = 0; i < child_count(); ++i) { 290
277 View* v = child_at(i); 291 for (int i = 0; i < child_count(); i += 2) {
278 if (v->IsVisible()) { 292 View* result = child_at(i);
279 v->SetBounds(contents_rect.x(), top, contents_rect.width(), 293 if (!result->IsVisible())
280 v->GetPreferredSize().height()); 294 continue;
281 top = v->bounds().bottom(); 295
296 AutocompleteResultView* keyword =
sky 2011/08/01 16:02:15 Casts like this are easy to get wrong. Use an id o
aaron.randolph 2011/08/02 21:54:58 Just to be clear, are you suggesting I keep a list
Peter Kasting 2011/08/04 20:07:53 Nit: TBH, I don't think this suggestion of Scott's
297 static_cast<AutocompleteResultView*>(child_at(i + 1));
298 if (keyword->IsVisible()) {
299 const float collapsed_width = static_cast<float>(
300 keyword->GetCollapsedSize().width() + LocationBarView::kItemPadding);
301 const float kw_collapsed_x = static_cast<float>(contents_rect.width() -
302 collapsed_width);
303 const int kw_x = static_cast<int>(kw_collapsed_x - ((kw_collapsed_x -
304 collapsed_width) * keyword_animations_[i / 2]->GetCurrentValue()));
sky 2011/08/01 16:02:15 To make lifetime easier can be push the animation
305
306 result->SetBounds(contents_rect.x(), top,
307 kw_x - LocationBarView::kItemPadding,
Peter Kasting 2011/07/29 21:08:44 Don't we only want to subtract 1?
308 result->GetPreferredSize().height());
309 keyword->SetBounds(kw_x + LocationBarView::kItemPadding, top,
310 contents_rect.width() - (kw_x - LocationBarView::kItemPadding),
311 keyword->GetPreferredSize().height());
312 } else {
313 result->SetBounds(contents_rect.x(), top, contents_rect.width(),
314 result->GetPreferredSize().height());
282 } 315 }
316 top = result->bounds().bottom();
283 } 317 }
318
319 if (opt_in_view_ && opt_in_view_->IsVisible())
320 opt_in_view_->SetBounds(contents_rect.x(), top, contents_rect.width(),
321 opt_in_view_->GetPreferredSize().height());
284 } 322 }
285 323
286 //////////////////////////////////////////////////////////////////////////////// 324 ////////////////////////////////////////////////////////////////////////////////
287 // AutocompletePopupContentsView, AutocompletePopupView overrides: 325 // AutocompletePopupContentsView, AutocompletePopupView overrides:
288 326
289 bool AutocompletePopupContentsView::IsOpen() const { 327 bool AutocompletePopupContentsView::IsOpen() const {
290 return (popup_ != NULL); 328 return (popup_ != NULL);
291 } 329 }
292 330
293 void AutocompletePopupContentsView::InvalidateLine(size_t line) { 331 void AutocompletePopupContentsView::InvalidateLine(size_t line) {
294 child_at(static_cast<int>(line))->SchedulePaint(); 332 child_at(static_cast<int>(line * 2))->SchedulePaint();
sky 2011/08/01 16:02:15 spacing if off.
333 child_at(static_cast<int>(line * 2 + 1))->SchedulePaint();
334
335 if (line == model_->selected_line() && model_->keyword_selected())
336 keyword_animations_[line]->Show();
337 else
338 keyword_animations_[line]->Hide();
295 } 339 }
296 340
297 void AutocompletePopupContentsView::UpdatePopupAppearance() { 341 void AutocompletePopupContentsView::UpdatePopupAppearance() {
298 if (model_->result().empty()) { 342 if (model_->result().empty()) {
299 // No matches, close any existing popup. 343 // No matches, close any existing popup.
300 if (popup_ != NULL) { 344 if (popup_ != NULL) {
301 size_animation_.Stop(); 345 size_animation_.Stop();
346
347 for (SlideAnimations::iterator i(keyword_animations_.begin());
348 i != keyword_animations_.end(); ++i)
349 (*i)->Stop();
350
302 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 351 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack
303 // triggered by the popup receiving a message (e.g. LBUTTONUP), and 352 // triggered by the popup receiving a message (e.g. LBUTTONUP), and
304 // destroying the popup would cause us to read garbage when we unwind back 353 // destroying the popup would cause us to read garbage when we unwind back
305 // to that level. 354 // to that level.
306 popup_->Close(); // This will eventually delete the popup. 355 popup_->Close(); // This will eventually delete the popup.
307 popup_.reset(); 356 popup_.reset();
308 } 357 }
309 return; 358 return;
310 } 359 }
311 360
312 // Update the match cached by each row, in the process of doing so make sure 361 // Update the match cached by each row, in the process of doing so make sure
313 // we have enough row views. 362 // we have enough row views.
314 size_t child_rv_count = child_count(); 363 size_t child_rv_count = child_count();
315 if (opt_in_view_) { 364 if (opt_in_view_) {
316 DCHECK(child_rv_count > 0); 365 DCHECK(child_rv_count > 0);
317 child_rv_count--; 366 child_rv_count--;
318 } 367 }
319 for (size_t i = 0; i < model_->result().size(); ++i) { 368 const size_t result_size = model_->result().size();
320 AutocompleteResultView* result_view; 369 for (size_t i = 0; i < result_size; ++i) {
321 if (i >= child_rv_count) { 370 const AutocompleteMatch& match = GetMatchAtIndex(i);
322 result_view = 371 AutocompleteResultView* view = static_cast<AutocompleteResultView*>(
323 CreateResultView(this, i, result_font_, result_bold_font_); 372 child_at(i * 2));
324 AddChildViewAt(result_view, static_cast<int>(i)); 373 view->SetMatch(match);
325 } else { 374 view->SetVisible(true);
326 result_view = static_cast<AutocompleteResultView*>(child_at(i)); 375
327 result_view->SetVisible(true); 376 view = static_cast<AutocompleteResultView*>(child_at(i * 2 + 1));
328 } 377 view->SetVisible(match.associated_keyword.get() != NULL);
329 result_view->SetMatch(GetMatchAtIndex(i)); 378 if (view->IsVisible())
379 view->SetMatch(*match.associated_keyword);
380
381 keyword_animations_[i]->Reset();
330 } 382 }
331 for (size_t i = model_->result().size(); i < child_rv_count; ++i) 383 for (size_t i = result_size * 2; i < child_rv_count; ++i)
332 child_at(i)->SetVisible(false); 384 child_at(i)->SetVisible(false);
333 385
334 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 386 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
335 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { 387 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) {
336 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); 388 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_);
337 AddChildView(opt_in_view_); 389 AddChildView(opt_in_view_);
338 } else if (opt_in_view_ && (!counter || 390 } else if (opt_in_view_ && (!counter ||
339 !counter->ShouldShow(base::Time::Now()))) { 391 !counter->ShouldShow(base::Time::Now()))) {
340 delete opt_in_view_; 392 delete opt_in_view_;
341 opt_in_view_ = NULL; 393 opt_in_view_ = NULL;
(...skipping 26 matching lines...) Expand all
368 // Animate the popup shrinking, but don't animate growing larger since that 420 // Animate the popup shrinking, but don't animate growing larger since that
369 // would make the popup feel less responsive. 421 // would make the popup feel less responsive.
370 start_bounds_ = GetWidget()->GetWindowScreenBounds(); 422 start_bounds_ = GetWidget()->GetWindowScreenBounds();
371 if (target_bounds_.height() < start_bounds_.height()) 423 if (target_bounds_.height() < start_bounds_.height())
372 size_animation_.Show(); 424 size_animation_.Show();
373 else 425 else
374 start_bounds_ = target_bounds_; 426 start_bounds_ = target_bounds_;
375 popup_->SetBounds(GetPopupBounds()); 427 popup_->SetBounds(GetPopupBounds());
376 } 428 }
377 429
378 SchedulePaint(); 430 Layout();
379 } 431 }
380 432
381 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() { 433 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() {
382 return target_bounds_; 434 return target_bounds_;
383 } 435 }
384 436
385 void AutocompletePopupContentsView::PaintUpdatesNow() { 437 void AutocompletePopupContentsView::PaintUpdatesNow() {
386 // TODO(beng): remove this from the interface. 438 // TODO(beng): remove this from the interface.
387 } 439 }
388 440
389 void AutocompletePopupContentsView::OnDragCanceled() { 441 void AutocompletePopupContentsView::OnDragCanceled() {
390 ignore_mouse_drag_ = true; 442 ignore_mouse_drag_ = true;
391 } 443 }
392 444
393 //////////////////////////////////////////////////////////////////////////////// 445 ////////////////////////////////////////////////////////////////////////////////
394 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation: 446 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation:
395 447
396 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const { 448 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const {
397 return HasMatchAt(index) ? index == model_->selected_line() : false; 449 size_t selected_line = model_->selected_line() * 2;
450
451 if (model_->keyword_selected())
452 selected_line++;
453
454 return index == selected_line;
398 } 455 }
399 456
400 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const { 457 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const {
401 return HasMatchAt(index) ? index == model_->hovered_line() : false; 458 return index == model_->hovered_line() * 2;
402 } 459 }
403 460
404 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch( 461 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch(
405 size_t index) const { 462 size_t index) const {
406 if (!HasMatchAt(index)) 463 if (!HasMatchAt(index))
407 return NULL; 464 return NULL;
408 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index)); 465 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index));
409 } 466 }
410 467
411 //////////////////////////////////////////////////////////////////////////////// 468 ////////////////////////////////////////////////////////////////////////////////
412 // AutocompletePopupContentsView, AnimationDelegate implementation: 469 // AutocompletePopupContentsView, AnimationDelegate implementation:
413 470
414 void AutocompletePopupContentsView::AnimationProgressed( 471 void AutocompletePopupContentsView::AnimationProgressed(
415 const ui::Animation* animation) { 472 const ui::Animation* animation) {
416 // We should only be running the animation when the popup is already visible. 473 // We should only be running the animation when the popup is already visible.
417 DCHECK(popup_ != NULL); 474 DCHECK(popup_ != NULL);
418 popup_->SetBounds(GetPopupBounds()); 475 popup_->SetBounds(GetPopupBounds());
476
477 Layout();
419 } 478 }
420 479
421 //////////////////////////////////////////////////////////////////////////////// 480 ////////////////////////////////////////////////////////////////////////////////
422 // AutocompletePopupContentsView, views::View overrides: 481 // AutocompletePopupContentsView, views::View overrides:
423 482
424 void AutocompletePopupContentsView::Layout() { 483 void AutocompletePopupContentsView::Layout() {
425 UpdateBlurRegion(); 484 UpdateBlurRegion();
426 485
427 // Size our children to the available content area. 486 // Size our children to the available content area.
428 LayoutChildren(); 487 LayoutChildren();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); 561 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
503 } 562 }
504 563
505 //////////////////////////////////////////////////////////////////////////////// 564 ////////////////////////////////////////////////////////////////////////////////
506 // AutocompletePopupContentsView, protected: 565 // AutocompletePopupContentsView, protected:
507 566
508 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { 567 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) {
509 canvas->drawColor(AutocompleteResultView::GetColor( 568 canvas->drawColor(AutocompleteResultView::GetColor(
510 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); 569 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND));
511 View::PaintChildren(canvas); 570 View::PaintChildren(canvas);
571
572 // Draw dividing lines between results and keyword views.
573 SkPaint paint;
574 paint.setColor(AutocompleteResultView::GetColor(
575 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT));
576 paint.setStrokeWidth(SkIntToScalar(1));
577 paint.setAntiAlias(true);
578
579 for (size_t i = 0; i < model_->result().size(); ++i) {
580 views::View* kw_child = child_at(i * 2 + 1);
581 if (kw_child->IsVisible()) {
582 gfx::Rect bounds = kw_child->bounds();
583
584 canvas->drawLine(
585 SkIntToScalar(bounds.x() -
586 LocationBarView::kNormalHorizontalEdgeThickness),
Peter Kasting 2011/07/29 21:08:44 Nit: Simpler: Use the even children and draw at (b
aaron.randolph 2011/07/29 21:57:10 I would still need to add the constant to the righ
Peter Kasting 2011/07/30 00:00:29 I was imagining the left and right sides having ex
aaron.randolph 2011/07/30 00:34:17 I'm with you now. I was thinking right() was incl
587 SkIntToScalar(bounds.y() +
588 LocationBarView::kNormalHorizontalEdgeThickness),
589 SkIntToScalar(bounds.x() -
590 LocationBarView::kNormalHorizontalEdgeThickness),
591 SkIntToScalar(bounds.y() + bounds.height() -
592 LocationBarView::kNormalHorizontalEdgeThickness * 2),
593 paint);
594 }
595 }
512 } 596 }
513 597
514 int AutocompletePopupContentsView::CalculatePopupHeight() { 598 int AutocompletePopupContentsView::CalculatePopupHeight() {
515 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); 599 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
516 int popup_height = 0; 600 int popup_height = 0;
517 for (size_t i = 0; i < model_->result().size(); ++i) 601 for (size_t i = 0; i < model_->result().size(); ++i)
518 popup_height += child_at(i)->GetPreferredSize().height(); 602 popup_height += child_at(i)->GetPreferredSize().height();
519 return popup_height + 603 return popup_height +
520 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); 604 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0);
521 } 605 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void AutocompletePopupContentsView::OpenIndex( 722 void AutocompletePopupContentsView::OpenIndex(
639 size_t index, 723 size_t index,
640 WindowOpenDisposition disposition) { 724 WindowOpenDisposition disposition) {
641 if (!HasMatchAt(index)) 725 if (!HasMatchAt(index))
642 return; 726 return;
643 727
644 // OpenMatch() may close the popup, which will clear the result set and, by 728 // OpenMatch() may close the popup, which will clear the result set and, by
645 // extension, |match| and its contents. So copy the relevant match out to 729 // extension, |match| and its contents. So copy the relevant match out to
646 // make sure it stays alive until the call completes. 730 // make sure it stays alive until the call completes.
647 AutocompleteMatch match = model_->result().match_at(index); 731 AutocompleteMatch match = model_->result().match_at(index);
648 string16 keyword;
649 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword);
650 omnibox_view_->OpenMatch(match, disposition, GURL(), index, 732 omnibox_view_->OpenMatch(match, disposition, GURL(), index,
651 is_keyword_hint ? string16() : keyword); 733 match.keyword);
652 } 734 }
653 735
654 size_t AutocompletePopupContentsView::GetIndexForPoint( 736 size_t AutocompletePopupContentsView::GetIndexForPoint(
655 const gfx::Point& point) { 737 const gfx::Point& point) {
656 if (!HitTest(point)) 738 if (!HitTest(point))
657 return AutocompletePopupModel::kNoMatch; 739 return AutocompletePopupModel::kNoMatch;
658 740
659 int nb_match = model_->result().size(); 741 int nb_match = model_->result().size();
660 DCHECK(nb_match <= child_count()); 742 DCHECK(nb_match <= child_count());
661 for (int i = 0; i < nb_match; ++i) { 743 for (int i = 0; i < nb_match; ++i) {
662 views::View* child = child_at(i); 744 views::View* child = child_at(i * 2);
663 gfx::Point point_in_child_coords(point); 745 gfx::Point point_in_child_coords(point);
664 View::ConvertPointToView(this, child, &point_in_child_coords); 746 View::ConvertPointToView(this, child, &point_in_child_coords);
665 if (child->HitTest(point_in_child_coords)) 747 if (child->HitTest(point_in_child_coords))
666 return i; 748 return i;
667 } 749 }
668 return AutocompletePopupModel::kNoMatch; 750 return AutocompletePopupModel::kNoMatch;
669 } 751 }
670 752
671 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) { 753 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) {
672 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); 754 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds());
(...skipping 23 matching lines...) Expand all
696 opt_in_view_ = NULL; 778 opt_in_view_ = NULL;
697 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 779 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
698 DCHECK(counter); 780 DCHECK(counter);
699 counter->Hide(); 781 counter->Hide();
700 if (opt_in) { 782 if (opt_in) {
701 browser::ShowInstantConfirmDialogIfNecessary( 783 browser::ShowInstantConfirmDialogIfNecessary(
702 location_bar_->GetWidget()->GetNativeWindow(), model_->profile()); 784 location_bar_->GetWidget()->GetNativeWindow(), model_->profile());
703 } 785 }
704 UpdatePopupAppearance(); 786 UpdatePopupAppearance();
705 } 787 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698