| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 OmniboxView* omnibox_view, | 60 OmniboxView* omnibox_view, |
| 61 OmniboxEditModel* edit_model, | 61 OmniboxEditModel* edit_model, |
| 62 LocationBarView* location_bar_view) | 62 LocationBarView* location_bar_view) |
| 63 : model_(new OmniboxPopupModel(this, edit_model)), | 63 : model_(new OmniboxPopupModel(this, edit_model)), |
| 64 omnibox_view_(omnibox_view), | 64 omnibox_view_(omnibox_view), |
| 65 location_bar_view_(location_bar_view), | 65 location_bar_view_(location_bar_view), |
| 66 font_list_(font_list), | 66 font_list_(font_list), |
| 67 ignore_mouse_drag_(false), | 67 ignore_mouse_drag_(false), |
| 68 size_animation_(this), | 68 size_animation_(this), |
| 69 left_margin_(0), | 69 left_margin_(0), |
| 70 right_margin_(0), | 70 right_margin_(0) { |
| 71 outside_vertical_padding_(0) { | |
| 72 // The contents is owned by the LocationBarView. | 71 // The contents is owned by the LocationBarView. |
| 73 set_owned_by_client(); | 72 set_owned_by_client(); |
| 74 | 73 |
| 75 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider(); | 74 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider(); |
| 76 bottom_shadow_ = theme->GetImageSkiaNamed(IDR_BUBBLE_B); | 75 bottom_shadow_ = theme->GetImageSkiaNamed(IDR_BUBBLE_B); |
| 77 | 76 |
| 78 SetEventTargeter( | 77 SetEventTargeter( |
| 79 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 78 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 80 } | 79 } |
| 81 | 80 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 108 int current_height_delta = static_cast<int>( | 107 int current_height_delta = static_cast<int>( |
| 109 size_animation_.GetCurrentValue() * total_height_delta - 0.5); | 108 size_animation_.GetCurrentValue() * total_height_delta - 0.5); |
| 110 current_frame_bounds.set_height( | 109 current_frame_bounds.set_height( |
| 111 current_frame_bounds.height() + current_height_delta); | 110 current_frame_bounds.height() + current_height_delta); |
| 112 return current_frame_bounds; | 111 return current_frame_bounds; |
| 113 } | 112 } |
| 114 | 113 |
| 115 void OmniboxPopupContentsView::LayoutChildren() { | 114 void OmniboxPopupContentsView::LayoutChildren() { |
| 116 gfx::Rect contents_rect = GetContentsBounds(); | 115 gfx::Rect contents_rect = GetContentsBounds(); |
| 117 | 116 |
| 118 contents_rect.Inset(left_margin_, | 117 contents_rect.Inset( |
| 119 views::NonClientFrameView::kClientEdgeThickness + | 118 left_margin_, views::NonClientFrameView::kClientEdgeThickness + |
| 120 outside_vertical_padding_, | 119 OmniboxResultView::kMinimumTextVerticalPadding, |
| 121 right_margin_, outside_vertical_padding_); | 120 right_margin_, OmniboxResultView::kMinimumTextVerticalPadding); |
| 122 int top = contents_rect.y(); | 121 int top = contents_rect.y(); |
| 123 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 122 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| 124 View* v = child_at(i); | 123 View* v = child_at(i); |
| 125 if (v->visible()) { | 124 if (v->visible()) { |
| 126 v->SetBounds(contents_rect.x(), top, contents_rect.width(), | 125 v->SetBounds(contents_rect.x(), top, contents_rect.width(), |
| 127 v->GetPreferredSize().height()); | 126 v->GetPreferredSize().height()); |
| 128 top = v->bounds().bottom(); | 127 top = v->bounds().bottom(); |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 } | 130 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); | 380 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); |
| 382 int popup_height = 0; | 381 int popup_height = 0; |
| 383 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; | 382 for (size_t i = model_->result().ShouldHideTopMatch() ? 1 : 0; |
| 384 i < model_->result().size(); ++i) | 383 i < model_->result().size(); ++i) |
| 385 popup_height += child_at(i)->GetPreferredSize().height(); | 384 popup_height += child_at(i)->GetPreferredSize().height(); |
| 386 | 385 |
| 387 // Add enough space on the top and bottom so it looks like there is the same | 386 // Add enough space on the top and bottom so it looks like there is the same |
| 388 // amount of space between the text and the popup border as there is in the | 387 // amount of space between the text and the popup border as there is in the |
| 389 // interior between each row of text. | 388 // interior between each row of text. |
| 390 // | 389 // |
| 391 // Discovering the exact amount of leading and padding around the font is | 390 // The * 2 accounts for vertical padding used at the top and bottom. |
| 392 // a bit tricky and platform-specific, but this computation seems to work in | |
| 393 // practice. | |
| 394 OmniboxResultView* result_view = result_view_at(0); | |
| 395 outside_vertical_padding_ = | |
| 396 (result_view->GetPreferredSize().height() - | |
| 397 result_view->GetTextHeight()); | |
| 398 | |
| 399 return popup_height + | 391 return popup_height + |
| 400 views::NonClientFrameView::kClientEdgeThickness + // Top border. | 392 views::NonClientFrameView::kClientEdgeThickness + // Top border. |
| 401 outside_vertical_padding_ * 2 + // Padding. | 393 OmniboxResultView::kMinimumTextVerticalPadding * 2 + // Padding. |
| 402 bottom_shadow_->height() - kBorderInterior; // Bottom border. | 394 bottom_shadow_->height() - kBorderInterior; // Bottom border. |
| 403 } | 395 } |
| 404 | 396 |
| 405 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( | 397 OmniboxResultView* OmniboxPopupContentsView::CreateResultView( |
| 406 int model_index, | 398 int model_index, |
| 407 const gfx::FontList& font_list) { | 399 const gfx::FontList& font_list) { |
| 408 return new OmniboxResultView(this, model_index, location_bar_view_, | 400 return new OmniboxResultView(this, model_index, location_bar_view_, |
| 409 font_list); | 401 font_list); |
| 410 } | 402 } |
| 411 | 403 |
| 412 //////////////////////////////////////////////////////////////////////////////// | 404 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 size_t index = GetIndexForPoint(event.location()); | 499 size_t index = GetIndexForPoint(event.location()); |
| 508 if (!HasMatchAt(index)) | 500 if (!HasMatchAt(index)) |
| 509 return; | 501 return; |
| 510 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 502 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
| 511 GURL(), base::string16(), index); | 503 GURL(), base::string16(), index); |
| 512 } | 504 } |
| 513 | 505 |
| 514 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 506 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
| 515 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 507 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
| 516 } | 508 } |
| OLD | NEW |