diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 07:28:25 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 07:28:25 +0000 |
commit | b75b829359b4b432d0462ab5011542f99f2021a5 (patch) | |
tree | 564389d8698b140e97918a4cefd7ad18c7c99e7f /chrome/browser/tab_contents | |
parent | 3ec5d92cbba6b7b13ead81ebfd9e3c202fae001d (diff) | |
download | chromium_src-b75b829359b4b432d0462ab5011542f99f2021a5.zip chromium_src-b75b829359b4b432d0462ab5011542f99f2021a5.tar.gz chromium_src-b75b829359b4b432d0462ab5011542f99f2021a5.tar.bz2 |
Chrome side of consolidating zoom code for pepper plugins (i.e. pdf) and the rest of Chrome. Allows plugins to have different zoom ranges, and also to update zoom on its own.
Review URL: http://codereview.chromium.org/3419023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/match_preview.cc | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 55 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 22 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.cc | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.h | 5 |
5 files changed, 64 insertions, 22 deletions
diff --git a/chrome/browser/tab_contents/match_preview.cc b/chrome/browser/tab_contents/match_preview.cc index f611872..01e6931 100644 --- a/chrome/browser/tab_contents/match_preview.cc +++ b/chrome/browser/tab_contents/match_preview.cc @@ -419,7 +419,6 @@ class MatchPreview::TabContentsDelegateImpl : public TabContentsDelegate { virtual bool infobars_enabled() { return false; } virtual bool ShouldEnablePreferredSizeNotifications() { return false; } virtual void UpdatePreferredSize(const gfx::Size& pref_size) {} - virtual void ContentTypeChanged(TabContents* source) {} virtual void OnSetSuggestResult(int32 page_id, const std::string& result) { TabContents* source = match_preview_->preview_contents(); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 4071540..693532e 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -4,6 +4,8 @@ #include "chrome/browser/tab_contents/tab_contents.h" +#include <cmath> + #if defined(OS_CHROMEOS) // For GdkScreen #include <gdk/gdk.h> @@ -45,6 +47,7 @@ #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/top_sites.h" +#include "chrome/browser/host_zoom_map.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/file_select_helper.h" #include "chrome/browser/find_bar_state.h" @@ -109,6 +112,7 @@ #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/base/registry_controlled_domain.h" +#include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/password_form.h" @@ -375,7 +379,16 @@ TabContents::TabContents(Profile* profile, opener_dom_ui_type_(DOMUIFactory::kNoDOMUI), language_state_(&controller_), closed_by_user_gesture_(false), - displaying_pdf_content_(false) { +#ifdef ZOOM_LEVEL_IS_DOUBLE + minimum_zoom_percent_( + static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)), + maximum_zoom_percent_( + static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)), +#else + minimum_zoom_percent_(50), + maximum_zoom_percent_(300), +#endif + temporary_zoom_settings_(false) { renderer_preferences_util::UpdateFromSystemSettings( &renderer_preferences_, profile); @@ -1483,6 +1496,33 @@ void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { hs->SetPageTitle(entry.virtual_url(), entry.title()); } +int TabContents::GetZoomPercent(bool* enable_increment, + bool* enable_decrement) { + *enable_decrement = *enable_increment = false; + HostZoomMap* zoom_map = profile()->GetHostZoomMap(); + if (!zoom_map) + return 100; + + double zoom_level; + if (temporary_zoom_settings_) { + zoom_level = zoom_map->GetTemporaryZoomLevel( + GetRenderProcessHost()->id(), render_view_host()->routing_id()); + } else { + zoom_level = zoom_map->GetZoomLevel(GetURL()); + } + +#ifdef ZOOM_LEVEL_IS_DOUBLE + int percent = static_cast<int>( + WebKit::WebView::zoomLevelToZoomFactor(zoom_level) * 100); +#else + int percent = static_cast<int>(std::pow(1.2, zoom_level) * 100); +#endif + + *enable_decrement = percent > minimum_zoom_percent_; + *enable_increment = percent < maximum_zoom_percent_; + return percent; +} + // Notifies the RenderWidgetHost instance about the fact that the page is // loading, or done loading and calls the base implementation. void TabContents::SetIsLoading(bool is_loading, @@ -2618,9 +2658,6 @@ void TabContents::RequestMove(const gfx::Rect& new_bounds) { } void TabContents::DidStartLoading() { - // By default, we assume that the content is not PDF. The renderer - // will tell us if this is not the case. - displaying_pdf_content_ = false; SetIsLoading(true, NULL); } @@ -2979,10 +3016,12 @@ void TabContents::FocusedNodeChanged() { NotificationService::NoDetails()); } -void TabContents::SetDisplayingPDFContent() { - displaying_pdf_content_ = true; - if (delegate()) - delegate()->ContentTypeChanged(this); +void TabContents::UpdateZoomLimits(int minimum_percent, + int maximum_percent, + bool remember) { + minimum_zoom_percent_ = minimum_percent; + maximum_zoom_percent_ = maximum_percent; + temporary_zoom_settings_ = !remember; } void TabContents::BeforeUnloadFiredFromRenderManager( diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index d37aab8..be8ac99 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -670,8 +670,6 @@ class TabContents : public PageNavigator, } bool closed_by_user_gesture() const { return closed_by_user_gesture_; } - bool is_displaying_pdf_content() const { return displaying_pdf_content_; } - // JavaScriptMessageBoxClient ------------------------------------------------ virtual gfx::NativeWindow GetMessageBoxRootWindow(); virtual void OnMessageBoxClosed(IPC::Message* reply_msg, @@ -711,6 +709,13 @@ class TabContents : public PageNavigator, // the page title and we know we want to update history. void UpdateHistoryPageTitle(const NavigationEntry& entry); + // Gets the zoom percent for this tab. + int GetZoomPercent(bool* enable_increment, bool* enable_decrement); + + // Gets the minimum/maximum zoom percent. + int minimum_zoom_percent() const { return minimum_zoom_percent_; } + int maximum_zoom_percent() const { return maximum_zoom_percent_; } + private: friend class NavigationController; // Used to access the child_windows_ (ConstrainedWindowList) for testing @@ -986,7 +991,9 @@ class TabContents : public PageNavigator, virtual bool IsExternalTabContainer() const; virtual void DidInsertCSS(); virtual void FocusedNodeChanged(); - virtual void SetDisplayingPDFContent(); + virtual void UpdateZoomLimits(int minimum_percent, + int maximum_percent, + bool remember); // RenderViewHostManager::Delegate ------------------------------------------- @@ -1274,8 +1281,13 @@ class TabContents : public PageNavigator, // See description above setter. bool closed_by_user_gesture_; - // See description in RenderViewHostDelegate::SetDisplayingPDFContent. - bool displaying_pdf_content_; + // Minimum/maximum zoom percent. + int minimum_zoom_percent_; + int maximum_zoom_percent_; + // If true, the default zoom limits have been overriden for this tab, in which + // case we don't want saved settings to apply to it and we don't want to + // remember it. + bool temporary_zoom_settings_; // --------------------------------------------------------------------------- diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/chrome/browser/tab_contents/tab_contents_delegate.cc index 5f82ead..85f3641 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/chrome/browser/tab_contents/tab_contents_delegate.cc @@ -182,9 +182,6 @@ bool TabContentsDelegate::ShouldEnablePreferredSizeNotifications() { void TabContentsDelegate::UpdatePreferredSize(const gfx::Size& pref_size) { } -void TabContentsDelegate::ContentTypeChanged(TabContents* source) { -} - void TabContentsDelegate::OnSetSuggestResult(int32 page_id, const std::string& result) { } diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index a870cf3..b566479 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -296,11 +296,6 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Only called if ShouldEnablePreferredSizeNotifications() returns true. virtual void UpdatePreferredSize(const gfx::Size& pref_size); - // Notifies the delegate that something has changed about what content the - // TabContents is displaying. Currently this is only fired when displaying - // PDF using the internal PDF plugin. - virtual void ContentTypeChanged(TabContents* source); - // Notifies the delegate that the page has a suggest result. virtual void OnSetSuggestResult(int32 page_id, const std::string& result); |