OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" |
10 #include "ui/views/focus/widget_focus_manager.h" | 10 #include "ui/views/focus/widget_focus_manager.h" |
11 #include "ui/views/widget/widget_delegate.h" | 11 #include "ui/views/widget/widget_delegate.h" |
12 #include "ui/views/widget/widget_observer.h" | |
13 | 12 |
14 namespace content { | 13 namespace content { |
15 class WebContents; | 14 class WebContents; |
16 } | 15 } |
17 | 16 |
18 namespace gfx { | 17 namespace gfx { |
19 class Point; | 18 class Point; |
20 } | 19 } |
21 | 20 |
| 21 namespace views { |
| 22 class FocusManager; |
| 23 } |
| 24 |
22 namespace autofill { | 25 namespace autofill { |
23 | 26 |
24 // Class that deals with the event handling for Autofill-style popups. This | 27 // Class that deals with the event handling for Autofill-style popups. This |
25 // class should only be instantiated by sub-classes. | 28 // class should only be instantiated by sub-classes. |
26 class AutofillPopupBaseView : public views::WidgetDelegateView, | 29 class AutofillPopupBaseView : public views::WidgetDelegateView, |
27 public views::WidgetFocusChangeListener, | 30 public views::WidgetFocusChangeListener { |
28 public views::WidgetObserver { | |
29 public: | 31 public: |
30 static const SkColor kBorderColor; | 32 static const SkColor kBorderColor; |
31 static const SkColor kHoveredBackgroundColor; | 33 static const SkColor kHoveredBackgroundColor; |
32 static const SkColor kItemTextColor; | 34 static const SkColor kItemTextColor; |
33 static const SkColor kPopupBackground; | 35 static const SkColor kPopupBackground; |
34 static const SkColor kValueTextColor; | 36 static const SkColor kValueTextColor; |
35 static const SkColor kWarningTextColor; | 37 static const SkColor kWarningTextColor; |
36 | 38 |
37 protected: | 39 protected: |
38 explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate, | 40 explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate, |
39 views::Widget* observing_widget); | 41 views::FocusManager* focus_manager); |
40 ~AutofillPopupBaseView() override; | 42 ~AutofillPopupBaseView() override; |
41 | 43 |
42 // Show this popup. Idempotent. | 44 // Show this popup. Idempotent. |
43 void DoShow(); | 45 void DoShow(); |
44 | 46 |
45 // Hide the widget and delete |this|. | 47 // Hide the widget and delete |this|. |
46 void DoHide(); | 48 void DoHide(); |
47 | 49 |
48 // Update size of popup and paint. | 50 // Update size of popup and paint. |
49 void DoUpdateBoundsAndRedrawPopup(); | 51 void DoUpdateBoundsAndRedrawPopup(); |
50 | 52 |
51 private: | 53 private: |
52 friend class AutofillPopupBaseViewTest; | 54 friend class AutofillPopupBaseViewTest; |
53 | 55 |
54 // views::Views implementation. | 56 // views::Views implementation. |
55 void OnMouseCaptureLost() override; | 57 void OnMouseCaptureLost() override; |
56 bool OnMouseDragged(const ui::MouseEvent& event) override; | 58 bool OnMouseDragged(const ui::MouseEvent& event) override; |
57 void OnMouseExited(const ui::MouseEvent& event) override; | 59 void OnMouseExited(const ui::MouseEvent& event) override; |
58 void OnMouseMoved(const ui::MouseEvent& event) override; | 60 void OnMouseMoved(const ui::MouseEvent& event) override; |
59 bool OnMousePressed(const ui::MouseEvent& event) override; | 61 bool OnMousePressed(const ui::MouseEvent& event) override; |
60 void OnMouseReleased(const ui::MouseEvent& event) override; | 62 void OnMouseReleased(const ui::MouseEvent& event) override; |
61 void OnGestureEvent(ui::GestureEvent* event) override; | 63 void OnGestureEvent(ui::GestureEvent* event) override; |
62 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 64 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
63 | 65 |
64 // views::WidgetFocusChangeListener implementation. | 66 // views::WidgetFocusChangeListener implementation. |
65 void OnNativeFocusChange(gfx::NativeView focused_before, | 67 void OnNativeFocusChange(gfx::NativeView focused_before, |
66 gfx::NativeView focused_now) override; | 68 gfx::NativeView focused_now) override; |
67 | 69 |
68 // views::WidgetObserver implementation. | 70 // Stop observing accelerators and focus changes. |
69 void OnWidgetBoundsChanged(views::Widget* widget, | |
70 const gfx::Rect& new_bounds) override; | |
71 | |
72 // Stop observing the |observing_widget_|. | |
73 void RemoveObserver(); | 71 void RemoveObserver(); |
74 | 72 |
75 void SetSelection(const gfx::Point& point); | 73 void SetSelection(const gfx::Point& point); |
76 void AcceptSelection(const gfx::Point& point); | 74 void AcceptSelection(const gfx::Point& point); |
77 void ClearSelection(); | 75 void ClearSelection(); |
78 | 76 |
79 // Hide the controller of this view. This assumes that doing so will | 77 // Hide the controller of this view. This assumes that doing so will |
80 // eventually hide this view in the process. | 78 // eventually hide this view in the process. |
81 void HideController(); | 79 void HideController(); |
82 | 80 |
83 // Must return the container view for this popup. | 81 // Must return the container view for this popup. |
84 gfx::NativeView container_view(); | 82 gfx::NativeView container_view(); |
85 | 83 |
86 // Controller for this popup. Weak reference. | 84 // Controller for this popup. Weak reference. |
87 AutofillPopupViewDelegate* delegate_; | 85 AutofillPopupViewDelegate* delegate_; |
88 | 86 |
89 // The widget that |this| observes. Weak reference. | 87 // The focus manager that |this| observes. Weak reference. |
90 views::Widget* observing_widget_; | 88 views::FocusManager* focus_manager_; |
91 | 89 |
92 base::WeakPtrFactory<AutofillPopupBaseView> weak_ptr_factory_; | 90 base::WeakPtrFactory<AutofillPopupBaseView> weak_ptr_factory_; |
93 | 91 |
94 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView); | 92 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView); |
95 }; | 93 }; |
96 | 94 |
97 } // namespace autofill | 95 } // namespace autofill |
98 | 96 |
99 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ | 97 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ |
OLD | NEW |