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

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) {
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 keyword_animations_.push_back(new ui::SlideAnimation(this));
259 }
260 }
249 } 261 }
250 262
251 AutocompletePopupContentsView::~AutocompletePopupContentsView() { 263 AutocompletePopupContentsView::~AutocompletePopupContentsView() {
252 // We don't need to do anything with |popup_| here. The OS either has already 264 // 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 265 // 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. 266 // which case there's nothing we need to do.
255 } 267 }
256 268
257 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { 269 gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const {
258 if (!size_animation_.is_animating()) 270 if (!size_animation_.is_animating())
259 return target_bounds_; 271 return target_bounds_;
260 272
261 gfx::Rect current_frame_bounds = start_bounds_; 273 gfx::Rect current_frame_bounds = start_bounds_;
262 int total_height_delta = target_bounds_.height() - start_bounds_.height(); 274 int total_height_delta = target_bounds_.height() - start_bounds_.height();
263 // Round |current_height_delta| instead of truncating so we won't leave single 275 // 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 276 // white pixels at the bottom of the popup as long when animating very small
265 // height differences. 277 // height differences.
266 int current_height_delta = static_cast<int>( 278 int current_height_delta = static_cast<int>(
267 size_animation_.GetCurrentValue() * total_height_delta - 0.5); 279 size_animation_.GetCurrentValue() * total_height_delta - 0.5);
268 current_frame_bounds.set_height( 280 current_frame_bounds.set_height(
269 current_frame_bounds.height() + current_height_delta); 281 current_frame_bounds.height() + current_height_delta);
270 return current_frame_bounds; 282 return current_frame_bounds;
271 } 283 }
272 284
273 void AutocompletePopupContentsView::LayoutChildren() { 285 void AutocompletePopupContentsView::LayoutChildren() {
274 gfx::Rect contents_rect = GetContentsBounds(); 286 gfx::Rect contents_rect = GetContentsBounds();
275 int top = contents_rect.y(); 287 int top = contents_rect.y();
276 for (int i = 0; i < child_count(); ++i) { 288
277 View* v = child_at(i); 289 for (size_t i = 0; i < AutocompleteResult::kMaxMatches * 2; i += 2) {
278 if (v->IsVisible()) { 290 View* result = child_at(i);
279 v->SetBounds(contents_rect.x(), top, contents_rect.width(), 291 if (!result->IsVisible())
280 v->GetPreferredSize().height()); 292 continue;
281 top = v->bounds().bottom(); 293
294 AutocompleteResultView* keyword =
295 static_cast<AutocompleteResultView*>(child_at(i + 1));
296 if (keyword->IsVisible()) {
297 const int collapsed_width = keyword->GetCollapsedSize().width() +
298 LocationBarView::kEdgeItemPadding;
299 const int kw_collapsed_x = contents_rect.width() - collapsed_width;
300 const int kw_x = contents_rect.width() -
301 keyword_animations_[i / 2]->CurrentValueBetween(collapsed_width,
302 kw_collapsed_x);
303
304 result->SetBounds(contents_rect.x(), top,
305 kw_x - LocationBarView::kNormalHorizontalEdgeThickness,
306 result->GetPreferredSize().height());
307 keyword->SetBounds(contents_rect.x() + kw_x, top,
308 contents_rect.width() - kw_x, keyword->GetPreferredSize().height());
309 } else {
310 result->SetBounds(contents_rect.x(), top, contents_rect.width(),
311 result->GetPreferredSize().height());
282 } 312 }
313 top = result->bounds().bottom();
283 } 314 }
315
316 if (opt_in_view_ && opt_in_view_->IsVisible())
317 opt_in_view_->SetBounds(contents_rect.x(), top, contents_rect.width(),
318 opt_in_view_->GetPreferredSize().height());
284 } 319 }
285 320
286 //////////////////////////////////////////////////////////////////////////////// 321 ////////////////////////////////////////////////////////////////////////////////
287 // AutocompletePopupContentsView, AutocompletePopupView overrides: 322 // AutocompletePopupContentsView, AutocompletePopupView overrides:
288 323
289 bool AutocompletePopupContentsView::IsOpen() const { 324 bool AutocompletePopupContentsView::IsOpen() const {
290 return (popup_ != NULL); 325 return (popup_ != NULL);
291 } 326 }
292 327
293 void AutocompletePopupContentsView::InvalidateLine(size_t line) { 328 void AutocompletePopupContentsView::InvalidateLine(size_t line) {
294 child_at(static_cast<int>(line))->SchedulePaint(); 329 child_at(static_cast<int>(line * 2))->SchedulePaint();
330 child_at(static_cast<int>(line * 2 + 1))->SchedulePaint();
331
332 if (line == model_->selected_line() &&
333 model_->selected_match() == AutocompletePopupModel::KEYWORD)
334 keyword_animations_[line]->Show();
335 else
336 keyword_animations_[line]->Hide();
295 } 337 }
296 338
297 void AutocompletePopupContentsView::UpdatePopupAppearance() { 339 void AutocompletePopupContentsView::UpdatePopupAppearance() {
298 if (model_->result().empty()) { 340 if (model_->result().empty()) {
299 // No matches, close any existing popup. 341 // No matches, close any existing popup.
300 if (popup_ != NULL) { 342 if (popup_ != NULL) {
301 size_animation_.Stop(); 343 size_animation_.Stop();
344
345 for (SlideAnimations::iterator i(keyword_animations_.begin());
346 i != keyword_animations_.end(); ++i)
347 (*i)->Stop();
348
302 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 349 // 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 350 // 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 351 // destroying the popup would cause us to read garbage when we unwind back
305 // to that level. 352 // to that level.
306 popup_->Close(); // This will eventually delete the popup. 353 popup_->Close(); // This will eventually delete the popup.
307 popup_.reset(); 354 popup_.reset();
308 } 355 }
309 return; 356 return;
310 } 357 }
311 358
312 // Update the match cached by each row, in the process of doing so make sure 359 // Update the match cached by each row, in the process of doing so make sure
313 // we have enough row views. 360 // we have enough row views.
314 size_t child_rv_count = child_count(); 361 size_t child_rv_count = child_count();
315 if (opt_in_view_) { 362 if (opt_in_view_) {
316 DCHECK(child_rv_count > 0); 363 DCHECK(child_rv_count > 0);
317 child_rv_count--; 364 child_rv_count--;
318 } 365 }
319 for (size_t i = 0; i < model_->result().size(); ++i) { 366 const size_t result_size = model_->result().size();
320 AutocompleteResultView* result_view; 367 for (size_t i = 0; i < result_size; ++i) {
321 if (i >= child_rv_count) { 368 const AutocompleteMatch& match = GetMatchAtIndex(i);
322 result_view = 369 AutocompleteResultView* view = static_cast<AutocompleteResultView*>(
323 CreateResultView(this, i, result_font_, result_bold_font_); 370 child_at(i * 2));
324 AddChildViewAt(result_view, static_cast<int>(i)); 371 view->SetMatch(match);
325 } else { 372 view->SetVisible(true);
326 result_view = static_cast<AutocompleteResultView*>(child_at(i)); 373
327 result_view->SetVisible(true); 374 view = static_cast<AutocompleteResultView*>(child_at(i * 2 + 1));
328 } 375 view->SetVisible(match.associated_keyword.get() != NULL);
329 result_view->SetMatch(GetMatchAtIndex(i)); 376 if (view->IsVisible())
377 view->SetMatch(*match.associated_keyword);
378
379 keyword_animations_[i]->Reset();
330 } 380 }
331 for (size_t i = model_->result().size(); i < child_rv_count; ++i) 381 for (size_t i = result_size * 2; i < child_rv_count; ++i)
332 child_at(i)->SetVisible(false); 382 child_at(i)->SetVisible(false);
333 383
334 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 384 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
335 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { 385 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) {
336 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); 386 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_);
337 AddChildView(opt_in_view_); 387 AddChildView(opt_in_view_);
338 } else if (opt_in_view_ && (!counter || 388 } else if (opt_in_view_ && (!counter ||
339 !counter->ShouldShow(base::Time::Now()))) { 389 !counter->ShouldShow(base::Time::Now()))) {
340 delete opt_in_view_; 390 delete opt_in_view_;
341 opt_in_view_ = NULL; 391 opt_in_view_ = NULL;
(...skipping 26 matching lines...) Expand all
368 // Animate the popup shrinking, but don't animate growing larger since that 418 // Animate the popup shrinking, but don't animate growing larger since that
369 // would make the popup feel less responsive. 419 // would make the popup feel less responsive.
370 start_bounds_ = GetWidget()->GetWindowScreenBounds(); 420 start_bounds_ = GetWidget()->GetWindowScreenBounds();
371 if (target_bounds_.height() < start_bounds_.height()) 421 if (target_bounds_.height() < start_bounds_.height())
372 size_animation_.Show(); 422 size_animation_.Show();
373 else 423 else
374 start_bounds_ = target_bounds_; 424 start_bounds_ = target_bounds_;
375 popup_->SetBounds(GetPopupBounds()); 425 popup_->SetBounds(GetPopupBounds());
376 } 426 }
377 427
378 SchedulePaint(); 428 Layout();
379 } 429 }
380 430
381 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() { 431 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() {
382 return target_bounds_; 432 return target_bounds_;
383 } 433 }
384 434
385 void AutocompletePopupContentsView::PaintUpdatesNow() { 435 void AutocompletePopupContentsView::PaintUpdatesNow() {
386 // TODO(beng): remove this from the interface. 436 // TODO(beng): remove this from the interface.
387 } 437 }
388 438
389 void AutocompletePopupContentsView::OnDragCanceled() { 439 void AutocompletePopupContentsView::OnDragCanceled() {
390 ignore_mouse_drag_ = true; 440 ignore_mouse_drag_ = true;
391 } 441 }
392 442
393 //////////////////////////////////////////////////////////////////////////////// 443 ////////////////////////////////////////////////////////////////////////////////
394 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation: 444 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation:
395 445
396 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const { 446 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const {
397 return HasMatchAt(index) ? index == model_->selected_line() : false; 447 size_t selected_line = model_->selected_line() * 2;
448
449 if (model_->selected_match() == AutocompletePopupModel::KEYWORD)
450 selected_line++;
451
452 return index == selected_line;
398 } 453 }
399 454
400 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const { 455 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const {
401 return HasMatchAt(index) ? index == model_->hovered_line() : false; 456 return index == model_->hovered_line() * 2;
402 } 457 }
403 458
404 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch( 459 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch(
405 size_t index) const { 460 size_t index) const {
406 if (!HasMatchAt(index)) 461 if (!HasMatchAt(index))
407 return NULL; 462 return NULL;
408 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index)); 463 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index));
409 } 464 }
410 465
411 //////////////////////////////////////////////////////////////////////////////// 466 ////////////////////////////////////////////////////////////////////////////////
412 // AutocompletePopupContentsView, AnimationDelegate implementation: 467 // AutocompletePopupContentsView, AnimationDelegate implementation:
413 468
414 void AutocompletePopupContentsView::AnimationProgressed( 469 void AutocompletePopupContentsView::AnimationProgressed(
415 const ui::Animation* animation) { 470 const ui::Animation* animation) {
416 // We should only be running the animation when the popup is already visible. 471 // We should only be running the animation when the popup is already visible.
417 DCHECK(popup_ != NULL); 472 DCHECK(popup_ != NULL);
418 popup_->SetBounds(GetPopupBounds()); 473 popup_->SetBounds(GetPopupBounds());
474
475 Layout();
419 } 476 }
420 477
421 //////////////////////////////////////////////////////////////////////////////// 478 ////////////////////////////////////////////////////////////////////////////////
422 // AutocompletePopupContentsView, views::View overrides: 479 // AutocompletePopupContentsView, views::View overrides:
423 480
424 void AutocompletePopupContentsView::Layout() { 481 void AutocompletePopupContentsView::Layout() {
425 UpdateBlurRegion(); 482 UpdateBlurRegion();
426 483
427 // Size our children to the available content area. 484 // Size our children to the available content area.
428 LayoutChildren(); 485 LayoutChildren();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); 559 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
503 } 560 }
504 561
505 //////////////////////////////////////////////////////////////////////////////// 562 ////////////////////////////////////////////////////////////////////////////////
506 // AutocompletePopupContentsView, protected: 563 // AutocompletePopupContentsView, protected:
507 564
508 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { 565 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) {
509 canvas->drawColor(AutocompleteResultView::GetColor( 566 canvas->drawColor(AutocompleteResultView::GetColor(
510 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); 567 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND));
511 View::PaintChildren(canvas); 568 View::PaintChildren(canvas);
569
570 // Draw dividing lines between results and keyword views.
571 SkColor divider_color = SkColorSetA(AutocompleteResultView::GetColor(
572 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT),
573 160);
Peter Kasting 2011/08/05 20:45:17 Where did this number come from? The code elsewhe
aaron.randolph 2011/08/05 20:56:58 I saw those but kGlassPopupAlpha is only ~94%, whi
Peter Kasting 2011/08/05 21:02:31 OK, please test glass/opaque as well as high-contr
aaron.randolph 2011/08/05 21:48:21 How about this? // An alpha value to apply to the
574
575 for (size_t i = 0; i < model_->result().size(); ++i) {
576 if (model_->result().match_at(i).associated_keyword.get()) {
577 views::View* child = child_at(i * 2);
578
Peter Kasting 2011/08/05 20:45:17 Nit: Extra newline
579 canvas->FillRectInt(divider_color, child->bounds().right(),
580 child->bounds().y(), LocationBarView::kNormalHorizontalEdgeThickness,
581 child->bounds().height());
582 }
583 }
512 } 584 }
513 585
514 int AutocompletePopupContentsView::CalculatePopupHeight() { 586 int AutocompletePopupContentsView::CalculatePopupHeight() {
515 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); 587 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
516 int popup_height = 0; 588 int popup_height = 0;
517 for (size_t i = 0; i < model_->result().size(); ++i) 589 for (size_t i = 0; i < model_->result().size(); ++i)
518 popup_height += child_at(i)->GetPreferredSize().height(); 590 popup_height += child_at(i)->GetPreferredSize().height();
519 return popup_height + 591 return popup_height +
520 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); 592 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0);
521 } 593 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void AutocompletePopupContentsView::OpenIndex( 710 void AutocompletePopupContentsView::OpenIndex(
639 size_t index, 711 size_t index,
640 WindowOpenDisposition disposition) { 712 WindowOpenDisposition disposition) {
641 if (!HasMatchAt(index)) 713 if (!HasMatchAt(index))
642 return; 714 return;
643 715
644 // OpenMatch() may close the popup, which will clear the result set and, by 716 // 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 717 // extension, |match| and its contents. So copy the relevant match out to
646 // make sure it stays alive until the call completes. 718 // make sure it stays alive until the call completes.
647 AutocompleteMatch match = model_->result().match_at(index); 719 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, 720 omnibox_view_->OpenMatch(match, disposition, GURL(), index,
651 is_keyword_hint ? string16() : keyword); 721 match.keyword);
652 } 722 }
653 723
654 size_t AutocompletePopupContentsView::GetIndexForPoint( 724 size_t AutocompletePopupContentsView::GetIndexForPoint(
655 const gfx::Point& point) { 725 const gfx::Point& point) {
656 if (!HitTest(point)) 726 if (!HitTest(point))
657 return AutocompletePopupModel::kNoMatch; 727 return AutocompletePopupModel::kNoMatch;
658 728
659 int nb_match = model_->result().size(); 729 int nb_match = model_->result().size();
660 DCHECK(nb_match <= child_count()); 730 DCHECK(nb_match <= child_count());
661 for (int i = 0; i < nb_match; ++i) { 731 for (int i = 0; i < nb_match; ++i) {
662 views::View* child = child_at(i); 732 views::View* child = child_at(i * 2);
663 gfx::Point point_in_child_coords(point); 733 gfx::Point point_in_child_coords(point);
664 View::ConvertPointToView(this, child, &point_in_child_coords); 734 View::ConvertPointToView(this, child, &point_in_child_coords);
665 if (child->HitTest(point_in_child_coords)) 735 if (child->HitTest(point_in_child_coords))
666 return i; 736 return i;
667 } 737 }
668 return AutocompletePopupModel::kNoMatch; 738 return AutocompletePopupModel::kNoMatch;
669 } 739 }
670 740
671 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) { 741 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) {
672 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); 742 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds());
(...skipping 23 matching lines...) Expand all
696 opt_in_view_ = NULL; 766 opt_in_view_ = NULL;
697 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 767 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
698 DCHECK(counter); 768 DCHECK(counter);
699 counter->Hide(); 769 counter->Hide();
700 if (opt_in) { 770 if (opt_in) {
701 browser::ShowInstantConfirmDialogIfNecessary( 771 browser::ShowInstantConfirmDialogIfNecessary(
702 location_bar_->GetWidget()->GetNativeWindow(), model_->profile()); 772 location_bar_->GetWidget()->GetNativeWindow(), model_->profile());
703 } 773 }
704 UpdatePopupAppearance(); 774 UpdatePopupAppearance();
705 } 775 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698