| 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 #include "chrome/browser/ui/zoom/zoom_controller.h" | 5 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/page_zoom.h" | 16 #include "content/public/common/page_zoom.h" |
| 17 | 17 |
| 18 ZoomController::ZoomController(TabContentsWrapper* tab_contents) | 18 ZoomController::ZoomController(TabContents* tab_contents) |
| 19 : content::WebContentsObserver(tab_contents->web_contents()), | 19 : content::WebContentsObserver(tab_contents->web_contents()), |
| 20 zoom_icon_state_(NONE), | 20 zoom_icon_state_(NONE), |
| 21 zoom_percent_(100), | 21 zoom_percent_(100), |
| 22 tab_contents_wrapper_(tab_contents), | 22 tab_contents_(tab_contents), |
| 23 observer_(NULL) { | 23 observer_(NULL) { |
| 24 default_zoom_level_.Init(prefs::kDefaultZoomLevel, | 24 default_zoom_level_.Init(prefs::kDefaultZoomLevel, |
| 25 tab_contents->profile()->GetPrefs(), this); | 25 tab_contents->profile()->GetPrefs(), this); |
| 26 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 26 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| 27 content::NotificationService::AllBrowserContextsAndSources()); | 27 content::NotificationService::AllBrowserContextsAndSources()); |
| 28 | 28 |
| 29 UpdateState(); | 29 UpdateState(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 ZoomController::~ZoomController() { | 32 ZoomController::~ZoomController() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 53 // Fall through. | 53 // Fall through. |
| 54 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: | 54 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: |
| 55 UpdateState(); | 55 UpdateState(); |
| 56 break; | 56 break; |
| 57 default: | 57 default: |
| 58 NOTREACHED(); | 58 NOTREACHED(); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 void ZoomController::UpdateState() { | 62 void ZoomController::UpdateState() { |
| 63 double current_zoom_level = | 63 double current_zoom_level = tab_contents_->web_contents()->GetZoomLevel(); |
| 64 tab_contents_wrapper_->web_contents()->GetZoomLevel(); | |
| 65 double default_zoom_level = default_zoom_level_.GetValue(); | 64 double default_zoom_level = default_zoom_level_.GetValue(); |
| 66 | 65 |
| 67 ZoomIconState state; | 66 ZoomIconState state; |
| 68 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level)) | 67 if (content::ZoomValuesEqual(current_zoom_level, default_zoom_level)) |
| 69 state = NONE; | 68 state = NONE; |
| 70 else if (current_zoom_level > default_zoom_level) | 69 else if (current_zoom_level > default_zoom_level) |
| 71 state = ZOOM_PLUS_ICON; | 70 state = ZOOM_PLUS_ICON; |
| 72 else | 71 else |
| 73 state = ZOOM_MINUS_ICON; | 72 state = ZOOM_MINUS_ICON; |
| 74 | 73 |
| 75 bool dummy; | 74 bool dummy; |
| 76 int zoom_percent = tab_contents_wrapper_->web_contents()-> | 75 int zoom_percent = tab_contents_->web_contents()-> |
| 77 GetZoomPercent(&dummy, &dummy); | 76 GetZoomPercent(&dummy, &dummy); |
| 78 | 77 |
| 79 if (state != zoom_icon_state_) { | 78 if (state != zoom_icon_state_) { |
| 80 zoom_icon_state_ = state; | 79 zoom_icon_state_ = state; |
| 81 if (observer_) | 80 if (observer_) |
| 82 observer_->OnZoomIconChanged(tab_contents_wrapper_, state); | 81 observer_->OnZoomIconChanged(tab_contents_, state); |
| 83 } | 82 } |
| 84 | 83 |
| 85 if (zoom_percent != zoom_percent_) { | 84 if (zoom_percent != zoom_percent_) { |
| 86 zoom_percent_ = zoom_percent; | 85 zoom_percent_ = zoom_percent; |
| 87 if (observer_) | 86 if (observer_) |
| 88 observer_->OnZoomChanged(tab_contents_wrapper_, | 87 observer_->OnZoomChanged(tab_contents_, |
| 89 zoom_percent, | 88 zoom_percent, |
| 90 state != NONE); | 89 state != NONE); |
| 91 } | 90 } |
| 92 } | 91 } |
| OLD | NEW |