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 #include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h"
8 #include "components/ui/zoom/zoom_event_manager.h"
10 ChromeZoomLevelOTRDelegate::ChromeZoomLevelOTRDelegate(
11 base::WeakPtr
<ui_zoom::ZoomEventManager
> zoom_event_manager
)
12 : zoom_event_manager_(zoom_event_manager
), host_zoom_map_(nullptr) {
15 ChromeZoomLevelOTRDelegate::~ChromeZoomLevelOTRDelegate() {
18 void ChromeZoomLevelOTRDelegate::InitHostZoomMap(
19 content::HostZoomMap
* host_zoom_map
) {
20 // This init function must be called only once.
21 DCHECK(!host_zoom_map_
);
22 DCHECK(host_zoom_map
);
23 host_zoom_map_
= host_zoom_map
;
25 zoom_subscription_
= host_zoom_map_
->AddZoomLevelChangedCallback(base::Bind(
26 &ChromeZoomLevelOTRDelegate::OnZoomLevelChanged
, base::Unretained(this)));
29 void ChromeZoomLevelOTRDelegate::OnZoomLevelChanged(
30 const content::HostZoomMap::ZoomLevelChange
& change
) {
31 // If there's a manager to aggregate ZoomLevelChanged events, pass this event
32 // along. Since we already hold a subscription to our associated HostZoomMap,
33 // we don't need to create a separate subscription for this.
34 if (zoom_event_manager_
)
35 zoom_event_manager_
->OnZoomLevelChanged(change
);