autofill_popup_base_view.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 "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" 13 14namespace content { 15class WebContents; 16} 17 18namespace gfx { 19class Point; 20} 21 22namespace autofill { 23 24// Class that deals with the event handling for Autofill-style popups. This 25// class should only be instantiated by sub-classes. 26class AutofillPopupBaseView : public views::WidgetDelegateView, 27 public views::WidgetFocusChangeListener, 28 public views::WidgetObserver { 29 protected: 30 explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate, 31 views::Widget* observing_widget); 32 virtual ~AutofillPopupBaseView(); 33 34 // Show this popup. Idempotent. 35 void DoShow(); 36 37 // Hide the widget and delete |this|. 38 void DoHide(); 39 40 // Update size of popup and paint. 41 void DoUpdateBoundsAndRedrawPopup(); 42 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; 49 50 private: 51 friend class AutofillPopupBaseViewTest; 52 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; 62 63 // views::WidgetFocusChangeListener implementation. 64 virtual void OnNativeFocusChange(gfx::NativeView focused_before, 65 gfx::NativeView focused_now) OVERRIDE; 66 67 // views::WidgetObserver implementation. 68 virtual void OnWidgetBoundsChanged(views::Widget* widget, 69 const gfx::Rect& new_bounds) OVERRIDE; 70 71 // Stop observing the |observing_widget_|. 72 void RemoveObserver(); 73 74 void SetSelection(const gfx::Point& point); 75 void AcceptSelection(const gfx::Point& point); 76 void ClearSelection(); 77 78 // Hide the controller of this view. This assumes that doing so will 79 // eventually hide this view in the process. 80 void HideController(); 81 82 // Must return the container view for this popup. 83 gfx::NativeView container_view(); 84 85 // Controller for this popup. Weak reference. 86 AutofillPopupViewDelegate* delegate_; 87 88 // The widget that |this| observes. Weak reference. 89 views::Widget* observing_widget_; 90 91 base::WeakPtrFactory<AutofillPopupBaseView> weak_ptr_factory_; 92 93 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView); 94}; 95 96} // namespace autofill 97 98#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ 99