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" |
11 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 11 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
13 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 13 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
15 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
19 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/view_targeter.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 #include "ui/views/window/non_client_view.h" | 22 #include "ui/views/window/non_client_view.h" |
22 #include "ui/wm/core/window_animations.h" | 23 #include "ui/wm/core/window_animations.h" |
23 | 24 |
24 // This is the number of pixels in the border image interior to the actual | 25 // This is the number of pixels in the border image interior to the actual |
25 // border. | 26 // border. |
26 const int kBorderInterior = 6; | 27 const int kBorderInterior = 6; |
27 | 28 |
28 class OmniboxPopupContentsView::AutocompletePopupWidget | 29 class OmniboxPopupContentsView::AutocompletePopupWidget |
29 : public views::Widget, | 30 : public views::Widget, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ignore_mouse_drag_(false), | 64 ignore_mouse_drag_(false), |
64 size_animation_(this), | 65 size_animation_(this), |
65 left_margin_(0), | 66 left_margin_(0), |
66 right_margin_(0), | 67 right_margin_(0), |
67 outside_vertical_padding_(0) { | 68 outside_vertical_padding_(0) { |
68 // The contents is owned by the LocationBarView. | 69 // The contents is owned by the LocationBarView. |
69 set_owned_by_client(); | 70 set_owned_by_client(); |
70 | 71 |
71 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider(); | 72 ui::ThemeProvider* theme = location_bar_view_->GetThemeProvider(); |
72 bottom_shadow_ = theme->GetImageSkiaNamed(IDR_BUBBLE_B); | 73 bottom_shadow_ = theme->GetImageSkiaNamed(IDR_BUBBLE_B); |
| 74 |
| 75 SetEventTargeter( |
| 76 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
73 } | 77 } |
74 | 78 |
75 void OmniboxPopupContentsView::Init() { | 79 void OmniboxPopupContentsView::Init() { |
76 // This can't be done in the constructor as at that point we aren't | 80 // This can't be done in the constructor as at that point we aren't |
77 // necessarily our final class yet, and we may have subclasses | 81 // necessarily our final class yet, and we may have subclasses |
78 // overriding CreateResultView. | 82 // overriding CreateResultView. |
79 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { | 83 for (size_t i = 0; i < AutocompleteResult::kMaxMatches; ++i) { |
80 OmniboxResultView* result_view = CreateResultView(i, font_list_); | 84 OmniboxResultView* result_view = CreateResultView(i, font_list_); |
81 result_view->SetVisible(false); | 85 result_view->SetVisible(false); |
82 AddChildViewAt(result_view, static_cast<int>(i)); | 86 AddChildViewAt(result_view, static_cast<int>(i)); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 285 |
282 void OmniboxPopupContentsView::Layout() { | 286 void OmniboxPopupContentsView::Layout() { |
283 // Size our children to the available content area. | 287 // Size our children to the available content area. |
284 LayoutChildren(); | 288 LayoutChildren(); |
285 | 289 |
286 // We need to manually schedule a paint here since we are a layered window and | 290 // We need to manually schedule a paint here since we are a layered window and |
287 // won't implicitly require painting until we ask for one. | 291 // won't implicitly require painting until we ask for one. |
288 SchedulePaint(); | 292 SchedulePaint(); |
289 } | 293 } |
290 | 294 |
291 views::View* OmniboxPopupContentsView::GetEventHandlerForRect( | |
292 const gfx::Rect& rect) { | |
293 return this; | |
294 } | |
295 | |
296 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( | 295 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( |
297 const gfx::Point& point) { | 296 const gfx::Point& point) { |
298 return NULL; | 297 return NULL; |
299 } | 298 } |
300 | 299 |
301 bool OmniboxPopupContentsView::OnMousePressed( | 300 bool OmniboxPopupContentsView::OnMousePressed( |
302 const ui::MouseEvent& event) { | 301 const ui::MouseEvent& event) { |
303 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. | 302 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. |
304 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) | 303 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) |
305 UpdateLineEvent(event, event.IsLeftMouseButton()); | 304 UpdateLineEvent(event, event.IsLeftMouseButton()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 431 } |
433 | 432 |
434 void OmniboxPopupContentsView::PaintChildren(gfx::Canvas* canvas, | 433 void OmniboxPopupContentsView::PaintChildren(gfx::Canvas* canvas, |
435 const views::CullSet& cull_set) { | 434 const views::CullSet& cull_set) { |
436 // We paint our children inside OnPaint(). | 435 // We paint our children inside OnPaint(). |
437 } | 436 } |
438 | 437 |
439 //////////////////////////////////////////////////////////////////////////////// | 438 //////////////////////////////////////////////////////////////////////////////// |
440 // OmniboxPopupContentsView, private: | 439 // OmniboxPopupContentsView, private: |
441 | 440 |
| 441 views::View* OmniboxPopupContentsView::TargetForRect(views::View* root, |
| 442 const gfx::Rect& rect) { |
| 443 CHECK_EQ(root, this); |
| 444 return this; |
| 445 } |
| 446 |
442 bool OmniboxPopupContentsView::HasMatchAt(size_t index) const { | 447 bool OmniboxPopupContentsView::HasMatchAt(size_t index) const { |
443 return index < model_->result().size(); | 448 return index < model_->result().size(); |
444 } | 449 } |
445 | 450 |
446 const AutocompleteMatch& OmniboxPopupContentsView::GetMatchAtIndex( | 451 const AutocompleteMatch& OmniboxPopupContentsView::GetMatchAtIndex( |
447 size_t index) const { | 452 size_t index) const { |
448 return model_->result().match_at(index); | 453 return model_->result().match_at(index); |
449 } | 454 } |
450 | 455 |
451 void OmniboxPopupContentsView::MakeContentsPath( | 456 void OmniboxPopupContentsView::MakeContentsPath( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 size_t index = GetIndexForPoint(event.location()); | 496 size_t index = GetIndexForPoint(event.location()); |
492 if (!HasMatchAt(index)) | 497 if (!HasMatchAt(index)) |
493 return; | 498 return; |
494 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, | 499 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, |
495 GURL(), base::string16(), index); | 500 GURL(), base::string16(), index); |
496 } | 501 } |
497 | 502 |
498 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { | 503 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { |
499 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); | 504 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); |
500 } | 505 } |
OLD | NEW |