Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class BrowserContext; | 18 class BrowserContext; |
| 19 class ResourceContext; | 19 class ResourceContext; |
| 20 | 20 |
| 21 // Maps hostnames to custom zoom levels. Written on the UI thread and read on | 21 // Maps hostnames to custom zoom levels. Written on the UI thread and read on |
| 22 // any thread. One instance per browser context. Must be created on the UI | 22 // any thread. One instance per browser context. Must be created on the UI |
| 23 // thread, and it'll delete itself on the UI thread as well. | 23 // thread, and it'll delete itself on the UI thread as well. |
| 24 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom | |
| 25 // for host with specific scheme. Setting any of the levels leaves settings | |
| 26 // for other settings intact. Getting zoom level tries to look up most specific | |
| 27 // setting | |
|
sky
2013/03/07 15:47:03
For that last sentence, how about: "Getting the zo
| |
| 28 | |
| 24 class HostZoomMap { | 29 class HostZoomMap { |
| 25 public: | 30 public: |
| 31 // Enum that indicates what was the scope of zoom level change. | |
| 32 enum ZoomLevelChangeMode { | |
| 33 ZOOM_CHANGED_FOR_HOST, // Zoom level changed for host. | |
| 34 ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host | |
| 35 // pair. | |
| 36 ZOOM_CHANGED_TEMPORARY_ZOOM, // Temporary zoom change for specific | |
| 37 // renderer, no scheme/host is specified. | |
| 38 }; | |
| 39 | |
| 40 // Structure used to notify about zoom changes. Host and Scheme part can be | |
|
sky
2013/03/07 15:47:03
Host and/or scheme are empty if not applicable to
| |
| 41 // empty if they do not make sense for particular mode. | |
| 42 struct ZoomLevelChange { | |
| 43 ZoomLevelChangeMode mode; | |
| 44 std::string host; | |
| 45 std::string scheme; | |
| 46 double zoom_level; | |
| 47 }; | |
| 48 | |
| 26 CONTENT_EXPORT static HostZoomMap* GetForBrowserContext( | 49 CONTENT_EXPORT static HostZoomMap* GetForBrowserContext( |
| 27 BrowserContext* browser_context); | 50 BrowserContext* browser_context); |
| 28 | 51 |
| 29 // Copy the zoom levels from the given map. Can only be called on the UI | 52 // Copy the zoom levels from the given map. Can only be called on the UI |
| 30 // thread. | 53 // thread. |
| 31 virtual void CopyFrom(HostZoomMap* copy) = 0; | 54 virtual void CopyFrom(HostZoomMap* copy) = 0; |
| 32 | 55 |
| 33 // Returns the zoom level for the host or spec for a given url. The zoom | 56 // Here |host| is the host portion of URL, or (in the absence of a host) |
| 34 // level is determined by the host portion of the URL, or (in the absence of | 57 // the complete spec of the URL. |
| 35 // a host) the complete spec of the URL. In most cases, there is no custom | 58 // Returns the zoom level for the |host| for a given url, taking |scheme| in |
|
sky
2013/03/07 15:47:03
I think I nuke all this and go with:
// Reeturns t
| |
| 36 // zoom level, and this returns the user's default zoom level. Otherwise, | 59 // account. If there is specific zoom level specified for given |scheme| and |
| 37 // returns the saved zoom level, which may be positive (to zoom in) or | 60 // |host| pair, it will be returned. In other cases the zoom level is |
| 61 // determined by the |host| only, In most cases, there is no custom zoom | |
| 62 // level, and this returns the user's default zoom level. | |
| 63 // | |
| 64 // Returns the saved zoom level, which may be positive (to zoom in) or | |
| 38 // negative (to zoom out). | 65 // negative (to zoom out). |
| 39 // | 66 // |
| 40 // This may be called on any thread. | 67 // This may be called on any thread. |
| 41 virtual double GetZoomLevel(const std::string& host) const = 0; | 68 virtual double GetZoomLevelForHostAndScheme( |
| 69 const std::string& scheme, | |
| 70 const std::string& host) const = 0; | |
| 42 | 71 |
| 43 // Sets the zoom level for the host or spec for a given url to |level|. If | 72 // Here |host| is the host portion of URL, or (in the absence of a host) |
| 44 // the level matches the current default zoom level, the host is erased | 73 // the complete spec of the URL. |
| 45 // from the saved preferences; otherwise the new value is written out. | 74 // Sets the zoom level for the |host| to |level|. If the level matches the |
| 75 // current default zoom level, the host is erased from the saved preferences; | |
| 76 // otherwise the new value is written out. | |
| 77 // Zoom levels specified for both scheme and host are not affected. | |
| 46 // | 78 // |
| 47 // This should only be called on the UI thread. | 79 // This should only be called on the UI thread. |
| 48 virtual void SetZoomLevel(const std::string& host, double level) = 0; | 80 virtual void SetZoomLevelForHost(const std::string& host, double level) = 0; |
| 81 | |
| 82 // Here |host| is the host portion of URL, or (in the absence of a host) | |
| 83 // the complete spec of the URL. | |
| 84 // Sets the zoom level for the |scheme|/|host| pair to |level|. No values | |
| 85 // will be erased during this operation, and this value will not be stored in | |
| 86 // the preferences. | |
| 87 // | |
| 88 // This should only be called on the UI thread. | |
| 89 virtual void SetZoomLevelForHostAndScheme(const std::string& scheme, | |
| 90 const std::string& host, | |
| 91 double level) = 0; | |
| 49 | 92 |
| 50 // Get/Set the default zoom level for pages that don't override it. | 93 // Get/Set the default zoom level for pages that don't override it. |
| 51 virtual double GetDefaultZoomLevel() const = 0; | 94 virtual double GetDefaultZoomLevel() const = 0; |
| 52 virtual void SetDefaultZoomLevel(double level) = 0;; | 95 virtual void SetDefaultZoomLevel(double level) = 0;; |
| 53 | 96 |
| 54 typedef base::Callback<void(const std::string&)> ZoomLevelChangedCallback; | 97 typedef base::Callback<void(const ZoomLevelChange&)> ZoomLevelChangedCallback; |
| 55 | 98 |
| 56 // Add and remove zoom level changed callbacks. | 99 // Add and remove zoom level changed callbacks. |
| 57 virtual void AddZoomLevelChangedCallback( | 100 virtual void AddZoomLevelChangedCallback( |
| 58 const ZoomLevelChangedCallback& callback) = 0; | 101 const ZoomLevelChangedCallback& callback) = 0; |
| 59 virtual void RemoveZoomLevelChangedCallback( | 102 virtual void RemoveZoomLevelChangedCallback( |
| 60 const ZoomLevelChangedCallback& callback) = 0; | 103 const ZoomLevelChangedCallback& callback) = 0; |
| 61 | 104 |
| 62 protected: | 105 protected: |
| 63 virtual ~HostZoomMap() {} | 106 virtual ~HostZoomMap() {} |
| 64 }; | 107 }; |
| 65 | 108 |
| 66 } // namespace content | 109 } // namespace content |
| 67 | 110 |
| 68 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ | 111 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_ |
| OLD | NEW |