[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | ||||
6 | #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | ||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 7 | |
8 | #include "base/basictypes.h" | ||||
9 | #include "base/compiler_specific.h" | ||||
[email protected] | 0abb6712 | 2012-12-12 11:36:05 | [diff] [blame] | 10 | #include "base/prefs/public/pref_member.h" |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 11 | #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] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 14 | #include "content/public/browser/web_contents_user_data.h" |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 15 | |
[email protected] | ff3d94e | 2012-12-18 07:16:31 | [diff] [blame^] | 16 | class ZoomObserver; |
17 | |||||
[email protected] | dea9cee8 | 2012-09-25 03:10:52 | [diff] [blame] | 18 | namespace content { |
19 | class WebContents; | ||||
20 | } | ||||
21 | |||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 22 | // Per-tab class to manage the Omnibox zoom icon. |
23 | class ZoomController : public content::NotificationObserver, | ||||
[email protected] | dea9cee8 | 2012-09-25 03:10:52 | [diff] [blame] | 24 | public content::WebContentsObserver, |
[email protected] | 46b3c98 | 2012-10-09 18:38:30 | [diff] [blame] | 25 | public content::WebContentsUserData<ZoomController> { |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 26 | public: |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 27 | virtual ~ZoomController(); |
28 | |||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 29 | int zoom_percent() const { return zoom_percent_; } |
30 | |||||
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 31 | // 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] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 37 | void set_observer(ZoomObserver* observer) { observer_ = observer; } |
38 | |||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 39 | // 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] | 550fd377 | 2012-11-20 01:06:02 | [diff] [blame] | 49 | private: |
50 | explicit ZoomController(content::WebContents* web_contents); | ||||
51 | friend class content::WebContentsUserData<ZoomController>; | ||||
52 | friend class ZoomControllerTest; | ||||
53 | |||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 54 | // Updates the zoom icon and zoom percentage based on current values and |
[email protected] | 9a840890 | 2012-09-26 16:17:59 | [diff] [blame] | 55 | // 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] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 59 | |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 60 | // 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] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 68 | // Observer receiving notifications on state changes. |
69 | ZoomObserver* observer_; | ||||
70 | |||||
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(ZoomController); |
72 | }; | ||||
73 | |||||
74 | #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |