1 // Copyright 2014 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 COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_
6 #define COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_
8 #include "base/callback_list.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/supports_user_data.h"
12 #include "content/public/browser/host_zoom_map.h"
16 } // namespace content
20 class ZoomEventManagerObserver
;
22 // This class serves as a target for event notifications from all ZoomController
23 // objects. Classes that need to know about browser-specific zoom events (e.g.
24 // manual-mode zoom) should subscribe here.
25 class ZoomEventManager
: public base::SupportsUserData::Data
{
28 ~ZoomEventManager() override
;
30 // Returns the ZoomEventManager for the specified BrowserContext. This
31 // function creates the ZoomEventManager if it hasn't been created already.
32 static ZoomEventManager
* GetForBrowserContext(
33 content::BrowserContext
* context
);
35 // Called by ZoomControllers when changes are made to zoom levels in manual
36 // mode in order that browser listeners can be notified.
37 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange
& change
);
39 // Add and remove zoom level changed callbacks.
40 // TODO(wjmaclean): Convert this callback mechanism to use
41 // ZoomEventManagerObserver instead.
42 scoped_ptr
<content::HostZoomMap::Subscription
> AddZoomLevelChangedCallback(
43 const content::HostZoomMap::ZoomLevelChangedCallback
& callback
);
45 // Called by ZoomLevelDelegates when changes are made to the default zoom
46 // level for their associated HostZoomMap.
47 void OnDefaultZoomLevelChanged();
49 // Add and remove observers.
50 void AddZoomEventManagerObserver(ZoomEventManagerObserver
* observer
);
51 void RemoveZoomEventManagerObserver(ZoomEventManagerObserver
* observer
);
53 // Get a weak ptr to be used by clients who may themselves be UserData for
54 // the context, since the order of destruction is undefined between the client
56 base::WeakPtr
<ZoomEventManager
> GetWeakPtr() {
57 return weak_ptr_factory_
.GetWeakPtr();
61 base::CallbackList
<void(const content::HostZoomMap::ZoomLevelChange
&)>
62 zoom_level_changed_callbacks_
;
63 ObserverList
<ZoomEventManagerObserver
> observers_
;
64 base::WeakPtrFactory
<ZoomEventManager
> weak_ptr_factory_
;
66 DISALLOW_COPY_AND_ASSIGN(ZoomEventManager
);
69 } // namespace ui_zoom
71 #endif // COMPONENTS_UI_ZOOM_ZOOM_EVENT_MANAGER_H_