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.h" |
16 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
17 | 17 |
18 struct AutocompleteMatch; | 18 struct AutocompleteMatch; |
19 class OmniboxEditModel; | 19 class OmniboxEditModel; |
20 class OmniboxResultView; | 20 class OmniboxResultView; |
21 class OmniboxView; | 21 class OmniboxView; |
| 22 class OmniboxViewDelegate; |
22 class Profile; | 23 class Profile; |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 class BubbleBorder; | 26 class ImageView; |
26 } | 27 } |
27 | 28 |
28 // A view representing the contents of the autocomplete popup. | 29 // A view representing the contents of the autocomplete popup. |
29 class OmniboxPopupContentsView : public views::View, | 30 class OmniboxPopupContentsView : public views::View, |
30 public OmniboxResultViewModel, | 31 public OmniboxResultViewModel, |
31 public OmniboxPopupView, | 32 public OmniboxPopupView, |
32 public ui::AnimationDelegate { | 33 public ui::AnimationDelegate { |
33 public: | 34 public: |
34 // Factory method for creating the AutocompletePopupView. | 35 // Factory method for creating the AutocompletePopupView. |
35 static OmniboxPopupView* Create(const gfx::Font& font, | 36 static OmniboxPopupView* Create(const gfx::Font& font, |
36 OmniboxView* omnibox_view, | 37 OmniboxView* omnibox_view, |
37 OmniboxEditModel* edit_model, | 38 OmniboxEditModel* edit_model, |
38 views::View* location_bar); | 39 OmniboxViewDelegate* view_delegate); |
39 | 40 |
40 // Returns the bounds the popup should be shown at. This is the display bounds | 41 // Returns the bounds the popup should be shown at. This is the display bounds |
41 // and includes offsets for the dropshadow which this view's border renders. | 42 // and includes offsets for the dropshadow which this view's border renders. |
42 gfx::Rect GetPopupBounds() const; | 43 gfx::Rect GetPopupBounds() const; |
43 | 44 |
44 virtual void LayoutChildren(); | 45 virtual void LayoutChildren(); |
45 | 46 |
46 // Overridden from OmniboxPopupView: | 47 // Overridden from OmniboxPopupView: |
47 virtual bool IsOpen() const OVERRIDE; | 48 virtual bool IsOpen() const OVERRIDE; |
48 virtual void InvalidateLine(size_t line) OVERRIDE; | 49 virtual void InvalidateLine(size_t line) OVERRIDE; |
(...skipping 24 matching lines...) Expand all Loading... |
73 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 74 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
74 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 75 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
75 | 76 |
76 // Overridden from ui::EventHandler: | 77 // Overridden from ui::EventHandler: |
77 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 78 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
78 | 79 |
79 protected: | 80 protected: |
80 OmniboxPopupContentsView(const gfx::Font& font, | 81 OmniboxPopupContentsView(const gfx::Font& font, |
81 OmniboxView* omnibox_view, | 82 OmniboxView* omnibox_view, |
82 OmniboxEditModel* edit_model, | 83 OmniboxEditModel* edit_model, |
83 views::View* location_bar); | 84 OmniboxViewDelegate* view_delegate); |
84 virtual ~OmniboxPopupContentsView(); | 85 virtual ~OmniboxPopupContentsView(); |
85 | 86 |
86 views::View* location_bar() { return location_bar_; } | 87 OmniboxViewDelegate* view_delegate() { return view_delegate_; } |
87 | 88 |
88 virtual void PaintResultViews(gfx::Canvas* canvas); | 89 virtual void PaintResultViews(gfx::Canvas* canvas); |
89 | 90 |
90 // Calculates the height needed to show all the results in the model. | 91 // Calculates the height needed to show all the results in the model. |
91 virtual int CalculatePopupHeight(); | 92 virtual int CalculatePopupHeight(); |
92 virtual OmniboxResultView* CreateResultView(OmniboxResultViewModel* model, | 93 virtual OmniboxResultView* CreateResultView(OmniboxResultViewModel* model, |
93 int model_index, | 94 int model_index, |
94 const gfx::Font& font); | 95 const gfx::Font& font); |
95 | 96 |
96 // Overridden from views::View: | 97 // Overridden from views::View: |
(...skipping 15 matching lines...) Expand all Loading... |
112 // Returns true if the model has a match at the specified index. | 113 // Returns true if the model has a match at the specified index. |
113 bool HasMatchAt(size_t index) const; | 114 bool HasMatchAt(size_t index) const; |
114 | 115 |
115 // Returns the match at the specified index within the popup model. | 116 // Returns the match at the specified index within the popup model. |
116 const AutocompleteMatch& GetMatchAtIndex(size_t index) const; | 117 const AutocompleteMatch& GetMatchAtIndex(size_t index) const; |
117 | 118 |
118 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that | 119 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that |
119 // bounds the path. | 120 // bounds the path. |
120 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); | 121 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); |
121 | 122 |
122 // Updates the window's blur region for the current size. | |
123 void UpdateBlurRegion(); | |
124 | |
125 // Makes the contents of the canvas slightly transparent. | |
126 void MakeCanvasTransparent(gfx::Canvas* canvas); | |
127 | |
128 // Called when the line at the specified index should be opened with the | 123 // Called when the line at the specified index should be opened with the |
129 // provided disposition. | 124 // provided disposition. |
130 void OpenIndex(size_t index, WindowOpenDisposition disposition); | 125 void OpenIndex(size_t index, WindowOpenDisposition disposition); |
131 | 126 |
132 // Find the index of the match under the given |point|, specified in window | 127 // Find the index of the match under the given |point|, specified in window |
133 // coordinates. Returns OmniboxPopupModel::kNoMatch if there isn't a match at | 128 // coordinates. Returns OmniboxPopupModel::kNoMatch if there isn't a match at |
134 // the specified point. | 129 // the specified point. |
135 size_t GetIndexForPoint(const gfx::Point& point); | 130 size_t GetIndexForPoint(const gfx::Point& point); |
136 | 131 |
137 // Processes a located event (e.g. mouse/gesture) and sets the selection/hover | 132 // Processes a located event (e.g. mouse/gesture) and sets the selection/hover |
(...skipping 13 matching lines...) Expand all Loading... |
151 | 146 |
152 // The popup that contains this view. We create this, but it deletes itself | 147 // The popup that contains this view. We create this, but it deletes itself |
153 // when its window is destroyed. This is a WeakPtr because it's possible for | 148 // when its window is destroyed. This is a WeakPtr because it's possible for |
154 // the OS to destroy the window and thus delete this object before we're | 149 // the OS to destroy the window and thus delete this object before we're |
155 // deleted, or without our knowledge. | 150 // deleted, or without our knowledge. |
156 base::WeakPtr<AutocompletePopupWidget> popup_; | 151 base::WeakPtr<AutocompletePopupWidget> popup_; |
157 | 152 |
158 // The edit view that invokes us. | 153 // The edit view that invokes us. |
159 OmniboxView* omnibox_view_; | 154 OmniboxView* omnibox_view_; |
160 | 155 |
161 // An object that the popup positions itself against. | 156 OmniboxViewDelegate* view_delegate_; |
162 views::View* location_bar_; | |
163 | |
164 // Our border, which can compute our desired bounds. | |
165 const views::BubbleBorder* bubble_border_; | |
166 | 157 |
167 // The font used for result rows, based on the omnibox font. | 158 // The font used for result rows, based on the omnibox font. |
168 gfx::Font font_; | 159 gfx::Font font_; |
169 | 160 |
170 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have | 161 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have |
171 // a convenient way to release mouse capture. Instead we use this flag to | 162 // a convenient way to release mouse capture. Instead we use this flag to |
172 // simply ignore all remaining drag events, and the eventual mouse release | 163 // simply ignore all remaining drag events, and the eventual mouse release |
173 // event. Since OnDragCanceled() can be called when we're not dragging, this | 164 // event. Since OnDragCanceled() can be called when we're not dragging, this |
174 // flag is reset to false on a mouse pressed event, to make sure we don't | 165 // flag is reset to false on a mouse pressed event, to make sure we don't |
175 // erroneously ignore the next drag. | 166 // erroneously ignore the next drag. |
176 bool ignore_mouse_drag_; | 167 bool ignore_mouse_drag_; |
177 | 168 |
178 // The popup sizes vertically using an animation when the popup is getting | 169 // The popup sizes vertically using an animation when the popup is getting |
179 // shorter (not larger, that makes it look "slow"). | 170 // shorter (not larger, that makes it look "slow"). |
180 ui::SlideAnimation size_animation_; | 171 ui::SlideAnimation size_animation_; |
181 gfx::Rect start_bounds_; | 172 gfx::Rect start_bounds_; |
182 gfx::Rect target_bounds_; | 173 gfx::Rect target_bounds_; |
183 | 174 |
| 175 scoped_ptr<views::ImageView> provider_logo_; |
| 176 int left_margin_; |
| 177 int right_margin_; |
| 178 |
| 179 const gfx::ImageSkia* bottom_shadow_; // Ptr owned by resource bundle. |
| 180 |
| 181 // Amount of extra padding to add to the popup on the top and bottom. |
| 182 int outside_vertical_padding_; |
| 183 |
184 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupContentsView); | 184 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupContentsView); |
185 }; | 185 }; |
186 | 186 |
187 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ | 187 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ |
OLD | NEW |