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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_
8 #include "chrome/browser/extensions/extension_action.h"
9 #include "chrome/browser/extensions/extension_action_icon_factory.h"
10 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
15 @class ExtensionActionContextMenuController;
17 class LocationBarViewMac;
23 // PageActionDecoration is used to display the icon for a given Page
24 // Action and notify the extension when the icon is clicked.
26 class PageActionDecoration : public ImageDecoration,
27 public ExtensionActionIconFactory::Observer,
28 public content::NotificationObserver,
29 public ExtensionAction::IconAnimation::Observer {
31 PageActionDecoration(LocationBarViewMac* owner,
33 ExtensionAction* page_action);
34 virtual ~PageActionDecoration();
36 ExtensionAction* page_action() { return page_action_; }
37 int current_tab_id() { return current_tab_id_; }
38 void set_preview_enabled(bool enabled) { preview_enabled_ = enabled; }
39 bool preview_enabled() const { return preview_enabled_; }
41 // Overridden from |ExtensionActionIconFactory::Observer|.
42 virtual void OnIconUpdated() OVERRIDE;
44 // Called to notify the Page Action that it should determine whether
45 // to be visible or hidden. |contents| is the WebContents that is
46 // active, |url| is the current page URL.
47 void UpdateVisibility(content::WebContents* contents, const GURL& url);
49 // Sets the tooltip for this Page Action image.
50 void SetToolTip(NSString* tooltip);
51 void SetToolTip(std::string tooltip);
53 // Get the point where extension info bubbles should point within
54 // the given decoration frame.
55 NSPoint GetBubblePointInFrame(NSRect frame);
57 // Overridden from |LocationBarDecoration|
58 virtual CGFloat GetWidthForSpace(CGFloat width) OVERRIDE;
59 virtual void DrawWithBackgroundInFrame(NSRect background_frame,
61 NSView* control_view) OVERRIDE;
62 virtual bool AcceptsMousePress() OVERRIDE;
63 virtual bool OnMousePressed(NSRect frame) OVERRIDE;
64 virtual NSString* GetToolTip() OVERRIDE;
65 virtual NSMenu* GetMenu() OVERRIDE;
68 // Activate the page action in the given |frame|.
69 bool ActivatePageAction(NSRect frame);
71 // Show the popup in the frame, with the given URL.
72 void ShowPopup(const NSRect& frame, const GURL& popup_url);
74 // Overridden from ExtensionAction::IconAnimation::Observer.
75 virtual void OnIconChanged() OVERRIDE;
77 // Overridden from NotificationObserver:
78 virtual void Observe(int type,
79 const content::NotificationSource& source,
80 const content::NotificationDetails& details) OVERRIDE;
82 // The location bar view that owns us.
83 LocationBarViewMac* owner_;
85 // The current browser (not owned by us).
88 // The Page Action that this view represents. The Page Action is not
89 // owned by us, it resides in the extension of this particular
91 ExtensionAction* page_action_;
94 // The object that will be used to get the page action icon for us.
95 // It may load the icon asynchronously (in which case the initial icon
96 // returned by the factory will be transparent), so we have to observe it for
97 // updates to the icon.
98 scoped_ptr<ExtensionActionIconFactory> icon_factory_;
100 // The tab id we are currently showing the icon for.
103 // The URL we are currently showing the icon for.
106 // The string to show for a tooltip.
107 base::scoped_nsobject<NSString> tooltip_;
109 // The context menu controller for the Page Action.
110 base::scoped_nsobject<
111 ExtensionActionContextMenuController> contextMenuController_;
113 // This is used for post-install visual feedback. The page_action
114 // icon is briefly shown even if it hasn't been enabled by its
116 bool preview_enabled_;
118 // Fade-in animation for the icon with observer scoped to this.
119 ExtensionAction::IconAnimation::ScopedObserver
120 scoped_icon_animation_observer_;
122 // Used to register for notifications received by
123 // NotificationObserver.
124 content::NotificationRegistrar registrar_;
126 DISALLOW_COPY_AND_ASSIGN(PageActionDecoration);
129 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_PAGE_ACTION_DECORATION_H_