Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/ui/browser_finder.h" | |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 10 #include "chrome/common/chrome_notification_types.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "content/public/browser/notification_types.h" | |
| 13 #include "content/public/browser/notification_details.h" | |
| 14 #include "content/public/browser/notification_service.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/common/page_zoom.h" | |
| 17 | |
| 18 ZoomController::ZoomController(TabContentsWrapper* tab_contents) | |
| 19 : content::WebContentsObserver(tab_contents->web_contents()), | |
| 20 tab_contents_wrapper_(tab_contents), | |
| 21 observer_(NULL) { | |
| 22 default_zoom_level_.Init(prefs::kDefaultZoomLevel, | |
| 23 tab_contents->profile()->GetPrefs(), this); | |
| 24 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 25 content::NotificationService::AllBrowserContextsAndSources()); | |
| 26 | |
| 27 UpdateState(); | |
| 28 } | |
| 29 | |
| 30 ZoomController::~ZoomController() { | |
| 31 default_zoom_level_.Destroy(); | |
| 32 registrar_.RemoveAll(); | |
| 33 } | |
| 34 | |
| 35 void ZoomController::DidNavigateMainFrame( | |
| 36 const content::LoadCommittedDetails& details, | |
| 37 const content::FrameNavigateParams& params) { | |
| 38 // If the main frame's content has changed, the new page may have a different | |
| 39 // zoom level from the old one. | |
| 40 UpdateState(); | |
| 41 } | |
| 42 | |
| 43 void ZoomController::Observe(int type, | |
| 44 const content::NotificationSource& source, | |
| 45 const content::NotificationDetails& details) { | |
| 46 switch (type) { | |
| 47 case chrome::NOTIFICATION_PREF_CHANGED: { | |
| 48 std::string* pref_name = content::Details<std::string>(details).ptr(); | |
| 49 DCHECK(pref_name && *pref_name == prefs::kDefaultZoomLevel); | |
| 50 } | |
| 51 // Fall through. | |
|
tfarina
2012/06/01 00:47:53
nit: fix indentation here.
Kyle Horimoto
2012/06/01 18:04:50
Done.
| |
| 52 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: | |
| 53 UpdateState(); | |
| 54 break; | |
| 55 default: | |
| 56 NOTREACHED(); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void ZoomController::UpdateState() { | |
| 61 double current_zoom_level = | |
| 62 tab_contents_wrapper_->web_contents()->GetZoomLevel(); | |
| 63 double default_zoom_level = default_zoom_level_.GetValue(); | |
| 64 | |
| 65 ZoomIconState state; | |
| 66 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level)) | |
| 67 state = NONE; | |
| 68 else if (current_zoom_level > default_zoom_level) | |
| 69 state = ZOOM_PLUS_ICON; | |
| 70 else | |
| 71 state = ZOOM_MINUS_ICON; | |
| 72 | |
| 73 bool dummy; | |
| 74 int zoom_percent = tab_contents_wrapper_->web_contents()-> | |
| 75 GetZoomPercent(&dummy, &dummy); | |
| 76 | |
| 77 if (state != zoom_icon_state_) { | |
| 78 zoom_icon_state_ = state; | |
| 79 if (observer_) | |
| 80 observer_->OnZoomIconChanged(tab_contents_wrapper_, state); | |
| 81 } | |
| 82 | |
| 83 if (zoom_percent != zoom_percent_) { | |
| 84 zoom_percent_ = zoom_percent; | |
| 85 if (observer_) | |
| 86 observer_->OnZoomChanged(tab_contents_wrapper_, zoom_percent); | |
| 87 } | |
| 88 } | |
| OLD | NEW |