Home | History | Annotate | Download | only in autofill
      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 
     14 namespace gfx {
     15 class Font;
     16 class Point;
     17 class Rect;
     18 class RectF;
     19 }
     20 
     21 namespace autofill {
     22 
     23 // This interface provides data to an AutofillPopupView.
     24 class AutofillPopupController {
     25  public:
     26   // Called when the popup should get hidden.
     27   virtual void Hide() = 0;
     28 
     29   // Called whent the popup view was destroyed.
     30   virtual void ViewDestroyed() = 0;
     31 
     32   // Recalculates the height and width of the popup and triggers a redraw.
     33   virtual void UpdateBoundsAndRedrawPopup() = 0;
     34 
     35   // The user has moved the mouse within the popup.
     36   virtual void MouseHovered(int x, int y) = 0;
     37 
     38   // The user clicked the mouse within the popup.
     39   virtual void MouseClicked(int x, int y) = 0;
     40 
     41   // The user has moved the mouse outside of the popup.
     42   virtual void MouseExitedPopup() = 0;
     43 
     44   // Accepts the suggestion at |index|.
     45   virtual void AcceptSuggestion(size_t index) = 0;
     46 
     47   // Gets the resource value for the given resource, returning -1 if the
     48   // resource isn't recognized.
     49   virtual int GetIconResourceID(const string16& resource_name) = 0;
     50 
     51   // Returns true if the given index refers to an element that can be deleted.
     52   virtual bool CanDelete(size_t index) const = 0;
     53 
     54   // Returns true if the given index refers to an element that is a warning
     55   // rather than an Autofill suggestion.
     56   virtual bool IsWarning(size_t index) const = 0;
     57 
     58   // Updates the bounds of the popup and initiates a redraw.
     59   virtual void SetPopupBounds(const gfx::Rect& bounds) = 0;
     60 
     61   // Returns the bounds of the item at |index| in the popup, relative to
     62   // the top left of the popup.
     63   virtual gfx::Rect GetRowBounds(size_t index) = 0;
     64 
     65   // The actual bounds of the popup.
     66   virtual const gfx::Rect& popup_bounds() const = 0;
     67 
     68   // The view that the form field element sits in.
     69   virtual gfx::NativeView container_view() const = 0;
     70 
     71   // The bounds of the form field element (screen coordinates).
     72   virtual const gfx::RectF& element_bounds() const = 0;
     73 
     74   // If the current popup should be displayed in RTL mode.
     75   virtual bool IsRTL() const = 0;
     76 
     77   // TODO(csharp): The names, subtexts and icon getters can probably be adjusted
     78   // to take in the row index and return a single element, instead of the
     79   // whole vector.
     80   // The main labels for each autofill item.
     81   virtual const std::vector<string16>& names() const = 0;
     82 
     83   // Smaller labels for each autofill item.
     84   virtual const std::vector<string16>& subtexts() const = 0;
     85 
     86   // A string which identifies the icon to be shown for each autofill item.
     87   virtual const std::vector<string16>& icons() const = 0;
     88 
     89   // Identifier for the row.
     90   virtual const std::vector<int>& identifiers() const = 0;
     91 
     92 #if !defined(OS_ANDROID)
     93   // The same font can vary based on the type of data it is showing,
     94   // so we need to know the row.
     95   virtual const gfx::Font& GetNameFontForRow(size_t index) const = 0;
     96   virtual const gfx::Font& subtext_font() const = 0;
     97 #endif
     98 
     99   // Returns the index of the selected line. A line is "selected" when it is
    100   // hovered or has keyboard focus.
    101   virtual int selected_line() const = 0;
    102 
    103  protected:
    104   virtual ~AutofillPopupController() {}
    105 };
    106 
    107 }  // namespace autofill
    108 
    109 #endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_
    110