| 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_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
| 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 9 #include "base/string16.h" | 10 #include "base/string16.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 11 #include "content/public/browser/keyboard_listener.h" | 12 #include "content/public/browser/keyboard_listener.h" |
| 12 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
| 13 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 14 | 15 |
| 15 class AutofillPopupDelegate; | 16 class AutofillPopupDelegate; |
| 16 class AutofillPopupView; | 17 class AutofillPopupView; |
| 17 | 18 |
| 18 namespace gfx { | 19 namespace gfx { |
| 19 class Display; | 20 class Display; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 23 class KeyEvent; | 24 class KeyEvent; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // This class is a controller for an AutofillPopupView. It implements | 27 // This class is a controller for an AutofillPopupView. It implements |
| 27 // AutofillPopupController to allow calls from AutofillPopupView. The | 28 // AutofillPopupController to allow calls from AutofillPopupView. The |
| 28 // other, public functions are available to its instantiator. | 29 // other, public functions are available to its instantiator. |
| 29 class AutofillPopupControllerImpl : public AutofillPopupController, | 30 class AutofillPopupControllerImpl : public AutofillPopupController, |
| 30 public content::KeyboardListener { | 31 public content::KeyboardListener { |
| 31 public: | 32 public: |
| 32 // Creates a new |AutofillPopupControllerImpl|, or reuses |previous| if | 33 // Creates a new |AutofillPopupControllerImpl|, or reuses |previous| if |
| 33 // the construction arguments are the same. |previous| may be invalidated by | 34 // the construction arguments are the same. |previous| may be invalidated by |
| 34 // this call. | 35 // this call. |
| 35 static AutofillPopupControllerImpl* GetOrCreate( | 36 static base::WeakPtr<AutofillPopupControllerImpl> GetOrCreate( |
| 36 AutofillPopupControllerImpl* previous, | 37 base::WeakPtr<AutofillPopupControllerImpl> previous, |
| 37 AutofillPopupDelegate* delegate, | 38 AutofillPopupDelegate* delegate, |
| 38 gfx::NativeView container_view, | 39 gfx::NativeView container_view, |
| 39 const gfx::Rect& element_bounds); | 40 const gfx::Rect& element_bounds); |
| 40 | 41 |
| 41 // Shows the popup, or updates the existing popup with the given values. | 42 // Shows the popup, or updates the existing popup with the given values. |
| 42 void Show(const std::vector<string16>& names, | 43 void Show(const std::vector<string16>& names, |
| 43 const std::vector<string16>& subtexts, | 44 const std::vector<string16>& subtexts, |
| 44 const std::vector<string16>& icons, | 45 const std::vector<string16>& icons, |
| 45 const std::vector<int>& identifiers); | 46 const std::vector<int>& identifiers); |
| 46 | 47 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 virtual const std::vector<string16>& subtexts() const OVERRIDE; | 80 virtual const std::vector<string16>& subtexts() const OVERRIDE; |
| 80 virtual const std::vector<string16>& icons() const OVERRIDE; | 81 virtual const std::vector<string16>& icons() const OVERRIDE; |
| 81 virtual const std::vector<int>& identifiers() const OVERRIDE; | 82 virtual const std::vector<int>& identifiers() const OVERRIDE; |
| 82 #if !defined(OS_ANDROID) | 83 #if !defined(OS_ANDROID) |
| 83 virtual const gfx::Font& name_font() const OVERRIDE; | 84 virtual const gfx::Font& name_font() const OVERRIDE; |
| 84 virtual const gfx::Font& subtext_font() const OVERRIDE; | 85 virtual const gfx::Font& subtext_font() const OVERRIDE; |
| 85 #endif | 86 #endif |
| 86 virtual int selected_line() const OVERRIDE; | 87 virtual int selected_line() const OVERRIDE; |
| 87 virtual bool delete_icon_hovered() const OVERRIDE; | 88 virtual bool delete_icon_hovered() const OVERRIDE; |
| 88 | 89 |
| 89 // Like Hide(), but doesn't invalidate |delegate_| (the delegate will still | |
| 90 // be informed of destruction). | |
| 91 void HideInternal(); | |
| 92 | |
| 93 // Change which line is currently selected by the user. | 90 // Change which line is currently selected by the user. |
| 94 void SetSelectedLine(int selected_line); | 91 void SetSelectedLine(int selected_line); |
| 95 | 92 |
| 96 // Increase the selected line by 1, properly handling wrapping. | 93 // Increase the selected line by 1, properly handling wrapping. |
| 97 void SelectNextLine(); | 94 void SelectNextLine(); |
| 98 | 95 |
| 99 // Decrease the selected line by 1, properly handling wrapping. | 96 // Decrease the selected line by 1, properly handling wrapping. |
| 100 void SelectPreviousLine(); | 97 void SelectPreviousLine(); |
| 101 | 98 |
| 102 // The user has choosen the selected line. | 99 // The user has choosen the selected line. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 | 126 |
| 130 // Protected so tests can access. | 127 // Protected so tests can access. |
| 131 #if !defined(OS_ANDROID) | 128 #if !defined(OS_ANDROID) |
| 132 // Calculates the desired width of the popup based on its contents. | 129 // Calculates the desired width of the popup based on its contents. |
| 133 int GetDesiredPopupWidth() const; | 130 int GetDesiredPopupWidth() const; |
| 134 | 131 |
| 135 // Calculates the desired height of the popup based on its contents. | 132 // Calculates the desired height of the popup based on its contents. |
| 136 int GetDesiredPopupHeight() const; | 133 int GetDesiredPopupHeight() const; |
| 137 #endif | 134 #endif |
| 138 | 135 |
| 136 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr(); |
| 137 |
| 139 private: | 138 private: |
| 140 #if !defined(OS_ANDROID) | 139 #if !defined(OS_ANDROID) |
| 141 // Calculate the width of the row, excluding all the text. This provides | 140 // Calculate the width of the row, excluding all the text. This provides |
| 142 // the size of the row that won't be reducible (since all the text can be | 141 // the size of the row that won't be reducible (since all the text can be |
| 143 // elided if there isn't enough space). | 142 // elided if there isn't enough space). |
| 144 int RowWidthWithoutText(int row) const; | 143 int RowWidthWithoutText(int row) const; |
| 145 | 144 |
| 146 // Calculates and sets the bounds of the popup, including placing it properly | 145 // Calculates and sets the bounds of the popup, including placing it properly |
| 147 // to prevent it from going off the screen. | 146 // to prevent it from going off the screen. |
| 148 void UpdatePopupBounds(); | 147 void UpdatePopupBounds(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // The line that is currently selected by the user. | 195 // The line that is currently selected by the user. |
| 197 // |kNoSelection| indicates that no line is currently selected. | 196 // |kNoSelection| indicates that no line is currently selected. |
| 198 int selected_line_; | 197 int selected_line_; |
| 199 | 198 |
| 200 // Used to indicate if the delete icon within a row is currently selected. | 199 // Used to indicate if the delete icon within a row is currently selected. |
| 201 bool delete_icon_hovered_; | 200 bool delete_icon_hovered_; |
| 202 | 201 |
| 203 // True if |HideInternal| has already been called. | 202 // True if |HideInternal| has already been called. |
| 204 bool is_hiding_; | 203 bool is_hiding_; |
| 205 | 204 |
| 206 // True if the delegate should be informed when |this| is destroyed. | 205 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; |
| 207 bool inform_delegate_of_destruction_; | |
| 208 }; | 206 }; |
| 209 | 207 |
| 210 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 208 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
| OLD | NEW |