Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 (int i = 0; i < child_count(); 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 View* keyword = child_at(i + 1); | |
| 295 if (keyword->IsVisible()) { | |
| 296 DCHECK(keyword->GetClassName() == | |
| 297 AutocompleteResultView::kViewClassName); | |
| 298 AutocompleteResultView* kw_result = | |
| 299 static_cast<AutocompleteResultView*>(keyword); | |
| 300 const int collapsed_width = kw_result->GetCollapsedSize().width() + | |
| 301 LocationBarView::kEdgeItemPadding; | |
| 302 const int kw_collapsed_x = contents_rect.width() - collapsed_width; | |
| 303 const int kw_x = contents_rect.width() - | |
| 304 keyword_animations_[i / 2]->CurrentValueBetween(collapsed_width, | |
| 305 kw_collapsed_x); | |
| 306 | |
| 307 result->SetBounds(contents_rect.x(), top, | |
| 308 kw_x - LocationBarView::kNormalHorizontalEdgeThickness, | |
| 309 result->GetPreferredSize().height()); | |
| 310 keyword->SetBounds(contents_rect.x() + kw_x, top, | |
| 311 contents_rect.width() - kw_x, 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(); |
| 333 child_at(static_cast<int>(line * 2 + 1))->SchedulePaint(); | |
| 334 | |
| 335 if (line == model_->selected_line() && | |
| 336 model_->selected_match() == AutocompletePopupModel::KEYWORD) | |
| 337 keyword_animations_[line]->Show(); | |
| 338 else | |
| 339 keyword_animations_[line]->Hide(); | |
| 295 } | 340 } |
| 296 | 341 |
| 297 void AutocompletePopupContentsView::UpdatePopupAppearance() { | 342 void AutocompletePopupContentsView::UpdatePopupAppearance() { |
| 298 if (model_->result().empty()) { | 343 if (model_->result().empty()) { |
| 299 // No matches, close any existing popup. | 344 // No matches, close any existing popup. |
| 300 if (popup_ != NULL) { | 345 if (popup_ != NULL) { |
| 301 size_animation_.Stop(); | 346 size_animation_.Stop(); |
| 347 | |
| 348 for (SlideAnimations::iterator i(keyword_animations_.begin()); | |
| 349 i != keyword_animations_.end(); ++i) | |
| 350 (*i)->Stop(); | |
| 351 | |
| 302 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack | 352 // 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 | 353 // 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 | 354 // destroying the popup would cause us to read garbage when we unwind back |
| 305 // to that level. | 355 // to that level. |
| 306 popup_->Close(); // This will eventually delete the popup. | 356 popup_->Close(); // This will eventually delete the popup. |
| 307 popup_.reset(); | 357 popup_.reset(); |
| 308 } | 358 } |
| 309 return; | 359 return; |
| 310 } | 360 } |
| 311 | 361 |
| 312 // Update the match cached by each row, in the process of doing so make sure | 362 // Update the match cached by each row, in the process of doing so make sure |
| 313 // we have enough row views. | 363 // we have enough row views. |
| 314 size_t child_rv_count = child_count(); | 364 size_t child_rv_count = child_count(); |
| 315 if (opt_in_view_) { | 365 if (opt_in_view_) { |
| 316 DCHECK(child_rv_count > 0); | 366 DCHECK(child_rv_count > 0); |
| 317 child_rv_count--; | 367 child_rv_count--; |
| 318 } | 368 } |
| 319 for (size_t i = 0; i < model_->result().size(); ++i) { | 369 const size_t result_size = model_->result().size(); |
| 320 AutocompleteResultView* result_view; | 370 for (size_t i = 0; i < result_size; ++i) { |
| 321 if (i >= child_rv_count) { | 371 const AutocompleteMatch& match = GetMatchAtIndex(i); |
| 322 result_view = | 372 DCHECK(child_at(i * 2)->GetClassName() == |
| 323 CreateResultView(this, i, result_font_, result_bold_font_); | 373 AutocompleteResultView::kViewClassName); |
| 324 AddChildViewAt(result_view, static_cast<int>(i)); | 374 AutocompleteResultView* view = static_cast<AutocompleteResultView*>( |
| 325 } else { | 375 child_at(i * 2)); |
| 326 result_view = static_cast<AutocompleteResultView*>(child_at(i)); | 376 view->SetMatch(match); |
| 327 result_view->SetVisible(true); | 377 view->SetVisible(true); |
| 328 } | 378 |
| 329 result_view->SetMatch(GetMatchAtIndex(i)); | 379 DCHECK(child_at(i * 2 + 1)->GetClassName() == |
| 380 AutocompleteResultView::kViewClassName); | |
| 381 view = static_cast<AutocompleteResultView*>(child_at(i * 2 + 1)); | |
| 382 view->SetVisible(match.associated_keyword.get() != NULL); | |
| 383 if (view->IsVisible()) | |
| 384 view->SetMatch(*match.associated_keyword); | |
| 385 | |
| 386 keyword_animations_[i]->Reset(); | |
| 330 } | 387 } |
| 331 for (size_t i = model_->result().size(); i < child_rv_count; ++i) | 388 for (size_t i = result_size * 2; i < child_rv_count; ++i) |
| 332 child_at(i)->SetVisible(false); | 389 child_at(i)->SetVisible(false); |
| 333 | 390 |
| 334 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 391 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 335 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { | 392 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { |
| 336 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); | 393 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); |
| 337 AddChildView(opt_in_view_); | 394 AddChildView(opt_in_view_); |
| 338 } else if (opt_in_view_ && (!counter || | 395 } else if (opt_in_view_ && (!counter || |
| 339 !counter->ShouldShow(base::Time::Now()))) { | 396 !counter->ShouldShow(base::Time::Now()))) { |
| 340 delete opt_in_view_; | 397 delete opt_in_view_; |
| 341 opt_in_view_ = NULL; | 398 opt_in_view_ = NULL; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 368 // Animate the popup shrinking, but don't animate growing larger since that | 425 // Animate the popup shrinking, but don't animate growing larger since that |
| 369 // would make the popup feel less responsive. | 426 // would make the popup feel less responsive. |
| 370 start_bounds_ = GetWidget()->GetWindowScreenBounds(); | 427 start_bounds_ = GetWidget()->GetWindowScreenBounds(); |
| 371 if (target_bounds_.height() < start_bounds_.height()) | 428 if (target_bounds_.height() < start_bounds_.height()) |
| 372 size_animation_.Show(); | 429 size_animation_.Show(); |
| 373 else | 430 else |
| 374 start_bounds_ = target_bounds_; | 431 start_bounds_ = target_bounds_; |
| 375 popup_->SetBounds(GetPopupBounds()); | 432 popup_->SetBounds(GetPopupBounds()); |
| 376 } | 433 } |
| 377 | 434 |
| 378 SchedulePaint(); | 435 Layout(); |
| 379 } | 436 } |
| 380 | 437 |
| 381 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() { | 438 gfx::Rect AutocompletePopupContentsView::GetTargetBounds() { |
| 382 return target_bounds_; | 439 return target_bounds_; |
| 383 } | 440 } |
| 384 | 441 |
| 385 void AutocompletePopupContentsView::PaintUpdatesNow() { | 442 void AutocompletePopupContentsView::PaintUpdatesNow() { |
| 386 // TODO(beng): remove this from the interface. | 443 // TODO(beng): remove this from the interface. |
| 387 } | 444 } |
| 388 | 445 |
| 389 void AutocompletePopupContentsView::OnDragCanceled() { | 446 void AutocompletePopupContentsView::OnDragCanceled() { |
| 390 ignore_mouse_drag_ = true; | 447 ignore_mouse_drag_ = true; |
| 391 } | 448 } |
| 392 | 449 |
| 393 //////////////////////////////////////////////////////////////////////////////// | 450 //////////////////////////////////////////////////////////////////////////////// |
| 394 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation: | 451 // AutocompletePopupContentsView, AutocompleteResultViewModel implementation: |
| 395 | 452 |
| 396 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const { | 453 bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) const { |
| 397 return HasMatchAt(index) ? index == model_->selected_line() : false; | 454 size_t selected_line = model_->selected_line() * 2; |
| 455 | |
| 456 if (model_->selected_match() == AutocompletePopupModel::KEYWORD) | |
| 457 selected_line++; | |
| 458 | |
| 459 return index == selected_line; | |
| 398 } | 460 } |
| 399 | 461 |
| 400 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const { | 462 bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const { |
| 401 return HasMatchAt(index) ? index == model_->hovered_line() : false; | 463 return index == model_->hovered_line() * 2; |
| 402 } | 464 } |
| 403 | 465 |
| 404 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch( | 466 const SkBitmap* AutocompletePopupContentsView::GetIconIfExtensionMatch( |
| 405 size_t index) const { | 467 size_t index) const { |
| 406 if (!HasMatchAt(index)) | 468 if (!HasMatchAt(index)) |
| 407 return NULL; | 469 return NULL; |
| 408 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index)); | 470 return model_->GetIconIfExtensionMatch(GetMatchAtIndex(index)); |
| 409 } | 471 } |
| 410 | 472 |
| 411 //////////////////////////////////////////////////////////////////////////////// | 473 //////////////////////////////////////////////////////////////////////////////// |
| 412 // AutocompletePopupContentsView, AnimationDelegate implementation: | 474 // AutocompletePopupContentsView, AnimationDelegate implementation: |
| 413 | 475 |
| 414 void AutocompletePopupContentsView::AnimationProgressed( | 476 void AutocompletePopupContentsView::AnimationProgressed( |
| 415 const ui::Animation* animation) { | 477 const ui::Animation* animation) { |
| 416 // We should only be running the animation when the popup is already visible. | 478 // We should only be running the animation when the popup is already visible. |
| 417 DCHECK(popup_ != NULL); | 479 DCHECK(popup_ != NULL); |
| 418 popup_->SetBounds(GetPopupBounds()); | 480 popup_->SetBounds(GetPopupBounds()); |
| 481 | |
| 482 Layout(); | |
| 419 } | 483 } |
| 420 | 484 |
| 421 //////////////////////////////////////////////////////////////////////////////// | 485 //////////////////////////////////////////////////////////////////////////////// |
| 422 // AutocompletePopupContentsView, views::View overrides: | 486 // AutocompletePopupContentsView, views::View overrides: |
| 423 | 487 |
| 424 void AutocompletePopupContentsView::Layout() { | 488 void AutocompletePopupContentsView::Layout() { |
| 425 UpdateBlurRegion(); | 489 UpdateBlurRegion(); |
| 426 | 490 |
| 427 // Size our children to the available content area. | 491 // Size our children to the available content area. |
| 428 LayoutChildren(); | 492 LayoutChildren(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); | 566 model_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
| 503 } | 567 } |
| 504 | 568 |
| 505 //////////////////////////////////////////////////////////////////////////////// | 569 //////////////////////////////////////////////////////////////////////////////// |
| 506 // AutocompletePopupContentsView, protected: | 570 // AutocompletePopupContentsView, protected: |
| 507 | 571 |
| 508 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { | 572 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { |
| 509 canvas->drawColor(AutocompleteResultView::GetColor( | 573 canvas->drawColor(AutocompleteResultView::GetColor( |
| 510 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); | 574 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); |
| 511 View::PaintChildren(canvas); | 575 View::PaintChildren(canvas); |
| 576 | |
| 577 // Draw dividing lines between results and keyword views. | |
| 578 SkPaint paint; | |
| 579 paint.setColor(AutocompleteResultView::GetColor( | |
| 580 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT)); | |
| 581 paint.setStrokeWidth(SkIntToScalar(1)); | |
| 582 paint.setAntiAlias(true); | |
| 583 | |
| 584 for (size_t i = 0; i < model_->result().size(); ++i) { | |
| 585 if (model_->result().match_at(i).associated_keyword.get()) { | |
| 586 views::View* child = child_at(i * 2); | |
| 587 gfx::Rect bounds = child->bounds(); | |
| 588 | |
| 589 canvas->drawLine( | |
|
Peter Kasting
2011/08/04 20:07:53
Nit: This won't make a visible difference, but sin
aaron.randolph
2011/08/04 22:32:25
Drawing with a rect makes the line darker and narr
Peter Kasting
2011/08/04 23:13:16
Were you using FillRectInt()? Use that, not DrawR
aaron.randolph
2011/08/05 00:52:26
Yes, I tried FillRectInt first and then various ot
| |
| 590 SkIntToScalar(bounds.right()), | |
| 591 SkIntToScalar(bounds.y() + | |
| 592 LocationBarView::kNormalHorizontalEdgeThickness), | |
|
Peter Kasting
2011/08/04 20:07:53
Nit: It's wrong to use this constant to do vertica
| |
| 593 SkIntToScalar(bounds.right()), | |
| 594 SkIntToScalar(bounds.y() + bounds.height() - | |
| 595 LocationBarView::kNormalHorizontalEdgeThickness * 2), | |
| 596 paint); | |
| 597 } | |
| 598 } | |
| 512 } | 599 } |
| 513 | 600 |
| 514 int AutocompletePopupContentsView::CalculatePopupHeight() { | 601 int AutocompletePopupContentsView::CalculatePopupHeight() { |
| 515 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 602 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 516 int popup_height = 0; | 603 int popup_height = 0; |
| 517 for (size_t i = 0; i < model_->result().size(); ++i) | 604 for (size_t i = 0; i < model_->result().size(); ++i) |
| 518 popup_height += child_at(i)->GetPreferredSize().height(); | 605 popup_height += child_at(i)->GetPreferredSize().height(); |
| 519 return popup_height + | 606 return popup_height + |
| 520 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); | 607 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); |
| 521 } | 608 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 void AutocompletePopupContentsView::OpenIndex( | 725 void AutocompletePopupContentsView::OpenIndex( |
| 639 size_t index, | 726 size_t index, |
| 640 WindowOpenDisposition disposition) { | 727 WindowOpenDisposition disposition) { |
| 641 if (!HasMatchAt(index)) | 728 if (!HasMatchAt(index)) |
| 642 return; | 729 return; |
| 643 | 730 |
| 644 // OpenMatch() may close the popup, which will clear the result set and, by | 731 // 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 | 732 // extension, |match| and its contents. So copy the relevant match out to |
| 646 // make sure it stays alive until the call completes. | 733 // make sure it stays alive until the call completes. |
| 647 AutocompleteMatch match = model_->result().match_at(index); | 734 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, | 735 omnibox_view_->OpenMatch(match, disposition, GURL(), index, |
| 651 is_keyword_hint ? string16() : keyword); | 736 match.keyword); |
| 652 } | 737 } |
| 653 | 738 |
| 654 size_t AutocompletePopupContentsView::GetIndexForPoint( | 739 size_t AutocompletePopupContentsView::GetIndexForPoint( |
| 655 const gfx::Point& point) { | 740 const gfx::Point& point) { |
| 656 if (!HitTest(point)) | 741 if (!HitTest(point)) |
| 657 return AutocompletePopupModel::kNoMatch; | 742 return AutocompletePopupModel::kNoMatch; |
| 658 | 743 |
| 659 int nb_match = model_->result().size(); | 744 int nb_match = model_->result().size(); |
| 660 DCHECK(nb_match <= child_count()); | 745 DCHECK(nb_match <= child_count()); |
| 661 for (int i = 0; i < nb_match; ++i) { | 746 for (int i = 0; i < nb_match; ++i) { |
| 662 views::View* child = child_at(i); | 747 views::View* child = child_at(i * 2); |
| 663 gfx::Point point_in_child_coords(point); | 748 gfx::Point point_in_child_coords(point); |
| 664 View::ConvertPointToView(this, child, &point_in_child_coords); | 749 View::ConvertPointToView(this, child, &point_in_child_coords); |
| 665 if (child->HitTest(point_in_child_coords)) | 750 if (child->HitTest(point_in_child_coords)) |
| 666 return i; | 751 return i; |
| 667 } | 752 } |
| 668 return AutocompletePopupModel::kNoMatch; | 753 return AutocompletePopupModel::kNoMatch; |
| 669 } | 754 } |
| 670 | 755 |
| 671 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) { | 756 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) { |
| 672 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); | 757 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 696 opt_in_view_ = NULL; | 781 opt_in_view_ = NULL; |
| 697 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 782 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
| 698 DCHECK(counter); | 783 DCHECK(counter); |
| 699 counter->Hide(); | 784 counter->Hide(); |
| 700 if (opt_in) { | 785 if (opt_in) { |
| 701 browser::ShowInstantConfirmDialogIfNecessary( | 786 browser::ShowInstantConfirmDialogIfNecessary( |
| 702 location_bar_->GetWidget()->GetNativeWindow(), model_->profile()); | 787 location_bar_->GetWidget()->GetNativeWindow(), model_->profile()); |
| 703 } | 788 } |
| 704 UpdatePopupAppearance(); | 789 UpdatePopupAppearance(); |
| 705 } | 790 } |
| OLD | NEW |