OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
12 #include "chrome/browser/extensions/extension_context_menu_model.h" | 13 #include "chrome/browser/extensions/extension_context_menu_model.h" |
13 #include "chrome/browser/extensions/image_loading_tracker.h" | |
14 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 14 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
15 #include "chrome/common/extensions/extension_action.h" | 15 #include "chrome/common/extensions/extension_action.h" |
16 #include "ui/views/context_menu_controller.h" | 16 #include "ui/views/context_menu_controller.h" |
17 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
18 #include "ui/views/widget/widget_observer.h" | 18 #include "ui/views/widget/widget_observer.h" |
19 | 19 |
20 class Browser; | 20 class Browser; |
21 class LocationBarView; | 21 class LocationBarView; |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 class WebContents; | 24 class WebContents; |
25 } | 25 } |
26 namespace views { | 26 namespace views { |
27 class MenuRunner; | 27 class MenuRunner; |
28 } | 28 } |
29 | 29 |
30 // PageActionImageView is used by the LocationBarView to display the icon for a | 30 // PageActionImageView is used by the LocationBarView to display the icon for a |
31 // given PageAction and notify the extension when the icon is clicked. | 31 // given PageAction and notify the extension when the icon is clicked. |
32 class PageActionImageView : public views::ImageView, | 32 class PageActionImageView : public views::ImageView, |
33 public ImageLoadingTracker::Observer, | |
34 public ExtensionContextMenuModel::PopupDelegate, | 33 public ExtensionContextMenuModel::PopupDelegate, |
35 public views::WidgetObserver, | 34 public views::WidgetObserver, |
36 public views::ContextMenuController, | 35 public views::ContextMenuController, |
37 public content::NotificationObserver, | 36 public content::NotificationObserver, |
| 37 public ExtensionActionIconFactory::Observer, |
38 public ExtensionAction::IconAnimation::Observer { | 38 public ExtensionAction::IconAnimation::Observer { |
39 public: | 39 public: |
40 PageActionImageView(LocationBarView* owner, | 40 PageActionImageView(LocationBarView* owner, |
41 ExtensionAction* page_action, | 41 ExtensionAction* page_action, |
42 Browser* browser); | 42 Browser* browser); |
43 virtual ~PageActionImageView(); | 43 virtual ~PageActionImageView(); |
44 | 44 |
45 ExtensionAction* page_action() { return page_action_; } | 45 ExtensionAction* page_action() { return page_action_; } |
46 | 46 |
47 int current_tab_id() { return current_tab_id_; } | 47 int current_tab_id() { return current_tab_id_; } |
48 | 48 |
49 void set_preview_enabled(bool preview_enabled) { | 49 void set_preview_enabled(bool preview_enabled) { |
50 preview_enabled_ = preview_enabled; | 50 preview_enabled_ = preview_enabled; |
51 } | 51 } |
52 | 52 |
53 // Overridden from views::View: | 53 // Overridden from views::View: |
54 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 54 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
55 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 55 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
56 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 56 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
57 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 57 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
58 | 58 |
59 // Overridden from ImageLoadingTracker: | |
60 virtual void OnImageLoaded(const gfx::Image& image, | |
61 const std::string& extension_id, | |
62 int index) OVERRIDE; | |
63 | |
64 // Overridden from ExtensionContextMenuModel::Delegate | 59 // Overridden from ExtensionContextMenuModel::Delegate |
65 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; | 60 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; |
66 | 61 |
67 // Overridden from views::WidgetObserver: | 62 // Overridden from views::WidgetObserver: |
68 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 63 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
69 | 64 |
70 // Overridden from views::ContextMenuController. | 65 // Overridden from views::ContextMenuController. |
71 virtual void ShowContextMenuForView(View* source, | 66 virtual void ShowContextMenuForView(View* source, |
72 const gfx::Point& point) OVERRIDE; | 67 const gfx::Point& point) OVERRIDE; |
73 | 68 |
74 // Overridden from content::NotificationObserver: | 69 // Overridden from content::NotificationObserver: |
75 virtual void Observe(int type, | 70 virtual void Observe(int type, |
76 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
77 const content::NotificationDetails& details) OVERRIDE; | 72 const content::NotificationDetails& details) OVERRIDE; |
78 | 73 |
| 74 // Overriden from ExtensionActionIconFactory::Observer. |
| 75 virtual void OnIconUpdated() OVERRIDE; |
| 76 |
79 // Overridden from ui::AcceleratorTarget: | 77 // Overridden from ui::AcceleratorTarget: |
80 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 78 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
81 virtual bool CanHandleAccelerators() const OVERRIDE; | 79 virtual bool CanHandleAccelerators() const OVERRIDE; |
82 | 80 |
83 // Called to notify the PageAction that it should determine whether to be | 81 // Called to notify the PageAction that it should determine whether to be |
84 // visible or hidden. |contents| is the WebContents that is active, |url| is | 82 // visible or hidden. |contents| is the WebContents that is active, |url| is |
85 // the current page URL. | 83 // the current page URL. |
86 void UpdateVisibility(content::WebContents* contents, const GURL& url); | 84 void UpdateVisibility(content::WebContents* contents, const GURL& url); |
87 | 85 |
88 // Either notify listeners or show a popup depending on the page action. | 86 // Either notify listeners or show a popup depending on the page action. |
(...skipping 13 matching lines...) Expand all Loading... |
102 // The location bar view that owns us. | 100 // The location bar view that owns us. |
103 LocationBarView* owner_; | 101 LocationBarView* owner_; |
104 | 102 |
105 // The PageAction that this view represents. The PageAction is not owned by | 103 // The PageAction that this view represents. The PageAction is not owned by |
106 // us, it resides in the extension of this particular profile. | 104 // us, it resides in the extension of this particular profile. |
107 ExtensionAction* page_action_; | 105 ExtensionAction* page_action_; |
108 | 106 |
109 // The corresponding browser. | 107 // The corresponding browser. |
110 Browser* browser_; | 108 Browser* browser_; |
111 | 109 |
112 // The object that is waiting for the image loading to complete | 110 // The object that will be used to get the page action icon for us. |
113 // asynchronously. | 111 // It may load the icon asynchronously (in which case the initial icon |
114 ImageLoadingTracker tracker_; | 112 // returned by the factory will be transparent), so we have to observe it for |
| 113 // updates to the icon. |
| 114 scoped_ptr<ExtensionActionIconFactory> icon_factory_; |
115 | 115 |
116 // The tab id we are currently showing the icon for. | 116 // The tab id we are currently showing the icon for. |
117 int current_tab_id_; | 117 int current_tab_id_; |
118 | 118 |
119 // The URL we are currently showing the icon for. | 119 // The URL we are currently showing the icon for. |
120 GURL current_url_; | 120 GURL current_url_; |
121 | 121 |
122 // The string to show for a tooltip; | 122 // The string to show for a tooltip; |
123 std::string tooltip_; | 123 std::string tooltip_; |
124 | 124 |
(...skipping 17 matching lines...) Expand all Loading... |
142 scoped_ptr<views::MenuRunner> menu_runner_; | 142 scoped_ptr<views::MenuRunner> menu_runner_; |
143 | 143 |
144 // Fade-in animation for the icon with observer scoped to this. | 144 // Fade-in animation for the icon with observer scoped to this. |
145 ExtensionAction::IconAnimation::ScopedObserver | 145 ExtensionAction::IconAnimation::ScopedObserver |
146 scoped_icon_animation_observer_; | 146 scoped_icon_animation_observer_; |
147 | 147 |
148 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); | 148 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); |
149 }; | 149 }; |
150 | 150 |
151 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 151 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
OLD | NEW |