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/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
13 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 13 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
14 #include "chrome/common/extensions/extension_action.h" | 14 #include "chrome/common/extensions/extension_action.h" |
15 #include "ui/views/context_menu_controller.h" | 15 #include "ui/views/context_menu_controller.h" |
16 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
17 #include "ui/views/widget/widget_observer.h" | 17 #include "ui/views/widget/widget_observer.h" |
18 | 18 |
19 class Browser; | 19 class Browser; |
20 class LocationBarView; | 20 class LocationBarView; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class WebContents; | 23 class WebContents; |
24 } | 24 } |
25 namespace views { | 25 namespace views { |
26 class MenuRunner; | 26 class MenuRunner; |
27 } | 27 } |
28 | 28 |
29 // PageActionImageView is used by the LocationBarView to display the icon for a | 29 // PageActionImageView is used by the LocationBarView to display the icon for a |
30 // given PageAction and notify the extension when the icon is clicked. | 30 // given PageAction and notify the extension when the icon is clicked. |
31 class PageActionImageView : public views::ImageView, | 31 class PageActionImageView : public views::ImageView, |
32 public ImageLoadingTracker::Observer, | |
33 public views::WidgetObserver, | 32 public views::WidgetObserver, |
34 public views::ContextMenuController, | 33 public views::ContextMenuController, |
35 public content::NotificationObserver, | 34 public content::NotificationObserver, |
| 35 public ExtensionActionIconFactory::Observer, |
36 public ExtensionAction::IconAnimation::Observer { | 36 public ExtensionAction::IconAnimation::Observer { |
37 public: | 37 public: |
38 PageActionImageView(LocationBarView* owner, | 38 PageActionImageView(LocationBarView* owner, |
39 ExtensionAction* page_action, | 39 ExtensionAction* page_action, |
40 Browser* browser); | 40 Browser* browser); |
41 virtual ~PageActionImageView(); | 41 virtual ~PageActionImageView(); |
42 | 42 |
43 ExtensionAction* page_action() { return page_action_; } | 43 ExtensionAction* page_action() { return page_action_; } |
44 | 44 |
45 int current_tab_id() { return current_tab_id_; } | 45 int current_tab_id() { return current_tab_id_; } |
46 | 46 |
47 void set_preview_enabled(bool preview_enabled) { | 47 void set_preview_enabled(bool preview_enabled) { |
48 preview_enabled_ = preview_enabled; | 48 preview_enabled_ = preview_enabled; |
49 } | 49 } |
50 | 50 |
51 // Overridden from views::View: | 51 // Overridden from views::View: |
52 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 52 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 53 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 54 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
55 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 55 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
56 | 56 |
57 // Overridden from ImageLoadingTracker: | |
58 virtual void OnImageLoaded(const gfx::Image& image, | |
59 const std::string& extension_id, | |
60 int index) OVERRIDE; | |
61 | |
62 // Overridden from views::WidgetObserver: | 57 // Overridden from views::WidgetObserver: |
63 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 58 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
64 | 59 |
65 // Overridden from views::ContextMenuController. | 60 // Overridden from views::ContextMenuController. |
66 virtual void ShowContextMenuForView(View* source, | 61 virtual void ShowContextMenuForView(View* source, |
67 const gfx::Point& point) OVERRIDE; | 62 const gfx::Point& point) OVERRIDE; |
68 | 63 |
69 // Overridden from content::NotificationObserver: | 64 // Overridden from content::NotificationObserver: |
70 virtual void Observe(int type, | 65 virtual void Observe(int type, |
71 const content::NotificationSource& source, | 66 const content::NotificationSource& source, |
72 const content::NotificationDetails& details) OVERRIDE; | 67 const content::NotificationDetails& details) OVERRIDE; |
73 | 68 |
| 69 // Overriden from ExtensionActionIconFactory::Observer. |
| 70 virtual void OnIconUpdated() OVERRIDE; |
| 71 |
74 // Overridden from ui::AcceleratorTarget: | 72 // Overridden from ui::AcceleratorTarget: |
75 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 73 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
76 virtual bool CanHandleAccelerators() const OVERRIDE; | 74 virtual bool CanHandleAccelerators() const OVERRIDE; |
77 | 75 |
78 // Called to notify the PageAction that it should determine whether to be | 76 // Called to notify the PageAction that it should determine whether to be |
79 // visible or hidden. |contents| is the WebContents that is active, |url| is | 77 // visible or hidden. |contents| is the WebContents that is active, |url| is |
80 // the current page URL. | 78 // the current page URL. |
81 void UpdateVisibility(content::WebContents* contents, const GURL& url); | 79 void UpdateVisibility(content::WebContents* contents, const GURL& url); |
82 | 80 |
83 // Either notify listeners or show a popup depending on the page action. | 81 // Either notify listeners or show a popup depending on the page action. |
(...skipping 12 matching lines...) Expand all Loading... |
96 // The location bar view that owns us. | 94 // The location bar view that owns us. |
97 LocationBarView* owner_; | 95 LocationBarView* owner_; |
98 | 96 |
99 // The PageAction that this view represents. The PageAction is not owned by | 97 // The PageAction that this view represents. The PageAction is not owned by |
100 // us, it resides in the extension of this particular profile. | 98 // us, it resides in the extension of this particular profile. |
101 ExtensionAction* page_action_; | 99 ExtensionAction* page_action_; |
102 | 100 |
103 // The corresponding browser. | 101 // The corresponding browser. |
104 Browser* browser_; | 102 Browser* browser_; |
105 | 103 |
106 // The object that is waiting for the image loading to complete | 104 // The object that page action will use to create icon for us. |
107 // asynchronously. | 105 // It may load icon asynchronously (in which case initial icon returned by |
108 ImageLoadingTracker tracker_; | 106 // the action will be blank), so we have to observe it for icon's updates. |
| 107 scoped_ptr<ExtensionActionIconFactory> icon_factory_; |
109 | 108 |
110 // The tab id we are currently showing the icon for. | 109 // The tab id we are currently showing the icon for. |
111 int current_tab_id_; | 110 int current_tab_id_; |
112 | 111 |
113 // The URL we are currently showing the icon for. | 112 // The URL we are currently showing the icon for. |
114 GURL current_url_; | 113 GURL current_url_; |
115 | 114 |
116 // The string to show for a tooltip; | 115 // The string to show for a tooltip; |
117 std::string tooltip_; | 116 std::string tooltip_; |
118 | 117 |
(...skipping 17 matching lines...) Expand all Loading... |
136 scoped_ptr<views::MenuRunner> menu_runner_; | 135 scoped_ptr<views::MenuRunner> menu_runner_; |
137 | 136 |
138 // Fade-in animation for the icon with observer scoped to this. | 137 // Fade-in animation for the icon with observer scoped to this. |
139 ExtensionAction::IconAnimation::ScopedObserver | 138 ExtensionAction::IconAnimation::ScopedObserver |
140 scoped_icon_animation_observer_; | 139 scoped_icon_animation_observer_; |
141 | 140 |
142 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); | 141 DISALLOW_IMPLICIT_CONSTRUCTORS(PageActionImageView); |
143 }; | 142 }; |
144 | 143 |
145 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ | 144 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_PAGE_ACTION_IMAGE_VIEW_H_ |
OLD | NEW |