| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 break; | 363 break; |
| 364 default: | 364 default: |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 event->SetHandled(); | 367 event->SetHandled(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 //////////////////////////////////////////////////////////////////////////////// | 370 //////////////////////////////////////////////////////////////////////////////// |
| 371 // OmniboxPopupContentsView, protected: | 371 // OmniboxPopupContentsView, protected: |
| 372 | 372 |
| 373 void OmniboxPopupContentsView::PaintResultViews(gfx::Canvas* canvas) { | |
| 374 canvas->DrawColor(result_view_at(0)->GetColor( | |
| 375 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND)); | |
| 376 View::PaintChildren(canvas, views::CullSet()); | |
| 377 } | |
| 378 | |
| 379 int OmniboxPopupContentsView::CalculatePopupHeight() { | 373 int OmniboxPopupContentsView::CalculatePopupHeight() { |
| 380 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 374 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 381 int popup_height = 0; | 375 int popup_height = 0; |
| 382 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; | 376 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; |
| 383 i < model_->result().size(); ++i) | 377 i < model_->result().size(); ++i) |
| 384 popup_height += child_at(i)->GetPreferredSize().height(); | 378 popup_height += child_at(i)->GetPreferredSize().height(); |
| 385 | 379 |
| 386 // Add enough space on the top and bottom so it looks like there is the same | 380 // 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 | 381 // amount of space between the text and the popup border as there is in the |
| 388 // interior between each row of text. | 382 // interior between each row of text. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 402 } | 396 } |
| 403 | 397 |
| 404 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
| 405 // OmniboxPopupContentsView, views::View overrides, private: | 399 // OmniboxPopupContentsView, views::View overrides, private: |
| 406 | 400 |
| 407 const char* OmniboxPopupContentsView::GetClassName() const { | 401 const char* OmniboxPopupContentsView::GetClassName() const { |
| 408 return "OmniboxPopupContentsView"; | 402 return "OmniboxPopupContentsView"; |
| 409 } | 403 } |
| 410 | 404 |
| 411 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { | 405 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
| 412 gfx::Rect contents_bounds = GetContentsBounds(); | |
| 413 contents_bounds.set_height( | |
| 414 contents_bounds.height() - bottom_shadow_->height() + kBorderInterior); | |
| 415 | |
| 416 gfx::Path path; | |
| 417 MakeContentsPath(&path, contents_bounds); | |
| 418 canvas->Save(); | |
| 419 canvas->sk_canvas()->clipPath(path, | |
| 420 SkRegion::kIntersect_Op, | |
| 421 true /* doAntialias */); | |
| 422 PaintResultViews(canvas); | |
| 423 canvas->Restore(); | |
| 424 | |
| 425 // Top border. | 406 // Top border. |
| 426 canvas->FillRect( | 407 canvas->FillRect( |
| 427 gfx::Rect(0, 0, width(), views::NonClientFrameView::kClientEdgeThickness), | 408 gfx::Rect(0, 0, width(), views::NonClientFrameView::kClientEdgeThickness), |
| 428 ThemeProperties::GetDefaultColor( | 409 ThemeProperties::GetDefaultColor( |
| 429 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); | 410 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); |
| 430 | 411 |
| 431 // Bottom border. | 412 // Bottom border. |
| 432 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), | 413 canvas->TileImageInt(*bottom_shadow_, 0, height() - bottom_shadow_->height(), |
| 433 width(), bottom_shadow_->height()); | 414 width(), bottom_shadow_->height()); |
| 434 } | 415 } |
| 435 | 416 |
| 436 void OmniboxPopupContentsView::PaintChildren(gfx::Canvas* canvas, | 417 void OmniboxPopupContentsView::PaintChildren(gfx::Canvas* canvas, |
| 437 const views::CullSet& cull_set) { | 418 const views::CullSet& cull_set) { |
| 438 // We paint our children inside OnPaint(). | 419 gfx::Rect contents_bounds = GetContentsBounds(); |
| 420 contents_bounds.Inset(0, views::NonClientFrameView::kClientEdgeThickness, 0, |
| 421 bottom_shadow_->height() - kBorderInterior); |
| 422 |
| 423 canvas->Save(); |
| 424 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(contents_bounds), |
| 425 SkRegion::kIntersect_Op, |
| 426 true /* doAntialias */); |
| 427 canvas->DrawColor(result_view_at(0)->GetColor(OmniboxResultView::NORMAL, |
| 428 OmniboxResultView::BACKGROUND)); |
| 429 View::PaintChildren(canvas, cull_set); |
| 430 canvas->Restore(); |
| 439 } | 431 } |
| 440 | 432 |
| 441 //////////////////////////////////////////////////////////////////////////////// | 433 //////////////////////////////////////////////////////////////////////////////// |
| 442 // OmniboxPopupContentsView, private: | 434 // OmniboxPopupContentsView, private: |
| 443 | 435 |
| 444 views::View* OmniboxPopupContentsView::TargetForRect(views::View* root, | 436 views::View* OmniboxPopupContentsView::TargetForRect(views::View* root, |
| 445 const gfx::Rect& rect) { | 437 const gfx::Rect& rect) { |
| 446 CHECK_EQ(root, this); | 438 CHECK_EQ(root, this); |
| 447 return this; | 439 return this; |
| 448 } | 440 } |
| 449 | 441 |
| 450 bool OmniboxPopupContentsView::HasMatchAt(size_t index) const { | 442 bool OmniboxPopupContentsView::HasMatchAt(size_t index) const { |
| 451 return index < model_->result().size(); | 443 return index < model_->result().size(); |
| 452 } | 444 } |
| 453 | 445 |
| 454 const AutocompleteMatch& OmniboxPopupContentsView::GetMatchAtIndex( | 446 const AutocompleteMatch& OmniboxPopupContentsView::GetMatchAtIndex( |
| 455 size_t index) const { | 447 size_t index) const { |
| 456 return model_->result().match_at(index); | 448 return model_->result().match_at(index); |
| 457 } | 449 } |
| 458 | 450 |
| 459 void OmniboxPopupContentsView::MakeContentsPath( | |
| 460 gfx::Path* path, | |
| 461 const gfx::Rect& bounding_rect) { | |
| 462 SkRect rect; | |
| 463 rect.set(SkIntToScalar(bounding_rect.x()), | |
| 464 SkIntToScalar(bounding_rect.y()), | |
| 465 SkIntToScalar(bounding_rect.right()), | |
| 466 SkIntToScalar(bounding_rect.bottom())); | |
| 467 path->addRect(rect); | |
| 468 } | |
| 469 | |
| 470 size_t OmniboxPopupContentsView::GetIndexForPoint( | 451 size_t OmniboxPopupContentsView::GetIndexForPoint( |
| 471 const gfx::Point& point) { | 452 const gfx::Point& point) { |
| 472 if (!HitTestPoint(point)) | 453 if (!HitTestPoint(point)) |
| 473 return OmniboxPopupModel::kNoMatch; | 454 return OmniboxPopupModel::kNoMatch; |
| 474 | 455 |
| 475 int nb_match = model_->result().size(); | 456 int nb_match = model_->result().size(); |
| 476 DCHECK(nb_match <= child_count()); | 457 DCHECK(nb_match <= child_count()); |
| 477 for (int i = 0; i < nb_match; ++i) { | 458 for (int i = 0; i < nb_match; ++i) { |
| 478 views::View* child = child_at(i); | 459 views::View* child = child_at(i); |
| 479 gfx::Point point_in_child_coords(point); | 460 gfx::Point point_in_child_coords(point); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 499 size_t index = GetIndexForPoint(event.location()); | 480 size_t index = GetIndexForPoint(event.location()); |
| 500 if (!HasMatchAt(index)) | 481 if (!HasMatchAt(index)) |
| 501 return; | 482 return; |
| 502 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 483 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 503 GURL(), base::string16(), index); | 484 GURL(), base::string16(), index); |
| 504 } | 485 } |
| 505 | 486 |
| 506 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 487 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 507 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 488 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 508 } | 489 } |
| OLD | NEW |