OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_HELPER_H_ | |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_HELPER_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include "base/strings/string16.h" | |
11 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" | |
12 #include "chrome/browser/ui/autofill/popup_view_common.h" | |
13 #include "ui/gfx/geometry/rect.h" | |
14 #include "ui/gfx/native_widget_types.h" | |
15 | |
16 namespace gfx { | |
17 class Display; | |
18 class Point; | |
19 } | |
20 | |
21 namespace ui { | |
22 class KeyEvent; | |
23 } | |
24 | |
25 namespace autofill { | |
26 | |
27 // Helper class which keeps tracks of popup bounds and related view information. | |
28 // TODO(mathp): This should ideally be owned by the view, and not the popup | |
Evan Stade
2016/01/20 04:51:17
this comment is a bit long, I'd leave it at the ge
Mathieu
2016/01/20 17:57:44
Done.
| |
29 // controller. However since the controller interface is being used by both | |
30 // Autofill and the Password Generation popup, some more refactoring is needed | |
31 // in order to move more view-related things from the PopupController to each of | |
32 // the implementer's views. | |
33 class AutofillPopupViewHelper { | |
Evan Stade
2016/01/20 04:51:17
can we call this something like LayoutModel instea
Mathieu
2016/01/20 17:57:44
Sure I like the name
| |
34 public: | |
35 explicit AutofillPopupViewHelper(AutofillPopupViewDelegate* delegate); | |
36 | |
37 // The minimum amount of padding between the Autofill name and subtext, | |
38 // in pixels. | |
39 static const size_t kNamePadding = 15; | |
40 | |
41 // The amount of padding between icons in pixels. | |
42 static const int kIconPadding = 5; | |
43 | |
44 // The amount of padding at the end of the popup in pixels. | |
45 static const int kEndPadding = 3; | |
46 | |
47 #if !defined(OS_ANDROID) | |
48 // Calculates the desired height of the popup based on its contents. | |
49 int GetDesiredPopupHeight() const; | |
50 | |
51 // Calculates the desired width of the popup based on its contents. | |
52 int GetDesiredPopupWidth() const; | |
53 | |
54 // Calculate the width of the row, excluding all the text. This provides | |
55 // the size of the row that won't be reducible (since all the text can be | |
56 // elided if there isn't enough space). |with_label| indicates whether a label | |
57 // is expected to be present. | |
58 int RowWidthWithoutText(int row, bool with_label) const; | |
59 | |
60 // Get the available space for the total text width. |with_label| indicates | |
61 // whether a label is expected to be present. | |
62 int GetAvailableWidthForRow(int row, bool with_label) const; | |
63 | |
64 // Calculates and sets the bounds of the popup, including placing it properly | |
65 // to prevent it from going off the screen. | |
66 void UpdatePopupBounds(); | |
67 #endif | |
68 | |
69 // Convert a y-coordinate to the closest line. | |
70 int LineFromY(int y); | |
Evan Stade
2016/01/20 04:51:17
could this be const?
Mathieu
2016/01/20 17:57:44
Done.
| |
71 | |
72 const gfx::Rect popup_bounds() const { return popup_bounds_; } | |
73 | |
74 // Returns the bounds of the item at |index| in the popup, relative to | |
75 // the top left of the popup. | |
76 gfx::Rect GetRowBounds(size_t index); | |
Evan Stade
2016/01/20 04:51:17
could this be const?
Mathieu
2016/01/20 17:57:44
Done.
| |
77 | |
78 // Gets the resource value for the given resource, returning -1 if the | |
79 // resource isn't recognized. | |
80 int GetIconResourceID(const base::string16& resource_name) const; | |
81 | |
82 private: | |
83 // Returns the enclosing rectangle for the element_bounds. | |
84 const gfx::Rect RoundedElementBounds() const; | |
85 | |
86 // The bounds of the Autofill popup. | |
87 gfx::Rect popup_bounds_; | |
88 | |
89 PopupViewCommon view_common_; | |
90 | |
91 AutofillPopupViewDelegate* delegate_; // Weak reference. | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(AutofillPopupViewHelper); | |
94 }; | |
95 | |
96 } // namespace autofill | |
97 | |
98 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_HELPER_H_ | |
OLD | NEW |