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/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
;
25 class ContentSettingDecoration
;
26 class EVBubbleDecoration
;
27 class GeneratedCreditCardDecoration
;
28 class KeywordHintDecoration
;
29 class LocationBarDecoration
;
30 class LocationIconDecoration
;
31 class MicSearchDecoration
;
32 class OriginChipDecoration
;
33 class PageActionDecoration
;
35 class SearchButtonDecoration
;
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 content::NotificationObserver
,
50 public SearchModelObserver
{
52 LocationBarViewMac(AutocompleteTextField
* field
,
53 CommandUpdater
* command_updater
,
56 virtual ~LocationBarViewMac();
58 // Overridden from LocationBar:
59 virtual void ShowFirstRunBubble() OVERRIDE
;
60 virtual GURL
GetDestinationURL() const OVERRIDE
;
61 virtual WindowOpenDisposition
GetWindowOpenDisposition() const OVERRIDE
;
62 virtual content::PageTransition
GetPageTransition() const OVERRIDE
;
63 virtual void AcceptInput() OVERRIDE
;
64 virtual void FocusLocation(bool select_all
) OVERRIDE
;
65 virtual void FocusSearch() OVERRIDE
;
66 virtual void UpdateContentSettingsIcons() OVERRIDE
;
67 virtual void UpdateManagePasswordsIconAndBubble() OVERRIDE
{};
68 virtual void UpdatePageActions() OVERRIDE
;
69 virtual void InvalidatePageActions() OVERRIDE
;
70 virtual void UpdateOpenPDFInReaderPrompt() OVERRIDE
;
71 virtual void UpdateGeneratedCreditCardView() OVERRIDE
;
72 virtual void SaveStateToContents(content::WebContents
* contents
) OVERRIDE
;
73 virtual void Revert() OVERRIDE
;
74 virtual const OmniboxView
* GetOmniboxView() const OVERRIDE
;
75 virtual OmniboxView
* GetOmniboxView() OVERRIDE
;
76 virtual LocationBarTesting
* GetLocationBarForTesting() OVERRIDE
;
78 // Overridden from LocationBarTesting:
79 virtual int PageActionCount() OVERRIDE
;
80 virtual int PageActionVisibleCount() OVERRIDE
;
81 virtual ExtensionAction
* GetPageAction(size_t index
) OVERRIDE
;
82 virtual ExtensionAction
* GetVisiblePageAction(size_t index
) OVERRIDE
;
83 virtual void TestPageActionPressed(size_t index
) OVERRIDE
;
84 virtual bool GetBookmarkStarVisibility() OVERRIDE
;
86 // Set/Get the editable state of the field.
87 void SetEditable(bool editable
);
90 // Set the starred state of the bookmark star.
91 void SetStarred(bool starred
);
93 // Set whether or not the translate icon is lit.
94 void SetTranslateIconLit(bool on
);
96 // Happens when the zoom changes for the active tab. |can_show_bubble| is
97 // false when the change in zoom for the active tab wasn't an explicit user
98 // action (e.g. switching tabs, creating a new tab, creating a new browser).
99 // Additionally, |can_show_bubble| will only be true when the bubble wouldn't
100 // be obscured by other UI (wrench menu) or redundant (+/- from wrench).
101 void ZoomChangedForActiveTab(bool can_show_bubble
);
103 // Checks if the bookmark star should be enabled or not.
104 bool IsStarEnabled() const;
106 // Get the point in window coordinates on the star for the bookmark bubble to
107 // aim at. Only works if IsStarEnabled returns YES.
108 NSPoint
GetBookmarkBubblePoint() const;
110 // Get the point in window coordinates on the star for the Translate bubble to
112 NSPoint
GetTranslateBubblePoint() const;
114 // Get the point in window coordinates in the security icon at which the page
116 NSPoint
GetPageInfoBubblePoint() const;
118 // Get the point in window coordinates in the "generated cc" icon at which the
119 // corresponding info bubble aims.
120 NSPoint
GetGeneratedCreditCardBubblePoint() const;
122 // When any image decorations change, call this to ensure everything is
123 // redrawn and laid out if necessary.
124 void OnDecorationsChanged();
126 // Layout the various decorations which live in the field.
129 // Re-draws |decoration| if it's already being displayed.
130 void RedrawDecoration(LocationBarDecoration
* decoration
);
132 // Sets preview_enabled_ for the PageActionImageView associated with this
133 // |page_action|. If |preview_enabled|, the location bar will display the
134 // PageAction icon even if it has not been activated by the extension.
135 // This is used by the ExtensionInstalledBubble to preview what the icon
136 // will look like for the user upon installation of the extension.
137 void SetPreviewEnabledPageAction(ExtensionAction
* page_action
,
138 bool preview_enabled
);
140 // Retrieve the frame for the given |page_action|.
141 NSRect
GetPageActionFrame(ExtensionAction
* page_action
);
143 // Return |page_action|'s info-bubble point in window coordinates.
144 // This function should always be called with a visible page action.
145 // If |page_action| is not a page action or not visible, NOTREACHED()
146 // is called and this function returns |NSZeroPoint|.
147 NSPoint
GetPageActionBubblePoint(ExtensionAction
* page_action
);
149 // OmniboxEditController:
150 virtual void Update(const content::WebContents
* contents
) OVERRIDE
;
151 virtual void OnChanged() OVERRIDE
;
152 virtual void OnSetFocus() OVERRIDE
;
153 virtual void ShowURL() OVERRIDE
;
154 virtual InstantController
* GetInstant() OVERRIDE
;
155 virtual content::WebContents
* GetWebContents() OVERRIDE
;
156 virtual ToolbarModel
* GetToolbarModel() OVERRIDE
;
157 virtual const ToolbarModel
* GetToolbarModel() const OVERRIDE
;
159 NSImage
* GetKeywordImage(const base::string16
& keyword
);
161 AutocompleteTextField
* GetAutocompleteTextField() { return field_
; }
164 // content::NotificationObserver:
165 virtual void Observe(int type
,
166 const content::NotificationSource
& source
,
167 const content::NotificationDetails
& details
) OVERRIDE
;
169 // SearchModelObserver:
170 virtual void ModelChanged(const SearchModel::State
& old_state
,
171 const SearchModel::State
& new_state
) OVERRIDE
;
173 Browser
* browser() const { return browser_
; }
175 // Activates the page action for the extension that has the given id.
176 void ActivatePageAction(const std::string
& extension_id
);
179 // OmniboxEditController:
180 virtual void HideURL() OVERRIDE
;
183 friend ZoomDecorationTest
;
185 // Posts |notification| to the default notification center.
186 void PostNotification(NSString
* notification
);
188 // Return the decoration for |page_action|.
189 PageActionDecoration
* GetPageActionDecoration(ExtensionAction
* page_action
);
191 // Clear the page-action decorations.
192 void DeletePageActionDecorations();
194 void OnEditBookmarksEnabledChanged();
196 // Re-generate the page-action decorations from the profile's
197 // extension service.
198 void RefreshPageActionDecorations();
200 // Updates visibility of the content settings icons based on the current
201 // tab contents state.
202 bool RefreshContentSettingsDecorations();
204 void ShowFirstRunBubbleInternal();
206 // Updates the translate decoration in the omnibox with the current translate
208 void UpdateTranslateDecoration();
210 // Updates the zoom decoration in the omnibox with the current zoom level.
211 void UpdateZoomDecoration();
213 // Ensures the star decoration is visible or hidden, as required.
214 void UpdateStarDecorationVisibility();
216 // Updates the voice search decoration. Returns true if the visible state was
218 bool UpdateMicSearchDecorationVisibility();
220 scoped_ptr
<OmniboxViewMac
> omnibox_view_
;
222 AutocompleteTextField
* field_
; // owned by tab controller
224 // A decoration that shows an icon to the left of the address.
225 scoped_ptr
<LocationIconDecoration
> location_icon_decoration_
;
227 // A decoration that shows the keyword-search bubble on the left.
228 scoped_ptr
<SelectedKeywordDecoration
> selected_keyword_decoration_
;
230 // A decoration that shows a lock icon and ev-cert label in a bubble
232 scoped_ptr
<EVBubbleDecoration
> ev_bubble_decoration_
;
234 // Bookmark star right of page actions.
235 scoped_ptr
<StarDecoration
> star_decoration_
;
237 // Translate icon at the end of the ominibox.
238 scoped_ptr
<TranslateDecoration
> translate_decoration_
;
240 // A zoom icon at the end of the omnibox, which shows at non-standard zoom
242 scoped_ptr
<ZoomDecoration
> zoom_decoration_
;
244 // The installed page actions.
245 std::vector
<ExtensionAction
*> page_actions_
;
247 // Decorations for the installed Page Actions.
248 ScopedVector
<PageActionDecoration
> page_action_decorations_
;
250 // The content blocked decorations.
251 ScopedVector
<ContentSettingDecoration
> content_setting_decorations_
;
253 // Keyword hint decoration displayed on the right-hand side.
254 scoped_ptr
<KeywordHintDecoration
> keyword_hint_decoration_
;
256 // The voice search icon.
257 scoped_ptr
<MicSearchDecoration
> mic_search_decoration_
;
259 // Generated CC hint decoration.
260 scoped_ptr
<GeneratedCreditCardDecoration
> generated_credit_card_decoration_
;
262 // The right-hand-side search button that is shown on search result pages.
263 scoped_ptr
<SearchButtonDecoration
> search_button_decoration_
;
265 // The left-hand-side origin chip.
266 scoped_ptr
<OriginChipDecoration
> origin_chip_decoration_
;
270 // Used to register for notifications received by NotificationObserver.
271 content::NotificationRegistrar registrar_
;
273 // Used to schedule a task for the first run info bubble.
274 base::WeakPtrFactory
<LocationBarViewMac
> weak_ptr_factory_
;
276 // Used to change the visibility of the star decoration.
277 BooleanPrefMember edit_bookmarks_enabled_
;
279 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac
);
282 #endif // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_LOCATION_BAR_VIEW_MAC_H_