autofill_popup_base_view.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_
7
8#include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
9#include "ui/views/widget/widget_delegate.h"
10#include "ui/views/widget/widget_observer.h"
11
12namespace content {
13class WebContents;
14}
15
16namespace gfx {
17class Point;
18}
19
20namespace autofill {
21
22// Class that deals with the event handling for Autofill-style popups. This
23// class should only be instantiated by sub-classes.
24class AutofillPopupBaseView : public views::WidgetDelegateView,
25                              public views::WidgetObserver {
26 protected:
27  explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate,
28                                 views::Widget* observing_widget);
29  virtual ~AutofillPopupBaseView();
30
31  // Show this popup. Idempotent.
32  void DoShow();
33
34  // Hide the widget and delete |this|.
35  void DoHide();
36
37  // Update size of popup and paint.
38  void DoUpdateBoundsAndRedrawPopup();
39
40  static const SkColor kBorderColor;
41  static const SkColor kHoveredBackgroundColor;
42  static const SkColor kItemTextColor;
43  static const SkColor kPopupBackground;
44  static const SkColor kValueTextColor;
45  static const SkColor kWarningTextColor;
46
47 private:
48  // views::Views implementation.
49  virtual void OnMouseCaptureLost() OVERRIDE;
50  virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
51  virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
52  virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
53  virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
54  virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
55  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
56
57  // views::WidgetObserver implementation.
58  virtual void OnWidgetBoundsChanged(views::Widget* widget,
59                                     const gfx::Rect& new_bounds) OVERRIDE;
60
61  // Stop observing the |observing_widget_|.
62  void RemoveObserver();
63
64  void SetSelection(const gfx::Point& point);
65  void AcceptSelection(const gfx::Point& point);
66  void ClearSelection();
67
68  // If the popup should be hidden if the user clicks outside it's bounds.
69  bool ShouldHideOnOutsideClick();
70
71  // Hide the controller of this view. This assumes that doing so will
72  // eventually hide this view in the process.
73  void HideController();
74
75  // Returns true if this event should be passed along.
76  bool ShouldRepostEvent(const ui::MouseEvent& event);
77
78  // Must return the container view for this popup.
79  gfx::NativeView container_view();
80
81  // Controller for this popup. Weak reference.
82  AutofillPopupViewDelegate* delegate_;
83
84  // The widget that |this| observes. Weak reference.
85  views::Widget* observing_widget_;
86
87  DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView);
88};
89
90}  // namespace autofill
91
92#endif  // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_
93