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 "chrome/browser/ui/omnibox/omnibox_popup_non_view.h" | 7 #include "chrome/browser/ui/omnibox/omnibox_popup_non_view.h" |
8 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
10 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 10 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 OmniboxPopupContentsView::OmniboxPopupContentsView( | 83 OmniboxPopupContentsView::OmniboxPopupContentsView( |
84 const gfx::Font& font, | 84 const gfx::Font& font, |
85 OmniboxView* omnibox_view, | 85 OmniboxView* omnibox_view, |
86 OmniboxEditModel* edit_model, | 86 OmniboxEditModel* edit_model, |
87 views::View* location_bar) | 87 views::View* location_bar) |
88 : model_(new OmniboxPopupModel(this, edit_model)), | 88 : model_(new OmniboxPopupModel(this, edit_model)), |
89 omnibox_view_(omnibox_view), | 89 omnibox_view_(omnibox_view), |
90 profile_(edit_model->profile()), | 90 profile_(edit_model->profile()), |
91 location_bar_(location_bar), | 91 location_bar_(location_bar), |
92 result_font_(font.DeriveFont(kEditFontAdjust)), | 92 font_(font.DeriveFont(kEditFontAdjust)), |
93 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), | |
94 ignore_mouse_drag_(false), | 93 ignore_mouse_drag_(false), |
95 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { | 94 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { |
96 // The following little dance is required because set_border() requires a | 95 // The following little dance is required because set_border() requires a |
97 // pointer to a non-const object. | 96 // pointer to a non-const object. |
98 views::BubbleBorder* bubble_border = | 97 views::BubbleBorder* bubble_border = |
99 new views::BubbleBorder(views::BubbleBorder::NONE, | 98 new views::BubbleBorder(views::BubbleBorder::NONE, |
100 views::BubbleBorder::NO_SHADOW); | 99 views::BubbleBorder::NO_SHADOW); |
101 bubble_border_ = bubble_border; | 100 bubble_border_ = bubble_border; |
102 set_border(bubble_border); | 101 set_border(bubble_border); |
103 // The contents is owned by the LocationBarView. | 102 // The contents is owned by the LocationBarView. |
104 set_owned_by_client(); | 103 set_owned_by_client(); |
105 } | 104 } |
106 | 105 |
107 void OmniboxPopupContentsView::Init() { | 106 void OmniboxPopupContentsView::Init() { |
108 // This can't be done in the constructor as at that point we aren't | 107 // This can't be done in the constructor as at that point we aren't |
109 // necessarily our final class yet, and we may have subclasses | 108 // necessarily our final class yet, and we may have subclasses |
110 // overriding CreateResultView. | 109 // overriding CreateResultView. |
111 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 110 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
112 OmniboxResultView* result_view = | 111 OmniboxResultView* result_view = CreateResultView(this, i, font_); |
113 CreateResultView(this, i, result_font_, result_bold_font_); | |
114 result_view->SetVisible(false); | 112 result_view->SetVisible(false); |
115 AddChildViewAt(result_view, static_cast<int>(i)); | 113 AddChildViewAt(result_view, static_cast<int>(i)); |
116 } | 114 } |
117 } | 115 } |
118 | 116 |
119 OmniboxPopupContentsView::~OmniboxPopupContentsView() { | 117 OmniboxPopupContentsView::~OmniboxPopupContentsView() { |
120 // We don't need to do anything with |popup_| here. The OS either has already | 118 // We don't need to do anything with |popup_| here. The OS either has already |
121 // closed the window, in which case it's been deleted, or it will soon, in | 119 // closed the window, in which case it's been deleted, or it will soon, in |
122 // which case there's nothing we need to do. | 120 // which case there's nothing we need to do. |
123 } | 121 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 384 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
387 int popup_height = 0; | 385 int popup_height = 0; |
388 for (size_t i = 0; i < model_->result().size(); ++i) | 386 for (size_t i = 0; i < model_->result().size(); ++i) |
389 popup_height += child_at(i)->GetPreferredSize().height(); | 387 popup_height += child_at(i)->GetPreferredSize().height(); |
390 return popup_height; | 388 return popup_height; |
391 } | 389 } |
392 | 390 |
393 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( | 391 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
394 OmniboxResultViewModel* model, | 392 OmniboxResultViewModel* model, |
395 int model_index, | 393 int model_index, |
396 const gfx::Font& font, | 394 const gfx::Font& font) { |
397 const gfx::Font& bold_font) { | 395 return new OmniboxResultView(model, model_index, font); |
398 return new OmniboxResultView(model, model_index, font, bold_font); | |
399 } | 396 } |
400 | 397 |
401 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
402 // OmniboxPopupContentsView, views::View overrides, protected: | 399 // OmniboxPopupContentsView, views::View overrides, protected: |
403 | 400 |
404 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { | 401 void OmniboxPopupContentsView::OnPaint(gfx::Canvas* canvas) { |
405 gfx::Path path; | 402 gfx::Path path; |
406 MakeContentsPath(&path, GetContentsBounds()); | 403 MakeContentsPath(&path, GetContentsBounds()); |
407 canvas->Save(); | 404 canvas->Save(); |
408 canvas->sk_canvas()->clipPath(path, | 405 canvas->sk_canvas()->clipPath(path, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 void OmniboxPopupContentsView::OpenSelectedLine( | 545 void OmniboxPopupContentsView::OpenSelectedLine( |
549 const ui::LocatedEvent& event, | 546 const ui::LocatedEvent& event, |
550 WindowOpenDisposition disposition) { | 547 WindowOpenDisposition disposition) { |
551 size_t index = GetIndexForPoint(event.location()); | 548 size_t index = GetIndexForPoint(event.location()); |
552 OpenIndex(index, disposition); | 549 OpenIndex(index, disposition); |
553 } | 550 } |
554 | 551 |
555 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 552 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
556 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 553 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
557 } | 554 } |
OLD | NEW |