blob: 1dd7809c84c59acb7ebbfbf7f5bb0bf95d1ff318 [file] [log] [blame]
[email protected]6f80e932012-06-04 19:00:071// 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.
4
5#ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
6#define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
[email protected]6f80e932012-06-04 19:00:077
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
[email protected]0abb67122012-12-12 11:36:0510#include "base/prefs/public/pref_member.h"
[email protected]6f80e932012-06-04 19:00:0711#include "content/public/browser/notification_observer.h"
12#include "content/public/browser/notification_registrar.h"
13#include "content/public/browser/web_contents_observer.h"
[email protected]46b3c982012-10-09 18:38:3014#include "content/public/browser/web_contents_user_data.h"
[email protected]6f80e932012-06-04 19:00:0715
[email protected]ff3d94e2012-12-18 07:16:3116class ZoomObserver;
17
[email protected]dea9cee82012-09-25 03:10:5218namespace content {
19class WebContents;
20}
21
[email protected]6f80e932012-06-04 19:00:0722// Per-tab class to manage the Omnibox zoom icon.
23class ZoomController : public content::NotificationObserver,
[email protected]dea9cee82012-09-25 03:10:5224 public content::WebContentsObserver,
[email protected]46b3c982012-10-09 18:38:3025 public content::WebContentsUserData<ZoomController> {
[email protected]6f80e932012-06-04 19:00:0726 public:
[email protected]6f80e932012-06-04 19:00:0727 virtual ~ZoomController();
28
[email protected]6f80e932012-06-04 19:00:0729 int zoom_percent() const { return zoom_percent_; }
30
[email protected]5423c372012-08-22 05:50:1631 // Convenience method to quickly check if the tab's at default zoom.
32 bool IsAtDefaultZoom() const;
33
34 // Returns which image should be loaded for the current zoom level.
35 int GetResourceForZoomLevel() const;
36
[email protected]6f80e932012-06-04 19:00:0737 void set_observer(ZoomObserver* observer) { observer_ = observer; }
38
[email protected]6f80e932012-06-04 19:00:0739 // content::WebContentsObserver overrides:
40 virtual void DidNavigateMainFrame(
41 const content::LoadCommittedDetails& details,
42 const content::FrameNavigateParams& params) OVERRIDE;
43
44 // content::NotificationObserver overrides:
45 virtual void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) OVERRIDE;
48
[email protected]550fd3772012-11-20 01:06:0249 private:
50 explicit ZoomController(content::WebContents* web_contents);
51 friend class content::WebContentsUserData<ZoomController>;
52 friend class ZoomControllerTest;
53
[email protected]6f80e932012-06-04 19:00:0754 // Updates the zoom icon and zoom percentage based on current values and
[email protected]9a8408902012-09-26 16:17:5955 // notifies the observer if changes have occurred. |host| may be empty,
56 // meaning the change should apply to ~all sites. If it is not empty, the
57 // change only affects sites with the given host.
58 void UpdateState(const std::string& host);
[email protected]6f80e932012-06-04 19:00:0759
[email protected]6f80e932012-06-04 19:00:0760 // The current zoom percentage.
61 int zoom_percent_;
62
63 content::NotificationRegistrar registrar_;
64
65 // Used to access the default zoom level preference.
66 DoublePrefMember default_zoom_level_;
67
[email protected]6f80e932012-06-04 19:00:0768 // Observer receiving notifications on state changes.
69 ZoomObserver* observer_;
70
[email protected]6f80e932012-06-04 19:00:0771 DISALLOW_COPY_AND_ASSIGN(ZoomController);
72};
73
74#endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_