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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 void ZoomController::DidNavigateMainFrame( | 251 void ZoomController::DidNavigateMainFrame( |
252 const content::LoadCommittedDetails& details, | 252 const content::LoadCommittedDetails& details, |
253 const content::FrameNavigateParams& params) { | 253 const content::FrameNavigateParams& params) { |
254 // If the main frame's content has changed, the new page may have a different | 254 // If the main frame's content has changed, the new page may have a different |
255 // zoom level from the old one. | 255 // zoom level from the old one. |
256 UpdateState(std::string()); | 256 UpdateState(std::string()); |
257 } | 257 } |
258 | 258 |
259 void ZoomController::OnZoomLevelChanged( | 259 void ZoomController::OnZoomLevelChanged( |
260 const content::HostZoomMap::ZoomLevelChange& change) { | 260 const content::HostZoomMap::ZoomLevelChange& change) { |
261 UpdateStateIncludingTemporary( | 261 UpdateState(change.host); |
262 change.host, | |
263 change.mode == content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM); | |
264 } | 262 } |
265 | 263 |
266 void ZoomController::UpdateState(const std::string& host) { | 264 void ZoomController::UpdateState(const std::string& host) { |
267 UpdateStateIncludingTemporary(host, false); | |
268 } | |
269 | |
270 void ZoomController::UpdateStateIncludingTemporary(const std::string& host, | |
271 bool is_temporary_zoom) { | |
272 // If |host| is empty, all observers should be updated. | 265 // If |host| is empty, all observers should be updated. |
273 if (!host.empty()) { | 266 if (!host.empty()) { |
274 // Use the navigation entry's URL instead of the WebContents' so virtual | 267 // Use the navigation entry's URL instead of the WebContents' so virtual |
275 // URLs work (e.g. chrome://settings). http://crbug.com/153950 | 268 // URLs work (e.g. chrome://settings). http://crbug.com/153950 |
276 content::NavigationEntry* entry = | 269 content::NavigationEntry* entry = |
277 web_contents()->GetController().GetLastCommittedEntry(); | 270 web_contents()->GetController().GetLastCommittedEntry(); |
278 if (!entry || | 271 if (!entry || |
279 host != net::GetHostOrSpecFromURL(entry->GetURL())) { | 272 host != net::GetHostOrSpecFromURL(entry->GetURL())) { |
280 return; | 273 return; |
281 } | 274 } |
282 } | 275 } |
283 | 276 |
284 // The zoom bubble can be shown for all normal, per-origin zoom changes | 277 // The zoom bubble can be shown for all zoom changes where the host is |
285 // (where the host will not be empty and the zoom is not temporary), or any | 278 // not empty. |
286 // special zoom changes (where the zoom mode will not be "default"). | 279 bool can_show_bubble = !host.empty(); |
287 bool can_show_bubble = | |
288 zoom_mode_ != ZOOM_MODE_DEFAULT || (!host.empty() && !is_temporary_zoom); | |
289 | 280 |
290 if (event_data_) { | 281 if (event_data_) { |
291 // For state changes initiated within the ZoomController, information about | 282 // For state changes initiated within the ZoomController, information about |
292 // the change should be sent. | 283 // the change should be sent. |
293 ZoomChangedEventData zoom_change_data = *event_data_; | 284 ZoomChangedEventData zoom_change_data = *event_data_; |
294 event_data_.reset(); | 285 event_data_.reset(); |
295 zoom_change_data.can_show_bubble |= can_show_bubble; | 286 zoom_change_data.can_show_bubble = can_show_bubble; |
296 FOR_EACH_OBSERVER( | 287 FOR_EACH_OBSERVER( |
297 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 288 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
298 } else { | 289 } else { |
299 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and | 290 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and |
300 // new zoom levels here? | 291 // new zoom levels here? |
301 double zoom_level = GetZoomLevel(); | 292 double zoom_level = GetZoomLevel(); |
302 ZoomChangedEventData zoom_change_data( | 293 ZoomChangedEventData zoom_change_data( |
303 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); | 294 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); |
304 FOR_EACH_OBSERVER( | 295 FOR_EACH_OBSERVER( |
305 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 296 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
306 } | 297 } |
307 } | 298 } |
OLD | NEW |