Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/ui/zoom/zoom_controller.h

Issue 301733006: Zoom Extension API (chrome) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, make zoom bubble icon loading safer. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/observer_list.h"
10 #include "base/prefs/pref_member.h" 11 #include "base/prefs/pref_member.h"
11 #include "content/public/browser/host_zoom_map.h" 12 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h" 14 #include "content/public/browser/web_contents_user_data.h"
14 15
15 class ZoomObserver; 16 class ZoomObserver;
16 17
17 namespace content { 18 namespace content {
18 class WebContents; 19 class WebContents;
19 } 20 }
20 21
21 // Per-tab class to manage the Omnibox zoom icon. 22 namespace extensions {
23 class Extension;
24 } // namespace extensions
25
26 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
22 class ZoomController : public content::WebContentsObserver, 27 class ZoomController : public content::WebContentsObserver,
23 public content::WebContentsUserData<ZoomController> { 28 public content::WebContentsUserData<ZoomController> {
24 public: 29 public:
30 // Defines how zoom changes are handled.
31 // |kZoomModeDefault| results in default zoom behavior, i.e. zoom changes are
32 // handled automatically and on a per-origin basis, meaning that other
33 // tabs navigated to the same origin will also zoom.
34 // |kZoomModeIsolated| results in zoom changes being handled automatically,
35 // but on a per-tab basis. Tabs in this zoom mode will not be affected by
36 // zoom changes in other tabs, and vice versa.
37 // |kZoomModeManual| overrides the automatic handling of zoom changes. The
38 // |onZoomChange| event will still be dispatched, but the page will not
39 // actually be zoomed. These zoom changes can be handled manually by
40 // listening for the |onZoomChange| event. Zooming in this mode is also on
41 // a per-tab basis.
42 // |kZoomModeDisabled| disables all zooming in this tab. The tab will revert
43 // to default (100%) zoom, and all attempted zoom changes will be ignored.
44 enum ZoomMode {
45 kZoomModeDefault,
sky 2014/06/24 16:23:42 ZOOM_MODE_DEFAULT is the right name and style for
wjmaclean 2014/06/24 18:04:07 Done.
46 kZoomModeIsolated,
47 kZoomModeManual,
48 kZoomModeDisabled,
49 };
50
25 virtual ~ZoomController(); 51 virtual ~ZoomController();
26 52
27 int zoom_percent() const { return zoom_percent_; } 53 ZoomMode zoom_mode() const { return zoom_mode_; }
28 54
29 // Convenience method to quickly check if the tab's at default zoom. 55 // Convenience method to quickly check if the tab's at default zoom.
30 bool IsAtDefaultZoom() const; 56 bool IsAtDefaultZoom() const;
31 57
32 // Returns which image should be loaded for the current zoom level. 58 // Returns which image should be loaded for the current zoom level.
33 int GetResourceForZoomLevel() const; 59 int GetResourceForZoomLevel() const;
34 60
35 void set_observer(ZoomObserver* observer) { observer_ = observer; } 61 const extensions::Extension* last_extension() const {
62 return last_extension_.get();
63 }
64
65 void AddObserver(ZoomObserver* observer);
66 void RemoveObserver(ZoomObserver* observer);
67
68 double GetZoomLevel() const;
69 int GetZoomPercent() const;
70
71 // Sets the zoom level through HostZoomMap.
72 // Returns true on success.
73 bool SetZoomLevel(double zoom_level);
74
75 // Sets the zoom level through WebContents::SetZoomLevel(), and attributes the
76 // zoom to |extension|. Returns a boolean flag indicating success (true) or
77 // failure (false).
78 bool SetZoomLevelByExtension(
79 double zoom_level,
80 scoped_refptr<const extensions::Extension> extension);
81
82 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
83 void SetZoomMode(ZoomMode zoom_mode);
36 84
37 // content::WebContentsObserver overrides: 85 // content::WebContentsObserver overrides:
38 virtual void DidNavigateMainFrame( 86 virtual void DidNavigateMainFrame(
39 const content::LoadCommittedDetails& details, 87 const content::LoadCommittedDetails& details,
40 const content::FrameNavigateParams& params) OVERRIDE; 88 const content::FrameNavigateParams& params) OVERRIDE;
41 89
42 private: 90 private:
43 explicit ZoomController(content::WebContents* web_contents); 91 explicit ZoomController(content::WebContents* web_contents);
44 friend class content::WebContentsUserData<ZoomController>; 92 friend class content::WebContentsUserData<ZoomController>;
45 friend class ZoomControllerTest; 93 friend class ZoomControllerTest;
46 94
47 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 95 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
48 96
49 // Updates the zoom icon and zoom percentage based on current values and 97 // Updates the zoom icon and zoom percentage based on current values and
50 // notifies the observer if changes have occurred. |host| may be empty, 98 // notifies the observer if changes have occurred. |host| may be empty,
51 // meaning the change should apply to ~all sites. If it is not empty, the 99 // meaning the change should apply to ~all sites. If it is not empty, the
52 // change only affects sites with the given host. 100 // change only affects sites with the given host.
53 void UpdateState(const std::string& host); 101 void UpdateState(const std::string& host);
102 // Same as UpdateState, but takes into account whether a temporary zoom level
103 // has been set on |host| when deciding whether to show the zoom notification
104 // bubble.
105 void UpdateStateIncludingTemporary(const std::string& host,
106 bool is_temporary_zoom);
54 107
55 // The current zoom percentage. 108 // The current zoom mode.
56 int zoom_percent_; 109 ZoomMode zoom_mode_;
110
111 // Current zoom level.
112 double zoom_level_;
57 113
58 // Used to access the default zoom level preference. 114 // Used to access the default zoom level preference.
59 DoublePrefMember default_zoom_level_; 115 DoublePrefMember default_zoom_level_;
60 116
117 // Keeps track of the extension (if any) that initiated the last zoom change
118 // that took effect.
119 scoped_refptr<const extensions::Extension> last_extension_;
120
61 // Observer receiving notifications on state changes. 121 // Observer receiving notifications on state changes.
62 ZoomObserver* observer_; 122 ObserverList<ZoomObserver> observers_;
63 123
64 content::BrowserContext* browser_context_; 124 content::BrowserContext* browser_context_;
65 125
66 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 126 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
67 127
68 DISALLOW_COPY_AND_ASSIGN(ZoomController); 128 DISALLOW_COPY_AND_ASSIGN(ZoomController);
69 }; 129 };
70 130
71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ 131 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698