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"
12 #include "ui/views/widget/widget_observer.h"
24 // Class that deals with the event handling for Autofill-style popups. This
25 // class should only be instantiated by sub-classes.
26 class AutofillPopupBaseView
: public views::WidgetDelegateView
,
27 public views::WidgetFocusChangeListener
,
28 public views::WidgetObserver
{
30 explicit AutofillPopupBaseView(AutofillPopupViewDelegate
* delegate
,
31 views::Widget
* observing_widget
);
32 virtual ~AutofillPopupBaseView();
34 // Show this popup. Idempotent.
37 // Hide the widget and delete |this|.
40 // Update size of popup and paint.
41 void DoUpdateBoundsAndRedrawPopup();
43 static const SkColor kBorderColor
;
44 static const SkColor kHoveredBackgroundColor
;
45 static const SkColor kItemTextColor
;
46 static const SkColor kPopupBackground
;
47 static const SkColor kValueTextColor
;
48 static const SkColor kWarningTextColor
;
51 friend class AutofillPopupBaseViewTest
;
53 // views::Views implementation.
54 virtual void OnMouseCaptureLost() OVERRIDE
;
55 virtual bool OnMouseDragged(const ui::MouseEvent
& event
) OVERRIDE
;
56 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
57 virtual void OnMouseMoved(const ui::MouseEvent
& event
) OVERRIDE
;
58 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
;
59 virtual void OnMouseReleased(const ui::MouseEvent
& event
) OVERRIDE
;
60 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
61 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
63 // views::WidgetFocusChangeListener implementation.
64 virtual void OnNativeFocusChange(gfx::NativeView focused_before
,
65 gfx::NativeView focused_now
) OVERRIDE
;
67 // views::WidgetObserver implementation.
68 virtual void OnWidgetBoundsChanged(views::Widget
* widget
,
69 const gfx::Rect
& new_bounds
) OVERRIDE
;
71 // Stop observing the |observing_widget_|.
72 void RemoveObserver();
74 void SetSelection(const gfx::Point
& point
);
75 void AcceptSelection(const gfx::Point
& point
);
76 void ClearSelection();
78 // Hide the controller of this view. This assumes that doing so will
79 // eventually hide this view in the process.
80 void HideController();
82 // Must return the container view for this popup.
83 gfx::NativeView
container_view();
85 // Controller for this popup. Weak reference.
86 AutofillPopupViewDelegate
* delegate_
;
88 // The widget that |this| observes. Weak reference.
89 views::Widget
* observing_widget_
;
91 base::WeakPtrFactory
<AutofillPopupBaseView
> weak_ptr_factory_
;
93 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView
);
96 } // namespace autofill
98 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_