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 static const SkColor kBorderColor;
31 static const SkColor kHoveredBackgroundColor;
32 static const SkColor kItemTextColor;
33 static const SkColor kPopupBackground;
34 static const SkColor kValueTextColor;
35 static const SkColor kWarningTextColor;
38 explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate,
39 views::Widget* observing_widget);
40 virtual ~AutofillPopupBaseView();
42 // Show this popup. Idempotent.
45 // Hide the widget and delete |this|.
48 // Update size of popup and paint.
49 void DoUpdateBoundsAndRedrawPopup();
52 friend class AutofillPopupBaseViewTest;
54 // views::Views implementation.
55 virtual void OnMouseCaptureLost() OVERRIDE;
56 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
57 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
58 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
59 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
60 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
61 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
62 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
64 // views::WidgetFocusChangeListener implementation.
65 virtual void OnNativeFocusChange(gfx::NativeView focused_before,
66 gfx::NativeView focused_now) OVERRIDE;
68 // views::WidgetObserver implementation.
69 virtual void OnWidgetBoundsChanged(views::Widget* widget,
70 const gfx::Rect& new_bounds) OVERRIDE;
72 // Stop observing the |observing_widget_|.
73 void RemoveObserver();
75 void SetSelection(const gfx::Point& point);
76 void AcceptSelection(const gfx::Point& point);
77 void ClearSelection();
79 // Hide the controller of this view. This assumes that doing so will
80 // eventually hide this view in the process.
81 void HideController();
83 // Must return the container view for this popup.
84 gfx::NativeView container_view();
86 // Controller for this popup. Weak reference.
87 AutofillPopupViewDelegate* delegate_;
89 // The widget that |this| observes. Weak reference.
90 views::Widget* observing_widget_;
92 base::WeakPtrFactory<AutofillPopupBaseView> weak_ptr_factory_;
94 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView);
97 } // namespace autofill
99 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_