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