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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
11 #include "ui/views/focus/widget_focus_manager.h"
12 #include "ui/views/widget/widget_delegate.h"
28 // Class that deals with the event handling for Autofill-style popups. This
29 // class should only be instantiated by sub-classes.
30 class AutofillPopupBaseView
: public views::WidgetDelegateView
,
31 public views::WidgetFocusChangeListener
{
33 static const SkColor kBorderColor
;
34 static const SkColor kHoveredBackgroundColor
;
35 static const SkColor kItemTextColor
;
36 static const SkColor kPopupBackground
;
37 static const SkColor kValueTextColor
;
38 static const SkColor kWarningTextColor
;
41 explicit AutofillPopupBaseView(AutofillPopupViewDelegate
* delegate
,
42 views::FocusManager
* focus_manager
);
43 ~AutofillPopupBaseView() override
;
45 // Show this popup. Idempotent.
48 // Hide the widget and delete |this|.
51 // Update size of popup and paint.
52 void DoUpdateBoundsAndRedrawPopup();
55 friend class AutofillPopupBaseViewTest
;
57 // views::Views implementation.
58 void OnMouseCaptureLost() override
;
59 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
60 void OnMouseExited(const ui::MouseEvent
& event
) override
;
61 void OnMouseMoved(const ui::MouseEvent
& event
) override
;
62 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
63 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
64 void OnGestureEvent(ui::GestureEvent
* event
) override
;
65 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
67 // views::WidgetFocusChangeListener implementation.
68 void OnNativeFocusChanged(gfx::NativeView focused_now
) override
;
70 // Stop observing accelerators and focus changes.
71 void RemoveObserver();
73 void SetSelection(const gfx::Point
& point
);
74 void AcceptSelection(const gfx::Point
& point
);
75 void ClearSelection();
77 // Hide the controller of this view. This assumes that doing so will
78 // eventually hide this view in the process.
79 void HideController();
81 // Must return the container view for this popup.
82 gfx::NativeView
container_view();
84 // Controller for this popup. Weak reference.
85 AutofillPopupViewDelegate
* delegate_
;
87 // The focus manager that |this| observes. Weak reference.
88 views::FocusManager
* focus_manager_
;
90 // The time when the popup was shown.
91 base::Time show_time_
;
93 base::WeakPtrFactory
<AutofillPopupBaseView
> weak_ptr_factory_
;
95 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView
);
98 } // namespace autofill
100 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_