Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / location_bar / location_bar_view_mac.h
blobbda15ea65f94d1b4f57139040d728ebc49ba6a10
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_LOCATION_BAR_VIEW_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_VIEW_MAC_H_
8 #include <string>
10 #import <Cocoa/Cocoa.h>
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/prefs/pref_member.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
18 #include "chrome/browser/ui/omnibox/location_bar.h"
19 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
20 #include "chrome/browser/ui/search/search_model_observer.h"
21 #include "chrome/common/content_settings_types.h"
23 @class AutocompleteTextField;
24 class CommandUpdater;
25 class ContentSettingDecoration;
26 class EVBubbleDecoration;
27 class GeneratedCreditCardDecoration;
28 class KeywordHintDecoration;
29 class LocationBarDecoration;
30 class LocationIconDecoration;
31 class MicSearchDecoration;
32 class PageActionDecoration;
33 class Profile;
34 class SearchButtonDecoration;
35 class SelectedKeywordDecoration;
36 class StarDecoration;
37 class ZoomDecoration;
38 class ZoomDecorationTest;
40 // A C++ bridge class that represents the location bar UI element to
41 // the portable code. Wires up an OmniboxViewMac instance to
42 // the location bar text field, which handles most of the work.
44 class LocationBarViewMac : public LocationBar,
45 public LocationBarTesting,
46 public OmniboxEditController,
47 public content::NotificationObserver,
48 public SearchModelObserver {
49 public:
50 LocationBarViewMac(AutocompleteTextField* field,
51 CommandUpdater* command_updater,
52 Profile* profile,
53 Browser* browser);
54 virtual ~LocationBarViewMac();
56 // Overridden from LocationBar:
57 virtual void ShowFirstRunBubble() OVERRIDE;
58 virtual GURL GetDestinationURL() const OVERRIDE;
59 virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE;
60 virtual content::PageTransition GetPageTransition() const OVERRIDE;
61 virtual void AcceptInput() OVERRIDE;
62 virtual void FocusLocation(bool select_all) OVERRIDE;
63 virtual void FocusSearch() OVERRIDE;
64 virtual void UpdateContentSettingsIcons() OVERRIDE;
65 virtual void UpdateManagePasswordsIconAndBubble() OVERRIDE {};
66 virtual void UpdatePageActions() OVERRIDE;
67 virtual void InvalidatePageActions() OVERRIDE;
68 virtual void UpdateOpenPDFInReaderPrompt() OVERRIDE;
69 virtual void UpdateGeneratedCreditCardView() OVERRIDE;
70 virtual void SaveStateToContents(content::WebContents* contents) OVERRIDE;
71 virtual void Revert() OVERRIDE;
72 virtual const OmniboxView* GetOmniboxView() const OVERRIDE;
73 virtual OmniboxView* GetOmniboxView() OVERRIDE;
74 virtual LocationBarTesting* GetLocationBarForTesting() OVERRIDE;
76 // Overridden from LocationBarTesting:
77 virtual int PageActionCount() OVERRIDE;
78 virtual int PageActionVisibleCount() OVERRIDE;
79 virtual ExtensionAction* GetPageAction(size_t index) OVERRIDE;
80 virtual ExtensionAction* GetVisiblePageAction(size_t index) OVERRIDE;
81 virtual void TestPageActionPressed(size_t index) OVERRIDE;
82 virtual bool GetBookmarkStarVisibility() OVERRIDE;
84 // Set/Get the editable state of the field.
85 void SetEditable(bool editable);
86 bool IsEditable();
88 // Set the starred state of the bookmark star.
89 void SetStarred(bool starred);
91 // Happens when the zoom changes for the active tab. |can_show_bubble| is
92 // false when the change in zoom for the active tab wasn't an explicit user
93 // action (e.g. switching tabs, creating a new tab, creating a new browser).
94 // Additionally, |can_show_bubble| will only be true when the bubble wouldn't
95 // be obscured by other UI (wrench menu) or redundant (+/- from wrench).
96 void ZoomChangedForActiveTab(bool can_show_bubble);
98 // Checks if the bookmark star should be enabled or not.
99 bool IsStarEnabled() const;
101 // Get the point in window coordinates on the star for the bookmark bubble to
102 // aim at. Only works if IsStarEnabled returns YES.
103 NSPoint GetBookmarkBubblePoint() const;
105 // Get the point in window coordinates in the security icon at which the page
106 // info bubble aims.
107 NSPoint GetPageInfoBubblePoint() const;
109 // Get the point in window coordinates in the "generated cc" icon at which the
110 // corresponding info bubble aims.
111 NSPoint GetGeneratedCreditCardBubblePoint() const;
113 // When any image decorations change, call this to ensure everything is
114 // redrawn and laid out if necessary.
115 void OnDecorationsChanged();
117 // Layout the various decorations which live in the field.
118 void Layout();
120 // Re-draws |decoration| if it's already being displayed.
121 void RedrawDecoration(LocationBarDecoration* decoration);
123 // Sets preview_enabled_ for the PageActionImageView associated with this
124 // |page_action|. If |preview_enabled|, the location bar will display the
125 // PageAction icon even if it has not been activated by the extension.
126 // This is used by the ExtensionInstalledBubble to preview what the icon
127 // will look like for the user upon installation of the extension.
128 void SetPreviewEnabledPageAction(ExtensionAction* page_action,
129 bool preview_enabled);
131 // Retrieve the frame for the given |page_action|.
132 NSRect GetPageActionFrame(ExtensionAction* page_action);
134 // Return |page_action|'s info-bubble point in window coordinates.
135 // This function should always be called with a visible page action.
136 // If |page_action| is not a page action or not visible, NOTREACHED()
137 // is called and this function returns |NSZeroPoint|.
138 NSPoint GetPageActionBubblePoint(ExtensionAction* page_action);
140 // OmniboxEditController:
141 virtual void Update(const content::WebContents* contents) OVERRIDE;
142 virtual void OnChanged() OVERRIDE;
143 virtual void OnSetFocus() OVERRIDE;
144 virtual InstantController* GetInstant() OVERRIDE;
145 virtual content::WebContents* GetWebContents() OVERRIDE;
146 virtual ToolbarModel* GetToolbarModel() OVERRIDE;
147 virtual const ToolbarModel* GetToolbarModel() const OVERRIDE;
149 NSImage* GetKeywordImage(const base::string16& keyword);
151 AutocompleteTextField* GetAutocompleteTextField() { return field_; }
154 // content::NotificationObserver:
155 virtual void Observe(int type,
156 const content::NotificationSource& source,
157 const content::NotificationDetails& details) OVERRIDE;
159 // SearchModelObserver:
160 virtual void ModelChanged(const SearchModel::State& old_state,
161 const SearchModel::State& new_state) OVERRIDE;
163 Browser* browser() const { return browser_; }
165 private:
166 friend ZoomDecorationTest;
168 // Posts |notification| to the default notification center.
169 void PostNotification(NSString* notification);
171 // Return the decoration for |page_action|.
172 PageActionDecoration* GetPageActionDecoration(ExtensionAction* page_action);
174 // Clear the page-action decorations.
175 void DeletePageActionDecorations();
177 void OnEditBookmarksEnabledChanged();
179 // Re-generate the page-action decorations from the profile's
180 // extension service.
181 void RefreshPageActionDecorations();
183 // Updates visibility of the content settings icons based on the current
184 // tab contents state.
185 bool RefreshContentSettingsDecorations();
187 void ShowFirstRunBubbleInternal();
189 // Updates the zoom decoration in the omnibox with the current zoom level.
190 void UpdateZoomDecoration();
192 // Ensures the star decoration is visible or hidden, as required.
193 void UpdateStarDecorationVisibility();
195 // Updates the voice search decoration. Returns true if the visible state was
196 // changed.
197 bool UpdateMicSearchDecorationVisibility();
199 scoped_ptr<OmniboxViewMac> omnibox_view_;
201 AutocompleteTextField* field_; // owned by tab controller
203 // A decoration that shows an icon to the left of the address.
204 scoped_ptr<LocationIconDecoration> location_icon_decoration_;
206 // A decoration that shows the keyword-search bubble on the left.
207 scoped_ptr<SelectedKeywordDecoration> selected_keyword_decoration_;
209 // A decoration that shows a lock icon and ev-cert label in a bubble
210 // on the left.
211 scoped_ptr<EVBubbleDecoration> ev_bubble_decoration_;
213 // Bookmark star right of page actions.
214 scoped_ptr<StarDecoration> star_decoration_;
216 // A zoom icon at the end of the omnibox, which shows at non-standard zoom
217 // levels.
218 scoped_ptr<ZoomDecoration> zoom_decoration_;
220 // The installed page actions.
221 std::vector<ExtensionAction*> page_actions_;
223 // Decorations for the installed Page Actions.
224 ScopedVector<PageActionDecoration> page_action_decorations_;
226 // The content blocked decorations.
227 ScopedVector<ContentSettingDecoration> content_setting_decorations_;
229 // Keyword hint decoration displayed on the right-hand side.
230 scoped_ptr<KeywordHintDecoration> keyword_hint_decoration_;
232 // The voice search icon.
233 scoped_ptr<MicSearchDecoration> mic_search_decoration_;
235 // Generated CC hint decoration.
236 scoped_ptr<GeneratedCreditCardDecoration> generated_credit_card_decoration_;
238 // The right-hand-side search button that is shown on search result pages.
239 scoped_ptr<SearchButtonDecoration> search_button_decoration_;
241 Browser* browser_;
243 // Used to register for notifications received by NotificationObserver.
244 content::NotificationRegistrar registrar_;
246 // Used to schedule a task for the first run info bubble.
247 base::WeakPtrFactory<LocationBarViewMac> weak_ptr_factory_;
249 // Used to change the visibility of the star decoration.
250 BooleanPrefMember edit_bookmarks_enabled_;
252 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
255 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_VIEW_MAC_H_