| 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 #if defined(OS_WIN) | |
| 8 #include <commctrl.h> | |
| 9 #include <dwmapi.h> | |
| 10 #include <objidl.h> | |
| 11 #endif | |
| 12 | |
| 13 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 14 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 16 #include "chrome/browser/instant/instant_confirm_dialog.h" | 10 #include "chrome/browser/instant/instant_confirm_dialog.h" |
| 17 #include "chrome/browser/instant/promo_counter.h" | 11 #include "chrome/browser/instant/promo_counter.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 13 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 20 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" | 14 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view.h" |
| 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 22 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 25 #include "third_party/skia/include/core/SkShader.h" | 19 #include "third_party/skia/include/core/SkShader.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
| 29 #include "ui/gfx/canvas_skia.h" | 23 #include "ui/gfx/canvas_skia.h" |
| 30 #include "ui/gfx/insets.h" | 24 #include "ui/gfx/insets.h" |
| 31 #include "ui/gfx/path.h" | 25 #include "ui/gfx/path.h" |
| 32 #include "unicode/ubidi.h" | 26 #include "unicode/ubidi.h" |
| 33 #include "views/bubble/bubble_border.h" | 27 #include "views/bubble/bubble_border.h" |
| 34 #include "views/controls/button/text_button.h" | 28 #include "views/controls/button/text_button.h" |
| 35 #include "views/controls/label.h" | 29 #include "views/controls/label.h" |
| 36 #include "views/layout/grid_layout.h" | 30 #include "views/layout/grid_layout.h" |
| 37 #include "views/layout/layout_constants.h" | 31 #include "views/layout/layout_constants.h" |
| 38 #include "views/painter.h" | 32 #include "views/painter.h" |
| 39 #include "views/widget/widget.h" | 33 #include "views/widget/widget.h" |
| 40 | 34 |
| 41 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 36 #include <commctrl.h> |
| 37 #include <dwmapi.h> |
| 38 #include <objidl.h> |
| 39 |
| 42 #include "base/win/scoped_gdi_object.h" | 40 #include "base/win/scoped_gdi_object.h" |
| 43 #if !defined(USE_AURA) | 41 #if !defined(USE_AURA) |
| 44 #include "views/widget/native_widget_win.h" | 42 #include "views/widget/native_widget_win.h" |
| 45 #endif | 43 #endif |
| 46 #endif | 44 #endif |
| 47 | 45 |
| 48 #if defined(TOOLKIT_USES_GTK) | 46 #if defined(TOOLKIT_USES_GTK) |
| 49 #include "ui/gfx/skia_utils_gtk.h" | 47 #include "ui/gfx/skia_utils_gtk.h" |
| 50 #endif | 48 #endif |
| 51 | 49 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } // namespace | 141 } // namespace |
| 144 | 142 |
| 145 class AutocompletePopupContentsView::AutocompletePopupWidget | 143 class AutocompletePopupContentsView::AutocompletePopupWidget |
| 146 : public views::Widget, | 144 : public views::Widget, |
| 147 public base::SupportsWeakPtr<AutocompletePopupWidget> { | 145 public base::SupportsWeakPtr<AutocompletePopupWidget> { |
| 148 public: | 146 public: |
| 149 AutocompletePopupWidget() {} | 147 AutocompletePopupWidget() {} |
| 150 virtual ~AutocompletePopupWidget() {} | 148 virtual ~AutocompletePopupWidget() {} |
| 151 | 149 |
| 152 private: | 150 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); | 151 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); |
| 154 }; | 152 }; |
| 155 | 153 |
| 156 class AutocompletePopupContentsView::InstantOptInView | 154 class AutocompletePopupContentsView::InstantOptInView |
| 157 : public views::View, | 155 : public views::View, |
| 158 public views::ButtonListener { | 156 public views::ButtonListener { |
| 159 public: | 157 public: |
| 160 InstantOptInView(AutocompletePopupContentsView* contents_view, | 158 InstantOptInView(AutocompletePopupContentsView* contents_view, |
| 161 const gfx::Font& label_font, | 159 const gfx::Font& label_font, |
| 162 const gfx::Font& button_font) | 160 const gfx::Font& button_font) |
| 163 : contents_view_(contents_view), | 161 : contents_view_(contents_view), |
| 164 bg_painter_(views::Painter::CreateVerticalGradient( | 162 bg_painter_(views::Painter::CreateVerticalGradient( |
| 165 SkColorSetRGB(255, 242, 183), | 163 SkColorSetRGB(255, 242, 183), |
| 166 SkColorSetRGB(250, 230, 145))) { | 164 SkColorSetRGB(250, 230, 145))) { |
| 167 views::Label* label = new views::Label( | 165 views::Label* label = new views::Label( |
| 168 l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_LABEL)); | 166 UTF16ToWide(l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_LABEL))); |
| 169 label->SetFont(label_font); | 167 label->SetFont(label_font); |
| 170 | 168 |
| 171 views::GridLayout* layout = new views::GridLayout(this); | 169 views::GridLayout* layout = new views::GridLayout(this); |
| 172 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding, | 170 layout->SetInsets(kOptInTopPadding, kOptInLeftPadding, |
| 173 kOptInBottomPadding, kOptInRightPadding); | 171 kOptInBottomPadding, kOptInRightPadding); |
| 174 SetLayoutManager(layout); | 172 SetLayoutManager(layout); |
| 175 | 173 |
| 176 const int first_column_set = 1; | 174 const int first_column_set = 1; |
| 177 views::GridLayout::Alignment v_align = views::GridLayout::CENTER; | 175 views::GridLayout::Alignment v_align = views::GridLayout::CENTER; |
| 178 views::ColumnSet* column_set = layout->AddColumnSet(first_column_set); | 176 views::ColumnSet* column_set = layout->AddColumnSet(first_column_set); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 206 width() - kOptInBackgroundHInset * 2, | 204 width() - kOptInBackgroundHInset * 2, |
| 207 height() - kOptInBackgroundVInset * 2); | 205 height() - kOptInBackgroundVInset * 2); |
| 208 canvas->Restore(); | 206 canvas->Restore(); |
| 209 } | 207 } |
| 210 | 208 |
| 211 private: | 209 private: |
| 212 // Creates and returns a button configured for the opt-in promo. | 210 // Creates and returns a button configured for the opt-in promo. |
| 213 views::View* CreateButton(int id, const gfx::Font& font) { | 211 views::View* CreateButton(int id, const gfx::Font& font) { |
| 214 // NOTE: we can't use NativeButton as the popup is a layered window and | 212 // NOTE: we can't use NativeButton as the popup is a layered window and |
| 215 // native buttons don't draw in layered windows. | 213 // native buttons don't draw in layered windows. |
| 216 // TODO(sky): these buttons look crap. Figure out the right | 214 // TODO: these buttons look crap. Figure out the right border/background to |
| 217 // border/background to use. | 215 // use. |
| 218 views::TextButton* button = | 216 views::TextButton* button = |
| 219 new views::TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(id))); | 217 new views::TextButton(this, UTF16ToWide(l10n_util::GetStringUTF16(id))); |
| 220 button->set_border(new OptInButtonBorder()); | 218 button->set_border(new OptInButtonBorder()); |
| 221 button->set_tag(id); | 219 button->set_tag(id); |
| 222 button->SetFont(font); | 220 button->SetFont(font); |
| 223 button->set_animate_on_state_change(false); | 221 button->set_animate_on_state_change(false); |
| 224 return button; | 222 return button; |
| 225 } | 223 } |
| 226 | 224 |
| 227 AutocompletePopupContentsView* contents_view_; | 225 AutocompletePopupContentsView* contents_view_; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 popup_->Close(); // This will eventually delete the popup. | 313 popup_->Close(); // This will eventually delete the popup. |
| 316 popup_.reset(); | 314 popup_.reset(); |
| 317 } | 315 } |
| 318 return; | 316 return; |
| 319 } | 317 } |
| 320 | 318 |
| 321 // Update the match cached by each row, in the process of doing so make sure | 319 // Update the match cached by each row, in the process of doing so make sure |
| 322 // we have enough row views. | 320 // we have enough row views. |
| 323 size_t child_rv_count = child_count(); | 321 size_t child_rv_count = child_count(); |
| 324 if (opt_in_view_) { | 322 if (opt_in_view_) { |
| 325 DCHECK_GT(child_rv_count, 0u); | 323 DCHECK(child_rv_count > 0); |
| 326 child_rv_count--; | 324 child_rv_count--; |
| 327 } | 325 } |
| 328 for (size_t i = 0; i < model_->result().size(); ++i) { | 326 for (size_t i = 0; i < model_->result().size(); ++i) { |
| 329 AutocompleteResultView* result_view; | 327 AutocompleteResultView* result_view; |
| 330 if (i >= child_rv_count) { | 328 if (i >= child_rv_count) { |
| 331 result_view = | 329 result_view = |
| 332 CreateResultView(this, i, result_font_, result_bold_font_); | 330 CreateResultView(this, i, result_font_, result_bold_font_); |
| 333 AddChildViewAt(result_view, static_cast<int>(i)); | 331 AddChildViewAt(result_view, static_cast<int>(i)); |
| 334 } else { | 332 } else { |
| 335 result_view = static_cast<AutocompleteResultView*>(child_at(i)); | 333 result_view = static_cast<AutocompleteResultView*>(child_at(i)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 params.transparent = true; | 366 params.transparent = true; |
| 369 params.parent_widget = location_bar_->GetWidget(); | 367 params.parent_widget = location_bar_->GetWidget(); |
| 370 params.bounds = GetPopupBounds(); | 368 params.bounds = GetPopupBounds(); |
| 371 popup_->Init(params); | 369 popup_->Init(params); |
| 372 popup_->SetContentsView(this); | 370 popup_->SetContentsView(this); |
| 373 popup_->MoveAbove( | 371 popup_->MoveAbove( |
| 374 GetRelativeWindowForPopup(omnibox_view_->GetNativeView())); | 372 GetRelativeWindowForPopup(omnibox_view_->GetNativeView())); |
| 375 if (!popup_.get()) { | 373 if (!popup_.get()) { |
| 376 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose | 374 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose |
| 377 // focus, thereby closing (and destroying) the popup. | 375 // focus, thereby closing (and destroying) the popup. |
| 378 // TODO(sky): this won't be needed once we close the omnibox on input | 376 // TODO: this won't be needed once we close the omnibox on input window |
| 379 // window showing. | 377 // showing. |
| 380 return; | 378 return; |
| 381 } | 379 } |
| 382 popup_->Show(); | 380 popup_->Show(); |
| 383 } else { | 381 } else { |
| 384 // Animate the popup shrinking, but don't animate growing larger since that | 382 // Animate the popup shrinking, but don't animate growing larger since that |
| 385 // would make the popup feel less responsive. | 383 // would make the popup feel less responsive. |
| 386 start_bounds_ = GetWidget()->GetWindowScreenBounds(); | 384 start_bounds_ = GetWidget()->GetWindowScreenBounds(); |
| 387 if (target_bounds_.height() < start_bounds_.height()) | 385 if (target_bounds_.height() < start_bounds_.height()) |
| 388 size_animation_.Show(); | 386 size_animation_.Show(); |
| 389 else | 387 else |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 opt_in_view_ = NULL; | 710 opt_in_view_ = NULL; |
| 713 PromoCounter* counter = profile_->GetInstantPromoCounter(); | 711 PromoCounter* counter = profile_->GetInstantPromoCounter(); |
| 714 DCHECK(counter); | 712 DCHECK(counter); |
| 715 counter->Hide(); | 713 counter->Hide(); |
| 716 if (opt_in) { | 714 if (opt_in) { |
| 717 browser::ShowInstantConfirmDialogIfNecessary( | 715 browser::ShowInstantConfirmDialogIfNecessary( |
| 718 location_bar_->GetWidget()->GetNativeWindow(), profile_); | 716 location_bar_->GetWidget()->GetNativeWindow(), profile_); |
| 719 } | 717 } |
| 720 UpdatePopupAppearance(); | 718 UpdatePopupAppearance(); |
| 721 } | 719 } |
| OLD | NEW |