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 public: 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; 36 37 protected: 38 explicit AutofillPopupBaseView(AutofillPopupViewDelegate* delegate, 39 views::Widget* observing_widget); 40 virtual ~AutofillPopupBaseView(); 41 42 // Show this popup. Idempotent. 43 void DoShow(); 44 45 // Hide the widget and delete |this|. 46 void DoHide(); 47 48 // Update size of popup and paint. 49 void DoUpdateBoundsAndRedrawPopup(); 50 51 private: 52 friend class AutofillPopupBaseViewTest; 53 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; 63 64 // views::WidgetFocusChangeListener implementation. 65 virtual void OnNativeFocusChange(gfx::NativeView focused_before, 66 gfx::NativeView focused_now) OVERRIDE; 67 68 // views::WidgetObserver implementation. 69 virtual void OnWidgetBoundsChanged(views::Widget* widget, 70 const gfx::Rect& new_bounds) OVERRIDE; 71 72 // Stop observing the |observing_widget_|. 73 void RemoveObserver(); 74 75 void SetSelection(const gfx::Point& point); 76 void AcceptSelection(const gfx::Point& point); 77 void ClearSelection(); 78 79 // Hide the controller of this view. This assumes that doing so will 80 // eventually hide this view in the process. 81 void HideController(); 82 83 // Must return the container view for this popup. 84 gfx::NativeView container_view(); 85 86 // Controller for this popup. Weak reference. 87 AutofillPopupViewDelegate* delegate_; 88 89 // The widget that |this| observes. Weak reference. 90 views::Widget* observing_widget_; 91 92 base::WeakPtrFactory<AutofillPopupBaseView> weak_ptr_factory_; 93 94 DISALLOW_COPY_AND_ASSIGN(AutofillPopupBaseView); 95}; 96 97} // namespace autofill 98 99#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_POPUP_BASE_VIEW_H_ 100