• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_COCOA_LOCATION_BAR_VIEW_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_VIEW_MAC_H_
7 #pragma once
8 
9 #include <string>
10 
11 #import <Cocoa/Cocoa.h>
12 
13 #include "base/memory/scoped_nsobject.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "chrome/browser/autocomplete/autocomplete_edit.h"
17 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
18 #include "chrome/browser/extensions/image_loading_tracker.h"
19 #include "chrome/browser/first_run/first_run.h"
20 #include "chrome/browser/prefs/pref_member.h"
21 #include "chrome/browser/ui/omnibox/location_bar.h"
22 #include "chrome/browser/ui/toolbar/toolbar_model.h"
23 #include "chrome/common/content_settings_types.h"
24 
25 @class AutocompleteTextField;
26 class CommandUpdater;
27 class ContentSettingDecoration;
28 class ContentSettingImageModel;
29 class EVBubbleDecoration;
30 @class ExtensionPopupController;
31 class KeywordHintDecoration;
32 class LocationIconDecoration;
33 class PageActionDecoration;
34 class Profile;
35 class SelectedKeywordDecoration;
36 class SkBitmap;
37 class StarDecoration;
38 class ToolbarModel;
39 
40 // A C++ bridge class that represents the location bar UI element to
41 // the portable code.  Wires up an AutocompleteEditViewMac instance to
42 // the location bar text field, which handles most of the work.
43 
44 class LocationBarViewMac : public AutocompleteEditController,
45                            public LocationBar,
46                            public LocationBarTesting,
47                            public NotificationObserver {
48  public:
49   LocationBarViewMac(AutocompleteTextField* field,
50                      CommandUpdater* command_updater,
51                      ToolbarModel* toolbar_model,
52                      Profile* profile,
53                      Browser* browser);
54   virtual ~LocationBarViewMac();
55 
56   // Overridden from LocationBar:
57   virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type);
58   virtual void SetSuggestedText(const string16& text,
59                                 InstantCompleteBehavior behavior);
60   virtual std::wstring GetInputString() const;
61   virtual WindowOpenDisposition GetWindowOpenDisposition() const;
62   virtual PageTransition::Type GetPageTransition() const;
63   virtual void AcceptInput();
64   virtual void FocusLocation(bool select_all);
65   virtual void FocusSearch();
66   virtual void UpdateContentSettingsIcons();
67   virtual void UpdatePageActions();
68   virtual void InvalidatePageActions();
69   virtual void SaveStateToContents(TabContents* contents);
70   virtual void Revert();
71   virtual const AutocompleteEditView* location_entry() const;
72   virtual AutocompleteEditView* location_entry();
73   virtual LocationBarTesting* GetLocationBarForTesting();
74 
75   // Overridden from LocationBarTesting:
76   virtual int PageActionCount();
77   virtual int PageActionVisibleCount();
78   virtual ExtensionAction* GetPageAction(size_t index);
79   virtual ExtensionAction* GetVisiblePageAction(size_t index);
80   virtual void TestPageActionPressed(size_t index);
81 
82   // Set/Get the editable state of the field.
83   void SetEditable(bool editable);
84   bool IsEditable();
85 
86   // Set the starred state of the bookmark star.
87   void SetStarred(bool starred);
88 
89   // Get the point on the star for the bookmark bubble to aim at.
90   NSPoint GetBookmarkBubblePoint() const;
91 
92   // Get the point in the security icon at which the page info bubble aims.
93   NSPoint GetPageInfoBubblePoint() const;
94 
95   // Get the point in the omnibox at which the first run bubble aims.
96   NSPoint GetFirstRunBubblePoint() const;
97 
98   // Updates the location bar.  Resets the bar's permanent text and
99   // security style, and if |should_restore_state| is true, restores
100   // saved state from the tab (for tab switching).
101   void Update(const TabContents* tab, bool should_restore_state);
102 
103   // Layout the various decorations which live in the field.
104   void Layout();
105 
106   // Returns the current TabContents.
107   TabContents* GetTabContents() const;
108 
109   // Sets preview_enabled_ for the PageActionImageView associated with this
110   // |page_action|. If |preview_enabled|, the location bar will display the
111   // PageAction icon even if it has not been activated by the extension.
112   // This is used by the ExtensionInstalledBubble to preview what the icon
113   // will look like for the user upon installation of the extension.
114   void SetPreviewEnabledPageAction(ExtensionAction* page_action,
115                                    bool preview_enabled);
116 
117   // Return |page_action|'s info-bubble point in window coordinates.
118   // This function should always be called with a visible page action.
119   // If |page_action| is not a page action or not visible, NOTREACHED()
120   // is called and this function returns |NSZeroPoint|.
121   NSPoint GetPageActionBubblePoint(ExtensionAction* page_action);
122 
123   // Get the blocked-popup content setting's frame in window
124   // coordinates.  Used by the blocked-popup animation.  Returns
125   // |NSZeroRect| if the relevant content setting decoration is not
126   // visible.
127   NSRect GetBlockedPopupRect() const;
128 
129   // AutocompleteEditController implementation.
130   virtual void OnAutocompleteAccept(const GURL& url,
131       WindowOpenDisposition disposition,
132       PageTransition::Type transition,
133       const GURL& alternate_nav_url);
134   virtual void OnChanged();
135   virtual void OnSelectionBoundsChanged();
136   virtual void OnInputInProgress(bool in_progress);
137   virtual void OnKillFocus();
138   virtual void OnSetFocus();
139   virtual SkBitmap GetFavicon() const;
140   virtual string16 GetTitle() const;
141   virtual InstantController* GetInstant();
142   virtual TabContentsWrapper* GetTabContentsWrapper() const;
143 
144   NSImage* GetKeywordImage(const string16& keyword);
145 
GetAutocompleteTextField()146   AutocompleteTextField* GetAutocompleteTextField() { return field_; }
147 
148 
149   // Overridden from NotificationObserver.
150   virtual void Observe(NotificationType type,
151                        const NotificationSource& source,
152                        const NotificationDetails& details);
153 
154  private:
155   // Posts |notification| to the default notification center.
156   void PostNotification(NSString* notification);
157 
158   // Return the decoration for |page_action|.
159   PageActionDecoration* GetPageActionDecoration(ExtensionAction* page_action);
160 
161   // Clear the page-action decorations.
162   void DeletePageActionDecorations();
163 
164   // Re-generate the page-action decorations from the profile's
165   // extension service.
166   void RefreshPageActionDecorations();
167 
168   // Updates visibility of the content settings icons based on the current
169   // tab contents state.
170   bool RefreshContentSettingsDecorations();
171 
172   void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type);
173 
174   // Checks if the bookmark star should be enabled or not.
175   bool IsStarEnabled();
176 
177   scoped_ptr<AutocompleteEditViewMac> edit_view_;
178 
179   CommandUpdater* command_updater_;  // Weak, owned by Browser.
180 
181   AutocompleteTextField* field_;  // owned by tab controller
182 
183   // When we get an OnAutocompleteAccept notification from the autocomplete
184   // edit, we save the input string so we can give it back to the browser on
185   // the LocationBar interface via GetInputString().
186   std::wstring location_input_;
187 
188   // The user's desired disposition for how their input should be opened.
189   WindowOpenDisposition disposition_;
190 
191   // A decoration that shows an icon to the left of the address.
192   scoped_ptr<LocationIconDecoration> location_icon_decoration_;
193 
194   // A decoration that shows the keyword-search bubble on the left.
195   scoped_ptr<SelectedKeywordDecoration> selected_keyword_decoration_;
196 
197   // A decoration that shows a lock icon and ev-cert label in a bubble
198   // on the left.
199   scoped_ptr<EVBubbleDecoration> ev_bubble_decoration_;
200 
201   // Bookmark star right of page actions.
202   scoped_ptr<StarDecoration> star_decoration_;
203 
204   // Any installed Page Actions.
205   ScopedVector<PageActionDecoration> page_action_decorations_;
206 
207   // The content blocked decorations.
208   ScopedVector<ContentSettingDecoration> content_setting_decorations_;
209 
210   // Keyword hint decoration displayed on the right-hand side.
211   scoped_ptr<KeywordHintDecoration> keyword_hint_decoration_;
212 
213   Profile* profile_;
214 
215   Browser* browser_;
216 
217   ToolbarModel* toolbar_model_;  // Weak, owned by Browser.
218 
219   // The transition type to use for the navigation.
220   PageTransition::Type transition_;
221 
222   // Used to register for notifications received by NotificationObserver.
223   NotificationRegistrar registrar_;
224 
225   // Used to schedule a task for the first run info bubble.
226   ScopedRunnableMethodFactory<LocationBarViewMac> first_run_bubble_;
227 
228   // Used to change the visibility of the star decoration.
229   BooleanPrefMember edit_bookmarks_enabled_;
230 
231   DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
232 };
233 
234 #endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_VIEW_MAC_H_
235