OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "ui/gfx/screen_display_observer_delegate.h" | |
6 | |
7 #include "ui/gfx/display.h" | |
8 | |
9 ScreenDisplayObserverDelegate::ScreenDisplayObserverDelegate() { | |
10 } | |
11 | |
12 ScreenDisplayObserverDelegate::~ScreenDisplayObserverDelegate() { | |
13 } | |
14 | |
15 void ScreenDisplayObserverDelegate::AddObserver(gfx::DisplayObserver* obs) { | |
16 observer_list_.AddObserver(obs); | |
17 } | |
18 | |
19 void ScreenDisplayObserverDelegate::RemoveObserver(gfx::DisplayObserver* obs) { | |
20 observer_list_.RemoveObserver(obs); | |
21 } | |
22 | |
23 void ScreenDisplayObserverDelegate::NotifyDisplaysChanged( | |
24 const std::vector<gfx::Display>& old_displays, | |
25 const std::vector<gfx::Display>& new_displays) { | |
26 typedef std::vector<gfx::Display>::const_iterator DisplayIt; | |
27 std::vector<gfx::Display>::const_iterator old_it = old_displays.begin(); | |
28 for (; old_it != old_displays.end(); ++old_it) { | |
29 bool found = false; | |
oshima
2014/07/09 17:12:51
can you use std::find_if ? I usualyl prefer loop o
mlamouri (slow - plz ping)
2014/07/10 12:54:34
Unfortunately, std::find() will compare the items
oshima
2014/07/10 18:11:58
Yes, I meant std:find_if (sorry I mentioned find_i
| |
30 for (std::vector<gfx::Display>::const_iterator new_it = | |
31 new_displays.begin(); new_it != new_displays.end(); ++new_it) { | |
32 if (old_it->id() == new_it->id()) { | |
33 found = true; | |
34 break; | |
35 } | |
36 } | |
37 | |
38 if (!found) { | |
39 FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_, | |
40 OnDisplayRemoved(*old_it)); | |
41 } | |
42 } | |
43 | |
44 for (std::vector<gfx::Display>::const_iterator new_it = | |
45 new_displays.begin(); new_it != new_displays.end(); ++new_it) { | |
46 bool found = false; | |
47 for (std::vector<gfx::Display>::const_iterator old_it = | |
48 old_displays.begin(); old_it != old_displays.end(); ++old_it) { | |
49 if (new_it->id() != old_it->id()) | |
50 continue; | |
51 | |
52 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_NONE; | |
53 | |
54 if (new_it->bounds() != old_it->bounds()) | |
55 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS; | |
56 | |
57 if (new_it->rotation() != old_it->rotation()) | |
58 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION; | |
59 | |
60 if (new_it->work_area() != old_it->work_area()) | |
61 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA; | |
62 | |
63 if (new_it->device_scale_factor() != old_it->device_scale_factor()) | |
64 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; | |
65 | |
66 if (metrics != gfx::DisplayObserver::DISPLAY_METRIC_NONE) { | |
67 FOR_EACH_OBSERVER(gfx::DisplayObserver, | |
68 observer_list_, | |
69 OnDisplayMetricsChanged(*new_it, metrics)); | |
70 } | |
71 | |
72 found = true; | |
73 break; | |
74 } | |
75 | |
76 if (!found) { | |
77 FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_, | |
78 OnDisplayAdded(*new_it)); | |
79 } | |
80 } | |
81 } | |
OLD | NEW |