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_
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/location_bar/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 "components/content_settings/core/common/content_settings_types.h"
22 #include "components/ui/zoom/zoom_event_manager_observer.h"
24 @
class AutocompleteTextField
;
26 class ContentSettingDecoration
;
27 class EVBubbleDecoration
;
28 class GeneratedCreditCardDecoration
;
29 class KeywordHintDecoration
;
30 class LocationBarDecoration
;
31 class LocationIconDecoration
;
32 class ManagePasswordsDecoration
;
33 class MicSearchDecoration
;
34 class PageActionDecoration
;
36 class SelectedKeywordDecoration
;
38 class TranslateDecoration
;
40 class ZoomDecorationTest
;
42 // A C++ bridge class that represents the location bar UI element to
43 // the portable code. Wires up an OmniboxViewMac instance to
44 // the location bar text field, which handles most of the work.
46 class LocationBarViewMac
: public LocationBar
,
47 public LocationBarTesting
,
48 public OmniboxEditController
,
49 public SearchModelObserver
,
50 public ui_zoom::ZoomEventManagerObserver
{
52 LocationBarViewMac(AutocompleteTextField
* field
,
53 CommandUpdater
* command_updater
,
56 ~LocationBarViewMac() override
;
58 // Overridden from LocationBar:
59 void ShowFirstRunBubble() override
;
60 GURL
GetDestinationURL() const override
;
61 WindowOpenDisposition
GetWindowOpenDisposition() const override
;
62 ui::PageTransition
GetPageTransition() const override
;
63 void AcceptInput() override
;
64 void FocusLocation(bool select_all
) override
;
65 void FocusSearch() override
;
66 void UpdateContentSettingsIcons() override
;
67 void UpdateManagePasswordsIconAndBubble() override
;
68 void UpdatePageActions() override
;
69 void UpdateBookmarkStarVisibility() override
;
70 bool ShowPageActionPopup(const extensions::Extension
* extension
,
71 bool grant_active_tab
) override
;
72 void UpdateOpenPDFInReaderPrompt() override
;
73 void UpdateGeneratedCreditCardView() override
;
74 void SaveStateToContents(content::WebContents
* contents
) override
;
75 void Revert() override
;
76 const OmniboxView
* GetOmniboxView() const override
;
77 OmniboxView
* GetOmniboxView() override
;
78 LocationBarTesting
* GetLocationBarForTesting() override
;
80 // Overridden from LocationBarTesting:
81 int PageActionCount() override
;
82 int PageActionVisibleCount() override
;
83 ExtensionAction
* GetPageAction(size_t index
) override
;
84 ExtensionAction
* GetVisiblePageAction(size_t index
) override
;
85 void TestPageActionPressed(size_t index
) override
;
86 bool GetBookmarkStarVisibility() override
;
88 // Set/Get the editable state of the field.
89 void SetEditable(bool editable
);
92 // Set the starred state of the bookmark star.
93 void SetStarred(bool starred
);
95 // Set whether or not the translate icon is lit.
96 void SetTranslateIconLit(bool on
);
98 // Happens when the zoom changes for the active tab. |can_show_bubble| is
99 // false when the change in zoom for the active tab wasn't an explicit user
100 // action (e.g. switching tabs, creating a new tab, creating a new browser).
101 // Additionally, |can_show_bubble| will only be true when the bubble wouldn't
102 // be obscured by other UI (wrench menu) or redundant (+/- from wrench).
103 void ZoomChangedForActiveTab(bool can_show_bubble
);
105 // Checks if the bookmark star should be enabled or not.
106 bool IsStarEnabled() const;
108 // Get the point in window coordinates on the star for the bookmark bubble to
109 // aim at. Only works if IsStarEnabled returns YES.
110 NSPoint
GetBookmarkBubblePoint() const;
112 // Get the point in window coordinates on the star for the Translate bubble to
114 NSPoint
GetTranslateBubblePoint() const;
116 // Get the point in window coordinates in the lock icon for the Manage
117 // Passwords bubble to aim at.
118 NSPoint
GetManagePasswordsBubblePoint() const;
120 // Get the point in window coordinates in the security icon at which the page
122 NSPoint
GetPageInfoBubblePoint() const;
124 // Get the point in window coordinates in the "generated cc" icon at which the
125 // corresponding info bubble aims.
126 NSPoint
GetGeneratedCreditCardBubblePoint() const;
128 // When any image decorations change, call this to ensure everything is
129 // redrawn and laid out if necessary.
130 void OnDecorationsChanged();
132 // Layout the various decorations which live in the field.
135 // Re-draws |decoration| if it's already being displayed.
136 void RedrawDecoration(LocationBarDecoration
* decoration
);
138 // Sets preview_enabled_ for the PageActionImageView associated with this
139 // |page_action|. If |preview_enabled|, the location bar will display the
140 // PageAction icon even if it has not been activated by the extension.
141 // This is used by the ExtensionInstalledBubble to preview what the icon
142 // will look like for the user upon installation of the extension.
143 void SetPreviewEnabledPageAction(ExtensionAction
* page_action
,
144 bool preview_enabled
);
146 // Retrieve the frame for the given |page_action|.
147 NSRect
GetPageActionFrame(ExtensionAction
* page_action
);
149 // Return |page_action|'s info-bubble point in window coordinates.
150 // This function should always be called with a visible page action.
151 // If |page_action| is not a page action or not visible, NOTREACHED()
152 // is called and this function returns |NSZeroPoint|.
153 NSPoint
GetPageActionBubblePoint(ExtensionAction
* page_action
);
155 // Clears any location bar state stored for |contents|.
156 void ResetTabState(content::WebContents
* contents
);
158 // OmniboxEditController:
159 void Update(const content::WebContents
* contents
) override
;
160 void OnChanged() override
;
161 void OnSetFocus() override
;
162 void ShowURL() override
;
163 InstantController
* GetInstant() override
;
164 content::WebContents
* GetWebContents() override
;
165 ToolbarModel
* GetToolbarModel() override
;
166 const ToolbarModel
* GetToolbarModel() const override
;
168 NSImage
* GetKeywordImage(const base::string16
& keyword
);
170 AutocompleteTextField
* GetAutocompleteTextField() { return field_
; }
172 ManagePasswordsDecoration
* manage_passwords_decoration() {
173 return manage_passwords_decoration_
.get();
176 // SearchModelObserver:
177 void ModelChanged(const SearchModel::State
& old_state
,
178 const SearchModel::State
& new_state
) override
;
180 Browser
* browser() const { return browser_
; }
182 // ZoomManagerObserver:
183 // Updates the view for the zoom icon when default zoom levels change.
184 void OnDefaultZoomLevelChanged() override
;
187 friend ZoomDecorationTest
;
189 // Posts |notification| to the default notification center.
190 void PostNotification(NSString
* notification
);
192 // Return the decoration for |page_action|.
193 PageActionDecoration
* GetPageActionDecoration(ExtensionAction
* page_action
);
195 // Clear the page-action decorations.
196 void DeletePageActionDecorations();
198 void OnEditBookmarksEnabledChanged();
200 // Re-generate the page-action decorations from the profile's
201 // extension service.
202 void RefreshPageActionDecorations();
204 // Whether the page actions represented by |page_action_decorations_| differ
205 // in ordering or value from |page_actions|.
206 bool PageActionsDiffer(
207 const std::vector
<ExtensionAction
*>& page_actions
) const;
209 // Updates visibility of the content settings icons based on the current
210 // tab contents state.
211 bool RefreshContentSettingsDecorations();
213 void ShowFirstRunBubbleInternal();
215 // Updates the translate decoration in the omnibox with the current translate
217 void UpdateTranslateDecoration();
219 // Updates the zoom decoration in the omnibox with the current zoom level.
220 // Returns whether any updates were made.
221 bool UpdateZoomDecoration(bool default_zoom_changed
);
223 // Updates the voice search decoration. Returns true if the visible state was
225 bool UpdateMicSearchDecorationVisibility();
227 scoped_ptr
<OmniboxViewMac
> omnibox_view_
;
229 AutocompleteTextField
* field_
; // owned by tab controller
231 // A decoration that shows an icon to the left of the address.
232 scoped_ptr
<LocationIconDecoration
> location_icon_decoration_
;
234 // A decoration that shows the keyword-search bubble on the left.
235 scoped_ptr
<SelectedKeywordDecoration
> selected_keyword_decoration_
;
237 // A decoration that shows a lock icon and ev-cert label in a bubble
239 scoped_ptr
<EVBubbleDecoration
> ev_bubble_decoration_
;
241 // Bookmark star right of page actions.
242 scoped_ptr
<StarDecoration
> star_decoration_
;
244 // Translate icon at the end of the ominibox.
245 scoped_ptr
<TranslateDecoration
> translate_decoration_
;
247 // A zoom icon at the end of the omnibox, which shows at non-standard zoom
249 scoped_ptr
<ZoomDecoration
> zoom_decoration_
;
251 // Decorations for the installed Page Actions.
252 ScopedVector
<PageActionDecoration
> page_action_decorations_
;
254 // The content blocked decorations.
255 ScopedVector
<ContentSettingDecoration
> content_setting_decorations_
;
257 // Keyword hint decoration displayed on the right-hand side.
258 scoped_ptr
<KeywordHintDecoration
> keyword_hint_decoration_
;
260 // The voice search icon.
261 scoped_ptr
<MicSearchDecoration
> mic_search_decoration_
;
263 // Generated CC hint decoration.
264 scoped_ptr
<GeneratedCreditCardDecoration
> generated_credit_card_decoration_
;
266 // The right-hand-side button to manage passwords associated with a page.
267 scoped_ptr
<ManagePasswordsDecoration
> manage_passwords_decoration_
;
271 // Used to change the visibility of the star decoration.
272 BooleanPrefMember edit_bookmarks_enabled_
;
274 // Used to schedule a task for the first run info bubble.
275 base::WeakPtrFactory
<LocationBarViewMac
> weak_ptr_factory_
;
277 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac
);
280 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_VIEW_MAC_H_