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 "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
10 #include "ui/views/focus/widget_focus_manager.h"
11 #include "ui/views/widget/widget_delegate.h"
27 // Class that deals with the event handling for Autofill-style popups. This
28 // class should only be instantiated by sub-classes.
29 class AutofillPopupBaseView
: public views::WidgetDelegateView
,
30 public views::WidgetFocusChangeListener
{
32 static const SkColor kBorderColor
;
33 static const SkColor kHoveredBackgroundColor
;
34 static const SkColor kItemTextColor
;
35 static const SkColor kPopupBackground
;
36 static const SkColor kValueTextColor
;
37 static const SkColor kWarningTextColor
;
40 explicit AutofillPopupBaseView(AutofillPopupViewDelegate
* delegate
,
41 views::FocusManager
* focus_manager
);
42 ~AutofillPopupBaseView() override
;
44 // Show this popup. Idempotent.
47 // Hide the widget and delete |this|.
50 // Update size of popup and paint.
51 void DoUpdateBoundsAndRedrawPopup();
54 friend class AutofillPopupBaseViewTest
;
56 // views::Views implementation.
57 void OnMouseCaptureLost() override
;
58 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
59 void OnMouseExited(const ui::MouseEvent
& event
) override
;
60 void OnMouseMoved(const ui::MouseEvent
& event
) override
;
61 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
62 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
63 void OnGestureEvent(ui::GestureEvent
* event
) override
;
64 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
66 // views::WidgetFocusChangeListener implementation.
67 void OnNativeFocusChange(gfx::NativeView focused_before
,
68 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 base::WeakPtrFactory
<AutofillPopupBaseView
> weak_ptr_factory_
;
92 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView
);
95 } // namespace autofill
97 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_