| 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/autocomplete/autocomplete_popup_contents_view.
h" | 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <commctrl.h> | 8 #include <commctrl.h> |
| 9 #include <dwmapi.h> | 9 #include <dwmapi.h> |
| 10 #include <objidl.h> | 10 #include <objidl.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/themes/theme_service.h" | 17 #include "chrome/browser/themes/theme_service.h" |
| 18 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 18 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 19 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" | 19 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" |
| 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 21 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents
_view.h" |
| 21 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 24 #include "third_party/skia/include/core/SkShader.h" | 25 #include "third_party/skia/include/core/SkShader.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/layout.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/base/theme_provider.h" | 29 #include "ui/base/theme_provider.h" |
| 28 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/insets.h" | 31 #include "ui/gfx/insets.h" |
| 30 #include "ui/gfx/path.h" | 32 #include "ui/gfx/path.h" |
| 31 #include "ui/views/bubble/bubble_border.h" | 33 #include "ui/views/bubble/bubble_border.h" |
| 32 #include "ui/views/controls/button/text_button.h" | 34 #include "ui/views/controls/button/text_button.h" |
| 33 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" |
| 35 #include "ui/views/layout/layout_constants.h" | 37 #include "ui/views/layout/layout_constants.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 AutocompletePopupWidget() {} | 72 AutocompletePopupWidget() {} |
| 71 virtual ~AutocompletePopupWidget() {} | 73 virtual ~AutocompletePopupWidget() {} |
| 72 | 74 |
| 73 private: | 75 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); | 76 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 78 // AutocompletePopupContentsView, public: | 80 // AutocompletePopupContentsView, public: |
| 79 | 81 |
| 82 AutocompletePopupContentsView* |
| 83 AutocompletePopupContentsView::CreateForEnvironment( |
| 84 const gfx::Font& font, |
| 85 OmniboxView* omnibox_view, |
| 86 AutocompleteEditModel* edit_model, |
| 87 views::View* location_bar) { |
| 88 AutocompletePopupContentsView* view = NULL; |
| 89 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { |
| 90 view = new TouchAutocompletePopupContentsView( |
| 91 font, omnibox_view, edit_model, location_bar); |
| 92 } else { |
| 93 view = new AutocompletePopupContentsView( |
| 94 font, omnibox_view, edit_model, location_bar); |
| 95 } |
| 96 |
| 97 view->Init(); |
| 98 return view; |
| 99 } |
| 100 |
| 80 AutocompletePopupContentsView::AutocompletePopupContentsView( | 101 AutocompletePopupContentsView::AutocompletePopupContentsView( |
| 81 const gfx::Font& font, | 102 const gfx::Font& font, |
| 82 OmniboxView* omnibox_view, | 103 OmniboxView* omnibox_view, |
| 83 AutocompleteEditModel* edit_model, | 104 AutocompleteEditModel* edit_model, |
| 84 views::View* location_bar) | 105 views::View* location_bar) |
| 85 : model_(new AutocompletePopupModel(this, edit_model)), | 106 : model_(new AutocompletePopupModel(this, edit_model)), |
| 86 omnibox_view_(omnibox_view), | 107 omnibox_view_(omnibox_view), |
| 87 profile_(edit_model->profile()), | 108 profile_(edit_model->profile()), |
| 88 location_bar_(location_bar), | 109 location_bar_(location_bar), |
| 89 result_font_(font.DeriveFont(kEditFontAdjust)), | 110 result_font_(font.DeriveFont(kEditFontAdjust)), |
| 90 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), | 111 result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)), |
| 91 ignore_mouse_drag_(false), | 112 ignore_mouse_drag_(false), |
| 92 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { | 113 ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { |
| 93 // The following little dance is required because set_border() requires a | 114 // The following little dance is required because set_border() requires a |
| 94 // pointer to a non-const object. | 115 // pointer to a non-const object. |
| 95 views::BubbleBorder* bubble_border = | 116 views::BubbleBorder* bubble_border = |
| 96 new views::BubbleBorder(views::BubbleBorder::NONE, | 117 new views::BubbleBorder(views::BubbleBorder::NONE, |
| 97 views::BubbleBorder::NO_SHADOW); | 118 views::BubbleBorder::NO_SHADOW); |
| 98 bubble_border_ = bubble_border; | 119 bubble_border_ = bubble_border; |
| 99 set_border(bubble_border); | 120 set_border(bubble_border); |
| 100 // The contents is owned by the LocationBarView. | 121 // The contents is owned by the LocationBarView. |
| 101 set_owned_by_client(); | 122 set_owned_by_client(); |
| 123 } |
| 102 | 124 |
| 125 void AutocompletePopupContentsView::Init() { |
| 126 // This can't be done in the constructor as at that point we aren't |
| 127 // necessarily our final class yet, and we may have subclasses |
| 128 // overriding CreateResultView. |
| 103 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 129 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
| 104 AutocompleteResultView* result_view = | 130 AutocompleteResultView* result_view = |
| 105 CreateResultView(this, i, result_font_, result_bold_font_); | 131 CreateResultView(this, i, result_font_, result_bold_font_); |
| 106 result_view->SetVisible(false); | 132 result_view->SetVisible(false); |
| 107 AddChildViewAt(result_view, static_cast<int>(i)); | 133 AddChildViewAt(result_view, static_cast<int>(i)); |
| 108 } | 134 } |
| 109 } | 135 } |
| 110 | 136 |
| 111 AutocompletePopupContentsView::~AutocompletePopupContentsView() { | 137 AutocompletePopupContentsView::~AutocompletePopupContentsView() { |
| 112 // We don't need to do anything with |popup_| here. The OS either has already | 138 // We don't need to do anything with |popup_| here. The OS either has already |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 // bubble appear at the same height as the Star bubble. | 540 // bubble appear at the same height as the Star bubble. |
| 515 location_bar_bounds.Inset(LocationBarView::kNormalHorizontalEdgeThickness, | 541 location_bar_bounds.Inset(LocationBarView::kNormalHorizontalEdgeThickness, |
| 516 0); | 542 0); |
| 517 } | 543 } |
| 518 gfx::Point location_bar_origin(location_bar_bounds.origin()); | 544 gfx::Point location_bar_origin(location_bar_bounds.origin()); |
| 519 views::View::ConvertPointToScreen(location_bar_, &location_bar_origin); | 545 views::View::ConvertPointToScreen(location_bar_, &location_bar_origin); |
| 520 location_bar_bounds.set_origin(location_bar_origin); | 546 location_bar_bounds.set_origin(location_bar_origin); |
| 521 return bubble_border_->GetBounds( | 547 return bubble_border_->GetBounds( |
| 522 location_bar_bounds, gfx::Size(location_bar_bounds.width(), h)); | 548 location_bar_bounds, gfx::Size(location_bar_bounds.width(), h)); |
| 523 } | 549 } |
| OLD | NEW |