Chromium Code Reviews| 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_utils.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 class AutofillPopupViewHelper { | |
|
Ilya Sherman
2016/01/11 21:06:45
nit: "helper" is a pretty vague name. How does th
| |
| 29 public: | |
| 30 explicit AutofillPopupViewHelper(AutofillPopupViewDelegate* delegate); | |
| 31 | |
| 32 #if !defined(OS_ANDROID) | |
| 33 // Calculates the desired height of the popup based on its contents. | |
| 34 int GetDesiredPopupHeight() const; | |
| 35 | |
| 36 // Calculates the desired width of the popup based on its contents. | |
| 37 int GetDesiredPopupWidth() const; | |
| 38 | |
| 39 // Calculate the width of the row, excluding all the text. This provides | |
| 40 // the size of the row that won't be reducible (since all the text can be | |
| 41 // elided if there isn't enough space). |with_label| indicates whether a label | |
| 42 // is expected to be present. | |
| 43 int RowWidthWithoutText(int row, bool with_label) const; | |
| 44 | |
| 45 // Get the available space for the total text width. |with_label| indicates | |
| 46 // whether a label is expected to be present. | |
| 47 int GetAvailableWidthForRow(int row, bool with_label) const; | |
| 48 | |
| 49 // Calculates and sets the bounds of the popup, including placing it properly | |
| 50 // to prevent it from going off the screen. | |
| 51 void UpdatePopupBounds(); | |
| 52 #endif | |
| 53 | |
| 54 // Convert a y-coordinate to the closest line. | |
| 55 int LineFromY(int y); | |
| 56 | |
| 57 const gfx::Rect popup_bounds() { return popup_bounds_; } | |
| 58 | |
| 59 // Returns the bounds of the item at |index| in the popup, relative to | |
| 60 // the top left of the popup. | |
| 61 gfx::Rect GetRowBounds(size_t index); | |
| 62 | |
| 63 // Returns the bounds that the popup should be placed at, given the desired | |
| 64 // width and height. By default this places the popup below |element_bounds| | |
| 65 // but it will be placed above if there isn't enough space. | |
| 66 gfx::Rect GetPopupBounds(int desired_width, int desired_height) const; | |
| 67 | |
| 68 // Gets the resource value for the given resource, returning -1 if the | |
| 69 // resource isn't recognized. | |
| 70 int GetIconResourceID(const base::string16& resource_name) const; | |
| 71 | |
| 72 private: | |
| 73 // Returns the enclosing rectangle for the element_bounds. | |
| 74 const gfx::Rect RoundedElementBounds() const; | |
| 75 | |
| 76 // The bounds of the Autofill popup. | |
| 77 gfx::Rect popup_bounds_; | |
| 78 | |
| 79 autofill::view_utils::PopupViewUtils view_utils_; | |
| 80 | |
| 81 AutofillPopupViewDelegate* delegate_; // Weak reference. | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(AutofillPopupViewHelper); | |
| 84 }; | |
| 85 | |
| 86 } // namespace autofill | |
| 87 | |
| 88 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_VIEW_HELPER_H_ | |
| OLD | NEW |