Chromium Code Reviews| 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_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 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_utils.h" | |
| 13 #include "ui/gfx/geometry/rect.h" | |
| 10 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
| 11 | 15 |
| 12 namespace gfx { | 16 namespace gfx { |
| 13 class Rect; | 17 class Display; |
| 18 class Point; | |
| 14 } | 19 } |
| 15 | 20 |
| 16 namespace ui { | 21 namespace ui { |
| 17 class KeyEvent; | 22 class KeyEvent; |
| 18 } | 23 } |
| 19 | 24 |
| 20 namespace autofill { | 25 namespace autofill { |
| 21 | 26 |
| 22 class AutofillPopupController; | 27 class AutofillPopupController; |
| 23 | 28 |
| 24 // The interface for creating and controlling a platform-dependent | 29 // The interface for creating and controlling a platform-dependent |
| 25 // AutofillPopupView. | 30 // AutofillPopupView. |
| 26 class AutofillPopupView { | 31 class AutofillPopupView { |
| 27 public: | 32 public: |
| 33 explicit AutofillPopupView(AutofillPopupViewDelegate* delegate); | |
| 34 virtual ~AutofillPopupView() {} | |
| 35 | |
| 28 // The minimum amount of padding between the Autofill name and subtext, | 36 // The minimum amount of padding between the Autofill name and subtext, |
| 29 // in pixels. | 37 // in pixels. |
| 30 static const size_t kNamePadding = 15; | 38 static const size_t kNamePadding = 15; |
| 31 | 39 |
| 32 // The amount of padding between icons in pixels. | 40 // The amount of padding between icons in pixels. |
| 33 static const int kIconPadding = 5; | 41 static const int kIconPadding = 5; |
| 34 | 42 |
| 35 // The amount of padding at the end of the popup in pixels. | 43 // The amount of padding at the end of the popup in pixels. |
| 36 static const int kEndPadding = 3; | 44 static const int kEndPadding = 3; |
| 37 | 45 |
| 38 // Height of the delete icon in pixels. | 46 // Height of the delete icon in pixels. |
| 39 static const int kDeleteIconHeight = 16; | 47 static const int kDeleteIconHeight = 16; |
| 40 | 48 |
| 41 // Width of the delete icon in pixels. | 49 // Width of the delete icon in pixels. |
| 42 static const int kDeleteIconWidth = 16; | 50 static const int kDeleteIconWidth = 16; |
| 43 | 51 |
| 44 // Displays the Autofill popup and fills it in with data from the controller. | 52 // Displays the Autofill popup and fills it in with data from the controller. |
| 45 virtual void Show() = 0; | 53 virtual void Show() = 0; |
| 46 | 54 |
| 47 // Hides the popup from view. This will cause the popup to be deleted. | 55 // Hides the popup from view. This will cause the popup to be deleted. |
| 48 virtual void Hide() = 0; | 56 virtual void Hide() = 0; |
| 49 | 57 |
| 50 // Invalidates the given row and redraw it. | 58 // Invalidates the given row and redraw it. |
| 51 virtual void InvalidateRow(size_t row) = 0; | 59 virtual void InvalidateRow(size_t row) = 0; |
| 52 | 60 |
| 53 // Refreshes the position of the popup. | 61 // Refreshes the position of the popup. |
| 54 virtual void UpdateBoundsAndRedrawPopup() = 0; | 62 virtual void UpdateBoundsAndRedrawPopup() = 0; |
| 55 | 63 |
| 64 #if !defined(OS_ANDROID) | |
| 65 // Calculates the desired height of the popup based on its contents. | |
| 66 int GetDesiredPopupHeight() const; | |
|
Evan Stade
2016/01/09 00:19:02
This design uses multiple inheritance, which is no
Mathieu
2016/01/09 00:53:17
In your mind, would AutofillPopupViewViews extend
| |
| 67 | |
| 68 // Calculates the desired width of the popup based on its contents. | |
| 69 int GetDesiredPopupWidth() const; | |
| 70 | |
| 71 // Calculate the width of the row, excluding all the text. This provides | |
| 72 // the size of the row that won't be reducible (since all the text can be | |
| 73 // elided if there isn't enough space). |with_label| indicates whether a label | |
| 74 // is expected to be present. | |
| 75 int RowWidthWithoutText(int row, bool with_label) const; | |
| 76 | |
| 77 // Get the available space for the total text width. |with_label| indicates | |
| 78 // whether a label is expected to be present. | |
| 79 int GetAvailableWidthForRow(int row, bool with_label) const; | |
| 80 | |
| 81 // Calculates and sets the bounds of the popup, including placing it properly | |
| 82 // to prevent it from going off the screen. | |
| 83 void UpdatePopupBounds(); | |
| 84 #endif | |
| 85 | |
| 86 // Convert a y-coordinate to the closest line. | |
| 87 int LineFromY(int y); | |
| 88 | |
| 89 const gfx::Rect popup_bounds() { return popup_bounds_; } | |
| 90 | |
| 56 // Factory function for creating the view. | 91 // Factory function for creating the view. |
| 57 static AutofillPopupView* Create(AutofillPopupController* controller); | 92 static AutofillPopupView* Create(AutofillPopupController* controller); |
| 58 | 93 |
| 59 protected: | 94 protected: |
| 60 virtual ~AutofillPopupView() {} | 95 // Returns the bounds of the item at |index| in the popup, relative to |
| 96 // the top left of the popup. | |
| 97 gfx::Rect GetRowBounds(size_t index); | |
| 98 | |
| 99 // Returns the bounds that the popup should be placed at, given the desired | |
| 100 // width and height. By default this places the popup below |element_bounds| | |
| 101 // but it will be placed above if there isn't enough space. | |
| 102 gfx::Rect GetPopupBounds(int desired_width, int desired_height) const; | |
| 103 | |
| 104 // Gets the resource value for the given resource, returning -1 if the | |
| 105 // resource isn't recognized. | |
| 106 int GetIconResourceID(const base::string16& resource_name) const; | |
| 107 | |
| 108 AutofillPopupViewDelegate* delegate_; // Weak reference. | |
| 109 | |
| 110 private: | |
| 111 // Returns the enclosing rectangle for the element_bounds. | |
| 112 const gfx::Rect RoundedElementBounds() const; | |
| 113 | |
| 114 // The bounds of the Autofill popup. | |
| 115 gfx::Rect popup_bounds_; | |
| 116 | |
| 117 autofill::view_utils::PopupViewUtils view_utils_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(AutofillPopupView); | |
| 61 }; | 120 }; |
| 62 | 121 |
| 63 } // namespace autofill | 122 } // namespace autofill |
| 64 | 123 |
| 65 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_H_ | 124 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_H_ |
| OLD | NEW |