12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/gtest_prod_util.h"
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/i18n/rtl.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/weak_ptr.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/keyboard_listener.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/font.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect_f.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace gfx {
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Display;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ui {
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class KeyEvent;
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace autofill {
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class AutofillPopupDelegate;
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class AutofillPopupView;
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This class is a controller for an AutofillPopupView. It implements
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// AutofillPopupController to allow calls from AutofillPopupView. The
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// other, public functions are available to its instantiator.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AutofillPopupControllerImpl : public AutofillPopupController,
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    public content::KeyboardListener {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Creates a new |AutofillPopupControllerImpl|, or reuses |previous| if
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the construction arguments are the same. |previous| may be invalidated by
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // this call.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static base::WeakPtr<AutofillPopupControllerImpl> GetOrCreate(
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      base::WeakPtr<AutofillPopupControllerImpl> previous,
42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      base::WeakPtr<AutofillPopupDelegate> delegate,
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      gfx::NativeView container_view,
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const gfx::RectF& element_bounds,
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      base::i18n::TextDirection text_direction);
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shows the popup, or updates the existing popup with the given values.
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Show(const std::vector<string16>& names,
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            const std::vector<string16>& subtexts,
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            const std::vector<string16>& icons,
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            const std::vector<int>& identifiers);
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
53ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Updates the data list values currently shown with the popup.
54ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void UpdateDataListValues(const std::vector<base::string16>& values,
55ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                            const std::vector<base::string16>& labels);
56ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Hides the popup and destroys the controller. This also invalidates
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |delegate_|.
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Hide() OVERRIDE;
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked when the view was destroyed by by someone other than this class.
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ViewDestroyed() OVERRIDE;
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // KeyboardListener implementation.
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool HandleKeyPressEvent(
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const content::NativeWebKeyboardEvent& event) OVERRIDE;
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(AutofillExternalDelegateBrowserTest,
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           CloseWidgetAndNoLeaking);
71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest,
72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           ProperlyResetController);
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  AutofillPopupControllerImpl(base::WeakPtr<AutofillPopupDelegate> delegate,
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                              gfx::NativeView container_view,
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                              const gfx::RectF& element_bounds,
777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                              base::i18n::TextDirection text_direction);
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~AutofillPopupControllerImpl();
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // AutofillPopupController implementation.
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void UpdateBoundsAndRedrawPopup() OVERRIDE;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void MouseHovered(int x, int y) OVERRIDE;
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void MouseClicked(int x, int y) OVERRIDE;
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void MouseExitedPopup() OVERRIDE;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void AcceptSuggestion(size_t index) OVERRIDE;
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual int GetIconResourceID(const string16& resource_name) OVERRIDE;
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool CanDelete(size_t index) const OVERRIDE;
887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual bool IsWarning(size_t index) const OVERRIDE;
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Rect GetRowBounds(size_t index) OVERRIDE;
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE;
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const gfx::Rect& popup_bounds() const OVERRIDE;
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::NativeView container_view() const OVERRIDE;
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const gfx::RectF& element_bounds() const OVERRIDE;
947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual bool IsRTL() const OVERRIDE;
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const std::vector<string16>& names() const OVERRIDE;
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const std::vector<string16>& subtexts() const OVERRIDE;
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const std::vector<string16>& icons() const OVERRIDE;
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const std::vector<int>& identifiers() const OVERRIDE;
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_ANDROID)
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const gfx::Font& GetNameFontForRow(size_t index) const OVERRIDE;
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual const gfx::Font& subtext_font() const OVERRIDE;
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual int selected_line() const OVERRIDE;
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Change which line is currently selected by the user.
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetSelectedLine(int selected_line);
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Increase the selected line by 1, properly handling wrapping.
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SelectNextLine();
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Decrease the selected line by 1, properly handling wrapping.
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SelectPreviousLine();
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The user has choosen the selected line.
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool AcceptSelectedLine();
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The user has removed a suggestion.
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool RemoveSelectedLine();
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Convert a y-coordinate to the closest line.
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int LineFromY(int y);
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the height of a row depending on its type.
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int GetRowHeightFromId(int identifier) const;
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the given id refers to an element that can be accepted.
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool CanAccept(int id);
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the popup still has non-options entries to show the user.
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool HasSuggestions();
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Set the Autofill entry values. Exposed to allow tests to set these values
134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // without showing the popup.
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetValues(const std::vector<string16>& names,
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                 const std::vector<string16>& subtexts,
137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                 const std::vector<string16>& icons,
138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                 const std::vector<int>& identifier);
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AutofillPopupView* view() { return view_; }
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |view_| pass throughs (virtual for testing).
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ShowView();
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void InvalidateRow(size_t row);
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Protected so tests can access.
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_ANDROID)
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculates the desired width of the popup based on its contents.
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int GetDesiredPopupWidth() const;
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculates the desired height of the popup based on its contents.
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int GetDesiredPopupHeight() const;
153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Calculate the width of the row, excluding all the text. This provides
155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // the size of the row that won't be reducible (since all the text can be
156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // elided if there isn't enough space).
157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int RowWidthWithoutText(int row) const;
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr();
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Clear the internal state of the controller. This is needed to ensure that
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // when the popup is reused it doesn't leak values between uses.
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void ClearState();
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const gfx::Rect RoundedElementBounds() const;
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_ANDROID)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculates and sets the bounds of the popup, including placing it properly
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to prevent it from going off the screen.
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void UpdatePopupBounds();
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A helper function to get the display closest to the given point (virtual
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // for testing).
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const;
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculates the width of the popup and the x position of it. These values
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // will stay on the screen.
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::pair<int, int> CalculatePopupXAndWidth(
1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Display& left_display,
1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Display& right_display,
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int popup_required_width) const;
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Calculates the height of the popup and the y position of it. These values
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // will stay on the screen.
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::pair<int, int> CalculatePopupYAndHeight(
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Display& top_display,
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Display& bottom_display,
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int popup_required_height) const;
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AutofillPopupView* view_;  // Weak reference.
193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::WeakPtr<AutofillPopupDelegate> delegate_;
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::NativeView container_view_;  // Weak reference.
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The bounds of the text element that is the focus of the Autofill.
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These coordinates are in screen space.
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const gfx::RectF element_bounds_;
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The bounds of the Autofill popup.
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Rect popup_bounds_;
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The text direction of the popup.
2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  base::i18n::TextDirection text_direction_;
2057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The current Autofill query values.
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> names_;
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> subtexts_;
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> icons_;
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<int> identifiers_;
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Since names_ can be elided to ensure that it fits on the screen, we need to
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // keep an unelided copy of the names to be able to pass to the delegate.
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::vector<string16> full_names_;
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if !defined(OS_ANDROID)
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The fonts for the popup text.
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Font name_font_;
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Font subtext_font_;
2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Font warning_font_;
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The line that is currently selected by the user.
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |kNoSelection| indicates that no line is currently selected.
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int selected_line_;
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_;
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}  // namespace autofill
231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
233