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 "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
12 #include "chrome/browser/themes/theme_properties.h" | 12 #include "chrome/browser/themes/theme_properties.h" |
13 #include "chrome/browser/ui/layout_constants.h" | 13 #include "chrome/browser/ui/layout_constants.h" |
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
15 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 15 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| 16 #include "chrome/browser/ui/views/theme_copying_widget.h" |
16 #include "components/omnibox/browser/omnibox_view.h" | 17 #include "components/omnibox/browser/omnibox_view.h" |
17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
18 #include "ui/base/material_design/material_design_controller.h" | 19 #include "ui/base/material_design/material_design_controller.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
21 #include "ui/compositor/clip_recorder.h" | 22 #include "ui/compositor/clip_recorder.h" |
22 #include "ui/compositor/paint_recorder.h" | 23 #include "ui/compositor/paint_recorder.h" |
23 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
25 #include "ui/gfx/path.h" | 26 #include "ui/gfx/path.h" |
26 #include "ui/resources/grit/ui_resources.h" | 27 #include "ui/resources/grit/ui_resources.h" |
27 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
28 #include "ui/views/resources/grit/views_resources.h" | 29 #include "ui/views/resources/grit/views_resources.h" |
29 #include "ui/views/view_targeter.h" | 30 #include "ui/views/view_targeter.h" |
30 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
31 #include "ui/views/window/non_client_view.h" | 32 #include "ui/views/window/non_client_view.h" |
32 | 33 |
33 class OmniboxPopupContentsView::AutocompletePopupWidget | 34 class OmniboxPopupContentsView::AutocompletePopupWidget |
34 : public views::Widget, | 35 : public ThemeCopyingWidget, |
35 public base::SupportsWeakPtr<AutocompletePopupWidget> { | 36 public base::SupportsWeakPtr<AutocompletePopupWidget> { |
36 public: | 37 public: |
37 AutocompletePopupWidget() {} | 38 explicit AutocompletePopupWidget(views::Widget* role_model) |
| 39 : ThemeCopyingWidget(role_model) {} |
38 ~AutocompletePopupWidget() override {} | 40 ~AutocompletePopupWidget() override {} |
39 | 41 |
40 private: | 42 private: |
41 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); | 43 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); |
42 }; | 44 }; |
43 | 45 |
44 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
45 // OmniboxPopupContentsView, public: | 47 // OmniboxPopupContentsView, public: |
46 | 48 |
47 OmniboxPopupView* OmniboxPopupContentsView::Create( | 49 OmniboxPopupView* OmniboxPopupContentsView::Create( |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the | 234 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the |
233 // last few pixels to get to one visible result. | 235 // last few pixels to get to one visible result. |
234 if (new_target_bounds.height() != target_bounds_.height()) | 236 if (new_target_bounds.height() != target_bounds_.height()) |
235 size_animation_.Reset(); | 237 size_animation_.Reset(); |
236 target_bounds_ = new_target_bounds; | 238 target_bounds_ = new_target_bounds; |
237 | 239 |
238 if (popup_ == NULL) { | 240 if (popup_ == NULL) { |
239 views::Widget* popup_parent = location_bar_view_->GetWidget(); | 241 views::Widget* popup_parent = location_bar_view_->GetWidget(); |
240 | 242 |
241 // If the popup is currently closed, we need to create it. | 243 // If the popup is currently closed, we need to create it. |
242 popup_ = (new AutocompletePopupWidget)->AsWeakPtr(); | 244 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); |
243 | 245 |
244 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 246 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
245 #if defined(OS_WIN) | 247 #if defined(OS_WIN) |
246 // On Windows use the software compositor to ensure that we don't block | 248 // On Windows use the software compositor to ensure that we don't block |
247 // the UI thread blocking issue during command buffer creation. We can | 249 // the UI thread blocking issue during command buffer creation. We can |
248 // revert this change once http://crbug.com/125248 is fixed. | 250 // revert this change once http://crbug.com/125248 is fixed. |
249 params.force_software_compositing = true; | 251 params.force_software_compositing = true; |
250 #endif | 252 #endif |
251 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 253 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
252 params.parent = popup_parent->GetNativeView(); | 254 params.parent = popup_parent->GetNativeView(); |
253 params.bounds = GetPopupBounds(); | 255 params.bounds = GetPopupBounds(); |
254 params.context = popup_parent->GetNativeWindow(); | 256 params.context = popup_parent->GetNativeWindow(); |
255 params.native_theme = popup_parent->GetNativeTheme(); | |
256 popup_->Init(params); | 257 popup_->Init(params); |
257 // Third-party software such as DigitalPersona identity verification can | 258 // Third-party software such as DigitalPersona identity verification can |
258 // hook the underlying window creation methods and use SendMessage to | 259 // hook the underlying window creation methods and use SendMessage to |
259 // synchronously change focus/activation, resulting in the popup being | 260 // synchronously change focus/activation, resulting in the popup being |
260 // destroyed by the time control returns here. Bail out in this case to | 261 // destroyed by the time control returns here. Bail out in this case to |
261 // avoid a NULL dereference. | 262 // avoid a NULL dereference. |
262 if (!popup_.get()) | 263 if (!popup_.get()) |
263 return; | 264 return; |
264 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 265 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
265 popup_->SetContentsView(this); | 266 popup_->SetContentsView(this); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 size_t index = GetIndexForPoint(event.location()); | 528 size_t index = GetIndexForPoint(event.location()); |
528 if (!HasMatchAt(index)) | 529 if (!HasMatchAt(index)) |
529 return; | 530 return; |
530 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
531 GURL(), base::string16(), index); | 532 GURL(), base::string16(), index); |
532 } | 533 } |
533 | 534 |
534 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
535 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
536 } | 537 } |
OLD | NEW |