OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ |
6 #define CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ | 6 #define CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ |
7 | 7 |
8 #include "app/gfx/font.h" | 8 #include "app/gfx/font.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #include "chrome/browser/autocomplete/autocomplete.h" | 10 #include "chrome/browser/autocomplete/autocomplete.h" |
11 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 11 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
(...skipping 14 matching lines...) Expand all Loading... |
26 | 26 |
27 // An interface implemented by an object that provides data to populate | 27 // An interface implemented by an object that provides data to populate |
28 // individual result views. | 28 // individual result views. |
29 class AutocompleteResultViewModel { | 29 class AutocompleteResultViewModel { |
30 public: | 30 public: |
31 // Returns true if the index is selected. | 31 // Returns true if the index is selected. |
32 virtual bool IsSelectedIndex(size_t index) const = 0; | 32 virtual bool IsSelectedIndex(size_t index) const = 0; |
33 | 33 |
34 // Returns true if the index is hovered. | 34 // Returns true if the index is hovered. |
35 virtual bool IsHoveredIndex(size_t index) const = 0; | 35 virtual bool IsHoveredIndex(size_t index) const = 0; |
36 | |
37 // Called when the line at the specified index should be opened with the | |
38 // provided disposition. | |
39 virtual void OpenIndex(size_t index, WindowOpenDisposition disposition) = 0; | |
40 | |
41 // Called when the line at the specified index should be shown as hovered. | |
42 virtual void SetHoveredLine(size_t index) = 0; | |
43 | |
44 // Called when the line at the specified index should be shown as selected. | |
45 virtual void SetSelectedLine(size_t index, bool revert_to_default) = 0; | |
46 }; | 36 }; |
47 | 37 |
48 // A view representing the contents of the autocomplete popup. | 38 // A view representing the contents of the autocomplete popup. |
49 class AutocompletePopupContentsView : public views::View, | 39 class AutocompletePopupContentsView : public views::View, |
50 public AutocompleteResultViewModel, | 40 public AutocompleteResultViewModel, |
51 public AutocompletePopupView, | 41 public AutocompletePopupView, |
52 public AnimationDelegate { | 42 public AnimationDelegate { |
53 public: | 43 public: |
54 AutocompletePopupContentsView(const gfx::Font& font, | 44 AutocompletePopupContentsView(const gfx::Font& font, |
55 AutocompleteEditView* edit_view, | 45 AutocompleteEditView* edit_view, |
56 AutocompleteEditModel* edit_model, | 46 AutocompleteEditModel* edit_model, |
57 Profile* profile, | 47 Profile* profile, |
58 const BubblePositioner* bubble_positioner); | 48 const BubblePositioner* bubble_positioner); |
59 virtual ~AutocompletePopupContentsView() {} | 49 virtual ~AutocompletePopupContentsView() {} |
60 | 50 |
61 // Returns the bounds the popup should be shown at. This is the display bounds | 51 // Returns the bounds the popup should be shown at. This is the display bounds |
62 // and includes offsets for the dropshadow which this view's border renders. | 52 // and includes offsets for the dropshadow which this view's border renders. |
63 gfx::Rect GetPopupBounds() const; | 53 gfx::Rect GetPopupBounds() const; |
64 | 54 |
65 // Overridden from AutocompletePopupView: | 55 // Overridden from AutocompletePopupView: |
66 virtual bool IsOpen() const; | 56 virtual bool IsOpen() const; |
67 virtual void InvalidateLine(size_t line); | 57 virtual void InvalidateLine(size_t line); |
68 virtual void UpdatePopupAppearance(); | 58 virtual void UpdatePopupAppearance(); |
69 virtual void PaintUpdatesNow(); | 59 virtual void PaintUpdatesNow(); |
70 virtual AutocompletePopupModel* GetModel(); | 60 virtual AutocompletePopupModel* GetModel(); |
71 | 61 |
72 // Overridden from AutocompleteResultViewModel: | 62 // Overridden from AutocompleteResultViewModel: |
73 virtual bool IsSelectedIndex(size_t index) const; | 63 virtual bool IsSelectedIndex(size_t index) const; |
74 virtual bool IsHoveredIndex(size_t index) const; | 64 virtual bool IsHoveredIndex(size_t index) const; |
75 virtual void OpenIndex(size_t index, WindowOpenDisposition disposition); | |
76 virtual void SetHoveredLine(size_t index); | |
77 virtual void SetSelectedLine(size_t index, bool revert_to_default); | |
78 | 65 |
79 // Overridden from AnimationDelegate: | 66 // Overridden from AnimationDelegate: |
80 virtual void AnimationProgressed(const Animation* animation); | 67 virtual void AnimationProgressed(const Animation* animation); |
81 | 68 |
82 // Overridden from views::View: | 69 // Overridden from views::View: |
83 virtual void Paint(gfx::Canvas* canvas); | 70 virtual void Paint(gfx::Canvas* canvas); |
84 virtual void PaintChildren(gfx::Canvas* canvas) { | 71 virtual void PaintChildren(gfx::Canvas* canvas) { |
85 // We paint our children inside Paint(). | 72 // We paint our children inside Paint(). |
86 } | 73 } |
87 virtual void Layout(); | 74 virtual void Layout(); |
| 75 virtual void OnMouseEntered(const views::MouseEvent& event); |
| 76 virtual void OnMouseMoved(const views::MouseEvent& event); |
| 77 virtual void OnMouseExited(const views::MouseEvent& event); |
| 78 virtual bool OnMousePressed(const views::MouseEvent& event); |
| 79 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); |
| 80 virtual bool OnMouseDragged(const views::MouseEvent& event); |
| 81 virtual views::View* GetViewForPoint(const gfx::Point& point); |
88 | 82 |
89 private: | 83 private: |
90 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
91 typedef AutocompletePopupWin AutocompletePopupClass; | 85 typedef AutocompletePopupWin AutocompletePopupClass; |
92 #else | 86 #else |
93 typedef AutocompletePopupGtk AutocompletePopupClass; | 87 typedef AutocompletePopupGtk AutocompletePopupClass; |
94 #endif | 88 #endif |
95 | 89 |
96 // Returns true if the model has a match at the specified index. | 90 // Returns true if the model has a match at the specified index. |
97 bool HasMatchAt(size_t index) const; | 91 bool HasMatchAt(size_t index) const; |
98 | 92 |
99 // Returns the match at the specified index within the popup model. | 93 // Returns the match at the specified index within the popup model. |
100 const AutocompleteMatch& GetMatchAtIndex(size_t index) const; | 94 const AutocompleteMatch& GetMatchAtIndex(size_t index) const; |
101 | 95 |
102 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that | 96 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that |
103 // bounds the path. | 97 // bounds the path. |
104 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); | 98 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); |
105 | 99 |
106 // Updates the window's blur region for the current size. | 100 // Updates the window's blur region for the current size. |
107 void UpdateBlurRegion(); | 101 void UpdateBlurRegion(); |
108 | 102 |
109 // Makes the contents of the canvas slightly transparent. | 103 // Makes the contents of the canvas slightly transparent. |
110 void MakeCanvasTransparent(gfx::Canvas* canvas); | 104 void MakeCanvasTransparent(gfx::Canvas* canvas); |
111 | 105 |
| 106 // Called when the line at the specified index should be opened with the |
| 107 // provided disposition. |
| 108 void OpenIndex(size_t index, WindowOpenDisposition disposition); |
| 109 |
| 110 // Find the index of the match under the given |point|, specified in window |
| 111 // coordinates. |
| 112 int GetIndexForPoint(const gfx::Point& point); |
| 113 |
112 // The popup that contains this view. | 114 // The popup that contains this view. |
113 scoped_ptr<AutocompletePopupClass> popup_; | 115 scoped_ptr<AutocompletePopupClass> popup_; |
114 | 116 |
115 // The provider of our result set. | 117 // The provider of our result set. |
116 scoped_ptr<AutocompletePopupModel> model_; | 118 scoped_ptr<AutocompletePopupModel> model_; |
117 | 119 |
118 // The edit view that invokes us. | 120 // The edit view that invokes us. |
119 AutocompleteEditView* edit_view_; | 121 AutocompleteEditView* edit_view_; |
120 | 122 |
121 // An object that tells the popup how to position itself. | 123 // An object that tells the popup how to position itself. |
122 const BubblePositioner* bubble_positioner_; | 124 const BubblePositioner* bubble_positioner_; |
123 | 125 |
124 // Our border, which can compute our desired bounds. | 126 // Our border, which can compute our desired bounds. |
125 const BubbleBorder* bubble_border_; | 127 const BubbleBorder* bubble_border_; |
126 | 128 |
127 // The font that we should use for result rows. This is based on the font used | 129 // The font that we should use for result rows. This is based on the font used |
128 // by the edit that created us. | 130 // by the edit that created us. |
129 gfx::Font result_font_; | 131 gfx::Font result_font_; |
130 | 132 |
131 // The popup sizes vertically using an animation when the popup is getting | 133 // The popup sizes vertically using an animation when the popup is getting |
132 // shorter (not larger, that makes it look "slow"). | 134 // shorter (not larger, that makes it look "slow"). |
133 SlideAnimation size_animation_; | 135 SlideAnimation size_animation_; |
134 gfx::Rect start_bounds_; | 136 gfx::Rect start_bounds_; |
135 gfx::Rect target_bounds_; | 137 gfx::Rect target_bounds_; |
136 | 138 |
137 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupContentsView); | 139 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupContentsView); |
138 }; | 140 }; |
139 | 141 |
140 #endif // CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ | 142 #endif // CHROME_BROWSER_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ |
OLD | NEW |