autofill_popup_controller.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_ 6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_ 7 8#include <vector> 9 10#include "base/compiler_specific.h" 11#include "base/strings/string16.h" 12#include "ui/gfx/native_widget_types.h" 13 14namespace gfx { 15class Font; 16class Point; 17class Rect; 18class RectF; 19} 20 21namespace ui { 22class MouseEvent; 23} 24 25namespace autofill { 26 27// This interface provides data to an AutofillPopupView. 28class AutofillPopupController { 29 public: 30 // Called when the popup should get hidden. 31 virtual void Hide() = 0; 32 33 // Called whent the popup view was destroyed. 34 virtual void ViewDestroyed() = 0; 35 36 // Recalculates the height and width of the popup and triggers a redraw. 37 virtual void UpdateBoundsAndRedrawPopup() = 0; 38 39 // The user selected the line at (x, y), e.g. by hovering the mouse cursor. 40 // |x| and |y| must be in the popup coordinates. 41 virtual void LineSelectedAtPoint(int x, int y) = 0; 42 43 // The user accepted the line at (x, y); e.g., by clicking on it using the 44 // mouse. |x| and |y| must be in the popup coordinates. 45 virtual void LineAcceptedAtPoint(int x, int y) = 0; 46 47 // The user cleared the selected line, e.g. by moving the mouse cursor out of 48 // the popup bounds. 49 virtual void SelectionCleared() = 0; 50 51 // Whether |event| should be reposted to the native window management. 52 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) = 0; 53 54 // Accepts the suggestion at |index|. 55 virtual void AcceptSuggestion(size_t index) = 0; 56 57 // Gets the resource value for the given resource, returning -1 if the 58 // resource isn't recognized. 59 virtual int GetIconResourceID(const base::string16& resource_name) const = 0; 60 61 // Returns true if the given index refers to an element that can be deleted. 62 virtual bool CanDelete(size_t index) const = 0; 63 64 // Returns true if the given index refers to an element that is a warning 65 // rather than an Autofill suggestion. 66 virtual bool IsWarning(size_t index) const = 0; 67 68 // Updates the bounds of the popup and initiates a redraw. 69 virtual void SetPopupBounds(const gfx::Rect& bounds) = 0; 70 71 // Returns the bounds of the item at |index| in the popup, relative to 72 // the top left of the popup. 73 virtual gfx::Rect GetRowBounds(size_t index) = 0; 74 75 // The actual bounds of the popup. 76 virtual const gfx::Rect& popup_bounds() const = 0; 77 78 // The view that the form field element sits in. 79 virtual gfx::NativeView container_view() const = 0; 80 81 // The bounds of the form field element (screen coordinates). 82 virtual const gfx::RectF& element_bounds() const = 0; 83 84 // If the current popup should be displayed in RTL mode. 85 virtual bool IsRTL() const = 0; 86 87 // TODO(csharp): The names, subtexts and icon getters can probably be adjusted 88 // to take in the row index and return a single element, instead of the 89 // whole vector. 90 // The main labels for each autofill item. 91 virtual const std::vector<string16>& names() const = 0; 92 93 // Smaller labels for each autofill item. 94 virtual const std::vector<string16>& subtexts() const = 0; 95 96 // A string which identifies the icon to be shown for each autofill item. 97 virtual const std::vector<string16>& icons() const = 0; 98 99 // Identifier for the row. 100 virtual const std::vector<int>& identifiers() const = 0; 101 102#if !defined(OS_ANDROID) 103 // The same font can vary based on the type of data it is showing, 104 // so we need to know the row. 105 virtual const gfx::Font& GetNameFontForRow(size_t index) const = 0; 106 virtual const gfx::Font& subtext_font() const = 0; 107#endif 108 109 // Returns the index of the selected line. A line is "selected" when it is 110 // hovered or has keyboard focus. 111 virtual int selected_line() const = 0; 112 113 // Whether the view should be hidden on outside mouse presses. 114 virtual bool hide_on_outside_click() const = 0; 115 116 protected: 117 virtual ~AutofillPopupController() {} 118}; 119 120} // namespace autofill 121 122#endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_ 123