Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: components/zoom/zoom_controller.cc

Issue 2430823002: Reduce usage of FOR_EACH_OBSERVER macro in components/ (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/wallpaper/wallpaper_resizer.cc ('k') | components/zoom/zoom_event_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/zoom/zoom_controller.h" 5 #include "components/zoom/zoom_controller.h"
6 6
7 #include "components/zoom/zoom_event_manager.h" 7 #include "components/zoom/zoom_event_manager.h"
8 #include "components/zoom/zoom_observer.h" 8 #include "components/zoom/zoom_observer.h"
9 #include "content/public/browser/host_zoom_map.h" 9 #include "content/public/browser/host_zoom_map.h"
10 #include "content/public/browser/navigation_details.h" 10 #include "content/public/browser/navigation_details.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ZoomEventManager::GetForBrowserContext(browser_context_) 120 ZoomEventManager::GetForBrowserContext(browser_context_)
121 ->OnZoomLevelChanged(change); 121 ->OnZoomLevelChanged(change);
122 122
123 bool can_show_bubble = can_show_bubble_; 123 bool can_show_bubble = can_show_bubble_;
124 if (client && client->ShouldSuppressBubble()) 124 if (client && client->ShouldSuppressBubble())
125 can_show_bubble = false; 125 can_show_bubble = false;
126 126
127 ZoomChangedEventData zoom_change_data(web_contents(), old_zoom_level, 127 ZoomChangedEventData zoom_change_data(web_contents(), old_zoom_level,
128 zoom_level_, zoom_mode_, 128 zoom_level_, zoom_mode_,
129 can_show_bubble); 129 can_show_bubble);
130 FOR_EACH_OBSERVER(ZoomObserver, observers_, 130 for (auto& observer : observers_)
131 OnZoomChanged(zoom_change_data)); 131 observer.OnZoomChanged(zoom_change_data);
132 132
133 last_client_ = NULL; 133 last_client_ = NULL;
134 return true; 134 return true;
135 } 135 }
136 136
137 content::HostZoomMap* zoom_map = 137 content::HostZoomMap* zoom_map =
138 content::HostZoomMap::GetForWebContents(web_contents()); 138 content::HostZoomMap::GetForWebContents(web_contents());
139 DCHECK(zoom_map); 139 DCHECK(zoom_map);
140 DCHECK(!event_data_); 140 DCHECK(!event_data_);
141 event_data_.reset(new ZoomChangedEventData(web_contents(), GetZoomLevel(), 141 event_data_.reset(new ZoomChangedEventData(web_contents(), GetZoomLevel(),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 case ZOOM_MODE_ISOLATED: { 214 case ZOOM_MODE_ISOLATED: {
215 // Unless the zoom mode was |ZOOM_MODE_DISABLED| before this call, the 215 // Unless the zoom mode was |ZOOM_MODE_DISABLED| before this call, the
216 // page needs an initial isolated zoom back to the same level it was at 216 // page needs an initial isolated zoom back to the same level it was at
217 // in the other mode. 217 // in the other mode.
218 if (zoom_mode_ != ZOOM_MODE_DISABLED) { 218 if (zoom_mode_ != ZOOM_MODE_DISABLED) {
219 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 219 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
220 original_zoom_level); 220 original_zoom_level);
221 } else { 221 } else {
222 // When we don't call any HostZoomMap set functions, we send the event 222 // When we don't call any HostZoomMap set functions, we send the event
223 // manually. 223 // manually.
224 FOR_EACH_OBSERVER(ZoomObserver, observers_, 224 for (auto& observer : observers_)
225 OnZoomChanged(*event_data_)); 225 observer.OnZoomChanged(*event_data_);
226 event_data_.reset(); 226 event_data_.reset();
227 } 227 }
228 break; 228 break;
229 } 229 }
230 case ZOOM_MODE_MANUAL: { 230 case ZOOM_MODE_MANUAL: {
231 // Unless the zoom mode was |ZOOM_MODE_DISABLED| before this call, the 231 // Unless the zoom mode was |ZOOM_MODE_DISABLED| before this call, the
232 // page needs to be resized to the default zoom. While in manual mode, 232 // page needs to be resized to the default zoom. While in manual mode,
233 // the zoom level is handled independently. 233 // the zoom level is handled independently.
234 if (zoom_mode_ != ZOOM_MODE_DISABLED) { 234 if (zoom_mode_ != ZOOM_MODE_DISABLED) {
235 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 235 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
236 GetDefaultZoomLevel()); 236 GetDefaultZoomLevel());
237 zoom_level_ = original_zoom_level; 237 zoom_level_ = original_zoom_level;
238 } else { 238 } else {
239 // When we don't call any HostZoomMap set functions, we send the event 239 // When we don't call any HostZoomMap set functions, we send the event
240 // manually. 240 // manually.
241 FOR_EACH_OBSERVER(ZoomObserver, observers_, 241 for (auto& observer : observers_)
242 OnZoomChanged(*event_data_)); 242 observer.OnZoomChanged(*event_data_);
243 event_data_.reset(); 243 event_data_.reset();
244 } 244 }
245 break; 245 break;
246 } 246 }
247 case ZOOM_MODE_DISABLED: { 247 case ZOOM_MODE_DISABLED: {
248 // The page needs to be zoomed back to default before disabling the zoom 248 // The page needs to be zoomed back to default before disabling the zoom
249 double new_zoom_level = GetDefaultZoomLevel(); 249 double new_zoom_level = GetDefaultZoomLevel();
250 event_data_->new_zoom_level = new_zoom_level; 250 event_data_->new_zoom_level = new_zoom_level;
251 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 251 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
252 new_zoom_level); 252 new_zoom_level);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 } 339 }
340 340
341 if (event_data_) { 341 if (event_data_) {
342 // For state changes initiated within the ZoomController, information about 342 // For state changes initiated within the ZoomController, information about
343 // the change should be sent. 343 // the change should be sent.
344 ZoomChangedEventData zoom_change_data = *event_data_; 344 ZoomChangedEventData zoom_change_data = *event_data_;
345 event_data_.reset(); 345 event_data_.reset();
346 // The zoom bubble should not be shown for zoom changes where the host 346 // The zoom bubble should not be shown for zoom changes where the host
347 // is empty. 347 // is empty.
348 zoom_change_data.can_show_bubble = can_show_bubble_ && !host.empty(); 348 zoom_change_data.can_show_bubble = can_show_bubble_ && !host.empty();
349 FOR_EACH_OBSERVER(ZoomObserver, observers_, 349 for (auto& observer : observers_)
350 OnZoomChanged(zoom_change_data)); 350 observer.OnZoomChanged(zoom_change_data);
351 } else { 351 } else {
352 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and 352 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and
353 // new zoom levels here? 353 // new zoom levels here?
354 double zoom_level = GetZoomLevel(); 354 double zoom_level = GetZoomLevel();
355 // We never show a zoom bubble for an event we didn't generate. 355 // We never show a zoom bubble for an event we didn't generate.
356 ZoomChangedEventData zoom_change_data(web_contents(), zoom_level, 356 ZoomChangedEventData zoom_change_data(web_contents(), zoom_level,
357 zoom_level, zoom_mode_, 357 zoom_level, zoom_mode_,
358 false /* can_show_bubble */); 358 false /* can_show_bubble */);
359 FOR_EACH_OBSERVER(ZoomObserver, observers_, 359 for (auto& observer : observers_)
360 OnZoomChanged(zoom_change_data)); 360 observer.OnZoomChanged(zoom_change_data);
361 } 361 }
362 } 362 }
363 363
364 void ZoomController::SetPageScaleFactorIsOneForTesting(bool is_one) { 364 void ZoomController::SetPageScaleFactorIsOneForTesting(bool is_one) {
365 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); 365 int render_process_id = web_contents()->GetRenderProcessHost()->GetID();
366 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); 366 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID();
367 host_zoom_map_->SetPageScaleFactorIsOneForView(render_process_id, 367 host_zoom_map_->SetPageScaleFactorIsOneForView(render_process_id,
368 render_view_id, is_one); 368 render_view_id, is_one);
369 } 369 }
370 370
371 bool ZoomController::PageScaleFactorIsOne() const { 371 bool ZoomController::PageScaleFactorIsOne() const {
372 return content::HostZoomMap::PageScaleFactorIsOne(web_contents()); 372 return content::HostZoomMap::PageScaleFactorIsOne(web_contents());
373 } 373 }
374 374
375 } // namespace zoom 375 } // namespace zoom
OLDNEW
« no previous file with comments | « components/wallpaper/wallpaper_resizer.cc ('k') | components/zoom/zoom_event_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698