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_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
11 #include "content/public/browser/keyboard_listener.h" | 11 #include "content/public/browser/keyboard_listener.h" |
12 #include "ui/gfx/font.h" | 12 #include "ui/gfx/font.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 | 14 |
15 class AutofillPopupDelegate; | 15 class AutofillPopupDelegate; |
16 class AutofillPopupView; | 16 class AutofillPopupView; |
17 | 17 |
| 18 namespace gfx { |
| 19 class Display; |
| 20 } |
| 21 |
18 namespace ui { | 22 namespace ui { |
19 class KeyEvent; | 23 class KeyEvent; |
20 } | 24 } |
21 | 25 |
22 // This class is a controller for an AutofillPopupView. It implements | 26 // This class is a controller for an AutofillPopupView. It implements |
23 // AutofillPopupController to allow calls from AutofillPopupView. The | 27 // AutofillPopupController to allow calls from AutofillPopupView. The |
24 // other, public functions are available to its instantiator. | 28 // other, public functions are available to its instantiator. |
25 class AutofillPopupControllerImpl : public AutofillPopupController, | 29 class AutofillPopupControllerImpl : public AutofillPopupController, |
26 public content::KeyboardListener { | 30 public content::KeyboardListener { |
27 public: | 31 public: |
(...skipping 30 matching lines...) Expand all Loading... |
58 virtual ~AutofillPopupControllerImpl(); | 62 virtual ~AutofillPopupControllerImpl(); |
59 | 63 |
60 // AutofillPopupController implementation. | 64 // AutofillPopupController implementation. |
61 virtual void ViewDestroyed() OVERRIDE; | 65 virtual void ViewDestroyed() OVERRIDE; |
62 virtual void UpdateBoundsAndRedrawPopup() OVERRIDE; | 66 virtual void UpdateBoundsAndRedrawPopup() OVERRIDE; |
63 virtual void MouseHovered(int x, int y) OVERRIDE; | 67 virtual void MouseHovered(int x, int y) OVERRIDE; |
64 virtual void MouseClicked(int x, int y) OVERRIDE; | 68 virtual void MouseClicked(int x, int y) OVERRIDE; |
65 virtual void MouseExitedPopup() OVERRIDE; | 69 virtual void MouseExitedPopup() OVERRIDE; |
66 virtual void AcceptSuggestion(size_t index) OVERRIDE; | 70 virtual void AcceptSuggestion(size_t index) OVERRIDE; |
67 virtual int GetIconResourceID(const string16& resource_name) OVERRIDE; | 71 virtual int GetIconResourceID(const string16& resource_name) OVERRIDE; |
68 virtual bool CanDelete(size_t index) OVERRIDE; | 72 virtual bool CanDelete(size_t index) const OVERRIDE; |
69 #if !defined(OS_ANDROID) | |
70 virtual int GetPopupRequiredWidth() OVERRIDE; | |
71 virtual int GetPopupRequiredHeight() OVERRIDE; | |
72 #endif | |
73 virtual gfx::Rect GetRowBounds(size_t index) OVERRIDE; | 73 virtual gfx::Rect GetRowBounds(size_t index) OVERRIDE; |
74 virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE; | 74 virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE; |
75 virtual const gfx::Rect& popup_bounds() const OVERRIDE; | 75 virtual const gfx::Rect& popup_bounds() const OVERRIDE; |
76 virtual gfx::NativeView container_view() const OVERRIDE; | 76 virtual gfx::NativeView container_view() const OVERRIDE; |
77 virtual const gfx::Rect& element_bounds() const OVERRIDE; | 77 virtual const gfx::Rect& element_bounds() const OVERRIDE; |
78 virtual const std::vector<string16>& names() const OVERRIDE; | 78 virtual const std::vector<string16>& names() const OVERRIDE; |
79 virtual const std::vector<string16>& subtexts() const OVERRIDE; | 79 virtual const std::vector<string16>& subtexts() const OVERRIDE; |
80 virtual const std::vector<string16>& icons() const OVERRIDE; | 80 virtual const std::vector<string16>& icons() const OVERRIDE; |
81 virtual const std::vector<int>& identifiers() const OVERRIDE; | 81 virtual const std::vector<int>& identifiers() const OVERRIDE; |
82 #if !defined(OS_ANDROID) | 82 #if !defined(OS_ANDROID) |
(...skipping 19 matching lines...) Expand all Loading... |
102 // The user has choosen the selected line. | 102 // The user has choosen the selected line. |
103 bool AcceptSelectedLine(); | 103 bool AcceptSelectedLine(); |
104 | 104 |
105 // The user has removed a suggestion. | 105 // The user has removed a suggestion. |
106 bool RemoveSelectedLine(); | 106 bool RemoveSelectedLine(); |
107 | 107 |
108 // Convert a y-coordinate to the closest line. | 108 // Convert a y-coordinate to the closest line. |
109 int LineFromY(int y); | 109 int LineFromY(int y); |
110 | 110 |
111 // Returns the height of a row depending on its type. | 111 // Returns the height of a row depending on its type. |
112 int GetRowHeightFromId(int identifier); | 112 int GetRowHeightFromId(int identifier) const; |
113 | 113 |
114 // Returns true if the given |x| and |y| coordinates refer to a point that | 114 // Returns true if the given |x| and |y| coordinates refer to a point that |
115 // hits the delete icon in the current selected line. | 115 // hits the delete icon in the current selected line. |
116 bool DeleteIconIsUnder(int x, int y); | 116 bool DeleteIconIsUnder(int x, int y); |
117 | 117 |
118 // Returns true if the given id refers to an element that can be accepted. | 118 // Returns true if the given id refers to an element that can be accepted. |
119 bool CanAccept(int id); | 119 bool CanAccept(int id); |
120 | 120 |
121 // Returns true if the popup still has non-options entries to show the user. | 121 // Returns true if the popup still has non-options entries to show the user. |
122 bool HasSuggestions(); | 122 bool HasSuggestions(); |
123 | 123 |
124 AutofillPopupView* view() { return view_; } | 124 AutofillPopupView* view() { return view_; } |
125 | 125 |
126 // |view_| pass throughs (virtual for testing). | 126 // |view_| pass throughs (virtual for testing). |
127 virtual void ShowView(); | 127 virtual void ShowView(); |
128 virtual void InvalidateRow(size_t row); | 128 virtual void InvalidateRow(size_t row); |
129 | 129 |
| 130 // Protected so tests can access. |
| 131 #if !defined(OS_ANDROID) |
| 132 // Calculates the desired width of the popup based on its contents. |
| 133 int GetDesiredPopupWidth() const; |
| 134 |
| 135 // Calculates the desired height of the popup based on its contents. |
| 136 int GetDesiredPopupHeight() const; |
| 137 #endif |
| 138 |
130 private: | 139 private: |
| 140 #if !defined(OS_ANDROID) |
| 141 // Calculate the width of the row, excluding all the text. This provides |
| 142 // the size of the row that won't be reducible (since all the text can be |
| 143 // elided if there isn't enough space). |
| 144 int RowWidthWithoutText(int row) const; |
| 145 |
| 146 // Calculates and sets the bounds of the popup, including placing it properly |
| 147 // to prevent it from going off the screen. |
| 148 void UpdatePopupBounds(); |
| 149 #endif |
| 150 |
| 151 // A helper function to get the display closest to the given point (virtual |
| 152 // for testing). |
| 153 virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const; |
| 154 |
| 155 // Calculates the width of the popup and the x position of it. These values |
| 156 // will stay on the screen. |
| 157 std::pair<int, int> CalculatePopupXAndWidth( |
| 158 const gfx::Display& left_display, |
| 159 const gfx::Display& right_display, |
| 160 int popup_required_width) const; |
| 161 |
| 162 // Calculates the height of the popup and the y position of it. These values |
| 163 // will stay on the screen. |
| 164 std::pair<int, int> CalculatePopupYAndHeight( |
| 165 const gfx::Display& top_display, |
| 166 const gfx::Display& bottom_display, |
| 167 int popup_required_height) const; |
| 168 |
131 AutofillPopupView* view_; // Weak reference. | 169 AutofillPopupView* view_; // Weak reference. |
132 AutofillPopupDelegate* delegate_; // Weak reference. | 170 AutofillPopupDelegate* delegate_; // Weak reference. |
133 gfx::NativeView container_view_; // Weak reference. | 171 gfx::NativeView container_view_; // Weak reference. |
134 | 172 |
135 // The bounds of the text element that is the focus of the Autofill. | 173 // The bounds of the text element that is the focus of the Autofill. |
136 // These coordinates are in screen space. | 174 // These coordinates are in screen space. |
137 const gfx::Rect element_bounds_; | 175 const gfx::Rect element_bounds_; |
138 | 176 |
139 // The bounds of the Autofill popup. | 177 // The bounds of the Autofill popup. |
140 gfx::Rect popup_bounds_; | 178 gfx::Rect popup_bounds_; |
141 | 179 |
142 // The current Autofill query values. | 180 // The current Autofill query values. |
143 std::vector<string16> names_; | 181 std::vector<string16> names_; |
144 std::vector<string16> subtexts_; | 182 std::vector<string16> subtexts_; |
145 std::vector<string16> icons_; | 183 std::vector<string16> icons_; |
146 std::vector<int> identifiers_; | 184 std::vector<int> identifiers_; |
147 | 185 |
| 186 // Since names_ can be elided to ensure that it fits on the screen, we need to |
| 187 // keep an unelided copy of the names to be able to pass to the delegate. |
| 188 std::vector<string16> full_names_; |
| 189 |
148 #if !defined(OS_ANDROID) | 190 #if !defined(OS_ANDROID) |
149 // The fonts for the popup text. | 191 // The fonts for the popup text. |
150 gfx::Font name_font_; | 192 gfx::Font name_font_; |
151 gfx::Font subtext_font_; | 193 gfx::Font subtext_font_; |
152 #endif | 194 #endif |
153 | 195 |
154 // The line that is currently selected by the user. | 196 // The line that is currently selected by the user. |
155 // |kNoSelection| indicates that no line is currently selected. | 197 // |kNoSelection| indicates that no line is currently selected. |
156 int selected_line_; | 198 int selected_line_; |
157 | 199 |
158 // Used to indicate if the delete icon within a row is currently selected. | 200 // Used to indicate if the delete icon within a row is currently selected. |
159 bool delete_icon_hovered_; | 201 bool delete_icon_hovered_; |
160 | 202 |
161 // True if |HideInternal| has already been called. | 203 // True if |HideInternal| has already been called. |
162 bool is_hiding_; | 204 bool is_hiding_; |
163 | 205 |
164 // True if the delegate should be informed when |this| is destroyed. | 206 // True if the delegate should be informed when |this| is destroyed. |
165 bool inform_delegate_of_destruction_; | 207 bool inform_delegate_of_destruction_; |
166 }; | 208 }; |
167 | 209 |
168 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 210 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
OLD | NEW |