summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/location_bar_view_mac.h
diff options
context:
space:
mode:
authorpamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-14 23:13:44 +0000
committerpamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-14 23:13:44 +0000
commit3a5a6733f6226297c35dbdff21a5821921753bed (patch)
tree9d81e441b9c796a16818797ceb11f22fb3c0a645 /chrome/browser/cocoa/location_bar_view_mac.h
parent73fb91a959ad435a0fd95187c7b39ef41521d403 (diff)
downloadchromium_src-3a5a6733f6226297c35dbdff21a5821921753bed.zip
chromium_src-3a5a6733f6226297c35dbdff21a5821921753bed.tar.gz
chromium_src-3a5a6733f6226297c35dbdff21a5821921753bed.tar.bz2
First steps toward page actions on Mac. Page action icons shold show and
perform their click actions when clicked. This is very rough, being committed in an early form so more people can contribute to the effort. Includes some early work from andybons too, toward making popups work. Known issues: * Icons don't refresh properly when an extension is installed or removed. Switching windows, then back again, updates the location bar properly. * Right- and middle-clicks do nothing * No tooltips, badges, installation previews, or popups yet * No unit tests yet BUG=12281 TEST=none yet Review URL: http://codereview.chromium.org/427009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34509 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/location_bar_view_mac.h')
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h125
1 files changed, 120 insertions, 5 deletions
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
index 9d4f3b5..6426172 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -5,12 +5,17 @@
#ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
#define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
+#include <string>
+#include <map>
+#include <vector>
+
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
+#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/toolbar_model.h"
@@ -44,8 +49,8 @@ class LocationBarViewMac : public AutocompleteEditController,
virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition);
virtual void FocusLocation();
virtual void FocusSearch();
- virtual void UpdatePageActions() { /* http://crbug.com/12281 */ }
- virtual void InvalidatePageActions() { /* TODO(port): implement this */ }
+ virtual void UpdatePageActions();
+ virtual void InvalidatePageActions();
virtual void SaveStateToContents(TabContents* contents);
virtual void Revert();
virtual AutocompleteEditView* location_entry() {
@@ -98,6 +103,7 @@ class LocationBarViewMac : public AutocompleteEditController,
// Sets the image.
void SetImage(NSImage* image);
+ void SetImage(SkBitmap* image);
// Sets the label text, font, and color. |text| may be nil; |color| and
// |font| are ignored if |text| is nil.
@@ -111,8 +117,6 @@ class LocationBarViewMac : public AutocompleteEditController,
const NSAttributedString* GetLabel() const { return label_; }
bool IsVisible() const { return visible_; }
- virtual bool OnMousePressed() = 0;
-
private:
scoped_nsobject<NSImage> image_;
@@ -139,7 +143,7 @@ class LocationBarViewMac : public AutocompleteEditController,
// Sets the image to the appropriate icon.
void SetImageShown(Image image);
- // Shows the page info dialog.
+ // Shows the page info dialog. Virtual so it can be overridden for testing.
virtual bool OnMousePressed();
private:
@@ -157,6 +161,114 @@ class LocationBarViewMac : public AutocompleteEditController,
DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
};
+ // PageActionImageView is used to display the icon for a given Page Action
+ // and notify the extension when the icon is clicked.
+ class PageActionImageView : public LocationBarImageView,
+ public ImageLoadingTracker::Observer,
+ public NotificationObserver {
+ public:
+ PageActionImageView(LocationBarViewMac* owner,
+ Profile* profile,
+ ExtensionAction* page_action);
+ virtual ~PageActionImageView();
+
+ ExtensionAction* page_action() { return page_action_; }
+
+ int current_tab_id() { return current_tab_id_; }
+
+ void set_preview_enabled(bool preview_enabled) {
+ preview_enabled_ = preview_enabled;
+ }
+
+ // Either notify listeners or show a popup depending on the Page Action.
+ // Virtual so it can be overridden for testing.
+ virtual bool OnMousePressed(NSRect bounds);
+
+ // Overridden from ImageLoadingTracker.
+ virtual void OnImageLoaded(SkBitmap* image, size_t index);
+
+ // Called to notify the Page Action that it should determine whether to be
+ // visible or hidden. |contents| is the TabContents that is active, |url|
+ // is the current page URL.
+ void UpdateVisibility(TabContents* contents, const GURL& url);
+
+ private:
+ // Overridden from NotificationObserver:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // The location bar view that owns us.
+ LocationBarViewMac* owner_;
+
+ // The current profile (not owned by us).
+ Profile* profile_;
+
+ // The Page Action that this view represents. The Page Action is not owned
+ // by us, it resides in the extension of this particular profile.
+ ExtensionAction* page_action_;
+
+ // A cache of images the Page Actions might need to show, mapped by path.
+ typedef std::map<std::string, SkBitmap> PageActionMap;
+ PageActionMap page_action_icons_;
+
+ // The object that is waiting for the image loading to complete
+ // asynchronously.
+ ImageLoadingTracker* tracker_;
+
+ // The tab id we are currently showing the icon for.
+ int current_tab_id_;
+
+ // The URL we are currently showing the icon for.
+ GURL current_url_;
+
+ // The string to show for a tooltip.
+ std::string tooltip_;
+
+ // This is used for post-install visual feedback. The page_action icon
+ // is briefly shown even if it hasn't been enabled by it's extension.
+ bool preview_enabled_;
+
+ // Used to register for notifications received by NotificationObserver.
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PageActionImageView);
+ };
+
+ class PageActionViewList {
+ public:
+ PageActionViewList(LocationBarViewMac* location_bar,
+ Profile* profile,
+ ToolbarModel* toolbar_model)
+ : owner_(location_bar),
+ profile_(profile),
+ toolbar_model_(toolbar_model) {}
+
+ void DeleteAll();
+ void RefreshViews();
+
+ PageActionImageView* ViewAt(size_t index);
+
+ size_t Count();
+ size_t VisibleCount();
+
+ // Called when the action at |index| is clicked. The |iconFrame| should
+ // describe the bounds of the affected action's icon.
+ void OnMousePressed(NSRect iconFrame, size_t index);
+
+ private:
+ // Any installed Page Actions.
+ std::vector<PageActionImageView*> views_;
+
+ // The location bar view that owns us.
+ LocationBarViewMac* owner_;
+
+ Profile* profile_;
+ ToolbarModel* toolbar_model_;
+
+ DISALLOW_COPY_AND_ASSIGN(PageActionViewList);
+ };
+
private:
// Sets the SSL icon we should be showing.
void SetSecurityIcon(ToolbarModel::Icon icon);
@@ -181,6 +293,9 @@ class LocationBarViewMac : public AutocompleteEditController,
// The view that shows the lock/warning when in HTTPS mode.
SecurityImageView security_image_view_;
+ // Any installed Page Actions.
+ PageActionViewList* page_action_views_;
+
Profile* profile_;
ToolbarModel* toolbar_model_; // Weak, owned by Browser.