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 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 9 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
10 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 10 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
11 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h" | 11 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h" |
12 #include "ui/base/animation/animation_delegate.h" | 12 #include "ui/base/animation/animation_delegate.h" |
13 #include "ui/base/animation/slide_animation.h" | 13 #include "ui/base/animation/slide_animation.h" |
14 #include "ui/base/window_open_disposition.h" | 14 #include "ui/base/window_open_disposition.h" |
15 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font_list.h" |
16 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
17 | 17 |
18 struct AutocompleteMatch; | 18 struct AutocompleteMatch; |
19 class LocationBarView; | 19 class LocationBarView; |
20 class OmniboxEditModel; | 20 class OmniboxEditModel; |
21 class OmniboxResultView; | 21 class OmniboxResultView; |
22 class OmniboxView; | 22 class OmniboxView; |
23 class Profile; | 23 class Profile; |
24 | 24 |
25 // A view representing the contents of the autocomplete popup. | 25 // A view representing the contents of the autocomplete popup. |
26 class OmniboxPopupContentsView : public views::View, | 26 class OmniboxPopupContentsView : public views::View, |
27 public OmniboxResultViewModel, | 27 public OmniboxResultViewModel, |
28 public OmniboxPopupView, | 28 public OmniboxPopupView, |
29 public ui::AnimationDelegate { | 29 public ui::AnimationDelegate { |
30 public: | 30 public: |
31 // Factory method for creating the AutocompletePopupView. | 31 // Factory method for creating the AutocompletePopupView. |
32 static OmniboxPopupView* Create(const gfx::Font& font, | 32 static OmniboxPopupView* Create(const gfx::FontList& font_list, |
33 OmniboxView* omnibox_view, | 33 OmniboxView* omnibox_view, |
34 OmniboxEditModel* edit_model, | 34 OmniboxEditModel* edit_model, |
35 LocationBarView* location_bar_view); | 35 LocationBarView* location_bar_view); |
36 | 36 |
37 // Returns the bounds the popup should be shown at. This is the display bounds | 37 // Returns the bounds the popup should be shown at. This is the display bounds |
38 // and includes offsets for the dropshadow which this view's border renders. | 38 // and includes offsets for the dropshadow which this view's border renders. |
39 gfx::Rect GetPopupBounds() const; | 39 gfx::Rect GetPopupBounds() const; |
40 | 40 |
41 virtual void LayoutChildren(); | 41 virtual void LayoutChildren(); |
42 | 42 |
(...skipping 24 matching lines...) Expand all Loading... |
67 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 67 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
68 virtual void OnMouseCaptureLost() OVERRIDE; | 68 virtual void OnMouseCaptureLost() OVERRIDE; |
69 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; | 69 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; |
70 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 70 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
71 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 71 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
72 | 72 |
73 // Overridden from ui::EventHandler: | 73 // Overridden from ui::EventHandler: |
74 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 74 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
75 | 75 |
76 protected: | 76 protected: |
77 OmniboxPopupContentsView(const gfx::Font& font, | 77 OmniboxPopupContentsView(const gfx::FontList& font_list, |
78 OmniboxView* omnibox_view, | 78 OmniboxView* omnibox_view, |
79 OmniboxEditModel* edit_model, | 79 OmniboxEditModel* edit_model, |
80 LocationBarView* location_bar_view); | 80 LocationBarView* location_bar_view); |
81 virtual ~OmniboxPopupContentsView(); | 81 virtual ~OmniboxPopupContentsView(); |
82 | 82 |
83 LocationBarView* location_bar_view() { return location_bar_view_; } | 83 LocationBarView* location_bar_view() { return location_bar_view_; } |
84 | 84 |
85 virtual void PaintResultViews(gfx::Canvas* canvas); | 85 virtual void PaintResultViews(gfx::Canvas* canvas); |
86 | 86 |
87 // Calculates the height needed to show all the results in the model. | 87 // Calculates the height needed to show all the results in the model. |
88 virtual int CalculatePopupHeight(); | 88 virtual int CalculatePopupHeight(); |
89 virtual OmniboxResultView* CreateResultView(OmniboxResultViewModel* model, | 89 virtual OmniboxResultView* CreateResultView(OmniboxResultViewModel* model, |
90 int model_index, | 90 int model_index, |
91 const gfx::Font& font); | 91 const gfx::FontList& font_list); |
92 | 92 |
93 // Overridden from views::View: | 93 // Overridden from views::View: |
94 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 94 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
95 // This method should not be triggered directly as we paint our children | 95 // This method should not be triggered directly as we paint our children |
96 // in an un-conventional way inside OnPaint. We use a separate canvas to | 96 // in an un-conventional way inside OnPaint. We use a separate canvas to |
97 // paint the children. Hence we override this method to a no-op so that | 97 // paint the children. Hence we override this method to a no-op so that |
98 // the view hierarchy does not "accidentally" trigger this. | 98 // the view hierarchy does not "accidentally" trigger this. |
99 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 99 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
100 | 100 |
101 scoped_ptr<OmniboxPopupModel> model_; | 101 scoped_ptr<OmniboxPopupModel> model_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // when its window is destroyed. This is a WeakPtr because it's possible for | 137 // when its window is destroyed. This is a WeakPtr because it's possible for |
138 // the OS to destroy the window and thus delete this object before we're | 138 // the OS to destroy the window and thus delete this object before we're |
139 // deleted, or without our knowledge. | 139 // deleted, or without our knowledge. |
140 base::WeakPtr<AutocompletePopupWidget> popup_; | 140 base::WeakPtr<AutocompletePopupWidget> popup_; |
141 | 141 |
142 // The edit view that invokes us. | 142 // The edit view that invokes us. |
143 OmniboxView* omnibox_view_; | 143 OmniboxView* omnibox_view_; |
144 | 144 |
145 LocationBarView* location_bar_view_; | 145 LocationBarView* location_bar_view_; |
146 | 146 |
147 // The font used for result rows, based on the omnibox font. | 147 // The font list used for result rows, based on the omnibox font list. |
148 gfx::Font font_; | 148 gfx::FontList font_list_; |
149 | 149 |
150 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have | 150 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have |
151 // a convenient way to release mouse capture. Instead we use this flag to | 151 // a convenient way to release mouse capture. Instead we use this flag to |
152 // simply ignore all remaining drag events, and the eventual mouse release | 152 // simply ignore all remaining drag events, and the eventual mouse release |
153 // event. Since OnDragCanceled() can be called when we're not dragging, this | 153 // event. Since OnDragCanceled() can be called when we're not dragging, this |
154 // flag is reset to false on a mouse pressed event, to make sure we don't | 154 // flag is reset to false on a mouse pressed event, to make sure we don't |
155 // erroneously ignore the next drag. | 155 // erroneously ignore the next drag. |
156 bool ignore_mouse_drag_; | 156 bool ignore_mouse_drag_; |
157 | 157 |
158 // The popup sizes vertically using an animation when the popup is getting | 158 // The popup sizes vertically using an animation when the popup is getting |
159 // shorter (not larger, that makes it look "slow"). | 159 // shorter (not larger, that makes it look "slow"). |
160 ui::SlideAnimation size_animation_; | 160 ui::SlideAnimation size_animation_; |
161 gfx::Rect start_bounds_; | 161 gfx::Rect start_bounds_; |
162 gfx::Rect target_bounds_; | 162 gfx::Rect target_bounds_; |
163 | 163 |
164 int left_margin_; | 164 int left_margin_; |
165 int right_margin_; | 165 int right_margin_; |
166 | 166 |
167 const gfx::ImageSkia* bottom_shadow_; // Ptr owned by resource bundle. | 167 const gfx::ImageSkia* bottom_shadow_; // Ptr owned by resource bundle. |
168 | 168 |
169 // Amount of extra padding to add to the popup on the top and bottom. | 169 // Amount of extra padding to add to the popup on the top and bottom. |
170 int outside_vertical_padding_; | 170 int outside_vertical_padding_; |
171 | 171 |
172 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupContentsView); | 172 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupContentsView); |
173 }; | 173 }; |
174 | 174 |
175 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ | 175 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ |
OLD | NEW |